PageRenderTime 2778ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/query/run.pl

https://github.com/66laps/4store
Perl | 120 lines | 105 code | 12 blank | 3 comment | 24 complexity | b4ce77a4f5d9186407b9f80e33b7ea95 MD5 | raw file
  1. #!/usr/bin/perl -w
  2. use Term::ANSIColor;
  3. $kb_name = "query_test_".$ENV{'USER'};
  4. # names of tests that require LAQRS support
  5. my @need_laqrs = ('count', 'union-nobind');
  6. $dirname=`dirname '$0'`;
  7. chomp $dirname;
  8. chdir($dirname) || die "cannot cd to $dirname";
  9. $outdir = "results";
  10. $test = 1;
  11. my @tests = ();
  12. my $errs = 1;
  13. my $spawn = 1;
  14. $SIG{USR2} = 'IGNORE';
  15. if ($ARGV[0]) {
  16. if ($ARGV[0] eq "--exemplar") {
  17. $outdir = "exemplar";
  18. $test = 0;
  19. $errs = 0;
  20. shift;
  21. } elsif ($ARGV[0] eq "--outdir") {
  22. shift;
  23. $outdir = shift;
  24. $test = 1;
  25. } elsif ($ARGV[0] eq "--nospawn") {
  26. shift;
  27. $spawn = 0;
  28. }
  29. while ($t = shift) {
  30. $t =~ s/^(.\/)?scripts\///;
  31. push @tests, $t;
  32. }
  33. }
  34. mkdir($outdir);
  35. if (!@tests) {
  36. @tests = `ls scripts`;
  37. chomp @tests;
  38. }
  39. if (`../../src/frontend/4s-query -h 2>&1 | grep LAQRS` eq '') {
  40. my %tmp;
  41. foreach $t (@tests) { $tmp{$t} ++; }
  42. foreach $t (@need_laqrs) { delete $tmp{$t}; }
  43. @tests = sort keys %tmp;
  44. }
  45. if ($pid = fork()) {
  46. sleep(2);
  47. my $fails = 0;
  48. my $passes = 0;
  49. for $t (@tests) {
  50. chomp $t;
  51. if (!stat("exemplar/$t") && $test) {
  52. print("SKIP $t (no exemplar)\n");
  53. next;
  54. }
  55. unlink("$outdir/".$t);
  56. if ($errs) {
  57. $errout = "2>$outdir/$t-errs";
  58. } else {
  59. $errout = "";
  60. }
  61. print("[....] $t\r");
  62. my $ret = system("FORMAT=ascii LANG=C LC_ALL=C TESTPATH=../../src scripts/$t $kb_name > $outdir/$t $errout");
  63. if ($ret == 2) {
  64. exit(2);
  65. }
  66. if ($test) {
  67. @diff = `diff exemplar/$t $outdir/$t 2>/dev/null`;
  68. if (@diff) {
  69. print("[");
  70. print color 'bold red';
  71. print("FAIL");
  72. print color 'reset';
  73. print("] $t\n");
  74. open(RES, ">> $outdir/$t-errs") || die 'cannot open error file';
  75. print RES "\n";
  76. print RES @diff;
  77. close(RES);
  78. $fails++;
  79. } else {
  80. print("[");
  81. print color 'bold green';
  82. print("PASS");
  83. print color 'reset';
  84. print("] $t\n");
  85. $passes++;
  86. }
  87. } else {
  88. print("[PROC] $t\n");
  89. }
  90. }
  91. print("Tests completed: passed $passes/".($fails+$passes)." ($fails fails)\n");
  92. $ret = kill 15, $pid;
  93. if (!$ret) {
  94. warn("failed to kill server process, pid $pid");
  95. } else {
  96. waitpid($pid, 0);
  97. }
  98. if ($fails) {
  99. exit(1);
  100. }
  101. exit(0);
  102. } else {
  103. # child
  104. if ($spawn) {
  105. exec("../../src/backend/4s-backend", "-D", "-l", "2.0", "$kb_name");
  106. die "failed to exec sever: $!";
  107. }
  108. }