aboutsummaryrefslogtreecommitdiff
path: root/scripts/test-e2e.sh
blob: 17766a498d5be2315be7eb9090bba705c2c46c17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
#!/usr/bin/bash

# Instead of setting -e or something like that, we will accumulate errors and
# exit with the accumulated result at the end.
exit_code=0

AS65=${AS65:-"./target/debug/xa65"}

##
# Ensure git submodules are there and that the environment is set up correctly.

pushd tests
rm -rf out/
mkdir -p out/

if [ ! -d code.nes ]; then
    echo "(error) You need 'code.nes' for end-to-end tests."
    exit 1
fi

if [ ! -d aoc2023.nes ]; then
    echo "(error) you need 'aoc2023.nes' for end-to-end tests."
    exit 1
fi

if [ ! -d jetpac.nes ]; then
    echo "(error) you need 'jetpac.nes' for end-to-end tests."
    exit 1
fi

popd

##
# Build.

echo "(info): build development binaries"
cargo build

##
# Custom tests.

echo "test: custom => defines-undefines.nes"
./target/debug/nasm -c empty -Werror -o tests/out/defines-undefined.nes tests/defines.s
diff tests/out/defines-undefined.nes tests/expected/defines-undefined.nes
exit_code=$((exit_code + $?))

echo "test: custom => defines-one.nes"
./target/debug/nasm -D LALA -c empty -Werror -o tests/out/defines-one.nes tests/defines.s
diff tests/out/defines-one.nes tests/expected/defines-one.nes
exit_code=$((exit_code + $?))

echo "test: custom => defines-two.nes"
./target/debug/nasm -D LALA=2 -c empty -Werror -o tests/out/defines-two.nes tests/defines.s
diff tests/out/defines-two.nes tests/expected/defines-two.nes
exit_code=$((exit_code + $?))

echo "test: custom => unused.nes"
./target/debug/nasm -c empty --asan -o tests/out/unused.nes tests/unused.s 2> >(LC_ALL=C sort > tests/out/unused-warning.txt)
diff tests/out/unused-warning.txt tests/expected/unused-warning.txt
exit_code=$((exit_code + $?))
diff tests/out/unused.nes tests/expected/unused.nes
exit_code=$((exit_code + $?))

echo "test: custom => bare_accesses.nes"
./target/debug/nasm -c empty --asan tests/bare_accesses.s -o /dev/null 2>tests/out/bare_accesses.txt
diff tests/out/bare_accesses.txt tests/expected/bare_accesses.txt
exit_code=$((exit_code + $?))

echo "test: custom => variable_names.nes"
./target/debug/nasm -c empty --asan tests/variable_names.s -o /dev/null 2>tests/out/variable_names.txt
diff tests/out/variable_names.txt tests/expected/variable_names.txt
exit_code=$((exit_code + $?))

echo "test: custom => asan_reserve_constant.nes"
./target/debug/nasm -c empty --asan tests/asan_reserve_constant.s -o /dev/null 2>tests/out/asan_reserve_constant.txt
diff tests/out/asan_reserve_constant.txt tests/expected/asan_reserve_constant.txt
exit_code=$((exit_code + $?))

echo "test: custom => bad_jal.nes"
./target/debug/nasm -c empty --asan tests/bad_jal.s -o /dev/null 2>tests/out/bad_jal.txt
diff tests/out/bad_jal.txt tests/expected/bad_jal.txt
exit_code=$((exit_code + $?))

echo "test: custom => bad_fallthrough.nes"
./target/debug/nasm -c empty --asan tests/bad_fallthrough.s -o /dev/null 2>tests/out/bad_fallthrough.txt
diff tests/out/bad_fallthrough.txt tests/expected/bad_fallthrough.txt
exit_code=$((exit_code + $?))

echo "test: custom => fallthrough.nes"
./target/debug/nasm -c empty --asan tests/fallthrough.s -o tests/out/fallthrough.nes 2>tests/out/fallthrough.txt
diff tests/out/fallthrough.txt tests/expected/fallthrough.txt
exit_code=$((exit_code + $?))
diff tests/out/fallthrough.nes tests/expected/fallthrough.nes
exit_code=$((exit_code + $?))

echo "test: custom => avoid_bad_macro.nes"
./target/debug/nasm -c empty --asan tests/avoid_bad_macro.s -o tests/out/avoid_bad_macro.nes 2>tests/out/avoid_bad_macro.txt
diff tests/out/avoid_bad_macro.txt tests/expected/avoid_bad_macro.txt
exit_code=$((exit_code + $?))
diff tests/out/avoid_bad_macro.nes tests/expected/avoid_bad_macro.nes
exit_code=$((exit_code + $?))

echo "test: custom => indirect.nes"
./target/debug/nasm -c empty --asan tests/indirect.s -o tests/out/indirect.nes 2>tests/out/indirect.txt
diff tests/out/indirect.txt tests/expected/indirect.txt
exit_code=$((exit_code + $?))
diff tests/out/indirect.nes tests/expected/indirect.nes
exit_code=$((exit_code + $?))

echo "test: custom => delayed_macro_arguments.nes"
./target/debug/nasm -c empty --asan tests/delayed_macro_arguments.s -o tests/out/delayed_macro_arguments.nes 2>tests/out/delayed_macro_arguments.txt
diff tests/out/delayed_macro_arguments.txt tests/expected/delayed_macro_arguments.txt
exit_code=$((exit_code + $?))
diff tests/out/delayed_macro_arguments.nes tests/expected/delayed_macro_arguments.nes
exit_code=$((exit_code + $?))

echo "test: custom => unused_definition.nes"
./target/debug/nasm -c empty -Werror --asan tests/unused_definition.s -o /dev/null 2>tests/out/unused_definition.txt
diff tests/out/unused_definition.txt tests/expected/unused_definition.txt
exit_code=$((exit_code + $?))

echo "test: custom => unused_macro_arg.nes"
./target/debug/nasm -c empty --asan tests/unused_macro_arg.s -o tests/out/unused_macro_arg.nes 2>tests/out/unused_macro_arg.txt
diff tests/out/unused_macro_arg.txt tests/expected/unused_macro_arg.txt
exit_code=$((exit_code + $?))
diff tests/out/unused_macro_arg.nes tests/expected/unused_macro_arg.nes
exit_code=$((exit_code + $?))

echo "test: custom => unrom.nes"
./target/debug/nasm -c unrom tests/unrom.s -o tests/out/unrom.nes 2>tests/out/unrom.txt
diff tests/out/unrom.txt tests/expected/unrom.txt
exit_code=$((exit_code + $?))
diff tests/out/unrom.nes tests/expected/unrom.nes
exit_code=$((exit_code + $?))

echo "test: custom => fixed-segments.nes"
./target/debug/nasm -c unrom tests/fixed-segments.s -o tests/out/fixed-segments.nes 2>tests/out/fixed-segments.txt
diff tests/out/fixed-segments.txt tests/expected/fixed-segments.txt
exit_code=$((exit_code + $?))
diff tests/out/fixed-segments.nes tests/expected/fixed-segments.nes
exit_code=$((exit_code + $?))

echo "test: custom => global-labels.nes"
./target/debug/nasm -c empty -Werror --asan -o tests/out/global-labels.nes tests/global-labels.s 2>tests/out/global-labels.txt
diff tests/out/global-labels.txt tests/expected/global-labels.txt
exit_code=$((exit_code + $?))
diff tests/out/global-labels.nes tests/expected/global-labels.nes
exit_code=$((exit_code + $?))

echo "test: custom => out.nes"
./target/debug/nasm -c empty -Werror --asan -o tests/out/out.nes tests/out.s 2>tests/out/out.txt
diff tests/out/out.txt tests/expected/out.txt
exit_code=$((exit_code + $?))
diff tests/out/out.nes tests/expected/out.nes
exit_code=$((exit_code + $?))

echo "test: custom => conditionally_include.nes"
# No DEBUG
./target/debug/nasm -c empty -Werror --asan -o tests/out/conditionally_include.nes tests/conditionally_include.s 2> tests/out/conditionally_include.txt
diff tests/out/conditionally_include.txt tests/expected/conditionally_include.txt
exit_code=$((exit_code + $?))
diff tests/out/conditionally_include.nes tests/expected/conditionally_include.nes
exit_code=$((exit_code + $?))

# With DEBUG
./target/debug/nasm -c empty -Werror --asan -o tests/out/conditionally_include_debug.nes -D DEBUG=1 tests/conditionally_include.s 2> tests/out/conditionally_include_debug.txt
diff tests/out/conditionally_include_debug.txt tests/expected/conditionally_include_debug.txt
exit_code=$((exit_code + $?))
diff tests/out/conditionally_include_debug.nes tests/expected/conditionally_include_debug.nes
exit_code=$((exit_code + $?))

##
# code.nes

# NOTE: the address sanitizer is not enabled here as in most cases these files
# are using bare numbers for learning purposes, and in some other cases it
# doesn't matter that much as they are small programs.

echo "test: code.nes => basics/sprite.nes"
$AS65 --no-errors --allow-unused -b ./target/debug/nasm -C tests/code.nes/config/nrom.cfg -o /dev/null tests/code.nes/basics/sprite.s
exit_code=$((exit_code + $?))

echo "test: code.nes => basics/input.nes"
$AS65 --no-errors -b ./target/debug/nasm -C tests/code.nes/config/nrom.cfg -o /dev/null tests/code.nes/basics/input.s
exit_code=$((exit_code + $?))

echo "test: code.nes => basics/persist.nes"
$AS65 --no-errors -b ./target/debug/nasm -C tests/code.nes/config/mmc1.cfg -o /dev/null tests/code.nes/basics/persist.s
exit_code=$((exit_code + $?))

echo "test: code.nes => basics/flicker.nes"
$AS65 --no-errors --allow-unused -b ./target/debug/nasm -C tests/code.nes/config/nrom.cfg -o /dev/null tests/code.nes/basics/flicker.s
exit_code=$((exit_code + $?))

echo "test: code.nes => basics/unrom.nes"
$AS65 --no-errors --allow-unused -b ./target/debug/nasm -C tests/code.nes/config/unrom.cfg -o /dev/null tests/code.nes/basics/unrom.s
exit_code=$((exit_code + $?))

echo "test: code.nes => basics/chr-ram.nes"
$AS65 --no-errors -b ./target/debug/nasm -C tests/code.nes/config/unrom.cfg -o /dev/null tests/code.nes/basics/chr-ram.s
exit_code=$((exit_code + $?))

echo "test: code.nes => fx/blink.nes"
$AS65 --no-errors --allow-unused -b ./target/debug/nasm -C tests/code.nes/config/mmc3.cfg -o /dev/null tests/code.nes/fx/blink.s
exit_code=$((exit_code + $?))

echo "test: code.nes => scroll/toggle.nes"
$AS65 --no-errors --allow-unused -b ./target/debug/nasm -C tests/code.nes/config/nrom.cfg -o /dev/null tests/code.nes/scroll/toggle.s
exit_code=$((exit_code + $?))

echo "test: code.nes => scroll/level.nes"
$AS65 --no-errors --allow-unused -b ./target/debug/nasm -C tests/code.nes/config/nrom.cfg -o /dev/null tests/code.nes/scroll/level.s
exit_code=$((exit_code + $?))

echo "test: code.nes => scroll/sprite0.nes"
$AS65 --no-errors --allow-unused -b ./target/debug/nasm -C tests/code.nes/config/nrom.cfg -o /dev/null tests/code.nes/scroll/sprite0.s
exit_code=$((exit_code + $?))

echo "test: code.nes => scroll/mmc3.nes"
$AS65 --no-errors --allow-unused -b ./target/debug/nasm -C tests/code.nes/config/mmc3.cfg -o /dev/null tests/code.nes/scroll/mmc3.s
exit_code=$((exit_code + $?))

echo "test: code.nes => rand/rand.nes"
$AS65 --no-errors --allow-unused -b ./target/debug/nasm -C tests/code.nes/config/nrom.cfg -o /dev/null tests/code.nes/rand/rand.s
exit_code=$((exit_code + $?))

echo "test: code.nes => scroll/roulette.nes"
$AS65 --no-errors --allow-unused -b ./target/debug/nasm -C tests/code.nes/config/mmc3.cfg -o /dev/null tests/code.nes/scroll/roulette.s
exit_code=$((exit_code + $?))

echo "test: code.nes => space/space.nes"
$AS65 --no-errors --allow-unused -b ./target/debug/nasm -C tests/code.nes/config/nrom.cfg -o /dev/null tests/code.nes/space/src/space.s
exit_code=$((exit_code + $?))

##
# aoc2023.nes

echo "test: aoc2023.nes => 1.nes"
$AS65 --no-errors --allow-unused -b ./target/debug/nasm -C tests/cfg/nrom65.cfg -o /dev/null tests/aoc2023.nes/src/1.s
exit_code=$((exit_code + $?))

echo "test: aoc2023.nes => 2.nes"
$AS65 --no-errors --allow-unused -b ./target/debug/nasm -C tests/cfg/nrom65.cfg -o /dev/null tests/aoc2023.nes/src/2.s
exit_code=$((exit_code + $?))

echo "test: aoc2023.nes => 3.nes"
$AS65 --no-errors --allow-unused -b ./target/debug/nasm -C tests/cfg/nrom65.cfg -o /dev/null tests/aoc2023.nes/src/3.s
exit_code=$((exit_code + $?))

echo "test: aoc2023.nes => 4.nes"
$AS65 --no-errors --allow-unused -b ./target/debug/nasm -C tests/cfg/nrom65.cfg -o /dev/null tests/aoc2023.nes/src/4.s
exit_code=$((exit_code + $?))

##
# jetpac.nes

echo "test: jetpac.nes"

# Re-generate the config/generated.s file, which is usually built on a 'make
# build-*' target.
rm -f tests/jetpac.nes/config/generated.s
echo "HZ = 60" >> tests/jetpac.nes/config/generated.s
echo "LEVEL = 0" >> tests/jetpac.nes/config/generated.s

# NOTE: we use '--stats' as otherwise the 'segments.txt' file would be removed
# from the jetpac.nes repository, and the submodule would then be marked with
# "-dirty".
$AS65 --no-errors --allow-unused --strict --stats -b ./target/debug/nasm -C tests/jetpac.nes/config/nrom.cfg -o tests/out/jetpac.NTSC.nes tests/jetpac.nes/src/jetpac.s 1>/dev/null

# Remove the generated.s file to avoid git from thinking we have modified the
# project in any meaningful way.
rm -f tests/jetpac.nes/config/generated.s

##
# readrom

echo "test: readrom: header (jetpac.nes)"
./target/debug/readrom tests/out/jetpac.NTSC.nes > tests/out/jetpac.header.txt
diff tests/out/jetpac.header.txt tests/expected/readrom/header.txt
exit_code=$((exit_code + $?))

echo "test: readrom: hexadecimal address (jetpac.nes)"
./target/debug/readrom -d '$a3b2' -n tests/jetpac.nes/.nasm/ tests/out/jetpac.NTSC.nes > tests/out/jetpac-a3b2-address.txt
diff tests/out/jetpac-a3b2-address.txt tests/expected/readrom/a3b2-address.txt
exit_code=$((exit_code + $?))

echo "test: readrom: full NMI disassembling (jetpac.nes)"
./target/debug/readrom -d nmi -n tests/jetpac.nes/.nasm/ tests/out/jetpac.NTSC.nes > tests/out/jetpac-full-nmi.txt
diff tests/out/jetpac-full-nmi.txt tests/expected/readrom/jetpac-full-nmi.txt
exit_code=$((exit_code + $?))

echo "test: readrom: full NMI disassembling on MMC3 project (code.nes)"
./target/debug/nasm -c tests/code.nes/config/mmc3.cfg --asan --write-info -o tests/out/blink.nes tests/code.nes/fx/blink.s
./target/debug/readrom -d nmi -n tests/code.nes/.nasm/ --mmc "kind=mmc3; prg_rom_mode=0; r6=0; r7=1" tests/out/blink.nes > tests/out/blink-nmi.txt
diff tests/out/blink-nmi.txt tests/expected/readrom/blink-nmi.txt
exit_code=$((exit_code + $?))

# Remove the .nasm/ directory that has been created for code.nes.
rm -r tests/code.nes/.nasm

# Remove the dangling jetpac.nes ROM file.
rm tests/out/jetpac.NTSC.nes

# This file wasn't available originally on jetpac.nes
rm -f tests/jetpac.nes/.nasm/addresses.txt

##
# runrom

echo "test: runrom => arithlog.nes"
./target/debug/nasm -Werror -o tests/out/arithlog.nes tests/runrom/arithlog.s
./target/debug/runrom --function --dump-memory tests/out/arithlog.nes > tests/out/arithlog.txt
diff tests/out/arithlog.txt tests/expected/runrom/arithlog.txt
exit_code=$((exit_code + $?))

echo "test: runrom => stack.nes"
./target/debug/nasm -Werror -o tests/out/stack.nes tests/runrom/stack.s
./target/debug/runrom --no-halting-brk --function --dump-memory tests/out/stack.nes > tests/out/stack.txt
diff tests/out/stack.txt tests/expected/runrom/stack.txt
exit_code=$((exit_code + $?))

echo "test: runrom => halt.nes"
./target/debug/nasm -Werror -o tests/out/halt.nes tests/runrom/halt.s
./target/debug/runrom --dump-memory tests/out/halt.nes > tests/out/halt.txt
diff tests/out/halt.txt tests/expected/runrom/halt.txt
exit_code=$((exit_code + $?))

echo "test: runrom => cmp.nes"
./target/debug/nasm -Werror --asan -o tests/out/cmp.nes tests/runrom/cmp.s
./target/debug/runrom --function --dump-memory tests/out/cmp.nes > tests/out/cmp.txt
diff tests/out/cmp.txt tests/expected/runrom/cmp.txt
exit_code=$((exit_code + $?))

echo "test: runrom => branching.nes"
./target/debug/nasm -Werror --asan -o tests/out/branching.nes tests/runrom/branching.s
./target/debug/runrom --function --dump-memory tests/out/branching.nes > tests/out/branching.txt
diff tests/out/branching.txt tests/expected/runrom/branching.txt
exit_code=$((exit_code + $?))

echo "test: runrom => misc.nes"
./target/debug/nasm -Werror --asan --write-info --allow-unused --out tests/out/misc.nes tests/runrom/misc.s
./target/debug/runrom --nasm .nasm --dump-memory --function tests/out/misc.nes > tests/out/misc-all.txt
diff tests/out/misc-all.txt tests/expected/runrom/misc-all.txt
exit_code=$((exit_code + $?))

./target/debug/runrom --nasm .nasm --dump-memory --function --start 'foo::@loop' --until-address '$8007' tests/out/misc.nes > tests/out/misc-inx.txt
diff tests/out/misc-inx.txt tests/expected/runrom/misc-inx.txt
exit_code=$((exit_code + $?))

./target/debug/runrom --nasm .nasm --dump-memory --function --start foo --until-address foo::@end_loop tests/out/misc.nes > tests/out/misc-foo.txt
diff tests/out/misc-foo.txt tests/expected/runrom/misc-foo.txt
exit_code=$((exit_code + $?))

echo "test: runrom => overflows.nes"
./target/debug/nasm -Werror --asan --write-info --out tests/out/overflows.nes tests/runrom/overflows.s

./target/debug/runrom --nasm .nasm/ --dump-memory --function tests/out/overflows.nes &> tests/out/overflow-reset.txt
diff tests/out/overflow-reset.txt tests/expected/runrom/overflow-reset.txt
exit_code=$((exit_code + $?))

./target/debug/runrom --nasm .nasm/ --dump-memory --function --start overflow_on_arithmetics tests/out/overflows.nes &> tests/out/overflow-arithmetics.txt
diff tests/out/overflow-arithmetics.txt tests/expected/runrom/overflow-arithmetics.txt
exit_code=$((exit_code + $?))

./target/debug/runrom --nasm .nasm/ --dump-memory --function --start stack_underflow tests/out/overflows.nes &> tests/out/overflow-stack.txt
diff tests/out/overflow-stack.txt tests/expected/runrom/overflow-stack.txt
exit_code=$((exit_code + $?))

./target/debug/runrom --nasm .nasm/ --dump-memory --function --start bad_rom_data_indexing tests/out/overflows.nes &> tests/out/overflow-data-indexing.txt
diff tests/out/overflow-data-indexing.txt tests/expected/runrom/overflow-data-indexing.txt
exit_code=$((exit_code + $?))

##
# vnf-tests

# Needed for run_joypad_test()
./target/debug/nasm --asan -Werror -w -o tests/out/joypad.nes tests/runrom/joypad.s

echo "test: vnf-tests"
cargo run --bin vnf-tests -- tests/
exit_code=$((exit_code + $?))

##
# Done!

exit $exit_code