diff --git a/projects/hip/tests/hit/HIT.cmake b/projects/hip/tests/hit/HIT.cmake index 847f8fdadd..82f0c5eabf 100644 --- a/projects/hip/tests/hit/HIT.cmake +++ b/projects/hip/tests/hit/HIT.cmake @@ -78,6 +78,33 @@ macro(PARSE_RUN_COMMAND _target _arguments _exclude_platforms) endforeach() endmacro() +# Helper macro to parse RUN_NAMED instructions +macro(PARSE_RUN_NAMED_COMMAND _target _testname _arguments _exclude_platforms) + set(${_target}) + set(${_arguments} " ") + set(${_exclude_platforms}) + set(_target_found FALSE) + set(_testname_found FALSE) + set(_exclude_platforms_found FALSE) + foreach(arg ${ARGN}) + if(NOT _target_found) + set(_target_found TRUE) + set(${_target} ${arg}) + elseif(NOT _testname_found) + set(_testname_found TRUE) + set(${_testname} ${arg}) + elseif("x${arg}" STREQUAL "xEXCLUDE_HIP_PLATFORM") + set(_exclude_platforms_found TRUE) + else() + if(_exclude_platforms_found) + set(${_exclude_platforms} ${arg}) + else() + list(APPEND ${_arguments} ${arg}) + endif() + endif() + endforeach() +endmacro() + # Helper macro to insert key/value pair into "hashmap" macro(INSERT_INTO_MAP _map _key _value) set("${_map}_${_key}" "${_value}") @@ -95,6 +122,12 @@ macro(MAKE_TEST exe) add_test(NAME ${testname} COMMAND ${PROJECT_BINARY_DIR}/${exe} ${ARGN}) set_tests_properties(${testname} PROPERTIES PASS_REGULAR_EXPRESSION "PASSED") endmacro() + +macro(MAKE_NAMED_TEST exe _testname) + set(testname ${PROJECT_NAME}/${_testname}.tst) + add_test(NAME ${testname} COMMAND ${PROJECT_BINARY_DIR}/${exe} ${ARGN}) + set_tests_properties(${testname} PROPERTIES PASS_REGULAR_EXPRESSION "PASSED") +endmacro() #------------------------------------------------------------------------------- # Macro: HIT_ADD_FILES used to scan+add multiple files for testing. @@ -135,6 +168,24 @@ macro(HIT_ADD_FILES _dir) make_test(${_target} ${_arguments}) endif() endforeach() + + # Add named tests + execute_process(COMMAND ${HIP_SRC_PATH}/tests/hit/parser --runNamedCMDs ${file} + OUTPUT_VARIABLE _contents + ERROR_QUIET + WORKING_DIRECTORY ${_dir} + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(REGEX REPLACE "\n" ";" _contents "${_contents}") + foreach(_cmd ${_contents}) + string(REGEX REPLACE " " ";" _cmd "${_cmd}") + parse_run_named_command(_target _testname _arguments _exclude_platforms ${_cmd}) + read_from_map("_exclude" "${_target}" _exclude_platforms_from_build) + if(_exclude_platforms STREQUAL "all" OR _exclude_platforms STREQUAL ${HIP_PLATFORM} OR + _exclude_platforms_from_build STREQUAL "all" OR _exclude_platforms_from_build STREQUAL ${HIP_PLATFORM}) + else() + make_named_test(${_target} ${_testname} ${_arguments}) + endif() + endforeach() endforeach() endmacro() diff --git a/projects/hip/tests/hit/parser b/projects/hip/tests/hit/parser index 6f6f842587..3d851752e4 100755 --- a/projects/hip/tests/hit/parser +++ b/projects/hip/tests/hit/parser @@ -8,29 +8,38 @@ use File::Spec; sub parse_file { my $file = shift; (my $exe = $file) =~ s/\.[^.]+$//g; - my (@buildCMDs, @runCMDs); + my (@buildCMDs, @runCMDs, @runNamedCMDs); if (open (SOURCE, '<:encoding(UTF-8)', "$file")) { while () { my $line=$_; # Look for BUILD instructions if ($line =~ /^ \* BUILD:/) { - $line =~ s/^ \* BUILD: //g; # Remove " * BUILD: " - $line =~ s/%s/$file/g; # Substitute %s -> filename - $line =~ s/%t/$exe/g; # Substitute %t -> targetname - $line =~ s/\R//g; # Remove line endings + $line =~ s/^ \* BUILD: //g; # Remove " * BUILD: " + $line =~ s/%s/$file/g; # Substitute %s -> filename + $line =~ s/%t/$exe/g; # Substitute %t -> targetname + $line =~ s/\R//g; # Remove line endings push @buildCMDs, $line; } # Look for RUN instructions if ($line =~ /^ \* RUN:/) { - $line =~ s/^ \* RUN: //g; # Remove " * RUN: " - $line =~ s/%t/$exe/g; # Subsitute %t -> targetname - $line =~ s/\R//g; # Remove line endings + $line =~ s/^ \* RUN: //g; # Remove " * RUN: " + $line =~ s/%s/$file/g; # Substitute %s -> filename + $line =~ s/%t/$exe/g; # Subsitute %t -> targetname + $line =~ s/\R//g; # Remove line endings push @runCMDs, $line; } + # Look for RUN_NAMED instructions + if ($line =~ /^ \* RUN_NAMED:/) { + $line =~ s/^ \* RUN_NAMED: //g; # Remove " * RUN_NAMED: " + $line =~ s/%s/$file/g; # Substitute %s -> filename + $line =~ s/%t/$exe/g; # Subsitute %t -> targetname + $line =~ s/\R//g; # Remove line endings + push @runNamedCMDs, $line; + } } close(SOURCE); } - return (\@buildCMDs, \@runCMDs); + return (\@buildCMDs, \@runCMDs, \@runNamedCMDs); } # Exit if no arguments specified @@ -43,8 +52,9 @@ if(scalar @ARGV == 0){ my @options = (); my $retBuildCMDs = 0; my $retRunCMDs = 0; +my $retRunNamedCMDs = 0; foreach $arg (@ARGV) { - if ($retBuildCMDs or $retRunCMDs) { + if ($retBuildCMDs or $retRunCMDs or $retRunNamedCMDs) { push (@options, $arg); } if ($arg eq '--buildCMDs') { @@ -53,18 +63,21 @@ foreach $arg (@ARGV) { if ($arg eq '--runCMDs') { $retRunCMDs = 1; } + if ($arg eq '--runNamedCMDs') { + $retRunNamedCMDs = 1; + } } # Atleast one command needs to be specified -if ($retBuildCMDs eq 0 and $retRunCMDs eq 0) { - die "Usage: $0 <--buildCMDs|--runCMDs> FILENAMEs\n"; +if (($retBuildCMDs eq 0) and ($retRunCMDs eq 0) and ($retRunNamedCMDs eq 0)) { + die "Usage: $0 <--buildCMDs|--runCMDs|--runNamedCMDs> FILENAMEs\n"; } # Iterate over input files foreach $file (@options) { # Convert absolute path to path relative to working directory my $relfile = File::Spec->abs2rel($file); - my ($buildCMDs, $runCMDs) = parse_file("$relfile"); + my ($buildCMDs, $runCMDs, $runNamedCMDs) = parse_file("$relfile"); if ($retBuildCMDs) { # print "BuildCMDs:\n"; print "$_\n" for @$buildCMDs; @@ -73,6 +86,10 @@ foreach $file (@options) { # print "RunCMDs:\n"; print "$_\n" for @$runCMDs; } + if ($retRunNamedCMDs) { + # print "RunNamedCMDs:\n"; + print "$_\n" for @$runNamedCMDs; + } } # vim: ts=4:sw=4:expandtab:smartindent