Fix and re-enable unit tests (#2182)

* Add gdb_version to mock gdblib

* Re-enable unit tests

* Only collect unit test coverage if --cov is passed

* Source venv before running tests in github action

* Add venv path PATH in to Dockerfile

* Only check for "/ls" in `which` test
pull/2197/head
Gulshan Singh 2 years ago committed by GitHub
parent db320b6b97
commit d6abb33e02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -47,6 +47,7 @@ jobs:
# We set `kernel.yama.ptrace_scope=0` for `attachp` command tests
- name: Run tests
run: |
source .venv/bin/activate
mkdir .cov
sudo sysctl -w kernel.yama.ptrace_scope=0
./tests.sh --cov

@ -49,6 +49,8 @@ ADD . /pwndbg/
ARG LOW_PRIVILEGE_USER="vscode"
ENV PATH="${PWNDBG_VENV_PATH}/bin:${PATH}"
# Add .gdbinit to the home folder of both root and vscode users (if vscode user exists)
# This is useful for a VSCode dev container, not really for test builds
RUN if [ ! -f ~/.gdbinit ]; then echo "source /pwndbg/gdbinit.py" >> ~/.gdbinit; fi && \

@ -17,6 +17,7 @@ ENV PIP_NO_CACHE_DIR=true
ENV LANG en_US.utf8
ENV TZ=America/New_York
ENV ZIGPATH=/opt/zig
ENV PWNDBG_VENV_PATH=/venv
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
echo $TZ > /etc/timezone && \
@ -43,9 +44,11 @@ RUN rm README.md && rm -rf pwndbg
ADD ./setup-dev.sh /pwndbg/
RUN ./setup-dev.sh
ADD . /pwndbg/
ENV PATH="${PWNDBG_VENV_PATH}/bin:${PATH}"
RUN echo "source /pwndbg/gdbinit.py" >> ~/.gdbinit.py && \
echo "PYTHON_MINOR=$(python3 -c "import sys;print(sys.version_info.minor)")" >> /root/.bashrc && \
echo "PYTHON_PATH=\"/usr/local/lib/python3.${PYTHON_MINOR}/dist-packages/bin\"" >> /root/.bashrc && \
echo "export PATH=$PATH:$PYTHON_PATH" >> /root/.bashrc
ADD . /pwndbg/

@ -3,5 +3,17 @@
# Run integration tests
(cd tests/gdb-tests && python3 tests.py $@)
COV=0
# Run unit tests
# coverage run -m pytest tests/unit-tests
for arg in "$@"; do
if [ "$arg" == "--cov" ]; then
COV=1
break
fi
done
if [ $COV -eq 1 ]; then
coverage run -m pytest tests/unit-tests
else
pytest tests/unit-tests
fi

@ -13,6 +13,8 @@ class GdbLib(types.ModuleType):
def __init__(self, module_name):
super().__init__(module_name)
self.gdb_version = (12, 0)
self.config_mod = Config(module_name + ".config")
self.arch = Amd64Arch(module_name + ".arch")
self.typeinfo = Amd64TypeInfo(module_name + ".typeinfo")

@ -21,7 +21,7 @@ from pwndbg.lib.which import which
def test_basic():
assert which("ls") == "/bin/ls"
assert which("ls").endswith("/ls")
def test_nonexistent():

Loading…
Cancel
Save