Commit | Line | Data |
---|---|---|
6dffa64f FD |
1 | # Copyright (C) 2018 - Francis Deslauriers <francis.deslauriers@efficios.com> |
2 | # | |
3 | # This program is free software: you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation, either version 3 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | import datetime | |
17 | import gzip | |
18 | import os | |
19 | import pprint | |
20 | import random | |
21 | import subprocess | |
22 | import sys | |
23 | ||
24 | def save_instr_points(instr_points): | |
25 | ||
26 | # Save in /root to be persistent across lava slave reboots. | |
27 | instrumenation_points_arch = '/root/instr_points.txt.gz' | |
28 | ||
29 | print('Saving instrumentation points to \'{}\' ...'.format(instrumenation_points_arch), end='') | |
30 | sys.stdout.flush() | |
31 | ||
32 | text = "\n".join(instr_points) | |
33 | ||
34 | with gzip.open(instrumenation_points_arch, 'w') as f: | |
35 | f.write(text.encode('utf-8')) | |
36 | ||
37 | # Attach fuzzing data to test case. | |
38 | events = ['lava-test-case-attach', 'generate-fuzzing-data', instrumenation_points_arch] | |
39 | ||
40 | try: | |
41 | subprocess.call(events) | |
42 | except OSError as e: | |
43 | print("Execution failed:", e, file=sys.stderr) | |
44 | print("Probably not running on the lava worker") | |
45 | pprint.pprint(events) | |
46 | print('Done.') | |
47 | ||
48 | def main(): | |
49 | assert(len(sys.argv) == 2) | |
50 | ||
51 | seed = int(sys.argv[1]) | |
52 | print('Random seed: {}'.format(seed)) | |
53 | ||
54 | rng = random.Random(seed) | |
55 | ||
56 | # Get all the symbols from kallsyms. | |
57 | with open('/proc/kallsyms') as kallsyms_file: | |
58 | raw_symbol_list = kallsyms_file.readlines() | |
59 | ||
60 | # Keep only the symbol name. | |
61 | raw_symbol_list = [x.split()[2].strip() for x in raw_symbol_list] | |
62 | ||
63 | instrumentation_points = [] | |
64 | ||
65 | # Add all symbols. | |
66 | instrumentation_points.extend(raw_symbol_list) | |
67 | ||
68 | # For each symbol, create 2 new instrumentation points by random offsets. | |
69 | for s in raw_symbol_list: | |
70 | offsets = rng.sample(range(1, 10), 2) | |
71 | for offset in offsets: | |
72 | instrumentation_points.append(s + "+" + str(hex(offset))) | |
73 | ||
74 | lower_bound = 0x0 | |
75 | upper_bound = 0xffffffffffffffff | |
76 | address_list = [] | |
77 | ||
78 | # Add random addresses to the instrumentation points. | |
79 | for _ in range(1000): | |
80 | instrumentation_points.append(hex(rng.randint(lower_bound, upper_bound))) | |
81 | ||
82 | # Shuffle the entire list. | |
83 | rng.shuffle(instrumentation_points) | |
84 | ||
85 | # Save instrumentation points to disk and attach it to lava test run. | |
86 | save_instr_points(instrumentation_points) | |
87 | ||
88 | if __name__ == "__main__": | |
89 | main() |