|
39 | 39 |
|
40 | 40 | def _iter_weights( |
41 | 41 | fuzzer_jobs: Sequence[data_types.FuzzerJob]) -> Sequence[float]: |
42 | | - for fj in fuzzer_jobs: |
43 | | - yield fj.actual_weight |
| 42 | + for fuzzer_job in fuzzer_jobs: |
| 43 | + yield fuzzer_job.actual_weight |
44 | 44 |
|
45 | 45 |
|
46 | 46 | def _sum_weights(fuzzer_jobs: Sequence[data_types.FuzzerJob]) -> float: |
@@ -123,7 +123,8 @@ def _display_fuzzer_jobs(fuzzer_jobs: Sequence[data_types.FuzzerJob], |
123 | 123 | printer = _print_with_prefix(prefix) |
124 | 124 |
|
125 | 125 | fuzzer_jobs = list(fuzzer_jobs) |
126 | | - fuzzer_jobs.sort(key=lambda fj: fj.actual_weight, reverse=True) |
| 126 | + fuzzer_jobs.sort( |
| 127 | + key=lambda fuzzer_job: fuzzer_job.actual_weight, reverse=True) |
127 | 128 |
|
128 | 129 | total_weight = _sum_weights(fuzzer_jobs) |
129 | 130 |
|
@@ -316,6 +317,45 @@ def _aggregate_fuzzer_jobs( |
316 | 317 | _print_stats(others, total_weight) |
317 | 318 |
|
318 | 319 |
|
| 320 | +def _set_fuzzer_job_weight( |
| 321 | + fuzzer: str, |
| 322 | + job: str, |
| 323 | + weight: float, |
| 324 | +) -> None: |
| 325 | + """Sets the matching FuzzerJob's weight to the given value.""" |
| 326 | + fuzzer_jobs = list( |
| 327 | + data_types.FuzzerJob.query(data_types.FuzzerJob.fuzzer == fuzzer, |
| 328 | + data_types.FuzzerJob.job == job)) |
| 329 | + |
| 330 | + if not fuzzer_jobs: |
| 331 | + print('No matching FuzzerJob entries found for ' + |
| 332 | + f'fuzzer {fuzzer} and job {job}') |
| 333 | + return |
| 334 | + |
| 335 | + if len(fuzzer_jobs) > 1: |
| 336 | + print('Bailing out! Multiple FuzzerJob entries found for ' + |
| 337 | + f'fuzzer {fuzzer} and job {job}: {fuzzer_jobs}') |
| 338 | + return |
| 339 | + |
| 340 | + fuzzer_job = fuzzer_jobs[0] |
| 341 | + |
| 342 | + print(f'Fuzzer: {fuzzer_job.fuzzer}') |
| 343 | + print(f'Job: {fuzzer_job.job}') |
| 344 | + print(f'Platform: {fuzzer_job.platform}') |
| 345 | + print(f'Multiplier: {fuzzer_job.multiplier}') |
| 346 | + print(f'Old weight: {fuzzer_job.weight}') |
| 347 | + print(f'-> New weight: {weight}') |
| 348 | + |
| 349 | + answer = input('Do you want to apply this mutation? [y,n] ') |
| 350 | + if answer.lower() != 'y': |
| 351 | + print('Not applying mutation.') |
| 352 | + return |
| 353 | + |
| 354 | + fuzzer_job.weight = weight |
| 355 | + fuzzer_job.put() |
| 356 | + print('Mutation applied.') |
| 357 | + |
| 358 | + |
319 | 359 | def _set_fuzz_target_job_weight( |
320 | 360 | fuzz_target_name: str, |
321 | 361 | job: str, |
@@ -362,6 +402,8 @@ def _execute_fuzzer_command(args) -> None: |
362 | 402 | raise TypeError(f'--format {repr(args.format)} unrecognized') |
363 | 403 | elif cmd == 'aggregate': |
364 | 404 | _aggregate_fuzzer_jobs(args.platform, fuzzers=args.fuzzers, jobs=args.jobs) |
| 405 | + elif cmd == 'set': |
| 406 | + _set_fuzzer_job_weight(args.fuzzer, args.job, args.weight) |
365 | 407 | else: |
366 | 408 | raise TypeError(f'weights fuzzer command {repr(cmd)} unrecognized') |
367 | 409 |
|
|
0 commit comments