pike.git / src / modules / _Stdio / kqueuetest.pike

version» Context lines:

pike.git/src/modules/_Stdio/kqueuetest.pike:1:   #!/usr/local/bin/pike      final constant TEST_SIZE = 16384;      string testdata = random_string(TEST_SIZE);      int verbose;   int testno; + int failures;      mixed call_out_id;   object tf;      /*    * Some helper functions.    */      constant log_msg = Tools.Testsuite.log_msg;   constant log_status = Tools.Testsuite.log_status;    - void exit_test (int failure) + void exit_test()   { -  Tools.Testsuite.report_result (max (testno - !!failure, 0), !!failure); -  exit (failure); +  Tools.Testsuite.report_result (max (testno - failures, 0), failures); +  exit(!!failure);   }    -  + void fail_test(string) + { +  log_msg("Test %d failed: %s.\n", testno, msg); +  failures++; +  call_out(next, 0); + } +    /*    * The driver function.    */      void next()   {    testno++;       function test; -  if (!(test = this["test"+testno])) exit_test(0); +  if (!(test = this["test"+testno])) exit_test();    mixed err;    if (err = catch {    log_status("Kqueue test: %d", testno);    test();    }) { -  catch { -  log_msg("Test %d failed!\n" -  "%s\n", -  testno, -  describe_backtrace(err)); -  }; -  exit_test(1); +  fail_test(describe_backtrace(err));    }   }      void done()   {    remove_call_out(call_out_id);    tf->close(); -  if(0) -  { -  log_msg("Test %d failed.\n", testno); -  exit_test(1); -  } +     call_out(next, 0);   }      /*    * The actual tests.    * NOTE: We don't test NOTE_REVOKE, as there's no reliable way to generate this    * event type from within Pike.    */      void test6()   { -  +  log_status("kqueue: NOTE_DELETE\n");    tf = Stdio.File("kqueue.test");       // our failure timeout -  call_out_id = call_out(exit_test, 5, 1); +  call_out_id = call_out(fail_test, 5, "Timeout.");       tf->set_fs_event_callback(done, Stdio.NOTE_DELETE);       call_out(do_delete, 0);   }      void test5()   { -  +  log_status("kqueue: NOTE_ATTRIB\n");    tf = Stdio.File("kqueue.test");       // our failure timeout -  call_out_id = call_out(exit_test, 5, 1); +  call_out_id = call_out(fail_test, 5, "Timeout.");       tf->set_fs_event_callback(done, Stdio.NOTE_ATTRIB);       call_out(do_chmod, 0);   }      void test4()   { -  +  log_status("kqueue: NOTE_LINK\n");    tf = Stdio.File("kqueue.test");       // our failure timeout -  call_out_id = call_out(exit_test, 5, 1); +  call_out_id = call_out(fail_test, 5, "Timeout.");       tf->set_fs_event_callback(done, Stdio.NOTE_LINK);       call_out(do_link, 0);   }      void test3()   { -  +  log_status("kqueue: NOTE_RENAME\n");    tf = Stdio.File("kqueue.tst");       // our failure timeout -  call_out_id = call_out(exit_test, 5, 1); +  call_out_id = call_out(fail_test, 5, "Timeout.");       tf->set_fs_event_callback(done, Stdio.NOTE_RENAME);       call_out(do_rename, 0);   }      void test2()   { -  +  log_status("kqueue: NOTE_WRITE\n");    tf = Stdio.File("kqueue.tst");    tf->set_nonblocking();    tf->set_fs_event_callback(done, Stdio.NOTE_WRITE);       // our failure timeout -  call_out_id = call_out(exit_test, 5, 1); +  call_out_id = call_out(fail_test, 5, "Timeout.");       call_out(do_write, 0.1);   }      void test1()   { -  +  log_status("kqueue: NOTE_EXTEND\n");    /* first, create a test file */    tf = Stdio.File("kqueue.tst", "crw");    tf->close();       tf = Stdio.File("kqueue.tst");    tf->set_nonblocking();    tf->set_fs_event_callback(done, Stdio.NOTE_EXTEND);       // our failure timeout -  call_out_id = call_out(exit_test, 5, 1); +  call_out_id = call_out(fail_test, 5, "Timeout");       call_out(do_extend, 0.1);   }         void do_rename()   {    mv("kqueue.tst", "kqueue.test");   }