Skip to content

Commit a9dc8d0

Browse files
committed
fortify: Allow KUnit test to build without FORTIFY
In order for CI systems to notice all the skipped tests related to CONFIG_FORTIFY_SOURCE, allow the FORTIFY_SOURCE KUnit tests to build with or without CONFIG_FORTIFY_SOURCE. Signed-off-by: Kees Cook <[email protected]>
1 parent 4d90609 commit a9dc8d0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/Kconfig.debug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2645,7 +2645,7 @@ config STACKINIT_KUNIT_TEST
26452645

26462646
config FORTIFY_KUNIT_TEST
26472647
tristate "Test fortified str*() and mem*() function internals at runtime" if !KUNIT_ALL_TESTS
2648-
depends on KUNIT && FORTIFY_SOURCE
2648+
depends on KUNIT
26492649
default KUNIT_ALL_TESTS
26502650
help
26512651
Builds unit tests for checking internals of FORTIFY_SOURCE as used

lib/fortify_kunit.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ static const char array_of_10[] = "this is 10";
2525
static const char *ptr_of_11 = "this is 11!";
2626
static char array_unknown[] = "compiler thinks I might change";
2727

28+
/* Handle being built without CONFIG_FORTIFY_SOURCE */
29+
#ifndef __compiletime_strlen
30+
# define __compiletime_strlen __builtin_strlen
31+
#endif
32+
2833
static void known_sizes_test(struct kunit *test)
2934
{
3035
KUNIT_EXPECT_EQ(test, __compiletime_strlen("88888888"), 8);
@@ -307,6 +312,14 @@ DEFINE_ALLOC_SIZE_TEST_PAIR(kvmalloc)
307312
} while (0)
308313
DEFINE_ALLOC_SIZE_TEST_PAIR(devm_kmalloc)
309314

315+
static int fortify_test_init(struct kunit *test)
316+
{
317+
if (!IS_ENABLED(CONFIG_FORTIFY_SOURCE))
318+
kunit_skip(test, "Not built with CONFIG_FORTIFY_SOURCE=y");
319+
320+
return 0;
321+
}
322+
310323
static struct kunit_case fortify_test_cases[] = {
311324
KUNIT_CASE(known_sizes_test),
312325
KUNIT_CASE(control_flow_split_test),
@@ -323,6 +336,7 @@ static struct kunit_case fortify_test_cases[] = {
323336

324337
static struct kunit_suite fortify_test_suite = {
325338
.name = "fortify",
339+
.init = fortify_test_init,
326340
.test_cases = fortify_test_cases,
327341
};
328342

0 commit comments

Comments
 (0)