blob: c4795f2f77da6d35791d3dbbff3629e63c57418b [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,
7Quick compiler, Optimizing compiler) to check for bugs in these modes of execution.
8This 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
241. Build dexfuzz with mmm tools/dexfuzz from within art/.
252. Make sure you have an Android device connected via ADB, that is capable of
26 having DEX files pushed to it and executed with the dalvikvm command.
273. Make sure you're in the Android build environment!
28 (That is, . build/envsetup.sh && lunch)
294. Create a new directory, and place some DEX files in here. These are the seed files
30 that are mutated to form new tests.
315. Create a directory on your device that mutated test files can be pushed to and
32 executed in, using dalvikvm. For example, /data/art-test/
336. If you currently have multiple devices connected via ADB, find out the name of
34 your device using "adb devices -l".
357. Run this command:
36
37dexfuzz --inputs=<seeds dir> --execute --repeat=<attempts> \
38 --dump-output <combination of ISA(s) and and backend(s)>
39
40You MUST specify one of the following ISAs:
41 --arm
42 --arm64
43 --x86
44 --x86_64
45 --mips
46 --mips64
47
48And also at least two of the following backends:
49 --interpreter
50 --quick
51 --optimizing
52
53Note that if you wanted to test both ARM and ARM64 on an ARM64 device, you can use
54--allarm. Also in this case only one backend is needed, if i.e., you wanted to test
55ARM Quick Backend vs. ARM64 Quick Backend.
56
57Some legal examples:
58 --arm --quick --optimizing
59 --x86 --quick --optimizing --interpreter
60 --allarm --quick
61
62Add in --device=<device name, e.g. device:generic> if you want to specify a device.
63Add in --execute-dir=<dir on device> if you want to specify an execution directory.
64 (The default is /data/art-test/)
65
66As the fuzzer works, you'll see output like:
67
68|-----------------------------------------------------------------|
69|Iterations|VerifyFail|MutateFail|Timed Out |Successful|Divergence|
70|-----------------------------------------------------------------|
71| 48 | 37 | 4 | 0 | 6 | 1 |
72
73Iterations - number of attempts we've made to mutate DEX files.
74VerifyFail - the number of mutated files that ended up failing to verify, either
75 on the host, or the target.
76MutateFail - because mutation is a random process, and has attempt thresholds to
77 avoid attempting to mutate a file indefinitely, it is possible that
78 an attempt to mutate a file doesn't actually mutate it. This counts
79 those occurrences.
80Timed Out - mutated files that timed out for one or more backends.
81 Current timeouts are:
82 Quick - 5 seconds
83 Optimizing - 5 seconds
84 Intepreter - 30 seconds
85 (use --short-timeouts to set all backends to 2 seconds.)
86Successful - mutated files that executed and all backends agreed on the resulting
87 output. NB: if all backends crashed with the same output, this would
88 be considered a success - proper detection of crashes is still to come.
89Divergence - mutated files that executed and some backend disagreed about the
90 resulting output. Divergent programs are run multiple times with a
91 single backend, to check if they diverge from themselves, and these are
92 not included in the count. If multiple architectures are being used
93 (ARM/ARM64), and the divergences align with different architectures,
94 these are also not included in the count.
95
968. Check report.log for the full report, including input file and RNG seed for each
97 test program. This allows you to recreate a bad program with, e.g.:
98
99dexfuzz --input=<input file> --seed=<seed value>
100
101Check dexfuzz --help for the full list of options.
102
103NOTE: DEX files with unicode strings are not fully supported yet, and DEX files with
104JNI elements are not supported at all currently.
105
106Mutation Likelihoods
107====================
108
109Each bytecode mutation has a chance out of 100% of firing. Following is the listing
110of each mutation's probability. If you wish to easily adjust these values, copy
111these values into a file called likelihoods.txt, and run dexfuzz with
112--likelihoods=likelihoods.txt.
113
114ArithOpChanger 75
115BranchShifter 30
116CmpBiasChanger 30
117ConstantValueChanger 70
118ConversionRepeater 50
119FieldFlagChanger 40
120InstructionDeleter 40
121InstructionDuplicator 80
122InstructionSwapper 80
123NewMethodCaller 10
124NonsenseStringPrinter 10
125PoolIndexChanger 30
126RandomInstructionGenerator 30
127SwitchBranchShifter 30
128TryBlockShifter 40
129ValuePrinter 40
130VRegChanger 60