Hook support

Hook support — Support for running a hook script on test execution

Functions

Types and Values

Description

IGT provides support for running a hook script when executing tests. This support is provided to users via CLI option --hook available in test binaries. Users should use --help-hook for detailed usaged description of the feature.

The sole user of the exposed API is igt_core, which calls igt_hook_create() when initializing a test case, then calls igt_hook_event_notify() for each event that occurs during that test's execution and finally calls igt_hook_free() to clean up at the end.

Functions

igt_hook_create ()

int
igt_hook_create (const char **hook_strs,
                 size_t n,
                 struct igt_hook **igt_hook_ptr);

Allocate and initialize an igt_hook structure.

This function parses the hook descriptors in hook_strs and initializes the struct. The pointer to the allocated structure is stored in igt_hook_ptr .

Each hook descriptor comes from the argument to --hook of the test executable being run.

If an error happens, the returned error number can be passed to igt_hook_error_str() to get a human-readable error message.

Parameters

hook_str

Array of hook strings.

 

n

Number of element in hook_strs .

 

igt_hook_ptr

Destination of the struct igt_hook pointer.

 

Returns

Zero on success and a non-zero value on error.


igt_hook_free ()

void
igt_hook_free (struct igt_hook *igt_hook);

De-initialize an igt_hook struct returned by igt_hook_create() .

This is a no-op if igt_hook is NULL.

Parameters

igt_hook

The igt_hook struct.

 

igt_hook_event_notify ()

void
igt_hook_event_notify (struct igt_hook *igt_hook,
                       struct igt_hook_evt *evt);

Push a new igt_hook event.

The argument to igt_hook can be NULL, which is equivalent to a no-op.

This function must be used to notify on a new igt_hook event. Calling it will cause execution of the hook script if the event type matches the filters provided during initialization of igt_hook .

Parameters

igt_hook

The igt_hook structure.

 

evt

The event to be pushed.

 

igt_hook_error_str ()

const char *
igt_hook_error_str (int error);

Return a human-readable string containing a description of an error number generated by one of the igt_hook_* functions.

The string will be the result of strerror() for errors from the C standard library or a custom description specific to igt_hook.

Parameters

error

Non-zero error number.

 

igt_hook_print_help ()

void
igt_hook_print_help (FILE *f,
                     const char *option_name);

Print a detailed user help text on hook usage.

Parameters

f

File pointer where to write the output.

 

option_name

Name of the CLI option that accepts the hook descriptor.

 

Types and Values

enum igt_hook_evt_type

Events tracked by igt_hook. Those events occur at specific points during the execution of a test.

Members

IGT_HOOK_PRE_TEST

Occurs before a test case (executable) starts the test code.

 

IGT_HOOK_PRE_SUBTEST

Occurs before the execution of a subtest.

 

IGT_HOOK_PRE_DYN_SUBTEST

Occurs before the execution of a dynamic subtest.

 

IGT_HOOK_POST_DYN_SUBTEST

Occurs after the execution of a dynamic subtest.

 

IGT_HOOK_POST_SUBTEST

Occurs after the execution of a subtest..

 

IGT_HOOK_POST_TEST

Occurs after a test case (executable) is finished with the test code.

 

IGT_HOOK_NUM_EVENTS

This is not really an event and represents the number of possible events tracked by igt_hook.

 

struct igt_hook_evt

struct igt_hook_evt {
	enum igt_hook_evt_type evt_type;
	const char *target_name;
	const char *result;
};

An event tracked by igt_hook, which is done with @igt_hook_event_notify() . This must be zero initialized and fields relevant to the event type must be set before passing its reference to igt_hook_event_notify() .

Members

enum igt_hook_evt_type evt_type;

Type of event.

 

const char *target_name;

A string pointing to the name of the test, subtest or dynamic subtest, depending on evt_type .

 

const char *result;

A string containing the result of the test, subtest or dynamic subtest. This is only applicable for the `IGT_HOOK_POST_*' event types; other types must initialize this to NULL.

 

struct igt_hook

struct igt_hook;

Opaque struct to hold data related to hook support.