Skip to content

Commit

Permalink
Upgrade to mgba_rom_test for faster testing (#175)
Browse files Browse the repository at this point in the history
It's a 0.10 new platform, which is lighter than mgba-sdl, and also allows automatically closing the emulator when the tests end.
Helps making both the actions and the user-side docker testing faster
  • Loading branch information
Lorenzooone authored Jul 9, 2022
1 parent 7c9408e commit 1f03f27
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 18 deletions.
14 changes: 7 additions & 7 deletions docker-scripts/build-dockers/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM mcr.microsoft.com/powershell:ubuntu-20.04 AS builder
RUN echo "------------------Updating System------------------"
RUN apt update
RUN apt upgrade
RUN apt update -y
RUN apt upgrade -y
RUN apt install -y wget gcc-arm-none-eabi cmake build-essential tar git
RUN echo "------------------Installing dotnet core------------------"
RUN mkdir -p /opt/dep
Expand Down Expand Up @@ -37,7 +37,7 @@ CMD /home/m2gba/src/docker-scripts/docker-build-patch-script
#---------------------- Building mgba ------------------------
FROM builder AS mgba_builder
USER root
RUN apt-get update && \
RUN apt-get update -y && \
apt-get install -y --no-install-recommends build-essential ccache cmake \
git libavcodec-dev libavfilter-dev libavformat-dev libavresample-dev \
libavutil-dev libcmocka-dev libedit-dev libelf-dev libpng-dev \
Expand All @@ -47,17 +47,17 @@ RUN apt-get update && \
WORKDIR /home/m2gba
USER m2gba
RUN git clone https://github.com/mgba-emu/mgba.git
RUN cd mgba && mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .. && make
RUN cd mgba && mkdir build && cd build && cmake -DBUILD_ROM_TEST:BOOL=ON -DBUILD_QT:BOOL=OFF -DBUILD_SDL:BOOL=OFF -DCMAKE_INSTALL_PREFIX:PATH=/usr .. && make

#------------------- Building the Tester ---------------------
FROM builder AS tester
USER root
RUN apt-get update && \
apt-get install -y --no-install-recommends pulseaudio alsa-utils libsdl2-dev \
RUN apt-get update -y && \
apt-get install -y --no-install-recommends libgl1-mesa-glx \
libzip-dev libavcodec-dev libavfilter-dev && \
apt-get autoremove -y && apt-get clean
WORKDIR /opt/src
USER m2gba
COPY --from=mgba_builder /home/m2gba/mgba/build/sdl/mgba ./bin/mgba-sdl
COPY --from=mgba_builder /home/m2gba/mgba/build/test/mgba-rom-test ./bin/mgba-rom-test
COPY --from=mgba_builder /home/m2gba/mgba/build/libmgba* ./
CMD /home/m2gba/src/docker-scripts/docker-test-rom-script
8 changes: 2 additions & 6 deletions docker-scripts/docker-test-rom-script
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/bin/pwsh

"Starting Dummy services"
$Env:SDL_VIDEODRIVER = "dummy"
pulseaudio -D --exit-idle-time=-1
pactl load-module module-null-sink sink_name=SpeakerOutput sink_properties=device.description="Dummy_Output"

$Env:LD_LIBRARY_PATH += "/opt/src"
$Env:PATH += ":/home/m2gba/.dotnet:/home/m2gba/.dotnet/tools"
Copy-Item -Path "\home\m2gba\src\*" -Destination "\opt\src" -Recurse -Force

Expand All @@ -13,7 +9,7 @@ Copy-Item -Path "\home\m2gba\src\*" -Destination "\opt\src" -Recurse -Force
if ($LASTEXITCODE -ne 0) { exit -1 }

"Starting to build test rom"
./test.ps1
./test-fast.ps1
$LAST_VAL = $LASTEXITCODE

"Copying test log to output"
Expand Down
3 changes: 2 additions & 1 deletion src/c/ext.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "window.h"

void __attribute__((naked)) m12_first_function() {}
void __attribute__((naked)) stop(int param) {}
void __attribute__((naked)) cpufastset(void *source, void *dest, int mode) {}
void __attribute__((naked)) cpuset(void *source, void *dest, int mode) {}
byte* __attribute__((naked)) m2_strlookup(int *offset_table, byte *strings, int index) {}
Expand Down Expand Up @@ -39,4 +40,4 @@ void __attribute__((naked)) m2_title_teardown() {}
void __attribute__((naked)) vblank() {}
int __attribute__((naked)) m2_set_equippables(WINDOW* window, unsigned short choice, byte* index_list) {}
void __attribute__((naked)) reg_ram_reset(int flag) {}
void __attribute__((naked)) m2_printnextch(WINDOW* window) {}
void __attribute__((naked)) m2_printnextch(WINDOW* window) {}
5 changes: 2 additions & 3 deletions src/c/tests/main_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ void start_tests()

end_session();

while(1)
vblank();
}
stop(0);
}
2 changes: 1 addition & 1 deletion src/c/tests/main_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

void start_tests();

extern void vblank();
extern void stop(int);
4 changes: 4 additions & 0 deletions src/syscalls.asm
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
cpufastset:
swi 0xC
bx lr

stop:
swi 0x3
bx lr
35 changes: 35 additions & 0 deletions test-fast.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
$test_rom_file = "bin/m12test.gba"
$log_file = "bin/test.log"
$sleep_time = 300
$failure_text = "FAIL"
$end_text = "Done!"
$mgba_name = "mgba-rom-test"

If ($IsWindows) { $mgba_cmd = "bin/$mgba_name.exe" }
ElseIf ($IsLinux -or $IsMacOS) { $mgba_cmd = "bin/$mgba_name" }

"Building the test ROM..."
.\build.ps1 -t
if ($LASTEXITCODE -ne 0) { exit -1 }
Remove-Item -Path $log_file

"Starting the emulator... And closing it after $sleep_time seconds if it hasn't finished by then"
& timeout --preserve-status $sleep_time $mgba_cmd -l 16 -C logLevel.gba.bios=0 -C logToStdout=0 -C logToFile=1 -C logFile=$log_file $test_rom_file
if ($LASTEXITCODE -ne 0) { exit -1 }

$fails = Select-String -Path $log_file -Pattern $failure_text
if ($fails.count -ne 0) {
"Test failures:"
$fails
exit -1
}

$end_session = Select-String -Path $log_file -Pattern $end_text
if ($end_session.count -eq 0) {
"The tests did not run to completion!"
exit -1
}

"No failures!"

exit 0
Empty file modified test.ps1
100644 → 100755
Empty file.

0 comments on commit 1f03f27

Please sign in to comment.