proj/test-interrupts: Output well-formatted report
This commit is contained in:
@@ -26,6 +26,40 @@ StructMsgHdr = TypedDict('StructMsgHdr', {})
|
|||||||
RET_ADDR_RE = re.compile(r': *((0x)?[0-9a-fA-Fx]+) *\((.+?)\+(.+?)(, *([^:]+?))?(, *(([^:]+?):([0-9]+)))?\)$')
|
RET_ADDR_RE = re.compile(r': *((0x)?[0-9a-fA-Fx]+) *\((.+?)\+(.+?)(, *([^:]+?))?(, *(([^:]+?):([0-9]+)))?\)$')
|
||||||
|
|
||||||
|
|
||||||
|
class FunctionCallId:
|
||||||
|
func_name: str
|
||||||
|
ret_addr: int
|
||||||
|
obj_path: str
|
||||||
|
rel_ret_addr: int
|
||||||
|
sym_name: Optional[str]
|
||||||
|
src_file_name: Optional[str]
|
||||||
|
src_line_num: Optional[int]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def obj_name(self) -> str:
|
||||||
|
return self.obj_path.split('/')[-1]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def discriminator(self) -> str:
|
||||||
|
discr = [f'{self.obj_name}+0x{self.rel_ret_addr:x}']
|
||||||
|
if self.sym_name:
|
||||||
|
discr.append(self.sym_name)
|
||||||
|
if self.src_file_name and self.src_line_num:
|
||||||
|
discr.append(f'{self.src_file_name}:{self.src_line_num}')
|
||||||
|
return ', '.join(discr)
|
||||||
|
|
||||||
|
def __eq__(self, other) -> bool:
|
||||||
|
if not isinstance(other, FunctionCallId):
|
||||||
|
return False
|
||||||
|
return (self.func_name, self.obj_path, self.rel_ret_addr) == (other.func_name, other.obj_path, other.rel_ret_addr)
|
||||||
|
|
||||||
|
def __hash__(self) -> int:
|
||||||
|
return hash((self.func_name, self.obj_path, self.rel_ret_addr))
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return self.func_name + ', ' + self.discriminator
|
||||||
|
|
||||||
|
|
||||||
class ThreadedUnixStreamServer(ThreadingMixIn, UnixStreamServer):
|
class ThreadedUnixStreamServer(ThreadingMixIn, UnixStreamServer):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -51,6 +85,17 @@ class Parser:
|
|||||||
self.pid = None
|
self.pid = None
|
||||||
self.path = None
|
self.path = None
|
||||||
|
|
||||||
|
def get_call_id(self, func_name: str) -> FunctionCallId:
|
||||||
|
call_id = FunctionCallId()
|
||||||
|
call_id.func_name = func_name
|
||||||
|
call_id.ret_addr = self.ret_addr
|
||||||
|
call_id.obj_path = self.dli_file_name
|
||||||
|
call_id.rel_ret_addr = self.rel_ret_addr
|
||||||
|
call_id.sym_name = self.dli_sym_name
|
||||||
|
call_id.src_file_name = self.src_file_name
|
||||||
|
call_id.src_line_num = self.src_line_num
|
||||||
|
return call_id
|
||||||
|
|
||||||
def before(self) -> None: pass
|
def before(self) -> None: pass
|
||||||
def after(self) -> None: pass
|
def after(self) -> None: pass
|
||||||
def before_fallback(self, func_name: str, *args) -> str: pass
|
def before_fallback(self, func_name: str, *args) -> str: pass
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from intercept import *
|
from intercept import *
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
FUNCTION_ERRORS: dict[str, list[str]] = {
|
FUNCTION_ERRORS: dict[str, list[str]] = {
|
||||||
@@ -54,8 +53,8 @@ SKIP_ERRORS: list[str] = ['EINTR']
|
|||||||
|
|
||||||
|
|
||||||
class MemoryAllocationParser(Parser):
|
class MemoryAllocationParser(Parser):
|
||||||
allocated: dict[int, tuple[str, int, str, str, int, str, int]]
|
allocated: dict[int, tuple[FunctionCallId, int]]
|
||||||
invalid_frees: list[tuple[str, int, str, str, int, str, int]]
|
invalid_frees: list[tuple[FunctionCallId, int]]
|
||||||
max_allocated: int
|
max_allocated: int
|
||||||
num_alloc: int
|
num_alloc: int
|
||||||
num_realloc: int
|
num_realloc: int
|
||||||
@@ -77,56 +76,46 @@ class MemoryAllocationParser(Parser):
|
|||||||
def after_malloc(self, size, ret_value, errno=None) -> None:
|
def after_malloc(self, size, ret_value, errno=None) -> None:
|
||||||
self.num_alloc += 1
|
self.num_alloc += 1
|
||||||
if ret_value != 0:
|
if ret_value != 0:
|
||||||
self.allocated[ret_value] = ('malloc', size,
|
self.allocated[ret_value] = (self.get_call_id('malloc'), size)
|
||||||
self.dli_file_name, self.dli_sym_name, self.rel_ret_addr,
|
|
||||||
self.src_file_name, self.src_line_num)
|
|
||||||
self.update_max_allocated()
|
self.update_max_allocated()
|
||||||
|
|
||||||
def after_calloc(self, nmemb, size, ret_value, errno=None) -> None:
|
def after_calloc(self, nmemb, size, ret_value, errno=None) -> None:
|
||||||
self.num_alloc += 1
|
self.num_alloc += 1
|
||||||
if ret_value != 0:
|
if ret_value != 0:
|
||||||
self.allocated[ret_value] = ('calloc', nmemb * size,
|
self.allocated[ret_value] = (self.get_call_id('calloc'), nmemb * size)
|
||||||
self.dli_file_name, self.dli_sym_name, self.rel_ret_addr,
|
|
||||||
self.src_file_name, self.src_line_num)
|
|
||||||
self.update_max_allocated()
|
self.update_max_allocated()
|
||||||
|
|
||||||
def after_realloc(self, ptr, size, ret_value, errno=None) -> None:
|
def after_realloc(self, ptr, size, ret_value, errno=None) -> None:
|
||||||
if ptr == 0:
|
if ptr == 0:
|
||||||
self.num_alloc += 1
|
self.num_alloc += 1
|
||||||
if ret_value != 0:
|
if ret_value != 0:
|
||||||
self.allocated[ret_value] = ('realloc', size,
|
self.allocated[ret_value] = (self.get_call_id('realloc'), size)
|
||||||
self.dli_file_name, self.dli_sym_name, self.rel_ret_addr,
|
|
||||||
self.src_file_name, self.src_line_num)
|
|
||||||
else:
|
else:
|
||||||
self.num_realloc += 1
|
self.num_realloc += 1
|
||||||
if ret_value != 0 and ptr in self.allocated:
|
if ret_value != 0 and ptr in self.allocated:
|
||||||
v = self.allocated[ptr]
|
v = self.allocated[ptr]
|
||||||
del self.allocated[ptr]
|
del self.allocated[ptr]
|
||||||
self.allocated[ret_value] = (v[0], size, v[2], v[3], v[4], v[5], v[6])
|
self.allocated[ret_value] = (v[0], size)
|
||||||
self.update_max_allocated()
|
self.update_max_allocated()
|
||||||
|
|
||||||
def after_reallocarray(self, ptr, nmemb, size, ret_value, errno=None) -> None:
|
def after_reallocarray(self, ptr, nmemb, size, ret_value, errno=None) -> None:
|
||||||
if ptr == 0:
|
if ptr == 0:
|
||||||
self.num_alloc += 1
|
self.num_alloc += 1
|
||||||
if ret_value != 0:
|
if ret_value != 0:
|
||||||
self.allocated[ret_value] = ('reallocarray', nmemb * size,
|
self.allocated[ret_value] = (self.get_call_id('reallocarray'), nmemb * size)
|
||||||
self.dli_file_name, self.dli_sym_name, self.rel_ret_addr,
|
|
||||||
self.src_file_name, self.src_line_num)
|
|
||||||
else:
|
else:
|
||||||
self.num_realloc += 1
|
self.num_realloc += 1
|
||||||
if ret_value != 0:
|
if ret_value != 0:
|
||||||
v = self.allocated[ptr]
|
v = self.allocated[ptr]
|
||||||
del self.allocated[ptr]
|
del self.allocated[ptr]
|
||||||
self.allocated[ret_value] = (v[0], nmemb * size, v[2], v[3], v[4], v[5], v[6])
|
self.allocated[ret_value] = (v[0], nmemb * size)
|
||||||
self.update_max_allocated()
|
self.update_max_allocated()
|
||||||
|
|
||||||
def after_getaddrinfo(self, node, service, hints, res_ptr, ret_value, errno=None, res=None) -> None:
|
def after_getaddrinfo(self, node, service, hints, res_ptr, ret_value, errno=None, res=None) -> None:
|
||||||
self.num_alloc += 1
|
self.num_alloc += 1
|
||||||
if ret_value[0] == 0 and res is not None:
|
if ret_value[0] == 0 and res is not None:
|
||||||
size = sum(48 + r['ai_addrlen'] for r in res[1])
|
size = sum(48 + r['ai_addrlen'] for r in res[1])
|
||||||
self.allocated[res[0]] = ('getaddrinfo', size,
|
self.allocated[res[0]] = (self.get_call_id('getaddrinfo'), size)
|
||||||
self.dli_file_name, self.dli_sym_name, self.rel_ret_addr,
|
|
||||||
self.src_file_name, self.src_line_num)
|
|
||||||
self.update_max_allocated()
|
self.update_max_allocated()
|
||||||
|
|
||||||
def after_free(self, ptr) -> None:
|
def after_free(self, ptr) -> None:
|
||||||
@@ -136,9 +125,7 @@ class MemoryAllocationParser(Parser):
|
|||||||
del self.allocated[ptr]
|
del self.allocated[ptr]
|
||||||
else:
|
else:
|
||||||
self.num_free -= 1
|
self.num_free -= 1
|
||||||
self.invalid_frees.append(('free', ptr,
|
self.invalid_frees.append((self.get_call_id('free'), ptr))
|
||||||
self.dli_file_name, self.dli_sym_name, self.rel_ret_addr,
|
|
||||||
self.src_file_name, self.src_line_num))
|
|
||||||
|
|
||||||
def after_freeaddrinfo(self, res: Pointer) -> None:
|
def after_freeaddrinfo(self, res: Pointer) -> None:
|
||||||
self.num_free += 1
|
self.num_free += 1
|
||||||
@@ -147,9 +134,7 @@ class MemoryAllocationParser(Parser):
|
|||||||
del self.allocated[res]
|
del self.allocated[res]
|
||||||
else:
|
else:
|
||||||
self.num_free -= 1
|
self.num_free -= 1
|
||||||
self.invalid_frees.append(('freeaddrinfo', res,
|
self.invalid_frees.append((self.get_call_id('freeaddrinfo'), res))
|
||||||
self.dli_file_name, self.dli_sym_name, self.rel_ret_addr,
|
|
||||||
self.src_file_name, self.src_line_num))
|
|
||||||
|
|
||||||
|
|
||||||
class MemoryAllocationTester(MemoryAllocationParser, Handler):
|
class MemoryAllocationTester(MemoryAllocationParser, Handler):
|
||||||
@@ -164,37 +149,32 @@ class InterruptedCheckParser(Parser):
|
|||||||
for fn, errors in FUNCTION_ERRORS.items()
|
for fn, errors in FUNCTION_ERRORS.items()
|
||||||
if 'EINTR' in errors or fn in ('sem_post',)
|
if 'EINTR' in errors or fn in ('sem_post',)
|
||||||
}
|
}
|
||||||
|
context: dict
|
||||||
|
|
||||||
counter: int = 0
|
counter: int = 0
|
||||||
last_func_name: Optional[str] = None
|
last_call: Optional[FunctionCallId] = None
|
||||||
last_ret_addr: Optional[int] = None
|
tested_function_calls: dict[FunctionCallId, str]
|
||||||
tested_functions: dict[tuple[str, int], str]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def while_testing(self) -> bool:
|
def while_testing(self) -> bool:
|
||||||
return self.counter % self.cycles != 0
|
return self.counter % self.cycles != 0
|
||||||
|
|
||||||
def before(self) -> None:
|
def before(self) -> None:
|
||||||
self.tested_functions = {}
|
self.tested_function_calls = {}
|
||||||
|
|
||||||
def after(self) -> None:
|
def after(self) -> None:
|
||||||
if self.while_testing:
|
if self.while_testing:
|
||||||
self.error()
|
self.error()
|
||||||
for (name, ret_addr), status in self.tested_functions.items():
|
self.context['results'] = self.tested_function_calls
|
||||||
if status == 'passed':
|
|
||||||
print(f'\x1B[32;1m{name} (0x{ret_addr:x}) -> {status}\x1B[0m', file=sys.stderr)
|
|
||||||
else:
|
|
||||||
print(f'\x1B[31;1m{name} (0x{ret_addr:x}) -> {status}\x1B[0m', file=sys.stderr)
|
|
||||||
|
|
||||||
def error(self):
|
def error(self):
|
||||||
print(f'Error: Return value and errno EINTR not handled correctly in {self.last_func_name} (return address 0x{self.last_ret_addr:x})', file=sys.stderr)
|
self.tested_function_calls[self.last_call] = 'failed'
|
||||||
self.tested_functions[(self.last_func_name, self.last_ret_addr)] = 'failed'
|
|
||||||
self.counter = 0
|
self.counter = 0
|
||||||
self.last_func_name = None
|
self.last_call = None
|
||||||
self.last_ret_addr = None
|
|
||||||
|
|
||||||
def before_fallback(self, func_name: str, *args) -> str:
|
def before_fallback(self, func_name: str, *args) -> str:
|
||||||
if self.while_testing and (self.last_func_name != func_name or self.last_ret_addr != self.ret_addr):
|
call = self.get_call_id(func_name)
|
||||||
|
if self.while_testing and self.last_call != call:
|
||||||
self.error()
|
self.error()
|
||||||
return 'ok'
|
return 'ok'
|
||||||
elif func_name not in self.functions:
|
elif func_name not in self.functions:
|
||||||
@@ -203,14 +183,12 @@ class InterruptedCheckParser(Parser):
|
|||||||
return self.functions[func_name][1]
|
return self.functions[func_name][1]
|
||||||
self.counter += 1
|
self.counter += 1
|
||||||
if self.while_testing:
|
if self.while_testing:
|
||||||
self.last_ret_addr = self.ret_addr
|
self.last_call = call
|
||||||
self.last_func_name = func_name
|
self.tested_function_calls[self.last_call] = 'running'
|
||||||
self.tested_functions[(self.last_func_name, self.last_ret_addr)] = 'running'
|
|
||||||
return self.functions[func_name][0]
|
return self.functions[func_name][0]
|
||||||
else:
|
else:
|
||||||
self.tested_functions[(self.last_func_name, self.last_ret_addr)] = 'passed'
|
self.tested_function_calls[self.last_call] = 'passed'
|
||||||
self.last_ret_addr = None
|
self.last_call = None
|
||||||
self.last_func_name = None
|
|
||||||
return self.functions[func_name][1]
|
return self.functions[func_name][1]
|
||||||
|
|
||||||
|
|
||||||
@@ -218,91 +196,97 @@ class InterruptedCheckTester(InterruptedCheckParser, Handler):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def get_return_value_check_tester() -> tuple[dict, type[Parser]]:
|
class ReturnValueCheckParser(Parser):
|
||||||
ctx = {
|
functions: dict[str, list[str]] = {
|
||||||
'state': 'init',
|
fn: [e for e in errors if e not in SKIP_ERRORS]
|
||||||
'call_sequence': [],
|
for fn, errors in FUNCTION_ERRORS.items()
|
||||||
'next': None,
|
if len(set(errors) - set(SKIP_ERRORS)) > 0
|
||||||
'last_error': None,
|
|
||||||
'results': {},
|
|
||||||
}
|
}
|
||||||
|
context: dict
|
||||||
|
num: int = 0
|
||||||
|
|
||||||
class ReturnValueCheckTester(Parser):
|
@property
|
||||||
functions: dict[str, list[str]] = {
|
def call_sequence(self) -> list[str]:
|
||||||
fn: [e for e in errors if e not in SKIP_ERRORS]
|
return self.context['call_sequence']
|
||||||
for fn, errors in FUNCTION_ERRORS.items()
|
|
||||||
if len(set(errors) - set(SKIP_ERRORS)) > 0
|
|
||||||
}
|
|
||||||
context: dict
|
|
||||||
num: int = 0
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def call_sequence(self) -> list[str]:
|
def is_init(self) -> bool:
|
||||||
return self.context['call_sequence']
|
return self.context['state'] == 'init'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_init(self) -> bool:
|
def is_testing(self) -> bool:
|
||||||
return self.context['state'] == 'init'
|
return self.context['state'] == 'testing'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_testing(self) -> bool:
|
def is_waiting(self) -> bool:
|
||||||
return self.context['state'] == 'testing'
|
return self.context['state'] == 'waiting'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_waiting(self) -> bool:
|
def is_failed(self) -> bool:
|
||||||
return self.context['state'] == 'waiting'
|
return self.context['state'] == 'failed'
|
||||||
|
|
||||||
@property
|
def next(self, last: Optional[tuple[int, Optional[str]]]) -> tuple[int, Optional[str]]:
|
||||||
def is_failed(self) -> bool:
|
if last is None:
|
||||||
return self.context['state'] == 'failed'
|
if len(self.call_sequence) == 0:
|
||||||
|
return 0, None
|
||||||
|
err = self.functions.get(self.call_sequence[0], [None])[0]
|
||||||
|
return (0, err) if err else self.next((0, err))
|
||||||
|
last_fn, last_er = last
|
||||||
|
if last_er is None:
|
||||||
|
if last_fn + 1 >= len(self.call_sequence):
|
||||||
|
return last_fn + 1, None
|
||||||
|
err = self.functions.get(self.call_sequence[last_fn + 1], [None])[0]
|
||||||
|
return (last_fn + 1, err) if err else self.next((last_fn + 1, err))
|
||||||
|
errors = self.functions.get(self.call_sequence[last_fn], [])
|
||||||
|
i = errors.index(last_er)
|
||||||
|
return (last_fn, errors[i + 1]) if i + 1 < len(errors) else self.next((last_fn, None))
|
||||||
|
|
||||||
def next(self, last: Optional[tuple[int, Optional[str]]]) -> tuple[int, Optional[str]]:
|
def before(self) -> None:
|
||||||
if last is None:
|
if 'state' not in self.context:
|
||||||
if len(self.call_sequence) == 0:
|
self.context['state'] = 'init'
|
||||||
return 0, None
|
self.context['state'] = 'init'
|
||||||
err = self.functions.get(self.call_sequence[0], [None])[0]
|
self.context['call_sequence'] = []
|
||||||
return (0, err) if err else self.next((0, err))
|
self.context['next'] = None
|
||||||
last_fn, last_er = last
|
self.context['last_error'] = None
|
||||||
if last_er is None:
|
self.context['results'] = {}
|
||||||
if last_fn + 1 >= len(self.call_sequence):
|
if self.is_waiting or self.is_failed:
|
||||||
return last_fn + 1, None
|
self.context['state'] = 'testing'
|
||||||
err = self.functions.get(self.call_sequence[last_fn + 1], [None])[0]
|
|
||||||
return (last_fn + 1, err) if err else self.next((last_fn + 1, err))
|
|
||||||
errors = self.functions.get(self.call_sequence[last_fn], [])
|
|
||||||
i = errors.index(last_er)
|
|
||||||
return (last_fn, errors[i + 1]) if i + 1 < len(errors) else self.next((last_fn, None))
|
|
||||||
|
|
||||||
def before(self) -> None:
|
def after(self) -> None:
|
||||||
self.context = ctx
|
if self.is_init:
|
||||||
if self.is_waiting or self.is_failed:
|
self.context['state'] = 'testing'
|
||||||
self.context['state'] = 'testing'
|
self.context['next'] = self.next(None)
|
||||||
|
elif self.is_testing and self.context['next'][0] > len(self.context['call_sequence']):
|
||||||
|
self.context['state'] = 'finished'
|
||||||
|
elif self.is_waiting:
|
||||||
|
self.context['results'][(self.num - 1, self.context['last_error'])] = 'passed'
|
||||||
|
|
||||||
def after(self) -> None:
|
def before_fallback(self, func_name: str, *args) -> str:
|
||||||
if self.is_init:
|
if self.is_init:
|
||||||
self.context['state'] = 'testing'
|
self.call_sequence.append(func_name)
|
||||||
self.context['next'] = self.next(None)
|
return 'ok'
|
||||||
elif self.is_testing and self.context['next'][0] > len(self.context['call_sequence']):
|
elif self.is_waiting or self.is_failed:
|
||||||
self.context['state'] = 'finished'
|
print(func_name)
|
||||||
elif self.is_waiting:
|
if func_name not in ('malloc', 'free', 'close', 'exit'):
|
||||||
self.context['results'][(self.num - 1, self.context['last_error'])] = 'passed'
|
self.context['state'] = 'failed'
|
||||||
|
self.context['results'][(self.num - 1, self.context['last_error'])] = 'failed'
|
||||||
|
return 'ok'
|
||||||
|
self.num += 1
|
||||||
|
nxt = self.context['next']
|
||||||
|
if self.num - 1 != nxt[0] or nxt[1] is None:
|
||||||
|
return 'ok'
|
||||||
|
self.context['next'] = self.next(nxt)
|
||||||
|
self.context['state'] = 'waiting' if self.context['next'][1] else 'finished'
|
||||||
|
self.context['last_error'] = nxt[1]
|
||||||
|
return 'fail ' + nxt[1]
|
||||||
|
|
||||||
def before_fallback(self, func_name: str, *args) -> str:
|
|
||||||
if self.is_init:
|
|
||||||
self.call_sequence.append(func_name)
|
|
||||||
return 'ok'
|
|
||||||
elif self.is_waiting or self.is_failed:
|
|
||||||
print(func_name)
|
|
||||||
if func_name not in ('malloc', 'free', 'close', 'exit'):
|
|
||||||
self.context['state'] = 'failed'
|
|
||||||
self.context['results'][(self.num - 1, self.context['last_error'])] = 'failed'
|
|
||||||
return 'ok'
|
|
||||||
self.num += 1
|
|
||||||
nxt = self.context['next']
|
|
||||||
if self.num - 1 != nxt[0] or nxt[1] is None:
|
|
||||||
return 'ok'
|
|
||||||
self.context['next'] = self.next(nxt)
|
|
||||||
self.context['state'] = 'waiting' if self.context['next'][1] else 'finished'
|
|
||||||
self.context['last_error'] = nxt[1]
|
|
||||||
return 'fail ' + nxt[1]
|
|
||||||
|
|
||||||
return ctx, ReturnValueCheckTester
|
class ReturnValueCheckTester(ReturnValueCheckParser, Handler):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def init_with_ctx(parser: type[Parser]) -> tuple[dict, type[Parser]]:
|
||||||
|
ctx = {}
|
||||||
|
class ContextParser(parser):
|
||||||
|
context: dict = ctx
|
||||||
|
return ctx, ContextParser
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
import threading
|
import threading
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -10,8 +11,27 @@ import intercept
|
|||||||
import intercept.standard
|
import intercept.standard
|
||||||
|
|
||||||
|
|
||||||
def socket_thread(socket: str) -> None:
|
def neutral(text: str) -> None:
|
||||||
intercept.intercept(socket, intercept.standard.InterruptedCheckTester)
|
print(text, file=sys.stderr)
|
||||||
|
|
||||||
|
def color(text: str, col: str) -> None:
|
||||||
|
print(('\x1B[' + col + 'm' if sys.stderr.isatty() else '')
|
||||||
|
+ text
|
||||||
|
+ ('\x1B[0m' if sys.stderr.isatty() else ''),
|
||||||
|
file=sys.stderr)
|
||||||
|
|
||||||
|
def bold(text: str) -> None:
|
||||||
|
color(text, '1')
|
||||||
|
|
||||||
|
def red(text: str) -> None:
|
||||||
|
color(text, '31;1')
|
||||||
|
|
||||||
|
def green(text: str) -> None:
|
||||||
|
color(text, '32;1')
|
||||||
|
|
||||||
|
|
||||||
|
def socket_thread(socket: str, handler: type[intercept.Handler]) -> None:
|
||||||
|
intercept.intercept(socket, handler)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
@@ -20,10 +40,11 @@ def main() -> None:
|
|||||||
if len(extra) > 0 and extra[0] == '--':
|
if len(extra) > 0 and extra[0] == '--':
|
||||||
extra.pop(0)
|
extra.pop(0)
|
||||||
if len(extra) == 0:
|
if len(extra) == 0:
|
||||||
parser.error('command expected after arguments or \'--\'')
|
parser.error("command expected after arguments or '--'")
|
||||||
|
|
||||||
socket_name = f'/tmp/intercept.interrupts.{os.getpid()}.sock'
|
socket_name = f'/tmp/intercept.interrupts.{os.getpid()}.sock'
|
||||||
t1 = threading.Thread(target=socket_thread, args=(socket_name,))
|
ctx, handler = intercept.standard.init_with_ctx(intercept.standard.InterruptedCheckTester)
|
||||||
|
t1 = threading.Thread(target=socket_thread, args=(socket_name, handler))
|
||||||
t1.daemon = True
|
t1.daemon = True
|
||||||
t1.start()
|
t1.start()
|
||||||
subprocess.run(extra, env={
|
subprocess.run(extra, env={
|
||||||
@@ -34,6 +55,14 @@ def main() -> None:
|
|||||||
'INTERCEPT_LIBRARIES': ','.join(['*', '-/lib*', '-/usr/lib*']),
|
'INTERCEPT_LIBRARIES': ','.join(['*', '-/lib*', '-/usr/lib*']),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
bold(':: REPORT ::')
|
||||||
|
for call, status in ctx['results'].items():
|
||||||
|
if status == 'passed':
|
||||||
|
green(f':: TEST :: INTERRUPT HANDLING :: {call} :: PASSED')
|
||||||
|
else:
|
||||||
|
red(f':: TEST :: INTERRUPT HANDLING :: {call} :: FAILED')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -58,14 +58,8 @@ def main() -> None:
|
|||||||
if len(parser.allocated) > 0:
|
if len(parser.allocated) > 0:
|
||||||
red(':: TEST :: MEMORY LEAKS :: FAILED ::')
|
red(':: TEST :: MEMORY LEAKS :: FAILED ::')
|
||||||
red(":: Not free'd:")
|
red(":: Not free'd:")
|
||||||
for ptr, (func, size, fname, sname, ret, src, line) in parser.allocated.items():
|
for ptr, (call, size) in parser.allocated.items():
|
||||||
fname = fname.split('/')[-1]
|
red(f':: 0x{ptr:x}: {size:>6} bytes ({call})')
|
||||||
pos = [func, f'{fname}+0x{ret:x}']
|
|
||||||
if sname:
|
|
||||||
pos.append(sname)
|
|
||||||
if src and line:
|
|
||||||
pos.append(f'{src}:{line}')
|
|
||||||
red(f':: 0x{ptr:x}: {size:>6} bytes ({", ".join(pos)})')
|
|
||||||
else:
|
else:
|
||||||
green(':: TEST :: MEMORY LEAKS :: PASSED ::')
|
green(':: TEST :: MEMORY LEAKS :: PASSED ::')
|
||||||
green(":: All allocated memory blocks were free'd!")
|
green(":: All allocated memory blocks were free'd!")
|
||||||
@@ -73,14 +67,8 @@ def main() -> None:
|
|||||||
if len(parser.invalid_frees) > 0:
|
if len(parser.invalid_frees) > 0:
|
||||||
red(':: TEST :: INVALID FREES :: FAILED ::')
|
red(':: TEST :: INVALID FREES :: FAILED ::')
|
||||||
red(':: Invalid/double frees:')
|
red(':: Invalid/double frees:')
|
||||||
for (ptr, func, fname, sname, ret, src, line) in parser.invalid_frees:
|
for (call, ptr) in parser.invalid_frees:
|
||||||
fname = fname.split('/')[-1]
|
red(f':: {call.func_name}: 0x{ptr:x} ({call.discriminator})')
|
||||||
pos = [f'{fname}+0x{ret:x}']
|
|
||||||
if sname:
|
|
||||||
pos.append(sname)
|
|
||||||
if src and line:
|
|
||||||
pos.append(f'{src}:{line}')
|
|
||||||
red(f':: {func}: 0x{ptr:x} ({", ".join(pos)})')
|
|
||||||
else:
|
else:
|
||||||
green(':: TEST :: INVALID FREES :: PASSED ::')
|
green(':: TEST :: INVALID FREES :: PASSED ::')
|
||||||
green(':: No invalid/double frees occured!')
|
green(':: No invalid/double frees occured!')
|
||||||
|
|||||||
@@ -11,6 +11,25 @@ import intercept
|
|||||||
import intercept.standard
|
import intercept.standard
|
||||||
|
|
||||||
|
|
||||||
|
def neutral(text: str) -> None:
|
||||||
|
print(text, file=sys.stderr)
|
||||||
|
|
||||||
|
def color(text: str, col: str) -> None:
|
||||||
|
print(('\x1B[' + col + 'm' if sys.stderr.isatty() else '')
|
||||||
|
+ text
|
||||||
|
+ ('\x1B[0m' if sys.stderr.isatty() else ''),
|
||||||
|
file=sys.stderr)
|
||||||
|
|
||||||
|
def bold(text: str) -> None:
|
||||||
|
color(text, '1')
|
||||||
|
|
||||||
|
def red(text: str) -> None:
|
||||||
|
color(text, '31;1')
|
||||||
|
|
||||||
|
def green(text: str) -> None:
|
||||||
|
color(text, '32;1')
|
||||||
|
|
||||||
|
|
||||||
def socket_thread(socket: str, handler: type[intercept.Handler]) -> None:
|
def socket_thread(socket: str, handler: type[intercept.Handler]) -> None:
|
||||||
intercept.intercept(socket, handler)
|
intercept.intercept(socket, handler)
|
||||||
|
|
||||||
@@ -22,16 +41,16 @@ def main() -> None:
|
|||||||
if len(extra) > 0 and extra[0] == '--':
|
if len(extra) > 0 and extra[0] == '--':
|
||||||
extra.pop(0)
|
extra.pop(0)
|
||||||
if len(extra) == 0:
|
if len(extra) == 0:
|
||||||
parser.error('command expected after arguments or \'--\'')
|
parser.error("command expected after arguments or '--'")
|
||||||
|
|
||||||
stdin = open(args.stdin) if args.stdin else None
|
stdin = open(args.stdin) if args.stdin else None
|
||||||
|
|
||||||
socket_name = f'/tmp/intercept.return-values.{os.getpid()}.sock'
|
socket_name = f'/tmp/intercept.return-values.{os.getpid()}.sock'
|
||||||
ctx, handler = intercept.standard.get_return_value_check_tester()
|
ctx, handler = intercept.standard.init_with_ctx(intercept.standard.ReturnValueCheckTester)
|
||||||
t1 = threading.Thread(target=socket_thread, args=(socket_name, handler))
|
t1 = threading.Thread(target=socket_thread, args=(socket_name, handler))
|
||||||
t1.daemon = True
|
t1.daemon = True
|
||||||
t1.start()
|
t1.start()
|
||||||
while ctx['state'] != 'finished':
|
while ctx.get('state', None) != 'finished':
|
||||||
if stdin:
|
if stdin:
|
||||||
stdin.seek(0, 0)
|
stdin.seek(0, 0)
|
||||||
subprocess.run(extra, stdin=stdin, env={
|
subprocess.run(extra, stdin=stdin, env={
|
||||||
@@ -41,6 +60,10 @@ def main() -> None:
|
|||||||
'INTERCEPT_FUNCTIONS': '*',
|
'INTERCEPT_FUNCTIONS': '*',
|
||||||
'INTERCEPT_LIBRARIES': ','.join(['*', '-/lib*', '-/usr/lib*']),
|
'INTERCEPT_LIBRARIES': ','.join(['*', '-/lib*', '-/usr/lib*']),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
bold(':: REPORT ::')
|
||||||
|
neutral('::')
|
||||||
|
bold(':: SUMMARY ::')
|
||||||
for i, name in enumerate(ctx['call_sequence']):
|
for i, name in enumerate(ctx['call_sequence']):
|
||||||
errors = [r[1] for r in ctx['results'] if r[0] == i]
|
errors = [r[1] for r in ctx['results'] if r[0] == i]
|
||||||
results = [ctx['results'][(i, e)] for e in errors]
|
results = [ctx['results'][(i, e)] for e in errors]
|
||||||
@@ -52,10 +75,10 @@ def main() -> None:
|
|||||||
if res == '-':
|
if res == '-':
|
||||||
esc, unesc = '\x1B[90m', '\x1B[0m'
|
esc, unesc = '\x1B[90m', '\x1B[0m'
|
||||||
elif res == 'failed':
|
elif res == 'failed':
|
||||||
res = '\x1B[31;1mfailed\x1B[0m'
|
res = '\x1B[31;1m' 'FAILED' '\x1B[0m'
|
||||||
elif res == 'passed':
|
elif res == 'passed':
|
||||||
res = '\x1B[32;1mpassed\x1B[0m'
|
res = '\x1B[32;1m' 'PASSED' '\x1B[0m'
|
||||||
print(f'{esc}{i:3} {name:16} {res}{unesc}{errs}')
|
neutral(f':: {esc}{i:3} {name:16} {res}{unesc}{errs}', )
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user