[Intel-gfx] [PATCH i-g-t 1/4] lib: Add igt_can_fail()

Petri Latvala petri.latvala at intel.com
Mon Aug 14 09:48:54 UTC 2017


The series LGTM.

Can you resend the whole series and slap a revert of
1385b31d9371fae02af2fd8adb0d9ea86a5bb0f2 at the end? With a pass of
CI on such a bunch this series is

Reviewed-by: Petri Latvala <petri.latvala at intel.com>


On Mon, Aug 14, 2017 at 11:32:04AM +0200, Daniel Vetter wrote:
> Useful to make sure folks use library helpers correctly.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
> ---
>  lib/igt_core.c                  | 20 +++++++++++++++++--
>  lib/igt_core.h                  |  2 ++
>  lib/tests/.gitignore            |  2 ++
>  lib/tests/Makefile.sources      |  2 ++
>  lib/tests/igt_can_fail.c        | 44 +++++++++++++++++++++++++++++++++++++++++
>  lib/tests/igt_can_fail_simple.c | 32 ++++++++++++++++++++++++++++++
>  6 files changed, 100 insertions(+), 2 deletions(-)
>  create mode 100644 lib/tests/igt_can_fail.c
>  create mode 100644 lib/tests/igt_can_fail_simple.c
> 
> diff --git a/lib/igt_core.c b/lib/igt_core.c
> index c0488e944cec..9eb99eda0244 100644
> --- a/lib/igt_core.c
> +++ b/lib/igt_core.c
> @@ -1170,7 +1170,7 @@ void igt_fail(int exitcode)
>  		else
>  			exit_subtest("FAIL");
>  	} else {
> -		assert(!test_with_subtests || in_fixture);
> +		assert(igt_can_fail());
>  
>  		if (in_fixture) {
>  			skip_subtests_henceforth = FAIL;
> @@ -1181,6 +1181,22 @@ void igt_fail(int exitcode)
>  	}
>  }
>  
> +/**
> + * igt_can_fail:
> + *
> + * Returns true if called from either an #igt_fixture, #igt_subtest or a
> + * testcase without subtests, i.e. #igt_simple_main. Returns false otherwise. In
> + * other words, it checks whether it's legal to call igt_fail(), igt_skip_on()
> + * and all the convenience macros build around those.
> + *
> + * This is useful to make sure that library code is called from the right
> + * places.
> + */
> +bool igt_can_fail(void)
> +{
> +	return !test_with_subtests || in_fixture || in_subtest;
> +}
> +
>  static bool run_under_gdb(void)
>  {
>  	char buf[1024];
> @@ -2015,7 +2031,7 @@ void igt_skip_on_simulation(void)
>  	if (igt_only_list_subtests())
>  		return;
>  
> -	if (!in_fixture && !in_subtest) {
> +	if (!igt_can_fail()) {
>  		igt_fixture
>  			igt_require(!igt_run_in_simulation());
>  	} else
> diff --git a/lib/igt_core.h b/lib/igt_core.h
> index 1619a9d65400..619c45c6df90 100644
> --- a/lib/igt_core.h
> +++ b/lib/igt_core.h
> @@ -306,6 +306,8 @@ void __igt_skip_check(const char *file, const int line,
>  	__igt_skip_check(__FILE__, __LINE__, __func__, E, F)
>  void igt_success(void);
>  
> +bool igt_can_fail(void);
> +
>  void igt_fail(int exitcode) __attribute__((noreturn));
>  __attribute__((format(printf, 6, 7)))
>  void __igt_fail_assert(const char *domain, const char *file,
> diff --git a/lib/tests/.gitignore b/lib/tests/.gitignore
> index 12a3712c20de..ae11dd47af8c 100644
> --- a/lib/tests/.gitignore
> +++ b/lib/tests/.gitignore
> @@ -14,3 +14,5 @@ igt_stats
>  igt_subtest_group
>  igt_timeout
>  igt_hdmi_inject
> +igt_can_fail
> +igt_can_fail_simple
> diff --git a/lib/tests/Makefile.sources b/lib/tests/Makefile.sources
> index 4cfc0a53aebb..8d1a8dea8263 100644
> --- a/lib/tests/Makefile.sources
> +++ b/lib/tests/Makefile.sources
> @@ -14,6 +14,8 @@ check_prog_list = \
>  	igt_assert \
>  	igt_exit_handler \
>  	igt_hdmi_inject \
> +	igt_can_fail \
> +	igt_can_fail_simple \
>  	$(NULL)
>  
>  TESTS = \
> diff --git a/lib/tests/igt_can_fail.c b/lib/tests/igt_can_fail.c
> new file mode 100644
> index 000000000000..566682422b64
> --- /dev/null
> +++ b/lib/tests/igt_can_fail.c
> @@ -0,0 +1,44 @@
> +/*
> + * Copyright © 2017 Intel Corporation
> + *
> + * 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.
> + *
> + */
> +
> +#include <assert.h>
> +#include "igt_core.h"
> +
> +
> +igt_main
> +{
> +	assert(igt_can_fail() == false);
> +
> +	igt_fixture {
> +		assert(igt_can_fail());
> +	}
> +
> +	assert(igt_can_fail() == false);
> +
> +	igt_subtest("subtest") {
> +		assert(igt_can_fail());
> +	}
> +
> +	assert(igt_can_fail() == false);
> +}
> diff --git a/lib/tests/igt_can_fail_simple.c b/lib/tests/igt_can_fail_simple.c
> new file mode 100644
> index 000000000000..0d9f6dd4076c
> --- /dev/null
> +++ b/lib/tests/igt_can_fail_simple.c
> @@ -0,0 +1,32 @@
> +/*
> + * Copyright © 2017 Intel Corporation
> + *
> + * 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.
> + *
> + */
> +
> +#include <assert.h>
> +#include "igt_core.h"
> +
> +
> +igt_simple_main
> +{
> +	assert(igt_can_fail());
> +}
> -- 
> 2.5.5
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx


More information about the Intel-gfx mailing list