mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									897d1df653
								
							
						
					
					
						commit
						028df914e5
					
				
					 1 changed files with 4 additions and 6 deletions
				
			
		| 
						 | 
					@ -6,7 +6,7 @@
 | 
				
			||||||
use core::fmt::{self, Write};
 | 
					use core::fmt::{self, Write};
 | 
				
			||||||
use core::ops::{self, Deref, DerefMut, Index};
 | 
					use core::ops::{self, Deref, DerefMut, Index};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::error::{code::*, Error};
 | 
					use crate::prelude::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Byte string without UTF-8 validity guarantee.
 | 
					/// Byte string without UTF-8 validity guarantee.
 | 
				
			||||||
#[repr(transparent)]
 | 
					#[repr(transparent)]
 | 
				
			||||||
| 
						 | 
					@ -572,8 +572,7 @@ macro_rules! c_str {
 | 
				
			||||||
    }};
 | 
					    }};
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(test)]
 | 
					#[kunit_tests(rust_kernel_str)]
 | 
				
			||||||
#[expect(clippy::items_after_test_module)]
 | 
					 | 
				
			||||||
mod tests {
 | 
					mod tests {
 | 
				
			||||||
    use super::*;
 | 
					    use super::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -622,11 +621,10 @@ fn test_cstr_to_str() {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[test]
 | 
					    #[test]
 | 
				
			||||||
    #[should_panic]
 | 
					    fn test_cstr_to_str_invalid_utf8() {
 | 
				
			||||||
    fn test_cstr_to_str_panic() {
 | 
					 | 
				
			||||||
        let bad_bytes = b"\xc3\x28\0";
 | 
					        let bad_bytes = b"\xc3\x28\0";
 | 
				
			||||||
        let checked_cstr = CStr::from_bytes_with_nul(bad_bytes).unwrap();
 | 
					        let checked_cstr = CStr::from_bytes_with_nul(bad_bytes).unwrap();
 | 
				
			||||||
        checked_cstr.to_str().unwrap();
 | 
					        assert!(checked_cstr.to_str().is_err());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[test]
 | 
					    #[test]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue