File: 60_vpassert.t

package info (click to toggle)
libverilog-perl 3.482-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,728 kB
  • sloc: perl: 8,685; yacc: 3,387; cpp: 2,266; lex: 1,502; makefile: 8; fortran: 3
file content (145 lines) | stat: -rwxr-xr-x 4,842 bytes parent folder | download
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
#!/usr/bin/perl -w
# DESCRIPTION: Perl ExtUtils: Type 'make test' to test this package
#
# Copyright 2000-2024 by Wilson Snyder.  This program is free software;
# you can redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License Version 2.0.

use IO::File;
use strict;
use Test::More;

BEGIN { plan tests => 6 }
BEGIN { require "./t/test_utils.pl"; }

print "Checking vpassert...\n";

# Preprocess the files
mkdir "test_dir/.vpassert", 0777;
mkdir "test_dir/.vpassertcall", 0777;
system ("/bin/rm -rf test_dir/verilog");
symlink ("../verilog", "test_dir/verilog");  # So `line files are found; ok if fails
run_system ("${PERL} ./vpassert --minimum --nostop --date --axiom --verilator --vcs --synthcov"
	    ." -o test_dir/.vpassert -y verilog/");
ok(1, "vpassert ran");
ok(-r 'test_dir/.vpassert/pli.v', "pli.v created");

ok(compare('lines', [glob("test_dir/.vpassert/*.v")]), "lines output");
ok(compare('diff',  [glob("test_dir/.vpassert/*.v")]), "diff output");

# Preprocess with custom outputters
run_system ("${PERL} ./vpassert --date --verilator --vcs"
	    .q{ --call-error '$callError'}
	    .q{ --call-info '$callInfo'}
	    .q{ --call-warn '$callWarn'}
	    ." -o test_dir/.vpassertcall -y verilog/");
ok(files_identical("test_dir/.vpassertcall/example.v", "t/60_vpassert.out"), "diff");

# Build the model
unlink "simv";
chdir 'test_dir';
SKIP: {
    skip("author only test (harmless)",1)
	if (!$ENV{VERILATOR_AUTHOR_SITE});

    if ($ENV{VCS_HOME} && -r "$ENV{VCS_HOME}/bin/vcs") {
	run_system (# We use VCS, insert your simulator here
		    "$ENV{VCS_HOME}/bin/vcs"
		    # check line coverage
		    ." -cm line+assert"
		    # vpassert optionally uses SystemVerilog coverage for $ucover_clk
		    ." -sverilog"
		    # vpassert uses `pli to point to the hierarchy of the pli module
		    ." +define+pli=pli"
		    # vpassert uses `__message_on to point to the message on variable
		    ." +define+__message_on=pli.message_on"
		    # vpassert --minimum uses `__message_minimum to optimize away some messages
		    ." +define+__message_minimum=1"
		    # Read files from .vpassert BEFORE reading from other directories
		    ." +librescan +libext+.v -y .vpassert"
		    # Finally, read the needed top level file
		    ." .vpassert/example.v"
	    );
	# Execute the model (VCS is a compiled simulator)
	run_system ("./simv");
	unlink ("./simv");
	ok(1, "vcs sim");
    }
    elsif ($ENV{NC_ROOT} && -d "$ENV{NC_ROOT}/tools") {
	run_system ("ncverilog"
		    ." -q"
		    # vpassert optionally uses SystemVerilog coverage for $ucover_clk
		    ." +sv"
		    # vpassert uses `pli to point to the hierarchy of the pli module
		    ." +define+pli=pli"
		    # vpassert uses `__message_on to point to the message on variable
		    ." +define+__message_on=pli.message_on"
		    # vpassert --minimum uses `__message_minimum to optimize away some messages
		    ." +define+__message_minimum=1"
		    # Read files from .vpassert BEFORE reading from other directories
		    ." +librescan +libext+.v -y .vpassert"
		    # Finally, read the needed top level file
		    ." .vpassert/example.v"
	    );
	ok(1, "ncv sim");
    }
    else {
	warn "\n";
	warn "*** You do not seem to have VCS or NC-Verilog installed, not running rest of test.\n";
	warn "*** (If you do not license VCS/NC-Verilog, ignore this warning).\n";
	skip("No simulator found",1);
    }
}
chdir '..';

sub lines_in {
    my $filename = shift;
    my $fh = IO::File->new($filename) or die "%Error: $! $filename";
    my @lines = $fh->getlines();
    @lines = grep (!/\`line/, @lines);
    return $#lines;
}

sub compare {
    my $mode = shift;
    my $files = shift;
    my $ok = 1;
  file:
    foreach my $file (@{$files}) {
	$file =~ s!.*/!!;
	# SPECIAL FILES we processed!
	next if $file eq 'example.v';
	next if $file eq 'pli.v';


	my $fn1 = "verilog/$file";
	my $fn2 = "test_dir/.vpassert/$file";
	if ($mode eq 'lines') {
	    my $orig_lines = lines_in($fn1);
	    my $new_lines = lines_in($fn2);
	    if ($orig_lines!=$new_lines)  { $ok=0; print "%Error: "; }
	    print "Line count: $file: $orig_lines =? $new_lines\n";
	}
	elsif ($mode eq 'diff') {
	    my $f1 = IO::File->new ($fn1) or die "%Error: $! $fn1,";
	    my $f2 = IO::File->new ($fn2) or die "%Error: $! $fn2,";
	    my @l1 = $f1->getlines();
	    my @l2 = $f2->getlines();
	    @l1 = grep (!/`line/, @l1);
	    @l2 = grep (!/`line/, @l2);
	    my $nl = $#l1;  $nl = $#l2 if ($#l2 > $nl);
	    for (my $l=0; $l<=$nl; $l++) {
		next if $l2[$l] =~ /vpassert/;
		if (($l1[$l]||"") ne ($l2[$l]||"")) {
		    warn ("%Warning: Line ".($l+1)." mismatches; diff $fn1 $fn2\n"
			  ."F1: ".($l1[$l]||"*EOF*\n")
			  ."F2: ".($l2[$l]||"*EOF*\n"));
		    $ok = 0;
		    next file;
		}
	    }
	}
	else { die; }
    }
    return $ok;
}