aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarlon James <marlon.james@garmin.com>2020-11-17 17:08:18 -0800
committertgingold <tgingold@users.noreply.github.com>2020-11-19 17:37:35 +0100
commitfa6d95d94f7c309793cc096bfca4de7d646b9fcf (patch)
tree77a59bae89b94753997d47bc519ae39f2f652848
parent20072e856f8f4daea01f434bf7fd3c9468d987b2 (diff)
downloadghdl-fa6d95d94f7c309793cc096bfca4de7d646b9fcf.tar.gz
ghdl-fa6d95d94f7c309793cc096bfca4de7d646b9fcf.tar.bz2
ghdl-fa6d95d94f7c309793cc096bfca4de7d646b9fcf.zip
Add test for vpi_get_vlog_info()
-rw-r--r--testsuite/vpi/vpi004/mydesign.vhdl32
-rwxr-xr-xtestsuite/vpi/vpi004/testsuite.sh24
-rw-r--r--testsuite/vpi/vpi004/vpi1.c55
3 files changed, 111 insertions, 0 deletions
diff --git a/testsuite/vpi/vpi004/mydesign.vhdl b/testsuite/vpi/vpi004/mydesign.vhdl
new file mode 100644
index 000000000..6edbbe9a5
--- /dev/null
+++ b/testsuite/vpi/vpi004/mydesign.vhdl
@@ -0,0 +1,32 @@
+library ieee ;
+use ieee.std_logic_1164.all;
+
+entity myentity is
+ port (
+ iportbool: in boolean;
+ iportint: in integer;
+ iportsl: in std_logic;
+ oportbool: out boolean;
+ oportint: out integer;
+ oportsl: out std_logic
+ );
+end myentity;
+
+architecture arch of myentity is
+ constant constsl: std_logic := '0';
+ signal sigsl: std_logic;
+ constant constint: integer := 42;
+ signal sigint: integer;
+ constant constbool: boolean := True;
+ signal sigbool: boolean;
+ constant conststring: string := "fish";
+begin
+ sigsl <= iportsl;
+ sigbool <= iportbool;
+ sigint <= iportint;
+
+ oportbool <= constbool;
+ oportint <= constint;
+ oportsl <= constsl;
+
+end arch;
diff --git a/testsuite/vpi/vpi004/testsuite.sh b/testsuite/vpi/vpi004/testsuite.sh
new file mode 100755
index 000000000..a3edac791
--- /dev/null
+++ b/testsuite/vpi/vpi004/testsuite.sh
@@ -0,0 +1,24 @@
+#! /bin/sh
+
+. ../../testenv.sh
+
+analyze mydesign.vhdl
+elab myentity
+
+if ghdl_has_feature myentity vpi; then
+ $GHDL --vpi-compile -v gcc -c vpi1.c
+ $GHDL --vpi-link -v gcc -o vpi1.vpi vpi1.o
+
+ add_vpi_path
+
+ simulate myentity --vpi=./vpi1.vpi | tee myentity.out
+ if grep -q Error myentity.out; then
+ echo "Error in output"
+ exit 1;
+ fi
+
+ rm -f vpi1.vpi vpi1.o myentity.out
+fi
+clean
+
+echo "Test successful"
diff --git a/testsuite/vpi/vpi004/vpi1.c b/testsuite/vpi/vpi004/vpi1.c
new file mode 100644
index 000000000..96c6f3809
--- /dev/null
+++ b/testsuite/vpi/vpi004/vpi1.c
@@ -0,0 +1,55 @@
+#include <stdio.h>
+#include <vpi_user.h>
+#define N_NAMES 12
+
+void
+vpi_proc (void)
+{
+ s_vpi_vlog_info info;
+ printf ("Trying to get vlog_info\n");
+ int ret = vpi_get_vlog_info(&info);
+ if (ret != 1) {
+ printf ("Error: Failed to get vlog_info\n");
+ return;
+ }
+
+ if (info.argc < 1) {
+ printf ("Error: Argc was 0\n");
+ return;
+ }
+ printf ("Argc: %d\n", info.argc);
+
+ for (int i = 0; i < info.argc; i++) {
+ printf ("Argv[%d]: %s\n", i, info.argv[i]);
+ }
+
+ if (info.product == NULL) {
+ printf ("Error: product is NULL\n");
+ return;
+ }
+ printf ("Product: %s\n", info.product);
+
+ if (info.version == NULL) {
+ printf ("Error: version is NULL\n");
+ return;
+ }
+ printf ("Version: %s\n", info.version);
+}
+
+void my_handle_register()
+{
+ s_cb_data cb;
+ printf ("Hello world\n");
+
+ cb.reason = cbStartOfSimulation;
+ cb.cb_rtn = &vpi_proc;
+ cb.user_data = NULL;
+ if (vpi_register_cb (&cb) == NULL)
+ vpi_printf ("Error: Cannot register StartOfSimulation call back\n");
+}
+
+void (*vlog_startup_routines[]) () =
+{
+ my_handle_register,
+ 0
+};