aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/gna
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2021-01-29 20:35:37 +0100
committerTristan Gingold <tgingold@free.fr>2021-01-29 20:35:37 +0100
commitdd804ce80852aa583308b02330dd93a94d5fc423 (patch)
tree42a5fc4d533c9ba12b170dc6274a8dd6673586a4 /testsuite/gna
parent45dc90330d619d6445d178483a36fef7673b51fe (diff)
downloadghdl-dd804ce80852aa583308b02330dd93a94d5fc423.tar.gz
ghdl-dd804ce80852aa583308b02330dd93a94d5fc423.tar.bz2
ghdl-dd804ce80852aa583308b02330dd93a94d5fc423.zip
testsuite/gna: file testcase for #1623
Diffstat (limited to 'testsuite/gna')
-rw-r--r--testsuite/gna/issue1623/load.c28
-rw-r--r--testsuite/gna/issue1623/main.c27
-rw-r--r--testsuite/gna/issue1623/pyaux.py42
-rwxr-xr-xtestsuite/gna/issue1623/run.sh38
-rw-r--r--testsuite/gna/issue1623/tb.vhd18
-rwxr-xr-xtestsuite/gna/issue1623/testsuite.sh12
6 files changed, 165 insertions, 0 deletions
diff --git a/testsuite/gna/issue1623/load.c b/testsuite/gna/issue1623/load.c
new file mode 100644
index 000000000..5e45b3a70
--- /dev/null
+++ b/testsuite/gna/issue1623/load.c
@@ -0,0 +1,28 @@
+#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char** argv) {
+
+ void* h = dlopen(argv[1], RTLD_LAZY);
+ if (!h){
+ fprintf(stderr, "dlopen: %s\n", dlerror());
+ exit(1);
+ }
+
+ typedef int main_t(int, char**);
+
+ main_t* entry = (main_t*)dlsym(h, "entry");
+ if (!entry){
+ fprintf(stderr, "dlsym: %s\n", dlerror());
+ exit(2);
+ }
+
+ printf("Call entry\n");
+ printf("Return from entry: %d\n", entry(0, NULL));
+
+ dlclose(h);
+
+ return 0;
+
+}
diff --git a/testsuite/gna/issue1623/main.c b/testsuite/gna/issue1623/main.c
new file mode 100644
index 000000000..9ab757316
--- /dev/null
+++ b/testsuite/gna/issue1623/main.c
@@ -0,0 +1,27 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <signal.h>
+
+extern int ghdl_main(int argc, void** argv);
+
+void sigabrtHandler(int sig_num) {
+ // Reset handler to catch SIGABRT next time. Refer http://en.cppreference.com/w/c/program/signal
+ signal(SIGABRT, sigabrtHandler);
+ printf("SIGABRT caught %d!\n", sig_num);
+ fflush(stdout);
+}
+
+static void exit_handler(void) {
+ printf("This is the exit handler.\n");
+}
+
+int entry(int argc, void** argv) {
+ signal(SIGABRT, sigabrtHandler);
+ atexit(exit_handler);
+
+ printf("Hello entry!\n");
+ int ecode = ghdl_main(argc, argv);
+ printf("Bye entry <%d>!\n", ecode);
+
+ return ecode;
+}
diff --git a/testsuite/gna/issue1623/pyaux.py b/testsuite/gna/issue1623/pyaux.py
new file mode 100644
index 000000000..f7ac33a61
--- /dev/null
+++ b/testsuite/gna/issue1623/pyaux.py
@@ -0,0 +1,42 @@
+from sys import platform
+from pathlib import Path
+import ctypes
+import _ctypes
+from sys import stdout, stderr
+
+
+def dlopen(path):
+ if not Path(path).exists():
+ print('Executable binary not found: ' + path)
+ exit(1)
+ try:
+ return ctypes.CDLL(path)
+ except OSError:
+ print('Loading executables dynamically seems not to be supported on this platform')
+ exit(1)
+
+
+def dlclose(obj):
+ if platform == "win32":
+ _ctypes.FreeLibrary(obj._handle)
+ else:
+ _ctypes.dlclose(obj._handle)
+
+
+def enc_args(args):
+ xargs = (ctypes.POINTER(ctypes.c_char) * len(args))()
+ for idx, arg in enumerate(args):
+ xargs[idx] = ctypes.create_string_buffer(arg.encode('utf-8'))
+ return xargs
+
+
+def run(path, argc, argv):
+ print("PY RUN ENTER")
+ ghdl = dlopen(path)
+ _ret = ghdl.entry(argc, argv)
+ stdout.flush()
+ stderr.flush()
+ dlclose(ghdl)
+ print("PY RUN EXIT <%d>" % _ret)
+ stdout.flush()
+ stderr.flush()
diff --git a/testsuite/gna/issue1623/run.sh b/testsuite/gna/issue1623/run.sh
new file mode 100755
index 000000000..164b68422
--- /dev/null
+++ b/testsuite/gna/issue1623/run.sh
@@ -0,0 +1,38 @@
+#!/usr/bin/env sh
+
+set -e
+
+cd $(dirname "$0")
+
+_ext='so'
+case "$(uname)" in
+ MINGW*) _ext='dll';;
+ Darwin*) _ext='dylib';;
+esac
+
+gcc load.c -o load -ldl
+
+for std in '08' '93'; do
+
+ echo "> [$std] Analyze tb.vhd"
+ $GHDL -a --std="$std" tb.vhd
+
+ echo ""
+
+ for item in 'pass' 'fail'; do
+ echo "> [$std] Build tb-${item}.${_ext}"
+ $GHDL -e --std="$std" -shared -Wl,-fPIC -Wl,main.c tb ${item}
+ echo ""
+
+ echo "> [$std] C load and run tb-${item}.${_ext}"
+ ./load "./tb-${item}.${_ext}"
+ echo ""
+
+ echo "> [$std] Python load and run tb-${item}.${_ext}"
+ python3 -c 'from pyaux import run; run("./tb-'"${item}.${_ext}"'", 0, None)'
+ echo ""
+ done
+
+done
+
+rm -rf *.o *."${_ext}" *.cf
diff --git a/testsuite/gna/issue1623/tb.vhd b/testsuite/gna/issue1623/tb.vhd
new file mode 100644
index 000000000..bed04ddac
--- /dev/null
+++ b/testsuite/gna/issue1623/tb.vhd
@@ -0,0 +1,18 @@
+entity tb is
+end entity;
+
+architecture pass of tb is
+begin
+ process begin
+ report "Hello wrapping/exitcb [pass]!" severity note;
+ wait;
+ end process;
+end;
+
+architecture fail of tb is
+begin
+ process begin
+ report "Hello wrapping/exitcb [fail]!" severity failure;
+ wait;
+ end process;
+end;
diff --git a/testsuite/gna/issue1623/testsuite.sh b/testsuite/gna/issue1623/testsuite.sh
new file mode 100755
index 000000000..48122abbb
--- /dev/null
+++ b/testsuite/gna/issue1623/testsuite.sh
@@ -0,0 +1,12 @@
+#! /bin/sh
+
+exit 0
+. ../../testenv.sh
+
+export GHDL_STD_FLAGS=--std=08
+analyze repro.vhdl
+elab_simulate repro
+
+clean
+
+echo "Test successful"