diff --git a/projects/hip/tests/README.md b/projects/hip/tests/README.md index e0a7254963..b1f70048a1 100644 --- a/projects/hip/tests/README.md +++ b/projects/hip/tests/README.md @@ -57,6 +57,20 @@ NVCC_OPTIONS: All options specified after this delimiter are passed to hipcc on EXCLUDE_HIP_PLATFORM: This can be used to exclude a test case from HCC, NVCC or both platforms. +#### BUILD_CMD command + +The supported syntax for the BUILD_CMD command is: +``` +BUILD_CMD: EXCLUDE_HIP_PLATFORM +``` +%s: refers to current source file name. Additional source files needed for the test can be specified by name (including relative path). +%t: refers to target executable named derived by removing the extension from the current source file. Alternatively a target executable name can be specified. +%hc: refers to hipcc pointed to by $CMAKE_INSTALL_PREFIX/bin/hipcc. +%cc: refers to system c compiler pointed to by $CC. +%S: refers to path to current source file. +%T: refers to path to current build target. + + #### TEST command The supported syntax for the TEST command is: diff --git a/projects/hip/tests/hit/HIT.cmake b/projects/hip/tests/hit/HIT.cmake index 2823d8f050..f62ba65657 100644 --- a/projects/hip/tests/hit/HIT.cmake +++ b/projects/hip/tests/hit/HIT.cmake @@ -55,6 +55,29 @@ macro(PARSE_BUILD_COMMAND _target _sources _hipcc_options _hcc_options _nvcc_opt endforeach() endmacro() +# Helper macro to parse CUSTOM BUILD instructions +macro(PARSE_CUSTOMBUILD_COMMAND _target _buildcmd _exclude_platforms) + set(${_target}) + set(${_buildcmd} " ") + set(${_exclude_platforms}) + set(_target_found FALSE) + set(_exclude_platforms_found FALSE) + foreach(arg ${ARGN}) + if(NOT _target_found) + set(_target_found TRUE) + set(${_target} ${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 ${_buildcmd} ${arg}) + endif() + endif() + endforeach() +endmacro() + # Helper macro to parse TEST instructions macro(PARSE_TEST_COMMAND _target _arguments _exclude_platforms) set(${_target}) @@ -155,6 +178,33 @@ macro(HIT_ADD_FILES _dir _label _parent) endif() endforeach() + # Custom build commands + execute_process(COMMAND ${HIP_SRC_PATH}/tests/hit/parser --customBuildCMDs ${file} + OUTPUT_VARIABLE _contents + ERROR_QUIET + WORKING_DIRECTORY ${_dir} + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(REGEX REPLACE "\n" ";" _contents "${_contents}") + string(REGEX REPLACE "%hc" "${HIP_HIPCC_EXECUTABLE}" _contents "${_contents}") + string(REGEX REPLACE "%cc" "${CC}" _contents "${_contents}") + string(REGEX REPLACE "%S" ${_dir} _contents "${_contents}") + string(REGEX REPLACE "%T" ${_label} _contents "${_contents}") + foreach(_cmd ${_contents}) + string(REGEX REPLACE " " ";" _cmd "${_cmd}") + parse_custombuild_command(_target _buildcmd _exclude_platforms ${_cmd}) + string(REGEX REPLACE "/" "." target ${_label}/${_target}) + insert_into_map("_exclude" "${target}" "${_exclude_platforms}") + if(_exclude_platforms STREQUAL "all" OR _exclude_platforms STREQUAL ${HIP_PLATFORM}) + else() + string(REGEX REPLACE ";" " " _buildcmd "${_buildcmd}") + #string(CONCAT buildscript ${CMAKE_CURRENT_BINARY_DIR}/${target} ".sh") + #file(WRITE ${buildscript} ${_buildcmd}) + #add_custom_target(${target} COMMAND ${buildscript}) + add_custom_target(${target} COMMAND sh -c "${_buildcmd}") + add_dependencies(${_parent} ${target}) + endif() + endforeach() + # Add tests execute_process(COMMAND ${HIP_SRC_PATH}/tests/hit/parser --testCMDs ${file} OUTPUT_VARIABLE _contents diff --git a/projects/hip/tests/hit/parser b/projects/hip/tests/hit/parser index c74c0f9d01..8381c78a3c 100755 --- a/projects/hip/tests/hit/parser +++ b/projects/hip/tests/hit/parser @@ -4,16 +4,21 @@ use 5.006; use v5.10.1; use File::Basename; use File::Spec; +my $patBUILD = "^".quotemeta(" * BUILD:"); +my $patTEST = "^".quotemeta(" * TEST:"); +my $patTEST_NAMED = "^".quotemeta(" * TEST_NAMED:"); +my $patBUILD_CMD = "^".quotemeta(" * BUILD_CMD:"); + # Scan input file for HIT information sub parse_file { my $file = shift; (my $exe = $file) =~ s/\.[^.]+$//g; - my (@buildCMDs, @testCMDs, @testNamedCMDs); + my (@buildCMDs, @testCMDs, @testNamedCMDs, @customBuildCMDs); if (open (SOURCE, '<:encoding(UTF-8)', "$file")) { while () { my $line=$_; # Look for BUILD instructions - if ($line =~ /^ \* BUILD:/) { + if ($line =~ /$patBUILD/) { $line =~ s/^ \* BUILD: //g; # Remove " * BUILD: " $line =~ s/%s/$file/g; # Substitute %s -> filename $line =~ s/%t/$exe/g; # Substitute %t -> targetname @@ -21,7 +26,7 @@ sub parse_file { push @buildCMDs, $line; } # Look for TEST instructions - if ($line =~ /^ \* TEST:/) { + if ($line =~ /$patTEST/) { $line =~ s/^ \* TEST: //g; # Remove " * TEST: " $line =~ s/%s/$file/g; # Substitute %s -> filename $line =~ s/%t/$exe/g; # Subsitute %t -> targetname @@ -29,17 +34,27 @@ sub parse_file { push @testCMDs, $line; } # Look for TEST_NAMED instructions - if ($line =~ /^ \* TEST_NAMED:/) { + if ($line =~ /$patTEST_NAMED/) { $line =~ s/^ \* TEST_NAMED: //g;# Remove " * TEST_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 @testNamedCMDs, $line; } + # Look for BUILD_CMD instructions + if ($line =~ /$patBUILD_CMD/) { + $line =~ s/^ \* BUILD_CMD: //g; # Remove " * BUILD_CMD: " + $line =~ s/%s/$file/g; # Substitute %s -> filename + $line =~ s/%t/$exe/g; # Substitute %t -> targetname + # Substitute %hc -> /path/to/hipcc and %cc -> /path/to/cc happens in cmake + # Substitute %S -> src dir and %T -> target build dir happens in cmake + $line =~ s/\R//g; # Remove line endings + push @customBuildCMDs, $line; + } } close(SOURCE); } - return (\@buildCMDs, \@testCMDs, \@testNamedCMDs); + return (\@buildCMDs, \@testCMDs, \@testNamedCMDs, \@customBuildCMDs); } # Exit if no arguments specified @@ -53,8 +68,9 @@ my @options = (); my $retBuildCMDs = 0; my $retTestCMDs = 0; my $retTestNamedCMDs = 0; +my $retCustomBuildCMDs = 0; foreach $arg (@ARGV) { - if ($retBuildCMDs or $retTestCMDs or $retTestNamedCMDs) { + if ($retBuildCMDs or $retTestCMDs or $retTestNamedCMDs or $retCustomBuildCMDs) { push (@options, $arg); } if ($arg eq '--buildCMDs') { @@ -66,18 +82,21 @@ foreach $arg (@ARGV) { if ($arg eq '--testNamedCMDs') { $retTestNamedCMDs = 1; } + if ($arg eq '--customBuildCMDs') { + $retCustomBuildCMDs = 1; + } } # Atleast one command needs to be specified -if (($retBuildCMDs eq 0) and ($retTestCMDs eq 0) and ($retTestNamedCMDs eq 0)) { - die "Usage: $0 <--buildCMDs|--testCMDs|--testNamedCMDs> FILENAMEs\n"; +if (($retBuildCMDs eq 0) and ($retTestCMDs eq 0) and ($retTestNamedCMDs eq 0) and($retCustomBuildCMDs eq 0)) { + die "Usage: $0 <--buildCMDs|--testCMDs|--testNamedCMDs|--customBuildCMDs> 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, $testCMDs, $testNamedCMDs) = parse_file("$relfile"); + my ($buildCMDs, $testCMDs, $testNamedCMDs, $customBuildCMDs) = parse_file("$relfile"); if ($retBuildCMDs) { # print "BuildCMDs:\n"; print "$_\n" for @$buildCMDs; @@ -90,6 +109,10 @@ foreach $file (@options) { # print "TestNamedCMDs:\n"; print "$_\n" for @$testNamedCMDs; } + if ($retCustomBuildCMDs) { + # print "CustomBuildCMDs:\n"; + print "$_\n" for @$customBuildCMDs; + } } # vim: ts=4:sw=4:expandtab:smartindent