Skip to content

Commit

Permalink
Run unit tests in CI, some type portability fixes (#6)
Browse files Browse the repository at this point in the history
Run unit tests in CI, type portability fixes
  • Loading branch information
sozud authored Jan 9, 2024
1 parent ce219df commit 4ff48d4
Show file tree
Hide file tree
Showing 11 changed files with 768 additions and 587 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,36 @@ jobs:
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Run unit tests
run: ./build/Sound test

build-psx:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: wine
run: sudo dpkg --add-architecture i386 && sudo apt-get update && sudo apt-get install wine32
run: sudo dpkg --add-architecture i386 && sudo apt-get update && sudo apt-get install wine32 libsdl2-dev

- name: psy-q
run: git clone https://github.com/sozud/psyq_sdk.git

- name: Build
run: cd psx_seq_player/build && pip3 install -r requirements.txt && python3 build.py --psyq_path ../../psyq_sdk

- name: Get mednafen
run: git clone https://github.com/sozud/mednafen-build.git

- name: Get bios
run: |
wget https://archive.org/download/PlayStationBIOSFilesNAEUJP/scph5500.bin
mkdir -p /home/runner/.mednafen/firmware/
cp scph5500.bin /home/runner/.mednafen/firmware/
- name: Run unit tests
run: xvfb-run ./mednafen-build/mednafen ./psx_seq_player/obj/psx_seq_player_test/sound.exe

build-windows:
runs-on: windows-latest

Expand Down
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ project(Sound)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# turn on address sanitizer for gcc
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fsanitize=address")
endif()

if(WIN32)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
endif()
Expand All @@ -23,6 +30,7 @@ set(SOURCE_FILES
psx_seq_player/vs_vt.c
psx_seq_player/vs_vtc.c
psx_seq_player/main.cpp
psx_seq_player/test.cpp
)

# Add executable target
Expand Down
42 changes: 28 additions & 14 deletions psx_seq_player/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ def ninja_run():
ninja.variable("psyq_path", args.psyq_path)
ninja.newline()

ninja.variable("target_name", "default")
ninja.newline()

ninja.variable("suffix", "")
ninja.newline()

ninja.variable("psyq_path_backslashed", args.psyq_path.replace('/', '\\'))
ninja.newline()

Expand Down Expand Up @@ -94,11 +100,11 @@ def ninja_run():

includes = "-I " + args.psyq_path + "/psyq_4.4/INCLUDE" + " -I $src_dir"

ninja.rule("psyq_c_preprocess_44", "$psyq_c_preprocessor_44_exe -undef -DPSX -D__GNUC__=2 -D__OPTIMIZE__ " + includes + " -lang-c -Dmips -D__mips__ -D__mips -Dpsx -D__psx__ -D__psx -D_PSYQ -D__EXTENSIONS__ -D_MIPSEL -D__CHAR_UNSIGNED__ -D_LANGUAGE_C -D__cplusplus -D_LANGUAGE_C_PLUS_PLUS $in $out", "Preprocess $in -> $out")
ninja.rule("psyq_c_preprocess_44", "$psyq_c_preprocessor_44_exe -undef $is_test -DPSX -D__GNUC__=2 -D__OPTIMIZE__ " + includes + " -lang-c -Dmips -D__mips__ -D__mips -Dpsx -D__psx__ -D__psx -D_PSYQ -D__EXTENSIONS__ -D_MIPSEL -D__CHAR_UNSIGNED__ -D_LANGUAGE_C -D__cplusplus -D_LANGUAGE_C_PLUS_PLUS $in $out", "Preprocess $in -> $out")
ninja.newline()

# generate header deps, adds edges to the build graph for the next build -M option will write header deps
ninja.rule("psyq_c_preprocess_44_headers", "$psyq_c_preprocessor_44_exe -M -undef -DPSX -D_LANGUAGE_C_PLUS_PLUS -D__cplusplus -D__GNUC__=2 -D__OPTIMIZE__ " + includes + " -lang-c -Dmips -D__mips__ -D__mips -Dpsx -D__psx__ -D__psx -D_PSYQ -D__EXTENSIONS__ -D_MIPSEL -D__CHAR_UNSIGNED__ $in $out", "Preprocess for includes $in -> $out")
ninja.rule("psyq_c_preprocess_44_headers", "$psyq_c_preprocessor_44_exe -M -undef $is_test -DPSX -D_LANGUAGE_C_PLUS_PLUS -D__cplusplus -D__GNUC__=2 -D__OPTIMIZE__ " + includes + " -lang-c -Dmips -D__mips__ -D__mips -Dpsx -D__psx__ -D__psx -D_PSYQ -D__EXTENSIONS__ -D_MIPSEL -D__CHAR_UNSIGNED__ $in $out", "Preprocess for includes $in -> $out")
ninja.newline()

ninja.rule("header_deps", f"{sys.executable} hash_include_msvc_formatter.py $in $out", "Include deps fix $in -> $out", deps="msvc")
Expand All @@ -124,7 +130,7 @@ def ninja_run():

psqy_lib = f'{args.psyq_path}/psyq_4.4/LIB'

ninja.rule("psylink", f"$psyq_psylink_exe /l {psqy_lib} /c /n 4000 /q /gp .sdata /m @\"../{args.obj_directory}/linker_command_file$suffix.txt\",../{args.obj_directory}/sound$suffix.cpe,../{args.obj_directory}/asm$suffix.sym,../{args.obj_directory}/asm$suffix.map", "Link $out")
ninja.rule("psylink", f"$psyq_psylink_exe /l {psqy_lib} /c /n 4000 /q /gp .sdata /m @\"../{args.obj_directory}/$target_name/linker_command_file$suffix.txt\",../{args.obj_directory}/$target_name/sound$suffix.cpe,../{args.obj_directory}/$target_name/asm$suffix.sym,../{args.obj_directory}/$target_name/asm$suffix.map", "Link $out")

# TODO: update the tool so we can set the output name optionally
# cmd /c doesn't like forward slashed relative paths
Expand Down Expand Up @@ -153,13 +159,13 @@ def get_files_recursive(path, ext):
collectedFiles.append(os.path.join(r, file))
return collectedFiles

def gen_build_target(targetName):
def gen_build_target(targetName, is_test):
ninja.comment("Build target " + targetName)

asmFiles = get_files_recursive("../asm", ".s")
print("Got " + str(len(asmFiles)) + " asm files")

cFiles = ['../vs_vt.c', '../vs_vtc.c', '../main.cpp', '../lib_snd.cpp', '../lib_spu.cpp']
cFiles = ['../vs_vt.c', '../vs_vtc.c', '../main.cpp', '../lib_snd.cpp', '../lib_spu.cpp', '../test.cpp']
print("Got " + str(len(cFiles)) + " source files")

linkerDeps = []
Expand All @@ -170,7 +176,7 @@ def gen_build_target(targetName):
# build .s files
for asmFile in asmFiles:
asmFile = asmFile.replace("\\", "/")
asmOFile = asmFile.replace("/asm/", f"/{args.obj_directory}/")
asmOFile = asmFile.replace("/asm/", f"/{args.obj_directory}/{targetName}/")
asmOFile = asmOFile.replace(".s", ".obj")
#print("Build step " + asmFile + " -> " + asmOFile)
ninja.build(asmOFile, "psyq_asmpsx_assemble", asmFile)
Expand All @@ -179,7 +185,7 @@ def gen_build_target(targetName):
# build .c files
for cFile in cFiles:
cFile = cFile.replace("\\", "/")
cOFile = cFile.replace("../", f"../{args.obj_directory}/")
cOFile = cFile.replace("../", f"../{args.obj_directory}/{targetName}/")

if 'cpp' in cFile:
cPreProcHeadersFile = cOFile.replace(".cpp", ".cpp.preproc.headers")
Expand Down Expand Up @@ -210,7 +216,11 @@ def gen_build_target(targetName):

compiler = "psyq_cc_44"
aspsx = "psyq_aspsx_assemble_44"
ninja.build(cPreProcFile, "psyq_c_preprocess_44", cFile, implicit=[cPreProcHeadersFixedFile])
if(is_test):
is_test_def = "-DUNIT_TESTS"
else:
is_test_def = ""
ninja.build(cPreProcFile, "psyq_c_preprocess_44", cFile, implicit=[cPreProcHeadersFixedFile], variables={'is_test':is_test_def})
ninja.build([cAsmPreProcFile, cAsmPreProcFileDeps, cDynDepFile], "asm_include_preprocess_44", cPreProcFile)
ninja.build(cAsmFile, compiler, cAsmPreProcFile)
ninja.build(cTempOFile, aspsx, cAsmFile)
Expand All @@ -221,21 +231,25 @@ def gen_build_target(targetName):
# Build main exe

# preprocess linker_command_file.txt
linkerCommandFile = f"../{args.obj_directory}/linker_command_file.txt"
ninja.build(linkerCommandFile, "linker_command_file_preprocess", f"linker_command_file.txt", variables={'psyq_sdk': args.psyq_path})
linkerCommandFile = f"../{args.obj_directory}/{targetName}/linker_command_file.txt"
if(is_test):
ninja.build(linkerCommandFile, "linker_command_file_preprocess", f"linker_command_file_test.txt", variables={'psyq_sdk': args.psyq_path})
else:
ninja.build(linkerCommandFile, "linker_command_file_preprocess", f"linker_command_file.txt", variables={'psyq_sdk': args.psyq_path})
ninja.newline()

# run the linker to generate the cpe
cpeFile = f"../{args.obj_directory}/sound.cpe"
ninja.build(cpeFile, "psylink", implicit=linkerDeps + [linkerCommandFile])
cpeFile = f"../{args.obj_directory}/{targetName}/sound.cpe"
ninja.build(cpeFile, "psylink", implicit=linkerDeps + [linkerCommandFile], variables={'target_name':targetName})
ninja.newline()

# cpe to exe
exeFile = f"../{args.obj_directory}/sound.exe"
exeFile = f"../{args.obj_directory}/{targetName}/sound.exe"
ninja.build(exeFile, "cpe2exe", cpeFile)
ninja.newline()

gen_build_target("psx_seq_player")
gen_build_target("psx_seq_player", False)
gen_build_target("psx_seq_player_test", True)

f.close()

Expand Down
10 changes: 5 additions & 5 deletions psx_seq_player/build/linker_command_file.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
org $80010000

include "../obj/main.obj"
include "../obj/psx_seq_player/main.obj"
;include "seqplayer.obj"
include "../obj/lib_snd.obj"
include "../obj/lib_spu.obj"
include "../obj/vs_vtc.obj"
include "../obj/vs_vt.obj"
include "../obj/psx_seq_player/lib_snd.obj"
include "../obj/psx_seq_player/lib_spu.obj"
include "../obj/psx_seq_player/vs_vtc.obj"
include "../obj/psx_seq_player/vs_vt.obj"

inclib libsn.lib
inclib libds.lib
Expand Down
23 changes: 23 additions & 0 deletions psx_seq_player/build/linker_command_file_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
org $80010000

include "../obj/psx_seq_player_test/main.obj"
;include "seqplayer.obj"
include "../obj/psx_seq_player_test/lib_snd.obj"
include "../obj/psx_seq_player_test/lib_spu.obj"
include "../obj/psx_seq_player_test/vs_vtc.obj"
include "../obj/psx_seq_player_test/vs_vt.obj"
include "../obj/psx_seq_player_test/test.obj"

inclib libsn.lib
inclib libds.lib
inclib libapi.lib
inclib libgpu.lib

inclib libcd.lib
inclib libgs.lib
inclib libc.lib
inclib libetc.lib
inclib libgte.lib

regs pc=__SN_ENTRY_POINT

Loading

0 comments on commit 4ff48d4

Please sign in to comment.