diff options
author | Arkadiusz Hiler <arkadiusz.hiler@intel.com> | 2020-05-04 14:26:23 +0300 |
---|---|---|
committer | Arkadiusz Hiler <arkadiusz.hiler@intel.com> | 2020-05-05 15:29:44 +0300 |
commit | c8c2e5ed5cd8e4b7a69a903f3f1653612086abcc (patch) | |
tree | 44e042e86ef00d5ef4a621665ad57666c1545156 /lib/tests | |
parent | 2caa386a222f27d346871e09d55bb5fbb15ee6ee (diff) |
lib/tests: Add tests for magic control blocks nesting
Cc: Petri Latvala <petri.latvala@intel.com>
Signed-off-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
Reviewed-by: Petri Latvala <petri.latvala@intel.com>
Diffstat (limited to 'lib/tests')
-rw-r--r-- | lib/tests/igt_nesting.c | 261 | ||||
-rw-r--r-- | lib/tests/igt_tests_common.h | 5 | ||||
-rw-r--r-- | lib/tests/meson.build | 1 |
3 files changed, 267 insertions, 0 deletions
diff --git a/lib/tests/igt_nesting.c b/lib/tests/igt_nesting.c new file mode 100644 index 00000000..de674b6b --- /dev/null +++ b/lib/tests/igt_nesting.c @@ -0,0 +1,261 @@ +/* + * Copyright © 2020 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 "igt_core.h" +#include "igt_tests_common.h" +#include "drmtest.h" + +char test[] = "test"; +char *fake_argv[] = { test }; +int fake_argc = ARRAY_SIZE(fake_argv); + +static void all_valid_simple_test(void) +{ + igt_simple_init(fake_argc, fake_argv); + + igt_skip("o:"); + igt_assert(false); + + igt_exit(); +} + +static void all_valid(void) +{ + igt_subtest_init(fake_argc, fake_argv); + + igt_fixture { + } + + igt_subtest_group { + igt_subtest_group { + } + + igt_fixture { + } + + igt_subtest("a") + { + igt_skip("o:\n"); + } + + igt_subtest("b") + { + igt_assert(false); + } + + igt_subtest_with_dynamic("c") { + igt_dynamic("d") + { + igt_skip("o:\n"); + } + + igt_dynamic("e") + { + igt_assert(false); + } + } + + igt_subtest_with_dynamic("f") { + igt_skip("o:\n"); + } + + igt_subtest_with_dynamic("g") { + } + } + + igt_exit(); +} + +static void invalid_subtest_in_simple_test(void) +{ + igt_simple_init(fake_argc, fake_argv); + + igt_subtest("a") { + } + + igt_exit(); +} + +static void invalid_subtest_group_in_simple_test(void) +{ + igt_simple_init(fake_argc, fake_argv); + + igt_subtest_group { + } + + igt_exit(); +} + +static void invalid_subtest_with_dynamic_in_simple_test(void) +{ + igt_simple_init(fake_argc, fake_argv); + + igt_subtest_with_dynamic("a") { + } + + igt_exit(); +} + +static void invalid_dynamic_in_simple_test(void) +{ + igt_simple_init(fake_argc, fake_argv); + + igt_dynamic("a") { + } + + igt_exit(); +} + +static void invalid_fixture_in_fixture(void) +{ + igt_subtest_init(fake_argc, fake_argv); + + igt_fixture { + igt_fixture { + } + } + + igt_exit(); +} + +static void invalid_subtest_in_subtest(void) +{ + igt_subtest_init(fake_argc, fake_argv); + + igt_subtest("a") { + igt_subtest("b") { + } + } + + igt_exit(); +} + +static void invalid_top_level_dynamic(void) +{ + igt_subtest_init(fake_argc, fake_argv); + + igt_dynamic("a") { + } + + igt_exit(); +} + +static void invalid_dynamic_in_regular_subtest(void) +{ + igt_subtest_init(fake_argc, fake_argv); + + igt_subtest("a") { + igt_dynamic("b") { + } + } + + igt_exit(); +} + +static void invalid_fixture_in_subtest(void) +{ + igt_subtest_init(fake_argc, fake_argv); + + igt_subtest("a") { + igt_fixture { + } + } + + igt_exit(); +} + +static void invalid_top_level_skip(void) +{ + igt_subtest_init(fake_argc, fake_argv); + + igt_skip("o:\n"); + + igt_exit(); +} + +static void invalid_top_level_assert(void) +{ + igt_subtest_init(fake_argc, fake_argv); + + igt_assert(false); + + igt_exit(); +} + +static void invalid_dynamic_in_dynamic(void) +{ + igt_subtest_init(fake_argc, fake_argv); + + igt_subtest_with_dynamic("a") { + igt_dynamic("b") { + igt_dynamic("c") { + } + } + } + + igt_exit(); +} + +typedef void (*fork_fun)(void); + +int main(int argc, char **argv) +{ + int status; + + /* test the invalid nesting scenarios */ { + fork_fun should_sigabort[] = { + invalid_subtest_in_simple_test, + invalid_subtest_group_in_simple_test, + invalid_subtest_with_dynamic_in_simple_test, + invalid_dynamic_in_simple_test, + invalid_fixture_in_fixture, + invalid_subtest_in_subtest, + invalid_top_level_dynamic, + invalid_dynamic_in_regular_subtest, + invalid_fixture_in_subtest, + invalid_top_level_skip, + invalid_top_level_assert, + invalid_dynamic_in_dynamic, + }; + + for (int i = 0; i < ARRAY_SIZE(should_sigabort); ++i) { + status = do_fork(should_sigabort[i]); + internal_assert_wsignaled(status, SIGABRT); + } + } + + /* test the valid nesting scenarios */ { + fork_fun should_not_signal[] = { + all_valid_simple_test, + all_valid, + }; + + for (int i = 0; i < ARRAY_SIZE(should_not_signal); ++i) { + status = do_fork(should_not_signal[i]); + internal_assert_not_wsignaled(status); + } + } + + return 0; +} diff --git a/lib/tests/igt_tests_common.h b/lib/tests/igt_tests_common.h index f285d657..fa8ad920 100644 --- a/lib/tests/igt_tests_common.h +++ b/lib/tests/igt_tests_common.h @@ -51,6 +51,11 @@ static inline void internal_assert_wsignaled(int wstatus, int signal) WTERMSIG(wstatus) == signal); } +static inline void internal_assert_not_wsignaled(int wstatus) +{ + internal_assert(!WIFSIGNALED(wstatus)); +} + static inline int do_fork(void (*test_to_run)(void)) { int pid, status; diff --git a/lib/tests/meson.build b/lib/tests/meson.build index 22aa19da..47ef303a 100644 --- a/lib/tests/meson.build +++ b/lib/tests/meson.build @@ -12,6 +12,7 @@ lib_tests = [ 'igt_fork_helper', 'igt_list_only', 'igt_invalid_subtest_name', + 'igt_nesting', 'igt_no_exit', 'igt_segfault', 'igt_simulation', |