From 2c30861882c955ffccd9846347bb44f992a734e6 Mon Sep 17 00:00:00 2001 From: Aryaz Eghbali Date: Mon, 10 Oct 2022 11:53:32 +0200 Subject: [PATCH] Fixed issue #3: only calling site sensitive calls --- Dockerfile | 22 +++++----------------- experiment.sh | 4 ++++ filter_tests.py | 4 ++-- src/dynapyt/instrument/CodeInstrumenter.py | 3 ++- src/dynapyt/runtime.py | 5 +++-- 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index e758344..a2fd328 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,11 @@ FROM python:3.9 -RUN groupadd --gid 5000 eghbalaz \ -&& useradd --home-dir /home/eghbalaz --create-home --uid 5000 \ ---gid 5000 --shell /bin/sh --skel /dev/null eghbalaz +ARG repo -USER eghbalaz +WORKDIR /DynaPyt -ENV PATH="/home/eghbalaz/.local/bin:${PATH}" +RUN pip install --upgrade pip setuptools wheel -WORKDIR /home/eghbalaz/app +COPY . . -RUN pip install --user --upgrade pip setuptools wheel - -COPY --chown=eghbalaz:eghbalaz requirements.txt ./ -RUN pip install --user --no-cache-dir -r requirements.txt - -COPY --chown=eghbalaz:eghbalaz . . -RUN pip install --user . -RUN chmod +x ./run_all.sh -RUN mkdir test/results - -ENTRYPOINT [ "./run_all.sh" ] \ No newline at end of file +RUN pip install . diff --git a/experiment.sh b/experiment.sh index dfe273c..540fd8d 100644 --- a/experiment.sh +++ b/experiment.sh @@ -13,6 +13,8 @@ venv=$1_$3_env virtualenv --python 3.9.0 venvs/$venv source venvs/$venv/bin/activate +export PYTHONPATH="$PWD/venvs/$venv/lib/python3.9/site-packages" + exactTime=`date +%y%m%d%H%M%S` # Install DynaPyt @@ -34,6 +36,7 @@ if [ $3 = "original" ]; then [ -f myInstall.sh ] && bash ./myInstall.sh || pip install . # Run tests python run_all_tests.py > $1_original_${exactTime}_output.txt + tail -n 3 $1_original_${exactTime}_output.txt else # Instrument code python -m dynapyt.run_instrumentation --dir . --analysis $3 @@ -41,6 +44,7 @@ else [ -f myInstall.sh ] && bash ./myInstall.sh || pip install . # Run tests python -m dynapyt.run_analysis --entry run_all_tests.py --analysis $3 > $1_$3_${exactTime}_output.txt + tail -n 3 $1_$3_${exactTime}_output.txt fi cd ../.. diff --git a/filter_tests.py b/filter_tests.py index b4066c2..a72a143 100644 --- a/filter_tests.py +++ b/filter_tests.py @@ -5,7 +5,7 @@ bad_tests = set() results = [] print(' '.join(sys.argv)) -test_dir = sys.argv[2] +test_dir = sys.argv[-1] def find_testfile(frame, package_test_dir): while frame is not None: @@ -34,7 +34,7 @@ def uses_stack(frame, event, arg=None): sys.settrace(uses_stack) -pytest.main([sys.argv[1] + '/' + test_dir]) +pytest.main(sys.argv[1:]) print('\n'.join(bad_tests)) with open('filtered.txt', 'w') as f: diff --git a/src/dynapyt/instrument/CodeInstrumenter.py b/src/dynapyt/instrument/CodeInstrumenter.py index 2fecaa6..5439409 100644 --- a/src/dynapyt/instrument/CodeInstrumenter.py +++ b/src/dynapyt/instrument/CodeInstrumenter.py @@ -628,6 +628,7 @@ def leave_Assert(self, original_node, updated_node): def leave_Call(self, original_node, updated_node): if ('pre_call' not in self.selected_hooks) and ('post_call' not in self.selected_hooks): return updated_node + site_sensitive_functions = ['breakpoint', 'dir', 'eval', 'exec', 'globals', 'help', 'locals', 'super', 'vars'] callee_name = cst.Name(value='_call_') self.to_import.add('_call_') iid = self.__create_iid(original_node) @@ -640,7 +641,7 @@ def leave_Call(self, original_node, updated_node): name_source = self.get_metadata(QualifiedNameProvider, original_node) except KeyError: name_source = [] - if (((len(list(name_source)) > 0) and (list(name_source)[0].source == QualifiedNameSource.BUILTIN)) or + if (((len(list(name_source)) > 0) and (list(name_source)[0].source == QualifiedNameSource.BUILTIN) and (original_node.func.value in site_sensitive_functions)) or (any(a for a in updated_node.args if m.matches(a.value, m.GeneratorExp())))): call_arg = cst.Arg(value=updated_node) only_post = cst.Arg(value=cst.Name('True')) diff --git a/src/dynapyt/runtime.py b/src/dynapyt/runtime.py index 93423fd..19733c0 100644 --- a/src/dynapyt/runtime.py +++ b/src/dynapyt/runtime.py @@ -9,6 +9,7 @@ def set_analysis(new_analysis): analysis = new_analysis def call_if_exists(f, *args): + print(f'Calling {f} on analysis {analysis}') try: func = getattr(analysis, f) return func(*args) @@ -480,6 +481,6 @@ def _gen_(dyn_ast, iid, iterator): yield result else: yield it - except StopIteration: - _enter_for_(dyn_ast, iid, StopIteration()) + except StopIteration as e: + _enter_for_(dyn_ast, iid, e) return \ No newline at end of file