forked from seth4618/bbsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgentest.pl
executable file
·116 lines (95 loc) · 2.61 KB
/
gentest.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/perl
my ($prog) = ($0 =~ m!([^/]+)$!);
use Cwd;
use Expect;
use Time::HiRes;
$verbose = 0;
$sim = `which sim`;
($sim eq "") && die("Can't find sim command");
$sim =~ s/[ \r\t\n]+$//;
$vm = `which meldvm`;
($vm eq "") && die("Can't find meldvm command");
$vm =~ s/[ \r\t\n]+$//;
print STDERR "[$sim] [$vm]\n";
$port = 5000;
$cmdargs = "";
#
# process options
#
while ($ARGV[0] =~ /^-/) {
$_ = shift @ARGV;
option:
{
if (/^-p/) {
$port = shift @ARGV;
last option;
}
if (/^-[h?]/) {
&usage("");
last option;
}
if (/^-v/) {
$verbose++;
last option;
}
&usage("Unknown option: $_\n");
}
}
# now expect three args: meldfile to run, config to run it on, and output name for test
($#ARGV < (3-1)) && &usage("Expected 3 arguments");
$meldfile = shift @ARGV;
( ! -e $meldfile ) && &usage("Expected a meld byte code file, Could not find $meldfile");
$configfile = shift @ARGV;
( ! -e $configfile ) && &usage("Expected a config file, Could not find $configfile");
$testfile = shift @ARGV;
( -e $testfile ) && &usage("Expected a name for a test file, but $testfile already exists");
$_ = shift @ARGV;
$simargs = "";
if (/^--$/) {
# rest of ARGV are args to simulator
$simargs = join(' ', @ARGV);
}
my @params = ("-c", $configfile, "-n", "-i", 10);
if ($simargs ne "") {
@params = (@params, split(' ', $simargs));
}
print STDERR "Spawning $sim\n";
my $simprocess = Expect->spawn($sim, @params) or die "Cannot spawn $sim: $!\n";
$simprocess->log_file("sim.log", "w");
Time::HiRes::sleep(0.1);
print STDERR "Spawning $vm\n";
my $vmprocess = Expect->spawn($vm, ("-p", $port, "-f", $meldfile)) or die "Cannot spawn $vm: $!\n";
while ($simprocess->expect(undef)) {
print $simprocess->before();
}
open(F, "<sim.log") || die("Can't open sim.log");
open(G, ">$testfile") || die("Can't open $testfile");
while (<F>) {
/Final Status/ && last;
}
print G "config: $configfile\n";
print G "meld: $meldfile\n\n";
while (<F>) {
s/[ \t\r\n]*$//;
print G "$_\n";
}
close(F);
close(G);
################################################################
# say what we do
#
sub usage {
my ($msg) = @_;
($msg ne "") && print STDERR "$prog:Error: $msg\n";
print STDERR <<"EndEndEnd";
$prog [-v] [-p <port>] [-h] prog-name config-name test-name [-- args-to-sim]
-v: more verbose (repeat these for more and more)
-p <port>: run sim on port <port>
-h: show this
prog-name: meld byte code file to run
config-name: configuration to run it on
test-name: path to test file spec that is created
--: rest of args are passed to simulator
EndEndEnd
exit 0;
}