Re: [PATCH] selftests: sync: Skip the test if kernel support is not found
From: Gustavo Padovan
Date: Wed May 31 2017 - 10:44:24 EST
Hi Michael,
On 05/31/2017 07:40 PM, Michael Ellerman wrote:
> The "Sync framework" test doesn't work if the kernel has no support,
> obviously. Rather than reporting a failure, check for the kernel support
> by looking for /sys/kernel/debug/sync/sw_sync, and if not found skip the
> test.
>
> Signed-off-by: Michael Ellerman <mpe@xxxxxxxxxxxxxx>
> ---
> tools/testing/selftests/sync/sync_test.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/tools/testing/selftests/sync/sync_test.c b/tools/testing/selftests/sync/sync_test.c
> index 9ea08d9f0b13..62fa666e501a 100644
> --- a/tools/testing/selftests/sync/sync_test.c
> +++ b/tools/testing/selftests/sync/sync_test.c
> @@ -29,6 +29,7 @@
> #include <unistd.h>
> #include <stdlib.h>
> #include <sys/types.h>
> +#include <sys/stat.h>
> #include <sys/wait.h>
>
> #include "synctest.h"
> @@ -52,10 +53,22 @@ static int run_test(int (*test)(void), char *name)
> exit(test());
> }
>
> +static int sync_api_supported(void)
> +{
> + struct stat sbuf;
> +
> + return 0 == stat("/sys/kernel/debug/sync/sw_sync", &sbuf);
> +}
> +
> int main(void)
> {
> int err = 0;
>
> + if (!sync_api_supported()) {
> + printf("SKIP: Sync framework not supported by kernel\n");
> + return 0;
> + }
> +
> printf("[RUN]\tTesting sync framework\n");
>
> err += RUN_TEST(test_alloc_timeline);
>
Reviewed-by: Gustavo Padovan <gustavo.padovan@xxxxxxxxxxxxx>
--
Gustavo Padovan
Collabora Ltd.