1 // -*- mode: C++; c-file-style: "cc-mode" -*-
2 //*************************************************************************
3 //
4 // Copyright 2009-2017 by Wilson Snyder. This program is free software; you can
5 // redistribute it and/or modify it under the terms of either the GNU
6 // Lesser General Public License Version 3 or the Perl Artistic License
7 // Version 2.0.
8 // SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
9 //
10 //*************************************************************************
11 
12 #include <cstdio>
13 #include <cstring>
14 #include <iostream>
15 #include "svdpi.h"
16 
17 #include "TestCheck.h"
18 
19 //======================================================================
20 
21 // clang-format off
22 #if defined(VERILATOR)
23 # include "Vt_dpi_openfirst__Dpi.h"
24 #elif defined(VCS)
25 # include "../vc_hdrs.h"
26 #elif defined(NC)
27 # define NEED_EXTERNS
28 #else
29 # error "Unknown simulator for DPI test"
30 #endif
31 // clang-format on
32 
33 #ifdef NEED_EXTERNS
34 extern "C" {
35 // If get ncsim: *F,NOFDPI: Function {foo} not found in default libdpi.
36 // Then probably forgot to list a function here.
37 
38 extern int dpii_failure();
39 extern void dpii_open_i(const svOpenArrayHandle i, const svOpenArrayHandle o);
40 }
41 #endif
42 
43 //======================================================================
44 
45 int errors = 0;
dpii_failure()46 int dpii_failure() { return errors; }
47 
48 //======================================================================
49 
dpii_open_i(const svOpenArrayHandle i,const svOpenArrayHandle o)50 void dpii_open_i(const svOpenArrayHandle i, const svOpenArrayHandle o) {
51     // Illegal in VCS:
52     // TEST_CHECK_HEX_EQ(svLeft(i, 0), 2);
53     // TEST_CHECK_HEX_EQ(svRight(i, 0), 0);
54     // TEST_CHECK_HEX_EQ(svLow(i, 0), 0);
55     // TEST_CHECK_HEX_EQ(svHigh(i, 0), 2);
56     //
57     TEST_CHECK_HEX_EQ(svDimensions(i), 1);
58     TEST_CHECK_HEX_EQ(svLeft(i, 1), 2);
59     TEST_CHECK_HEX_EQ(svRight(i, 1), 0);
60     TEST_CHECK_HEX_EQ(svLow(i, 1), 0);
61     TEST_CHECK_HEX_EQ(svHigh(i, 1), 2);
62     // TEST_CHECK_HEX_EQ(svIncrement(i, 1), 0);
63     TEST_CHECK_HEX_EQ(svSize(i, 1), 3);
64     for (int a = 0; a < 3; ++a) {
65         svBitVecVal vec[1];
66         svGetBitArrElemVecVal(vec, i, a);
67         vec[0] = ~vec[0];
68         svPutBitArrElemVecVal(o, vec, a);
69     }
70 }
71