Skip to content

Commit

Permalink
Fixed issue #3: only calling site sensitive calls
Browse files Browse the repository at this point in the history
  • Loading branch information
AryazE committed Oct 10, 2022
1 parent 9c27b03 commit 2c30861
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
22 changes: 5 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
RUN pip install .
4 changes: 4 additions & 0 deletions experiment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,13 +36,15 @@ 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
# Install package
[ -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 ../..
Expand Down
4 changes: 2 additions & 2 deletions filter_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/dynapyt/instrument/CodeInstrumenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'))
Expand Down
5 changes: 3 additions & 2 deletions src/dynapyt/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 2c30861

Please sign in to comment.