From 5927716c97994ca04761c69e4ee0ea1f23db1057 Mon Sep 17 00:00:00 2001 From: Bruno LATHUILIERE Date: Sat, 27 Apr 2024 00:32:22 +0200 Subject: [PATCH] restructure python binding --- Makefile.am | 66 ++++---- pyTools/verrou_dd_stdout | 12 +- {synchroLib => pyWrapper}/verrouCBinding.c | 16 +- pyWrapper/verrouCBinding.h | 23 +++ pyWrapper/verrouPyBinding.py | 125 +++++++++++++++ synchroLib/trace_verrou_synchro.py | 44 ++---- synchroLib/tstDDPython/Makefile | 12 -- synchroLib/tstDDPython/ddRun.sh | 5 - synchroLib/verrouCBinding.h | 23 --- synchroLib/verrouPyBinding.py | 147 ------------------ synchroLib/verrouSynchroLib.cxx | 4 +- unbufferPrintf.c | 8 +- unitTest/makefile | 2 +- unitTest/verrouDDPython/Makefile | 11 ++ .../verrouDDPython}/Muller.py | 0 unitTest/verrouDDPython/ddRun.sh | 4 + .../verrouDDPython}/extractOrCmp.py | 0 .../verrouDDPython}/genExcludePython.sh | 0 18 files changed, 239 insertions(+), 263 deletions(-) rename {synchroLib => pyWrapper}/verrouCBinding.c (81%) create mode 100644 pyWrapper/verrouCBinding.h create mode 100755 pyWrapper/verrouPyBinding.py delete mode 100644 synchroLib/tstDDPython/Makefile delete mode 100755 synchroLib/tstDDPython/ddRun.sh delete mode 100644 synchroLib/verrouCBinding.h delete mode 100755 synchroLib/verrouPyBinding.py create mode 100644 unitTest/verrouDDPython/Makefile rename {synchroLib/tstDDPython => unitTest/verrouDDPython}/Muller.py (100%) create mode 100755 unitTest/verrouDDPython/ddRun.sh rename {synchroLib/tstDDPython => unitTest/verrouDDPython}/extractOrCmp.py (100%) rename {synchroLib/tstDDPython => unitTest/verrouDDPython}/genExcludePython.sh (100%) diff --git a/Makefile.am b/Makefile.am index 6421842..859f8ec 100644 --- a/Makefile.am +++ b/Makefile.am @@ -12,15 +12,17 @@ pkginclude_HEADERS = verrou.h synchroLib/verrouSynchroLib.h PYTHON_REP=pyTools -bin_SCRIPTS = ${PYTHON_REP}/verrou_dd_line ${PYTHON_REP}/verrou_dd_sym ${PYTHON_REP}/genCovBB ${PYTHON_REP}/verrou_plot_stat ${PYTHON_REP}/paraview_script.py ${PYTHON_REP}/verrou_dd_synchro ${PYTHON_REP}/post_verrou_dd ${PYTHON_REP}/verrou_dd_stdout +bin_SCRIPTS = ${PYTHON_REP}/verrou_dd_line ${PYTHON_REP}/verrou_dd_sym ${PYTHON_REP}/genCovBB ${PYTHON_REP}/verrou_plot_stat ${PYTHON_REP}/paraview_script.py ${PYTHON_REP}/verrou_dd_synchro ${PYTHON_REP}/post_verrou_dd ${PYTHON_REP}/verrou_dd_stdout synchroLib/trace_verrou_synchro.py -pkgpython_PYTHON = ${PYTHON_REP}/DD.py ${PYTHON_REP}/dd_config.py ${PYTHON_REP}/DD_stoch.py ${PYTHON_REP}/DD_exec_stat.py ${PYTHON_REP}/convNumLineTool.py ${PYTHON_REP}/post_config.py ${PYTHON_REP}/gen_config.py ${PYTHON_REP}/rounding_tool.py +pkgpython_PYTHON = ${PYTHON_REP}/DD.py ${PYTHON_REP}/dd_config.py ${PYTHON_REP}/DD_stoch.py ${PYTHON_REP}/DD_exec_stat.py ${PYTHON_REP}/convNumLineTool.py ${PYTHON_REP}/post_config.py ${PYTHON_REP}/gen_config.py ${PYTHON_REP}/rounding_tool.py pyWrapper/verrouPyBinding.py install-exec-local: mkdir -p ${pkgpythondir} touch ${pkgpythondir}/__init__.py install -t ${prefix} -m 644 env.sh install -t ${verrouUnbuffereddir} verrouUnbuffered.so + install -t ${verrouCbindingDir} verrouCBinding.so + noinst_PROGRAMS = verrou-@VGCONF_ARCH_PRI@-@VGCONF_OS@ if VGCONF_HAVE_PLATFORM_SEC @@ -168,27 +170,6 @@ endif - - -#---------------------------------------------------------------------------- -# verrouSynchroLib-.so -#---------------------------------------------------------------------------- - -noinst_PROGRAMS += verrouSynchroLib-@VGCONF_ARCH_PRI@-@VGCONF_OS@.so -if VGCONF_HAVE_PLATFORM_SEC -noinst_PROGRAMS += verrouSynchroLib-@VGCONF_ARCH_SEC@-@VGCONF_OS@.so -endif - -VERROUSYNCHROLIB_SOURCES_COMMON = synchroLib/verrouSynchroLib.cxx - -verrouSynchroLib_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_SOURCES = \ - $(VERROUSYNCHROLIB_SOURCES_COMMON) -verrouSynchroLib_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_CPPFLAGS = \ - $(AM_CPPFLAGS@VGCONF_PLATFORM_PRI_CAPS@) $(AM_CFLAGS_PSO_@VGCONF_PLATFORM_PRI_CAPS@) -verrouSynchroLib_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_LDFLAGS = \ - $(PRELOAD_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@) - - #---------------------------------------------------------------------------- # vgpreload_verrou-.so #---------------------------------------------------------------------------- @@ -214,7 +195,7 @@ vgpreload_verrou_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_LDFLAGS = \ vgpreload_verrou_@VGCONF_ARCH_PRI@_@VGCONF_OS@_so_LDADD = -ldl $(VERROU_LD) #---------------------------------------------------------------------------- -# verrouUnbuffered-.so +# verrouUnbuffered.so #---------------------------------------------------------------------------- verrouUnbuffereddir = $(pkglibdir) noinst_PROGRAMS += verrouUnbuffered.so @@ -224,6 +205,39 @@ VERROUUNBUFFERED_SOURCES_COMMON = unbufferPrintf.c verrouUnbuffered_so_SOURCES = \ $(VERROUUNBUFFERED_SOURCES_COMMON) verrouUnbuffered_so_CPPFLAGS = \ + $(subst -Wstrict-prototypes,,$(AM_CPPFLAGS@VGCONF_PLATFORM_PRI_CAPS@)) $(AM_CFLAGS_PSO_@VGCONF_PLATFORM_PRI_CAPS@) +verrouUnbuffered_so_LDFLAGS = $(PRELOAD_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@) + + +#---------------------------------------------------------------------------- +# verrouCBinding.so +#---------------------------------------------------------------------------- +verrouCbindingDir = $(pkglibdir) +noinst_PROGRAMS += verrouCBinding.so + + +VERROUCBINDING_SOURCES_COMMON = pyWrapper/verrouCBinding.c + +verrouCBinding_so_SOURCES = $(VERROUCBINDING_SOURCES_COMMON) +verrouCBinding_so_CPPFLAGS = \ + $(AM_CPPFLAGS@VGCONF_PLATFORM_PRI_CAPS@) $(AM_CFLAGS_PSO_@VGCONF_PLATFORM_PRI_CAPS@) +verrouCBinding_so_LDFLAGS = $(PRELOAD_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@) + + +#---------------------------------------------------------------------------- +# verrouSynchro.so +#---------------------------------------------------------------------------- +noinst_PROGRAMS += verrouSynchro.so +if VGCONF_HAVE_PLATFORM_SEC +noinst_PROGRAMS += verrouSynchro.so +endif + +PRELOADSYNCHRO1 = $(subst -nodefaultlibs,,$(PRELOAD_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)) +PRELOADSYNCHRO = $(subst -m64,,$(PRELOADSYNCHRO1)) + +VERROUSYNCHRO_SOURCES_COMMON = synchroLib/verrouSynchroLib.cxx +verrouSynchro_so_SOURCES = $(VERROUSYNCHRO_SOURCES_COMMON) +verrouSynchro_so_CPPFLAGS = \ $(AM_CPPFLAGS@VGCONF_PLATFORM_PRI_CAPS@) $(AM_CFLAGS_PSO_@VGCONF_PLATFORM_PRI_CAPS@) -verrouUnbuffered_so_LDFLAGS = \ - $(PRELOAD_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@) +verrouSynchro_so_LDFLAGS = -static-libstdc++ \ + $(PRELOADSYNCHRO) diff --git a/pyTools/verrou_dd_stdout b/pyTools/verrou_dd_stdout index ef17dc9..a059bf3 100755 --- a/pyTools/verrou_dd_stdout +++ b/pyTools/verrou_dd_stdout @@ -131,11 +131,12 @@ class DDstdout(DD_stoch.DDStoch): refFile.write("begin:\n") refFile.close() res= {"PYTHONUNBUFFERED": "x", - "VERROU_ROUNDING_MODE": self.config_.referenceRounding, - "VERROU_MCA_MODE": "ieee", - "VERROU_EXPECT_CLR":refPath, - "VERROU_OUTPUT_EXPECT_REP":self.ref_ - } + "LD_PRELOAD": "verrouUnbuffered.so:"+os.environ["LD_PRELOAD"], + "VERROU_ROUNDING_MODE": self.config_.referenceRounding, + "VERROU_MCA_MODE": "ieee", + "VERROU_EXPECT_CLR":refPath, + "VERROU_OUTPUT_EXPECT_REP":self.ref_ + } filePattern=self.config_.get_file_pattern() if filePattern!=None: res["VERROU_EXPECT_FILE_PATTERN"]=filePattern @@ -209,6 +210,7 @@ class DDstdout(DD_stoch.DDStoch): def sampleRunEnv(self,dirName): res={"PYTHONUNBUFFERED": "x", + "LD_PRELOAD": "verrouUnbuffered.so:"+os.environ["LD_PRELOAD"], "VERROU_EXPECT_CLR": os.path.join(dirName, "vr_expect.txt"), "VERROU_OUTPUT_EXPECT_REP":os.path.join(dirName,"%DDRUN%"), "VERROU_LIBM_NOINST_ROUNDING_MODE":self.config_.referenceRounding, diff --git a/synchroLib/verrouCBinding.c b/pyWrapper/verrouCBinding.c similarity index 81% rename from synchroLib/verrouCBinding.c rename to pyWrapper/verrouCBinding.c index 857e35b..eeb0c9c 100644 --- a/synchroLib/verrouCBinding.c +++ b/pyWrapper/verrouCBinding.c @@ -29,19 +29,19 @@ #include -void c_verrou_start_instrumentation(){ +void c_verrou_start_instrumentation(void){ VERROU_START_INSTRUMENTATION; } -void c_verrou_stop_instrumentation(){ +void c_verrou_stop_instrumentation(void){ VERROU_STOP_INSTRUMENTATION; } -void c_verrou_start_soft_instrumentation(){ +void c_verrou_start_soft_instrumentation(void){ VERROU_START_SOFT_INSTRUMENTATION; } -void c_verrou_stop_soft_instrumentation(){ +void c_verrou_stop_soft_instrumentation(void){ VERROU_STOP_SOFT_INSTRUMENTATION; } @@ -55,21 +55,21 @@ void c_verrou_stop_determinitic(int level){ } -void c_verrou_display_counters(){ +void c_verrou_display_counters(void){ VERROU_DISPLAY_COUNTERS; } -unsigned int c_verrou_dump_cover(){ +unsigned int c_verrou_dump_cover(void){ return VERROU_DUMP_COVER; } -unsigned int c_verrou_count_fp_instrumented(){ +unsigned int c_verrou_count_fp_instrumented(void){ unsigned int res=VERROU_COUNT_FP_INSTRUMENTED; return res; } -unsigned int c_verrou_count_fp_not_instrumented(){ +unsigned int c_verrou_count_fp_not_instrumented(void){ unsigned int res=VERROU_COUNT_FP_NOT_INSTRUMENTED; return res; } diff --git a/pyWrapper/verrouCBinding.h b/pyWrapper/verrouCBinding.h new file mode 100644 index 0000000..454c003 --- /dev/null +++ b/pyWrapper/verrouCBinding.h @@ -0,0 +1,23 @@ +#pragma once + +//C functions to call verrou client request + +// start/stop instrumentation +void c_verrou_start_instrumentation(void); +void c_verrou_stop_instrumentation(void); + +void c_verrou_start_soft_instrumentation(void); +void c_verrou_stop_soft_instrumentation(void); + +// define derteministic section +void c_verrou_start_determinitic(int level); +void c_verrou_stop_determinitic(int level); + +//dump cover +unsigned int c_verrou_dump_cover(void); + + +//counters +void c_verrou_display_counters(void); +unsigned int c_verrou_count_fp_instrumented(void); +unsigned int c_verrou_count_fp_not_instrumented(void); diff --git a/pyWrapper/verrouPyBinding.py b/pyWrapper/verrouPyBinding.py new file mode 100755 index 0000000..6aee189 --- /dev/null +++ b/pyWrapper/verrouPyBinding.py @@ -0,0 +1,125 @@ +#!/usr/bin/python3 +import sys, platform +import ctypes, ctypes.util +import os +import os.path + + +def searchDefaultPath(fileName): + dirName=os.path.dirname(os.path.abspath(__file__)) + pathPrefixTab=["./", dirName, os.path.join(dirName, "..", "lib"), + os.path.join(dirName, "..", "..","..","valgrind"), + os.path.join(dirName, "..", "..","..","..","libexec","valgrind"), + "../" + ] + + print(pathPrefixTab, file=sys.stderr) + for pathPrefix in pathPrefixTab: + absPath=os.path.join(pathPrefix, fileName) + if os.path.exists(absPath): +# print("absPath: ", absPath,file=sys.stderr) + return absPath + print("FileName %s not found"%(fileName),file=sys.stderr) + sys.exit(42) + +class bindingSynchroLib: + def __init__(self, pathLib=None): + if(pathLib!=None): + self.lib=ctypes.CDLL(pathLib) + else: + self.lib=ctypes.CDLL(searchDefaultPath("verrouSynchro.so"), ctypes.RTLD_GLOBAL ) + self.lib.verrou_synchro.argtypes = [ ctypes.c_char_p, ctypes.c_int] + self.lib.verrou_synchro_init() + def __del__(self): + self.lib.verrou_synchro_finalyze() + +bindSynchro=bindingSynchroLib() + +def synchro(string, index): + bindSynchro.lib.verrou_synchro(string.encode('utf-8'), index) + +class bindingVerrouCLib: + def __init__(self, pathLib=None): + if(pathLib!=None): + self.lib=ctypes.CDLL(pathLib) + else: + self.lib=ctypes.CDLL(searchDefaultPath("verrouCBinding.so") ) + + self.lib.c_verrou_start_instrumentation.argtypes = [] + self.lib.c_verrou_stop_instrumentation.argtypes = [] + self.lib.c_verrou_start_soft_instrumentation.argtypes = [] + self.lib.c_verrou_stop_soft_instrumentation.argtypes = [] + self.lib.c_verrou_start_determinitic.argtypes = [ctypes.c_int] + self.lib.c_verrou_stop_determinitic.argtypes = [ctypes.c_int] + + self.lib.c_verrou_display_counters.argtypes = [] + + self.lib.c_verrou_dump_cover.argtypes= [] + self.lib.c_verrou_dump_cover.restype= ctypes.c_uint + + self.lib.c_verrou_count_fp_instrumented.argtypes= [] + self.lib.c_verrou_count_fp_not_instrumented.argtypes= [] + self.lib.c_verrou_count_fp_instrumented.restype= ctypes.c_uint + self.lib.c_verrou_count_fp_not_instrumented.restype= ctypes.c_uint + + +bindVerrou=bindingVerrouCLib() + +def start_instrumentation(): + bindVerrou.lib.c_verrou_start_instrumentation() + +def stop_instrumentation(): + bindVerrou.lib.c_verrou_stop_instrumentation() + +def start_soft_instrumentation(): + bindVerrou.lib.c_verrou_start_soft_instrumentation() + +def stop_soft_instrumentation(): + bindVerrou.lib.c_verrou_stop_soft_instrumentation() + +def start_determinitic (level): + bindVerrou.lib.c_verrou_start_determinitic(level) + +def stop_determinitic (level): + bindVerrou.lib.c_verrou_stop_determinitic(level) + +def dump_cover(): + return bindVerrou.lib.c_verrou_dump_cover(); + +def display_counters(): + bindVerrou.lib.c_verrou_display_counters() + +def count_fp_instrumented(): + return bindVerrou.lib.c_verrou_count_fp_instrumented() + +def count_fp_not_instrumented(): + return bindVerrou.lib.c_verrou_count_fp_not_instrumented() + + + +if __name__=="__main__": + + print("avt a binding fp: ", count_fp_instrumented()) + print("avt a binding not fp: ", count_fp_not_instrumented()) + a=3.*4. + print(a) + print("apres a binding fp: ", count_fp_instrumented()) + print("apres a binding not fp: ", count_fp_not_instrumented()) + + + synchro("toto",10) + + display_counters() + start_instrumentation() + a=3.*4 + stop_instrumentation() + + synchro("toto",10) + start_instrumentation() + + a*=5 + stop_instrumentation() + + print(a) + synchro("toto",10) + diff --git a/synchroLib/trace_verrou_synchro.py b/synchroLib/trace_verrou_synchro.py index 80f9c68..1e41977 100755 --- a/synchroLib/trace_verrou_synchro.py +++ b/synchroLib/trace_verrou_synchro.py @@ -1,4 +1,4 @@ -#! /usr/bin/python3.5 +#! /usr/bin/python3 # portions copyright 2001, Autonomous Zones Industries, Inc., all rights... # err... reserved and offered to the public under the terms of the @@ -60,8 +60,7 @@ import pickle from warnings import warn as _warn from time import monotonic as _time -from verrouPyBinding import bindingSynchroLib - +import valgrind.verrouPyBinding as verrou try: import threading except ImportError: @@ -214,24 +213,6 @@ def _fullmodname(path): return filename.lstrip(".") -class synchro_lib: - def __init__(self): - print("Debug trace_verrou_init") - print("os.environ: ", os.environ) -# self.lib=bindingSynchroLib("./verrouSynchroLib.so") - self.lib=bindingSynchroLib() - self.lib.verrou_synchro_init() - - def finalyze(self): - print("Debug trace_verrou_finalize") - self.lib.verrou_synchro_finalyze() - - - def synchro(self,bname,lineno): - print("Debug trace_verrou_synchro %s %i"%(bname,lineno)) - self.lib.verrou_synchro(bname,lineno) - - class CoverageResults: def __init__(self, counts=None, calledfuncs=None, infile=None, @@ -496,7 +477,7 @@ def __init__(self, count=1, trace=1, countfuncs=0, countcallers=0, self._callers = {} self._caller_cache = {} self.start_time = None - self.synchroLib= synchro_lib() +# self.synchroLib= synchro_lib() if timing: self.start_time = _time() if countcallers: @@ -530,12 +511,11 @@ def runctx(self, cmd, globals=None, locals=None): if not self.donothing: _settrace(self.globaltrace) try: - self.synchroLib.synchro("runctx",0) + verrou.synchro("runctx",0) exec(cmd, globals, locals) finally: if not self.donothing: _unsettrace() - self.synchroLib.finalyze() def runfunc(self, func, *args, **kw): result = None @@ -616,7 +596,7 @@ def globaltrace_lt(self, frame, why, arg): else returns self.localtrace. """ if why == 'call': - self.synchroLib.synchro("globaltrace_lt",0) + verrou.synchro("globaltrace_lt",0) code = frame.f_code filename = frame.f_globals.get('__file__', None) if filename: @@ -646,7 +626,7 @@ def localtrace_trace_and_count(self, frame, why, arg): bname = os.path.basename(filename) print("%s(%d): %s" % (bname, lineno, linecache.getline(filename, lineno)), end='') - self.synchroLib.synchro(bname,lineno) + verrou.synchro(bname,lineno) return self.localtrace def localtrace_trace(self, frame, why, arg): @@ -660,7 +640,7 @@ def localtrace_trace(self, frame, why, arg): bname = os.path.basename(filename) print("%s(%d): %s" % (bname, lineno, linecache.getline(filename, lineno)), end='') - self.synchroLib.synchro(bname,lineno) + verrou.synchro(bname,lineno) return self.localtrace def localtrace_count(self, frame, why, arg): @@ -669,14 +649,14 @@ def localtrace_count(self, frame, why, arg): lineno = frame.f_lineno key = filename, lineno self.counts[key] = self.counts.get(key, 0) + 1 - self.synchroLib.synchro(filename,lineno) + verrou.synchro(filename,lineno) return self.localtrace def localtrace_verrou(self, frame, why, arg): if why == "line": filename = frame.f_code.co_filename lineno = frame.f_lineno - self.synchroLib.synchro(filename,lineno) + verrou.synchro(filename,lineno) return self.localtrace def results(self): @@ -713,7 +693,7 @@ def main(argv=None): count = 0 report = 0 no_report = 0 - verrou = 1 + verrou_mode = 1 counts_file = None missing = 0 ignore_modules = [] @@ -802,7 +782,7 @@ def main(argv=None): if listfuncs and (count or trace): _err_exit("cannot specify both --listfuncs and (--trace or --count)") - if not (count or trace or report or listfuncs or countcallers or verrou): + if not (count or trace or report or listfuncs or countcallers or verrou_mode): _err_exit("must specify one of --trace, --count, --report, " "--listfuncs, or --trackcalls") @@ -830,7 +810,7 @@ def main(argv=None): ignoredirs=ignore_dirs, infile=counts_file, outfile=counts_file, timing=timing) try: - t.synchroLib.synchro("compile",0) + verrou.synchro("compile",0) with open(progname) as fp: code = compile(fp.read(), progname, 'exec') # try to emulate __main__ namespace as much as possible diff --git a/synchroLib/tstDDPython/Makefile b/synchroLib/tstDDPython/Makefile deleted file mode 100644 index 4ba7eb8..0000000 --- a/synchroLib/tstDDPython/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -PYTHON=/usr/bin/python3 -all: dd.synchro - -exclude.ex: - ./genExcludePython.sh $(PYTHON) exclude.ex - - -dd.synchro: clean exclude.ex - verrou_dd_synchro ddRun.sh extractOrCmp.py - -clean: - rm -rf exclude.ex dd.synchro diff --git a/synchroLib/tstDDPython/ddRun.sh b/synchroLib/tstDDPython/ddRun.sh deleted file mode 100755 index f45092c..0000000 --- a/synchroLib/tstDDPython/ddRun.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -DIR=$1 - -valgrind --demangle=no --tool=verrou --exclude=exclude.ex --rounding-mode=random /usr/bin/python3 ../trace_verrou_synchro.py ./Muller.py > $DIR/res.dat - diff --git a/synchroLib/verrouCBinding.h b/synchroLib/verrouCBinding.h deleted file mode 100644 index 678b723..0000000 --- a/synchroLib/verrouCBinding.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -//C functions to call verrou client request - -// start/stop instrumentation -void c_verrou_start_instrumentation(); -void c_verrou_stop_instrumentation(); - -void c_verrou_start_soft_instrumentation(); -void c_verrou_stop_soft_instrumentation(); - -// define derteministic section -void c_verrou_start_determinitic(int level); -void c_verrou_stop_determinitic(int level); - -//dump cover -unsigned int c_verrou_dump_cover(); - - -//counters -void c_verrou_display_counters(); -unsigned int c_verrou_count_fp_instrumented(); -unsigned int c_verrou_count_fp_not_instrumented(); diff --git a/synchroLib/verrouPyBinding.py b/synchroLib/verrouPyBinding.py deleted file mode 100755 index eed571b..0000000 --- a/synchroLib/verrouPyBinding.py +++ /dev/null @@ -1,147 +0,0 @@ -#!/usr/bin/python3 -import sys, platform -import ctypes, ctypes.util - - -import os -import os.path - - - - -class bindingSynchroLib: - - def __init__(self, pathLib=None): - if(pathLib!=None): - self.lib=ctypes.CDLL(pathLib) - else: - self.lib=ctypes.CDLL(searchDefaultPath("verrouSynchroLib.so") ) - self.lib.verrou_synchro.argtypes = [ ctypes.c_char_p, ctypes.c_int] - - def verrou_synchro_init(self): - print("bindingSynchroLib : verrou_synchro_init") - self.lib.verrou_synchro_init() - - def verrou_synchro_finalyze(self): - print("bindingSynchroLib : verrou_synchro_finalyze") - self.lib.verrou_synchro_finalyze() - - def verrou_synchro(self,string, index): - print("bindingSynchroLib : verrou_synchro", string, index) - self.lib.verrou_synchro(string.encode('utf-8'), index) - -class bindingVerrouCLib: - def __init__(self, pathLib): - if(pathLib!=None): - self.lib=ctypes.CDLL(pathLib) - else: - self.lib=ctypes.CDLL(searchDefaultPath("verrouCBindingLib.so") ) - - self.lib=ctypes.CDLL(pathLib) - self.lib.c_verrou_start_instrumentation.argtypes = [] - self.lib.c_verrou_stop_instrumentation.argtypes = [] - self.lib.c_verrou_start_determinitic.argtypes = [ctypes.c_int] - self.lib.c_verrou_stop_determinitic.argtypes = [ctypes.c_int] - - self.lib.c_verrou_display_counters.argtypes = [] - - self.lib.c_verrou_dump_cover.argtypes= [] - self.lib.c_verrou_dump_cover.restype= ctypes.c_uint - - self.lib.c_verrou_count_fp_instrumented.argtypes= [] - self.lib.c_verrou_count_fp_not_instrumented.argtypes= [] - self.lib.c_verrou_count_fp_instrumented.restype= ctypes.c_uint - self.lib.c_verrou_count_fp_not_instrumented.restype= ctypes.c_uint - - - def verrou_start_instrumentation(self): - self.lib.c_verrou_start_instrumentation() - - def verrou_stop_instrumentation(self): - self.lib.c_verrou_stop_instrumentation() - - def verrou_start_determinitic (self, level): - self.lib.c_verrou_start_determinitic(level) - - def verrou_stop_determinitic (self, level): - self.lib.c_verrou_stop_determinitic(level) - - def verrou_dump_cover(self): - return self.lib.c_verrou_dump_cover(); - - def verrou_display_counters(self): - self.lib.c_verrou_display_counters() - - def verrou_count_fp_instrumented(self): - return self.lib.c_verrou_count_fp_instrumented() - - def verrou_count_fp_not_instrumented(self): - return self.lib.c_verrou_count_fp_not_instrumented() - - -def searchDefaultPath(fileName): - dirName=os.path.dirname(os.path.abspath(__file__)) - pathPrefixTab=["./", dirName, os.path.join(dirName, "..", "lib")] - - print(pathPrefixTab, file=sys.stderr) - for pathPrefix in pathPrefixTab: - absPath=os.path.join(pathPrefix, fileName) - if os.path.exists(absPath): - print("absPath: ", absPath,file=sys.stderr) - return absPath - print("FileName %s not found"%(fileName),file=sys.stderr) - sys.exit(42) - - - - - -if __name__=="__main__": - verrouSynchroLib="./verrouSynchroLib.so" - verrouCBindingLib="./verrouCBindingLib.so" - - bindVerrou=bindingVerrouCLib(verrouCBindingLib) - bindVerrou.verrou_stop_instrumentation() - bindVerrou.verrou_display_counters() - - - -# print("dumpCover : ",bindVerrou.verrou_dump_cover()) -# print("dumpCover : ",bindVerrou.verrou_dump_cover()) -# print("dumpCover : ",bindVerrou.verrou_dump_cover()) - - - - - print("avt a binding fp: ", bindVerrou.verrou_count_fp_instrumented()) - print("avt a binding not fp: ", bindVerrou.verrou_count_fp_not_instrumented()) - a=3.*4. - print(a) - print("apres a binding fp: ", bindVerrou.verrou_count_fp_instrumented()) - print("apres a binding not fp: ", bindVerrou.verrou_count_fp_not_instrumented()) - - - bindSynchro=bindingSynchroLib(verrouSynchroLib) - - - - bindSynchro.verrou_synchro_init() - bindSynchro.verrou_synchro("toto",10) - - bindVerrou.verrou_display_counters() - bindVerrou.verrou_start_instrumentation() - a=3.*4 - bindVerrou.verrou_stop_instrumentation() - - bindSynchro.verrou_synchro("toto",10) - bindVerrou.verrou_start_instrumentation() - - a*=5 - bindVerrou.verrou_stop_instrumentation() - - - print(a) - bindSynchro.verrou_synchro("toto",10) - - bindSynchro.verrou_synchro_finalyze() - diff --git a/synchroLib/verrouSynchroLib.cxx b/synchroLib/verrouSynchroLib.cxx index 1942bc5..4ccf09a 100644 --- a/synchroLib/verrouSynchroLib.cxx +++ b/synchroLib/verrouSynchroLib.cxx @@ -35,8 +35,10 @@ #include +#define outputPrefix "==verrouSynchroLib.so== " + bool synchroDebug=false; -std::string outputPrefix("==verrouSynchroLib.so== "); + bool generateTrace; diff --git a/unbufferPrintf.c b/unbufferPrintf.c index 38b3261..646e399 100644 --- a/unbufferPrintf.c +++ b/unbufferPrintf.c @@ -1,8 +1,10 @@ #include -void __attribute__((constructor)) init_unbufferPrintf(){ +void __attribute__((constructor)) init_unbufferPrintf(void); +void __attribute__((constructor)) init_unbufferPrintf(void){ setbuf(stdout,NULL); -} +}; -void __attribute__((destructor)) finalyze_unbufferPrintf(){ +void __attribute__((destructor)) finalyze_unbufferPrintf(void); +void __attribute__((destructor)) finalyze_unbufferPrintf(void){ }; diff --git a/unitTest/makefile b/unitTest/makefile index f7da998..efe261f 100644 --- a/unitTest/makefile +++ b/unitTest/makefile @@ -1,4 +1,4 @@ -SUBREPLIST=checkRounding checkStatRounding checkUCB-vecto check-libM ddTest check-verrou-dd-synchro ddStdOut ddLibm +SUBREPLIST=checkRounding checkStatRounding checkUCB-vecto check-libM ddTest check-verrou-dd-synchro ddStdOut ddLibm verrouDDPython .PHONY: valgrind-test diff --git a/unitTest/verrouDDPython/Makefile b/unitTest/verrouDDPython/Makefile new file mode 100644 index 0000000..596a983 --- /dev/null +++ b/unitTest/verrouDDPython/Makefile @@ -0,0 +1,11 @@ +export INSTALLPATH = $(shell bash ../installpath) +export BASH_ENV=$(INSTALLPATH)/env.sh +export SHELL=bash + +all: dd.synchro + +dd.synchro: clean + verrou_dd_synchro --num-threads=4 --nrun=1 ddRun.sh extractOrCmp.py + +clean: + rm -rf exclude.ex dd.synchro diff --git a/synchroLib/tstDDPython/Muller.py b/unitTest/verrouDDPython/Muller.py similarity index 100% rename from synchroLib/tstDDPython/Muller.py rename to unitTest/verrouDDPython/Muller.py diff --git a/unitTest/verrouDDPython/ddRun.sh b/unitTest/verrouDDPython/ddRun.sh new file mode 100755 index 0000000..0bc8664 --- /dev/null +++ b/unitTest/verrouDDPython/ddRun.sh @@ -0,0 +1,4 @@ +#!/bin/bash +DIR=$1 +valgrind --tool=verrou --rounding-mode=downward trace_verrou_synchro.py ./Muller.py > $DIR/res.dat + diff --git a/synchroLib/tstDDPython/extractOrCmp.py b/unitTest/verrouDDPython/extractOrCmp.py similarity index 100% rename from synchroLib/tstDDPython/extractOrCmp.py rename to unitTest/verrouDDPython/extractOrCmp.py diff --git a/synchroLib/tstDDPython/genExcludePython.sh b/unitTest/verrouDDPython/genExcludePython.sh similarity index 100% rename from synchroLib/tstDDPython/genExcludePython.sh rename to unitTest/verrouDDPython/genExcludePython.sh