fiji_ee.pl 8.46 KB
Newer Older
1
2
#!/usr/bin/env perl

3
4
5
#-----------------------------------------------------------------------
# Fault InJection Instrumenter (FIJI)
# https://embsys.technikum-wien.at/projects/vecs/fiji
Christian Fibich's avatar
Christian Fibich committed
6
#
7
8
9
10
# The creation of this file has been supported by the publicly funded
# R&D project Josef Ressel Center for Verification of Embedded Computing
# Systems (VECS) managed by the Christian Doppler Gesellschaft (CDG).
#
11
12
13
# Authors:
# Christian Fibich <fibich@technikum-wien.at>
# Stefan Tauner <tauner@technikum-wien.at>
Christian Fibich's avatar
Christian Fibich committed
14
#
15
16
# This module is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself.
Christian Fibich's avatar
Christian Fibich committed
17
#
18
19
20
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Christian Fibich's avatar
Christian Fibich committed
21
#
22
23
# See the LICENSE file for more details.
#-----------------------------------------------------------------------
Christian Fibich's avatar
Christian Fibich committed
24

25
## @file
Christian Fibich's avatar
Christian Fibich committed
26
27
28
# @brief FIJI download script (CLI)
## @file
# Command-line script to download predefined, manually entered, and random tests
Stefan Tauner's avatar
Stefan Tauner committed
29
30
31

use strict;
use warnings;
32

33
34
35
use FindBin;
use lib "$FindBin::Bin";

Stefan Tauner's avatar
Stefan Tauner committed
36
use Log::Log4perl qw(get_logger);
37
use Log::Log4perl::Appender::String;
Stefan Tauner's avatar
Stefan Tauner committed
38

39
use FIJI::Downloader;
40
use FIJI::Utils;
41
use FIJI qw(:fiji_version);
42
use File::Basename;
43
use Getopt::Long qw(:config no_ignore_case bundling);
44
use POSIX qw(strftime);
45
use Time::HiRes qw(time);
46

47
48
use Pod::Usage;

49
50
use constant TESTS   => "tst";
use constant TB      => "tb";
51

52
my $cfg   = {};
53
54
my $prob  = {};
my $dur   = {};
Stefan Tauner's avatar
Stefan Tauner committed
55

Stefan Tauner's avatar
Stefan Tauner committed
56
sub main {
57
58
59
    my $logger = get_logger("");

    pod2usage(0) if (defined $cfg->{'help'});
60

Christian Fibich's avatar
Christian Fibich committed
61
    # Validate parameters
Christian Fibich's avatar
Christian Fibich committed
62
    if (!defined $cfg->{'settings_name'} || !defined $cfg->{'tests_name'} || !defined $cfg->{'mode'}) {
63
        my $msg = "";
64
65
        $msg .= "$0: No settings file specified.\n" if (!defined $cfg->{'settings_name'});
        $msg .= "$0: No tests file specified.\n" if (!defined $cfg->{'tests_name'});
66
        $msg .= "$0: No test mode specified.\n" if (!defined $cfg->{'mode'});
67
68
        $logger->error($msg);
        pod2usage(-exitval=>1,-msg=>$msg,-verbose);
69
70
    }

71
72
    FIJI::Utils::increase_verbosity($cfg->{'verbosity_delta'});

73
74
75
76
77
78
    # Do our own globbing because the shell does not glob
    # when the filename is passed with --long-option=PATH
    foreach my $k ('settings_name','tests_name') {
        $cfg->{$k} = FIJI::Utils::glob_path($cfg->{$k});
    }

79
    if ($cfg->{'mode'} ne 'auto' &&
80
81
       $cfg->{'mode'} ne 'manual' &&
       $cfg->{'mode'} ne 'random') {
82
83
84
        my $msg = "$0: Invalid mode \"" . $cfg->{'mode'} . "\"\n\n";
        $logger->error($msg);
        pod2usage(-exitval=>1,-msg=>$msg,-verbose);
85
86
    }

87
88
89
    # default to interactive in manual mode
    $cfg->{'interactive'} = 1 if ($cfg->{'mode'} eq 'manual');

90

Christian Fibich's avatar
Christian Fibich committed
91
    # Make new downloader
92
    my $fiji_downloader = FIJI::Downloader->new($cfg->{'mode'}, $cfg->{'tests_name'}, undef, $cfg->{'settings_name'});
Christian Fibich's avatar
Christian Fibich committed
93
94
    if (!ref($fiji_downloader)) {
        $logger->error($fiji_downloader . " Aborting.\n");
95
96
97
        return 1;
    }

98
99
    my $faulty_tests = {};
    my $starttime = time;
100

101
102
    $cfg->{'one-shot'} = 0 if (!defined $cfg->{'one-shot'});

Christian Fibich's avatar
Christian Fibich committed
103
    # Check mode and execute tests accordingly
104
    my $downloader_reply;
Christian Fibich's avatar
Christian Fibich committed
105
    if ($cfg->{'mode'} eq "auto") {
106
        $downloader_reply = $fiji_downloader->download_auto(\1, \$faulty_tests, $cfg->{'portname'});
Christian Fibich's avatar
Christian Fibich committed
107
    } elsif ($cfg->{'mode'} eq "manual") {
108
        $downloader_reply = $fiji_downloader->download_manual(\1, $cfg->{'portname'}, $cfg->{'one-shot'});
Christian Fibich's avatar
Christian Fibich committed
109
    } elsif ($cfg->{'mode'} eq "random") {
110
111
112
113
114
        $downloader_reply = $fiji_downloader->update_dur($dur);
        if (!defined $downloader_reply) {
            $downloader_reply = $fiji_downloader->update_prob($prob);
            if(!defined $downloader_reply) {
                $downloader_reply = $fiji_downloader->download_random(\1, \$faulty_tests, $cfg->{'portname'});
Christian Fibich's avatar
Christian Fibich committed
115
116
            }
        }
Stefan Tauner's avatar
Stefan Tauner committed
117
    }
118

119
    my $string_appender = $Log::Log4perl::Logger::APPENDER_BY_NAME{'string'};
120
121
122
123
124
125
    my $completion_script;
    if (defined($cfg->{'completion_script'})) {
        $completion_script = File::Spec->rel2abs($cfg->{'completion_script'});
    } else {
        $completion_script = $fiji_downloader->{'fiji_tests'}->{'design'}->{'COMPLETION_SCRIPT'};
    }
126
    FIJI::Utils::execute_completion_script(
127
        $completion_script,
128
129
130
131
132
        $fiji_downloader->{'fiji_tests'}->{'filename'},
        $downloader_reply,
        $starttime,
        time,
        $faulty_tests,
133
        $string_appender->string(),
134
135
136
137
    );

    if (defined $downloader_reply && !ref($downloader_reply)) {
        $logger->error($downloader_reply);
Christian Fibich's avatar
Christian Fibich committed
138
        return 1;
139
    }
140

141
142
143
144
    # We don't get back the test in manual mode hence no saving.
    # Rationale: if user enters test manually he knows all values anyway.
    if (defined($cfg->{'interactive'}) &&
        ($cfg->{'mode'} eq 'random' || $cfg->{'mode'} eq 'auto')) {
145
        my $time = strftime("%F-%H%M%S",localtime);
146
147
        _ask_save($cfg, TESTS, $faulty_tests, $fiji_downloader, $time);
        _ask_save($cfg, TB, $faulty_tests, $fiji_downloader, $time);
148
149
    }

150
    $logger->info("=== Stopping execution ===");
151
152
153
    return 0;
}

154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
sub _ask_save {
    my ($cfg, $save_mode, $tests, $fiji_downloader, $postfix) = @_;
    my $filename=basename($cfg->{'settings_name'},["cfg"])."_".$postfix;
    print "Save test run as .tst file? y/n [n]: " if $save_mode eq TESTS;
    print "Save test run as .vhd/.sv files? y/n [n]: " if $save_mode eq TB;
    my $save=<STDIN>;
    $save =~ s/^\s+|\s+$//g;
    return undef unless lc($save) eq 'y';
    $filename .= ".$save_mode" if ($save_mode eq TESTS);
    print "Enter path [$filename]: ";
    my $fn=<STDIN>;
    $fn =~ s/^\s+|\s+$//g;
    $filename = $fn if ($fn ne "");
    return $tests->save($filename)      if $save_mode eq TESTS;
    return $tests->export_tb($filename,$fiji_downloader->{'fiji_settings'}) if $save_mode eq TB;
}

171
172
FIJI::Utils::log_start(1, 1, @ARGV);

173
GetOptions(
Stefan Tauner's avatar
Stefan Tauner committed
174
175
    "m|mode=s"     => \($cfg->{'mode'}),
    "s|settings=s" => \($cfg->{'settings_name'}),
176
    "t|tests=s"    => \($cfg->{'tests_name'}),
177
    "c|completion=s" => \($cfg->{'completion_script'}),
178
    "p|port=s"     => \($cfg->{'portname'}),
179
180
181
182
    "a|timer1-minimum-duration=i"   => \($dur->{'MIN_DUR_T1'}),
    "b|timer2-minimum-duration=i"   => \($dur->{'MIN_DUR_T2'}),
    "A|timer1-maximum-duration=i"   => \($dur->{'MAX_DUR_T1'}),
    "B|timer2-maximum-duration=i"   => \($dur->{'MAX_DUR_T2'}),
183
184
185
186
187
    "0|prob-s0=f"  => \($prob->{'PROB_STUCK_AT_0'}),
    "1|prob-s1=f"  => \($prob->{'PROB_STUCK_AT_1'}),
    "d|prob-dly=f" => \($prob->{'PROB_DELAY'}),
    "f|prob-seu=f" => \($prob->{'PROB_SEU'}),
    "o|prob-so=f"  => \($prob->{'PROB_STUCK_OPEN'}),
188
    "i|interactive" => \($cfg->{'interactive'}),
189
    "z|one-shot"    => \($cfg->{'one-shot'}),
Stefan Tauner's avatar
Stefan Tauner committed
190
    "v|verbose+"   => \($cfg->{'verbosity_delta'}),
Stefan Tauner's avatar
Stefan Tauner committed
191
    "h|help"       => \($cfg->{'help'}),
Christian Fibich's avatar
Christian Fibich committed
192
  )
193
  or pod2usage(-exitval=>1,-verbose=>1);
Christian Fibich's avatar
Christian Fibich committed
194

195
exit main();
196
197
198
199
200
201
202
203
204
205
206

__END__

=head1 NAME
    
    fiji_ee.pl

=head1 SYNOPSIS

    fiji_ee.pl [options] -m MODE -s SETTINGS -t TESTS

Stefan Tauner's avatar
Stefan Tauner committed
207
    fiji_ee.pl is the CLI version of the FIJI Execution Engine
208
209
210
211
212
213

=head1 OPTIONS

=item B<-m, --mode MODE>

Download mode:
Stefan Tauner's avatar
Stefan Tauner committed
214
215
216
217

 manual   Prompt for fault patterns & timer values
 auto     Download tests in cfg file
 random   Download randomly generated tests
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301

=item B<-s, --settings FILENAME>

FIJI Settings file

=item B<-t, --tests FILENAME>

FIJI Tests file

=back

=head2 OPTIONAL

    Values for the random execution mode. 

    These values default to the values in the Test file

=over

=item B<-a, --timer-1-min DURATION>

Minimum duration t1

=item B<-b, --timer-2-min  DURATION>

Minimum duration t2

=item B<-A, --timer-1-max  DURATION>

Maximum duration t1

=item B<-B, --timer-2-max  DURATION>

Maximum duration t2

=item B<-0, --prob-s0  PROBABILITY>

Probability of stuck-at-0 fault

=item B<-1, --prob-s1  PROBABILITY>

Probability of stuck-at-1 fault

=item B<-d, --prob-dly  PROBABILITY>

Probability of delay fault

=item B<-f, --prob-seu  PROBABILITY>

Probability of SEU fault

=item B<-o, --prob-so  PROBABILITY>

Probability of stuck-open fault

=back

    General optional arguments.

=over

=item B<-p, --port PORT>

Serial port to use. Defaults to value in Tests file

=item B<-c, --completion FILENAME>

Overrides the completion script from settings

=item B<-i, --interactive>

Wait for user input (default in manual mode).
Normally EE is to be used without user interaction.

=item B<-v, --verbose>

Increase verbosity of output. Can be given multiple times to increase
the verbosity level once per occurrence.

=item B<-h, --help>

Display this help and exit

=back