1 # Copyright (C) 2018 - Francis Deslauriers <francis.deslauriers@efficios.com>
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.
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.
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/>.
24 def save_instr_points(instr_points
):
26 # Save in /root to be persistent across lava slave reboots.
27 instrumenation_points_arch
= '/root/instr_points.txt.gz'
29 print('Saving instrumentation points to \'{}\' ...'.format(instrumenation_points_arch
), end
='')
32 text
= "\n".join(instr_points
)
34 with gzip
.open(instrumenation_points_arch
, 'w') as f
:
35 f
.write(text
.encode('utf-8'))
37 # Attach fuzzing data to test case.
38 events
= ['lava-test-case-attach', 'generate-fuzzing-data', instrumenation_points_arch
]
41 subprocess
.call(events
)
43 print("Execution failed:", e
, file=sys
.stderr
)
44 print("Probably not running on the lava worker")
49 assert(len(sys
.argv
) == 2)
51 seed
= int(sys
.argv
[1])
52 print('Random seed: {}'.format(seed
))
54 rng
= random
.Random(seed
)
56 # Get all the symbols from kallsyms.
57 with
open('/proc/kallsyms') as kallsyms_file
:
58 raw_symbol_list
= kallsyms_file
.readlines()
60 # Keep only the symbol name.
61 raw_symbol_list
= [x
.split()[2].strip() for x
in raw_symbol_list
]
63 instrumentation_points
= []
66 instrumentation_points
.extend(raw_symbol_list
)
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
)))
75 upper_bound
= 0xffffffffffffffff
78 # Add random addresses to the instrumentation points.
80 instrumentation_points
.append(hex(rng
.randint(lower_bound
, upper_bound
)))
82 # Shuffle the entire list.
83 rng
.shuffle(instrumentation_points
)
85 # Save instrumentation points to disk and attach it to lava test run.
86 save_instr_points(instrumentation_points
)
88 if __name__
== "__main__":