diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..f4ee720fffccaa60eb2fb0f438ddccdd2deaba04 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__binaries__ diff --git a/__init__.py b/__init__.py index 83345fbc33b8c5ebffbdd4f9301558b5462b8fd7..f31efd03eaf0badea4c73f09d4320beda3a15da6 100644 --- a/__init__.py +++ b/__init__.py @@ -2,51 +2,69 @@ import pkgutil, importlib, difflib # standard lib packages import sys, subprocess, shlex, fcntl, os, time, errno # standard lib packages import logging; log = logging.getLogger(__name__) -import mcgdb - -mcGDB_PATH = mcgdb.__path__[0] - EXPECTED_FILE_PREFIX = "file://" ##############################################3 def all_subpackages(pkg_prefix, verbose, what_to_run, parent, prefix=""): - if not hasattr(parent, "__path__"): - print("ERROR: if this is mcgdb: {}, then you certainly have a *module* named 'mcgdb'. Please change it !".format(parent)) - - for _, modname, ispkg in pkgutil.walk_packages(parent.__path__, prefix="mcgdb.", onerror=lambda x : None): - if pkg_prefix and not modname.startswith(pkg_prefix): + if not pkg_prefix.endswith("."): pkg_prefix += "." + + to_skip = [] + for _, modname, ispkg in pkgutil.walk_packages(parent.__path__, prefix=pkg_prefix, onerror=lambda x : None): + if ".testing" not in modname and "_testing" not in modname and not ispkg: continue - if ".testing" not in modname and not ispkg: - continue - mod = importlib.import_module(modname) - try: - if os.path.islink(mod.__path__[0] if ispkg else mod.__file__): - log.warn("Skipping symbolic link to {}.".format(modname)) + + path = mod.__path__[0] if ispkg else mod.__file__ + do_skip = False + for skip in to_skip: + if path.startswith(skip): + do_skip = True + break + if do_skip: + continue + + if os.path.islink(path): + log.info("Skipping symbolic link to {}".format(mod.__path__[0])) # might be better to check if it is in the path first ... - continue - except Exception as e: - import pdb;pdb.set_trace() - pass + if ispkg: + to_skip.append(mod.__path__[0]) + continue + for what in what_to_run: if not hasattr(mod, what): continue + try: + run_module(verbose, modname, mod, getattr(mod, what)) + except Exception as e: + log.warn("{} failed {}".format(modname, e)) - run_module(verbose, modname, mod, getattr(mod, what)) - -def main(pkg_prefix=None, benchmark=True, test=True, verbose=False): +def main(pkg_prefix, module=None, benchmark=True, test=True, verbose=False, help=False): what_to_run = [] + if help: + print(""" Options: + pkg_prefix: run only tests/benchmarks inside this package (mandatory) + + benchmark: If false, do not run benchmark + tests: If false, do not run tests + verbose: If true, print some more details + help: Prints this help. +""") + return + + if module is None: + module = importlib.import_module(pkg_prefix) + if test: what_to_run.append("test") if benchmark: what_to_run.append("benchmark") - all_subpackages(pkg_prefix, verbose, what_to_run, mcgdb) + all_subpackages(pkg_prefix, verbose, what_to_run, module) -def run_benchmark(pkg_prefix=None, verbose=False): +def run_benchmark(pkg_prefix, module=None, verbose=False): GDB_Instance.CSV_mode = True - - all_subpackages(pkg_prefix, verbose, ["benchmark"], mcgdb) + + all_subpackages(pkg_prefix, verbose, ["benchmark"], module) ##############################################3 class CompilationError(Exception): pass @@ -166,9 +184,9 @@ class GDB_Instance: self._fout = None self._fcmd = None - def start(self, source, no_mcgdb=False): + def start(self, source, init_hook=None): self.src = source - self.no_mcgdb = no_mcgdb + self.init_hook = init_hook source.package = self.package source.compile() @@ -192,9 +210,8 @@ class GDB_Instance: self.execute("set confirm off") - if not no_mcgdb: - self.execute("python sys.path.append('{}/..')".format(mcGDB_PATH)) - self.execute("python import mcgdb; mcgdb.initialize()") + if init_hook: + init_hook(self) self.execute("file {}".format(source.binary)) @@ -335,7 +352,7 @@ class GDB_Instance: if hard: self.quit() - self.start(self.src, self.no_mcgdb) + self.start(self.src, self.init_hook) def sync_outputs(self): diff --git a/mcgdb_testing/__init__.py b/mcgdb_testing/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..82f3352cfce82c5ab4599347f42af257d2bb1493 --- /dev/null +++ b/mcgdb_testing/__init__.py @@ -0,0 +1,36 @@ +import importlib + +def gdb__init_mcgdb(gdb): + import mcgdb + mcGDB_PATH = mcgdb.__path__[0] + + gdb.execute("python sys.path.append('{}/..')".format(mcGDB_PATH)) + gdb.execute("python import mcgdb; mcgdb.initialize()") + +def run_tests(*args, **kwargs): + import gdb_tester + import mcgdb + + if "pkg_prefix" not in kwargs: + kwargs["pkg_prefix"] = "mcgdb" + else: + kwargs["module"] = importlib.import_module(kwargs["pkg_prefix"]) + + if "module" not in kwargs: + kwargs["module"] = mcgdb + + gdb_tester.main(*args, **kwargs) + +def run_benchmark(*args, **kwargs): + import gdb_tester + import mcgdb + + if "pkg_prefix" not in kwargs: + kwargs["pkg_prefix"] = "mcgdb" + else: + kwargs["module"] = importlib.import_module(kwargs["pkg_prefix"]) + + if "module" not in kwargs: + kwargs["module"] = mcgdb + + gdb_tester.run_benchmark(*args, **kwargs) diff --git a/mcgdb_testing/native_gdb.py b/mcgdb_testing/native_gdb.py index 56c5e9765f0974b264c1e924b302c9446d20a099..b6cb324d2be0f8b72676ed0cf13ab95e0087076a 100644 --- a/mcgdb_testing/native_gdb.py +++ b/mcgdb_testing/native_gdb.py @@ -1,4 +1,5 @@ from gdb_tester import * +import mcgdb gdb = None @@ -67,7 +68,7 @@ def benchmark(_gdb, what=None, no_mcgdb=True): what = [nominal_time, gdb_breakpoint, gdb_watchpoint] + \ list(map(lambda x: gdb_py_breakpoint_parameter(x), (0b0, 0b1, 0b10, 0b11))) - gdb.start(CSource("benchmark.c"), no_mcgdb) + gdb.start(CSource("benchmark.c"), None if no_mcgdb else mcgdb.testing.gdb__init_mcgdb) for prepare_and_run in what: prepare_and_run() gdb.reset(hard=(not no_mcgdb)) diff --git a/openmp_testing/__init__.py b/openmp_testing/__init__.py index 718e328169ed215d7c0eee75545a82c348dce28c..f4170b25cf3ae5a9a63cba92e160b7f0b97cb298 100644 --- a/openmp_testing/__init__.py +++ b/openmp_testing/__init__.py @@ -1,4 +1,2 @@ -LD_PRELOAD = "/home/kevin/travail/Python/mcgdb/openmp/capture/preload/__binaries__/libmcgdb_omp.preload.so" - from . import sequence, stepping diff --git a/openmp_testing/benchmark.py b/openmp_testing/benchmark.py index 730e069a05288b3214b659914fda263d476caf8f..f04d8efc2f8a56f2fcb0f7474f18b6627ac62dce 100644 --- a/openmp_testing/benchmark.py +++ b/openmp_testing/benchmark.py @@ -1,13 +1,19 @@ from gdb_tester import * -from . import LD_PRELOAD +import mcgdb + gdb = None def prepare_and_run(what): gdb.set_title(what.replace("do_", "").replace("_", " ")) - gdb.execute('set env LD_PRELOAD={}'.format(LD_PRELOAD)) + gdb.execute("set env OMP_NUM_THREADS=2") - gdb.execute_many(["autodetect_models", "start"]) + + gdb.execute("py import mcgdb; mcgdb.load_by_name('mcgdb-omp')") + gdb.execute_many(["start"]) + + gdb.execute("set var it_count=10") + gdb.execute("set what_to_do = {}".format(what)) gdb.execute("break finish_data_ready") gdb.execute("continue") @@ -28,7 +34,7 @@ def benchmark(_gdb): global gdb gdb = _gdb - gdb.start(CSource("benchmark.c")) + gdb.start(CSource("benchmark.c"), init_hook=mcgdb.testing.gdb__init_mcgdb) for what in WHAT_TO_RUN: gdb.reset(hard=True) prepare_and_run(what) diff --git a/openmp_testing/count.py b/openmp_testing/count.py index 8c23810b0bfa7bd9b8f124df9adbe1aa2776cad8..07329a73c7bd2d51288bdebca2cd58f8b5c1cea1 100644 --- a/openmp_testing/count.py +++ b/openmp_testing/count.py @@ -1,14 +1,14 @@ from gdb_tester import * -from . import LD_PRELOAD +import mcgdb gdb = None def prepare_and_run(what): gdb.set_title(what.replace("do_", "")) - gdb.execute('set env LD_PRELOAD={}'.format(LD_PRELOAD)) + gdb.execute("py import mcgdb; mcgdb.load_by_name('mcgdb-omp')") - gdb.execute_many(["autodetect_models", "start"]) + gdb.execute_many(["start"]) gdb.execute("set what_to_do = {}".format(what)) gdb.execute("set repeat = 0") @@ -27,7 +27,7 @@ def benchmark(_gdb): from . import benchmark - gdb.start(CSource("benchmark.c")) + gdb.start(CSource("benchmark.c"), init_hook=mcgdb.testing.gdb__init_mcgdb) for what in benchmark.WHAT_TO_RUN: gdb.reset(hard=True) prepare_and_run(what) diff --git a/openmp_testing/no_instrumentation.py b/openmp_testing/no_instrumentation.py index 720821f56ca70f3a6de6e8f75b715fd46f2397a2..e3a09190fe52289c20bf00ca954a84d57ef88440 100644 --- a/openmp_testing/no_instrumentation.py +++ b/openmp_testing/no_instrumentation.py @@ -1,10 +1,9 @@ from gdb_tester import * -from . import LD_PRELOAD + gdb = None def prepare_and_run(what): gdb.set_title(what.replace("do_", "")) - gdb.execute('set env LD_PRELOAD={}'.format(LD_PRELOAD)) gdb.execute("start") diff --git a/openmp_testing/sequence.py b/openmp_testing/sequence.py index 7317efd41d71d5c2788719343a3e933c0dc60c1d..b9bf51caab671a7cf8f9f8294ef70b89a1ddbee7 100644 --- a/openmp_testing/sequence.py +++ b/openmp_testing/sequence.py @@ -5,10 +5,11 @@ expected_print = expected_file("opm_seq_print.expected") expected_print_all = expected_file("opm_seq_print_all.expected") def test(gdb): - print("Running :)") gdb.start(CSource("parallel-demo.c")) - gdb.execute_many(["autodetect_models", "run"]) + + gdb.execute("py import mcgdb; mcgdb.load_by_name('mcgdb-omp')") + gdb.execute_many(["run"]) gdb.execute("opm sequence --print", expected_print, may_fail=True) gdb.execute("opm sequence --print --all", expected_print_all, may_fail=True) diff --git a/openmp_testing/stepping.py b/openmp_testing/stepping.py index 6c4332b7563218d4aaadd5ddde088167db9dcb30..45cf637a89cb3ed707e8f004fd6bb6e0b11528c5 100644 --- a/openmp_testing/stepping.py +++ b/openmp_testing/stepping.py @@ -1,18 +1,19 @@ from gdb_tester import * -from . import LD_PRELOAD +import mcgdb def test(gdb): - gdb.start(CSource("parallel-demo.c")) - gdb.execute('set env LD_PRELOAD={}'.format(LD_PRELOAD)) - - gdb.execute_many(["autodetect_models", "start"]) - gdb.execute("opm start", "OpenMP parallel zone started") - gdb.execute("opm step", "in single zone") - gdb.execute("opm all_out", "Out of the single zone") - gdb.execute("opm step", "in critical zone") - gdb.execute("opm critical next", "in critical zone") - gdb.execute("opm critical next", "in critical zone") - gdb.execute("opm step out", "outside Critical zone") + gdb.start(CSource("parallel-demo.c"), init_hook=mcgdb.testing.gdb__init_mcgdb) + + gdb.execute("py import mcgdb; mcgdb.load_by_name('mcgdb-omp')") + gdb.execute_many(["start"]) + + gdb.execute("omp start", "OpenMP parallel zone started") + gdb.execute("omp step", "in single zone") + gdb.execute("omp all_out", "Out of the single zone") + gdb.execute("omp step", "in critical zone") + gdb.execute("omp critical next", "in critical zone") + gdb.execute("omp critical next", "in critical zone") + gdb.execute("omp step out", "outside Critical zone") gdb.quit() diff --git a/to_import_from_mcgdb b/to_import_from_mcgdb new file mode 100644 index 0000000000000000000000000000000000000000..ebb14eb2b628e74fca2a825ec255bb67d8ad37e5 --- /dev/null +++ b/to_import_from_mcgdb @@ -0,0 +1,2 @@ +cp ../mcgdb/testing/* mcgdb_testing/ -r +cp ../mcgdb/model/task/environment/openmp/testing/* openmp_testing/ -r