criu/test/others/action-script/check_actions.py
Radostin Stoyanov f74e68daf9 ci: verify call order of action-script hooks
The existing test collects all action-script hooks triggered during
`h`, `ns`, and `uns` runs with ZDTM into `actions_called.txt`, then
verifies that each hook appears at least once. However, the test does
not verify that hooks are invoked *exactly once* or in *correct order*.

This change updates the test to run ZDTM only with ns flavour as this
seems to cover all action-script hooks, and checks that all hooks are
called correctly.

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
2025-11-05 15:41:34 -08:00

54 lines
1.5 KiB
Python
Executable file

#!/usr/bin/env python3
import os
import sys
EXPECTED_ACTIONS = [
'pre-dump',
'network-lock',
'post-dump',
'pre-restore',
'setup-namespaces',
'post-setup-namespaces',
'post-restore',
'network-unlock',
'pre-resume',
'post-resume',
]
errors = []
actions_called = []
actions_called_file = os.path.join(os.path.dirname(__file__), 'actions_called.txt')
with open(actions_called_file) as f:
for index, line in enumerate(f):
parts = line.strip().split()
parts += ['EMPTY'] * (3 - len(parts))
action_hook, image_dir, pid = parts
if action_hook == 'EMPTY':
raise ValueError("Error in test: bogus actions line")
expected_action = EXPECTED_ACTIONS[index] if index < len(EXPECTED_ACTIONS) else None
if action_hook != expected_action:
raise ValueError(f"Invalid action: {action_hook} != {expected_action}")
if image_dir == 'EMPTY':
errors.append(f'Action {action_hook} misses CRTOOLS_IMAGE_DIR')
if action_hook != 'pre-restore':
if pid == 'EMPTY':
errors.append(f'Action {action_hook} misses CRTOOLS_INIT_PID')
elif not pid.isdigit() or int(pid) == 0:
errors.append(f'Action {action_hook} PID is not a valid number ({pid})')
actions_called.append(action_hook)
if actions_called != EXPECTED_ACTIONS:
errors.append(f'Not all actions called: {actions_called!r}')
if errors:
print('\n'.join(errors))
sys.exit(1)
print('Check Actions PASS')