aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2017-05-17 06:55:08 +0200
committerTristan Gingold <tgingold@free.fr>2017-05-18 07:59:34 +0200
commitb8655214d98075df0147015a0fab864b3f2abc86 (patch)
tree00d78f7ad6e63bc67e995087d3ec352c7c39620c /testsuite
parent2e52e07e6a18a89d06060f09f952d78d704d0c00 (diff)
downloadghdl-b8655214d98075df0147015a0fab864b3f2abc86.tar.gz
ghdl-b8655214d98075df0147015a0fab864b3f2abc86.tar.bz2
ghdl-b8655214d98075df0147015a0fab864b3f2abc86.zip
Testcase for #333
Close #333
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/gna/issue333/repro.vhdl30
-rwxr-xr-xtestsuite/gna/issue333/testsuite.sh15
-rw-r--r--testsuite/gna/issue333/time_test.vhdl24
3 files changed, 69 insertions, 0 deletions
diff --git a/testsuite/gna/issue333/repro.vhdl b/testsuite/gna/issue333/repro.vhdl
new file mode 100644
index 000000000..8bab387ce
--- /dev/null
+++ b/testsuite/gna/issue333/repro.vhdl
@@ -0,0 +1,30 @@
+entity repro is
+end repro;
+
+architecture Behavioral of repro is
+
+constant c_CLOCK_FREQUENCY : natural := 32000000;
+constant c_SWITCH_ON_TIME_ms : time := 200 ms;
+constant c_switch_ms : natural := c_SWITCH_ON_TIME_ms / 1 ms;
+constant c_freq1 : real := real(c_CLOCK_FREQUENCY *
+ (c_SWITCH_ON_TIME_ms / 1 ms));
+constant c_SWITCH_COUNT_CYCLES : integer := integer(real(c_CLOCK_FREQUENCY *
+ (c_SWITCH_ON_TIME_ms / 1 ms)) / 1000.0);
+
+begin
+process is
+begin
+ report " Switch ON time " & time'image(c_SWITCH_ON_TIME_ms) severity NOTE;
+ report " Switch count " & natural'image(c_SWITCH_COUNT_CYCLES) severity NOTE;
+ -- sanity checks on time constraints
+ report "Clock frequency = " & natural'image(c_CLOCK_FREQUENCY) & " Hz" severity NOTE;
+ report "switch_time (ms): " & natural'image (c_switch_ms);
+ report "freq * switch_time (ms): " & real'image (c_freq1);
+
+ report "Clock period = " & time'image( 1 sec / c_CLOCK_FREQUENCY) severity NOTE;
+ report "Switch period = " & time'image ( 1 sec / c_CLOCK_FREQUENCY * c_SWITCH_COUNT_CYCLES) severity NOTE;
+ Assert c_SWITCH_ON_TIME_ms = 1 sec / c_CLOCK_FREQUENCY * c_SWITCH_COUNT_CYCLES
+ report "Wrong Switch ON time = " & time'image ( 1 sec / c_CLOCK_FREQUENCY * c_SWITCH_COUNT_CYCLES) severity ERROR;
+ wait;
+end process;
+end Behavioral;
diff --git a/testsuite/gna/issue333/testsuite.sh b/testsuite/gna/issue333/testsuite.sh
new file mode 100755
index 000000000..e182d70eb
--- /dev/null
+++ b/testsuite/gna/issue333/testsuite.sh
@@ -0,0 +1,15 @@
+#! /bin/sh
+
+. ../../testenv.sh
+
+if $GHDL --version | grep -q "mcode code generator"; then
+ analyze repro.vhdl
+ elab_simulate_failure repro
+
+ analyze time_test.vhdl
+ elab_simulate_failure time_test
+fi
+
+clean
+
+echo "Test successful"
diff --git a/testsuite/gna/issue333/time_test.vhdl b/testsuite/gna/issue333/time_test.vhdl
new file mode 100644
index 000000000..2895f3ef0
--- /dev/null
+++ b/testsuite/gna/issue333/time_test.vhdl
@@ -0,0 +1,24 @@
+entity Time_test is
+end Time_test;
+
+architecture Behavioral of Time_test is
+
+constant c_CLOCK_FREQUENCY : natural := 32000000;
+constant c_SWITCH_ON_TIME_ms : time := 200 ms;
+constant c_SWITCH_COUNT_CYCLES : integer := integer(real(c_CLOCK_FREQUENCY *
+ (c_SWITCH_ON_TIME_ms / 1 ms)) / 1000.0);
+
+begin
+process is
+begin
+ report " Switch ON time " & time'image(c_SWITCH_ON_TIME_ms) severity NOTE;
+ report " Switch count " & natural'image(c_SWITCH_COUNT_CYCLES) severity NOTE;
+ -- sanity checks on time constraints
+ report "Clock frequency = " & natural'image(c_CLOCK_FREQUENCY) & " Hz" severity NOTE;
+ report "Clock period = " & time'image( 1 sec / c_CLOCK_FREQUENCY) severity NOTE;
+ report "Switch period = " & time'image ( 1 sec / c_CLOCK_FREQUENCY * c_SWITCH_COUNT_CYCLES) severity NOTE;
+ Assert c_SWITCH_ON_TIME_ms = 1 sec / c_CLOCK_FREQUENCY * c_SWITCH_COUNT_CYCLES
+ report "Wrong Switch ON time = " & time'image ( 1 sec / c_CLOCK_FREQUENCY * c_SWITCH_COUNT_CYCLES) severity ERROR;
+ wait;
+end process;
+end Behavioral;