Skip to content

Commit

Permalink
rework testing under tox
Browse files Browse the repository at this point in the history
  • Loading branch information
neok-m4700 committed Feb 15, 2021
1 parent 8e3a57b commit 327b84b
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 15 deletions.
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
)
}

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
11 changes: 11 additions & 0 deletions tests/test_strace.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
import tempfile
import unittest
import signal
import shutil
import platform

STRACE = os.path.normpath(
os.path.join(os.path.dirname(__file__), '..', 'strace.py'))

AARCH64 = (getattr(os.uname(), 'machine', None) == 'aarch64')

UNTESTED = platform.system() not in ('Linux', 'FreeBSD')


class TestStrace(unittest.TestCase):
def strace(self, *args):
Expand Down Expand Up @@ -106,6 +110,13 @@ def test_socket(self):
"import socket; socket.socket(socket.AF_INET,socket.SOCK_STREAM).close()",
br'^socket\(AF_INET, SOCK_STREAM(\|SOCK_CLOEXEC)?')

@unittest.skipIf(UNTESTED, 'Untested system/OS')
def test_crash(self):
dn = os.path.join(os.path.dirname(__file__), 'crash')
shell = shutil.which('bash')
if shell:
self.assertEqual(subprocess.call([shell, '-e', 'run.sh'], cwd=dn), 0)


if __name__ == "__main__":
unittest.main()
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

0 comments on commit 327b84b

Please sign in to comment.