forked from svunit/svunit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunSVUnit
executable file
·195 lines (170 loc) · 5.83 KB
/
runSVUnit
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env perl
############################################################################
#
# Copyright 2011 The SVUnit Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
############################################################################
use strict;
use Getopt::Long;
use File::Glob;
use File::Find;
use IO::File;
use Cwd 'abs_path';
use vars qw/ %opt /;
##########################################################################
# PrintHelp(): Prints the script usage.
##########################################################################
my $cmd;
my $logfile = "run.log";
my $vlogfile = "compile.log";
my $simulator;
my @defines;
my @filelists;
my $uvm;
my $wavedrom;
my @simargs;
my @compileargs;
my $outdir = ".";
my $clean;
my $vhdlfile;
my @tests;
my $help;
sub usage () {
print "Usage: runSVUnit [-s|--sim <simulator> -l|--log <log> -d|--define <macro> -f|--filelist <file> -U|-uvm -m|-mixedsim <vhdlfile>\n";
print " -r|--r_arg <option> -c|--c_arg <option> -o|--out <dir> -t|--test <test>]\n";
print " -s|--sim <simulator> : simulator is either of questa, modelsim, riviera, ius, xcelium or vcs\n";
print " -l|--log <log> : simulation log file (default: run.log)\n";
print " -d|--define <macro> : appended to the command line as +define+<macro>\n";
print " -f|--filelist <file> : some verilog file list\n";
print " -r|--r_arg <option> : specify additional runtime options\n";
print " -c|--c_arg <option> : specify additional compile options\n";
print " -U|--uvm : run SVUnit with UVM\n";
print " -o|--out : output directory for tmp and simulation files\n";
print " -t|--test : specifies a unit test to run (multiple can be given)\n";
print " -m|--mixedsim <vhdlfile> : consolidated file list with VHDL files and command line switches\n";
print " -w|--wavedrom : process json files as wavedrom output\n";
print " -h|--help : prints this help screen\n";
print "\n";
exit 1;
}
sub clean () {
find({
wanted => sub {
if (/^\..*testsuite\.sv$/ or
/^\..*testrunner\.sv$/
) {
unlink;
}
}
}, $outdir);
unlink qw( run.log .svunit.f vsim.wlf ncsc.log irun.key );
system("rm -rf work INCA_libs");
}
# command line options
GetOptions("l|log=s" => \$logfile,
"s|sim=s" => \$simulator,
"d|define=s" => \@defines,
"f|filelist=s" => \@filelists,
"U|uvm" => \$uvm,
"r|r_arg=s" => \@simargs,
"c|c_arg=s" => \@compileargs,
"o|out=s" => \$outdir,
"m|mixedsim=s" => \$vhdlfile,
"t|test=s{,}" => \@tests,
"w|wavedrom" => \$wavedrom,
"h|help" => \$help
) or usage();
usage() if $help;
clean();
# version
my $VERSION = IO::File->new();
$VERSION->open("$ENV{SVUNIT_INSTALL}/VERSION.txt") || die;
my $version = $VERSION->getline;
chomp $version;
push @defines, qq!SVUNIT_VERSION='"$version"'!;
# Extract simulator from PATH if nothing passed as argument
if ($simulator eq "") {
my @sims = qw(xrun irun vsim vcs);
foreach my $sim (@sims) {
if (system("which $sim > /dev/null 2>&1") == 0) {
$simulator = $sim;
last;
}
}
# We look for the executable 'vsim', but the script uses 'modelsim' as a simulator name
$simulator =~ s/vsim/modelsim/;
}
# simulator check
$simulator =~ tr/A-Z/a-z/;
$simulator =~ s/questa/modelsim/;
$simulator =~ s/ius/irun/;
$simulator =~ s/xcelium/xrun/;
if (not grep { $_ eq $simulator } qw(xrun irun modelsim riviera vcs)) {
print("Could not determine simulator. None found on 'PATH' and none specified via command line\n");
usage()
}
# start the command line
$cmd = "cd $outdir; ";
# add the vdhl switches if necessary
if ($simulator eq "modelsim" or $simulator eq "riviera") {
$cmd .= "vlib work; ";
$cmd .= "vcom -work work -f $vhdlfile ; " if $vhdlfile;
$cmd .= "vlog -l $vlogfile ";
} elsif ($simulator eq "vcs") {
$cmd .= "$simulator -R -sverilog -l $logfile";
$cmd .= "-f $vhdlfile " if $vhdlfile;
} else {
$cmd .= "$simulator -l $logfile ";
$cmd .= "-f $vhdlfile " if $vhdlfile;
}
# add the uvm switches if necessary
if (defined $uvm) {
$cmd .= " -uvm" if ($simulator eq "xrun" or $simulator eq "irun");
$cmd .= " -ntb_opts uvm" if $simulator eq "vcs";
push @defines, "RUN_SVUNIT_WITH_UVM";
}
# add the filelists and defines
foreach (@filelists) {
my $f = abs_path($_);
$cmd .= " -f " . join " -f ", $f;
}
$cmd .= " -f .svunit.f";
# defines
$cmd .= " +define+" . join " +define+", @defines if (@defines > 0);
if ($simulator eq "modelsim" or $simulator eq "riviera") {
if (!grep(/(^| )(-gui|-c|-i)( |$)/, @simargs)) {
push @simargs, "-c";
}
$cmd .= qq! @compileargs; vsim @simargs -lib work -do "run -all; quit" -l $logfile testrunner!;
} else {
$cmd .= " @compileargs @simargs -top testrunner";
}
my $build_cmd = "buildSVUnit -o $outdir";
foreach (@tests) {
$build_cmd .= " -t $_";
}
$build_cmd .= " --uvm" if $uvm;
$build_cmd .= " --wavedrom" if $wavedrom;
# include mock package for UVM compilation
if (defined $uvm) {
$build_cmd .= " --mock";
}
# run!!
if (system("$build_cmd")) {
exit -1;
}
print $cmd . "\n";
system("$cmd");
system("svunit_user_feedback.pl")