[hit] Add support for BUILD_CMD

[ROCm/hip commit: 49a2d785d0]
This commit is contained in:
Maneesh Gupta
2019-05-09 08:41:05 +05:30
parent 4b274cc6f8
commit ba620dfbe4
3 changed files with 96 additions and 9 deletions
+14
View File
@@ -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: <targetname> <build_command> EXCLUDE_HIP_PLATFORM <hcc|nvcc|all>
```
%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:
+50
View File
@@ -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
+32 -9
View File
@@ -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 (<SOURCE>) {
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