06983f1996-09-22Fredrik Hübinette (Hubbe) #!/usr/local/bin/pike
0df3a72001-11-14Jonas Wallden /* $Id: test_pike.pike,v 1.54 2001/11/14 16:44:54 jonasw Exp $ */
7bd16b1997-06-01Henrik Grubbström (Grubba) 
8164111999-03-11Fredrik Hübinette (Hubbe) import Stdio;
e9361f1995-11-06Fredrik Hübinette (Hubbe) 
6657a51999-10-21Fredrik Hübinette (Hubbe) #if !constant(_verify_internals)
c7dbb61996-06-09Fredrik Hübinette (Hubbe) #define _verify_internals() #endif
6657a51999-10-21Fredrik Hübinette (Hubbe) #if !constant(_dmalloc_set_name) void _dmalloc_set_name(mixed ... args) {} #endif
73b75f1998-02-24Fredrik Hübinette (Hubbe) int foo(string opt) { if(opt=="" || !opt) return 1; return (int)opt; }
dddccc1998-04-15Fredrik Hübinette (Hubbe) 
619f882000-01-30Fredrik Hübinette (Hubbe) int istty_cache; int istty() { #ifdef __NT__ return 1; #else if(!istty_cache) { istty_cache=!!Stdio.stdin->tcgetattr();
b7df1b2000-03-27Fredrik Hübinette (Hubbe)  if(!istty_cache) { istty_cache=-1; }else{ switch(getenv("TERM")) { case "dumb": case "emacs": istty_cache=-1; } }
619f882000-01-30Fredrik Hübinette (Hubbe)  } return istty_cache>0; #endif }
dddccc1998-04-15Fredrik Hübinette (Hubbe) mapping(string:int) cond_cache=([]);
bd227a1999-01-21Fredrik Hübinette (Hubbe) #if constant(thread_create) #define HAVE_DEBUG #endif
394d7d1999-04-08Fredrik Hübinette (Hubbe) void bzot(string test) { int line=1; int tmp=strlen(test)-1; while(test[tmp]=='\n') tmp--; foreach(test[..tmp]/"\n",string s) werror("%3d: %s\n",line++,s); }
ada13c1999-06-19Fredrik Hübinette (Hubbe) array find_testsuites(string dir) { array(string) ret=({}); if(array(string) s=get_dir(dir||".")) { foreach(s, string file) { switch(file) { case "testsuite": case "module_testsuite": ret+=({ combine_path(dir||"",file) }); } }
1da4a12001-01-01Mirar (Pontus Hagland)  foreach(s, string file) { string name=combine_path(dir||"",file); if(file_size(name)==-2) ret+=find_testsuites(name); }
ada13c1999-06-19Fredrik Hübinette (Hubbe)  } return ret; }
c749142000-03-28Fredrik Hübinette (Hubbe) // 20 minutes should be enough.. #define WATCHDOG_TIMEOUT 60*20
8240052000-02-22Fredrik Hübinette (Hubbe) #if constant(thread_create) #define WATCHDOG #define WATCHDOG_PIPE
d3027a2000-03-07Fredrik Hübinette (Hubbe) object watchdog_pipe;
8240052000-02-22Fredrik Hübinette (Hubbe) #else #if constant(signal) && constant(signum) #define WATCHDOG #define WATCHDOG_SIGNAL #endif #endif
d3027a2000-03-07Fredrik Hübinette (Hubbe)  #ifdef WATCHDOG
aebd8f2000-03-25Fredrik Hübinette (Hubbe) object watchdog;
d3027a2000-03-07Fredrik Hübinette (Hubbe) int use_watchdog=1;
c749142000-03-28Fredrik Hübinette (Hubbe) int watchdog_time; void signal_watchdog() { #ifdef WATCHDOG if(use_watchdog && time() - watchdog_time > 30) { watchdog_time=time(); // werror("{WATCHDOG} Ping!\n"); #ifdef WATCHDOG_PIPE watchdog_pipe->write("x",1); #endif #ifdef WATCHDOG_SIGNAL watchdog->kill(signum("SIGQUIT")); #endif } #endif }
d3027a2000-03-07Fredrik Hübinette (Hubbe) #endif
c83fb62000-03-30Henrik Grubbström (Grubba) int main(int argc, array(string) argv)
a9679f1995-11-13David Hedbor {
0df3a72001-11-14Jonas Wallden  int e, verbose, prompt, successes, errors, t, check;
4faea62000-07-26Martin Nilsson  int skipped, quiet;
c83fb62000-03-30Henrik Grubbström (Grubba)  array(string) tests; string tmp;
a9679f1995-11-13David Hedbor  program testprogram;
c3c7031996-12-04Fredrik Hübinette (Hubbe)  int start, fail, mem; int loop=1;
0073821998-04-05Fredrik Hübinette (Hubbe)  int end=0x7fffffff;
bd227a1999-01-21Fredrik Hübinette (Hubbe)  string extra_info="";
1869a91999-02-28Fredrik Hübinette (Hubbe)  int shift;
bd227a1999-01-21Fredrik Hübinette (Hubbe)  #if constant(signal) && constant(signum) if(signum("SIGQUIT")>=0) { signal(signum("SIGQUIT"),lambda() { master()->handle_error( ({"\nSIGQUIT recived, printing backtrace and continuing.\n",backtrace() }) ); }); } #endif
a9679f1995-11-13David Hedbor 
c83fb62000-03-30Henrik Grubbström (Grubba)  array(string) args=backtrace()[0][3];
ada13c1999-06-19Fredrik Hübinette (Hubbe)  array(string) testsuites=({});
086bfa1998-04-09Fredrik Hübinette (Hubbe)  args=args[..sizeof(args)-1-argc];
f751821998-04-16Fredrik Hübinette (Hubbe)  add_constant("RUNPIKE",Array.map(args,Process.sh_quote)*" ");
086bfa1998-04-09Fredrik Hübinette (Hubbe) 
73b75f1998-02-24Fredrik Hübinette (Hubbe)  foreach(Getopt.find_all_options(argv,aggregate(
d3027a2000-03-07Fredrik Hübinette (Hubbe)  ({"no-watchdog",Getopt.NO_ARG,({"--no-watchdog"})}),
8240052000-02-22Fredrik Hübinette (Hubbe)  ({"watchdog",Getopt.HAS_ARG,({"--watchdog"})}),
73b75f1998-02-24Fredrik Hübinette (Hubbe)  ({"help",Getopt.NO_ARG,({"-h","--help"})}),
97c35b2000-03-31Fredrik Hübinette (Hubbe)  ({"verbose",Getopt.MAY_HAVE_ARG,({"-v","--verbose"})}),
0df3a72001-11-14Jonas Wallden  ({"prompt",Getopt.NO_ARG,({"-p","--prompt"})}),
4faea62000-07-26Martin Nilsson  ({"quiet",Getopt.NO_ARG,({"-q","--quiet"})}),
73b75f1998-02-24Fredrik Hübinette (Hubbe)  ({"start",Getopt.HAS_ARG,({"-s","--start-test"})}),
0073821998-04-05Fredrik Hübinette (Hubbe)  ({"end",Getopt.HAS_ARG,({"--end-after"})}),
73b75f1998-02-24Fredrik Hübinette (Hubbe)  ({"fail",Getopt.MAY_HAVE_ARG,({"-f","--fail"})}), ({"loop",Getopt.MAY_HAVE_ARG,({"-l","--loop"})}), ({"trace",Getopt.MAY_HAVE_ARG,({"-t","--trace"})}), ({"check",Getopt.MAY_HAVE_ARG,({"-c","--check"})}), ({"mem",Getopt.MAY_HAVE_ARG,({"-m","--mem","--memory"})}),
ada13c1999-06-19Fredrik Hübinette (Hubbe)  ({"auto",Getopt.MAY_HAVE_ARG,({"-a","--auto"})}),
4faea62000-07-26Martin Nilsson  ({"notty",Getopt.NO_ARG,({"-T","--notty"})}),
bd227a1999-01-21Fredrik Hübinette (Hubbe) #ifdef HAVE_DEBUG ({"debug",Getopt.MAY_HAVE_ARG,({"-d","--debug"})}), #endif
73b75f1998-02-24Fredrik Hübinette (Hubbe)  )),array opt)
a9679f1995-11-13David Hedbor  {
73b75f1998-02-24Fredrik Hübinette (Hubbe)  switch(opt[0]) {
d3027a2000-03-07Fredrik Hübinette (Hubbe)  case "no-watchdog": use_watchdog=0; break;
8240052000-02-22Fredrik Hübinette (Hubbe)  case "watchdog": #ifdef WATCHDOG int cnt=0; int pid=(int)opt[1]; int last_time=time();
680b3e2000-03-01Fredrik Hübinette (Hubbe)  int exit_quietly;
8240052000-02-22Fredrik Hübinette (Hubbe) #ifdef WATCHDOG_PIPE thread_create(lambda() { object o=Stdio.File("stdin"); while(strlen(o->read(1) || "")) { // werror("[WATCHDOG] Pong!\n"); last_time=time(); } // werror("[WATCHDOG] exiting.\n");
680b3e2000-03-01Fredrik Hübinette (Hubbe)  exit_quietly=1;
8240052000-02-22Fredrik Hübinette (Hubbe)  }); #endif #ifdef WATCHDOG_SIGNAL werror("Setting signal (1)\n"); if(signum("SIGQUIT")>=0) { werror("Setting signal (2)\n"); signal(signum("SIGQUIT"),lambda() { // werror("[WATCHDOG] Pong!\n"); last_time=time(); }); }else{ exit(1); } #endif // werror("[WATCHDOG] started, watching %d.\n",pid); while(1) {
680b3e2000-03-01Fredrik Hübinette (Hubbe)  sleep(10);
03f5dc2000-03-20Fredrik Hübinette (Hubbe)  if(exit_quietly) _exit(0);
680b3e2000-03-01Fredrik Hübinette (Hubbe) #ifndef __NT__
03f5dc2000-03-20Fredrik Hübinette (Hubbe)  if(!kill(pid, 0)) _exit(0);
8240052000-02-22Fredrik Hübinette (Hubbe) #endif // werror("[WATCHDOG] t=%d\n",time()-last_time); /* I hope 30 minutes per test is enough for everybody */
c749142000-03-28Fredrik Hübinette (Hubbe)  if(time() - last_time > WATCHDOG_TIMEOUT)
8240052000-02-22Fredrik Hübinette (Hubbe)  { werror("\n[WATCHDOG] Pike testsuite timeout, sending SIGABRT.\n"); kill(pid, signum("SIGABRT"));
03f5dc2000-03-20Fredrik Hübinette (Hubbe)  for(int q=0;q<60;q++) if(!kill(pid,0)) _exit(0); else sleep(1);
8240052000-02-22Fredrik Hübinette (Hubbe)  werror("\n" "[WATCHDOG] This is your friendly watchdog again...\n" "[WATCHDOG] testsuite failed to die from SIGABRT, sending SIGKILL\n"); kill(pid, signum("SIGKILL"));
03f5dc2000-03-20Fredrik Hübinette (Hubbe)  for(int q=0;q<60;q++) if(!kill(pid,0)) _exit(0); else sleep(1);
8240052000-02-22Fredrik Hübinette (Hubbe)  werror("\n" "[WATCHDOG] This is your friendly watchdog AGAIN...\n" "[WATCHDOG] SIGKILL, SIGKILL, SIGKILL, DIE!\n"); kill(pid, signum("SIGKILL")); kill(pid, signum("SIGKILL")); kill(pid, signum("SIGKILL")); kill(pid, signum("SIGKILL"));
03f5dc2000-03-20Fredrik Hübinette (Hubbe)  for(int q=0;q<60;q++) if(!kill(pid,0)) _exit(0); else sleep(1);
8240052000-02-22Fredrik Hübinette (Hubbe)  werror("\n" "[WATCHDOG] Giving up, must be a device wait.. :(\n");
03f5dc2000-03-20Fredrik Hübinette (Hubbe)  _exit(0);
8240052000-02-22Fredrik Hübinette (Hubbe)  } } #else
03f5dc2000-03-20Fredrik Hübinette (Hubbe)  _exit(1);
8240052000-02-22Fredrik Hübinette (Hubbe) #endif break;
619f882000-01-30Fredrik Hübinette (Hubbe)  case "notty": istty_cache=-1; break;
73b75f1998-02-24Fredrik Hübinette (Hubbe)  case "help":
0df3a72001-11-14Jonas Wallden  werror("Usage: "+argv[e]+" [-v | --verbose] [-p | --prompt] [-h | --help] [-t <testno>] <testfile>\n");
73b75f1998-02-24Fredrik Hübinette (Hubbe)  return 0; case "verbose": verbose+=foo(opt[1]); break;
0df3a72001-11-14Jonas Wallden  case "prompt": prompt+=foo(opt[1]); break;
4faea62000-07-26Martin Nilsson  case "quiet": quiet=1; istty_cache=-1; break;
73b75f1998-02-24Fredrik Hübinette (Hubbe)  case "start": start=foo(opt[1]); start--; break;
0073821998-04-05Fredrik Hübinette (Hubbe)  case "end": end=foo(opt[1]); break;
73b75f1998-02-24Fredrik Hübinette (Hubbe)  case "fail": fail+=foo(opt[1]); break; case "loop": loop+=foo(opt[1]); break; case "trace": t+=foo(opt[1]); break; case "check": check+=foo(opt[1]); break; case "mem": mem+=foo(opt[1]); break;
bd227a1999-01-21Fredrik Hübinette (Hubbe) 
ada13c1999-06-19Fredrik Hübinette (Hubbe)  case "auto": testsuites=find_testsuites("."); break;
bd227a1999-01-21Fredrik Hübinette (Hubbe) #ifdef HAVE_DEBUG case "debug": { object p=Stdio.Port(); p->bind(0); werror("Debug port is: %s\n",p->query_address()); sscanf(p->query_address(),"%*s %d",int portno); extra_info+=sprintf(" dport:%d",portno); thread_create(lambda(object p){ while(p) { if(object o=p->accept()) { object q=Stdio.FILE(); q->assign(o); destruct(o); Tools.Hilfe.GenericHilfe(q,q); } } },p); } #endif
73b75f1998-02-24Fredrik Hübinette (Hubbe)  }
a9679f1995-11-13David Hedbor  }
8240052000-02-22Fredrik Hübinette (Hubbe) #ifdef WATCHDOG int watchdog_time=time();
d3027a2000-03-07Fredrik Hübinette (Hubbe)  if(use_watchdog) {
8240052000-02-22Fredrik Hübinette (Hubbe) #ifdef WATCHDOG_PIPE
d3027a2000-03-07Fredrik Hübinette (Hubbe)  object watchdog_tmp=Stdio.File(); watchdog_pipe=watchdog_tmp->pipe(Stdio.PROP_IPC); watchdog=Process.create_process( backtrace()[0][3] + ({ "--watchdog="+getpid() }), (["stdin":watchdog_tmp ])); destruct(watchdog_tmp);
8240052000-02-22Fredrik Hübinette (Hubbe) #endif
d3027a2000-03-07Fredrik Hübinette (Hubbe) 
8240052000-02-22Fredrik Hübinette (Hubbe) #ifdef WATCHDOG_SIGNAL
d3027a2000-03-07Fredrik Hübinette (Hubbe)  watchdog=Process.create_process( backtrace()[0][3] + ({ "--watchdog="+getpid() }) );
8240052000-02-22Fredrik Hübinette (Hubbe) #endif
d3027a2000-03-07Fredrik Hübinette (Hubbe)  }
c749142000-03-28Fredrik Hübinette (Hubbe)  add_constant("__signal_watchdog",signal_watchdog); #else add_constant("__signal_watchdog",lambda(){});
8240052000-02-22Fredrik Hübinette (Hubbe) #endif
ada13c1999-06-19Fredrik Hübinette (Hubbe)  argv=Getopt.get_args(argv,1)+testsuites;
73b75f1998-02-24Fredrik Hübinette (Hubbe)  if(sizeof(argv)<1)
06983f1996-09-22Fredrik Hübinette (Hubbe)  {
e42eaf1998-01-02Fredrik Hübinette (Hubbe)  if(!tmp) {
73b75f1998-02-24Fredrik Hübinette (Hubbe)  werror("No tests?\n");
e42eaf1998-01-02Fredrik Hübinette (Hubbe)  exit(1); }
06983f1996-09-22Fredrik Hübinette (Hubbe)  }
c3c7031996-12-04Fredrik Hübinette (Hubbe)  while(loop--) { successes=errors=0;
73b75f1998-02-24Fredrik Hübinette (Hubbe)  for(int f=1;f<sizeof(argv);f++)
a9679f1995-11-13David Hedbor  {
73b75f1998-02-24Fredrik Hübinette (Hubbe)  tmp=read_bytes(argv[f]); if(!tmp)
a9679f1995-11-13David Hedbor  {
1ab6792000-10-08Henrik Grubbström (Grubba)  werror("Failed to read test file %O, errno=%d.\n", argv[f], errno());
73b75f1998-02-24Fredrik Hübinette (Hubbe)  exit(1);
a9679f1995-11-13David Hedbor  }
c3c7031996-12-04Fredrik Hübinette (Hubbe) 
73b75f1998-02-24Fredrik Hübinette (Hubbe)  tests=tmp/"\n....\n"; tmp=0; tests=tests[0..sizeof(tests)-2];
c3c7031996-12-04Fredrik Hübinette (Hubbe) 
73b75f1998-02-24Fredrik Hübinette (Hubbe)  werror("Doing tests in %s (%d tests)\n",argv[f],sizeof(tests));
9ac7792000-07-28Martin Nilsson  int qmade, qskipped, qmadep, qskipp;
c3c7031996-12-04Fredrik Hübinette (Hubbe) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  for(e=start;e<sizeof(tests);e++) {
c749142000-03-28Fredrik Hübinette (Hubbe)  signal_watchdog();
8240052000-02-22Fredrik Hübinette (Hubbe)  int skip=0;
1869a91999-02-28Fredrik Hübinette (Hubbe)  string test,condition;
a2c6f41999-12-10Henrik Grubbström (Grubba)  string|int type;
1869a91999-02-28Fredrik Hübinette (Hubbe)  object o; mixed a,b;
73b75f1998-02-24Fredrik Hübinette (Hubbe) 
a571702000-04-14Fredrik Hübinette (Hubbe)  if(check) { if(check < 0) { if(!(e % -check)) _verify_internals(); }else{ _verify_internals(); } }
0c75741999-10-21Henrik Grubbström (Grubba)  if(check>3) { gc(); _verify_internals(); }
c3c7031996-12-04Fredrik Hübinette (Hubbe) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  test=tests[e]; if(sscanf(test,"COND %s\n%s",condition,test)==2)
dddccc1998-04-15Fredrik Hübinette (Hubbe)  {
1869a91999-02-28Fredrik Hübinette (Hubbe)  int tmp; if(!(tmp=cond_cache[condition])) {
61bc3d2000-04-05Henrik Grubbström (Grubba)  mixed err; if (err = catch { tmp=!!(compile_string("mixed c() { return "+condition+"; }", "Cond "+(e+1))()->c()); }) { werror(sprintf("\nConditional %d failed:\n" "%s\n", e+1, describe_backtrace(err))); errors++; tmp = -1; }
1869a91999-02-28Fredrik Hübinette (Hubbe)  if(!tmp) tmp=-1; cond_cache[condition]=tmp; }
dddccc1998-04-15Fredrik Hübinette (Hubbe) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  if(tmp==-1) { if(verbose) werror("Not doing test "+(e+1)+"\n"); successes++;
284dce1999-08-24Fredrik Hübinette (Hubbe)  skipped++;
8240052000-02-22Fredrik Hübinette (Hubbe)  skip=1; } } if(istty()) {
06fe872000-05-16Fredrik Hübinette (Hubbe)  if(!verbose) werror("%6d\r",e+1);
9ac7792000-07-28Martin Nilsson  }else if(quiet){ if(skip) { if(qmade) werror(" Made %d test%s.\n", qmade, qmade==1?"":"s"); qmade=0; qskipp=1; qskipped++; } else { if(qskipped) werror(" Skipped %d test%s.\n", qskipped, qskipped==1?"":"s"); qskipped=0; qmadep=1; qmade++; } }else{
8240052000-02-22Fredrik Hübinette (Hubbe)  /* Use + instead of . so that sendmail and * cron will not cut us off... :( */ switch( (e-start) % 50) { case 0: werror("%5d: ",e); break; case 9: case 19: case 29: case 39: werror(skip?"- ":"+ "); break; default: werror(skip?"-":"+"); break; case 49: werror(skip?"-\n":"+\n");
1869a91999-02-28Fredrik Hübinette (Hubbe)  }
73b75f1998-02-24Fredrik Hübinette (Hubbe)  }
8240052000-02-22Fredrik Hübinette (Hubbe)  if(skip) continue;
c3c7031996-12-04Fredrik Hübinette (Hubbe) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  sscanf(test,"%s\n%s",type,test); sscanf(type,"%*s expected result: %s",type);
c3c7031996-12-04Fredrik Hübinette (Hubbe) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  if(verbose) {
0df3a72001-11-14Jonas Wallden  if (prompt) { if (Stdio.Readline()-> read(sprintf("About to run test: %d. [<RETURN>/'quit']: ", e + 1)) == "quit") { f = 999999; break; } }
1869a91999-02-28Fredrik Hübinette (Hubbe)  werror("Doing test %d (%d total)%s\n",e+1,successes+errors+1,extra_info);
394d7d1999-04-08Fredrik Hübinette (Hubbe)  if(verbose>1) bzot(test);
1869a91999-02-28Fredrik Hübinette (Hubbe)  }
475a841999-02-20Henrik Grubbström (Grubba) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  if(check > 1) _verify_internals();
c3c7031996-12-04Fredrik Hübinette (Hubbe) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  shift++; string fname = argv[f] + ": Test " + (e + 1) +
a4db192000-02-27Fredrik Hübinette (Hubbe)  " (shift " + (shift%3) + ")";
475a841999-02-20Henrik Grubbström (Grubba) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  string widener = ([ 0:"",
475a841999-02-20Henrik Grubbström (Grubba)  1:"\nint \x30c6\x30b9\x30c8=0;\n",
1869a91999-02-28Fredrik Hübinette (Hubbe)  2:"\nint \x10001=0;\n" ])[shift%3];
a2c6f41999-12-10Henrik Grubbström (Grubba) 
63e4d22000-03-30Henrik Grubbström (Grubba)  // widener += "#pragma strict_types\n";
a2c6f41999-12-10Henrik Grubbström (Grubba) 
53db3a1999-10-28Fredrik Hübinette (Hubbe)  if(test[-1]!='\n') test+="\n"; int computed_line=sizeof(test/"\n"); array gnapp= test/"#";
db3ddf2000-03-31Fredrik Hübinette (Hubbe)  for(int e=1;e<sizeof(gnapp);e++)
53db3a1999-10-28Fredrik Hübinette (Hubbe)  { if(sscanf(gnapp[e],"%*d")) { computed_line=0; break; } }
a2c6f41999-12-10Henrik Grubbström (Grubba)  string linetester="int __cpp_line=__LINE__; int __rtl_line=[int]backtrace()[-1][1];\n";
32a6ac1998-04-11Henrik Grubbström (Grubba) 
53db3a1999-10-28Fredrik Hübinette (Hubbe)  string to_compile = test + linetester + widener;
a4db192000-02-27Fredrik Hübinette (Hubbe)  if((shift/3)&1) { fname+=" (CRNL)"; to_compile=replace(to_compile,"\n","\r\n"); }
1ab6792000-10-08Henrik Grubbström (Grubba)  // _optimizer_debug(5);
97c35b2000-03-31Fredrik Hübinette (Hubbe)  if(verbose>9) bzot(to_compile);
1869a91999-02-28Fredrik Hübinette (Hubbe)  switch(type) {
06fe872000-05-16Fredrik Hübinette (Hubbe)  mixed at,bt; mixed err;
1869a91999-02-28Fredrik Hübinette (Hubbe)  case "COMPILE":
6657a51999-10-21Fredrik Hübinette (Hubbe)  _dmalloc_set_name(fname,0);
53db3a1999-10-28Fredrik Hübinette (Hubbe)  if(catch(compile_string(to_compile, fname)))
1869a91999-02-28Fredrik Hübinette (Hubbe)  {
6657a51999-10-21Fredrik Hübinette (Hubbe)  _dmalloc_set_name();
1869a91999-02-28Fredrik Hübinette (Hubbe)  werror(fname + " failed.\n");
394d7d1999-04-08Fredrik Hübinette (Hubbe)  bzot(test);
1869a91999-02-28Fredrik Hübinette (Hubbe)  errors++; }else{
6657a51999-10-21Fredrik Hübinette (Hubbe)  _dmalloc_set_name();
1869a91999-02-28Fredrik Hübinette (Hubbe)  successes++; } break;
086bfa1998-04-09Fredrik Hübinette (Hubbe) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  case "COMPILE_ERROR": master()->set_inhibit_compile_errors(1);
6657a51999-10-21Fredrik Hübinette (Hubbe)  _dmalloc_set_name(fname,0);
53db3a1999-10-28Fredrik Hübinette (Hubbe)  if(catch(compile_string(to_compile, fname)))
1869a91999-02-28Fredrik Hübinette (Hubbe)  {
6657a51999-10-21Fredrik Hübinette (Hubbe)  _dmalloc_set_name();
1869a91999-02-28Fredrik Hübinette (Hubbe)  successes++; }else{
6657a51999-10-21Fredrik Hübinette (Hubbe)  _dmalloc_set_name();
1869a91999-02-28Fredrik Hübinette (Hubbe)  werror(fname + " failed.\n");
394d7d1999-04-08Fredrik Hübinette (Hubbe)  bzot(test);
1869a91999-02-28Fredrik Hübinette (Hubbe)  errors++; } master()->set_inhibit_compile_errors(0); break;
73b75f1998-02-24Fredrik Hübinette (Hubbe) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  case "EVAL_ERROR": master()->set_inhibit_compile_errors(1);
6657a51999-10-21Fredrik Hübinette (Hubbe)  _dmalloc_set_name(fname,0);
06fe872000-05-16Fredrik Hübinette (Hubbe)  at = gauge { err=catch { clone(compile_string(to_compile, fname))->a(); }; }; if(err)
1869a91999-02-28Fredrik Hübinette (Hubbe)  {
6657a51999-10-21Fredrik Hübinette (Hubbe)  _dmalloc_set_name();
1869a91999-02-28Fredrik Hübinette (Hubbe)  successes++;
06fe872000-05-16Fredrik Hübinette (Hubbe)  if(verbose>2) werror("Time in a(): %f\n",at);
1869a91999-02-28Fredrik Hübinette (Hubbe)  }else{
6657a51999-10-21Fredrik Hübinette (Hubbe)  _dmalloc_set_name();
1869a91999-02-28Fredrik Hübinette (Hubbe)  werror(fname + " failed.\n");
394d7d1999-04-08Fredrik Hübinette (Hubbe)  bzot(test);
1869a91999-02-28Fredrik Hübinette (Hubbe)  errors++; } master()->set_inhibit_compile_errors(0); break;
73b75f1998-02-24Fredrik Hübinette (Hubbe) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  default:
433b1d1999-03-06Henrik Grubbström (Grubba)  if (err = catch{
6657a51999-10-21Fredrik Hübinette (Hubbe)  _dmalloc_set_name(fname,0);
53db3a1999-10-28Fredrik Hübinette (Hubbe)  o=clone(compile_string(to_compile,fname));
6657a51999-10-21Fredrik Hübinette (Hubbe)  _dmalloc_set_name();
73b75f1998-02-24Fredrik Hübinette (Hubbe) 
433b1d1999-03-06Henrik Grubbström (Grubba)  if(check > 1) _verify_internals();
73b75f1998-02-24Fredrik Hübinette (Hubbe) 
433b1d1999-03-06Henrik Grubbström (Grubba)  a=b=0; if(t) trace(t);
6657a51999-10-21Fredrik Hübinette (Hubbe)  _dmalloc_set_name(fname,1);
06fe872000-05-16Fredrik Hübinette (Hubbe)  if(functionp(o->a)) {
1ab6792000-10-08Henrik Grubbström (Grubba)  // trace(10);
06fe872000-05-16Fredrik Hübinette (Hubbe)  at = gauge { a=o->a(); };
1ab6792000-10-08Henrik Grubbström (Grubba)  // trace(0);
06fe872000-05-16Fredrik Hübinette (Hubbe)  } if(functionp(o->b)) { bt = gauge { b=o->b(); }; }
6657a51999-10-21Fredrik Hübinette (Hubbe)  _dmalloc_set_name();
433b1d1999-03-06Henrik Grubbström (Grubba)  if(t) trace(0); if(check > 1) _verify_internals();
53db3a1999-10-28Fredrik Hübinette (Hubbe) 
433b1d1999-03-06Henrik Grubbström (Grubba)  }) {
1ab6792000-10-08Henrik Grubbström (Grubba)  // trace(0);
433b1d1999-03-06Henrik Grubbström (Grubba)  werror(fname + " failed.\n");
20a9341999-05-11Fredrik Hübinette (Hubbe)  bzot(test);
433b1d1999-03-06Henrik Grubbström (Grubba)  if (arrayp(err) && sizeof(err) && stringp(err[0])) {
78db651999-08-29Fredrik Hübinette (Hubbe)  werror("Error: " + master()->describe_backtrace(err));
433b1d1999-03-06Henrik Grubbström (Grubba)  }
20a9341999-05-11Fredrik Hübinette (Hubbe)  if (objectp(err)) {
78db651999-08-29Fredrik Hübinette (Hubbe)  werror("Error: " + master()->describe_backtrace(err));
20a9341999-05-11Fredrik Hübinette (Hubbe)  }
433b1d1999-03-06Henrik Grubbström (Grubba)  errors++; break; }
53db3a1999-10-28Fredrik Hübinette (Hubbe)  if( o->__cpp_line != o->__rtl_line || ( computed_line && computed_line!=o->__cpp_line)) { werror(fname + " Line numbering failed.\n"); bzot(test + linetester); werror(" CPP lines: %d\n",o->__cpp_line); werror(" RTL lines: %d\n",o->__rtl_line); if(computed_line) werror("Actual lines: %d\n",computed_line); errors++; }
06fe872000-05-16Fredrik Hübinette (Hubbe)  if(verbose>2) werror("Time in a(): %f, Time in b(): %O\n",at,bt);
73b75f1998-02-24Fredrik Hübinette (Hubbe) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  switch(type) { case "FALSE": if(a) { werror(fname + " failed.\n");
394d7d1999-04-08Fredrik Hübinette (Hubbe)  bzot(test);
1869a91999-02-28Fredrik Hübinette (Hubbe)  werror(sprintf("o->a(): %O\n",a)); errors++; }else{ successes++; } break;
73b75f1998-02-24Fredrik Hübinette (Hubbe) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  case "TRUE": if(!a) { werror(fname + " failed.\n");
394d7d1999-04-08Fredrik Hübinette (Hubbe)  bzot(test);
1869a91999-02-28Fredrik Hübinette (Hubbe)  werror(sprintf("o->a(): %O\n",a)); errors++; }else{ successes++; } break; case "RUN":
73b75f1998-02-24Fredrik Hübinette (Hubbe)  successes++;
1869a91999-02-28Fredrik Hübinette (Hubbe)  break;
73b75f1998-02-24Fredrik Hübinette (Hubbe) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  case "EQ": if(a!=b) { werror(fname + " failed.\n");
394d7d1999-04-08Fredrik Hübinette (Hubbe)  bzot(test);
1869a91999-02-28Fredrik Hübinette (Hubbe)  werror(sprintf("o->a(): %O\n",a)); werror(sprintf("o->b(): %O\n",b)); errors++; }else{ successes++; } break;
73b75f1998-02-24Fredrik Hübinette (Hubbe) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  case "EQUAL": if(!equal(a,b)) { werror(fname + " failed.\n");
394d7d1999-04-08Fredrik Hübinette (Hubbe)  bzot(test);
1869a91999-02-28Fredrik Hübinette (Hubbe)  werror(sprintf("o->a(): %O\n",a)); werror(sprintf("o->b(): %O\n",b)); errors++; }else{ successes++; } break;
73b75f1998-02-24Fredrik Hübinette (Hubbe) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  default: werror(sprintf("%s: Unknown test type (%O).\n", fname, type));
73b75f1998-02-24Fredrik Hübinette (Hubbe)  errors++;
1869a91999-02-28Fredrik Hübinette (Hubbe)  } }
73b75f1998-02-24Fredrik Hübinette (Hubbe) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  if(check > 2) _verify_internals();
73b75f1998-02-24Fredrik Hübinette (Hubbe) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  if(fail && errors) exit(1);
475a841999-02-20Henrik Grubbström (Grubba) 
9854472000-07-17Henrik Grubbström (Grubba)  if(!--end) break;
73b75f1998-02-24Fredrik Hübinette (Hubbe) 
1869a91999-02-28Fredrik Hübinette (Hubbe)  a=b=0;
9ac7792000-07-28Martin Nilsson  }
619f882000-01-30Fredrik Hübinette (Hubbe)  if(istty()) { werror(" \r");
9ac7792000-07-28Martin Nilsson  }else if(quiet){ if(!qskipp && !qmadep); else if(!qskipp) werror("Made all tests\n"); else if(!qmadep) werror("Skipped all tests\n"); else if(qmade) werror(" Made %d test%s.\n", qmade, qmade==1?"":"s"); else if(qskipped) werror(" Skipped %d test%s.\n", qskipped, qskipped==1?"":"s"); }else{
619f882000-01-30Fredrik Hübinette (Hubbe)  werror("\n"); }
c3c7031996-12-04Fredrik Hübinette (Hubbe)  }
73b75f1998-02-24Fredrik Hübinette (Hubbe)  if(mem)
c3c7031996-12-04Fredrik Hübinette (Hubbe)  {
73b75f1998-02-24Fredrik Hübinette (Hubbe)  int total; tests=0; gc(); mapping tmp=_memory_usage(); write(sprintf("%-10s: %6s %10s\n","Category","num","bytes")); foreach(sort(indices(tmp)),string foo) { if(sscanf(foo,"%s_bytes",foo)) { write(sprintf("%-10s: %6d %10d\n", foo+"s", tmp["num_"+foo+"s"], tmp[foo+"_bytes"])); total+=tmp[foo+"_bytes"]; } } write(sprintf("%-10s: %6s %10d\n", "Total", "", total));
c3c7031996-12-04Fredrik Hübinette (Hubbe)  }
a9679f1995-11-13David Hedbor  }
b455c81998-03-20Fredrik Hübinette (Hubbe)  if(errors || verbose) { werror("Failed tests: "+errors+".\n"); }
284dce1999-08-24Fredrik Hübinette (Hubbe)  werror("Total tests: %d (%d tests skipped)\n",successes+errors,skipped);
a9679f1995-11-13David Hedbor 
8240052000-02-22Fredrik Hübinette (Hubbe) #ifdef WATCHDOG_SIGNAL
d3027a2000-03-07Fredrik Hübinette (Hubbe)  if(use_watchdog)
03f5dc2000-03-20Fredrik Hübinette (Hubbe)  {
d3027a2000-03-07Fredrik Hübinette (Hubbe)  watchdog->kill(signum("SIGKILL"));
03f5dc2000-03-20Fredrik Hübinette (Hubbe)  watchdog->wait(); } #endif #ifdef WATCHDOG_PIPE if(use_watchdog) { destruct(watchdog_pipe); #if constant(signum) catch { watchdog->kill(signum("SIGKILL")); }; #endif watchdog->wait(); }
8240052000-02-22Fredrik Hübinette (Hubbe) #endif
a9679f1995-11-13David Hedbor  return errors; }