2009-05-31 22:12:39 +02:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use XML::Simple;
|
|
|
|
use Getopt::Long;
|
2009-06-15 22:59:46 +02:00
|
|
|
use POSIX qw(ceil floor);
|
2009-05-31 22:12:39 +02:00
|
|
|
|
2009-06-15 23:56:00 +02:00
|
|
|
use Data::Dumper;
|
|
|
|
|
|
|
|
my $merge = 0;
|
2009-05-31 22:12:39 +02:00
|
|
|
|
|
|
|
sub usage() {
|
2009-06-14 22:52:17 +02:00
|
|
|
die("createtest -i <test template> -c <command> \n");
|
2009-05-31 22:12:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub parseString {
|
|
|
|
my $string = shift;
|
|
|
|
my $cmd = shift;
|
|
|
|
$string =~ s/\@CMD\@/$cmd/gi;
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub generateSRFull {
|
|
|
|
my $res = shift;
|
|
|
|
my $body = shift;
|
2009-06-15 18:48:34 +02:00
|
|
|
my $start = shift;
|
|
|
|
my $end = shift;
|
2009-06-15 22:59:46 +02:00
|
|
|
$end = 0xFFFF if ($end > 0xFFFF);
|
|
|
|
|
2009-06-15 18:48:34 +02:00
|
|
|
$res .= join "\n", map {my $b = sprintf "\#0x%04X", $_; (my $a = $body) =~ s/\@SR\@/$b/g; $a} $start..$end;
|
2009-05-31 22:12:39 +02:00
|
|
|
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
2009-06-14 22:52:17 +02:00
|
|
|
sub calculateLines {
|
2009-06-15 18:48:34 +02:00
|
|
|
my $file = shift;
|
2009-06-14 22:52:17 +02:00
|
|
|
|
2009-06-15 18:48:34 +02:00
|
|
|
my @lines = `dsptool -s $file`;
|
|
|
|
$lines[0] =~ /:\s*(.*)/;
|
|
|
|
my $lnum = $1;
|
|
|
|
|
|
|
|
return $lnum;
|
2009-06-14 22:52:17 +02:00
|
|
|
}
|
|
|
|
|
2009-05-31 22:12:39 +02:00
|
|
|
my ($cmds,$input,$output);
|
|
|
|
if (!GetOptions('cmds|c=s' => \$cmds,
|
|
|
|
'input|i=s' => \$input,
|
2009-06-15 23:56:00 +02:00
|
|
|
'merge|m' => \$merge,
|
2009-05-31 22:12:39 +02:00
|
|
|
# 'output|o=s' => \$output,
|
|
|
|
)) {
|
|
|
|
usage();
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
usage() if (! defined $input);
|
|
|
|
|
|
|
|
my $xtest = XMLin($input);
|
|
|
|
my $type = $xtest->{'type'};
|
|
|
|
|
2009-06-17 23:44:03 +02:00
|
|
|
my @cmdList = split(/,/, $cmds);
|
|
|
|
|
|
|
|
for(my $i = 0;$i < scalar(@cmdList);$i++) {
|
|
|
|
my $cmd = $cmdList[$i];
|
2009-05-31 22:12:39 +02:00
|
|
|
my $name = parseString($xtest->{'name'}, $cmd);
|
|
|
|
$name =~ s/ /_/g;
|
|
|
|
my $desc = parseString($xtest->{'description'}, $cmd);
|
2009-06-14 22:52:17 +02:00
|
|
|
|
2009-05-31 22:12:39 +02:00
|
|
|
my $header = parseString($xtest->{'header'}, $cmd);
|
2009-06-15 18:48:34 +02:00
|
|
|
open(OUTPUT, ">$name.tmp");
|
|
|
|
print OUTPUT $header;
|
|
|
|
close(OUTPUT);
|
|
|
|
|
|
|
|
my $hsize = calculateLines("$name.tmp");
|
2009-06-14 22:52:17 +02:00
|
|
|
|
2009-05-31 22:12:39 +02:00
|
|
|
my $body = parseString($xtest->{'body'}, $cmd);
|
2009-06-15 18:48:34 +02:00
|
|
|
open(OUTPUT, ">$name.tmp");
|
2009-06-15 22:59:46 +02:00
|
|
|
print OUTPUT generateSRFull($header, $body, 0, 0);
|
2009-06-15 18:48:34 +02:00
|
|
|
close(OUTPUT);
|
2009-05-31 22:12:39 +02:00
|
|
|
|
2009-06-15 18:48:34 +02:00
|
|
|
my $bsize = calculateLines("$name.tmp") - $hsize;
|
|
|
|
unlink("$name.tmp");
|
2009-05-31 22:12:39 +02:00
|
|
|
|
2009-06-15 18:48:34 +02:00
|
|
|
# how many tests we can fit in a ucode.
|
2009-06-15 22:59:46 +02:00
|
|
|
my $ucodes = POSIX::floor((0x1000 - $hsize) / $bsize);
|
2009-06-15 18:48:34 +02:00
|
|
|
|
2009-06-15 23:56:00 +02:00
|
|
|
if ($merge) {
|
|
|
|
open(NAMES, ">>all.lst");
|
|
|
|
} else {
|
|
|
|
open(NAMES, ">$name.lst");
|
|
|
|
}
|
|
|
|
|
2009-06-16 22:25:03 +02:00
|
|
|
my $numLines = POSIX::ceil(0xFFFF / $ucodes);
|
|
|
|
for(my $j = 0; $j < $numLines; $j++) {
|
2009-06-15 18:48:34 +02:00
|
|
|
open(OUTPUT, ">$name$j.tst");
|
2009-06-15 22:59:46 +02:00
|
|
|
print OUTPUT generateSRFull($header, $body, $j*$ucodes,
|
|
|
|
($j+1)*$ucodes-1);
|
2009-08-16 02:37:01 +02:00
|
|
|
print OUTPUT "jmp end_of_test";
|
2009-06-15 18:48:34 +02:00
|
|
|
close(OUTPUT);
|
2009-06-16 22:25:03 +02:00
|
|
|
print NAMES "$name$j.tst";
|
|
|
|
|
|
|
|
# Don't end with a newline
|
2009-06-17 23:44:03 +02:00
|
|
|
if ($j < $numLines - 1 || ($merge && $i != scalar(@cmdList)-1)) {
|
2009-06-16 22:25:03 +02:00
|
|
|
print NAMES "\n";
|
|
|
|
}
|
2009-06-15 18:48:34 +02:00
|
|
|
}
|
2009-06-15 22:59:46 +02:00
|
|
|
|
2009-06-15 18:48:34 +02:00
|
|
|
close(NAMES);
|
2009-06-15 22:59:46 +02:00
|
|
|
|
2009-06-15 23:56:00 +02:00
|
|
|
if (! $merge) {
|
2009-06-18 07:22:10 +02:00
|
|
|
print `dsptool -m $name.lst -h $name`;
|
2009-06-15 23:56:00 +02:00
|
|
|
open(NAMES, "$name.lst");
|
|
|
|
my @names = <NAMES>;
|
|
|
|
chomp @names;
|
|
|
|
unlink @names;
|
|
|
|
close(NAMES);
|
|
|
|
unlink("$name.lst");
|
|
|
|
}
|
2009-05-31 22:12:39 +02:00
|
|
|
}
|
|
|
|
|
2009-06-15 23:56:00 +02:00
|
|
|
if ($merge) {
|
2009-06-18 07:22:10 +02:00
|
|
|
print `dsptool -m all.lst -h unite_test`;
|
2009-06-15 23:56:00 +02:00
|
|
|
open(NAMES, "all.lst");
|
|
|
|
my @names = <NAMES>;
|
|
|
|
chomp @names;
|
|
|
|
unlink @names;
|
|
|
|
close(NAMES);
|
|
|
|
unlink "all.lst";
|
|
|
|
}
|