ca6bd02012-05-01Bill Welliver #!/usr/local/bin/pike final constant TEST_SIZE = 16384; string testdata = random_string(TEST_SIZE); int verbose; int testno;
5922f42017-09-13Henrik Grubbström (Grubba) int failures;
ca6bd02012-05-01Bill Welliver  mixed call_out_id; object tf; /* * Some helper functions. */ constant log_msg = Tools.Testsuite.log_msg; constant log_status = Tools.Testsuite.log_status;
5922f42017-09-13Henrik Grubbström (Grubba) void exit_test()
ca6bd02012-05-01Bill Welliver {
5922f42017-09-13Henrik Grubbström (Grubba)  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);
ca6bd02012-05-01Bill Welliver } /* * The driver function. */ void next() { testno++; function test;
5922f42017-09-13Henrik Grubbström (Grubba)  if (!(test = this["test"+testno])) exit_test();
ca6bd02012-05-01Bill Welliver  mixed err; if (err = catch { log_status("Kqueue test: %d", testno); test(); }) {
5922f42017-09-13Henrik Grubbström (Grubba)  fail_test(describe_backtrace(err));
ca6bd02012-05-01Bill Welliver  } } void done() { remove_call_out(call_out_id); tf->close(); 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() {
5922f42017-09-13Henrik Grubbström (Grubba)  log_status("kqueue: NOTE_DELETE\n");
ca6bd02012-05-01Bill Welliver  tf = Stdio.File("kqueue.test");
5922f42017-09-13Henrik Grubbström (Grubba) 
ca6bd02012-05-01Bill Welliver  // our failure timeout
5922f42017-09-13Henrik Grubbström (Grubba)  call_out_id = call_out(fail_test, 5, "Timeout.");
ca6bd02012-05-01Bill Welliver  tf->set_fs_event_callback(done, Stdio.NOTE_DELETE); call_out(do_delete, 0); } void test5() {
5922f42017-09-13Henrik Grubbström (Grubba)  log_status("kqueue: NOTE_ATTRIB\n");
ca6bd02012-05-01Bill Welliver  tf = Stdio.File("kqueue.test");
5922f42017-09-13Henrik Grubbström (Grubba) 
ca6bd02012-05-01Bill Welliver  // our failure timeout
5922f42017-09-13Henrik Grubbström (Grubba)  call_out_id = call_out(fail_test, 5, "Timeout.");
ca6bd02012-05-01Bill Welliver  tf->set_fs_event_callback(done, Stdio.NOTE_ATTRIB); call_out(do_chmod, 0); } void test4() {
5922f42017-09-13Henrik Grubbström (Grubba)  log_status("kqueue: NOTE_LINK\n");
ca6bd02012-05-01Bill Welliver  tf = Stdio.File("kqueue.test");
5922f42017-09-13Henrik Grubbström (Grubba) 
ca6bd02012-05-01Bill Welliver  // our failure timeout
5922f42017-09-13Henrik Grubbström (Grubba)  call_out_id = call_out(fail_test, 5, "Timeout.");
ca6bd02012-05-01Bill Welliver  tf->set_fs_event_callback(done, Stdio.NOTE_LINK); call_out(do_link, 0); } void test3() {
5922f42017-09-13Henrik Grubbström (Grubba)  log_status("kqueue: NOTE_RENAME\n");
ca6bd02012-05-01Bill Welliver  tf = Stdio.File("kqueue.tst");
5922f42017-09-13Henrik Grubbström (Grubba) 
ca6bd02012-05-01Bill Welliver  // our failure timeout
5922f42017-09-13Henrik Grubbström (Grubba)  call_out_id = call_out(fail_test, 5, "Timeout.");
ca6bd02012-05-01Bill Welliver  tf->set_fs_event_callback(done, Stdio.NOTE_RENAME); call_out(do_rename, 0); } void test2() {
5922f42017-09-13Henrik Grubbström (Grubba)  log_status("kqueue: NOTE_WRITE\n");
ca6bd02012-05-01Bill Welliver  tf = Stdio.File("kqueue.tst");
5922f42017-09-13Henrik Grubbström (Grubba)  tf->set_nonblocking();
ca6bd02012-05-01Bill Welliver  tf->set_fs_event_callback(done, Stdio.NOTE_WRITE); // our failure timeout
5922f42017-09-13Henrik Grubbström (Grubba)  call_out_id = call_out(fail_test, 5, "Timeout.");
ca6bd02012-05-01Bill Welliver  call_out(do_write, 0.1); } void test1() {
5922f42017-09-13Henrik Grubbström (Grubba)  log_status("kqueue: NOTE_EXTEND\n");
ca6bd02012-05-01Bill Welliver  /* first, create a test file */ tf = Stdio.File("kqueue.tst", "crw"); tf->close(); tf = Stdio.File("kqueue.tst");
5922f42017-09-13Henrik Grubbström (Grubba)  tf->set_nonblocking();
ca6bd02012-05-01Bill Welliver  tf->set_fs_event_callback(done, Stdio.NOTE_EXTEND); // our failure timeout
5922f42017-09-13Henrik Grubbström (Grubba)  call_out_id = call_out(fail_test, 5, "Timeout");
ca6bd02012-05-01Bill Welliver  call_out(do_extend, 0.1); } void do_rename() { mv("kqueue.tst", "kqueue.test"); } void do_chmod() { System.chmod("kqueue.tst", 777); } void do_write() { object tf1 = Stdio.File("kqueue.tst", "rw"); tf1->seek(0); tf1->write("foo"); tf1->close(); } void do_extend() { object tf1 = Stdio.File("kqueue.tst", "rw"); tf1->write("foo2"); tf1->close(); } void do_link() { System.hardlink("kqueue.test", "kqueue.tst"); } void do_delete() { rm("kqueue.test"); rm("kqueue.tst"); } /* * Start the backend. */ int main(int argc, array(string) argv) { verbose = (int) (getenv()->TEST_VERBOSITY || 2); #if constant(alarm) alarm(5*60); // 5 minutes should be sufficient for this test. #endif call_out(next, 0); return -1; }