[536] | 1 | #!/usr/bin/python |
---|
| 2 | |
---|
| 3 | import subprocess |
---|
| 4 | import os |
---|
| 5 | import random |
---|
| 6 | |
---|
| 7 | data_dir = 'data' |
---|
| 8 | gen_dir = 'generated' |
---|
| 9 | test_gen_tool_dir = 'LLSCTestGenerator' |
---|
| 10 | |
---|
| 11 | test_gen_binary = 'generate_test' |
---|
| 12 | |
---|
| 13 | log_init_name = 'log_init_' |
---|
| 14 | log_term_name = 'log_term_' |
---|
| 15 | |
---|
| 16 | generated_test = 'test_llsc.c' |
---|
| 17 | main_task = 'test_llsc_main.c' |
---|
| 18 | task_no_tty = 'test_llsc_no_tty.c' |
---|
| 19 | |
---|
| 20 | res_natif = 'res_natif.txt' |
---|
| 21 | |
---|
| 22 | # Parametres des tests |
---|
| 23 | nb_locks = 20 |
---|
| 24 | nb_max_incr = 2000 |
---|
[571] | 25 | nb_procs = 64 |
---|
[536] | 26 | |
---|
| 27 | |
---|
| 28 | os.chdir(os.path.dirname(__file__)) |
---|
| 29 | |
---|
| 30 | scripts_path = os.path.abspath(".") |
---|
| 31 | top_path = os.path.abspath("../") |
---|
| 32 | |
---|
| 33 | topcell_name = "top.cpp" |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | random.seed() |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | def get_x_y(nb_procs): |
---|
| 40 | x = 1 |
---|
| 41 | y = 1 |
---|
| 42 | to_x = True |
---|
| 43 | while (x * y * 4 < nb_procs): |
---|
| 44 | if to_x: |
---|
| 45 | x = x * 2 |
---|
| 46 | else: |
---|
| 47 | y = y * 2 |
---|
| 48 | to_x = not to_x |
---|
| 49 | return x, y |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | print "make -C", test_gen_tool_dir |
---|
| 53 | subprocess.call([ 'make', '-C', test_gen_tool_dir ]) |
---|
| 54 | |
---|
| 55 | print "cp", os.path.join(test_gen_tool_dir, test_gen_binary), os.path.join(scripts_path, test_gen_binary) |
---|
| 56 | subprocess.call([ 'cp', os.path.join(test_gen_tool_dir, test_gen_binary), os.path.join(scripts_path, test_gen_binary)]) |
---|
| 57 | |
---|
| 58 | print "mkdir -p", os.path.join(scripts_path, data_dir) |
---|
| 59 | subprocess.call([ 'mkdir', '-p', os.path.join(scripts_path, data_dir) ]) |
---|
| 60 | |
---|
| 61 | while True: |
---|
| 62 | x, y = get_x_y(nb_procs) |
---|
| 63 | |
---|
| 64 | b0 = random.randint(0, 1) |
---|
| 65 | b1 = random.randint(0, 1) |
---|
| 66 | |
---|
| 67 | print test_gen_binary, nb_procs, nb_max_incr, nb_locks, b0, b1, generated_test, main_task, task_no_tty |
---|
| 68 | tab_size = subprocess.Popen([ os.path.join(scripts_path, test_gen_binary), str(nb_procs), str(nb_max_incr), str(nb_locks), str(b0), str(b1), generated_test, main_task, task_no_tty ], stdout = subprocess.PIPE).communicate()[0] |
---|
| 69 | |
---|
| 70 | print "make -f Makefile.nat" |
---|
| 71 | subprocess.call([ 'make', '-f', 'Makefile.nat' ]) |
---|
| 72 | |
---|
| 73 | print "./test_natif >", os.path.join(data_dir, res_natif) |
---|
| 74 | output = subprocess.Popen([ './test_natif' ], stdout = subprocess.PIPE).communicate()[0] |
---|
| 75 | file = open(os.path.join(data_dir, res_natif), 'w') |
---|
| 76 | file.write(output) |
---|
| 77 | file.close() |
---|
| 78 | |
---|
| 79 | print "./test_llsc.py", str(x), str(y), tab_size |
---|
| 80 | subprocess.call([ './test_llsc.py', str(x), str(y), tab_size ]) |
---|
| 81 | |
---|
| 82 | print "cd", top_path |
---|
| 83 | os.chdir(top_path) |
---|
| 84 | print "touch", topcell_name |
---|
| 85 | subprocess.call([ 'touch', topcell_name ]) |
---|
| 86 | print "make" |
---|
| 87 | subprocess.call([ 'make' ]) |
---|
| 88 | |
---|
| 89 | # Launch simulation |
---|
| 90 | print "./simul.x >", os.path.join(scripts_path, data_dir, log_init_name + str(nb_procs)) |
---|
| 91 | output = subprocess.Popen([ './simul.x' ], stdout = subprocess.PIPE).communicate()[0] |
---|
| 92 | |
---|
| 93 | # Write simulation results to data directory |
---|
| 94 | print "cd", scripts_path |
---|
| 95 | os.chdir(scripts_path) |
---|
| 96 | filename = os.path.join(data_dir, log_init_name + str(nb_procs)) |
---|
| 97 | file = open(filename, 'w') |
---|
| 98 | file.write(output) |
---|
| 99 | file.close() |
---|
| 100 | |
---|
| 101 | term_filename = os.path.join(scripts_path, data_dir, log_term_name + str(nb_procs)) |
---|
| 102 | print "mv", os.path.join(top_path, 'term1'), term_filename |
---|
| 103 | subprocess.call([ 'mv', os.path.join(top_path, 'term1'), term_filename ]) |
---|
| 104 | |
---|
| 105 | # Quit if results obtained by simulation are incorrect |
---|
| 106 | print "diff", term_filename, os.path.join(data_dir, res_natif) |
---|
[571] | 107 | output = subprocess.Popen([ 'diff', term_filename, os.path.join(data_dir, res_natif) ], stdout = subprocess.PIPE).communicate()[0] |
---|
| 108 | if output != "": |
---|
[536] | 109 | break; |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | ## Enf of simulations |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | |
---|