Skip to content

Make UTs run on SEGA Saturn - #133

Merged
jae686 merged 55 commits into
mainfrom
feature/UTs
Jul 21, 2026
Merged

Make UTs run on SEGA Saturn#133
jae686 merged 55 commits into
mainfrom
feature/UTs

Conversation

@willll

@willll willll commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

The goal of the PR is to provide a way to run Unit tests on SEGA Saturn through the gamer's cartridge,
UTs run on Saturn without modification but they do not output results, this PR add a display of results per group tests and a summary of the execution results directly on the Screen.
If built with make SRL_LOG_OUTPUT=DEV_CART and a SRL_LOG_LEVEL high enough (such as TESTING), the logs are sent to the serial line :

> make SRL_LOG_OUTPUT=DEV_CART

rm -f /saturn/SaturnRingLib/saturnringlib/../modules/sgl/LIB/../SRC/*.o
rm -f /saturn/SaturnRingLib/saturnringlib/../modules/sgl/SRC/preloader.o src/main.o "./BuildDrop/UTs.elf" "./BuildDrop/UTs.iso" "./BuildDrop/UTs.map" "./cd/data/0.bin"
****** No pre build steps ******
sh-elf-g++ /saturn/SaturnRingLib/saturnringlib/../modules/sgl/SRC/preloader.cxx -DSRL_FRAMERATE=1 -DSRL_LOG_LEVEL=TESTING -DSRL_LOG_OUTPUT=DEV_CART -DSRL_MODE_NTSC -DSRL_MAX_TEXTURES=1 -DSRL_MAX_CD_BACKGROUND_JOBS=1 -DSRL_MAX_CD_FILES=256 -DSRL_MAX_CD_RETRIES=3 -DSRL_DEBUG_MAX_PRINT_LENGTH=45 -DSRL_DEBUG_MAX_LOG_LENGTH=255  -DNO_SGL_STDLIB -Wno-attribute-warning -DSGL_MAX_VERTICES=2500 -DSGL_MAX_POLYGONS=1500 -DSGL_MAX_EVENTS=1 -DSGL_MAX_WORKS=1 -DSGL_SLAVE_BUF_SIZE=71680 -W -m2 -c -O2 -Wno-strict-aliasing -I/saturn/SaturnRingLib/saturnringlib/../modules/dummy -I/saturn/SaturnRingLib/saturnringlib/../modules/SaturnMathPP -I/saturn/SaturnRingLib/saturnringlib/../modules/sgl/INC -I/saturn/SaturnRingLib/saturnringlib/../modules/danny/INC -I/saturn/SaturnRingLib/saturnringlib  -std=c++23 -fpermissive -fno-exceptions -fno-rtti -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-threadsafe-statics -fno-use-cxa-atexit -o /saturn/SaturnRingLib/saturnringlib/../modules/sgl/SRC/preloader.o
sh-elf-g++ src/main.cxx -DSRL_FRAMERATE=1 -DSRL_LOG_LEVEL=TESTING -DSRL_LOG_OUTPUT=DEV_CART -DSRL_MODE_NTSC -DSRL_MAX_TEXTURES=1 -DSRL_MAX_CD_BACKGROUND_JOBS=1 -DSRL_MAX_CD_FILES=256 -DSRL_MAX_CD_RETRIES=3 -DSRL_DEBUG_MAX_PRINT_LENGTH=45 -DSRL_DEBUG_MAX_LOG_LENGTH=255  -DNO_SGL_STDLIB -Wno-attribute-warning -DSGL_MAX_VERTICES=2500 -DSGL_MAX_POLYGONS=1500 -DSGL_MAX_EVENTS=1 -DSGL_MAX_WORKS=1 -DSGL_SLAVE_BUF_SIZE=71680 -W -m2 -c -O2 -Wno-strict-aliasing -I/saturn/SaturnRingLib/saturnringlib/../modules/dummy -I/saturn/SaturnRingLib/saturnringlib/../modules/SaturnMathPP -I/saturn/SaturnRingLib/saturnringlib/../modules/sgl/INC -I/saturn/SaturnRingLib/saturnringlib/../modules/danny/INC -I/saturn/SaturnRingLib/saturnringlib  -std=c++23 -fpermissive -fno-exceptions -fno-rtti -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-threadsafe-statics -fno-use-cxa-atexit -o src/main.o
sh-elf-gcc /saturn/SaturnRingLib/saturnringlib/../modules/sgl/LIB/../SRC/workarea.c -DSRL_FRAMERATE=1 -DSRL_LOG_LEVEL=TESTING -DSRL_LOG_OUTPUT=DEV_CART -DSRL_MODE_NTSC -DSRL_MAX_TEXTURES=1 -DSRL_MAX_CD_BACKGROUND_JOBS=1 -DSRL_MAX_CD_FILES=256 -DSRL_MAX_CD_RETRIES=3 -DSRL_DEBUG_MAX_PRINT_LENGTH=45 -DSRL_DEBUG_MAX_LOG_LENGTH=255  -DNO_SGL_STDLIB -Wno-attribute-warning -DSGL_MAX_VERTICES=2500 -DSGL_MAX_POLYGONS=1500 -DSGL_MAX_EVENTS=1 -DSGL_MAX_WORKS=1 -DSGL_SLAVE_BUF_SIZE=71680 -W -m2 -c -O2 -Wno-strict-aliasing -I/saturn/SaturnRingLib/saturnringlib/../modules/dummy -I/saturn/SaturnRingLib/saturnringlib/../modules/SaturnMathPP -I/saturn/SaturnRingLib/saturnringlib/../modules/sgl/INC -I/saturn/SaturnRingLib/saturnringlib/../modules/danny/INC -I/saturn/SaturnRingLib/saturnringlib  -std=c2x -o /saturn/SaturnRingLib/saturnringlib/../modules/sgl/LIB/../SRC/workarea.o
****** Info ******
Maximum textures : 1            
Maximum vertices : 2500         
Maximum polygons : 1500         
Maximum events : 1             	
Maximum work : 1             	
**Log level selected : TESTING         
Log output method selected : DEV_CART**
Maximum Log length : 255
******************
sh-elf-gcc -m2 -L/saturn/SaturnRingLib/saturnringlib/../modules/sgl/LIB -Xlinker -T/saturn/SaturnRingLib/saturnringlib/../modules/sgl/sgl.linker -Xlinker -Map -Xlinker "./BuildDrop/UTs.map" -Xlinker -e -Xlinker ___Start -nostartfiles -specs=nosys.specs -lstdc++ /saturn/SaturnRingLib/saturnringlib/../modules/sgl/LIB/../SRC/workarea.o /saturn/SaturnRingLib/saturnringlib/../modules/sgl/SRC/preloader.o src/main.o -Wl,-bcoff-sh /saturn/SaturnRingLib/saturnringlib/../modules/sgl/LIB/LIBCPK.A /saturn/SaturnRingLib/saturnringlib/../modules/sgl/LIB/SEGA_SYS.A /saturn/SaturnRingLib/saturnringlib/../modules/sgl/LIB/LIBCD.A /saturn/SaturnRingLib/saturnringlib/../modules/sgl/LIB/LIBSGL.A -Wl,-belf32-sh -o "./BuildDrop/UTs.elf"
/opt/saturn/toolchain/lib/gcc/sh-elf/14.3.0/../../../../sh-elf/bin/ld: warning: ./BuildDrop/UTs.elf has a LOAD segment with RWX permissions
sh-elf-objcopy -O binary -R WORK_AREA* -R COMMAND_BUF* -R SYSTEM_START* -R SYSTEM_END* "./BuildDrop/UTs.elf" ./cd/data/0.bin
xorrisofs --norock -quiet -sysid "SEGA SATURN" -volid "SaturnApp" -volset "SaturnApp" \
-publisher "SEGA ENTERPRISES, LTD." -preparer "SEGA ENTERPRISES, LTD." -appid "SaturnApp" \
-abstract "./cd/data/ABS.TXT" -copyright "./cd/data/CPY.TXT" -biblio "./cd/data/BIB.TXT" -generic-boot /saturn/SaturnRingLib/saturnringlib/../modules/sgl/IP.BIN \
-full-iso9660-filenames -o "./BuildDrop/UTs.iso" ./cd/data 
xorriso 1.5.6 : RockRidge filesystem manipulator, libburnia project.

# Check if iso2raw binary exists
Converting ISO to MODE1/2352 raw format...
Converting ./BuildDrop/UTs.iso to ./BuildDrop/UTs.bin
Total sectors: 550 (1.07 MB)
Using 8 worker threads
  [00:00:00] [########################################] 550/550 sectors (0s)                                                                                                         
Conversion completed in 21.97ms (56.16 MB/s)
Output file: ./BuildDrop/UTs.bin
Starting with 1293600 bytes (550 sectors)
No audio files found
****** No post build steps ******

./run_tests.bat USBGamers

Starting Saturn unit test runner...
Using USBGamers cartridge
Resetting USB device...
Resetting FT245R USB FIFO ... ok

Test command: ftx -c
Watching log file: uts.log
Waiting for completion marker: ***UT_END***
Emulator started, monitoring for completion...
[DoConsole] Entering debug console mode. Press Ctrl+C to exit.
INFO : ***UT_START***
TESTING : Passed :ascii_test_display_simple_text
TESTING : Passed :ascii_test_display_out_of_bounds
TESTING : Passed :ascii_test_apply_color_palette
TESTING : Passed :ascii_test_set_palette_out_of_range
TESTING : Passed :ascii_test_set_font_out_of_range
TESTING : Passed :ascii_test_set_color_out_of_range
TESTING : Passed :angle_test_initialization_zero
TESTING : Passed :angle_test_subtraction_half_circle_minus_quarter_circle
TESTING : Passed :angle_test_subtraction_zero_minus_quarter_circle
...
TESTING : Passed :timer_initialization
TESTING : Passed :timer_current_tickstamp_accessor
TESTING : Passed :timer_delta_minutes
TESTING : Passed :timer_multiple_updates
TESTING : Passed :timer_clock_mode_override
TESTING : ****UT_TIMER****
FATAL : timer_diagnostic_overflow failed:
	src/testsTimer.hpp:860: timer32 should have incremented after waiting for overflow
INFO : 308 tests, 22330 assertions, 35 failures
INFO : Finished in f seconds (real) f seconds (proc)
INFO : ***UT_END***
Test completion marker found
Terminating emulator...
Tests completed successfully

[Signal] Caught signal 15, exiting...

https://github.com/willll/ftx is required to retrieve traces from the gamer's cartridge, a new getFTX script has been added (to be tested).

willll added 26 commits July 1, 2026 18:55
…rtOrder, and Trigonometry

- Implemented tests for Vector2D covering construction, absolute values, sorting, dot/cross products, length calculations, normalization, and shift operations.
- Added tests for Vector3D including construction, absolute values, sorting, dot/cross products, length calculations, normalization, and shift operations.
- Created tests for Sphere to validate properties, intersections, translations, and closest point calculations.
- Developed tests for SortOrder to ensure distinct values and sorting functionality.
- Introduced tests for Trigonometry to verify key angle calculations for sine, cosine, tangent, and atan2 functions.
- Updated test descriptions for clarity and consistency.
- Added tests for angle conversions, including edge cases for wrapping.
- Implemented tests for unary operations and SLerp functionality.
- Ensured all tests cover various scenarios, including negative angles and large scalars.
…lues, degenerate cases, and various geometric classifications
- Added detailed Doxygen-style comments to all test functions and setup/teardown methods for clarity.
- Refactored tests for fixed-point initialization, arithmetic operations, and comparisons to improve readability and maintainability.
- Introduced new tests for methods like `TruncateFraction`, `GetFraction`, `Floor`, `Ceil`, and `Round`.
- Consolidated modulo tests into a helper function for better organization and reduced redundancy.
- Removed commented-out edge case tests to clean up the codebase.
@willll
willll requested review from ReyeMe and robertoduarte and removed request for ReyeMe July 13, 2026 15:10
willll added 9 commits July 15, 2026 13:31
…ng conventions for USB development cartridge
…plify FIFO wait functions with timeout handling
- Updated test utility functions in testsUtils.hpp for better readability and consistency.
- Enhanced logging in test output functions to differentiate between testing and error states.
- Refactored test cases in testsVector2D.hpp and testsVector3D.hpp to improve clarity and maintainability.
- Ensured consistent formatting and documentation style across all test cases.
- Added missing test cases and improved assertions for better test coverage.
@ReyeMe

ReyeMe commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Tested on JP saturn with gamers cartrige. UTs compiled on windows, and ftx used on windows. All works when done manually.
run_tests.bat is missing implementation for calling from windows side. also add the bat file to tasks.json, so it can be run from VSCode

Zadig tools was also needed to force correct driver (Winusb) for the gamers cartrige

@ReyeMe ReyeMe left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the new .vscode/tasks.json to Tests folder
make the task call compile.bat instead of make directly

ReyeMe
ReyeMe previously approved these changes Jul 18, 2026

@ReyeMe ReyeMe left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@willll willll left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ReyeMe ReyeMe left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ReyeMe
ReyeMe requested review from bimmerlabs, jae686 and nemesis-saturn and removed request for robertoduarte July 21, 2026 20:55

@jae686 jae686 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cant wait to test it.

@jae686
jae686 merged commit 344c58c into main Jul 21, 2026
1 check passed
@willll
willll deleted the feature/UTs branch July 21, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request required hardware test Issues marked with this label must be tested on real HW before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants