Skip to content

Commit 4237f60

Browse files
Wontae ChoiWontae Choi
Wontae Choi
authored and
Wontae Choi
committed
front-end script added
1 parent 4aba655 commit 4237f60

File tree

10 files changed

+175
-131
lines changed

10 files changed

+175
-131
lines changed

README.md

+92-51
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,81 @@ learn a model of the target app during testing, uses the learned model to genera
55
unexplored states of the app, and uses the execution of the app on the generated inputs to refine
66
the model.
77

8-
The main purpose of the repository is to provide working demo of the latest version of the
9-
*SwiftHand*. The repository provides ready-instrumented benchmakrs and back-end(testing engine) binary.
10-
Also source code for both front-end(instrumentation) and back-end is available. Currently, maven build
11-
script for the back-end is available. A script for the front-end will be added soon.
8+
The main purpose of the repository is to provide working demo of the version of the
9+
*SwiftHand* tool submited to OOPSLA'13 conference.
10+
The repository provides ready-instrumented benchmakrs and back-end(testing engine) binary.
11+
Also source code for both front-end (instrumentation) and back-end is available.
1212

1313

14+
INSTALLATION
15+
============
1416

15-
How to Use Compiled Back-End
16-
============================
17+
#### Step 1. Install Android Development Kit (ADK)
1718

18-
#### Step 1. Install Android SDK (ADK)
19-
Download from http://developer.android.com/sdk/index.html. We recomment to use SDK 4.1.2 or higher version. After install ADK, please make sure that you have following five files.
19+
Before playing with SwiftHand, please make sure to install the Android SDK (ADK).
20+
You can download it from http://developer.android.com/sdk/index.html.
21+
We recommend to use ADK then 4.1.2 or higher.
22+
After installing ADK, please make sure that you have following six files.
2023

2124
- ADK_ROOT/platform-tools/adb
2225
- ADK_ROOT/tools/lib/ddms.jar
2326
- ADK_ROOT/tools/lib/ddmlib.jar
2427
- ADK_ROOT/tools/lib/chimpchat.jar
25-
- ADK_ROOT/tools/lib/guava-13.0.1.jar
28+
- ADK_ROOT/tools/lib/guava-17.0.jar (version may vary)
29+
- ADK_ROOT/build-tools/21.0.3/lib/dx.jar (version may vary)
2630

31+
Please memo your guava.jar version (17.0 in the example), your build-tools version (21.0.3 in the example),
32+
and the path to the ADK root directory. We will need this information later.
2733

34+
#### Step 2. Install JDK 7
2835

29-
#### Step 2. Create Emulator
36+
The SwiftHand implementation works with JDK version 6 and 7, and we recommend to use JDK version 7.
37+
Please check the path to the JDK root directory. We will need this information later.
38+
39+
40+
#### Step 3. Install Maven.
41+
Maven (http://maven.apache.org) is a project management and comprehension tool.
42+
Any recent version of Maven 3 will work.
43+
44+
45+
#### Step 4. Clone the SwiftHand repository.
46+
Now, it is a time to start the real job.
47+
48+
49+
#### Step 5. Editing the build script.
50+
Open *build.sh.skeleton*, a skeleton of the main build script.
51+
You will find out following four commented lines.
52+
Assign an appropriate values to variable and uncomment it.
53+
54+
```
55+
#export ADK_ROOT=""
56+
#export JAVA_HOME=""
57+
#export GUAVA_VERSION=""
58+
#export DX_VERSION=""
59+
```
60+
61+
Once the editing is done, typing the following commands:
62+
```
63+
cp build.sh.skeleton build.sh
64+
chmod 700 build.sh
65+
```
66+
67+
#### Step 6. Build.
68+
69+
Now is the time to do the actual build!
70+
```
71+
./build.sh
72+
```
73+
74+
If the build process was succesful,
75+
you will see two new files in the directory:
76+
*inst.sh* and *test.sh*. Voila!
77+
78+
79+
Using the Back-End
80+
====================
81+
82+
#### Step 1. Create an Emulator
3083
Do following steps to create Android Vritual Device. The steps will create emulator image.
3184

3285
1. Luanch SDK Manager (ADK_ROOT/tools/android)
@@ -38,66 +91,54 @@ You can find the official guideline about emulator management:
3891
'http://developer.android.com/tools/devices/managing-avds.html'.
3992

4093

41-
#### Step 3. Start Emulator
94+
#### Step 2. Start an Emulator
4295
We recommand following command to setup necessary environment variable:
4396
```
4497
<ADK_ROOT>/tools/emulator -avd <AVD_NAME> -wipe-data -dns-server 127.0.0.1
4598
```
4699
-wipe-data options it to start emulator from the factory-reset state -dns-server 127.0.0.1 option is a trick to disabling internet access. <AVD_NAME> refer the name of AVD created by step 2.
47100

48101

49-
#### Step 4. Download SiwftHand Tool and benchmark programs.
50-
You can download it from /dist directory of this repository.
51-
52-
53-
#### Step 5. Set environment variables. Following command will do the work.
54-
```
55-
export ADK_ROOT=<ADK_ROOT>
56-
export ADK_LIB="$ADK_ROOT/tools/lib"
57-
export CLASSPATH="$ADK_LIB/ddml.jar:$ADK_LIB/ddmlib.jar:$ADK_LIB/chimpchat.jar:$ADK_LIB/guava-13.0.1.jar:<SWIFTHAND_DIR>/SwiftHand.jar:$CLASSPATH"
58-
```
59-
60-
#### Step 6. Execute Tool
61-
The tool can be executed using following command..
62-
```
63-
java edu.berkeley.wtchoi.swift.CommandLine
64-
```
102+
#### Step 3. Execute the Back-End
103+
The tool can be executed using the test.sh script generaated by the build scipt.
65104
For example, to test mininote using SwiftHand with random seed 0 for 1 hour:
66105
```
67-
java edu.berkeley.wtchoi.swift.CommandLine benchmark/mininote.modified.apk swift 3600 0 <OUTPUT_DIR>
106+
./test.sh dist/benchmark/mininote.modified.apk swift 3600 0 <OUTPUT_DIR>
68107
```
69108

109+
Please replace <OUTPUT_DIR> to the output directory you want.
110+
You can try any programs in the benchmark directory by replacing 'mininote.modified.apk' to an appropriate value.
70111

71-
How to Compile and Run
72-
======================
73-
#### Step 1. Install Maven.
74-
Maven (http://maven.apache.org) is a project management and comprehension tool.
75112

76113

77-
#### Step 2. Set up environment variables.
78-
Build script requires *ADK_ROOT* environemtn variable. Set the variable to the path of your
79-
installed Android SDK.
114+
Execute the Front-End
115+
=====================
80116

81-
#### Step 3. Build
82-
Type following command to compile the project
83-
```
84-
cd src
85-
mvn package
86-
```
87-
If build process is succesfull, you will find following files:
88-
```
89-
back-end/target/back-end-0.1-jar-with-dependencies.jar
90-
```
117+
#### Step 1. Instrument an Application
91118

92-
#### Step 4. Execute Tool
93-
With compiled jar, executing the testing tool is much simpler.
119+
With a compiled front-end, you can instrument an apk file using the inst.sh script generated by the build script.
94120
```
95-
java -jar back-end-0.1-jar-with-dependencies.jar benchmark/mininote.modified.apk swift 3600 0 <OUTPUT_DIR>
121+
./inst.sh <TARGET.apk>
96122
```
97-
We assume that a running emulator (or phone) is connected to ADB. If not, please create and boot
98-
an emulator before start testing.
99123

124+
Please make sure to replace <TARGET.apk> with the path of the target apk file. You can find two example target files located in *dist/unmofidied* directory.
125+
If the instrumentation process success, the front-end generates several files including the following two files,
126+
in the direcory containing the source apk file.
127+
128+
- TARGET.modified.apk
129+
- TARGET.json
130+
131+
If you have these two files, you are ready to play with the back-end. Please make sure to have these two files in the same directory.
132+
133+
Acknowledgements
134+
================
135+
- The front-end only works with ASMDEX library revision 1665 or an older version.
136+
- The front-end only compiles with Scala compiler 2.9.1.
137+
- The back-end only works correctly with an applicatio using a "real" screen resolution.
100138

101-
102139

140+
License
141+
=======
142+
The SwiftHand tool follows BSD licnese.
143+
Please check the License.txt file for more details.
103144

build.sh.skeleton

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/sh
2+
3+
# WARNING: Please assign proper contents and uncomment following four export statements.
4+
#export ADK_ROOT=
5+
#export JAVA_HOME=
6+
#export GUAVA_VERSION=
7+
#export DX_VERSION=
8+
9+
DOLLAR="\$"
10+
declare -a arr=("ADK_ROOT" "JAVA_HOME" "GUAVA_VERSION" "DX_VERSION")
11+
for varname in "${arr[@]}"
12+
do
13+
eval VAR="$DOLLAR$varname"
14+
if [[ -z "$VAR" ]]; then
15+
echo "[build.sh] ERROR: \$$varname unset!"
16+
exit 1;
17+
fi
18+
done
19+
20+
IS="inst.sh"
21+
TS="test.sh"
22+
23+
cd src && mvn package
24+
if (($? > 0)); then
25+
print "[build.sh] Maven build script failed"
26+
exit 2;
27+
fi
28+
29+
SWIFT_ROOT=$PWD
30+
31+
#create execution script
32+
FRONT_END_PATH="src/front-end/target/front-end-0.1-jar-with-dependencies.jar"
33+
KEY_PATH="src/front_end/resource/swifthand.keystore"
34+
SHARED_PATH="src/shared/target/shared-0.1.jar"
35+
36+
BACK_END_PATH="src/back-end/target/back-end-0.1-jar-with-dependencies.jar"
37+
38+
echo "[build.sh] Generating inst.sh instrumentation script"
39+
40+
echo "#!/bin/sh" > $IS
41+
echo "set -x" >> $IS
42+
echo "export ADK_ROOT=$ADK_ROOT" >> $IS
43+
echo "java -jar $SWIFT_ROOT/$FRONT_END_PATH \$1 $SWIFT_ROOT/$KEY_PATH $SWIFT_ROOT/$SHARED_PATH" >> $IS
44+
chmod 700 $IS
45+
46+
echo "[build.sh] Generating test.sh GUI testing script"
47+
48+
echo "#!/bin/sh" > $TS
49+
echo "set -x" >> $TS
50+
echo "export ADK_ROOT=$ADK_ROOT" >> $TS
51+
echo "java -jar $SWIFT_ROOT/$BACK_END_PATH \${*:1}" >> $TS
52+
chmod 700 $TS

dist/unmodified/mileage.apk

372 KB
Binary file not shown.

dist/unmodified/mininote.apk

164 KB
Binary file not shown.

src/back-end/pom.xml

+3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
<artifactId>swifthand</artifactId>
99
<version>0.1</version>
1010
</parent>
11+
12+
<groupId>edu.berkeley.wtchoi.swift</groupId>
1113
<artifactId>back-end</artifactId>
14+
<version>0.1</version>
1215
<packaging>jar</packaging>
1316
<name>SiwftHand Backend : TestGuide</name>
1417
<build>

src/front-end/pom.xml

+11-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
<version>0.1</version>
1010
</parent>
1111
<artifactId>front-end</artifactId>
12+
<version>0.1</version>
1213
<packaging>jar</packaging>
1314
<name>SiwftHand Frontend : Instrument</name>
14-
15+
16+
1517
<build>
1618
<plugins>
1719
<plugin>
@@ -104,7 +106,14 @@
104106
<version>local</version>
105107
<scope>system</scope>
106108
<systemPath>
107-
${env.ADK_ROOT}/build-tools/21.0.0/lib/dx.jar</systemPath>
109+
${env.ADK_ROOT}/build-tools/21.1.2/lib/dx.jar</systemPath>
110+
</dependency>
111+
<dependency>
112+
<groupId>com.sun</groupId>
113+
<artifactId>tools</artifactId>
114+
<version>local</version>
115+
<scope>system</scope>
116+
<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
108117
</dependency>
109118
</dependencies>
110119
</project>
2.2 KB
Binary file not shown.

src/front-end/src/main/java/edu/berkeley/wtchoi/instrument/CommandLine.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ public static void main(String args[]){
4242
String keystoreFileName = args[1];
4343
String libJarFileName = args[2];
4444
Instrument.Mode mode = Instrument.Mode.FullSilent;
45-
Instrument.run(inputApk, libJarFileName, keystoreFileName, mode, false);
45+
Instrument.run(inputApk, keystoreFileName, libJarFileName, mode, false);
4646
}
4747
catch (Exception e){
48+
e.printStackTrace();
4849
String message =
4950
"Usage\n" +
5051
"-----\n" +

0 commit comments

Comments
 (0)