From c521cc09a76a3c2a33e9650086748e4aa1cc51d1 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 6 Oct 2002 00:43:55 +0000 Subject: [PATCH] test framework svn path=/trunk/boinc/; revision=473 --- api/graphics_api.C | 20 ++++++++++++-------- doc/test.html | 16 ++++++++++++---- test/test.inc | 34 +++++++++++++++++++++++++++++++--- test/test_1sec.php | 5 +++-- test/test_concat.php | 3 ++- test/test_prefs.php | 2 +- test/test_rsc.php | 4 +--- test/test_sticky.php | 11 ++++------- test/test_time.php | 3 ++- test/test_uc.php | 5 ++++- test/test_uc_win.php | 2 +- 11 files changed, 73 insertions(+), 32 deletions(-) diff --git a/api/graphics_api.C b/api/graphics_api.C index 0409b2c381..2cc350c5c3 100755 --- a/api/graphics_api.C +++ b/api/graphics_api.C @@ -42,13 +42,15 @@ int boinc_init_opengl() { HANDLE hThread; // Create the graphics thread, passing it the graphics info - hThread = CreateThread( NULL, 0, win_graphics_event_loop, &gi, CREATE_SUSPENDED, &threadId ); + hThread = CreateThread( + NULL, 0, win_graphics_event_loop, &gi, CREATE_SUSPENDED, &threadId + ); // Set it to idle priority - SetThreadPriority (hThread, THREAD_PRIORITY_HIGHEST); + SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST); // Start the graphics thread - ResumeThread( hThread ); + ResumeThread(hThread); #endif #ifdef __APPLE_CC__ @@ -59,14 +61,16 @@ int boinc_init_opengl() { entry_proc = NewThreadEntryUPP( mac_graphics_event_loop ); // Create the thread in a suspended state - theErr = NewThread ( kCooperativeThread, entry_proc, - (void *)(&gi), 0, kNewSuspend, NULL, &graphicsThreadID ); + theErr = NewThread ( + kCooperativeThread, entry_proc, + (void *)(&gi), 0, kNewSuspend, NULL, &graphicsThreadID + ); if (theErr != noErr) return ERR_THREAD; // In theory we could do customized scheduling or install thread disposal routines here // Put the graphics event loop into the ready state - SetThreadState( graphicsThreadID, kReadyThreadState, kNoThreadID ); + SetThreadState(graphicsThreadID, kReadyThreadState, kNoThreadID); YieldToAnyThread(); #endif @@ -99,13 +103,13 @@ int write_graphics_file(FILE* f, GRAPHICS_INFO* gi) { int parse_graphics_file(FILE* f, GRAPHICS_INFO* gi) { char buf[256]; while (fgets(buf, 256, f)) { + if (match_tag(buf, "")) continue; if (match_tag(buf, "")) return 0; else if (parse_int(buf, "", gi->xsize)) continue; else if (parse_int(buf, "", gi->ysize)) continue; else if (parse_int(buf, "", gi->graphics_mode)) continue; else if (parse_double(buf, "", gi->refresh_period)) continue; - else fprintf(stderr, "parse_core_file: unrecognized %s", buf); + else fprintf(stderr, "parse_graphics_file: unrecognized %s", buf); } return -1; } - diff --git a/doc/test.html b/doc/test.html index deb0ad797c..4ef47a1485 100644 --- a/doc/test.html +++ b/doc/test.html @@ -87,9 +87,11 @@ class Project { // represents a project function install(); // set up directories and DB function start(); // start feeder function stop(); // stop feeder - function check_results_done(); // verify that all results are in state DONE function compare_file($out, $correct); // verify that a result file // matches a known-correct file + function check_results($n, $result); // check that there are n results + // and that they match "result" + // (for all fields that are defined) } class User { // represents an account on a project @@ -103,6 +105,8 @@ class Host { // represents a (virtual) host function add_project($project); function install(); function run($flags); + function check_file_present($project, $name); + // check that a file exists } class App { // represents an application @@ -177,23 +181,27 @@ illustrates the use of the testing framework. $project->add_app_version($app_version); $project->install(); // must install projects before adding to hosts + $host->log_flags = "log_flags.xml"; $host->add_project($project); $host->install(); echo "adding work\n"; - $work = new Work($project, $app); + $work = new Work($app); $work->wu_template = "uc_wu"; $work->result_template = "uc_result"; $work->nresults = 2; array_push($work->input_files, "input"); - $work->install(); + $work->install($project); $project->start(); $host->run("-exit_when_idle"); $project->stop(); - $project->check_results_done(); + $result->state = RESULT_STATE_DONE; + $result->stderr_out = "APP: upper_case: starting, argc 1"; + $result->exit_status = 0; + $project->check_results(2, $result); $project->compare_file("uc_wu_0_0", "uc_correct_output"); $project->compare_file("uc_wu_1_0", "uc_correct_output"); ?> diff --git a/test/test.inc b/test/test.inc index 5d3f3c7a4d..69fc8fdfc2 100644 --- a/test/test.inc +++ b/test/test.inc @@ -10,6 +10,8 @@ // // See doc/test.html for details +define("RESULT_STATE_DONE", 4); + // get an enviroment variable, and abort script if missing // function get_env_var($name) { @@ -239,11 +241,30 @@ class Project { fclose($f); } - function check_results_done() { + function check_results($ntarget, $result) { + $n = 0; db_open($this->db_name); - $result = mysql_query("select * from result where state<>4"); + $result = mysql_query("select * from result"); while ($x = mysql_fetch_object($result)) { - echo "result $x->id is not done\n"; + $n++; + if ($result->state != null) { + if ($result->state != $x->state) { + echo "ERROR: result $x->id: unexpected state $x->state\n"; + } + } + if ($result->stderr_out != null) { + if (substr($result->stderr_out, $x->stderr_out)==0) { + echo "ERROR: result $x->id: unexpected stderr_out $x->stderr_out\n"; + } + } + if ($result->exit_status != null) { + if ($result->exit_status != $x->exit_status) { + echo "ERROR: result $x->id: unexpected exit_status $x->exit_status\n"; + } + } + } + if ($n != $ntarget) { + echo "ERROR: expected $ntarget results, found $n.\n"; } } @@ -351,6 +372,13 @@ class Host { return $app_time; } + function check_file_present($project, $filename) { + $enc_url = replace($project->master_url, "/", "_"); + $path= "$this->host_dir/projects/$enc_url/$filename"; + if (!file_exists($path)) { + echo "ERROR: file $path doesn't exist\n"; + } + } } class Work { diff --git a/test/test_1sec.php b/test/test_1sec.php index 9a03ec4b57..3353b49e74 100644 --- a/test/test_1sec.php +++ b/test/test_1sec.php @@ -46,10 +46,11 @@ $project1->stop(); $project2->stop(); - $project1->check_results_done(); + $result->state = RESULT_STATE_DONE; + $project1->check_results(2, $result); $project1->compare_file("uc_wu_0_0", "uc_correct_output"); $project1->compare_file("uc_wu_1_0", "uc_correct_output"); - $project2->check_results_done(); + $project2->check_results(2, $result); $project2->compare_file("uc_wu_0_0", "uc_correct_output"); $project2->compare_file("uc_wu_1_0", "uc_correct_output"); ?> diff --git a/test/test_concat.php b/test/test_concat.php index 03aad67621..4e3a938870 100644 --- a/test/test_concat.php +++ b/test/test_concat.php @@ -31,7 +31,8 @@ $host->run("-exit_when_idle"); $project->stop(); - $project->check_results_done(); + $result->state = RESULT_STATE_DONE; + $project->check_results(2, $result); $project->compare_file("concat_wu_0_0", "concat_correct_output"); $project->compare_file("concat_wu_1_0", "concat_correct_output"); ?> diff --git a/test/test_prefs.php b/test/test_prefs.php index 034f83a03a..574d965835 100644 --- a/test/test_prefs.php +++ b/test/test_prefs.php @@ -33,6 +33,6 @@ echo "Now run the client manually; start and stop it a few times.\n"; - //$project->check_results_done(); + //$project->check_results(1, $result); //$project->compare_file("ucs_wu_0_0", "uc_small_correct_output"); ?> diff --git a/test/test_rsc.php b/test/test_rsc.php index 91707ee09d..f01afefc2a 100644 --- a/test/test_rsc.php +++ b/test/test_rsc.php @@ -34,7 +34,5 @@ $host->run("-exit_when_idle"); $project->stop(); - $x = $project->num_results_done(); - if ($x != 0) echo "Test failed\n"; - if ($x == 0) echo "Test succeeded\n"; + $project->check_results(0, $result); ?> diff --git a/test/test_sticky.php b/test/test_sticky.php index 26565d23c0..aedf22d179 100644 --- a/test/test_sticky.php +++ b/test/test_sticky.php @@ -32,16 +32,13 @@ $host->run("-exit_when_idle"); $project->stop(); - $project->check_results_done(); + $result->state = RESULT_STATE_DONE; + $project->check_results(2, $result); $project->compare_file("uc_wu_0_0", "uc_correct_output"); $project->compare_file("uc_wu_1_0", "uc_correct_output"); // make sure result files are still there - if (!$host->file_present($project, "uc_wu_0_0")) { - echo "test failed\n"; - } - if (!$host->file_present($project, "uc_wu_1_0")) { - echo "test failed\n"; - } + $host->check_file_present($project, "uc_wu_0_0"); + $host->check_file_present($project, "uc_wu_1_0"); ?> diff --git a/test/test_time.php b/test/test_time.php index a98cfdfa9e..e12d3ba53a 100644 --- a/test/test_time.php +++ b/test/test_time.php @@ -35,7 +35,8 @@ $host->run("-exit_when_idle"); $project->stop(); - $project->check_results_done(); + $result->state = RESULT_STATE_DONE; + $project->check_results(1, $result); $project->compare_file("uccpu_wu_0_0", "uc_small_correct_output"); $client_time = $host->read_cpu_time_file("client_time"); $x = mysql_query("select cpu_time from result where name='uccpu_wu_0'"); diff --git a/test/test_uc.php b/test/test_uc.php index b497e17fbc..e0aab22724 100644 --- a/test/test_uc.php +++ b/test/test_uc.php @@ -33,7 +33,10 @@ $host->run("-exit_when_idle"); $project->stop(); - $project->check_results_done(); + $result->state = RESULT_STATE_DONE; + $result->stderr_out = "APP: upper_case: starting, argc 1"; + $result->exit_status = 0; + $project->check_results(2, $result); $project->compare_file("uc_wu_0_0", "uc_correct_output"); $project->compare_file("uc_wu_1_0", "uc_correct_output"); ?> diff --git a/test/test_uc_win.php b/test/test_uc_win.php index f33b0b551b..e06bf90c13 100644 --- a/test/test_uc_win.php +++ b/test/test_uc_win.php @@ -31,7 +31,7 @@ //$project->stop(); - //$project->check_results_done(); + //$project->check_results(2, $result); //$project->compare_file("uc_wu_0_0", "uc_correct_output"); //$project->compare_file("uc_wu_1_0", "uc_correct_output"); ?>