6 use File
::Basename
qw(fileparse);
7 use File
::Compare
qw(compare compare_text);
8 use File
::Copy
qw(move);
9 use File
::Path
qw(mkpath rmtree);
13 'Perform tests on nasm.
15 Usage: performtest.pl ["quiet"] ["clean"] ["golden"] nasm_executable test_files...
20 # sub debugprint { print (pop() . "\n"); }
23 #Get one command line argument
24 sub get_arg
{ shift @ARGV; }
28 my ($clean, $golden, $nasm, $quiet, $testpath) = @_;
29 my ($stdoutfile, $stderrfile) = (".stdout", ".stderr");
31 my ($testname, $ignoredpath, $ignoredsuffix) = fileparse
($testpath, ".asm");
34 my $outputdir = $golden ?
"golden" : "testresults";
36 mkdir "$outputdir" unless -d
"$outputdir";
39 rmtree
"$outputdir/$testname";
43 if(-d
"$outputdir/$testname") {
44 rmtree
"$outputdir/$testname";
47 open(TESTFILE
, '<', $testpath) or (warn "Can't open $testpath\n", return);
50 #See if there is a test case
51 last unless /Testname=(.*);\s*Arguments=(.*);\s*Files=(.*)/;
52 my ($subname, $arguments, $files) = ($1, $2, $3);
53 debugprint
("$subname | $arguments | $files");
55 #Call nasm with this test case
56 system("$nasm $arguments $testpath > $stdoutfile 2> $stderrfile");
57 debugprint
("$nasm $arguments $testpath > $stdoutfile 2> $stderrfile ----> $?");
59 #Move the output to the test dir
60 mkpath
("$outputdir/$testname/$subname");
61 foreach(split / /,$files) {
63 move
($_, "$outputdir/$testname/$subname/$_") or die $!
66 unlink ("$stdoutfile", "$stderrfile"); #Just to be sure
69 #Compare them with the golden files
72 foreach(split / /, $files) {
73 if(-f
"$outputdir/$testname/$subname/$_") {
75 if($_ eq $stdoutfile or $_ eq $stderrfile) {
76 #Compare stdout and stderr in text mode so line ending changes won't matter
77 $temp = compare_text
("$outputdir/$testname/$subname/$_", "golden/$testname/$subname/$_");
79 $temp = compare
("$outputdir/$testname/$subname/$_", "golden/$testname/$subname/$_");
85 push @failedfiles, $_;
86 } elsif($temp == -1) {
88 print "Error in $testname/$subname with file $_\n";
91 } elsif (-f
"golden/$testname/$subname/$_") {
92 #File exists in golden but not in output
94 push @failedfiles, $_;
100 print "Test $testname/$subname succeeded.\n" unless $quiet;
101 } elsif ($result == 1) {
102 print "Test $testname/$subname failed on @failedfiles.\n";
104 die "Impossible result";
118 $arg = get_arg
() or usage
();
121 if($arg eq "quiet") {
123 $arg = get_arg
() or usage
();
125 if($arg eq "clean") {
127 $arg = get_arg
() or usage
();
129 if ($arg eq "golden") {
131 $arg = get_arg
() or usage
();
136 perform
($clean, $golden, $nasm, $quiet, $_) foreach @ARGV;