static noinline int leaf_switch_2_none(unsigned long sp, bool fill, uint64_t *arg){ return __leaf_switch_none(2, fill);} /* * These are expected to fail for most configurations because neither * GCC nor Clang have a way to perform initialization of variables in * non-code areas (i.e. in a switch statement before the first "case"). * https://llvm.org/pr44916 */DEFINE_TEST_DRIVER(switch_1_none, uint64_t, SCALAR, ALWAYS_FAIL);DEFINE_TEST_DRIVER(switch_2_none, uint64_t, SCALAR, ALWAYS_FAIL); #define KUNIT_test_scalars(init) \ KUNIT_CASE(test_u8_ ## init), \ KUNIT_CASE(test_u16_ ## init), \ KUNIT_CASE(test_u32_ ## init), \ KUNIT_CASE(test_u64_ ## init), \ KUNIT_CASE(test_char_array_ ## init) #define KUNIT_test_structs(init) \ KUNIT_CASE(test_small_hole_ ## init), \ KUNIT_CASE(test_big_hole_ ## init), \ KUNIT_CASE(test_trailing_hole_ ## init),\ KUNIT_CASE(test_packed_ ## init) \ #define KUNIT_test_unions(init) \ KUNIT_CASE(test_same_sizes_ ## init), \ KUNIT_CASE(test_small_start_ ## init), \ KUNIT_CASE(test_small_end_ ## init) \ static struct kunit_case stackinit_test_cases[] = { /* These are explicitly initialized and should always pass. */ KUNIT_test_scalars(zero), KUNIT_test_structs(zero), KUNIT_test_structs(old_zero), KUNIT_test_unions(zero), KUNIT_test_unions(old_zero), /* Padding here appears to be accidentally always initialized? */ KUNIT_test_structs(dynamic_partial), KUNIT_test_structs(assigned_dynamic_partial), KUNIT_test_unions(dynamic_partial), KUNIT_test_unions(assigned_dynamic_partial), /* Padding initialization depends on compiler behaviors. */ KUNIT_test_structs(static_partial), KUNIT_test_structs(static_all), KUNIT_test_structs(dynamic_all), KUNIT_test_structs(runtime_partial), KUNIT_test_structs(runtime_all), KUNIT_test_structs(assigned_static_partial), KUNIT_test_structs(assigned_static_all), KUNIT_test_structs(assigned_dynamic_all), KUNIT_test_unions(static_partial), KUNIT_test_unions(static_all), KUNIT_test_unions(dynamic_all), KUNIT_test_unions(runtime_partial), KUNIT_test_unions(runtime_all), KUNIT_test_unions(assigned_static_partial), KUNIT_test_unions(assigned_static_all), KUNIT_test_unions(assigned_dynamic_all), /* Everything fails this since it effectively performs a memcpy(). */ KUNIT_test_structs(assigned_copy), KUNIT_test_unions(assigned_copy), /* STRUCTLEAK_BYREF_ALL should cover everything from here down. */ KUNIT_test_scalars(none), KUNIT_CASE(test_switch_1_none), KUNIT_CASE(test_switch_2_none), /* STRUCTLEAK_BYREF should cover from here down. */ KUNIT_test_structs(none), /* STRUCTLEAK will only cover this. */ KUNIT_CASE(test_user), {}}; static struct kunit_suite stackinit_test_suite = { .name = "stackinit", .test_cases = stackinit_test_cases,}; kunit_test_suites(&stackinit_test_suite); MODULE_DESCRIPTION("Test cases for compiler-based stack variable zeroing");MODULE_LICENSE("GPL");Lines 501–586 of 586. Previous lines
static noinline int leaf_switch_2_none(unsigned long sp, bool fill, uint64_t *arg) { return __leaf_switch_none(2, fill); } /* * These are expected to fail for most configurations because neither * GCC nor Clang have a way to perform initialization of variables in * non-code areas (i.e. in a switch statement before the first "case"). * https://llvm.org/pr44916 */ DEFINE_TEST_DRIVER(switch_1_none, uint64_t, SCALAR, ALWAYS_FAIL); DEFINE_TEST_DRIVER(switch_2_none, uint64_t, SCALAR, ALWAYS_FAIL); #define KUNIT_test_scalars(init) \ KUNIT_CASE(test_u8_ ## init), \ KUNIT_CASE(test_u16_ ## init), \ KUNIT_CASE(test_u32_ ## init), \ KUNIT_CASE(test_u64_ ## init), \ KUNIT_CASE(test_char_array_ ## init) #define KUNIT_test_structs(init) \ KUNIT_CASE(test_small_hole_ ## init), \ KUNIT_CASE(test_big_hole_ ## init), \ KUNIT_CASE(test_trailing_hole_ ## init),\ KUNIT_CASE(test_packed_ ## init) \ #define KUNIT_test_unions(init) \ KUNIT_CASE(test_same_sizes_ ## init), \ KUNIT_CASE(test_small_start_ ## init), \ KUNIT_CASE(test_small_end_ ## init) \ static struct kunit_case stackinit_test_cases[] = { /* These are explicitly initialized and should always pass. */ KUNIT_test_scalars(zero), KUNIT_test_structs(zero), KUNIT_test_structs(old_zero), KUNIT_test_unions(zero), KUNIT_test_unions(old_zero), /* Padding here appears to be accidentally always initialized? */ KUNIT_test_structs(dynamic_partial), KUNIT_test_structs(assigned_dynamic_partial), KUNIT_test_unions(dynamic_partial), KUNIT_test_unions(assigned_dynamic_partial), /* Padding initialization depends on compiler behaviors. */ KUNIT_test_structs(static_partial), KUNIT_test_structs(static_all), KUNIT_test_structs(dynamic_all), KUNIT_test_structs(runtime_partial), KUNIT_test_structs(runtime_all), KUNIT_test_structs(assigned_static_partial), KUNIT_test_structs(assigned_static_all), KUNIT_test_structs(assigned_dynamic_all), KUNIT_test_unions(static_partial), KUNIT_test_unions(static_all), KUNIT_test_unions(dynamic_all), KUNIT_test_unions(runtime_partial), KUNIT_test_unions(runtime_all), KUNIT_test_unions(assigned_static_partial), KUNIT_test_unions(assigned_static_all), KUNIT_test_unions(assigned_dynamic_all), /* Everything fails this since it effectively performs a memcpy(). */ KUNIT_test_structs(assigned_copy), KUNIT_test_unions(assigned_copy), /* STRUCTLEAK_BYREF_ALL should cover everything from here down. */ KUNIT_test_scalars(none), KUNIT_CASE(test_switch_1_none), KUNIT_CASE(test_switch_2_none), /* STRUCTLEAK_BYREF should cover from here down. */ KUNIT_test_structs(none), /* STRUCTLEAK will only cover this. */ KUNIT_CASE(test_user), {} }; static struct kunit_suite stackinit_test_suite = { .name = "stackinit", .test_cases = stackinit_test_cases, }; kunit_test_suites(&stackinit_test_suite); MODULE_DESCRIPTION("Test cases for compiler-based stack variable zeroing"); MODULE_LICENSE("GPL");