Avoid depending on argument reception from the commandline, where possible. Here we take the command line arguments and embed them directly into `main` function. If we cannot find a `main` function, or if we have more than one argument, we do not do any embedding, and the resulting test
(self, code, args)
| 447 | utils.write_file('stats.json', json.dumps(output, indent=2) + '\n') |
| 448 | |
| 449 | def hardcode_arguments(self, code, args): |
| 450 | """Avoid depending on argument reception from the commandline, where possible. |
| 451 | |
| 452 | Here we take the command line arguments and embed them directly into `main` function. |
| 453 | If we cannot find a `main` function, or if we have more than one argument, we |
| 454 | do not do any embedding, and the resulting test will depend on arguments being |
| 455 | passed via argv (which works in most environments). |
| 456 | """ |
| 457 | if not code or 'int main()' in code: |
| 458 | return code |
| 459 | # We only know how to embed a single argument |
| 460 | if len(args) != 1: |
| 461 | return code |
| 462 | main_pattern = 'int main(int argc, char **argv)' |
| 463 | assert main_pattern in code |
| 464 | code = code.replace(main_pattern, 'int benchmark_main(int argc, char **argv)') |
| 465 | code += ''' |
| 466 | int main() { |
| 467 | int newArgc = 2; |
| 468 | char* newArgv[] = { (char*)"./program.exe", (char*)"%s" }; |
| 469 | int ret = benchmark_main(newArgc, newArgv); |
| 470 | return ret; |
| 471 | } |
| 472 | ''' % args[0] |
| 473 | return code |
| 474 | |
| 475 | def do_benchmark(self, name, src, expected_output='FAIL', args=None, |
| 476 | emcc_args=None, native_args=None, shared_args=None, |