Skip to content

Commit 1f03f27

Browse files
authored
Upgrade to mgba_rom_test for faster testing (#175)
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
1 parent 7c9408e commit 1f03f27

File tree

8 files changed

+53
-18
lines changed

8 files changed

+53
-18
lines changed

docker-scripts/build-dockers/Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM mcr.microsoft.com/powershell:ubuntu-20.04 AS builder
22
RUN echo "------------------Updating System------------------"
3-
RUN apt update
4-
RUN apt upgrade
3+
RUN apt update -y
4+
RUN apt upgrade -y
55
RUN apt install -y wget gcc-arm-none-eabi cmake build-essential tar git
66
RUN echo "------------------Installing dotnet core------------------"
77
RUN mkdir -p /opt/dep
@@ -37,7 +37,7 @@ CMD /home/m2gba/src/docker-scripts/docker-build-patch-script
3737
#---------------------- Building mgba ------------------------
3838
FROM builder AS mgba_builder
3939
USER root
40-
RUN apt-get update && \
40+
RUN apt-get update -y && \
4141
apt-get install -y --no-install-recommends build-essential ccache cmake \
4242
git libavcodec-dev libavfilter-dev libavformat-dev libavresample-dev \
4343
libavutil-dev libcmocka-dev libedit-dev libelf-dev libpng-dev \
@@ -47,17 +47,17 @@ RUN apt-get update && \
4747
WORKDIR /home/m2gba
4848
USER m2gba
4949
RUN git clone https://github.com/mgba-emu/mgba.git
50-
RUN cd mgba && mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .. && make
50+
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
5151

5252
#------------------- Building the Tester ---------------------
5353
FROM builder AS tester
5454
USER root
55-
RUN apt-get update && \
56-
apt-get install -y --no-install-recommends pulseaudio alsa-utils libsdl2-dev \
55+
RUN apt-get update -y && \
56+
apt-get install -y --no-install-recommends libgl1-mesa-glx \
5757
libzip-dev libavcodec-dev libavfilter-dev && \
5858
apt-get autoremove -y && apt-get clean
5959
WORKDIR /opt/src
6060
USER m2gba
61-
COPY --from=mgba_builder /home/m2gba/mgba/build/sdl/mgba ./bin/mgba-sdl
61+
COPY --from=mgba_builder /home/m2gba/mgba/build/test/mgba-rom-test ./bin/mgba-rom-test
6262
COPY --from=mgba_builder /home/m2gba/mgba/build/libmgba* ./
6363
CMD /home/m2gba/src/docker-scripts/docker-test-rom-script

docker-scripts/docker-test-rom-script

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#!/bin/pwsh
22

3-
"Starting Dummy services"
4-
$Env:SDL_VIDEODRIVER = "dummy"
5-
pulseaudio -D --exit-idle-time=-1
6-
pactl load-module module-null-sink sink_name=SpeakerOutput sink_properties=device.description="Dummy_Output"
7-
3+
$Env:LD_LIBRARY_PATH += "/opt/src"
84
$Env:PATH += ":/home/m2gba/.dotnet:/home/m2gba/.dotnet/tools"
95
Copy-Item -Path "\home\m2gba\src\*" -Destination "\opt\src" -Recurse -Force
106

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

1511
"Starting to build test rom"
16-
./test.ps1
12+
./test-fast.ps1
1713
$LAST_VAL = $LASTEXITCODE
1814

1915
"Copying test log to output"

src/c/ext.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "window.h"
22

33
void __attribute__((naked)) m12_first_function() {}
4+
void __attribute__((naked)) stop(int param) {}
45
void __attribute__((naked)) cpufastset(void *source, void *dest, int mode) {}
56
void __attribute__((naked)) cpuset(void *source, void *dest, int mode) {}
67
byte* __attribute__((naked)) m2_strlookup(int *offset_table, byte *strings, int index) {}
@@ -39,4 +40,4 @@ void __attribute__((naked)) m2_title_teardown() {}
3940
void __attribute__((naked)) vblank() {}
4041
int __attribute__((naked)) m2_set_equippables(WINDOW* window, unsigned short choice, byte* index_list) {}
4142
void __attribute__((naked)) reg_ram_reset(int flag) {}
42-
void __attribute__((naked)) m2_printnextch(WINDOW* window) {}
43+
void __attribute__((naked)) m2_printnextch(WINDOW* window) {}

src/c/tests/main_test.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ void start_tests()
1212

1313
end_session();
1414

15-
while(1)
16-
vblank();
17-
}
15+
stop(0);
16+
}

src/c/tests/main_test.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
void start_tests();
44

5-
extern void vblank();
5+
extern void stop(int);

src/syscalls.asm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
cpufastset:
22
swi 0xC
33
bx lr
4+
5+
stop:
6+
swi 0x3
7+
bx lr

test-fast.ps1

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
$test_rom_file = "bin/m12test.gba"
2+
$log_file = "bin/test.log"
3+
$sleep_time = 300
4+
$failure_text = "FAIL"
5+
$end_text = "Done!"
6+
$mgba_name = "mgba-rom-test"
7+
8+
If ($IsWindows) { $mgba_cmd = "bin/$mgba_name.exe" }
9+
ElseIf ($IsLinux -or $IsMacOS) { $mgba_cmd = "bin/$mgba_name" }
10+
11+
"Building the test ROM..."
12+
.\build.ps1 -t
13+
if ($LASTEXITCODE -ne 0) { exit -1 }
14+
Remove-Item -Path $log_file
15+
16+
"Starting the emulator... And closing it after $sleep_time seconds if it hasn't finished by then"
17+
& 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
18+
if ($LASTEXITCODE -ne 0) { exit -1 }
19+
20+
$fails = Select-String -Path $log_file -Pattern $failure_text
21+
if ($fails.count -ne 0) {
22+
"Test failures:"
23+
$fails
24+
exit -1
25+
}
26+
27+
$end_session = Select-String -Path $log_file -Pattern $end_text
28+
if ($end_session.count -eq 0) {
29+
"The tests did not run to completion!"
30+
exit -1
31+
}
32+
33+
"No failures!"
34+
35+
exit 0

test.ps1

100644100755
File mode changed.

0 commit comments

Comments
 (0)