RCS file: /cvsroot/gnugo/gnugo/regression/regress.pike,v
retrieving revision 1.10
diff -u -p -r1.10 regress.pike
|
|
|
|
| 1 | 1 | #!/usr/bin/env pike |
| 2 | 2 | |
| 3 | | static Thread.Queue write_queue; |
| 4 | | static Thread.Condition cond; |
| 5 | | static Thread.Mutex condmutex; |
| 6 | | static Thread.MutexKey condmutexkey; |
| | 3 | static Thread.Queue writing_finished; |
| | 4 | static Thread.Queue reading_finished; |
| 7 | 5 | static int debug = 0; |
| 8 | 6 | static object machine; |
| 9 | 7 | static mapping(int:string) correct_results = ([]); |
| … |
… |
|
| 94 | 92 | Highscorelist slow_moves; |
| 95 | 93 | int report_slow = 0; |
| 96 | 94 | |
| 97 | | void send(string|void s) |
| | 95 | void send(Thread.Queue out, string|void s) |
| 98 | 96 | { |
| 99 | 97 | if (!s) { |
| 100 | 98 | if (debug) |
| 101 | 99 | werror("Finishing sending.\n"); |
| 102 | | write_queue->write(""); |
| 103 | 100 | } |
| 104 | 101 | else { |
| 105 | 102 | if (debug) |
| 106 | 103 | werror("Sent: " + s + "\n"); |
| 107 | | write_queue->write(s + "\n"); |
| | 104 | out->write(s + "\n"); |
| 108 | 105 | } |
| 109 | 106 | } |
| 110 | 107 | |
| … |
… |
|
| 114 | 111 | current_testsuite->cputime, |
| 115 | 112 | current_testsuite->reading_nodes, current_testsuite->owl_nodes, |
| 116 | 113 | current_testsuite->connection_nodes); |
| 117 | | cond->signal(); |
| 118 | 114 | } |
| 119 | 115 | |
| 120 | 116 | static void program_reader(object f) |
| … |
… |
|
| 126 | 122 | array(int) unexpected_failures = ({}); |
| 127 | 123 | array(int) unexpected_passes = ({}); |
| 128 | 124 | int test_number; |
| | 125 | if (debug) |
| | 126 | werror("Waiting for writing to be finished.\n"); |
| | 127 | writing_finished->read(); |
| | 128 | if (debug) |
| | 129 | werror("Finished Waiting for writing to be finished.\n"); |
| 129 | 130 | while (1) { |
| 130 | 131 | string s = f->gets(); |
| 131 | 132 | float current_time = time(timebase); |
| … |
… |
|
| 187 | 188 | else if (sscanf(s, "?%s", answer)) { |
| 188 | 189 | number = -1; |
| 189 | 190 | sscanf(answer, "%d", number); |
| 190 | | if (verbose || (number != -1 && number < 10000)) |
| 191 | | write("%-15s ?%s\n", current_testsuite->name + ":", answer); |
| | 191 | write("%-15s ?%s\n", current_testsuite->name + ":", answer); |
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | | f->close(); |
| 195 | 194 | if (debug) |
| 196 | | werror("Reader closed down.\n"); |
| | 195 | werror("Reader closing down.\n"); |
| 197 | 196 | finish(); |
| | 197 | f->close(); |
| | 198 | reading_finished->write("\n"); |
| 198 | 199 | } |
| 199 | 200 | |
| 200 | | static void program_writer(object f) |
| | 201 | static void program_writer(Thread.Queue in, object f) |
| 201 | 202 | { |
| 202 | 203 | while (1) { |
| 203 | | string s = write_queue->read(); |
| | 204 | string s = in->read(); |
| 204 | 205 | if (s == "") |
| 205 | 206 | break; |
| 206 | 207 | f->write(s); |
| … |
… |
|
| 254 | 255 | if (options["check-unoccupied-answers"]) |
| 255 | 256 | testsuite = modify_testsuite(testsuite); |
| 256 | 257 | |
| 257 | | write_queue = Thread.Queue(); |
| | 258 | writing_finished = Thread.Queue(); |
| | 259 | reading_finished = Thread.Queue(); |
| | 260 | Thread.Queue write_queue = Thread.Queue(); |
| 258 | 261 | object f1 = Stdio.File(); |
| 259 | 262 | object pipe1 = f1->pipe(); |
| 260 | 263 | object f2 = Stdio.FILE(); |
| … |
… |
|
| 262 | 265 | machine = Process.create_process(program_start_array, |
| 263 | 266 | (["stdin":pipe1, "stdout":pipe2])); |
| 264 | 267 | thread_create(program_reader, f2); |
| 265 | | thread_create(program_writer, f1); |
| | 268 | thread_create(program_writer, write_queue, f1); |
| 266 | 269 | |
| 267 | 270 | int number; |
| 268 | 271 | string answer; |
| … |
… |
|
| 287 | 290 | continue; |
| 288 | 291 | if (correct_results[(int) number]) |
| 289 | 292 | write("Repeated test number " + number + ".\n"); |
| 290 | | send("reset_reading_node_counter"); |
| 291 | | send("reset_owl_node_counter"); |
| 292 | | send("reset_connection_node_counter"); |
| 293 | | send(s); |
| | 293 | send(write_queue, "reset_reading_node_counter"); |
| | 294 | send(write_queue, "reset_owl_node_counter"); |
| | 295 | send(write_queue, "reset_connection_node_counter"); |
| | 296 | send(write_queue, s); |
| 294 | 297 | if (sscanf(s, "%*sreg_genmove%*s") == 2) |
| 295 | | send("10005 move_uncertainty"); |
| 296 | | send("10000 get_reading_node_counter"); |
| 297 | | send("10001 get_owl_node_counter"); |
| 298 | | send("10002 get_connection_node_counter"); |
| 299 | | send("10003 cputime"); |
| | 298 | send(write_queue, "10005 move_uncertainty"); |
| | 299 | send(write_queue, "10000 get_reading_node_counter"); |
| | 300 | send(write_queue, "10001 get_owl_node_counter"); |
| | 301 | send(write_queue, "10002 get_connection_node_counter"); |
| | 302 | send(write_queue, "10003 cputime"); |
| 300 | 303 | } |
| 301 | 304 | else if (sscanf(s, "#? [%[^]]]%s", answer, expected)) { |
| 302 | 305 | correct_results[(int)number] = answer; |
| … |
… |
|
| 304 | 307 | expected_failures[(int)number] = 1; |
| 305 | 308 | } |
| 306 | 309 | else |
| 307 | | send(s); |
| | 310 | send(write_queue, s); |
| 308 | 311 | } |
| 309 | 312 | |
| 310 | | send("10004 quit"); |
| 311 | | send(); |
| 312 | | cond->wait(condmutexkey); |
| | 313 | if (debug) |
| | 314 | werror("Signalling finish of writing\n"); |
| | 315 | writing_finished->write("\n"); |
| | 316 | send(write_queue, "10004 cputime"); |
| | 317 | reading_finished->read(); |
| | 318 | send(write_queue, "10004 quit"); |
| | 319 | send(write_queue, ); |
| 313 | 320 | } |
| 314 | 321 | |
| 315 | 322 | void final_report() |
| … |
… |
|
| 385 | 392 | |
| 386 | 393 | int main(int argc, array(string) argv) |
| 387 | 394 | { |
| 388 | | cond = Thread.Condition(); |
| 389 | | condmutex = Thread.Mutex(); |
| 390 | | condmutexkey = condmutex->lock(); |
| 391 | 395 | array(string) testsuites = ({}); |
| 392 | 396 | mapping(string:array(int)) partial_testsuites = ([]); |
| 393 | 397 | |