Mentions légales du service

Skip to content
Snippets Groups Projects
Commit ce0a7532 authored by Kevin Pouget's avatar Kevin Pouget
Browse files

improve

parent 9acb8b06
Branches
No related tags found
No related merge requests found
__binaries__
...@@ -2,51 +2,69 @@ import pkgutil, importlib, difflib # standard lib packages ...@@ -2,51 +2,69 @@ import pkgutil, importlib, difflib # standard lib packages
import sys, subprocess, shlex, fcntl, os, time, errno # standard lib packages import sys, subprocess, shlex, fcntl, os, time, errno # standard lib packages
import logging; log = logging.getLogger(__name__) import logging; log = logging.getLogger(__name__)
import mcgdb
mcGDB_PATH = mcgdb.__path__[0]
EXPECTED_FILE_PREFIX = "file://" EXPECTED_FILE_PREFIX = "file://"
##############################################3 ##############################################3
def all_subpackages(pkg_prefix, verbose, what_to_run, parent, prefix=""): def all_subpackages(pkg_prefix, verbose, what_to_run, parent, prefix=""):
if not hasattr(parent, "__path__"): if not pkg_prefix.endswith("."): pkg_prefix += "."
print("ERROR: if this is mcgdb: {}, then you certainly have a *module* named 'mcgdb'. Please change it !".format(parent))
to_skip = []
for _, modname, ispkg in pkgutil.walk_packages(parent.__path__, prefix="mcgdb.", onerror=lambda x : None): for _, modname, ispkg in pkgutil.walk_packages(parent.__path__, prefix=pkg_prefix, onerror=lambda x : None):
if pkg_prefix and not modname.startswith(pkg_prefix): if ".testing" not in modname and "_testing" not in modname and not ispkg:
continue continue
if ".testing" not in modname and not ispkg:
continue
mod = importlib.import_module(modname) mod = importlib.import_module(modname)
try:
if os.path.islink(mod.__path__[0] if ispkg else mod.__file__): path = mod.__path__[0] if ispkg else mod.__file__
log.warn("Skipping symbolic link to {}.".format(modname)) 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 ... # might be better to check if it is in the path first ...
continue if ispkg:
except Exception as e: to_skip.append(mod.__path__[0])
import pdb;pdb.set_trace() continue
pass
for what in what_to_run: for what in what_to_run:
if not hasattr(mod, what): continue 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, module=None, benchmark=True, test=True, verbose=False, help=False):
def main(pkg_prefix=None, benchmark=True, test=True, verbose=False):
what_to_run = [] 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 test: what_to_run.append("test")
if benchmark: what_to_run.append("benchmark") 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 GDB_Instance.CSV_mode = True
all_subpackages(pkg_prefix, verbose, ["benchmark"], mcgdb) all_subpackages(pkg_prefix, verbose, ["benchmark"], module)
##############################################3 ##############################################3
class CompilationError(Exception): pass class CompilationError(Exception): pass
...@@ -166,9 +184,9 @@ class GDB_Instance: ...@@ -166,9 +184,9 @@ class GDB_Instance:
self._fout = None self._fout = None
self._fcmd = None self._fcmd = None
def start(self, source, no_mcgdb=False): def start(self, source, init_hook=None):
self.src = source self.src = source
self.no_mcgdb = no_mcgdb self.init_hook = init_hook
source.package = self.package source.package = self.package
source.compile() source.compile()
...@@ -192,9 +210,8 @@ class GDB_Instance: ...@@ -192,9 +210,8 @@ class GDB_Instance:
self.execute("set confirm off") self.execute("set confirm off")
if not no_mcgdb: if init_hook:
self.execute("python sys.path.append('{}/..')".format(mcGDB_PATH)) init_hook(self)
self.execute("python import mcgdb; mcgdb.initialize()")
self.execute("file {}".format(source.binary)) self.execute("file {}".format(source.binary))
...@@ -335,7 +352,7 @@ class GDB_Instance: ...@@ -335,7 +352,7 @@ class GDB_Instance:
if hard: if hard:
self.quit() self.quit()
self.start(self.src, self.no_mcgdb) self.start(self.src, self.init_hook)
def sync_outputs(self): def sync_outputs(self):
......
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)
from gdb_tester import * from gdb_tester import *
import mcgdb
gdb = None gdb = None
...@@ -67,7 +68,7 @@ def benchmark(_gdb, what=None, no_mcgdb=True): ...@@ -67,7 +68,7 @@ def benchmark(_gdb, what=None, no_mcgdb=True):
what = [nominal_time, gdb_breakpoint, gdb_watchpoint] + \ what = [nominal_time, gdb_breakpoint, gdb_watchpoint] + \
list(map(lambda x: gdb_py_breakpoint_parameter(x), (0b0, 0b1, 0b10, 0b11))) 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: for prepare_and_run in what:
prepare_and_run() prepare_and_run()
gdb.reset(hard=(not no_mcgdb)) gdb.reset(hard=(not no_mcgdb))
......
LD_PRELOAD = "/home/kevin/travail/Python/mcgdb/openmp/capture/preload/__binaries__/libmcgdb_omp.preload.so"
from . import sequence, stepping from . import sequence, stepping
from gdb_tester import * from gdb_tester import *
from . import LD_PRELOAD import mcgdb
gdb = None gdb = None
def prepare_and_run(what): def prepare_and_run(what):
gdb.set_title(what.replace("do_", "").replace("_", " ")) 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("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("set what_to_do = {}".format(what))
gdb.execute("break finish_data_ready") gdb.execute("break finish_data_ready")
gdb.execute("continue") gdb.execute("continue")
...@@ -28,7 +34,7 @@ def benchmark(_gdb): ...@@ -28,7 +34,7 @@ def benchmark(_gdb):
global gdb global gdb
gdb = _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: for what in WHAT_TO_RUN:
gdb.reset(hard=True) gdb.reset(hard=True)
prepare_and_run(what) prepare_and_run(what)
......
from gdb_tester import * from gdb_tester import *
from . import LD_PRELOAD import mcgdb
gdb = None gdb = None
def prepare_and_run(what): def prepare_and_run(what):
gdb.set_title(what.replace("do_", "")) 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 what_to_do = {}".format(what))
gdb.execute("set repeat = 0") gdb.execute("set repeat = 0")
...@@ -27,7 +27,7 @@ def benchmark(_gdb): ...@@ -27,7 +27,7 @@ def benchmark(_gdb):
from . import benchmark 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: for what in benchmark.WHAT_TO_RUN:
gdb.reset(hard=True) gdb.reset(hard=True)
prepare_and_run(what) prepare_and_run(what)
......
from gdb_tester import * from gdb_tester import *
from . import LD_PRELOAD
gdb = None gdb = None
def prepare_and_run(what): def prepare_and_run(what):
gdb.set_title(what.replace("do_", "")) gdb.set_title(what.replace("do_", ""))
gdb.execute('set env LD_PRELOAD={}'.format(LD_PRELOAD))
gdb.execute("start") gdb.execute("start")
......
...@@ -5,10 +5,11 @@ expected_print = expected_file("opm_seq_print.expected") ...@@ -5,10 +5,11 @@ expected_print = expected_file("opm_seq_print.expected")
expected_print_all = expected_file("opm_seq_print_all.expected") expected_print_all = expected_file("opm_seq_print_all.expected")
def test(gdb): def test(gdb):
print("Running :)")
gdb.start(CSource("parallel-demo.c")) 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", expected_print, may_fail=True)
gdb.execute("opm sequence --print --all", expected_print_all, may_fail=True) gdb.execute("opm sequence --print --all", expected_print_all, may_fail=True)
......
from gdb_tester import * from gdb_tester import *
from . import LD_PRELOAD import mcgdb
def test(gdb): def test(gdb):
gdb.start(CSource("parallel-demo.c")) gdb.start(CSource("parallel-demo.c"), init_hook=mcgdb.testing.gdb__init_mcgdb)
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("opm start", "OpenMP parallel zone started")
gdb.execute("opm step", "in single zone") gdb.execute("omp start", "OpenMP parallel zone started")
gdb.execute("opm all_out", "Out of the single zone") gdb.execute("omp step", "in single zone")
gdb.execute("opm step", "in critical zone") gdb.execute("omp all_out", "Out of the single zone")
gdb.execute("opm critical next", "in critical zone") gdb.execute("omp step", "in critical zone")
gdb.execute("opm critical next", "in critical zone") gdb.execute("omp critical next", "in critical zone")
gdb.execute("opm step out", "outside Critical zone") gdb.execute("omp critical next", "in critical zone")
gdb.execute("omp step out", "outside Critical zone")
gdb.quit() gdb.quit()
cp ../mcgdb/testing/* mcgdb_testing/ -r
cp ../mcgdb/model/task/environment/openmp/testing/* openmp_testing/ -r
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment