blob: fff5473327e76deb8df5ac7d194d9aa15af7def7 [file] [log] [blame]
Stephen Kyle959ffdf2014-11-28 14:27:44 +00001DexFuzz
2=======
3
4DexFuzz is primarily a tool for fuzzing DEX files. Fuzzing is the introduction of
5subtle changes ("mutations") to a file to produce a new test case. These test cases
6can be used to test the various modes of execution available to ART (Interpreter,
Branislav Rankovf559b572016-11-23 11:41:43 +00007Optimizing compiler) to check for bugs in these modes of execution.
Stephen Kyle959ffdf2014-11-28 14:27:44 +00008This is done by differential testing - each test file is executed with each mode of
9execution, and any differences between the resulting outputs may be an indication of
10a bug in one of the modes.
11
12For a wider overview of DexFuzz, see:
13
14http://community.arm.com/groups/android-community/blog/2014/11/26/the-art-of-fuzz-testing
15
16In typical operation, you provide DexFuzz with a set of DEX files that are the "seeds"
17for mutation - e.g. some tests taken from the ART test suite - and point it at an
18ADB-connected Android device, and it will fuzz these seed files, and execute the
19resulting new tests on the Android device.
20
21How to run DexFuzz
22==================
23
Stephen Kyle807f1782015-03-24 17:44:27 +000024DexFuzz can run its test programs on either an ADB-connected device, or a host-build of
25ART locally.
26
27Execution on an ADB-connected device
28------------------------------------
29
301. Build dexfuzz with mmma tools/dexfuzz from within art/.
Stephen Kyle959ffdf2014-11-28 14:27:44 +0000312. Make sure you have an Android device connected via ADB, that is capable of
32 having DEX files pushed to it and executed with the dalvikvm command.
333. Make sure you're in the Android build environment!
34 (That is, . build/envsetup.sh && lunch)
354. Create a new directory, and place some DEX files in here. These are the seed files
36 that are mutated to form new tests.
375. Create a directory on your device that mutated test files can be pushed to and
38 executed in, using dalvikvm. For example, /data/art-test/
396. If you currently have multiple devices connected via ADB, find out the name of
40 your device using "adb devices -l".
417. Run this command:
42
43dexfuzz --inputs=<seeds dir> --execute --repeat=<attempts> \
44 --dump-output <combination of ISA(s) and and backend(s)>
45
46You MUST specify one of the following ISAs:
47 --arm
48 --arm64
49 --x86
50 --x86_64
51 --mips
52 --mips64
53
54And also at least two of the following backends:
55 --interpreter
Stephen Kyle959ffdf2014-11-28 14:27:44 +000056 --optimizing
57
58Note that if you wanted to test both ARM and ARM64 on an ARM64 device, you can use
59--allarm. Also in this case only one backend is needed, if i.e., you wanted to test
Branislav Rankovf559b572016-11-23 11:41:43 +000060ARM Optimizing Backend vs. ARM64 Optimizing Backend.
Stephen Kyle959ffdf2014-11-28 14:27:44 +000061
62Some legal examples:
Branislav Rankovf559b572016-11-23 11:41:43 +000063 --arm --optimizing --interpreter
64 --x86 --optimizing --interpreter
65 --allarm --optimizing
Stephen Kyle959ffdf2014-11-28 14:27:44 +000066
67Add in --device=<device name, e.g. device:generic> if you want to specify a device.
68Add in --execute-dir=<dir on device> if you want to specify an execution directory.
69 (The default is /data/art-test/)
70
Stephen Kyle807f1782015-03-24 17:44:27 +000071Host Execution
72--------------
73
74DexFuzz now supports execution on your host machine.
75Follow steps 1, 3, 4, and 7 as above, but also observe the following:
76 - instead of specifying an ISA, use --host
77 - ANDROID_DATA must be set, pointing to a location where dex2oat will place
78 OAT files after compilation.
79 - Files will always be executed in the same directory where you are executing DexFuzz.
80
81Fuzzer Operation
82----------------
83
Stephen Kyle959ffdf2014-11-28 14:27:44 +000084As the fuzzer works, you'll see output like:
85
86|-----------------------------------------------------------------|
87|Iterations|VerifyFail|MutateFail|Timed Out |Successful|Divergence|
88|-----------------------------------------------------------------|
89| 48 | 37 | 4 | 0 | 6 | 1 |
90
91Iterations - number of attempts we've made to mutate DEX files.
92VerifyFail - the number of mutated files that ended up failing to verify, either
93 on the host, or the target.
94MutateFail - because mutation is a random process, and has attempt thresholds to
95 avoid attempting to mutate a file indefinitely, it is possible that
96 an attempt to mutate a file doesn't actually mutate it. This counts
97 those occurrences.
98Timed Out - mutated files that timed out for one or more backends.
99 Current timeouts are:
Stephen Kyle959ffdf2014-11-28 14:27:44 +0000100 Optimizing - 5 seconds
Aart Bik5618a572017-01-24 10:27:52 -0800101 Interpreter - 30 seconds
Stephen Kyle959ffdf2014-11-28 14:27:44 +0000102 (use --short-timeouts to set all backends to 2 seconds.)
103Successful - mutated files that executed and all backends agreed on the resulting
104 output. NB: if all backends crashed with the same output, this would
105 be considered a success - proper detection of crashes is still to come.
106Divergence - mutated files that executed and some backend disagreed about the
107 resulting output. Divergent programs are run multiple times with a
108 single backend, to check if they diverge from themselves, and these are
109 not included in the count. If multiple architectures are being used
110 (ARM/ARM64), and the divergences align with different architectures,
111 these are also not included in the count.
112
1138. Check report.log for the full report, including input file and RNG seed for each
114 test program. This allows you to recreate a bad program with, e.g.:
115
116dexfuzz --input=<input file> --seed=<seed value>
117
118Check dexfuzz --help for the full list of options.
119
120NOTE: DEX files with unicode strings are not fully supported yet, and DEX files with
121JNI elements are not supported at all currently.
122
123Mutation Likelihoods
124====================
125
126Each bytecode mutation has a chance out of 100% of firing. Following is the listing
127of each mutation's probability. If you wish to easily adjust these values, copy
128these values into a file called likelihoods.txt, and run dexfuzz with
129--likelihoods=likelihoods.txt.
130
131ArithOpChanger 75
132BranchShifter 30
133CmpBiasChanger 30
134ConstantValueChanger 70
135ConversionRepeater 50
136FieldFlagChanger 40
137InstructionDeleter 40
138InstructionDuplicator 80
139InstructionSwapper 80
Sumnima Joshic7c3d852017-06-30 17:10:38 -0700140InvokeChanger 30
Sumnima Joshi91617212017-07-14 11:52:23 -0700141NewArrayLengthChanger 50
Sumnima Joshi9557d052017-07-26 16:31:42 -0700142NewInstanceChanger 10
Stephen Kyle959ffdf2014-11-28 14:27:44 +0000143NewMethodCaller 10
144NonsenseStringPrinter 10
Sumnima Joshiabae6372017-06-22 15:03:02 -0700145OppositeBranchChanger 40
Stephen Kyle959ffdf2014-11-28 14:27:44 +0000146PoolIndexChanger 30
Sumnima Joshiabae6372017-06-22 15:03:02 -0700147RandomBranchChanger 30
Stephen Kyle959ffdf2014-11-28 14:27:44 +0000148RandomInstructionGenerator 30
Sumnima Joshiad708312017-07-25 14:39:35 -0700149RegisterClobber 10
Stephen Kyle959ffdf2014-11-28 14:27:44 +0000150SwitchBranchShifter 30
151TryBlockShifter 40
152ValuePrinter 40
153VRegChanger 60