OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.7/] [tools/] [bin/] [tbw] - Blame information for rev 33

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 wfjm
#!/usr/bin/perl -w
2 29 wfjm
# $Id: tbw 642 2015-02-06 18:53:12Z mueller $
3 2 wfjm
#
4 28 wfjm
# Copyright 2007-2015 by Walter F.J. Mueller 
5 2 wfjm
#
6
# This program is free software; you may redistribute and/or modify it under
7
# the terms of the GNU General Public License as published by the Free
8
# Software Foundation, either version 2, or at your option any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
12
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13
# for complete details.
14
#
15
#  Revision History:
16
# Date         Rev Version  Comment
17 28 wfjm
# 2015-01-04   629   1.2.6  BUGFIX: setup proper dsc values after -fifo
18
# 2014-12-23   619   1.2.5  add -fifo and -verbose options
19 25 wfjm
# 2014-07-27   575   1.2.4  use xtwi to start ISim models
20 13 wfjm
# 2011-11-06   420   1.2.3  fix tbw.dat parsing (allow / in file names)
21 2 wfjm
# 2010-05-23   294   1.2.2  handle tb_code's in non-local directories
22
# 2010-04-18   279   1.2.1  add -help and more text to print_usage()
23
# 2009-11-22   252   1.2    add ISim support
24
# 2007-09-15    82   1.1.1  test for ambigous matches of name arguments; for
25
#                           "suff=[l1;l2;..]" style inlines use linkname_tmp.tmp
26
#                           as filename
27
# 2007-09-09    81   1.1    add fifo setup to tbw; allow multiple action lines
28
#                           per target; support immediate mode data
29
#                           "[line1;line2;...]" values
30
# 2007-08-03    71   1.0.1  handle redefinition of existing symlink correctly
31
# 2007-06-30    62   1.0    Initial version
32
#
33
# 'test bench wrapper' to setup symlink refering to stimulus file(s)
34
#
35
#  usage: tbw  [file] [args]
36
#
37
#  will look for file (default is _stim.dat) and setup a symlink
38
#  _stim_dat to refer to it. All args are passed along to 
39
#
40
 
41
use 5.005;                                  # require Perl 5.005 or higher
42
use strict;                                 # require strict checking
43
use POSIX qw(mkfifo);
44
use FileHandle;
45
 
46
my $tb_code;
47
my $is_isim;
48
my $is_isim_run;
49 28 wfjm
my $is_fifo;
50
my $is_verbose;
51 2 wfjm
 
52
my @args_pos;                   # list of positional args
53
my @args_nam;                   # list of named args
54
my @file_dsc;                   # file descriptors from tbw.dat
55
 
56
sub print_usage;
57
 
58 29 wfjm
autoflush STDOUT 1;             # autoflush, so nothing lost on exec later
59 2 wfjm
 
60
if (scalar(@ARGV) && $ARGV[0] =~ /^-*help$/) { # -help or --help given
61
  print_usage;
62
  exit 0;
63
}
64
 
65
if (scalar(@ARGV) == 0) {
66
  print "tbw-E: name of test bench code missing\n";
67
  print_usage;
68
  exit 1;
69
}
70
 
71
$tb_code = shift @ARGV;
72
my $tb_code_path = ".";
73
my $tb_code_name = $tb_code;
74
if ($tb_code =~ m|^(.*)/(.*)$|) {
75
  $tb_code_path = $1;
76
  $tb_code_name = $2;
77
}
78
 
79
my $tb_code_stem = $tb_code_name;
80
$tb_code_stem =~ s/_[fst]sim$//;            # drop _ssim,_fsim, or _tsim
81
 
82
if ($tb_code_stem =~ /_ISim$/) {            # is it an ISim executable ?
83
  $is_isim = 1;
84
  $tb_code_stem =~ s/_ISim$//;              # drop _ISim
85
  if (scalar(@ARGV) && $ARGV[0] eq "-run") {
86
    $is_isim_run = 1;
87
    shift @ARGV;
88
  }
89
}
90
 
91 28 wfjm
if (scalar(@ARGV) && $ARGV[0] eq "-fifo") {
92
  push @file_dsc, {tag=>'rlink_cext_fifo_rx', val=>''};
93
  push @file_dsc, {tag=>'rlink_cext_fifo_tx', val=>''};
94
  push @file_dsc, {tag=>'rlink_cext_conf',    val=>''};
95
  $is_fifo = 1;
96
  shift @ARGV;
97
}
98
if (scalar(@ARGV) && $ARGV[0] eq "-verbose") {
99
  $is_verbose = 1;
100
  shift @ARGV;
101
}
102
 
103 2 wfjm
if (not -e $tb_code) {
104
  print "tbw-E: $tb_code not existing or not executable\n";
105
  print_usage;
106
  exit 1;
107
}
108
 
109
#
110
# read tbw.dat file in current directory or directory of executable
111
#
112
 
113
my $tbwdat_file = "tbw.dat";
114
$tbwdat_file = "$tb_code_path/tbw.dat" unless (-r "tbw.dat");
115
 
116 28 wfjm
if ((!$is_fifo) && -r $tbwdat_file) {
117 2 wfjm
  my $ok = 0;
118
  my $done = 0;
119
 
120
  open (TBW, $tbwdat_file) or die "failed to open $tbwdat_file: $!";
121
  while () {
122
    chomp;
123
    next if /^#/;
124 13 wfjm
    if ( m{^\s*\[([\.\/a-zA-Z0-9_]*)\]\s*$} ) {
125 2 wfjm
      last if $done;
126
      $ok = 0;
127
      $ok = 1 if ($1 eq $tb_code || $1 eq $tb_code_stem);
128 13 wfjm
    } elsif ( m{^\s*([a-zA-Z0-9_]*)\s*=\s*([a-zA-Z0-9_./<>]*)\s*$} ) {
129 2 wfjm
      if ($ok) {
130
        push @file_dsc, {tag=>$1, val=>$2};
131
        $done = 1;
132
      }
133 13 wfjm
    } else {
134
      print "tbw-E: bad line in tbw.dat:\n  $_\n";
135 2 wfjm
    }
136
  }
137
}
138
 
139
#
140 28 wfjm
# if no tbw.dat or no matching stanza found, setup defaults
141 2 wfjm
#
142
 
143 28 wfjm
if (!$is_fifo) {
144
  unless (scalar (@file_dsc)) {
145
    push @file_dsc, {tag=>$tb_code_stem . "_stim",
146
                     val=>$tb_code_stem . "_stim.dat"};
147 13 wfjm
  }
148 28 wfjm
} else {
149
  push @file_dsc, {tag=>"rlink_cext_fifo_rx",
150
                   val=>""};
151 13 wfjm
}
152
 
153 2 wfjm
#
154
# now process argument list
155
#
156
 
157
{
158
  my $ind = 0;
159
  while (scalar(@ARGV)>0 && not $ARGV[0] =~ /^-/) {
160
    my $arg = shift @ARGV;
161
    my $ok;
162
    if ($arg =~ /([a-zA-Z0-9_]*)=(.*)/) {   # named argument
163
      my $tag = $1;
164
      my $val = $2;
165
      foreach my $dsc (@file_dsc) {
166
        if ($dsc->{tag} =~ /$tag$/) {
167
          $dsc->{val} = $val;
168
          $ok += 1;
169
        }
170
      }
171
      if ($ok == 0) {
172
        print STDERR "tbw-F: can't match named argument: $arg\n";
173
        exit 1;
174
      } elsif ($ok > 1) {
175
        print STDERR "tbw-F: ambiguous match for named argument: $arg\n";
176
        exit 1;
177
      }
178
 
179
    } else {                                # positional argument
180
      if ($ind < scalar(@file_dsc)) {
181
        $file_dsc[$ind]->{val} = $arg;
182
      } else {
183
        print STDERR "tbw-F: too many positional arguments: $arg\n";
184
        exit 1;
185
      }
186
      $ind += 1;
187
    }
188
  }
189
}
190
 
191 28 wfjm
if ($is_verbose) {
192
  foreach my $dsc (@file_dsc) {
193
    my $tag = $dsc->{tag};
194
    my $val = $dsc->{val};
195
    printf "    %s = %s\n", $tag, $val;
196
  }
197
}
198
 
199 2 wfjm
#
200
# now handle all specified file descriptors
201
#
202
 
203
foreach my $dsc (@file_dsc) {
204
  my $tag = $dsc->{tag};
205
  my $val = $dsc->{val};
206
  if ($val eq "") {     # handle FIFO's
207
    next if (-p $tag);
208
    print "tbw-I: create FIFO $tag\n";
209
    mkfifo($tag, 0666) || die "can't mkfifo $tag: $!";
210
 
211
  } else {                      # handle link to file cases
212
 
213
    if ($val =~ /^\[(.*)\]$/) { # immediate data case: "[line1;line2;...]"
214
      my @lines = split /;/, $1;
215
      my $fname = "$tag\_tmp.tmp";
216
      open TFILE,">$fname" or die "can't create temporary file $fname: $!";
217
      foreach (@lines) {
218
        s/^\s*//;
219
        s/\s*$//;
220
        print TFILE "$_\n";
221
      }
222
      close TFILE;
223
      $val = $fname;
224
 
225
    } else {
226
      unlink "$tag\_tmp.tmp" if (-e "$tag\_tmp.tmp"); # remove old .tmp file
227
      $val = "/dev/null" if ($val eq "");       # null file case
228
    }
229
 
230
    if (not -r $val) {
231
      print "tbw-F: file for $tag not existing or not readable: $val\n";
232
      exit 1;
233
    }
234
    if (-l $tag) {
235
      my $cur_link = readlink $tag;
236
      if ($cur_link ne $val) {
237
        print "tbw-I: redefine $tag -> $val\n";
238
        unlink $tag
239
          or die "failed to unlink: $!";
240
        symlink $val, $tag
241
          or die "failed to symlink 1: $!";
242
      }
243
    } else {
244
      if (-e $tag) {
245
        print "tbw-F: $tag exists but is not a symlink\n";
246
        exit 1;
247
      } else {
248
        print "tbw-I: define $tag -> $val\n";
249
        symlink $val, $tag
250
          or die "failed to symlink 2: $!";
251
      }
252
    }
253
  }
254
}
255
 
256
#
257
# here all ok, finally exec test bench
258
#
259
 
260
if ($is_isim_run) {                         # handle for isim 'run all'
261 25 wfjm
  my $cmd = "xtwi" . " " . $tb_code . " " . join " ",@ARGV;
262 2 wfjm
  open (ISIM_RUN, "| $cmd")
263
    or die "failed to open process pipe to isim: $!";
264
  print ISIM_RUN "run all\n";
265
  print ISIM_RUN "quit\n";
266
  close (ISIM_RUN)
267
     or die "failed to close process pipe to isim: $!";
268
 
269
} else {                                    # otherwise just exec
270
  exec $tb_code,@ARGV
271
    or die "failed to exec: $!";
272
}
273
 
274
# ----------------------------------------------------------------------------
275
sub print_usage {
276 28 wfjm
  print "usage: tbw   [opts] [filedefs] [ghdl-opts]\n";
277
  print "  opts\n";
278
  print "    -run      for _ISim tb's, runs the tb with a 'run all' command\n";
279
  print "    -fifo     use rlink_cext fifo, ignore tbw.dat\n";
280
  print "    -verbose  show the used tag,value settings before execution\n";
281 2 wfjm
  print "  filedefs define tb input, either filename in tbw.dat order or\n";
282
  print "    tag=name or tag=[] pairs with tag matching one in in\n";
283
  print "    tbw.dat. The [] form allows to give data inline, e.g.\n";
284
  print "    like \"_conf=[.rpmon 1]\"\n";
285 28 wfjm
  print "  ghdl-opts are all other options starting with a '-', they are\n";
286
  print "     passed to the testbench. Some useful ghdl options are:\n";
287 2 wfjm
  print "      --wave=x.ghw\n";
288
  print "      --stack-max-size=16384\n";
289
  print "      --stop-time=1ns  --disp-time  --trace-processes\n";
290
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.