diff options
Diffstat (limited to 'testsuite/gna')
-rw-r--r-- | testsuite/gna/issue1779/repro1.vhdl | 31 | ||||
-rwxr-xr-x | testsuite/gna/issue1779/testsuite.sh | 26 | ||||
-rw-r--r-- | testsuite/gna/issue1779/vpi1.c | 117 |
3 files changed, 174 insertions, 0 deletions
diff --git a/testsuite/gna/issue1779/repro1.vhdl b/testsuite/gna/issue1779/repro1.vhdl new file mode 100644 index 000000000..a330675bc --- /dev/null +++ b/testsuite/gna/issue1779/repro1.vhdl @@ -0,0 +1,31 @@ +entity repro1 is +end; + +architecture rtl of repro1 is + signal v_32 : integer := 1; + signal v_8 : integer range 0 to 255; + signal res : integer; + signal clk : bit; +begin + process + begin + clk <= '0'; + for i in 1 to 5 * 2 loop + wait for 10 ns; + clk <= not clk; + end loop; + wait; + end process; + + process (v_32) is + begin + report "V_32=" & integer'image (v_32); + end process; + + process (v_8) is + begin + report "V_8=" & integer'image (v_8); + end process; + + res <= v_32 + v_8; +end rtl; diff --git a/testsuite/gna/issue1779/testsuite.sh b/testsuite/gna/issue1779/testsuite.sh new file mode 100755 index 000000000..288e383a7 --- /dev/null +++ b/testsuite/gna/issue1779/testsuite.sh @@ -0,0 +1,26 @@ +#! /bin/sh + +. ../../testenv.sh + +# From issue 531 + +analyze repro1.vhdl +elab repro1 + +if c_compiler_is_available && ghdl_has_feature repro1 vpi; then + $GHDL --vpi-compile -v gcc -c vpi1.c + $GHDL --vpi-link -v gcc -o vpi1.vpi vpi1.o + + add_vpi_path + + simulate repro1 --vpi=./vpi1.vpi | tee repro1.out + if grep -q Error repro1.out; then + echo "Error in output" + exit 1; + fi + + rm -f vpi1.vpi vpi1.o sliced_ex.out +fi +clean + +echo "Test successful" diff --git a/testsuite/gna/issue1779/vpi1.c b/testsuite/gna/issue1779/vpi1.c new file mode 100644 index 000000000..59e8550ed --- /dev/null +++ b/testsuite/gna/issue1779/vpi1.c @@ -0,0 +1,117 @@ +#include <stdio.h> +#include <string.h> +#include <vpi_user.h> + +struct net_descs +{ + const char *name; + vpiHandle *handle; +}; + +static vpiHandle clk, v_32, v_8, res; +static int cnt; + +static struct net_descs nets[] = { + { "repro1.clk", &clk}, + { "repro1.v_32", &v_32}, + { "repro1.v_8", &v_8}, + { "repro1.res", &res}, + { NULL, NULL} +}; + +static PLI_INT32 +vpi_clk_proc(p_cb_data data) +{ + s_vpi_value val; + + val.format = vpiBinStrVal; + vpi_get_value (clk, &val); + /* Detect edge. */ + if (strcmp (val.value.str, "1") != 0) + return 0; + + val.format = vpiBinStrVal; + vpi_get_value (res, &val); + printf ("cycle %d: res = %s\n", cnt, val.value.str); + + switch (cnt) + { + case 0: + val.format = vpiBinStrVal; + val.value.str = "0001"; + vpi_put_value (v_32, &val, NULL, vpiNoDelay); + val.format = vpiBinStrVal; + val.value.str = "0010"; + vpi_put_value (v_8, &val, NULL, vpiNoDelay); + break; + case 2: + val.format = vpiBinStrVal; + val.value.str = "0010"; + vpi_put_value (v_32, &val, NULL, vpiNoDelay); + val.format = vpiBinStrVal; + val.value.str = "0011"; + vpi_put_value (v_8, &val, NULL, vpiNoDelay); + break; + case 3: + if (strcmp(val.value.str, "00000000000000000000000000000101") != 0) + printf ("Error!\n"); + val.format = vpiIntVal; + val.value.integer = 123; + vpi_put_value (v_32, &val, NULL, vpiNoDelay); + break; + case 4: + if (strcmp(val.value.str, "00000000000000000000000001111110") != 0) + printf ("Error!\n"); + break; + default: + break; + } + + cnt++; + return 0; +} + +static PLI_INT32 +vpi_start_proc(p_cb_data data) +{ + s_vpi_value val; + s_cb_data cb; + int i; + + for (i = 0; nets[i].name; i++) + { + *nets[i].handle = vpi_handle_by_name ((char *)nets[i].name, NULL); + if (*nets[i].handle == NULL) + { + printf ("cannot get net %s\n", nets[i].name); + return 0; + } + } + + cb.reason = cbValueChange; + cb.cb_rtn = &vpi_clk_proc; + cb.user_data = NULL; + cb.obj = clk; + if (vpi_register_cb (&cb) == NULL) + vpi_printf ("cannot register ValueChange call back\n"); + + return 0; +} + +static void +my_handle_register(void) +{ + s_cb_data cb; + + cb.reason = cbStartOfSimulation; + cb.cb_rtn = &vpi_start_proc; + cb.user_data = NULL; + if (vpi_register_cb (&cb) == NULL) + vpi_printf ("cannot register StartOfSimulation call-back\n"); +} + +void (*vlog_startup_routines[]) () = +{ + my_handle_register, + 0 +}; |