diff options
author | Tristan Gingold <tgingold@free.fr> | 2020-04-24 06:05:32 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2020-04-24 06:05:32 +0200 |
commit | 4198d9f7a3b56129f862a219ad9becaa2c684486 (patch) | |
tree | d9f879b54cb09f8f1561fa00feb712c9f51ef561 /testsuite/gna | |
parent | 520e8f8ef162cda758f3e7b8f8deec620055c82e (diff) | |
download | ghdl-4198d9f7a3b56129f862a219ad9becaa2c684486.tar.gz ghdl-4198d9f7a3b56129f862a219ad9becaa2c684486.tar.bz2 ghdl-4198d9f7a3b56129f862a219ad9becaa2c684486.zip |
testsuite/gna: add test for #1256
Diffstat (limited to 'testsuite/gna')
-rw-r--r-- | testsuite/gna/issue1256/enum_test.ref | 17 | ||||
-rw-r--r-- | testsuite/gna/issue1256/enum_test.vhdl | 34 | ||||
-rwxr-xr-x | testsuite/gna/issue1256/testsuite.sh | 26 | ||||
-rw-r--r-- | testsuite/gna/issue1256/vpi_plugin.c | 127 |
4 files changed, 204 insertions, 0 deletions
diff --git a/testsuite/gna/issue1256/enum_test.ref b/testsuite/gna/issue1256/enum_test.ref new file mode 100644 index 000000000..3ad50f33c --- /dev/null +++ b/testsuite/gna/issue1256/enum_test.ref @@ -0,0 +1,17 @@ +Start of simulation +enum in <= 000 iteration 0 +enum decoded = 000 iteration 1 +enum out = 00000000 iteration 1 +enum in <= 001 iteration 1 +enum decoded = 001 iteration 2 +enum out = 00000001 iteration 2 +enum in <= 010 iteration 2 +enum decoded = 010 iteration 3 +enum out = 00000010 iteration 3 +enum in <= 011 iteration 3 +enum decoded = 011 iteration 4 +enum out = 00000011 iteration 4 +enum in <= 100 iteration 4 +enum decoded = 100 iteration 5 +enum out = 00000100 iteration 5 +End of simulation 6 diff --git a/testsuite/gna/issue1256/enum_test.vhdl b/testsuite/gna/issue1256/enum_test.vhdl new file mode 100644 index 000000000..42a1e2a3b --- /dev/null +++ b/testsuite/gna/issue1256/enum_test.vhdl @@ -0,0 +1,34 @@ +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +package pkg_enum is + type State is (A,B,C,D,E); +end pkg_enum; + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +library work; +use work.all; +use work.pkg_enum.all; + +entity enum_test is + port(enum_in : in State; + enum_out : out State; + enum_decoded: out unsigned(2 downto 0) + ); +end enum_test; + +architecture arch of enum_test is +begin + with enum_in select + enum_decoded <= "000" when A, + "001" when B, + "010" when C, + "011" when D, + "100" when others; + + enum_out <= enum_in; +end arch; diff --git a/testsuite/gna/issue1256/testsuite.sh b/testsuite/gna/issue1256/testsuite.sh new file mode 100755 index 000000000..1bb44dcf1 --- /dev/null +++ b/testsuite/gna/issue1256/testsuite.sh @@ -0,0 +1,26 @@ +#! /bin/sh + +. ../../testenv.sh + +analyze enum_test.vhdl +elab enum_test + +if ghdl_has_feature enum_test vpi; then + if [ "$OS" = "Windows_NT" ]; then + # Need to put the directory containing libghdlvpi.dll in the path. + vpi_lib=`$GHDL --vpi-library-dir | sed -e 's!\\\\!/!g' -e 's!^C:!/C!g'` + echo vpi_lib: $vpi_lib + PATH="$PATH:$vpi_lib" + fi + + $GHDL --vpi-compile -v gcc -c vpi_plugin.c + $GHDL --vpi-link -v gcc -o vpi_plugin.vpi vpi_plugin.o + + simulate enum_test --vpi=./vpi_plugin.vpi > enum_test.out + diff --strip-trailing-cr enum_test.ref enum_test.out + + rm -f vpi_plugin.vpi vpi_plugin.o +fi +clean + +echo "Test successful" diff --git a/testsuite/gna/issue1256/vpi_plugin.c b/testsuite/gna/issue1256/vpi_plugin.c new file mode 100644 index 000000000..6d365cc82 --- /dev/null +++ b/testsuite/gna/issue1256/vpi_plugin.c @@ -0,0 +1,127 @@ +#include<vpi_user.h> +#include<inttypes.h> +#include<stdio.h> + +#define STOP_ITERATION 5 + +static uint32_t iteration = 0; + +static const char* const input_values[5] = {"000", + "001", + "010", + "011", + "100"}; + +static vpiHandle enum_in_handle; +static vpiHandle enum_out_handle; +static vpiHandle enum_decoded_handle; + +static PLI_INT32 start_cb(p_cb_data); +static PLI_INT32 end_cb(p_cb_data); +static PLI_INT32 rw_cb(p_cb_data); +static PLI_INT32 ro_cb(p_cb_data); +static PLI_INT32 delay_rw_cb(p_cb_data); +static PLI_INT32 delay_ro_cb(p_cb_data); + +static void register_cb(PLI_INT32(*f)(p_cb_data), + PLI_INT32 reason, + int64_t cycles) +{ + + s_cb_data cbData; + s_vpi_time simuTime; + if (cycles < 0){ + cbData.time = NULL; + } else { + cbData.time = &simuTime; + simuTime.type = vpiSimTime; + simuTime.high = (PLI_INT32) (cycles >> 32); + simuTime.low = (PLI_INT32) (cycles & 0xFFFFFFFF); + } + + cbData.reason = reason; + cbData.cb_rtn = f; + cbData.user_data = 0; + cbData.value = 0; + + vpi_register_cb(&cbData); +} + +static void entry_point_cb() { + register_cb(start_cb, cbStartOfSimulation, -1); + register_cb(end_cb, cbEndOfSimulation, -1); + register_cb(delay_ro_cb, cbAfterDelay, 0); +} + +static PLI_INT32 start_cb(p_cb_data data){ + (void) data; + printf("Start of simulation \n"); + + enum_in_handle = vpi_handle_by_name("enum_test.enum_in", NULL); + if(!enum_in_handle) printf("enum in not found\n"); + enum_out_handle = vpi_handle_by_name("enum_test.enum_out", NULL); + if(!enum_out_handle) printf("enum out not found\n"); + enum_decoded_handle = vpi_handle_by_name("enum_test.enum_decoded", NULL); + if(!enum_decoded_handle) printf("enum decoded not found\n"); + + return 0; +} + +static PLI_INT32 end_cb(p_cb_data data){ + (void) data; + printf("End of simulation %u \n", iteration); + return 0; +} + + +static PLI_INT32 rw_cb(p_cb_data data){ + (void) data; + s_vpi_value val; + val.format = vpiBinStrVal; + + if(iteration > 0) { + vpi_get_value(enum_decoded_handle, &val); + val.format = vpiBinStrVal; + printf("enum decoded = %s iteration %d \n", val.value.str, iteration); + vpi_get_value(enum_out_handle, &val); + printf("enum out = %s iteration %d \n", val.value.str, iteration); + + val.format = vpiBinStrVal; + } + + if(iteration < STOP_ITERATION) { + + val.value.str = (char *) input_values[iteration]; + printf("enum in <= %s iteration %d \n", val.value.str, iteration); + vpi_put_value(enum_in_handle, &val, NULL, vpiNoDelay); + register_cb(delay_ro_cb, cbAfterDelay, 1); + } else { + vpi_control(vpiFinish, 0); + } + + iteration++; + return 0; +} + +static PLI_INT32 ro_cb(p_cb_data data){ + (void) data; + register_cb(delay_rw_cb, cbAfterDelay, 0); + return 0; +} + +static PLI_INT32 delay_rw_cb(p_cb_data data){ + (void) data; + register_cb(rw_cb, cbReadWriteSynch, 0); + return 0; +} + +static PLI_INT32 delay_ro_cb(p_cb_data data){ + (void) data; + register_cb(ro_cb, cbReadOnlySynch, 0); + return 0; +} + +void (*vlog_startup_routines[]) () = { + entry_point_cb, + 0 +}; |