Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ include setup_cptrace.py

# Tests
include runtests.py
include test_doc.py
include check_doc.py
include tests/test_*.py
include tests/crash/*.c
include tests/crash/BSDmakefile
Expand Down
11 changes: 2 additions & 9 deletions test_doc.py → check_doc.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from doctest import testfile, ELLIPSIS, testmod
from sys import exit, path as sys_path
from os.path import dirname
import importlib


def testDoc(filename, name=None):
Expand All @@ -13,17 +14,9 @@ def testDoc(filename, name=None):
print("--- %s: End of tests" % filename)


def importModule(name):
mod = __import__(name)
components = name.split('.')
for comp in components[1:]:
mod = getattr(mod, comp)
return mod


def testModule(name):
print("--- Test module %s" % name)
module = importModule(name)
module = importlib.import_module(name)
failure, nb_test = testmod(module)
if failure:
exit(1)
Expand Down
2 changes: 1 addition & 1 deletion doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Run tests manually
Type::

python3 runtests.py
python3 test_doc.py
python3 check_doc.py

It's also possible to run a specific test::

Expand Down
27 changes: 27 additions & 0 deletions tests/crash/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

trace() {
(
set +e
python ../../strace.py -e execve $1; ec=$?
if [ $ec -gt 0 ]; then
exit $(($ec - 128 - $2))
fi
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not writing the tests in pure Python in test_strace.py?

Copy link
Collaborator Author

@t-bltg t-bltg Feb 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that having the possibility to run these tests outside the python testing framework was useful (either for dev or for comprehension). If not, tell me, I will rewrite them in pure Python.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel the need, it's up to you. I'm trying to not be a control freak :-)

)
}

if command -v gcc && command -v make && command -v kill; then
make || exit

# trace ./invalid_read $(kill -l SEGV) |& tee /dev/stderr | grep -q 'Invalid read from'
trace ./invalid_read $(kill -l SEGV) # 2>&1 | grep -q 'Invalid read from'
trace ./invalid_write $(kill -l SEGV) # 2>&1 | grep -q 'Invalid write to'
trace ./stack_overflow $(kill -l SEGV) # 2>&1 | grep -q 'STACK OVERFLOW!'
trace ./call_null $(kill -l SEGV)
trace ./abort $(kill -l ABRT)
trace ./div_zero $(kill -l FPE)
trace ./socket_ipv4_tcp
trace ./pthread
trace ./execve
trace ./fork
fi
5 changes: 3 additions & 2 deletions tests/crash/stack_overflow.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
char toto()
{
char buffer[4096];
buffer[0] = 0;
volatile unsigned char buffer[4096];
buffer[0] = 1;
buffer[4095] = 0;
toto();
return buffer[0] + buffer[sizeof(buffer)-1];
}
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ envlist = py3, pep8
[testenv]
basepython = python3
commands=
python test_doc.py
python check_doc.py
python runtests.py -v

[testenv:py3]
Expand All @@ -13,7 +13,7 @@ basepython = python3
[testenv:pep8]
deps = flake8
commands =
flake8 ptrace/ tests/ gdb.py runtests.py setup_cptrace.py setup.py strace.py SYSCALL_PROTOTYPES.codegen.py test_doc.py
flake8 ptrace/ tests/ gdb.py runtests.py setup_cptrace.py setup.py strace.py SYSCALL_PROTOTYPES.codegen.py check_doc.py

[flake8]
# E501 line too long (88 > 79 characters)
Expand Down