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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.61/] [tools/] [bin/] [tbw] - Blame information for rev 26

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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