Introduce a test runner script to simplify invocation

... And to use a standard, highly amusing trick for making
coloured output work.
This commit is contained in:
Chris Kitching
2017-10-18 13:50:00 +01:00
parent 5912f465bd
commit c99dcbba8d
4 changed files with 34 additions and 3 deletions
+4 -2
View File
@@ -6,9 +6,10 @@ option(HIPIFY_CLANG_TESTS "Build the tests for hipify-clang, if lit is installed
# Disable the tests if `lit` or `FileCheck` is not installed.
find_program(LIT_COMMAND lit)
find_program(FILECHECK_COMMAND FileCheck)
if (NOT LIT_COMMAND OR NOT FILECHECK_COMMAND)
find_program(SOCAT_COMMAND socat)
if (NOT LIT_COMMAND OR NOT FILECHECK_COMMAND OR NOT SOCAT_COMMAND)
set(HIPIFY_CLANG_TESTS OFF CACHE INTERNAL "")
message(STATUS "hipify-clang's tests are not being built because `lit` or `FileCheck` could not be found.")
message(STATUS "hipify-clang's tests are not being built because `lit`,`FileCheck` or `socat` could not be found.")
endif()
set(BUILD_HIPIFY_CLANG 0 CACHE INTERNAL "")
@@ -88,6 +89,7 @@ if (HIPIFY_CLANG_TESTS)
add_lit_testsuite(test-hipify "Running HIPify regression tests"
${CMAKE_SOURCE_DIR}/tests/hipify-clang
PARAMS site_config=${CMAKE_CURRENT_BINARY_DIR}/tests/hipify-clang/lit.site.cfg
ARGS -v
DEPENDS hipify-clang
)
+1 -1
View File
@@ -1,4 +1,4 @@
// RUN: hipify "%s" -o=%t -- %cuda_args && cat %t | sed -Ee 's|//.+|// |g' | FileCheck %s
// RUN: %run_test hipify "%s" "%t" %cuda_args
#include <iostream>
+1
View File
@@ -48,3 +48,4 @@ config.substitutions.append(("hipify", obj_root+"/hipify-clang"))
# Clang args for CUDA...
config.substitutions.append(("%cuda_args", "-x cuda --cuda-path=%s --cuda-gpu-arch=sm_30" % config.cuda_root))
config.substitutions.append(("%run_test", config.test_source_root + "/run_test.sh"))
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -o errexit
# Run a single LIT test file in a magical way that preserves colour output, to work around
# a known flaw in lit.
# Capture lit substitutions
HIPIFY=$1
IN_FILE=$2
TMP_FILE=$3
shift 3
# Remaining args are the ones to forward to clang proper.
# Time for the classic insane little trick for making colour output work.
# A self-deleting shell-script that does the thing we want to do...
TMP_SCRIPT=$(mktemp)
cat << EOF > $TMP_SCRIPT
set -o errexit
set -o xtrace
rm $TMP_SCRIPT
$HIPIFY -o=$TMP_FILE $IN_FILE -- $@ && cat $TMP_FILE | sed -Ee 's|//.+|// |g' | FileCheck $IN_FILE
EOF
chmod a+x $TMP_SCRIPT
# Run the script via socat, spawning a virtual terminal and propagating exit code, and hence failure.
socat -du EXEC:$TMP_SCRIPT,pty,stderr STDOUT