From 7135caeea2880d7d1ee96a66bd7941bcc56a4ddb Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Tue, 26 Jan 2021 07:50:21 +0100 Subject: testsuite/gna: add a test for #803 --- testsuite/gna/issue803/main-mac.c | 27 +++++++++++++++++++++++++++ testsuite/gna/issue803/main-win.c | 27 +++++++++++++++++++++++++++ testsuite/gna/issue803/main.c | 33 +++++++++++++++++++++++++++++++++ testsuite/gna/issue803/tb.vhdl | 10 ++++++++++ testsuite/gna/issue803/testsuite.sh | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 131 insertions(+) create mode 100644 testsuite/gna/issue803/main-mac.c create mode 100644 testsuite/gna/issue803/main-win.c create mode 100644 testsuite/gna/issue803/main.c create mode 100644 testsuite/gna/issue803/tb.vhdl create mode 100755 testsuite/gna/issue803/testsuite.sh (limited to 'testsuite/gna') diff --git a/testsuite/gna/issue803/main-mac.c b/testsuite/gna/issue803/main-mac.c new file mode 100644 index 000000000..665c347e0 --- /dev/null +++ b/testsuite/gna/issue803/main-mac.c @@ -0,0 +1,27 @@ +#include +#include +#include + +int main(int argc, char** argv) { + + void* h = dlopen("./tb.dylib", RTLD_LAZY); + if (!h){ + fprintf(stderr, "%s\n", dlerror()); + exit(1); + } + + typedef int main_t(int, char**); + + main_t* ghdl_main = (main_t*)dlsym(h, "ghdl_main"); + if (!ghdl_main){ + fprintf(stderr, "%s\n", dlerror()); + exit(2); + } + + printf("ghdl_main return: %d\n", ghdl_main(argc, argv)); + + dlclose(h); + + return 0; + +} diff --git a/testsuite/gna/issue803/main-win.c b/testsuite/gna/issue803/main-win.c new file mode 100644 index 000000000..0cb560b3d --- /dev/null +++ b/testsuite/gna/issue803/main-win.c @@ -0,0 +1,27 @@ +#include +#include +#include + +int main(int argc, char** argv) { + + void* h = LoadLibraryA(".\\tb.dll"); + if (!h){ + fprintf(stderr, "error: cannot load library\n"); + exit(1); + } + + typedef int main_t(int, char**); + + main_t* ghdl_main = (main_t*)GetProcAddress(h, "_ghdl_main"); + if (!ghdl_main){ + fprintf(stderr, "error: cannot find symbol\n"); + exit(2); + } + + printf("ghdl_main return: %d\n", ghdl_main(argc, argv)); + + FreeLibrary(h); + + return 0; + +} diff --git a/testsuite/gna/issue803/main.c b/testsuite/gna/issue803/main.c new file mode 100644 index 000000000..80feb6019 --- /dev/null +++ b/testsuite/gna/issue803/main.c @@ -0,0 +1,33 @@ +#include +#include +#include + +int main(int argc, char** argv) { + + void* h = dlopen("./tb.so", RTLD_LAZY); + if (!h){ + fprintf(stderr, "%s\n", dlerror()); + exit(1); + } + + typedef int main_t(int, char**); + + h = dlopen("./tb.so", RTLD_LAZY); + if (!h){ + fprintf(stderr, "%s\n", dlerror()); + exit(1); + } + + main_t* ghdl_main = (main_t*)dlsym(h, "ghdl_main"); + if (!ghdl_main){ + fprintf(stderr, "%s\n", dlerror()); + exit(2); + } + + printf("ghdl_main return: %d\n", ghdl_main(argc, argv)); + + dlclose(h); + + return 0; + +} diff --git a/testsuite/gna/issue803/tb.vhdl b/testsuite/gna/issue803/tb.vhdl new file mode 100644 index 000000000..61ee11e42 --- /dev/null +++ b/testsuite/gna/issue803/tb.vhdl @@ -0,0 +1,10 @@ +entity tb is +end entity; + +architecture arch of tb is +begin + process begin + report "Hello!" severity failure; + wait; + end process; +end; diff --git a/testsuite/gna/issue803/testsuite.sh b/testsuite/gna/issue803/testsuite.sh new file mode 100755 index 000000000..018511ed9 --- /dev/null +++ b/testsuite/gna/issue803/testsuite.sh @@ -0,0 +1,34 @@ +#! /bin/sh + +. ../../testenv.sh + + +if $GHDL --version | grep -q "GCC back-end"; then + echo "GCC backend detected" +elif $GHDL --version | grep -q "LLVM back-end"; then + echo "LLVM backend detected" +else + echo "This test requires GCC or LLVM backends" + exit 0 +fi + +if [ "$OS" = "Windows_NT" ]; then + gcc main-win.c -o main + analyze tb.vhdl + $GHDL -e -Wl,-shared -Wl,-Wl,-u,ghdl_main -o tb.dll tb + ./main + rm main.exe tb.dll *.o +elif [ "$(uname -o)" = "Darwin" ]; then + gcc main-mac.c -o main + analyze tb.vhdl + $GHDL -e -Wl,-shared -Wl,-Wl,-u,_ghdl_main -o tb.dylib tb + ./main + rm main tb.dylib *.o +else + echo "This test is disabled on Linux (requires an -fpic libgrt)" + exit 0 +fi + +clean + +echo "Test successful" -- cgit v1.2.3