diff --git a/test_regress/t/t_dpi_export_scope_bad.cpp b/test_regress/t/t_dpi_export_scope_bad.cpp new file mode 100644 index 000000000..0a19d5add --- /dev/null +++ b/test_regress/t/t_dpi_export_scope_bad.cpp @@ -0,0 +1,44 @@ +// -*- mode: C++; c-file-style: "cc-mode" -*- +// +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2010 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +#include +#include VM_PREFIX_INCLUDE + +//====================================================================== + +#include "Vt_dpi_export_scope_bad__Dpi.h" + +#ifdef NEED_EXTERNS +extern "C" { +extern void dpix_task(); +} +#endif + +//====================================================================== + +unsigned int main_time = 0; + +double sc_time_stamp() { return main_time; } + +VM_PREFIX* topp = nullptr; + +int main(int argc, char* argv[]) { + topp = new VM_PREFIX; + + Verilated::debug(0); + + topp->eval(); + + topp->final(); + VL_DO_DANGLING(delete topp, topp); + return 1; +} + +void dpix_run_tests() { + dpix_task(); // Wrong scope +} diff --git a/test_regress/t/t_dpi_export_scope_bad.out b/test_regress/t/t_dpi_export_scope_bad.out new file mode 100644 index 000000000..490d26c84 --- /dev/null +++ b/test_regress/t/t_dpi_export_scope_bad.out @@ -0,0 +1,2 @@ +%Error: unknown:0: Testbench C called 'dpix_task' but this DPI export function exists only in other scopes, not scope 'TOP.t' +Aborting... diff --git a/test_regress/t/t_dpi_export_scope_bad.pl b/test_regress/t/t_dpi_export_scope_bad.pl new file mode 100755 index 000000000..5b97a7901 --- /dev/null +++ b/test_regress/t/t_dpi_export_scope_bad.pl @@ -0,0 +1,24 @@ +#!/usr/bin/env 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. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(simulator => 1); + +compile( + v_flags2 => ["--exe $Self->{t_dir}/$Self->{name}.cpp"], + make_main => 0, + ); + +execute( + fails => 1, + expect_filename => $Self->{golden_filename}, + ); + +ok(1); +1; diff --git a/test_regress/t/t_dpi_export_scope_bad.v b/test_regress/t/t_dpi_export_scope_bad.v new file mode 100644 index 000000000..ad45d37e6 --- /dev/null +++ b/test_regress/t/t_dpi_export_scope_bad.v @@ -0,0 +1,21 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// Copyright 2020 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. +// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +module t; + s s(); + + import "DPI-C" context function void dpix_run_tests(); + initial dpix_run_tests(); +endmodule + +module s; + export "DPI-C" task dpix_task; + task dpix_task(); + $write("Hello in %m\n"); + endtask +endmodule diff --git a/test_regress/t/t_wrapper_context.cpp b/test_regress/t/t_wrapper_context.cpp index d898c212d..9e203673c 100644 --- a/test_regress/t/t_wrapper_context.cpp +++ b/test_regress/t/t_wrapper_context.cpp @@ -11,11 +11,14 @@ #include #include +#include "TestCheck.h" #include VM_PREFIX_INCLUDE double sc_time_stamp() { return 0; } +int errors = 0; + VerilatedMutex outputMutex; #ifdef T_WRAPPER_CONTEXT @@ -89,6 +92,14 @@ int main(int argc, char** argv, char** env) { context0p->traceEverOn(true); context1p->traceEverOn(true); + // error number checks + TEST_CHECK_EQ(context0p->errorCount(), 0); + TEST_CHECK_EQ(context1p->errorCount(), 0); + context0p->errorCount(1); + TEST_CHECK_EQ(context0p->errorCount(), 1); + context0p->errorCount(0); + TEST_CHECK_EQ(context0p->errorCount(), 0); + // instantiate verilated design std::unique_ptr top0p{new VM_PREFIX{context0p.get(), "top0"}}; std::unique_ptr top1p{new VM_PREFIX{context1p.get(), "top1"}}; @@ -108,7 +119,10 @@ int main(int argc, char** argv, char** env) { // check if both finished bool pass = true; - if (top0p->done_o && top1p->done_o) { + if (errors) { + std::cout << "Error: comparison errors" << std::endl; + pass = false; + } else if (top0p->done_o && top1p->done_o) { std::cout << "*-* All Finished *-*" << std::endl; } else { std::cout << "Error: Early termination!" << std::endl;