Commit 2459b80b authored by Daniel Vetter's avatar Daniel Vetter Committed by Petri Latvala

lib: Add igt_can_fail()

Useful to make sure folks use library helpers correctly.
Signed-off-by: Daniel Vetter's avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Petri Latvala's avatarPetri Latvala <petri.latvala@intel.com>
parent 0c514b0c
......@@ -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
......
......@@ -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,
......
......@@ -14,3 +14,5 @@ igt_stats
igt_subtest_group
igt_timeout
igt_hdmi_inject
igt_can_fail
igt_can_fail_simple
......@@ -14,6 +14,8 @@ check_prog_list = \
igt_assert \
igt_exit_handler \
igt_hdmi_inject \
igt_can_fail \
igt_can_fail_simple \
$(NULL)
TESTS = \
......
/*
* 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);
}
/*
* 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());
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment