Skip to content

Commit 0867ff3

Browse files
nbdd0121BennoLossin
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 <[email protected]> Reviewed-by: Benno Lossin <[email protected]> Signed-off-by: Gary Guo <[email protected]>
1 parent c852a77 commit 0867ff3

File tree

2 files changed

+3
-27
lines changed

2 files changed

+3
-27
lines changed

rust/kernel/kunit.rs

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

194194
/// Represents an individual test case.
195-
///
196-
/// The [`kunit_unsafe_test_suite!`] macro expects a NULL-terminated list of valid test cases.
197-
/// Use [`kunit_case_null`] to generate such a delimiter.
198195
#[doc(hidden)]
199196
pub const fn kunit_case(
200197
name: &'static kernel::str::CStr,
@@ -215,27 +212,6 @@ pub const fn kunit_case(
215212
}
216213
}
217214

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

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(::kernel::c_str!("foo"), kunit_rust_wrapper_foo),
7676
// ::kernel::kunit::kunit_case(::kernel::c_str!("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)