diff options
author | Tristan Gingold <tgingold@free.fr> | 2021-01-29 20:35:37 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2021-01-29 20:35:37 +0100 |
commit | dd804ce80852aa583308b02330dd93a94d5fc423 (patch) | |
tree | 42a5fc4d533c9ba12b170dc6274a8dd6673586a4 /testsuite/gna/issue1623/pyaux.py | |
parent | 45dc90330d619d6445d178483a36fef7673b51fe (diff) | |
download | ghdl-dd804ce80852aa583308b02330dd93a94d5fc423.tar.gz ghdl-dd804ce80852aa583308b02330dd93a94d5fc423.tar.bz2 ghdl-dd804ce80852aa583308b02330dd93a94d5fc423.zip |
testsuite/gna: file testcase for #1623
Diffstat (limited to 'testsuite/gna/issue1623/pyaux.py')
-rw-r--r-- | testsuite/gna/issue1623/pyaux.py | 42 |
1 files changed, 42 insertions, 0 deletions
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() |