Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: str: convert `rusttest` tests into KUnit

In general, we should aim to test as much as possible within the actual
kernel, and not in the build host.

Thus convert these `rusttest` tests into KUnit tests.

Reviewed-by: David Gow <davidgow@google.com>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Link: https://lore.kernel.org/r/20250502215133.1923676-5-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

+4 -6
+4 -6
rust/kernel/str.rs
··· 6 6 use core::fmt::{self, Write}; 7 7 use core::ops::{self, Deref, DerefMut, Index}; 8 8 9 - use crate::error::{code::*, Error}; 9 + use crate::prelude::*; 10 10 11 11 /// Byte string without UTF-8 validity guarantee. 12 12 #[repr(transparent)] ··· 572 572 }}; 573 573 } 574 574 575 - #[cfg(test)] 576 - #[expect(clippy::items_after_test_module)] 575 + #[kunit_tests(rust_kernel_str)] 577 576 mod tests { 578 577 use super::*; 579 578 ··· 621 622 } 622 623 623 624 #[test] 624 - #[should_panic] 625 - fn test_cstr_to_str_panic() { 625 + fn test_cstr_to_str_invalid_utf8() { 626 626 let bad_bytes = b"\xc3\x28\0"; 627 627 let checked_cstr = CStr::from_bytes_with_nul(bad_bytes).unwrap(); 628 - checked_cstr.to_str().unwrap(); 628 + assert!(checked_cstr.to_str().is_err()); 629 629 } 630 630 631 631 #[test]