Skip to content

Instantly share code, notes, and snippets.

@jhejderup
Last active August 18, 2019 14:06
Show Gist options
  • Save jhejderup/fe4cb9c0c6505be9126ae1dc903148ab to your computer and use it in GitHub Desktop.
Save jhejderup/fe4cb9c0c6505be9126ae1dc903148ab to your computer and use it in GitHub Desktop.
Dependency Update Emulation
# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
import sys
regex = r"(\<|\>)\[\d\]\[\d\](.*)\=\d+"
if __name__ == "__main__":
for line in sys.stdin:
try:
sys.stdout.write(re.search(regex,line, re.MULTILINE).group(2) + "\n")
except:
pass
## Clean up previous experiments
cat eval-pom-folder.txt | parallel --max-procs=1 'cd {}; git checkout pom.xml'
##Select candidates
./call_reach_analysis.sh > cmdlist.txt
cat cmdlist.txt > ../trial.one
## Install plugin
cat trial-one.txt | sed 's/\/ast\-calls\-resolved\.txt//' | sort | uniq > eval/trial-one.txt
cat ../eval/trial-one.txt | parallel 'python ../scripts/install_uppdatera_profile.py {}'
## Remove previous agents
ls -d */* | parallel 'cd {}; find . -type f -name pom.xml | xargs -n 1 git checkout'
#NB: there are new `pom.xml` generated that show up as errors, just ignore them
##Create list for installing agents (this remove pom files that are not relevant)
find . -type f -name pom.xml | parallel 'if [ -z $(grep '"'"'uppdatera'"'"' {}) ]; then echo {}; fi' > ../install-cands-dyncg-agent.txt
import sys, os
from lxml import etree
plugins_txt = "<profiles><profile><id>uppdatera</id><properties><maven.test.skip>false</maven.test.skip></properties><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><configuration><argLine>-javaagent:/data/uppdatera/scripts/agent/target/uppdatera-agent-1.0-SNAPSHOT-jar-with-dependencies.jar</argLine></configuration></plugin></plugins></build></profile></profiles>"
plugin_txt = "<profile><id>uppdatera</id><properties><maven.test.skip>false</maven.test.skip></properties><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><configuration><argLine>-javaagent:/data/uppdatera/scripts/agent/target/uppdatera-agent-1.0-SNAPSHOT-jar-with-dependencies.jar</argLine></configuration></plugin></plugins></build></profile>"
plugins = etree.fromstring(plugins_txt)
plugin = etree.fromstring(plugin_txt)
ns= {"d" : "http://maven.apache.org/POM/4.0.0"}
root = etree.parse(sys.argv[1] + '/pom.xml')
exists = root.xpath('boolean(/d:project/d:profiles)',namespaces=ns)
exists_no_ns = root.xpath('boolean(/project/profiles)')
try:
if exists and not exists_no_ns:
xml_plugins = root.xpath('/d:project/d:profiles',namespaces=ns)
xml_plugins[0].append(plugin)
root.write('pom.xml', pretty_print=True)
elif exists_no_ns and not exists:
xml_plugins = root.xpath('/project/profiles')
xml_plugins[0].append(plugin)
root.write('pom.xml', pretty_print=True)
else:
xml_plugins = root.xpath('/d:project',namespaces=ns)
xml_non = root.xpath('/project')
if len(xml_plugins) > 0:
xml_plugins[0].append(plugins)
root.write(sys.argv[1] +'/pom.xml', pretty_print=True)
else:
xml_non[0].append(plugins)
root.write(sys.argv[1] +'/pom.xml', pretty_print=True)
except:
print os.getcwd() + '/pom.xml'
import sys, os
from lxml import etree
plugins_txt = "<profiles><profile><id>uppdatera-cgminter</id><properties><maven.test.skip>false</maven.test.skip></properties><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><configuration><argLine>${uppdatera.agent}</argLine></configuration></plugin></plugins></build></profile></profiles>"
plugin_txt = "<profile><id>uppdatera-cgminter</id><properties><maven.test.skip>false</maven.test.skip></properties><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><configuration><argLine>${uppdatera.agent}</argLine></configuration></plugin></plugins></build></profile>"
plugins = etree.fromstring(plugins_txt)
plugin = etree.fromstring(plugin_txt)
ns= {"d" : "http://maven.apache.org/POM/4.0.0"}
root = etree.parse(sys.argv[1] + '/pom.xml')
exists = root.xpath('boolean(/d:project/d:profiles)',namespaces=ns)
exists_no_ns = root.xpath('boolean(/project/profiles)')
try:
if exists and not exists_no_ns:
xml_plugins = root.xpath('/d:project/d:profiles',namespaces=ns)
xml_plugins[0].append(plugin)
root.write('pom.xml', pretty_print=True)
elif exists_no_ns and not exists:
xml_plugins = root.xpath('/project/profiles')
xml_plugins[0].append(plugin)
root.write('pom.xml', pretty_print=True)
else:
xml_plugins = root.xpath('/d:project',namespaces=ns)
xml_non = root.xpath('/project')
if len(xml_plugins) > 0:
xml_plugins[0].append(plugins)
root.write(sys.argv[1] +'/pom.xml', pretty_print=True)
else:
xml_non[0].append(plugins)
root.write(sys.argv[1] +'/pom.xml', pretty_print=True)
except:
print os.getcwd() + '/pom.xml'
#!/bin/bash
IFS=$'\n' read -d '' -r -a rows < /data/uppdatera/scripts/searchlist.txt
readarray -t FILES < <(find /data/uppdatera/github/repos -name ast-calls-resolved.txt);
for i in "${FILES[@]}"
do
for j in "${rows[@]}"
do
echo "grep -wq \"$j\" $i; [[ \$? -eq 0 ]] && echo $i"
done
done
#!/bin/bash
find /data/uppdatera/github/repos/ -name pom.xml -printf '%h\n' |
parallel 'agent="-javaagent:/data/uppdatera/scripts/dyncg/target/javacg-0.1-SNAPSHOT-dycg-agent.jar=\"";first=$(python -c "import sys;sys.stdout.write(\"incl=\")"); second=$(java -Xms2G -Xmx3G -jar /data/uppdatera/scripts/extract_depz/target/uppdatera-0.0.1-SNAPSHOT-jar-with-dependencies.jar {}/pom.xml);last=$(python -c "import sys;sys.stdout.write(\";excl=org.junit.*,org.apache.maven.plugins.*\" + \"\x22\")"); echo "$agent$first$second$last" > {}/dyn-agent.conf'
## Remove ones without dependencies
grep -Ril --include=\dyn-agent.conf "incl=;" . | parallel 'rm {}'

These have some custom xmlns schema so we have to manually add the javaagent

/data/uppdatera/github/repos/twitter/netty-http2/pom.xml
/data/uppdatera/github/repos/apache/cayenne/pom.xml
/data/uppdatera/github/repos/twitter/joauth/pom.xml
/data/uppdatera/github/repos/apache/cayenne/build-tools/cayenne-legal/pom.xml
/data/uppdatera/github/repos/twitter/distributedlog/distributedlog-protocol/pom.xml
/data/uppdatera/github/repos/twitter/nodes/pom.xml
/data/uppdatera/github/repos/psi-probe/psi-probe/pom.xml
/data/uppdatera/github/repos/apache/cayenne/build-tools/cayenne-test-utilities/pom.xml
/data/uppdatera/github/repos/twitter/GraphJet/graphjet-core/pom.xml
## Create a folder to store results
mkdir -p eval/$DEPNAME
## Add functions that belongs to $DEPNAME in this list
vi /data/uppdatera/scripts/searchlist.txt
## Build a list of modules calling a function
./locate_modules.sh | parallel > ../eval/$DEPNAME/modules.txt
## Remove filename
sed -i 's/\/ast\-calls\-resolved\.txt//g' ../eval/$DEPNAME/modules.txt
## Normal run to verify state without plugin
cat ../eval/$DEPNAME/modules.txt | parallel 'cd {}; cmd="mvn test -Dmaven.test.skip=false"; $cmd &> testlog-normal-uppdatera.out; [[ $? -eq 0 ]] && echo {}' > /data/uppdatera/eval/$DEPNAME/test-success-normal.txt
## Get info about test results (any flaky tests?)
diff <(sort /data/uppdatera/eval/alibaba/test-success-normal.txt) <(sort /data/uppdatera/eval/alibaba/modules.txt)
## Run with agent for trivial case
time cat ../eval/$DEPNAME/test-success-normal.txt| parallel 'cd {}; cmd="mvn test -Puppdatera -Dmaven.test.skip=false -X"; $cmd &> testlog-trivial-uppdatera.out; [[ $? -eq 0 ]] && echo {}' > /data/uppdatera/eval/$DEPNAME/test-success-trivial.txt
## Maven modules that caught this failure?
diff <(sort /data/uppdatera/eval/alibaba/test-success-trivial.txt) <(sort /data/uppdatera/eval/alibaba/test-success-normal.txt)
## Run with agent for eqvivalent case
time cat ../eval/$DEPNAME/test-success-normal.txt| parallel 'cd {}; cmd="mvn test -Puppdatera -Dmaven.test.skip=false -X"; $cmd &> testlog-eqv-uppdatera.out; [[ $? -eq 0 ]] && echo {}' > /data/uppdatera/eval/$DEPNAME/test-success-eqv.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment