2
0
Ficheiros
rocm-systems/tests/hit/parser
T

119 linhas
4.2 KiB
Perl
Em bruto Vista normal Histórico

#!/usr/bin/perl -w
use 5.006; use v5.10.1;
use File::Basename;
use File::Spec;
2019-05-09 08:41:05 +05:30
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;
2019-05-09 08:41:05 +05:30
my (@buildCMDs, @testCMDs, @testNamedCMDs, @customBuildCMDs);
if (open (SOURCE, '<:encoding(UTF-8)', "$file")) {
while (<SOURCE>) {
my $line=$_;
# Look for BUILD instructions
2019-05-09 08:41:05 +05:30
if ($line =~ /$patBUILD/) {
2016-09-27 17:22:23 +05:30
$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 TEST instructions
2019-05-09 08:41:05 +05:30
if ($line =~ /$patTEST/) {
$line =~ s/^ \* TEST: //g; # Remove " * TEST: "
2016-09-27 17:22:23 +05:30
$line =~ s/%s/$file/g; # Substitute %s -> filename
$line =~ s/%t/$exe/g; # Subsitute %t -> targetname
$line =~ s/\R//g; # Remove line endings
push @testCMDs, $line;
}
# Look for TEST_NAMED instructions
2019-05-09 08:41:05 +05:30
if ($line =~ /$patTEST_NAMED/) {
$line =~ s/^ \* TEST_NAMED: //g;# Remove " * TEST_NAMED: "
2016-09-27 17:22:23 +05:30
$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;
2016-09-27 17:22:23 +05:30
}
2019-05-09 08:41:05 +05:30
# 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);
}
2019-05-09 08:41:05 +05:30
return (\@buildCMDs, \@testCMDs, \@testNamedCMDs, \@customBuildCMDs);
}
# Exit if no arguments specified
if(scalar @ARGV == 0){
print "No Arguments passed, exiting ...\n";
exit(-1);
}
# Parse command
my @options = ();
my $retBuildCMDs = 0;
my $retTestCMDs = 0;
my $retTestNamedCMDs = 0;
2019-05-09 08:41:05 +05:30
my $retCustomBuildCMDs = 0;
foreach $arg (@ARGV) {
2019-05-09 08:41:05 +05:30
if ($retBuildCMDs or $retTestCMDs or $retTestNamedCMDs or $retCustomBuildCMDs) {
push (@options, $arg);
}
if ($arg eq '--buildCMDs') {
$retBuildCMDs = 1;
}
if ($arg eq '--testCMDs') {
$retTestCMDs = 1;
}
if ($arg eq '--testNamedCMDs') {
$retTestNamedCMDs = 1;
2016-09-27 17:22:23 +05:30
}
2019-05-09 08:41:05 +05:30
if ($arg eq '--customBuildCMDs') {
$retCustomBuildCMDs = 1;
}
}
# Atleast one command needs to be specified
2019-05-09 08:41:05 +05:30
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);
2019-05-09 08:41:05 +05:30
my ($buildCMDs, $testCMDs, $testNamedCMDs, $customBuildCMDs) = parse_file("$relfile");
if ($retBuildCMDs) {
# print "BuildCMDs:\n";
print "$_\n" for @$buildCMDs;
}
if ($retTestCMDs) {
# print "TestCMDs:\n";
print "$_\n" for @$testCMDs;
}
if ($retTestNamedCMDs) {
# print "TestNamedCMDs:\n";
print "$_\n" for @$testNamedCMDs;
2016-09-27 17:22:23 +05:30
}
2019-05-09 08:41:05 +05:30
if ($retCustomBuildCMDs) {
# print "CustomBuildCMDs:\n";
print "$_\n" for @$customBuildCMDs;
}
}
# vim: ts=4:sw=4:expandtab:smartindent