From a0919fe84b25f37d0307805650379830094fcfbf Mon Sep 17 00:00:00 2001 From: Ben Reynwar Date: Sun, 10 May 2020 07:56:48 -0700 Subject: 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 --- testsuite/vpi/testsuite.sh | 53 +++++++++++++++++++++++++ testsuite/vpi/vpi001/mydesign.vhdl | 38 ++++++++++++++++++ testsuite/vpi/vpi001/testsuite.sh | 24 ++++++++++++ testsuite/vpi/vpi001/vpi1.c | 65 +++++++++++++++++++++++++++++++ testsuite/vpi/vpi002/mydesign.vhdl | 46 ++++++++++++++++++++++ testsuite/vpi/vpi002/testsuite.sh | 28 +++++++++++++ testsuite/vpi/vpi002/vpi1.c | 80 ++++++++++++++++++++++++++++++++++++++ testsuite/vpi/vpi003/mydesign.vhdl | 30 ++++++++++++++ testsuite/vpi/vpi003/testsuite.sh | 28 +++++++++++++ testsuite/vpi/vpi003/vpi1.c | 55 ++++++++++++++++++++++++++ 10 files changed, 447 insertions(+) create mode 100755 testsuite/vpi/testsuite.sh create mode 100644 testsuite/vpi/vpi001/mydesign.vhdl create mode 100755 testsuite/vpi/vpi001/testsuite.sh create mode 100644 testsuite/vpi/vpi001/vpi1.c create mode 100644 testsuite/vpi/vpi002/mydesign.vhdl create mode 100755 testsuite/vpi/vpi002/testsuite.sh create mode 100644 testsuite/vpi/vpi002/vpi1.c create mode 100644 testsuite/vpi/vpi003/mydesign.vhdl create mode 100755 testsuite/vpi/vpi003/testsuite.sh create mode 100644 testsuite/vpi/vpi003/vpi1.c (limited to 'testsuite/vpi') diff --git a/testsuite/vpi/testsuite.sh b/testsuite/vpi/testsuite.sh new file mode 100755 index 000000000..12b367f2c --- /dev/null +++ b/testsuite/vpi/testsuite.sh @@ -0,0 +1,53 @@ +#! /bin/sh + +# Driver for a testsuite. + +set -e + +# This is the only place where test dirs are specified. Do not duplicate this +# line +dirs="*[0-9]" + +failures="" +full=n + +for opt; do + case "$opt" in + -k | --keep-going) full=y ;; + --dir=*) dirs=`echo $opt | sed -e 's/--dir=//'` ;; + --skip=*) d=`echo $opt | sed -e 's/--skip=//'` + dirs=`echo "" $dirs | sed -e "s/ $d//"` ;; + --start-at=*) d=`echo $opt | sed -e 's/--start-at=//'` + dirs=`echo "" $dirs | sed -e "s/^.* $d//"` + dirs="$d $dirs" ;; + --list-tests) echo $dirs; exit 0;; + *) echo "Unknown option $opt" + exit 2 + ;; + esac +done + +singlerun() { + echo "" + echo "dir $1:" + cd $1 + if ! ./testsuite.sh; then + echo "#################################################################" + echo "######### FAILURE: $1" + echo "#################################################################" + if [ $2 = "y" ]; then + failures="$failures $1" + else + exit 1; + fi + fi + cd .. +} + +for i in $dirs; do singlerun $i $full; done + +if [ x"$failures" = x"" ]; then + echo "tests are successful" && exit 0 +else + echo "test failed ($failures)" && exit 1 +fi diff --git a/testsuite/vpi/vpi001/mydesign.vhdl b/testsuite/vpi/vpi001/mydesign.vhdl new file mode 100644 index 000000000..6b420ac7a --- /dev/null +++ b/testsuite/vpi/vpi001/mydesign.vhdl @@ -0,0 +1,38 @@ +library ieee ; +use ieee.std_logic_1164.all; + +entity myentity is + generic ( + genint: integer := 42; + genstring: string := "fish"; + genbool: boolean := True; + gensl: std_logic := '0' + ); + 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/vpi001/testsuite.sh b/testsuite/vpi/vpi001/testsuite.sh new file mode 100755 index 000000000..a3edac791 --- /dev/null +++ b/testsuite/vpi/vpi001/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/vpi001/vpi1.c b/testsuite/vpi/vpi001/vpi1.c new file mode 100644 index 000000000..c4943fde6 --- /dev/null +++ b/testsuite/vpi/vpi001/vpi1.c @@ -0,0 +1,65 @@ +#include +#include +#define N_NAMES 12 + +void +vpi_proc (void) +{ + vpiHandle net; + s_vpi_value val; + char names[N_NAMES][64] = + { + // Integers + "myentity.sigint", + "myentity.iportint", + "myentity.genint", + "myentity.constint", + + // Std_logic + "myentity.sigsl", + "myentity.iportsl", + "myentity.gensl", + "myentity.constsl", + + // Boolean + "myentity.sigbool", + "myentity.iportbool", + "myentity.genbool", + "myentity.constbool", + + // String + //"myentity.genstring", -- Not supported + //"myentity.conststring" -- Not supported + }; + + for (int name_index=0; name_index '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 +#include +#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 +#include +#define N_NAMES 0 + +void +vpi_proc (void) +{ + vpiHandle net; + s_vpi_value val; + char names[N_NAMES][64] = + { + // Array 2 dimensional (Not supported) + //"myentity.sigarray2dim", + //"myentity.portarray2dim", + //"myentity.genarray2dim", + //"myentity.constarray2dim" + + // Array of bit_vectors (Not supported) + //"myentity.sigarray1", + //"myentity.portarray1", + //"myentity.genarray1", + //"myentity.constarray1" + }; + + for (int name_index=0; name_index