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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.6/] [tools/] [bin/] [tbw] - Blame information for rev 38

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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