message: Testing/FileCheck: Add a sanity for the FileCheck binary and disable FileCheck
  tests if it fails.
  Bug
  git-commit
  git-author Bryce Adelstein Lelbach aka wash
  VDVS:
  Jobs:
  [git-p4: depot-paths = "//sw/gpgpu/thrust/": change = 24223396]
diff: @@ -224,6 +224,42 @@ sub process_return_code {
  }
  }
  +my $have_filecheck = 1;
  +
  +sub filecheck_sanity {
  + my $filecheck_cmd = "$filecheck_path/FileCheck $filecheck_data_path/thrust.sanity.filecheck";
  +
  + my $filecheck_pid = open(my $filecheck_stdin, "|-", "$filecheck_cmd 2>&1");
  +
  + print $filecheck_stdin "SANITY";
  +
  + my $filecheck_ret = 0;
  + if (close($filecheck_stdin) == 0)
  + {
  + $filecheck_ret = $?;
  + }
  +
  + if ($filecheck_ret == 0) {
  + printf("#### SANE FileCheck\n");
  + } else {
  + # Use a temporary file to send the output to
  + # FileCheck so we can get the output this time,
  + # because Perl and bidirectional pipes suck.
  + my $tmp = File::Temp->new();
  + my $tmp_filename = $tmp->filename;
  + print $tmp "SANITY";
  +
  + printf("********************************************************************************\n");
  + print `$filecheck_cmd -input-file $tmp_filename`;
  + printf("********************************************************************************\n");
  +
  + process_return_code("FileCheck Sanity", $filecheck_ret, "");
  + printf("#### INSANE FileCheck\n");
  +
  + $have_filecheck = 0;
  + }
  +}
  +
  # Wrapper for system that logs the commands so you can see what it did
  sub run_cmd {
  my ($cmd) = @_;
  @@ -336,6 +372,7 @@ sub run_examples {
  printf("#### WALLTIME $test %.2f [s]\n", $elapsed);
  $passes = $passes + 1;
  + if ($have_filecheck) {
  # Check output with LLVM FileCheck.
  printf("&&&& RUNNING FileCheck $test\n");
  @@ -391,6 +428,7 @@ sub run_examples {
  $errors = $errors + 1;
  }
  }
  + }
  printf("\n");
  }
  }
  @@ -486,6 +524,7 @@ sub run_unit_tests {
  printf("&&&& PASSED $test\n");
  printf("#### WALLTIME $test %.2f [s]\n", $elapsed);
  + if ($have_filecheck) {
  # Check output with LLVM FileCheck if the test has a FileCheck input.
  if (-f "${filecheck_data_path}/${test}.filecheck") {
  @@ -538,6 +577,7 @@ sub run_unit_tests {
  }
  }
  }
  + }
  } else {
  $errors = $errors + 1;
  process_return_code($test, $ret, "Test crash?");
  @@ -582,9 +622,13 @@ printf("#### CONFIG have_time_hi_res `$have_time_hi_res`\n");
  printf("\n");
  +clear_libpath();
  +filecheck_sanity();
  +
  +printf("\n");
  +
  my $START_TIME = current_time();
  -clear_libpath();
  run_examples();
  run_unit_tests();
  