Skip to content

Commit b5bafb2

Browse files
author
the-themis-benchmarks
committed
adapt TimeMachine for Themis
1 parent ce7b091 commit b5bafb2

24 files changed

+441
-85
lines changed

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ MAINTAINER [email protected]
77
WORKDIR /root
88
ENV DEBIAN_FRONTEND noninteractive
99

10-
RUN apt-get update && apt-get install -y linux-headers-$(uname -r) virtualbox-dkms virtualbox virtualbox-qt python-pip openjdk-8-jdk git-core \
11-
&& pip install pyvbox enum vbox-sdk uiautomator
10+
RUN apt-get update && apt-get install -y linux-headers-$(uname -r) virtualbox-dkms virtualbox virtualbox-qt python-pip python3-pip openjdk-8-jdk git-core \
11+
&& pip install pyvbox enum vbox-sdk uiautomator \
12+
# uiautomator2's recent versions (v.2.10.1 - v2.9.6) failed; 2.4.3 at least works. The main issue is related to the version of atx-agent
13+
&& pip3 install -U uiautomator2==2.4.3
1214

1315

1416
#super important: setting enviroment variables

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,53 @@ cat duolingo_output/timemachine-output/crashes.log
105105
* Abhik Roychoudhury
106106

107107

108+
# Some useful commands to debug TimeMachine
109+
110+
1. view the GUI
111+
112+
Set up the $HOME/.Xauthority (on my desktop, Ubuntu-18.04), see this [link](https://askubuntu.com/questions/21923/how-do-i-create-the-xauthority-file)
113+
```
114+
ln -s -f $Xauthority $HOME/.Xauthority
115+
```
116+
117+
2. start the docker with GUI forwarding enabled
118+
119+
```
120+
docker run -it --privileged -e DISPLAY=$DISPLAY --net=host -v $HOME/.Xauthority:/root/.Xauthority:rw -v /dev:/dev droidtest/timemachine:1.0
121+
```
122+
123+
3. create, start, and power off the Android VM inside the docker
124+
```
125+
./setup_vm.bash Android7_1 5554
126+
127+
VBoxManage startvm Android7_1
128+
129+
VBoxManage controlvm Android7_1 poweroff
130+
131+
rm -rf /root/VirtualBox\ VMs/Android7_1/
132+
```
133+
134+
I tried to resize the VM screen size. But it does not take effect. See this [link](https://superuser.com/questions/31669/change-resolution-from-command-line-in-virtual-box)
135+
```
136+
VBoxManage controlvm "Android7_1" setvideomodehint 1024 600 32
137+
```
138+
139+
Show without GUI:
140+
```
141+
VBoxManage startvm Android7_1 --type headless
142+
```
143+
144+
4. connect to the Android VM
145+
```
146+
adb disconnect 127.0.0.1:5554
147+
148+
adb connect 127.0.0.1:5554
149+
```
150+
151+
5. Test uiautomator2 against Android VM (uiautomator2 v2.4.3 works)
152+
153+
```
154+
pip3 install -U uiautomator2==2.4.3
155+
156+
python3 -m uiautomator2 init
157+
```

fuzzingandroid/FuzzerEngine/fuzzerengine/config_fuzzer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class RunParameters:
1313

1414
OUTPUT_FILE = "pareto0.log"
1515
CRASH_FILE = "pareto0.crash"
16-
OPEN_SOURCE = False
16+
RUN_TIME_FILE = "run_time.log"
17+
OPEN_SOURCE = True
1718

1819

fuzzingandroid/FuzzerEngine/fuzzerengine/coverage_manager.py

Lines changed: 88 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import time
66
import threading
77
import re
8-
from config_fuzzer import RunParameters
8+
from xml.dom import minidom
9+
from xml.parsers.expat import ExpatError
10+
from config_fuzzer import RunParameters
911

1012
def get_emma_coverage(restore_count):
1113
# adb shell am broadcast -a edu.gatech.m3.emma.COLLECT_COVERAGE
@@ -15,51 +17,41 @@ def get_emma_coverage(restore_count):
1517
output, err = cmd.communicate()
1618
print 'get_emma_coverage- return code: ' + ' output: ' + str(output) + ' ' + str(err) +' '
1719

20+
def get_jacoco_coverage(restore_count, app_package_name, app_class_files_path, avd_serial):
21+
# adb shell am broadcast -a edu.gatech.m3.emma.COLLECT_COVERAGE
22+
cov_file_name = 'coverage' + str(restore_count)
23+
24+
cmd = subprocess.Popen(['../../scripts/pull_coverage_jacoco.sh', cov_file_name, app_package_name, app_class_files_path, avd_serial],
25+
stdout = subprocess.PIPE, stderr = subprocess.PIPE)
26+
output, err = cmd.communicate()
27+
print 'get_jacoco_coverage- return code: ' + ' output: ' + str(output) + ' ' + str(err) +' '
28+
1829
def get_ella_coverage(restore_count):
1930
cov_file_name = 'coverage' + str(restore_count)
20-
21-
31+
32+
2233
cmd = subprocess.Popen (['../../scripts/pull_coverage_ella.sh', cov_file_name],stdout = subprocess.PIPE, stderr = subprocess.PIPE)
2334
output, err = cmd.communicate()
24-
print 'get_ella_coverage: return msg: error: ' + str(output) + ' ' + str(err)
35+
print 'get_ella_coverage: return msg: error: ' + str(output) + ' ' + str(err)
2536

2637
def compute_coverage():
2738
#using compute_coverage to compute
2839
cmd = subprocess.Popen ('../../scripts/compute_coverage.sh',stdout = subprocess.PIPE, stderr = subprocess.PIPE)
2940
output, err=cmd.communicate()
3041
print 'compute_coverage-return code: ' + ' output: '+str(output) + ' ' + str(err) +' '
3142

32-
def compute_coverage_ella():
43+
def compute_coverage_jacoco(app_class_files_path):
3344
#using compute_coverage to compute
34-
35-
cmd = subprocess.Popen ('../../scripts/compute_coverage_ella.sh',stdout = subprocess.PIPE, stderr = subprocess.PIPE)
45+
cmd = subprocess.Popen (['../../scripts/compute_coverage_jacoco.sh', app_class_files_path],stdout = subprocess.PIPE, stderr = subprocess.PIPE)
3646
output, err=cmd.communicate()
3747
print 'compute_coverage-return code: ' + ' output: '+str(output) + ' ' + str(err) +' '
3848

39-
def read_coverage_ella():
40-
if not os.path.isfile ('../../output/ella_files/cov'):
41-
return 0
42-
f= open ('../../output/ella_files/cov', 'r')
43-
lines = f.readlines()
44-
f.close()
45-
46-
return int(lines[0])
49+
def compute_coverage_ella():
50+
#using compute_coverage to compute
4751

48-
def read_current_coverage():
49-
if RunParameters.OPEN_SOURCE:
50-
return read_coverage()
51-
else:
52-
return read_coverage_ella()
53-
def compute_current_coverage():
54-
if RunParameters.OPEN_SOURCE:
55-
compute_coverage()
56-
else:
57-
compute_coverage_ella()
58-
def pull_coverage_files(restore_count):
59-
if RunParameters.OPEN_SOURCE:
60-
get_emma_coverage(restore_count)
61-
else:
62-
get_ella_coverage(restore_count)
52+
cmd = subprocess.Popen ('../../scripts/compute_coverage_ella.sh',stdout = subprocess.PIPE, stderr = subprocess.PIPE)
53+
output, err=cmd.communicate()
54+
print 'compute_coverage-return code: ' + ' output: '+str(output) + ' ' + str(err) +' '
6355

6456
def read_coverage():
6557
if not os.path.isfile('../../output/coverage.txt'):
@@ -82,6 +74,64 @@ def read_coverage():
8274

8375
return int(s.replace("%", ""))
8476

77+
def read_coverage_jacoco():
78+
if not os.path.isfile('../../output/coverage.xml'):
79+
return 0
80+
81+
try:
82+
# see the format of coverage report generated by Jacoco in xml
83+
xmldoc = minidom.parse('../../output/coverage.xml')
84+
counters = xmldoc.getElementsByTagName('counter')
85+
line_coverage = 0
86+
for counter in counters:
87+
type_name = counter.getAttribute('type')
88+
if type_name == 'LINE':
89+
missed_lines = int(counter.getAttribute('missed'))
90+
covered_lines = int(counter.getAttribute('covered'))
91+
line_coverage = covered_lines * 100.0 / (missed_lines + covered_lines)
92+
93+
if line_coverage == 0:
94+
return 0
95+
else:
96+
print "-----------"
97+
print "current jacoco line coverage: " + str(line_coverage)
98+
print "-----------"
99+
return line_coverage
100+
except ExpatError:
101+
print "parse xml error, catch it!"
102+
return 0
103+
104+
def read_coverage_ella():
105+
if not os.path.isfile ('../../output/ella_files/cov'):
106+
return 0
107+
f= open ('../../output/ella_files/cov', 'r')
108+
lines = f.readlines()
109+
f.close()
110+
print "[tingsu] current ella method coverage: " + str(lines[0])
111+
112+
return int(lines[0])
113+
114+
def read_current_coverage():
115+
if RunParameters.OPEN_SOURCE:
116+
# return read_coverage()
117+
return read_coverage_jacoco()
118+
else:
119+
return read_coverage_ella()
120+
121+
def compute_current_coverage(app_class_files_path):
122+
if RunParameters.OPEN_SOURCE:
123+
# compute_coverage()
124+
compute_coverage_jacoco(app_class_files_path)
125+
else:
126+
compute_coverage_ella()
127+
128+
def pull_coverage_files(restore_count, app_package_name, app_class_files_path, avd_serial):
129+
if RunParameters.OPEN_SOURCE:
130+
# get_emma_coverage(restore_count)
131+
get_jacoco_coverage(restore_count, app_package_name, app_class_files_path, avd_serial)
132+
else:
133+
get_ella_coverage(restore_count)
134+
85135
def record_coverage():
86136
start_time = time.time()
87137
file_path='../../output/coverage_time.csv'
@@ -92,10 +142,13 @@ def record_coverage():
92142
while True:
93143
with open(file_path, 'a') as coverage_file:
94144
t = time.time() - start_time
95-
96-
compute_coverage()
97-
coverage = read_coverage()
98-
145+
146+
# compute_coverage()
147+
# coverage = read_coverage()
148+
# TODO, record_coverage() is not used in the project, so it is okay for now without giving proper parameters.
149+
compute_coverage_jacoco()
150+
coverage = read_coverage_jacoco()
151+
99152
line = str(round(t,1)) + "," + str(coverage) + "\n"
100153
coverage_file.writelines(line)
101154
coverage_file.flush()
@@ -114,3 +167,4 @@ def record_coverage():
114167
compute_coverage_ella()
115168
tp=read_coverage_ella()
116169
print str(tp)
170+

0 commit comments

Comments
 (0)