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. | |
a46ade4f FD |
61 | symbol_list = [] |
62 | for symbol in raw_symbol_list: | |
63 | symbol = symbol.split()[2].strip() | |
64 | if 'ftrace' not in symbol: | |
65 | symbol_list.append(symbol) | |
6dffa64f FD |
66 | |
67 | instrumentation_points = [] | |
68 | ||
69 | # Add all symbols. | |
a46ade4f | 70 | instrumentation_points.extend(symbol_list) |
6dffa64f FD |
71 | |
72 | # For each symbol, create 2 new instrumentation points by random offsets. | |
a46ade4f | 73 | for s in symbol_list: |
6dffa64f FD |
74 | offsets = rng.sample(range(1, 10), 2) |
75 | for offset in offsets: | |
76 | instrumentation_points.append(s + "+" + str(hex(offset))) | |
77 | ||
78 | lower_bound = 0x0 | |
79 | upper_bound = 0xffffffffffffffff | |
80 | address_list = [] | |
81 | ||
82 | # Add random addresses to the instrumentation points. | |
83 | for _ in range(1000): | |
84 | instrumentation_points.append(hex(rng.randint(lower_bound, upper_bound))) | |
85 | ||
86 | # Shuffle the entire list. | |
87 | rng.shuffle(instrumentation_points) | |
88 | ||
89 | # Save instrumentation points to disk and attach it to lava test run. | |
90 | save_instr_points(instrumentation_points) | |
91 | ||
92 | if __name__ == "__main__": | |
93 | main() |