mirror of
https://gitlab.freedesktop.org/wayland/weston
synced 2024-10-01 19:38:34 +00:00
tests: add helpers to create unique filenames
With such helpers we are able to create unique filenames for a test program, a fixture or specific test cases. This help us to avoid accidents related to using files from other tests or overriding them. Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
This commit is contained in:
parent
ac3e416402
commit
d29f904bec
|
@ -1184,6 +1184,99 @@ image_filename(const char *basename)
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Helper to create filenames for test programs.
|
||||||
|
*
|
||||||
|
* \param test_program The test program name.
|
||||||
|
* \param suffix Arbitrary suffix to append after the test program name.
|
||||||
|
* Optional, NULL is valid as well.
|
||||||
|
* \param file_ext The file extension (without '.').
|
||||||
|
* \return The ICC filename.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
output_filename_for_test_program(const char *test_program, const char *suffix,
|
||||||
|
const char *file_ext)
|
||||||
|
{
|
||||||
|
char *filename;
|
||||||
|
|
||||||
|
assert(test_program);
|
||||||
|
assert(file_ext);
|
||||||
|
|
||||||
|
if (suffix)
|
||||||
|
str_printf(&filename, "%s/%s-%s.%s", output_path(), test_program,
|
||||||
|
suffix, file_ext);
|
||||||
|
else
|
||||||
|
str_printf(&filename, "%s/%s.%s", output_path(), test_program,
|
||||||
|
file_ext);
|
||||||
|
|
||||||
|
assert(filename);
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Helper to create filenames for fixtures.
|
||||||
|
*
|
||||||
|
* \param test_program The test program name.
|
||||||
|
* \param harness The test harness, from which we get the fixture number.
|
||||||
|
* \param suffix Arbitrary suffix to append after the fixture number. Optional,
|
||||||
|
* NULL is valid as well.
|
||||||
|
* \param file_ext The file extension (without '.').
|
||||||
|
* \return The ICC filename.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
output_filename_for_fixture(const char *test_program,
|
||||||
|
struct weston_test_harness *harness,
|
||||||
|
const char *suffix, const char *file_ext)
|
||||||
|
{
|
||||||
|
int fixture_number;
|
||||||
|
char *filename;
|
||||||
|
|
||||||
|
assert(test_program);
|
||||||
|
assert(harness);
|
||||||
|
assert(file_ext);
|
||||||
|
|
||||||
|
fixture_number = get_test_fixture_number_from_harness(harness);
|
||||||
|
|
||||||
|
if (suffix)
|
||||||
|
str_printf(&filename, "%s/%s-f%02d-%s.%s", output_path(), test_program,
|
||||||
|
fixture_number, suffix, file_ext);
|
||||||
|
else
|
||||||
|
str_printf(&filename, "%s/%s-f%02d.%s", output_path(), test_program,
|
||||||
|
fixture_number, file_ext);
|
||||||
|
|
||||||
|
assert(filename);
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Helper to create filenames for test cases.
|
||||||
|
*
|
||||||
|
* \param suffix Arbitrary suffix to append after the test case name. Optional,
|
||||||
|
* NULL is valid as well.
|
||||||
|
* \param seq_number To differentiate filenames created from a loop. Simply use
|
||||||
|
* 0 if not in a loop.
|
||||||
|
* \param file_ext The file extension (without '.').
|
||||||
|
* \return The ICC filename.
|
||||||
|
*
|
||||||
|
* This is only usable from code paths inside TEST(), TEST_P(), PLUGIN_TEST()
|
||||||
|
* etc. defined functions.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
output_filename_for_test_case(const char *suffix, uint32_t seq_number,
|
||||||
|
const char *file_ext)
|
||||||
|
{
|
||||||
|
char *filename;
|
||||||
|
|
||||||
|
assert(file_ext);
|
||||||
|
|
||||||
|
if (suffix)
|
||||||
|
str_printf(&filename, "%s/%s-%s-%02d.%s", output_path(), get_test_name(),
|
||||||
|
suffix, seq_number, file_ext);
|
||||||
|
else
|
||||||
|
str_printf(&filename, "%s/%s-%02d.%s", output_path(), get_test_name(),
|
||||||
|
seq_number, file_ext);
|
||||||
|
|
||||||
|
assert(filename);
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
/** Open a writable file
|
/** Open a writable file
|
||||||
*
|
*
|
||||||
* \param suffix Custom file name suffix.
|
* \param suffix Custom file name suffix.
|
||||||
|
|
|
@ -258,6 +258,19 @@ screenshot_reference_filename(const char *basename, uint32_t seq);
|
||||||
char *
|
char *
|
||||||
image_filename(const char *basename);
|
image_filename(const char *basename);
|
||||||
|
|
||||||
|
char *
|
||||||
|
output_filename_for_test_program(const char *test_program, const char *suffix,
|
||||||
|
const char *file_ext);
|
||||||
|
|
||||||
|
char *
|
||||||
|
output_filename_for_fixture(const char *test_program,
|
||||||
|
struct weston_test_harness *harness,
|
||||||
|
const char *suffix, const char *file_ext);
|
||||||
|
|
||||||
|
char *
|
||||||
|
output_filename_for_test_case(const char *suffix, uint32_t seq_number,
|
||||||
|
const char *file_ext);
|
||||||
|
|
||||||
FILE *
|
FILE *
|
||||||
fopen_dump_file(const char *suffix);
|
fopen_dump_file(const char *suffix);
|
||||||
|
|
||||||
|
|
|
@ -212,6 +212,22 @@ struct weston_test_harness {
|
||||||
struct wet_testsuite_data data;
|
struct wet_testsuite_data data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Get the current fixture number from test harness
|
||||||
|
*
|
||||||
|
* \param harness The test harness.
|
||||||
|
*
|
||||||
|
* Similar to get_test_fixture_index(), but get the fixture number (index + 1)
|
||||||
|
* directly from the test harness. Can be called from fixture_setup() functions.
|
||||||
|
*
|
||||||
|
* \sa DECLARE_FIXTURE_SETUP(), DECLARE_FIXTURE_SETUP_WITH_ARG()
|
||||||
|
* \ingroup testharness
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
get_test_fixture_number_from_harness(struct weston_test_harness *harness)
|
||||||
|
{
|
||||||
|
return harness->data.fixture_iteration + 1;
|
||||||
|
}
|
||||||
|
|
||||||
typedef void (*weston_test_cb)(struct wet_testsuite_data *suite_data,
|
typedef void (*weston_test_cb)(struct wet_testsuite_data *suite_data,
|
||||||
const struct weston_test_entry *t,
|
const struct weston_test_entry *t,
|
||||||
const void *test_data,
|
const void *test_data,
|
||||||
|
|
|
@ -41,6 +41,12 @@
|
||||||
#error "Tests must not be built with NDEBUG defined, they rely on assert()."
|
#error "Tests must not be built with NDEBUG defined, they rely on assert()."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/** Test harness context
|
||||||
|
*
|
||||||
|
* \ingroup testharness
|
||||||
|
*/
|
||||||
|
struct weston_test_harness;
|
||||||
|
|
||||||
/** Test program entry
|
/** Test program entry
|
||||||
*
|
*
|
||||||
* Each invocation of TEST(), TEST_P(), or PLUGIN_TEST() will create one
|
* Each invocation of TEST(), TEST_P(), or PLUGIN_TEST() will create one
|
||||||
|
@ -163,6 +169,9 @@ get_test_name(void);
|
||||||
int
|
int
|
||||||
get_test_fixture_index(void);
|
get_test_fixture_index(void);
|
||||||
|
|
||||||
|
int
|
||||||
|
get_test_fixture_number_from_harness(struct weston_test_harness *harness);
|
||||||
|
|
||||||
/** Metadata for fixture setup array elements
|
/** Metadata for fixture setup array elements
|
||||||
*
|
*
|
||||||
* Every type used as a fixture setup array's elements needs one member of
|
* Every type used as a fixture setup array's elements needs one member of
|
||||||
|
@ -194,12 +203,6 @@ struct fixture_setup_array {
|
||||||
const struct fixture_setup_array *
|
const struct fixture_setup_array *
|
||||||
fixture_setup_array_get_(void);
|
fixture_setup_array_get_(void);
|
||||||
|
|
||||||
/** Test harness context
|
|
||||||
*
|
|
||||||
* \ingroup testharness
|
|
||||||
*/
|
|
||||||
struct weston_test_harness;
|
|
||||||
|
|
||||||
enum test_result_code
|
enum test_result_code
|
||||||
fixture_setup_run_(struct weston_test_harness *harness, const void *arg_);
|
fixture_setup_run_(struct weston_test_harness *harness, const void *arg_);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue