Skip to content

Commit be97f3c

Browse files
nbdd0121ojeda
authored andcommitted
rust: kunit: use pin_init::zeroed instead of custom null value
The last null element can be created (constly) using `pin_init::zeroed`, so prefer to use it instead of adding a custom way of building it. Reviewed-by: Tamir Duberstein <tamird@gmail.com> Reviewed-by: Benno Lossin <lossin@kernel.org> Signed-off-by: Gary Guo <gary@garyguo.net> Reviewed-by: David Gow <davidgow@google.com> Link: https://patch.msgid.link/20260112170919.1888584-12-gary@kernel.org Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent d421fa4 commit be97f3c

2 files changed

Lines changed: 3 additions & 27 deletions

File tree

rust/kernel/kunit.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@ pub fn is_test_result_ok(t: impl TestResult) -> bool {
189189
}
190190

191191
/// Represents an individual test case.
192-
///
193-
/// The [`kunit_unsafe_test_suite!`] macro expects a `NULL`-terminated list of valid test cases.
194-
/// Use [`kunit_case_null`] to generate such a delimiter.
195192
#[doc(hidden)]
196193
pub const fn kunit_case(
197194
name: &'static kernel::str::CStr,
@@ -212,27 +209,6 @@ pub const fn kunit_case(
212209
}
213210
}
214211

215-
/// Represents the `NULL` test case delimiter.
216-
///
217-
/// The [`kunit_unsafe_test_suite!`] macro expects a `NULL`-terminated list of test cases. This
218-
/// function returns such a delimiter.
219-
#[doc(hidden)]
220-
pub const fn kunit_case_null() -> kernel::bindings::kunit_case {
221-
kernel::bindings::kunit_case {
222-
run_case: None,
223-
name: core::ptr::null_mut(),
224-
generate_params: None,
225-
attr: kernel::bindings::kunit_attributes {
226-
speed: kernel::bindings::kunit_speed_KUNIT_SPEED_NORMAL,
227-
},
228-
status: kernel::bindings::kunit_status_KUNIT_SUCCESS,
229-
module_name: core::ptr::null_mut(),
230-
log: core::ptr::null_mut(),
231-
param_init: None,
232-
param_exit: None,
233-
}
234-
}
235-
236212
/// Registers a KUnit test suite.
237213
///
238214
/// # Safety
@@ -251,7 +227,7 @@ pub const fn kunit_case_null() -> kernel::bindings::kunit_case {
251227
///
252228
/// static mut KUNIT_TEST_CASES: [kernel::bindings::kunit_case; 2] = [
253229
/// kernel::kunit::kunit_case(c"name", test_fn),
254-
/// kernel::kunit::kunit_case_null(),
230+
/// pin_init::zeroed(),
255231
/// ];
256232
/// kernel::kunit_unsafe_test_suite!(suite_name, KUNIT_TEST_CASES);
257233
/// ```

rust/macros/kunit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub(crate) fn kunit_tests(test_suite: Ident, mut module: ItemMod) -> Result<Toke
7474
// static mut TEST_CASES: [::kernel::bindings::kunit_case; 3] = [
7575
// ::kernel::kunit::kunit_case(c"foo", kunit_rust_wrapper_foo),
7676
// ::kernel::kunit::kunit_case(c"bar", kunit_rust_wrapper_bar),
77-
// ::kernel::kunit::kunit_case_null(),
77+
// ::pin_init::zeroed(),
7878
// ];
7979
//
8080
// ::kernel::kunit_unsafe_test_suite!(kunit_test_suit_name, TEST_CASES);
@@ -159,7 +159,7 @@ pub(crate) fn kunit_tests(test_suite: Ident, mut module: ItemMod) -> Result<Toke
159159
processed_items.push(parse_quote! {
160160
static mut TEST_CASES: [::kernel::bindings::kunit_case; #num_tests_plus_1] = [
161161
#(#test_cases,)*
162-
::kernel::kunit::kunit_case_null(),
162+
::pin_init::zeroed(),
163163
];
164164
});
165165
processed_items.push(parse_quote! {

0 commit comments

Comments
 (0)