diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-12-23 17:49:57 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-12-23 18:02:18 +0100 |
commit | 8161f6086e56dc494a976a6eba14d3d4286ef6a0 (patch) | |
tree | 0d9cb3605e25c0b3505a324be754414d62f04162 /src/test/test-log.c | |
parent | log: introduce a knob to make assert_return() critical (diff) | |
download | systemd-8161f6086e56dc494a976a6eba14d3d4286ef6a0.tar.xz systemd-8161f6086e56dc494a976a6eba14d3d4286ef6a0.zip |
test: make assert_return() critical by default on fuzzer and unit tests
Several test cases intentionally trigger assert_return(). So, to avoid
the entire test fails, this introduces several macros that tentatively
make assert_return() not critical.
Diffstat (limited to 'src/test/test-log.c')
-rw-r--r-- | src/test/test-log.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/test/test-log.c b/src/test/test-log.c index b5ba67b74b..97eb5e0199 100644 --- a/src/test/test-log.c +++ b/src/test/test-log.c @@ -22,6 +22,26 @@ assert_cc(!IS_SYNTHETIC_ERRNO(0)); #define X100(x) X10(X10(x)) #define X1000(x) X100(X10(x)) +static int fail_with_EINVAL(void) { + assert_return(false, -EINVAL); + return 0; +} + +static void test_assert_return_is_critical(void) { + SAVE_ASSERT_RETURN_IS_CRITICAL; + + log_set_assert_return_is_critical(false); + assert_se(fail_with_EINVAL() == -EINVAL); + + log_set_assert_return_is_critical(true); + ASSERT_RETURN_IS_CRITICAL(false, assert_se(fail_with_EINVAL() == -EINVAL)); + assert_se(log_get_assert_return_is_critical() == true); + ASSERT_RETURN_EXPECTED(assert_se(fail_with_EINVAL() == -EINVAL)); + assert_se(log_get_assert_return_is_critical() == true); + ASSERT_RETURN_EXPECTED_SE(fail_with_EINVAL() == -EINVAL); + assert_se(log_get_assert_return_is_critical() == true); +} + static void test_file(void) { log_info("__FILE__: %s", __FILE__); log_info("RELATIVE_SOURCE_PATH: %s", RELATIVE_SOURCE_PATH); @@ -207,6 +227,7 @@ static void test_log_prefix(void) { int main(int argc, char* argv[]) { test_setup_logging(LOG_DEBUG); + test_assert_return_is_critical(); test_file(); assert_se(log_info_errno(SYNTHETIC_ERRNO(EUCLEAN), "foo") == -EUCLEAN); |