2024-10-12 10:31:42 +10:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2024 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2025-04-07 10:52:52 +10:00
|
|
|
#include "util-mem.h"
|
2025-07-01 16:30:11 +10:00
|
|
|
#include "util-range.h"
|
|
|
|
|
|
|
|
|
|
#include "litest.h"
|
2024-10-12 10:31:42 +10:00
|
|
|
|
|
|
|
|
#define LITEST_RUNNER_DEFAULT_TIMEOUT 30
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Result returned from tests or suites.
|
|
|
|
|
*/
|
|
|
|
|
enum litest_runner_result {
|
2025-07-01 16:30:11 +10:00
|
|
|
LITEST_PASS = 75, /**< test successful */
|
|
|
|
|
LITEST_FAIL = 76, /**< test failed. Should not be returned directly,
|
|
|
|
|
Use the litest_ macros instead */
|
|
|
|
|
LITEST_SKIP = 77, /**< test was skipped */
|
|
|
|
|
LITEST_NOT_APPLICABLE = 78, /**< test does not apply */
|
|
|
|
|
LITEST_TIMEOUT = 79, /**< test aborted after timeout */
|
|
|
|
|
LITEST_SYSTEM_ERROR = 80, /**< unrelated error occurred */
|
2024-10-12 10:31:42 +10:00
|
|
|
};
|
|
|
|
|
|
test: implement support for parametrizing tests
litest supports ranged tests but they are not enough, doubly so with
tests where we want to parametrize across multiple options.
This patch adds support for just that, in clunky C style.
The typical invocation for a test is by giving the test parameter
a name, a number of values and then the values themselves:
struct litest_parameters *params = litest_parameters_new("axis", 's', 2, "ABS_X", "ABS_Y",
"enabled", 'b', '2', true, false,
"number", 'u', '2', 10, 11,
NULL);
litest_add_parametrized(sometest, LITEST_ANY, LITEST_ANY, params);
litest_parameters_unref(params);
Currently supported are u (uint32), i (int32), d (double), b (bool),
c (char) and s (string).
In the test itself, the `test_env->params` variable is available and
retrieval of the parameters works like this:
const char *axis;
uint32_t number;
bool enabled;
litest_test_param_fetch(test_env->params,
"axis", &axis,
"enabled", &enabled,
"number", &number,
NULL);
Note that since this is an effectively internal test-suite only
functionality we don't do type-checking here, it's assumed that if you
write the code to pass parameters into a test you remember the type
of said params when you write the test code.
Because we don't have hashmaps or anything useful other than lists the
implementation is a bit clunky: we copy the parameter into the test
during litest_add_*, permutate it for our test list which gives us yet
another linked list C struct, and finally copy the actual value into
the test and test environment as it's executed. Not pretty, but it
works.
A few tests are switched as simple demonstration. The name of the
test has the parameters with their names and values appended now, e.g.:
"pointer:pointer_scroll_wheel_hires_send_only_lores:ms-surface-cover:axis:ABS_X"
"pointer:pointer_motion_relative_min_decel:mouse-roccat:direction:NW"
Filtering by parameters can be done via globs of their string
representation:
libinput-test-suite --filter-params="axis:ABS_*,enabled:true,number:10*"
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1109>
2024-12-22 00:06:19 +10:00
|
|
|
/* For parametrized tests (litest_add_parametrized and friends)
|
|
|
|
|
* a list of these is passed to every test. This struct isn't used
|
|
|
|
|
* directly, use litest_test_param_fetch() instead.
|
|
|
|
|
*/
|
|
|
|
|
struct litest_test_param {
|
|
|
|
|
struct list link;
|
|
|
|
|
char name[128];
|
|
|
|
|
struct multivalue value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct litest_test_parameters {
|
|
|
|
|
int refcnt;
|
|
|
|
|
struct list test_params;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct litest_test_parameters *
|
|
|
|
|
litest_test_parameters_new(void);
|
|
|
|
|
|
|
|
|
|
struct litest_test_parameters *
|
|
|
|
|
litest_test_parameters_unref(struct litest_test_parameters *params);
|
|
|
|
|
|
|
|
|
|
#define litest_test_param_fetch(...) \
|
|
|
|
|
_litest_test_param_fetch(__VA_ARGS__, NULL)
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
_litest_test_param_fetch(const struct litest_test_parameters *params, ...);
|
|
|
|
|
|
2025-02-12 12:03:41 +10:00
|
|
|
static inline const char *
|
2025-07-01 16:30:11 +10:00
|
|
|
litest_test_param_get_string(const struct litest_test_parameters *params,
|
|
|
|
|
const char *name)
|
2025-02-12 12:03:41 +10:00
|
|
|
{
|
|
|
|
|
const char *p;
|
|
|
|
|
litest_test_param_fetch(params, name, 's', &p);
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool
|
2025-07-01 16:30:11 +10:00
|
|
|
litest_test_param_get_bool(const struct litest_test_parameters *params,
|
|
|
|
|
const char *name)
|
2025-02-12 12:03:41 +10:00
|
|
|
{
|
|
|
|
|
bool p;
|
|
|
|
|
litest_test_param_fetch(params, name, 'b', &p);
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int32_t
|
|
|
|
|
litest_test_param_get_i32(const struct litest_test_parameters *params, const char *name)
|
|
|
|
|
{
|
|
|
|
|
int32_t p;
|
|
|
|
|
litest_test_param_fetch(params, name, 'i', &p);
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline uint32_t
|
|
|
|
|
litest_test_param_get_u32(const struct litest_test_parameters *params, const char *name)
|
|
|
|
|
{
|
|
|
|
|
uint32_t p;
|
|
|
|
|
litest_test_param_fetch(params, name, 'u', &p);
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline char
|
2025-07-01 16:30:11 +10:00
|
|
|
litest_test_param_get_char(const struct litest_test_parameters *params,
|
|
|
|
|
const char *name)
|
2025-02-12 12:03:41 +10:00
|
|
|
{
|
|
|
|
|
char p;
|
|
|
|
|
litest_test_param_fetch(params, name, 'c', &p);
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline double
|
2025-07-01 16:30:11 +10:00
|
|
|
litest_test_param_get_double(const struct litest_test_parameters *params,
|
|
|
|
|
const char *name)
|
2025-02-12 12:03:41 +10:00
|
|
|
{
|
|
|
|
|
double p;
|
|
|
|
|
litest_test_param_fetch(params, name, 'd', &p);
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-12 10:31:42 +10:00
|
|
|
/**
|
|
|
|
|
* This struct is passed into every test.
|
|
|
|
|
*/
|
|
|
|
|
struct litest_runner_test_env {
|
2025-07-01 16:30:11 +10:00
|
|
|
int rangeval; /* The current value within the args.range (or 0) */
|
test: implement support for parametrizing tests
litest supports ranged tests but they are not enough, doubly so with
tests where we want to parametrize across multiple options.
This patch adds support for just that, in clunky C style.
The typical invocation for a test is by giving the test parameter
a name, a number of values and then the values themselves:
struct litest_parameters *params = litest_parameters_new("axis", 's', 2, "ABS_X", "ABS_Y",
"enabled", 'b', '2', true, false,
"number", 'u', '2', 10, 11,
NULL);
litest_add_parametrized(sometest, LITEST_ANY, LITEST_ANY, params);
litest_parameters_unref(params);
Currently supported are u (uint32), i (int32), d (double), b (bool),
c (char) and s (string).
In the test itself, the `test_env->params` variable is available and
retrieval of the parameters works like this:
const char *axis;
uint32_t number;
bool enabled;
litest_test_param_fetch(test_env->params,
"axis", &axis,
"enabled", &enabled,
"number", &number,
NULL);
Note that since this is an effectively internal test-suite only
functionality we don't do type-checking here, it's assumed that if you
write the code to pass parameters into a test you remember the type
of said params when you write the test code.
Because we don't have hashmaps or anything useful other than lists the
implementation is a bit clunky: we copy the parameter into the test
during litest_add_*, permutate it for our test list which gives us yet
another linked list C struct, and finally copy the actual value into
the test and test environment as it's executed. Not pretty, but it
works.
A few tests are switched as simple demonstration. The name of the
test has the parameters with their names and values appended now, e.g.:
"pointer:pointer_scroll_wheel_hires_send_only_lores:ms-surface-cover:axis:ABS_X"
"pointer:pointer_motion_relative_min_decel:mouse-roccat:direction:NW"
Filtering by parameters can be done via globs of their string
representation:
libinput-test-suite --filter-params="axis:ABS_*,enabled:true,number:10*"
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1109>
2024-12-22 00:06:19 +10:00
|
|
|
const struct litest_test_parameters *params;
|
2024-10-12 10:31:42 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct litest_runner_test_description {
|
2025-07-01 16:30:11 +10:00
|
|
|
char name[512]; /* The name of the test */
|
|
|
|
|
int rangeval; /* The current value within the args.range (or 0) */
|
2024-10-12 10:31:42 +10:00
|
|
|
|
test: implement support for parametrizing tests
litest supports ranged tests but they are not enough, doubly so with
tests where we want to parametrize across multiple options.
This patch adds support for just that, in clunky C style.
The typical invocation for a test is by giving the test parameter
a name, a number of values and then the values themselves:
struct litest_parameters *params = litest_parameters_new("axis", 's', 2, "ABS_X", "ABS_Y",
"enabled", 'b', '2', true, false,
"number", 'u', '2', 10, 11,
NULL);
litest_add_parametrized(sometest, LITEST_ANY, LITEST_ANY, params);
litest_parameters_unref(params);
Currently supported are u (uint32), i (int32), d (double), b (bool),
c (char) and s (string).
In the test itself, the `test_env->params` variable is available and
retrieval of the parameters works like this:
const char *axis;
uint32_t number;
bool enabled;
litest_test_param_fetch(test_env->params,
"axis", &axis,
"enabled", &enabled,
"number", &number,
NULL);
Note that since this is an effectively internal test-suite only
functionality we don't do type-checking here, it's assumed that if you
write the code to pass parameters into a test you remember the type
of said params when you write the test code.
Because we don't have hashmaps or anything useful other than lists the
implementation is a bit clunky: we copy the parameter into the test
during litest_add_*, permutate it for our test list which gives us yet
another linked list C struct, and finally copy the actual value into
the test and test environment as it's executed. Not pretty, but it
works.
A few tests are switched as simple demonstration. The name of the
test has the parameters with their names and values appended now, e.g.:
"pointer:pointer_scroll_wheel_hires_send_only_lores:ms-surface-cover:axis:ABS_X"
"pointer:pointer_motion_relative_min_decel:mouse-roccat:direction:NW"
Filtering by parameters can be done via globs of their string
representation:
libinput-test-suite --filter-params="axis:ABS_*,enabled:true,number:10*"
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1109>
2024-12-22 00:06:19 +10:00
|
|
|
struct litest_test_parameters *params;
|
|
|
|
|
|
2024-10-12 10:31:42 +10:00
|
|
|
/* test function and corresponding setup/teardown, if any */
|
|
|
|
|
enum litest_runner_result (*func)(const struct litest_runner_test_env *);
|
|
|
|
|
void (*setup)(const struct litest_runner_test_description *);
|
|
|
|
|
void (*teardown)(const struct litest_runner_test_description *);
|
|
|
|
|
|
|
|
|
|
struct {
|
2025-07-01 16:30:11 +10:00
|
|
|
struct range range; /* The range this test applies to */
|
|
|
|
|
int signal; /* expected signal for fail tests */
|
2024-10-12 10:31:42 +10:00
|
|
|
} args;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct litest_runner;
|
|
|
|
|
|
2025-07-01 16:30:11 +10:00
|
|
|
struct litest_runner *
|
|
|
|
|
litest_runner_new(void);
|
2024-10-12 10:31:42 +10:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Default is nprocs * 2.
|
|
|
|
|
* Setting this to 0 means *no* forking. Setting this to 1 means only one test
|
|
|
|
|
* is run at a time but in a child process.
|
|
|
|
|
*/
|
2025-07-01 16:30:11 +10:00
|
|
|
void
|
|
|
|
|
litest_runner_set_num_parallel(struct litest_runner *runner, size_t num_jobs);
|
|
|
|
|
void
|
|
|
|
|
litest_runner_set_timeout(struct litest_runner *runner, unsigned int timeout);
|
|
|
|
|
void
|
|
|
|
|
litest_runner_set_verbose(struct litest_runner *runner, bool verbose);
|
|
|
|
|
void
|
|
|
|
|
litest_runner_set_use_colors(struct litest_runner *runner, bool use_colors);
|
|
|
|
|
void
|
|
|
|
|
litest_runner_set_exit_on_fail(struct litest_runner *runner, bool do_exit);
|
|
|
|
|
void
|
|
|
|
|
litest_runner_set_output_file(struct litest_runner *runner, FILE *fp);
|
|
|
|
|
void
|
|
|
|
|
litest_runner_add_test(struct litest_runner *runner,
|
|
|
|
|
const struct litest_runner_test_description *t);
|
|
|
|
|
enum litest_runner_result
|
|
|
|
|
litest_runner_run_tests(struct litest_runner *runner);
|
2024-10-12 10:31:42 +10:00
|
|
|
|
2024-10-16 18:31:35 +10:00
|
|
|
typedef enum litest_runner_result (*litest_runner_global_setup_func_t)(void *userdata);
|
|
|
|
|
typedef void (*litest_runner_global_teardown_func_t)(void *userdata);
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
litest_runner_set_setup_funcs(struct litest_runner *runner,
|
|
|
|
|
litest_runner_global_setup_func_t setup,
|
|
|
|
|
litest_runner_global_teardown_func_t teardown,
|
|
|
|
|
void *userdata);
|
|
|
|
|
|
2025-07-01 16:30:11 +10:00
|
|
|
void
|
|
|
|
|
litest_runner_destroy(struct litest_runner *runner);
|
2024-10-17 08:29:22 +10:00
|
|
|
|
2025-04-07 10:52:52 +10:00
|
|
|
DEFINE_DESTROY_CLEANUP_FUNC(litest_runner);
|
|
|
|
|
|
2024-10-17 08:29:22 +10:00
|
|
|
/*
|
|
|
|
|
* Function to call abort(). Depending on the number of forks permitted,
|
|
|
|
|
* this function may simply abort() or it may longjmp back out to collect
|
|
|
|
|
* errors from non-forking tests.
|
|
|
|
|
*/
|
2025-07-01 16:30:11 +10:00
|
|
|
__attribute__((noreturn)) void
|
|
|
|
|
litest_runner_abort(void);
|