diff options
author | Ben Reynwar <ben@reynwar.net> | 2020-05-10 07:56:48 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-10 16:56:48 +0200 |
commit | a0919fe84b25f37d0307805650379830094fcfbf (patch) | |
tree | 01d1e5693e7ce954495eca1473319a32057c57fe /testsuite/vpi/vpi002 | |
parent | 06202188e0e88c0096518415413c08bd0471644b (diff) | |
download | ghdl-a0919fe84b25f37d0307805650379830094fcfbf.tar.gz ghdl-a0919fe84b25f37d0307805650379830094fcfbf.tar.bz2 ghdl-a0919fe84b25f37d0307805650379830094fcfbf.zip |
Constants in vpi (#1297)
* Adding some very basic vpi tests.
* Modify test so that's it's checking VPI access to constants.
* Provide VPI to access constants.
* Add vpi tests to testsuite.
* Fix bug to allow getting values of generic/constant boolean and std_logic.
* Fix stupid copying mistake in last commit.
* Formatting and trying to get tests working on windows.
* Fixing comment and removing redundant VhpiConstantDeclK
Diffstat (limited to 'testsuite/vpi/vpi002')
-rw-r--r-- | testsuite/vpi/vpi002/mydesign.vhdl | 46 | ||||
-rwxr-xr-x | testsuite/vpi/vpi002/testsuite.sh | 28 | ||||
-rw-r--r-- | testsuite/vpi/vpi002/vpi1.c | 80 |
3 files changed, 154 insertions, 0 deletions
diff --git a/testsuite/vpi/vpi002/mydesign.vhdl b/testsuite/vpi/vpi002/mydesign.vhdl new file mode 100644 index 000000000..c542f5fa9 --- /dev/null +++ b/testsuite/vpi/vpi002/mydesign.vhdl @@ -0,0 +1,46 @@ +library ieee ; +use ieee.std_logic_1164.all; + +package mypackage is + type myenum is (ONE, TWO, THREE); + subtype myarray is bit_vector(2 downto 0); + type myarray5 is array(1 downto 0) of bit; +end package; + +library ieee ; +use ieee.std_logic_1164.all; +use work.mypackage.all; + +entity myentity is + generic ( + width: integer := 2; + genenum: myenum := ONE; + genarray1: bit_vector(1 downto 0) := "01"; + genarray3: myarray := "010"; + genarray5: myarray5 := ('1', '0') + ); + port ( + portenum: in myenum; + portarray1: in bit_vector(1 downto 0); + portarray2: in bit_vector(width downto 0); + portarray3: in myarray; + portarray5: in myarray5 + ); +end myentity; + +architecture arch of myentity is + subtype myarray4 is bit_vector(width downto 0); + signal sigenum: myenum; + constant constenum: myenum := ONE; + signal sigarray1: bit_vector(1 downto 0); + constant constarray1: bit_vector(1 downto 0) := "10"; + signal sigarray2: bit_vector(width downto 0); + constant constarray2: bit_vector(width downto 0) := (others => '1'); + signal sigarray3: myarray; + constant constarray3: myarray := "101"; + signal sigarray4: myarray4; + constant constarray4: myarray4:= (others => '1'); + signal sigarray5: myarray5; + constant constarray5: myarray5:= (others => '1'); +begin +end arch; diff --git a/testsuite/vpi/vpi002/testsuite.sh b/testsuite/vpi/vpi002/testsuite.sh new file mode 100755 index 000000000..508ad6b65 --- /dev/null +++ b/testsuite/vpi/vpi002/testsuite.sh @@ -0,0 +1,28 @@ +#! /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 + if grep -q error myentity.out; then + echo "error in output" + exit 1; + fi + + rm -f vpi1.vpi vpi1.o +fi +clean + +echo "Test successful" diff --git a/testsuite/vpi/vpi002/vpi1.c b/testsuite/vpi/vpi002/vpi1.c new file mode 100644 index 000000000..f992e8246 --- /dev/null +++ b/testsuite/vpi/vpi002/vpi1.c @@ -0,0 +1,80 @@ +#include <stdio.h> +#include <vpi_user.h> +#define N_NAMES 12 + +void +vpi_proc (void) +{ + vpiHandle net; + s_vpi_value val; + char names[N_NAMES][64] = + { + // Enum + "myentity.sigenum", + "myentity.portenum", + "myentity.genenum", + //"myentity.constenum" // Not supported + + // Array1 (unbounded static) + "myentity.sigarray1", + "myentity.portarray1", + //"myentity.genarray1", // Not supported + //"myentity.constarray1" // Not supported + //"myentity.sigarray1[0]", // Not supported + //"myentity.portarray1[0]", // Not supported + + // Array2 (unbounded complex) + "myentity.sigarray2", + "myentity.portarray2", + //"myentity.constarray2" // Not supported + + // Array3 (bounded static) + "myentity.sigarray3", + "myentity.portarray3", + //"myentity.genarray3", // Not supported + //"myentity.constarray3" // Not supported + + // Array4 (bounded complex) + "myentity.sigarray4", + //"myentity.constarray4" // Not supported + + // Array4 (bounded static) array of bit + "myentity.sigarray5", + "myentity.portarray5", + //"myentity.constarray5", // Not supported + //"myentity.genarray5", // Not supported + //"myentity.sigarray5[0]", // Not supported + //"myentity.portarray5[0]" // Not supported + }; + + for (int name_index=0; name_index<N_NAMES; name_index+=1) { + printf ("Trying to find name %s\n", names[name_index]); + net = vpi_handle_by_name (names[name_index], NULL); + if (net == NULL) + { + printf ("Error: Failed to find the net %s\n", names[name_index]); + return; + } + val.format = vpiBinStrVal; + vpi_get_value (net, &val); + printf ("value: %s\n", val.value.str); + } +} + +void my_handle_register() +{ + s_cb_data cb; + printf ("Hello world\n"); + + cb.reason = cbEndOfCompile; + cb.cb_rtn = &vpi_proc; + cb.user_data = NULL; + if (vpi_register_cb (&cb) == NULL) + vpi_printf ("Error: Cannot register EndOfCompile call back\n"); +} + +void (*vlog_startup_routines[]) () = +{ + my_handle_register, + 0 +}; |