Tests added

This commit is contained in:
Wilson Snyder 2012-04-12 20:13:35 -04:00
parent e85eb6d0f4
commit e5a991988f
3 changed files with 296 additions and 0 deletions

View File

@ -0,0 +1,23 @@
#!/usr/bin/perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2003 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.
$Self->{vlt} and $Self->unsupported("Verilator unsupported, bug413 short circuit");
compile (
# Amazingly VCS, NC and Verilator all just accept the C file here!
v_flags2 => ["t/t_dpi_shortcircuit_c.cpp"],
verilator_flags2 => ["-Wno-DECLFILENAME"],
);
execute (
check_finished=>1,
);
ok(1);
1;

View File

@ -0,0 +1,214 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// Copyright 2009 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.
`ifdef VCS
`define NO_SHORTREAL
`endif
`ifdef NC
`define NO_SHORTREAL
`endif
`ifdef VERILATOR // Unsupported
`define NO_SHORTREAL
`endif
module t (/*AUTOARG*/);
// Note these are NOT pure.
import "DPI-C" function int dpii_clear ();
import "DPI-C" function int dpii_count (input int i);
import "DPI-C" function bit dpii_inc0 (input int i);
import "DPI-C" function bit dpii_inc1 (input int i);
import "DPI-C" function bit dpii_incx (input int i, input bit value);
// verilator lint_off UNUSED
integer i;
bit b;
// verilator lint_on UNUSED
integer errors;
task check1(integer line, bit got, bit ex);
if (got != ex) begin
$display("%%Error: Line %0d: Bad result, got=%0d expect=%0d",line,got,ex);
errors++;
end
endtask
task check(integer line, int got, int ex);
if (got != ex) begin
$display("%%Error: Line %0d: Bad result, got=%0d expect=%0d",line,got,ex);
errors++;
end
endtask
// Test loop
initial begin
// Spec says && || -> and ?: short circuit, no others do.
// Check both constant & non constants.
dpii_clear();
check1(`__LINE__, (1'b0 && dpii_inc0(0)), 1'b0);
check1(`__LINE__, (1'b1 && dpii_inc0(1)), 1'b0);
check1(`__LINE__, (dpii_inc0(2) && dpii_inc0(3)), 1'b0);
check1(`__LINE__, (dpii_inc1(4) && dpii_inc0(5)), 1'b0);
check1(`__LINE__, (dpii_inc0(6) && dpii_inc1(7)), 1'b0);
check1(`__LINE__, (!(dpii_inc1(8) && dpii_inc1(9))), 1'b0);
check (`__LINE__, dpii_count(0), 0);
check (`__LINE__, dpii_count(1), 1);
check (`__LINE__, dpii_count(2), 1);
check (`__LINE__, dpii_count(3), 0);
check (`__LINE__, dpii_count(4), 1);
check (`__LINE__, dpii_count(5), 1);
check (`__LINE__, dpii_count(6), 1);
check (`__LINE__, dpii_count(7), 0);
check (`__LINE__, dpii_count(8), 1);
check (`__LINE__, dpii_count(9), 1);
//
dpii_clear();
check1(`__LINE__, (1'b0 & dpii_inc0(0)), 1'b0);
check1(`__LINE__, (1'b1 & dpii_inc0(1)), 1'b0);
check1(`__LINE__, (dpii_inc0(2) & dpii_inc0(3)), 1'b0);
check1(`__LINE__, (dpii_inc1(4) & dpii_inc0(5)), 1'b0);
check1(`__LINE__, (dpii_inc0(6) & dpii_inc1(7)), 1'b0);
check1(`__LINE__, (!(dpii_inc1(8) & dpii_inc1(9))), 1'b0);
check (`__LINE__, dpii_count(0), 1);
check (`__LINE__, dpii_count(1), 1);
check (`__LINE__, dpii_count(2), 1);
check (`__LINE__, dpii_count(3), 1);
check (`__LINE__, dpii_count(4), 1);
check (`__LINE__, dpii_count(5), 1);
check (`__LINE__, dpii_count(6), 1);
check (`__LINE__, dpii_count(7), 1);
check (`__LINE__, dpii_count(8), 1);
check (`__LINE__, dpii_count(9), 1);
//
dpii_clear();
check1(`__LINE__, (1'b0 || dpii_inc0(0)), 1'b0);
check1(`__LINE__, (1'b1 || dpii_inc0(1)), 1'b1);
check1(`__LINE__, (dpii_inc0(2) || dpii_inc0(3)), 1'b0);
check1(`__LINE__, (dpii_inc1(4) || dpii_inc0(5)), 1'b1);
check1(`__LINE__, (dpii_inc0(6) || dpii_inc1(7)), 1'b1);
check1(`__LINE__, (!(dpii_inc1(8) || dpii_inc1(9))), 1'b0);
check (`__LINE__, dpii_count(0), 1);
check (`__LINE__, dpii_count(1), 0);
check (`__LINE__, dpii_count(2), 1);
check (`__LINE__, dpii_count(3), 1);
check (`__LINE__, dpii_count(4), 1);
check (`__LINE__, dpii_count(5), 0);
check (`__LINE__, dpii_count(6), 1);
check (`__LINE__, dpii_count(7), 1);
check (`__LINE__, dpii_count(8), 1);
check (`__LINE__, dpii_count(9), 0);
//
dpii_clear();
check1(`__LINE__, (1'b0 | dpii_inc0(0)), 1'b0);
check1(`__LINE__, (1'b1 | dpii_inc0(1)), 1'b1);
check1(`__LINE__, (dpii_inc0(2) | dpii_inc0(3)), 1'b0);
check1(`__LINE__, (dpii_inc1(4) | dpii_inc0(5)), 1'b1);
check1(`__LINE__, (dpii_inc0(6) | dpii_inc1(7)), 1'b1);
check1(`__LINE__, (!(dpii_inc1(8) | dpii_inc1(9))), 1'b0);
check (`__LINE__, dpii_count(0), 1);
check (`__LINE__, dpii_count(1), 1);
check (`__LINE__, dpii_count(2), 1);
check (`__LINE__, dpii_count(3), 1);
check (`__LINE__, dpii_count(4), 1);
check (`__LINE__, dpii_count(5), 1);
check (`__LINE__, dpii_count(6), 1);
check (`__LINE__, dpii_count(7), 1);
check (`__LINE__, dpii_count(8), 1);
check (`__LINE__, dpii_count(9), 1);
//
dpii_clear();
check1(`__LINE__, (1'b0 -> dpii_inc0(0)), 1'b1);
check1(`__LINE__, (1'b1 -> dpii_inc0(1)), 1'b0);
check1(`__LINE__, (dpii_inc0(2) -> dpii_inc0(3)), 1'b1);
check1(`__LINE__, (dpii_inc1(4) -> dpii_inc0(5)), 1'b0);
check1(`__LINE__, (dpii_inc0(6) -> dpii_inc1(7)), 1'b1);
check1(`__LINE__, (!(dpii_inc1(8) -> dpii_inc1(9))), 1'b0);
check (`__LINE__, dpii_count(0), 0);
check (`__LINE__, dpii_count(1), 1);
check (`__LINE__, dpii_count(2), 1);
check (`__LINE__, dpii_count(3), 0);
check (`__LINE__, dpii_count(4), 1);
check (`__LINE__, dpii_count(5), 1);
check (`__LINE__, dpii_count(6), 1);
check (`__LINE__, dpii_count(7), 0);
check (`__LINE__, dpii_count(8), 1);
check (`__LINE__, dpii_count(9), 1);
//
dpii_clear();
check1(`__LINE__, (1'b0 ? dpii_inc0(0) : dpii_inc0(1)), 1'b0);
check1(`__LINE__, (1'b1 ? dpii_inc0(2) : dpii_inc0(3)), 1'b0);
check1(`__LINE__, (dpii_inc0(4) ? dpii_inc0(5) : dpii_inc0(6)), 1'b0);
check1(`__LINE__, (dpii_inc1(7) ? dpii_inc0(8) : dpii_inc0(9)), 1'b0);
check (`__LINE__, dpii_count(0), 0);
check (`__LINE__, dpii_count(1), 1);
check (`__LINE__, dpii_count(2), 1);
check (`__LINE__, dpii_count(3), 0);
check (`__LINE__, dpii_count(4), 1);
check (`__LINE__, dpii_count(5), 0);
check (`__LINE__, dpii_count(6), 1);
check (`__LINE__, dpii_count(7), 1);
check (`__LINE__, dpii_count(8), 1);
check (`__LINE__, dpii_count(9), 0);
//
dpii_clear();
check1(`__LINE__, (1'b0 * dpii_inc0(0)), 1'b0);
check1(`__LINE__, (1'b1 * dpii_inc0(1)), 1'b0);
check1(`__LINE__, (dpii_inc0(2) * dpii_inc0(3)), 1'b0);
check1(`__LINE__, (dpii_inc1(4) * dpii_inc0(5)), 1'b0);
check1(`__LINE__, (dpii_inc0(6) * dpii_inc1(7)), 1'b0);
check1(`__LINE__, (!(dpii_inc1(8) * dpii_inc1(9))), 1'b0);
check (`__LINE__, dpii_count(0), 1);
check (`__LINE__, dpii_count(1), 1);
check (`__LINE__, dpii_count(2), 1);
check (`__LINE__, dpii_count(3), 1);
check (`__LINE__, dpii_count(4), 1);
check (`__LINE__, dpii_count(5), 1);
check (`__LINE__, dpii_count(6), 1);
check (`__LINE__, dpii_count(7), 1);
check (`__LINE__, dpii_count(8), 1);
check (`__LINE__, dpii_count(9), 1);
//
dpii_clear();
check1(`__LINE__, (1'b0 + dpii_inc0(0)), 1'b0);
check1(`__LINE__, (1'b1 + dpii_inc0(1)), 1'b1);
check1(`__LINE__, (dpii_inc0(2) + dpii_inc0(3)), 1'b0);
check1(`__LINE__, (dpii_inc1(4) + dpii_inc0(5)), 1'b1);
check1(`__LINE__, (dpii_inc0(6) + dpii_inc1(7)), 1'b1);
check1(`__LINE__, (dpii_inc1(8) + dpii_inc1(9)), 1'b0);
check (`__LINE__, dpii_count(0), 1);
check (`__LINE__, dpii_count(1), 1);
check (`__LINE__, dpii_count(2), 1);
check (`__LINE__, dpii_count(3), 1);
check (`__LINE__, dpii_count(4), 1);
check (`__LINE__, dpii_count(5), 1);
check (`__LINE__, dpii_count(6), 1);
check (`__LINE__, dpii_count(7), 1);
check (`__LINE__, dpii_count(8), 1);
check (`__LINE__, dpii_count(9), 1);
//
// Something a lot more complicated
dpii_clear();
for (i=0; i<64; i++) begin
b = ( ((dpii_incx(0,i[0])
&& (dpii_incx(1,i[1])
|| dpii_incx(2,i[2])
| dpii_incx(3,i[3]))) // | not ||
|| dpii_incx(4,i[4]))
-> dpii_incx(5,i[5]));
end
check (`__LINE__, dpii_count(0), 64);
check (`__LINE__, dpii_count(1), 32);
check (`__LINE__, dpii_count(2), 16);
check (`__LINE__, dpii_count(3), 16);
check (`__LINE__, dpii_count(4), 36);
check (`__LINE__, dpii_count(5), 46);
if (|errors) $stop;
$write("*-* All Finished *-*\n");
$finish;
end
endmodule

View File

@ -0,0 +1,59 @@
// -*- C++ -*-
//*************************************************************************
//
// Copyright 2011-2011 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.
//
// Verilator 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. See the
// GNU General Public License for more details.
//
//*************************************************************************
#include <cstdio>
#include <cstring>
#include "svdpi.h"
//======================================================================
#if defined(VERILATOR)
# include "Vt_dpi_shortcircuit__Dpi.h"
#elif defined(VCS)
# include "../vc_hdrs.h"
#elif defined(CADENCE)
# define NEED_EXTERNS
#else
# error "Unknown simulator for DPI test"
#endif
#ifdef NEED_EXTERNS
extern "C" {
extern int dpii_clear ();
extern int dpii_count (int idx);
extern unsigned char dpii_inc0 (int idx);
extern unsigned char dpii_inc1 (int idx);
extern unsigned char dpii_incx (int idx, unsigned char value);
}
#endif
//======================================================================
#define COUNTERS 16
static int global_count[COUNTERS];
int dpii_clear () {
for (int i=0; i<COUNTERS; ++i) global_count[i] = 0;
return 0;
}
int dpii_count (int idx) {
return (idx >= 0 && idx<COUNTERS) ? global_count[idx] : -1;
}
unsigned char dpii_incx (int idx, unsigned char value) {
if (idx >= 0 && idx<COUNTERS) global_count[idx]++;
return value;
}
unsigned char dpii_inc0 (int idx) { return dpii_incx(idx,false); }
unsigned char dpii_inc1 (int idx) { return dpii_incx(idx,true); }