Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the Makefile in the root folder #898

Merged
merged 9 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

## Against which architecture was this tested ?

"Tested" indicates that the PR works *and* the unit test (i.e. `make test`) run passes without issue.
"Tested" indicates that the PR works *and* the unit test (see `docs/testing.md`) run passes without issue.

* [ ] x86-32
* [ ] x86-64
* [ ] ARM
* [ ] AARCH64
* [ ] MIPS
* [ ] POWERPC
* [ ] SPARC
* [ ] RISC-V
* [ ] MIPS
* [ ] POWERPC
* [ ] SPARC
* [ ] RISC-V


## Checklist
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/generate-docs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Generate GithubPages

on:

workflow_dispatch:

push:
branches:
- dev
Expand All @@ -21,10 +24,10 @@ jobs:
python${version} -m pip install --requirement docs/requirements.txt --upgrade
- name: Regenerate GEF API file
run: |
ls
echo "source $(pwd)/gef.py" > ~/.gdbinit
cat ~/.gdbinit
bash scripts/generate-api-docs.sh
bash scripts/generate-coverage-docs.sh
- name: Build and publish the docs
run: |
git config --global user.name "hugsy"
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ jobs:
sudo apt-get install -y gdb-multiarch python3-dev python3-pip python3-wheel python3-setuptools git cmake gcc g++ pkg-config libglib2.0-dev gdbserver
sudo python3 -m pip install --upgrade pip

- name: Set runtime environment variables
run: |
echo PY_VER=`gdb -q -nx -ex "pi print('.'.join(map(str, sys.version_info[:2])))" -ex quit` >> $GITHUB_ENV
echo NB_CPU=`grep -c ^processor /proc/cpuinfo` >> $GITHUB_ENV

- name: Set architecture specific properties
id: set-arch-properties
run: |
Expand Down Expand Up @@ -65,7 +70,7 @@ jobs:
- name: Install Python Requirements
run: |
mkdir -p ${{ steps.pip-cache.outputs.dir }}
python3 -m pip install --user --upgrade -r tests/requirements.txt
python${{ env.PY_VER }} -m pip install --user --upgrade -r tests/requirements.txt

- name: Setup GEF
run: |
Expand All @@ -76,9 +81,10 @@ jobs:
env:
GEF_CI_ARCH: ${{ steps.set-arch-properties.outputs.arch }}
run: |
make test
make -C tests/binaries -j ${{ env.NB_CPU }}
python${{ env.PY_VER }} -m pytest --forked -n ${{ env.NB_CPU }} -v -k "not benchmark" tests/

- name: Run linter
run: |
make lint
python${{ env.PY_VER }} -m pylint --rcfile=$(pwd)/.pylintrc gef.py tests/*/*.py

42 changes: 0 additions & 42 deletions Makefile

This file was deleted.

29 changes: 18 additions & 11 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,24 @@ is enough to get started.
### Running tests


#### Using `make tests`
#### Basic `pytest` te
hugsy marked this conversation as resolved.
Show resolved Hide resolved

For testing GEF on the architecture on the host running the tests (most cases), simply run

```bash
cd /root/of/gef
make test
python3 -m pytest -v -k not benchmark
```

Otherwise, `make` can be adjusted to :
- run one test/one group of tests specifically
- eg. `make test_cmd_heap` will trigger all the test functions for the `heap` command
- run for a different architecture
- eg. on x86, you can test x86 too with `TARGET=i686 make TARGET=i686 test`

Unless a specific test is mentioned, the command `make test` will run all the non-benchmark related tests.
At the end, a summary of explanation will be shown, clearly indicating the tests that have failed: for instance:
Note that to ensure compatibility, tests must be executed with the same Python version GDB was compiled against. To obtain this version, you can execute the following command:

```bash
gdb -q -nx -ex "pi print('.'.join(map(str, sys.version_info[:2])))" -ex quit
```

At the end, a summary of explanation will be shown, clearly indicating the tests that have failed, for instance:

```text
=================================== short test summary info ==================================
FAILED tests/commands/heap.py::HeapCommand::test_cmd_heap_bins_large - AssertionError: 'siz...
FAILED tests/commands/heap.py::HeapCommand::test_cmd_heap_bins_small - AssertionError: 'siz...
Expand Down Expand Up @@ -80,15 +79,23 @@ class MyCommandCommand(GefUnitTestGeneric):

When running your test, you can summon `pytest` with the `--pdb` flag to enter the python testing environment to help you get more information about the reason of failure.

One of the most convenient ways to test `gef` properly is using the `pytest` integration of modern editors such as VisualStudio Code or PyCharm. Without proper tests, new code will not be integrated.


### Linting GEF

You can use the Makefile at the root of the project to get the proper linting settings. For most cases, the following command is enough:

```bash
cd /root/of/gef
make lint
python3 -m pylint --rcfile .pylintrc
```

Note that to ensure compatibility, tests must be executed with the same Python version GDB was compiled against. To obtain this version, you can execute the following command:

```bash
gdb -q -nx -ex "pi print('.'.join(map(str, sys.version_info[:2])))" -ex quit
```

### Benchmarking GEF

Expand Down
4 changes: 2 additions & 2 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -4939,7 +4939,7 @@ class CanaryCommand(GenericCommand):
def do_invoke(self, argv: List[str]) -> None:
self.dont_repeat()

has_canary = checksec(get_filepath())["Canary"]
has_canary = Elf(get_filepath()).checksec["Canary"]
if not has_canary:
warn("This binary was not compiled with SSP.")
return
Expand Down Expand Up @@ -8801,7 +8801,7 @@ def do_invoke(self, argv: List[str]) -> None:
return

def print_security_properties(self, filename: str) -> None:
sec = checksec(filename)
sec = Elf(filename).checksec
for prop in sec:
if prop in ("Partial RelRO", "Full RelRO"): continue
val = sec[prop]
Expand Down
22 changes: 22 additions & 0 deletions scripts/generate-coverage-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -e
set -x

NB_CORES="$(grep --count '^processor' /proc/cpuinfo)"
TMPDIR_RUN="$(mktemp -d)"
TMPDIR_COV="$(mktemp)"
GEF_DIR="$(pwd)"
GEF_TESTS_DIR="${GEF_DIR}/tests"
GEF_DOCS_DIR="${GEF_DIR}/docs/coverage"

rm -f -- "${GEF_DOCS_DIR}"/*

echo "[+] Generating coverage report in '${TMPDIR_RUN}'"
COVERAGE_DIR="${TMPDIR_RUN}" python3.9 -m pytest -n ${NB_CORES} "${GEF_TESTS_DIR}"

echo "[+] Combining data to '${TMPDIR_COV}'"
python3.9 -m coverage combine --data-file=${TMPDIR_COV} "${TMPDIR_RUN}"/*

echo "[+] Generating HTML report to '${GEF_DOCS_DIR}'"
python3.9 -m coverage html --data-file="${TMPDIR_COV}" --include='*/gef.py' --directory="${GEF_DOCS_DIR}"
5 changes: 3 additions & 2 deletions tests/commands/gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ def test_cmd_gef_save(self):

@pytest.mark.online
def test_cmd_gef_install(self):
res = gdb_run_cmd("gef install skel windbg stack")
test_commands = ("skel", "windbg", "stack")
res = gdb_run_cmd(f"gef install {' '.join(test_commands)}")
self.assertNoException(res)
# we install 3 plugins, the pattern must be found 3 times
pattern = "Installed file"
for i in range(3):
for i in range(len(test_commands)):
idx = res.find(pattern)
self.assertNotEqual(-1, idx, f"Check {i}/{3} failed: missing '{pattern}' in\n{res}")
self.assertIn("new command(s) available", res)
Expand Down
5 changes: 3 additions & 2 deletions pytest.ini → tests/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
log_level = INFO
minversion = 6.0
required_plugins =
pytest-xdist
pytest-benchmark
pytest-cov
pytest-xdist
python_functions =
test_*
time_*
python_files = *.py
testpaths =
tests
.
markers =
slow: flag test as slow (deselect with '-m "not slow"')
online: flag test as requiring internet to work (deselect with '-m "not online"')
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pylint
pytest
pytest-cov
pytest-xdist
pytest-benchmark
coverage
4 changes: 3 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ def gdb_time_python_method(meth: str, setup: str,
def _target(name: str, extension: str = ".out") -> pathlib.Path:
target = TMPDIR / f"{name}{extension}"
if not target.exists():
raise FileNotFoundError(f"Could not find file '{target}'")
subprocess.run(["make", "-C", "tests/binaries", target.name])
if not target.exists():
raise FileNotFoundError(f"Could not find file '{target}'")
return target


Expand Down