pike.git / lib / modules / testsuite.in

version» Context lines:

pike.git/lib/modules/testsuite.in:1: - dnl $Id: testsuite.in,v 1.15 2003/04/29 00:11:18 nilsson Exp $ + dnl $Id: testsuite.in,v 1.16 2003/08/10 19:25:28 nilsson Exp $      dnl - Array      test_equal(Array.diff(({ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }),    ({ 6, 7, 8, 9, 3, 4, 5, 1, 2, 0 })),    ({ ({ ({ 0, 1, 2, 3, 4, 5 }),    ({ 6, 7, 8, 9 }), ({}) }),    ({ ({}), ({ 6, 7, 8, 9 }),    ({ 3, 4, 5, 1, 2, 0 }) }) }))   test_equal(Array.diff(({ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }),
pike.git/lib/modules/testsuite.in:648:   test_eq( Int.parity(4), 1 )   test_eq( Int.parity(6), 0 )   test_eq( Int.parity(7), 1 )      dnl - Mapping   dnl Mapping.delete   dnl Mapping.Iterator      dnl - Multiset   dnl Multiset.Iterator +  + dnl - Process + test_equal([[Process.split_quoted_string("test ")]],[[({"test"})]]) + test_equal([[Process.split_quoted_string("'test'")]],[[({"test"})]]) + test_equal([[Process.split_quoted_string("foo 'test' bar")]],[[({"foo","test","bar"})]]) + test_equal([[Process.split_quoted_string("pike -m master.pike 'write(\"test\");'")]],[[({"pike","-m","master.pike","write(\"test\");"})]]) + test_false([[ + #ifdef __NT__ +  Process.system(RUNPIKE +" -e exit(0)") + #else /* !__NT__ */ +  Process.system(RUNPIKE +" -e 'exit(0)'") + #endif /* __NT__ */ + ]]) + test_true([[ + #ifdef __NT__ +  Process.system(RUNPIKE+" -e exit(1)") + #else /* !__NT__ */ +  Process.system(RUNPIKE+" -e 'exit(1)'") + #endif /* __NT__ */ + ]]) + test_any([[object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(2)"})); sleep(10); return p->wait()]],2) + test_eq([[ + #ifdef __NT__ +  Process.popen(RUNPIKE+" -e \"write(\\\"test\\\");\"") + #else /* !__NT__ */ +  Process.popen(RUNPIKE+" -e 'write(\"test\");'") + #endif /* __NT__ */ + ]],"test") + test_any([[object o=Stdio.File(); object o2=o->pipe(Stdio.PROP_IPC); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.stdin->read(5)==\"hello\")"}),(["stdin":o])); o2->write("hello"); destruct(o); destruct(o2); return p->wait()]],1) + test_any([[object o=Stdio.File(); object o2=o->pipe(Stdio.PROP_IPC); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.stdin->read(1000)==\"hello\")"}),(["stdin":o])); o2->write("hello"); destruct(o); destruct(o2); return p->wait()]],1) + test_any([[object o=Stdio.Fd(); object o2=o->pipe(Stdio.PROP_IPC); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.stdin->read(1000)==\"hello\")"}),(["stdin":o])); o2->write("hello"); destruct(o); destruct(o2); return p->wait()]],1) + test_any([[object o=Stdio.Fd(); object o2=o->pipe(Stdio.PROP_IPC); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.stdin->read(1000)==\"hello\")"}),(["stdin":o])); o2->write("hello"); destruct(o2); return p->wait()]],1) + test_any([[object o=Stdio.Fd(); object o2=o->pipe(Stdio.PROP_IPC); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.stdin->read(1000)==\"hello\")"}),(["stdin":o])); o2->write("hello"); o2=0; return p->wait()]],1) +  + test_any([[object o=Stdio.Fd(); object o2=o->pipe(); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.stdin->read(5)==\"hello\")"}),(["stdin":o])); o2->write("hello"); destruct(o); destruct(o2); return p->wait()]],1) + test_any([[object o=Stdio.Fd(); object o2=o->pipe(); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.stdin->read(1000)==\"hello\")"}),(["stdin":o])); o2->write("hello"); destruct(o); destruct(o2); return p->wait()]],1) + test_any([[object o=Stdio.Fd(); object o2=o->pipe(); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.File(\"stdin\")->read(1000)==\"hello\")"}),(["stdin":o])); o2->write("hello"); destruct(o); destruct(o2); return p->wait()]],1) + test_any([[object o=Stdio.File(); object o2=o->pipe(); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.File(\"stdin\")->read(1000)==\"hello\")"}),(["stdin":o])); o2->write("hello"); destruct(o); destruct(o2); return p->wait()]],1) + test_any([[object o=Stdio.File(); object o2=o->pipe(Stdio.PROP_IPC); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.stdin->read(1000)==\"hello\")"}),(["stdin":o])); o2->write("hello"); destruct(o); destruct(o2); return p->wait()]],1) + test_any([[object o=Stdio.File(); object o2=o->pipe(Stdio.PROP_BIDIRECTIONAL); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.stdin->read(1000)==\"hello\")"}),(["stdin":o2])); o->write("hello"); destruct(o); destruct(o2); return p->wait()]],1) +  + cond([[ file_stat("/bin/cat") && file_stat("/dev/null") && (cpp("__NT__")/"\n")[1]=="__NT__" ]], + [[ +  test_false(Process.create_process(({"/bin/cat","/dev/null"}))->wait()); +  test_false(Process.create_process(({"/bin/cat","/dev/null"}))->wait()); +  test_false(Process.create_process(({"/bin/cat","/dev/null"}))->wait()); +  +  test_any([[ +  object o=Process.create_process(({"/bin/cat","/dev/null"})); +  if(Process.create_process(({"/bin/cat","/dev/null"}))->wait()) return 99; +  sleep(1); +  return kill(o->pid(), 9); +  ]],0); +  +  dnl Some OSs have a delay before PIDs are reused. +  dnl Be nice, and let them reuse some. +  test_do([[ sleep(2); ]]); +  test_any([[ for(int x=0;x<10;x++) { for(int e=0;e<100;e++) if(Process.create_process(({"/bin/cat","/dev/null"}))->wait()) return e; __signal_watchdog(); } return -1;]],-1) + ]]) +  + cond([[ file_stat("/bin/cat") && file_stat("/dev/null") && all_constants()->thread_create && (cpp("__NT__")/"\n")[1]=="__NT__" ]], + [[ +  test_any([[ +  return allocate(10, thread_create) ( +  lambda() { +  for (int x=0; x<10; x++) { +  for (int e=0; e<50; e++) +  if (Process.create_process(({"/bin/cat","/dev/null"}))->wait()) +  return e; +  __signal_watchdog(); +  } +  return -1; +  } +  )->wait() - ({-1})]],({})) + ]]) +  + cond([[ file_stat("/bin/cat") && file_stat("/dev/null") && all_constants()->thread_create && (cpp("__NT__")/"\n")[1]=="__NT__" ]], + [[ +  test_do([[ +  for(int q=0;q<100;q++) +  { +  array fnord=({}); +  Thread.Fifo fifo=Thread.Fifo(); +  +  for(int e=0;e<10;e++) +  { +  fnord+=({ thread_create(lambda() { +  Process.create_process(({"/bin/cat","/dev/null"})); +  fifo->read(); +  }) +  }); +  } +  // for(int e=0;e<50;e++) Stdio.Port()->bind(0); +  for(int e=0;e<10;e++) fifo->write(1); +  fnord->wait(); +  __signal_watchdog(); +  } +  ]]) + ]]) +  + cond([[ file_stat("/bin/sleep") && all_constants()->thread_create && (cpp("__NT__")/"\n")[1]=="__NT__" ]], + [[ + test_any([[ +  class Fnord +  { + int gnapp(int t) + { +  int e; +  for(e=0;e<7;e++) +  { +  for(int d=0;d<150;d++) +  { +  object o=Process.create_process(({"/bin/sleep","99999"})); +  kill( o->pid(), 9 ); +  o->wait(); +  __signal_watchdog(); +  } + // werror("%d",t); +  } +  return -1; + } +  + array start() + { +  array a=({}); +  for(int e=0;e<10;e++) +  a+=({thread_create(gnapp,e)}); +  return a; + } + }; +  + return Fnord()->start()->wait()-({ -1 }); + ]],[[ ({}) ]]) +  + test_do([[ +  object proc = Process.create_process (({"/bin/sleep", "99999"})); +  array threads = allocate (10, Thread.thread_create) ( +  lambda (object proc) {proc->wait();}, proc); +  sleep (1); +  proc->kill (9); +  return threads->wait() - ({-1}); + ]], ({})) + ]]) +  + cond([[ file_stat("/bin/sleep") && __builtin->TraceProcess && (cpp("__NT__")/"\n")[1]=="__NT__" ]], + [[ + test_any([[ +  // Check that tracing works... +  // Use a spawned pike to make sure the process doesn't exit +  // prematurely due to EINTR. +  Process.TraceProcess proc = +  Process.TraceProcess(RUNPIKE_ARRAY + ({ "-e", "sleep(99999)" })); +  +  int initial_sleep = 5; +  int count; +  int state; +  int code; +  while (((code = proc->wait()) == -2) && (count++ < 20)) { +  int sig = proc->last_signal(); +  switch(sig) { +  case signum("TRAP"): +  if (state) { +  // NB: OSF/1 issues two SIGTRAPS before the program starts executing. +  werror("Unexpected SIGTRAP in state %d.\n", state); +  } +  state = ((state <= 1) ? 1 : state); +  proc->cont(); +  +  // Give it some time to settle down after initialization. +  if (initial_sleep) { +  sleep(initial_sleep); +  initial_sleep=0; +  } +  +  // Check that we can block deadly signals. +  proc->kill(signum("TERM")); +  break; +  case signum("TERM"): +  if (state != 1) { +  werror("Unexpected SIGTERM in state %d.\n", state); +  } +  state = ((state <= 2) ? 2 : state); +  proc->cont(); // Ignore it... +  +  // Check that we can make harmless signals deadly. +  proc->kill(signum("CONT")); +  break; +  case signum("CONT"): +  if (state != 2) { +  werror("Unexpected SIGCONT in state %d.\n", state); +  } +  state = ((state <= 3) ? 3 : state); +  proc->cont(signum("KILL")); // Make it a SIGKILL +  +  sleep(5); // Give it some time to die and get reaped. +  +  if (proc->kill(signum("KILL"))) { +  return sprintf("Process didn't die of cont(%d).", signum("KILL")); +  } +  break; +  default: +  proc->kill(signum("KILL")); +  return sprintf("Unexpected signal:%d in state %d.", sig, state); +  } +  } +  +  if (code == -2) { +  proc->kill(signum("KILL")); +  return sprintf("Looping trace. (Looped %d times).", count-1); +  } +  +  if (code != -1) { +  proc->kill(signum("KILL")); +  return sprintf("Bad termination returncode from wait():%d (expected -1).", +  code); +  } +  +  if (state != 3) { +  return sprintf("Unexpected termination in state %d, signal %d.", +  state, proc->last_signal()); +  } +  +  int sig = proc->last_signal(); +  if (sig != signum("KILL")) { +  proc->kill(signum("KILL")); +  return sprintf("Unexpected termination signal:%d (expected %d).", +  sig, signum("KILL")); +  } +  // Test ok. +  return 0; ]], 0) + ]]) +  + test_do([[ +  string s; +  for(s="foobar";strlen(s)<78;s+=s) +  { +  for(int e=0;e<strlen(s);e++) +  { +  s[e]++; +  } +  } + ]])