@@ -98,6 +98,9 @@ use prelude::{GbaCell, IrqFn};
9898
9999mod macros;
100100
101+ #[ cfg( test) ]
102+ mod test_harness;
103+
101104#[ cfg( feature = "on_gba" ) ]
102105mod asm_runtime;
103106#[ cfg( feature = "on_gba" ) ]
@@ -183,121 +186,6 @@ macro_rules! include_aligned_bytes {
183186 } } ;
184187}
185188
186- #[ cfg( test) ]
187- mod test_harness {
188- use crate :: prelude:: * ;
189- use crate :: { bios, mem, mgba} ;
190- use core:: fmt:: Write ;
191-
192- #[ panic_handler]
193- fn panic ( info : & core:: panic:: PanicInfo ) -> ! {
194- DISPSTAT . write ( DisplayStatus :: new ( ) . with_irq_vblank ( true ) ) ;
195- BG_PALETTE . index ( 0 ) . write ( Color :: from_rgb ( 25 , 10 , 5 ) ) ;
196- IE . write ( IrqBits :: VBLANK ) ;
197- IME . write ( true ) ;
198- VBlankIntrWait ( ) ;
199- VBlankIntrWait ( ) ;
200- VBlankIntrWait ( ) ;
201-
202- // the Fatal one kills emulation after one line / 256 bytes
203- // so emit all the information as Error first
204- if let Ok ( mut log) =
205- mgba:: MgbaBufferedLogger :: try_new ( mgba:: MgbaMessageLevel :: Error )
206- {
207- writeln ! ( log, "[failed]" ) . ok ( ) ;
208- write ! ( log, "{}" , info) . ok ( ) ;
209- }
210-
211- if let Ok ( mut log) =
212- mgba:: MgbaBufferedLogger :: try_new ( mgba:: MgbaMessageLevel :: Fatal )
213- {
214- if let Some ( loc) = info. location ( ) {
215- write ! ( log, "panic at {loc}! see mgba error log for details." ) . ok ( ) ;
216- } else {
217- write ! ( log, "panic! see mgba error log for details." ) . ok ( ) ;
218- }
219- }
220-
221- IE . write ( IrqBits :: new ( ) ) ;
222- bios:: IntrWait ( true , IrqBits :: new ( ) ) ;
223- loop { }
224- }
225-
226- pub ( crate ) trait UnitTest {
227- fn run ( & self ) ;
228- }
229-
230- impl < T : Fn ( ) > UnitTest for T {
231- fn run ( & self ) {
232- if let Ok ( mut log) =
233- mgba:: MgbaBufferedLogger :: try_new ( mgba:: MgbaMessageLevel :: Info )
234- {
235- write ! ( log, "{}..." , core:: any:: type_name:: <T >( ) ) . ok ( ) ;
236- }
237-
238- self ( ) ;
239-
240- if let Ok ( mut log) =
241- mgba:: MgbaBufferedLogger :: try_new ( mgba:: MgbaMessageLevel :: Info )
242- {
243- writeln ! ( log, "[ok]" ) . ok ( ) ;
244- }
245- }
246- }
247-
248- pub ( crate ) fn test_runner ( tests : & [ & dyn UnitTest ] ) {
249- if let Ok ( mut log) =
250- mgba:: MgbaBufferedLogger :: try_new ( mgba:: MgbaMessageLevel :: Info )
251- {
252- write ! ( log, "Running {} tests" , tests. len( ) ) . ok ( ) ;
253- }
254-
255- for test in tests {
256- test. run ( ) ;
257- }
258- if let Ok ( mut log) =
259- mgba:: MgbaBufferedLogger :: try_new ( mgba:: MgbaMessageLevel :: Info )
260- {
261- write ! ( log, "Tests finished successfully" ) . ok ( ) ;
262- }
263- }
264-
265- #[ no_mangle]
266- extern "C" fn main ( ) {
267- DISPCNT . write ( DisplayControl :: new ( ) . with_video_mode ( VideoMode :: _0) ) ;
268- BG_PALETTE . index ( 0 ) . write ( Color :: new ( ) ) ;
269-
270- crate :: test_main ( ) ;
271-
272- BG_PALETTE . index ( 0 ) . write ( Color :: from_rgb ( 5 , 15 , 25 ) ) ;
273- BG_PALETTE . index ( 1 ) . write ( Color :: new ( ) ) ;
274- BG0CNT
275- . write ( BackgroundControl :: new ( ) . with_charblock ( 0 ) . with_screenblock ( 31 ) ) ;
276- DISPCNT . write (
277- DisplayControl :: new ( ) . with_video_mode ( VideoMode :: _0) . with_show_bg0 ( true ) ,
278- ) ;
279-
280- // some niceties for people without mgba-test-runner
281- let tsb = TEXT_SCREENBLOCKS . get_frame ( 31 ) . unwrap ( ) ;
282- unsafe {
283- mem:: set_u32x80_unchecked (
284- tsb. into_block :: < 1024 > ( ) . as_mut_ptr ( ) . cast ( ) ,
285- 0 ,
286- 12 ,
287- ) ;
288- }
289- Cga8x8Thick . bitunpack_4bpp ( CHARBLOCK0_4BPP . as_region ( ) , 0 ) ;
290-
291- let row = tsb. get_row ( 9 ) . unwrap ( ) . iter ( ) . skip ( 6 ) ;
292- for ( addr, ch) in row. zip ( b"all tests passed!" ) {
293- addr. write ( TextEntry :: new ( ) . with_tile ( * ch as u16 ) ) ;
294- }
295-
296- DISPSTAT . write ( DisplayStatus :: new ( ) ) ;
297- bios:: IntrWait ( true , IrqBits :: new ( ) ) ;
298- }
299- }
300-
301189#[ cfg( test) ]
302190mod test {
303191 use super :: Align4 ;
@@ -309,7 +197,6 @@ mod test {
309197 assert_eq ! ( a. as_u32_slice( ) , & [ 0x3020100_u32 . to_le( ) ] ) ;
310198 }
311199
312-
313200 #[ test_case]
314201 fn align4_as_generic ( ) {
315202 // with padding
@@ -335,9 +222,8 @@ mod test {
335222 . as_slice:: <ThreeHalfWords >( ) ,
336223 & [
337224 ThreeHalfWords ( 0x1111 , 0x2222 , 0x3333 ) ,
338- ThreeHalfWords ( 0x4444 0x5555 , 0x6666 )
225+ ThreeHalfWords ( 0x4444 , 0x5555 , 0x6666 )
339226 ]
340227 ) ;
341228 }
342-
343229}
0 commit comments