[PATCH i-g-t v3 1/6] igt_hook: Add feature

Lucas De Marchi lucas.demarchi at intel.com
Mon Aug 12 13:52:33 UTC 2024


On Thu, Jul 25, 2024 at 11:19:34AM GMT, Gustavo Sousa wrote:
>For development purposes, sometimes it is useful to have a way of
>running custom scripts at certain points of test executions. A
>real-world example I bumped into recently is to collect information from
>sysfs before and after running each entry of a testlist.
>
>While it is possible for the user to handcraft a script that calls each
>test with the correct actions before and after execution, we can provide
>a better experience by adding built-in support for running hooks during
>test execution.
>
>That would be even better when adding the same kind of support for
>igt_runner (which is done in an upcoming change), since the user can
>also nicely resume with igt_resume with the hook already setup in case a
>crash happens during execution of the test list.
>
>As such provide implement support for hooks, integrate it into
>igt_core and expose the functionality via --hook CLI option on test
>executables.
>
>v2:
>  - s/igt_hook_init/igt_hook_create/ (Lucas)
>  - Use SPDX License Identifier instead of license text. (Lucas)
>  - Do not rely on hard-coded length 3 when generating full test name.
>    (Lucas)
>  - Do not pollute current environment variables when running hooks.
>    (Lucas)
>  - Change hook string in run_tests_and_match_env() to use "printf"
>    instead of "echo" to be compatible with CI environment.
>
>v3:
>  - igt_hook_create() only errors out for invalid input.
>  - Use igt_hook_free() instead of simply free() in the error path for
>    common_init().
>  - Go back to the simpler logic for calling hooks instead of using
>    fork: setenv() calls followed by system().
>  - Change igt_hook_create() to return error number and receive
>    reference to destination pointer instead of the opposite. (Lucas)
>  - Remove checks for non-existing negative return of igt_hook_create().
>    (Lucas)
>  - s/igt_hook_push_evt/igt_hook_event_notify/. (Lucas)
>  - Simplify call sites for igt_hook_event_notify() by allowing argument
>    to igt_hook to be NULL and using compount literals for the event
>    struct. (Lucas)
>  - Fix style for igt_hook_calc_test_fullname_size(). (Lucas)
>
>Signed-off-by: Gustavo Sousa <gustavo.sousa at intel.com>


Reviewed-by: Lucas De Marchi <lucas.demarchi at intel.com>


just 2 nits below

>+void igt_hook_event_notify(struct igt_hook *igt_hook, struct igt_hook_evt *evt)
>+{
>+	evt_mask_t evt_bit;
>+
>+	if (!igt_hook)
>+		return;
>+
>+	evt_bit = (1 << evt->evt_type);

no need for parenthesis

>+	igt_hook_update_test_name_pre_call(igt_hook, evt);
>+
>+	if ((evt_bit & igt_hook->evt_mask)) {

same here

Lucas De Marchi


More information about the igt-dev mailing list