Skip to content

Commit

Permalink
Use pytest on top of unittest to allow multi-proc execution (#714)
Browse files Browse the repository at this point in the history
* Use `pytest` on top of `unittest` to allow multi-proc execution
* Added test binary to test `unicorn` more simply
  • Loading branch information
hugsy committed Sep 15, 2021
1 parent 3fc237c commit 90ffa6b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ['ubuntu-20.04', 'ubuntu-18.04']
os: [ubuntu-20.04, ubuntu-18.04]
name: "Run Unit tests on ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
defaults:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -8,14 +8,14 @@ PYLINT_PARAMETERS := --disable=$(PYLINT_DISABLE) --enable=$(PYLINT_ENABLE) --job

test: testbins
@cp gef.py /tmp/gef.py
python3 tests/runtests.py
python3 -m pytest --verbose --numprocesses=$(NB_CORES) tests/runtests.py
@rm -f /tmp/gef.py
@rm -f /tmp/gef-*
@$(MAKE) -j $(NB_CORES) -C tests/binaries clean

Test%: testbins
@cp gef.py /tmp/gef.py
python3 tests/runtests.py $@
python3 -m pytest --verbose --numprocesses=$(NB_CORES) tests/runtests.py $@
@rm -f /tmp/gef.py
@rm -f /tmp/gef-*

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -44,7 +44,7 @@ If you really need GDB+Python2, use the (not actively maintained) [`gef-legacy`]
## Community ##
[![Discord](https://img.shields.io/badge/Discord-GDB--GEF-yellow)](https://discordapp.com/channels/705160148813086841/705160148813086843) [[invite link](https://discord.gg/HCS8Hg7)]
[![Discord](https://img.shields.io/badge/Discord-GDB--GEF-yellow)](https://discord.gg/HCS8Hg7)
_Note_: For maintenance simplicity, the unified communities on IRC/Gitter/Slack/Discord based [MatterBridge](https://github.com/42wim/matterbridge) are now discontinued. The GEF Discord is now the only way for talking with us!
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Expand Up @@ -3,3 +3,5 @@ keystone-engine
pylint
ropper
unicorn
pytest
pytest-xdist
14 changes: 14 additions & 0 deletions tests/binaries/unicorn.c
@@ -0,0 +1,14 @@
#include <stdlib.h>
#include <string.h>

int function1()
{
const char* a1 = "PATH";
const char* a2 = "WHATEVER";
return strcmp( getenv(a1), a2);
}

int main()
{
return function1();
}
8 changes: 4 additions & 4 deletions tests/runtests.py
Expand Up @@ -629,16 +629,16 @@ def test_cmd_trace_run(self):
return

def test_cmd_unicorn_emulate(self):
before = ["br *main", "r", "si"] # "si" needed to avoid invalid memory read

nb_insn = 4
cmd = "emu {}".format(nb_insn)
res = gdb_run_cmd(cmd)
res = gdb_run_silent_cmd(cmd)
self.assertFailIfInactiveSession(res)

target = "/tmp/unicorn.out"
before = ["break function1", "si"]
start_marker = "= Starting emulation ="
end_marker = "Final registers"
res = gdb_run_cmd(cmd, before=before)
res = gdb_run_silent_cmd(cmd, target=target, before=before)
self.assertNoException(res)
self.assertNotIn("Emulation failed", res)
self.assertIn(start_marker, res)
Expand Down

0 comments on commit 90ffa6b

Please sign in to comment.