[PATCH weston 4/7] tests: implement get_test_name()
Quentin Glidic
sardemff7+wayland at sardemff7.net
Tue Feb 7 12:06:54 UTC 2017
On 07/02/2017 12:34, Pekka Paalanen wrote:
> On Tue, 7 Feb 2017 11:39:38 +0100
> Quentin Glidic <sardemff7+wayland at sardemff7.net> wrote:
>
>> On 27/01/2017 17:30, Emilio Pozuelo Monfort wrote:
>>> From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
>>>
>>> Screenshot tests often want to use the test name for writing out images.
>>> This is a helper to get the test name without writing it multiple times
>>> in the source.
>>>
>>> Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
>>> Reviewed-by: Emilio Pozuelo Monfort <emilio.pozuelo at collabora.co.uk>
>>> ---
>>> tests/weston-test-runner.c | 21 +++++++++++++++++++--
>>> tests/weston-test-runner.h | 12 ++++++++++++
>>> 2 files changed, 31 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/tests/weston-test-runner.c b/tests/weston-test-runner.c
>>> index b1e89bc2..f197265d 100644
>>> --- a/tests/weston-test-runner.c
>>> +++ b/tests/weston-test-runner.c
>>> @@ -42,6 +42,14 @@ char __attribute__((weak)) *server_parameters="";
>>>
>>> extern const struct weston_test __start_test_section, __stop_test_section;
>>>
>>> +static const char *test_name_;
>>> +
>>> +const char *
>>> +get_test_name(void)
>>> +{
>>> + return test_name_;
>>> +}
>>> +
>>> static const struct weston_test *
>>> find_test(const char *name)
>>> {
>>> @@ -55,8 +63,17 @@ find_test(const char *name)
>>> }
>>>
>>> static void
>>> -run_test(const struct weston_test *t, void *data)
>>> +run_test(const struct weston_test *t, void *data, int iteration)
>>> {
>>> + char str[512];
>>
>> Maybe a little comment that this will always be around because this
>> function never returns? (The "never returns" comment is easily missed
>> since it’s in the caller.)
>>
>
> Mm, the only way out from the function is exit() and it's a small
> function.
>
>>
>>> +
>>> + if (data) {
>>
>> Isn’t that supposed to be testing "iteration" instead?
>> With that fixed (or explained):
>> Reviewed-by: Quentin Glidic <sardemff7+git at sardemff7.net>
>
> The caller exec_and_report_test() already uses 'data' as the condition
> for an iterated test. 'iteration' OTOH will always be a valid index so
> it cannot be used to detect a (non-)iterated test.
>
> Do you want some comments added in the code or commit message?
Yeah, the less obscure the test code is, the better, I think. :-)
Thanks,
>>> + snprintf(str, sizeof(str), "%s[%d]", t->name, iteration);
>>> + test_name_ = str;
>>> + } else {
>>> + test_name_ = t->name;
>>> + }
>>> +
>>> t->run(data);
>>> exit(EXIT_SUCCESS);
>>> }
>>> @@ -83,7 +100,7 @@ exec_and_report_test(const struct weston_test *t, void *test_data, int iteration
>>> assert(pid >= 0);
>>>
>>> if (pid == 0)
>>> - run_test(t, test_data); /* never returns */
>>> + run_test(t, test_data, iteration); /* never returns */
>>>
>>> if (waitid(P_ALL, 0, &info, WEXITED)) {
>>> fprintf(stderr, "waitid failed: %m\n");
>>> diff --git a/tests/weston-test-runner.h b/tests/weston-test-runner.h
>>> index a4436919..21a059d6 100644
>>> --- a/tests/weston-test-runner.h
>>> +++ b/tests/weston-test-runner.h
>>> @@ -80,4 +80,16 @@ struct weston_test {
>>> #define TEST_P(name, data) ARG_TEST(name, 0, data)
>>> #define FAIL_TEST_P(name, data) ARG_TEST(name, 1, data)
>>>
>>> +/**
>>> + * Get the test name string with counter
>>> + *
>>> + * \return The test name. For an iterated test, e.g. defined with TEST_P(),
>>> + * the name has a '[%d]' suffix to indicate the iteration.
>>> + *
>>> + * This is only usable from code paths inside TEST(), TEST_P(), etc.
>>> + * defined functions.
>>> + */
>>> +const char *
>>> +get_test_name(void);
>>> +
>>> #endif
>>>
>>
>>
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
--
Quentin “Sardem FF7” Glidic
More information about the wayland-devel
mailing list