1
0

proj: Enhance ./test-return-values

This commit is contained in:
2025-03-09 10:58:24 +01:00
parent de790eabf9
commit ab6a405830
4 changed files with 119 additions and 11 deletions

View File

@@ -157,9 +157,91 @@ class InterruptedCheckTester(Handler):
return self.functions[func_name][1]
class ReturnValueCheckTester(Handler):
functions: dict[str, list[str]] = {
fn: [e for e in errors if e not in SKIP_ERRORS and e not in IGNORE_ERRORS]
for fn, errors in FUNCTION_ERRORS.items()
if len(set(errors) - set(SKIP_ERRORS) - set(IGNORE_ERRORS)) > 0
def get_return_value_check_tester() -> tuple[dict, type[Handler]]:
ctx = {
'state': 'init',
'call_sequence': [],
'next': None,
'last_error': None,
'results': {},
}
class ReturnValueCheckTester(Handler):
functions: dict[str, list[str]] = {
fn: [e for e in errors if e not in SKIP_ERRORS and e not in IGNORE_ERRORS]
for fn, errors in FUNCTION_ERRORS.items()
if len(set(errors) - set(SKIP_ERRORS) - set(IGNORE_ERRORS)) > 0
}
context: dict
num: int = 0
@property
def call_sequence(self) -> list[str]:
return self.context['call_sequence']
@property
def is_init(self) -> bool:
return self.context['state'] == 'init'
@property
def is_testing(self) -> bool:
return self.context['state'] == 'testing'
@property
def is_waiting(self) -> bool:
return self.context['state'] == 'waiting'
@property
def is_failed(self) -> bool:
return self.context['state'] == 'failed'
def next(self, last: Optional[tuple[int, Optional[str]]]) -> tuple[int, Optional[str]]:
if last is None:
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 before(self) -> None:
self.context = ctx
if self.is_waiting or self.is_failed:
self.context['state'] = 'testing'
def after(self) -> None:
if self.is_init:
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 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