Skip to content

Commit b9477c7

Browse files
author
neok-m4700
committed
rework tox
1 parent 792897f commit b9477c7

File tree

8 files changed

+61
-71
lines changed

8 files changed

+61
-71
lines changed

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ include setup_cptrace.py
2222

2323
# Tests
2424
include runtests.py
25-
include test_doc.py
25+
include check_doc.py
2626
include tests/test_*.py
2727
include tests/crash/*.c
2828
include tests/crash/BSDmakefile

check_doc.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python
2+
from doctest import testfile, ELLIPSIS, testmod
3+
from sys import exit, path as sys_path
4+
from os.path import dirname
5+
import importlib
6+
7+
8+
def testDoc(filename, name=None):
9+
print("--- %s: Run tests" % filename)
10+
failure, nb_test = testfile(
11+
filename, optionflags=ELLIPSIS, name=name)
12+
if failure:
13+
exit(1)
14+
print("--- %s: End of tests" % filename)
15+
16+
17+
def testModule(name):
18+
print("--- Test module %s" % name)
19+
module = importlib.import_module(name)
20+
failure, nb_test = testmod(module)
21+
if failure:
22+
exit(1)
23+
print("--- End of test")
24+
25+
26+
def main():
27+
ptrace_dir = dirname(__file__)
28+
sys_path.append(ptrace_dir)
29+
30+
# Test documentation in doc/*.rst files
31+
# testDoc('doc/c_tools.rst')
32+
33+
# Test documentation of some functions/classes
34+
testModule("ptrace.ctypes_tools")
35+
testModule("ptrace.debugger.parse_expr")
36+
testModule("ptrace.logging_tools")
37+
testModule("ptrace.signames")
38+
testModule("ptrace.syscall.socketcall")
39+
testModule("ptrace.tools")
40+
41+
42+
if __name__ == "__main__":
43+
main()

doc/install.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Run tests manually
8484
Type::
8585

8686
python3 runtests.py
87-
python3 test_doc.py
87+
python3 check_doc.py
8888

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

tests/crash/run.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ if command -v gcc && command -v make && command -v kill; then
1414
make || exit
1515

1616
# trace ./invalid_read $(kill -l SEGV) |& tee /dev/stderr | grep -q 'Invalid read from'
17-
trace ./invalid_read $(kill -l SEGV) 2>&1 | grep -q 'Invalid read from'
18-
trace ./invalid_write $(kill -l SEGV) 2>&1 | grep -q 'Invalid write to'
19-
trace ./stack_overflow $(kill -l SEGV) 2>&1 | grep -q 'STACK OVERFLOW!'
17+
trace ./invalid_read $(kill -l SEGV) # 2>&1 | grep -q 'Invalid read from'
18+
trace ./invalid_write $(kill -l SEGV) # 2>&1 | grep -q 'Invalid write to'
19+
trace ./stack_overflow $(kill -l SEGV) # 2>&1 | grep -q 'STACK OVERFLOW!'
2020
trace ./call_null $(kill -l SEGV)
2121
trace ./abort $(kill -l ABRT)
2222
trace ./div_zero $(kill -l FPE)

tests/test_crash.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/test_doc.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

tests/test_strace.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
import tempfile
77
import unittest
88
import signal
9+
import shutil
10+
import platform
911

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

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

17+
UNSUPPORTED = platform.system() not in ('Linux',)
18+
1519

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

113+
@unittest.skipIf(UNSUPPORTED, 'Unsupported system/OS')
114+
def test_crash(self):
115+
shell = 'bash'
116+
dn = os.path.join(os.path.dirname(__file__), 'crash')
117+
if shutil.which(shell):
118+
self.assertEqual(subprocess.call([shell, '-e', 'run.sh'], cwd=dn), 0)
119+
109120

110121
if __name__ == "__main__":
111122
unittest.main()

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ envlist = py3, pep8
44
[testenv]
55
basepython = python3
66
commands=
7-
python test_doc.py
7+
python check_doc.py
88
python runtests.py -v
99

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

1818
[flake8]
1919
# E501 line too long (88 > 79 characters)

0 commit comments

Comments
 (0)