From bf661e7b074d3fd7a9c5ad8625fe64ad4087d85d Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Sun, 24 Dec 2023 14:22:11 -0300 Subject: [PATCH] Rework tests a little bit (#318) * yeet clean.sh and move downloading kmc to makefile * yeet build.sh * deps * more deps * woops * a * remove docker from the sh * arrg * e * i * wget * maybe? * idk what im doing * xzcv * yeet docker because I couldn't make it work * i'm a dumb dumb * fix yaml * Fix test_gen_expected.sh * fixes * Add instructions to run the tests --- .github/workflows/unit_tests.yml | 25 +++--- Dockerfile | 8 -- run_tests.sh | 11 --- test.py | 48 +++++------ test/Dockerfile | 3 + test/README.md | 43 ++++++++++ test/basic_app/Makefile | 76 ++++++++++++++++++ test/basic_app/build.sh | 16 ---- test/basic_app/clean.sh | 2 - test/basic_app/expected/.splache | Bin 785 -> 814 bytes test/basic_app/expected/asm/data/main.bss.s | 2 +- .../asm/nonmatchings/main/D_80000510.s | 8 ++ .../asm/nonmatchings/main/func_80000400.s | 33 ++++++-- test/basic_app/expected/basic_app.ld | 20 ++--- test/basic_app/expected/src/main.c | 2 + .../expected/undefined_syms_auto.txt | 1 - test/basic_app/main.c | 6 +- test/basic_app/splat.yaml | 7 +- test/test_gen_expected.sh | 13 +++ test_gen_expected.sh | 3 - 20 files changed, 229 insertions(+), 98 deletions(-) delete mode 100644 Dockerfile delete mode 100644 run_tests.sh mode change 100644 => 100755 test.py create mode 100644 test/Dockerfile create mode 100644 test/README.md create mode 100644 test/basic_app/Makefile delete mode 100755 test/basic_app/build.sh delete mode 100644 test/basic_app/clean.sh create mode 100644 test/basic_app/expected/asm/nonmatchings/main/D_80000510.s create mode 100755 test/test_gen_expected.sh delete mode 100644 test_gen_expected.sh diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 9cdb1f5d..7f0e1d06 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -9,12 +9,19 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v1 - - name: Set up Python 3.8 - uses: actions/setup-python@v1 - with: - python-version: 3.8 - - name: Install Dependencies - run: pip install -r requirements.txt - - name: Run unit tests - run: sh run_tests.sh + uses: actions/checkout@v4 + + - name: Install dependencies + run: sudo apt-get install -y build-essential make binutils-mips-linux-gnu python3 python3-pip wget + + - name: Install Python dependencies + run: python3 -m pip install -U -r requirements.txt + + - name: Build basic_app + run: | + make -C test/basic_app clean + make -C test/basic_app download_kmc + make -C test/basic_app all + + - name: Run the test + run: python3 test.py diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 0c84c241..00000000 --- a/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM ubuntu:22.04 -RUN apt-get update -RUN apt install -y binutils-mips-linux-gnu -ADD https://github.com/decompals/mips-binutils-2.6/releases/download/main/binutils-2.6-linux.tar.gz . -ADD https://github.com/decompals/mips-gcc-2.7.2/releases/download/main/gcc-2.7.2-linux.tar.gz . -RUN mkdir -p ./gcc-2.7.2 && \ - tar -xvf gcc-2.7.2-linux.tar.gz -C ./gcc-2.7.2 && \ - tar -xvf binutils-2.6-linux.tar.gz -C ./gcc-2.7.2 diff --git a/run_tests.sh b/run_tests.sh deleted file mode 100644 index e57f8b3d..00000000 --- a/run_tests.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -# docker build container -docker build --tag splat-build:latest . && \ -# get compilers and tools -# clean -cd test/basic_app && sh clean.sh && cd ../../ && \ -# build -docker run --rm -v $(pwd):/splat -w /splat/test/basic_app splat-build sh build.sh && \ -# test -python3 test.py diff --git a/test.py b/test.py old mode 100644 new mode 100755 index 549c1121..8b0a3775 --- a/test.py +++ b/test.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + from spimdisasm.common import FileSectionType from split import * @@ -84,9 +86,9 @@ def test_basic_app(self): ): print(line) - assert len(diff_files) == 0 - assert len(left_only_files) == 0 - assert len(right_only_files) == 0 + assert len(diff_files) == 0, diff_files + assert len(left_only_files) == 0, left_only_files + assert len(right_only_files) == 0, right_only_files def test_init(): @@ -434,16 +436,16 @@ def test_overlay(self): yaml = { "name": "boot", "type": "code", - "start": 4096, - "vram": 2147484672, - "bss_size": 128, + "start": 0x1000, + "vram": 0x80000400, + "bss_size": 0x80, "exclusive_ram_id": "overlay", "subsegments": [ - [4096, "c", "main"], - [4336, "hasm", "handwritten"], - [4352, "data", "main"], - [4368, "rodata", "main"], - {"type": "bss", "vram": 2147484992, "name": "main"}, + [0x1000, "c", "main"], + [0x10F0, "hasm", "handwritten"], + [0x1100, "data", "main"], + [0x1110, ".rodata", "main"], + {"start": 0x1140, "type": "bss", "vram": 0x80000540, "name": "main"}, ], } @@ -477,16 +479,16 @@ def test_global(self): yaml = { "name": "boot", "type": "code", - "start": 4096, - "vram": 2147484672, - "bss_size": 128, + "start": 0x1000, + "vram": 0x80000400, + "bss_size": 0x80, "exclusive_ram_id": "overlay", "subsegments": [ - [4096, "c", "main"], - [4336, "hasm", "handwritten"], - [4352, "data", "main"], - [4368, "rodata", "main"], - {"type": "bss", "vram": 2147484992, "name": "main"}, + [0x1000, "c", "main"], + [0x10F0, "hasm", "handwritten"], + [0x1100, "data", "main"], + [0x1110, ".rodata", "main"], + {"start": 0x1140, "type": "bss", "vram": 0x80000540, "name": "main"}, ], } @@ -502,11 +504,11 @@ def test_global(self): ) ] - assert symbols.spim_context.globalSegment.vramStart == 2147483648 - assert symbols.spim_context.globalSegment.vramEnd == 2147487744 + assert symbols.spim_context.globalSegment.vramStart == 0x80000000 + assert symbols.spim_context.globalSegment.vramEnd == 0x80001000 symbols.initialize_spim_context(all_segments) - assert symbols.spim_context.globalSegment.vramStart == 256 - assert symbols.spim_context.globalSegment.vramEnd == 896 + assert symbols.spim_context.globalSegment.vramStart == 0x100 + assert symbols.spim_context.globalSegment.vramEnd == 0x380 if __name__ == "__main__": diff --git a/test/Dockerfile b/test/Dockerfile new file mode 100644 index 00000000..5e996a82 --- /dev/null +++ b/test/Dockerfile @@ -0,0 +1,3 @@ +FROM ubuntu:22.04 +RUN apt-get update +RUN apt install -y build-essential make binutils-mips-linux-gnu python3 python3-pip wget diff --git a/test/README.md b/test/README.md new file mode 100644 index 00000000..4f400128 --- /dev/null +++ b/test/README.md @@ -0,0 +1,43 @@ +# Test instructions + +## basic_app + +### Building the ROM + +You are expected to have a mips cross compiler installed on your system +(compatible with binutils). + +By default we use `mips-linux-gnu-`, but if you want to use a different +toolchain you can provide your own to `make` by passing the `CROSS=` option. +For example `make CROSS=mipsel-linux-gnu-`. + +To build the ROM: + +```bash +make -C test/basic_app clean +make -C test/basic_app download_kmc +make -C test/basic_app all +``` + +### Running the test + +Run `python3 test.py`. + +This script will check if the files were generated as expected or if anything +changed. Files changing may be good or bad depending on the changes made to the +repo. + +If changes are expected, then follow the instructions at +[Regenerate the expected files](#regenerate-the-expected-files). + +### Regenerate the expected files + +You need to have built the rom first. + +Run `test/test_gen_expected.sh` from the root of the repository and commit the +changes. + +## Docker + +There's a `Dockerfile`, but I don't know how to use Docker so I can't tell you +how to use it, shorry. diff --git a/test/basic_app/Makefile b/test/basic_app/Makefile new file mode 100644 index 00000000..739f31ff --- /dev/null +++ b/test/basic_app/Makefile @@ -0,0 +1,76 @@ +BUILD_FOLDER := build +KMC_FOLDER := gcc-2.7.2 +CROSS := mips-linux-gnu- + + +ROM := $(BUILD_FOLDER)/basic_app.bin + +## Programs + +CC := COMPILER_PATH=$(KMC_FOLDER) $(KMC_FOLDER)/gcc +LD := $(CROSS)ld +OBJCOPY := $(CROSS)objcopy + + +## Programs' flags + +CFLAGS := -G0 -mgp32 -mfp32 -mips3 + + +# Targets + +all: $(ROM) + +download_kmc: $(KMC_FOLDER)/gcc + +clean: + $(RM) -rf $(BUILD_FOLDER) + $(RM) -rf split + +.PHONY: all download_kmc clean +.DEFAULT_GOAL := all +# Prevent removing intermediate files +.SECONDARY: + + +## Files + +O_FILES := $(BUILD_FOLDER)/main.o $(BUILD_FOLDER)/header.o $(BUILD_FOLDER)/handwritten.o $(BUILD_FOLDER)/dummy_ipl3.o + +o_files: $(O_FILES) +.PHONY: o_files + +## Rules + +%.bin: %.elf + $(OBJCOPY) $< -O binary $@ --pad-to=0x1140 --gap-fill=0x00 + +$(BUILD_FOLDER)/%.elf: $(O_FILES) %.ld | $(BUILD_FOLDER) + $(LD) -Map $(@:.elf=.map) -T $*.ld -o $@ $(O_FILES) + +$(BUILD_FOLDER)/%.o: %.s | $(BUILD_FOLDER) + $(CC) -EB -c $(CFLAGS) -o $@ $< + +$(BUILD_FOLDER)/%.o: %.c | $(BUILD_FOLDER) + $(CC) -EB -c $(CFLAGS) -o $@ $< + + +$(KMC_FOLDER)/gcc: + $(RM) -rf $(KMC_FOLDER) + wget https://github.com/decompals/mips-binutils-2.6/releases/latest/download/binutils-2.6-linux.tar.gz + wget https://github.com/decompals/mips-gcc-2.7.2/releases/latest/download/gcc-2.7.2-linux.tar.gz + mkdir -p $(KMC_FOLDER) + tar -xvf binutils-2.6-linux.tar.gz -C $(KMC_FOLDER) + tar -xvf gcc-2.7.2-linux.tar.gz -C $(KMC_FOLDER) + $(RM) -rf binutils-2.6-linux.tar.gz + $(RM) -rf gcc-2.7.2-linux.tar.gz + + +## Folders to create + +$(BUILD_FOLDER): + mkdir -p $(BUILD_FOLDER) + + +# Print target for debugging +print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true diff --git a/test/basic_app/build.sh b/test/basic_app/build.sh deleted file mode 100755 index 0eb0ff12..00000000 --- a/test/basic_app/build.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -set -e - -mkdir -p build -echo "Building..." -export PATH=/gcc-2.7.2:$PATH -COMPILER_PATH=/gcc-2.7.2 /gcc-2.7.2/gcc -v -G0 -mgp32 -mfp32 -mips3 main.c -c -o build/main.o -COMPILER_PATH=/gcc-2.7.2 /gcc-2.7.2/gcc -G0 -mgp32 -mfp32 -mips3 header.s -c -o build/header.o -COMPILER_PATH=/gcc-2.7.2 /gcc-2.7.2/gcc -G0 -mgp32 -mfp32 -mips3 handwritten.s -c -o build/handwritten.o -COMPILER_PATH=/gcc-2.7.2 /gcc-2.7.2/gcc -G0 -mgp32 -mfp32 -mips3 dummy_ipl3.s -c -o build/dummy_ipl3.o -mips-linux-gnu-strip -N dummy_symbol_name build/*.o -echo "Linking..." -mips-linux-gnu-ld -Map build/basic_app.map -T basic_app.ld -o build/basic_app.elf -echo "Dumping bin..." -mips-linux-gnu-objcopy build/basic_app.elf -O binary build/basic_app.bin --pad-to=0x1140 --gap-fill=0xFF diff --git a/test/basic_app/clean.sh b/test/basic_app/clean.sh deleted file mode 100644 index 2fcd367d..00000000 --- a/test/basic_app/clean.sh +++ /dev/null @@ -1,2 +0,0 @@ -rm -rf ./build -rm -rf ./split diff --git a/test/basic_app/expected/.splache b/test/basic_app/expected/.splache index 8f17e1346d9d9c6db088cba47eea6df7b4dd8fb7..20e2fdd53fa1d64fd80ba58a9162cf1118f4c572 100644 GIT binary patch delta 91 zcmbQpwvLUZfn}=lMwY9L{5{*eM#dQ#2<3 PWYXpm5Cn^)mg)fj!&w(7 diff --git a/test/basic_app/expected/asm/data/main.bss.s b/test/basic_app/expected/asm/data/main.bss.s index 96a20c23..8cd08e41 100644 --- a/test/basic_app/expected/asm/data/main.bss.s +++ b/test/basic_app/expected/asm/data/main.bss.s @@ -3,4 +3,4 @@ .section .bss glabel D_80000540 -/* 1110 80000540 */ .space 0x78 +/* 1140 80000540 */ .space 0x80 diff --git a/test/basic_app/expected/asm/nonmatchings/main/D_80000510.s b/test/basic_app/expected/asm/nonmatchings/main/D_80000510.s new file mode 100644 index 00000000..e5d57521 --- /dev/null +++ b/test/basic_app/expected/asm/nonmatchings/main/D_80000510.s @@ -0,0 +1,8 @@ +.include "macro.inc" + +.section .rodata + +glabel D_80000510 +/* 1110 80000510 00010203 */ .word 0x00010203 +/* 1114 80000514 04050607 */ .word 0x04050607 +.size D_80000510, . - D_80000510 diff --git a/test/basic_app/expected/asm/nonmatchings/main/func_80000400.s b/test/basic_app/expected/asm/nonmatchings/main/func_80000400.s index 21d0010c..3788a876 100644 --- a/test/basic_app/expected/asm/nonmatchings/main/func_80000400.s +++ b/test/basic_app/expected/asm/nonmatchings/main/func_80000400.s @@ -1,6 +1,23 @@ .set noat /* allow manual use of $at */ .set noreorder /* don't insert nops after branches */ +.section .rodata +.align 3 +glabel jtbl_80000518 +/* 1118 80000518 80000448 */ .word .L80000448 +/* 111C 8000051C 80000450 */ .word .L80000450 +/* 1120 80000520 80000458 */ .word .L80000458 +/* 1124 80000524 80000460 */ .word .L80000460 +/* 1128 80000528 80000468 */ .word .L80000468 +/* 112C 8000052C 80000470 */ .word .L80000470 +/* 1130 80000530 80000478 */ .word .L80000478 +/* 1134 80000534 80000480 */ .word .L80000480 +/* 1138 80000538 00000000 */ .word 0x00000000 +/* 113C 8000053C 00000000 */ .word 0x00000000 +.size jtbl_80000518, . - jtbl_80000518 + + +.section .text glabel func_80000400 /* 1000 80000400 27BDFFF8 */ addiu $sp, $sp, -0x8 /* 1004 80000404 AFBE0000 */ sw $fp, 0x0($sp) @@ -20,28 +37,28 @@ glabel func_80000400 /* 103C 8000043C 8C430000 */ lw $v1, 0x0($v0) /* 1040 80000440 00600008 */ jr $v1 /* 1044 80000444 00000000 */ nop -glabel .L80000448 +.L80000448: /* 1048 80000448 08000124 */ j .L80000490 /* 104C 8000044C 24020007 */ addiu $v0, $zero, 0x7 -glabel .L80000450 +.L80000450: /* 1050 80000450 08000124 */ j .L80000490 /* 1054 80000454 24020006 */ addiu $v0, $zero, 0x6 -glabel .L80000458 +.L80000458: /* 1058 80000458 08000124 */ j .L80000490 /* 105C 8000045C 24020005 */ addiu $v0, $zero, 0x5 -glabel .L80000460 +.L80000460: /* 1060 80000460 08000124 */ j .L80000490 /* 1064 80000464 24020004 */ addiu $v0, $zero, 0x4 -glabel .L80000468 +.L80000468: /* 1068 80000468 08000124 */ j .L80000490 /* 106C 8000046C 24020003 */ addiu $v0, $zero, 0x3 -glabel .L80000470 +.L80000470: /* 1070 80000470 08000124 */ j .L80000490 /* 1074 80000474 24020002 */ addiu $v0, $zero, 0x2 -glabel .L80000478 +.L80000478: /* 1078 80000478 08000124 */ j .L80000490 /* 107C 8000047C 24020001 */ addiu $v0, $zero, 0x1 -glabel .L80000480 +.L80000480: /* 1080 80000480 08000124 */ j .L80000490 /* 1084 80000484 00001021 */ addu $v0, $zero, $zero .L80000488: diff --git a/test/basic_app/expected/basic_app.ld b/test/basic_app/expected/basic_app.ld index 57ec4ae9..16e6221e 100644 --- a/test/basic_app/expected/basic_app.ld +++ b/test/basic_app/expected/basic_app.ld @@ -8,8 +8,8 @@ SECTIONS { FILL(0x00000000); header_DATA_START = .; - header_s = .; - build/split/asm/header.s.o(.data); + header = .; + build/split/asm/header.o(.data); header_DATA_END = .; header_DATA_SIZE = ABSOLUTE(header_DATA_END - header_DATA_START); } @@ -23,8 +23,8 @@ SECTIONS { FILL(0x00000000); dummy_ipl3_DATA_START = .; - dummy_ipl3_bin = .; - build/split/assets/dummy_ipl3.bin.o(.data); + dummy_ipl3 = .; + build/split/assets/dummy_ipl3.o(.data); . = ALIGN(., 16); dummy_ipl3_DATA_END = .; dummy_ipl3_DATA_SIZE = ABSOLUTE(dummy_ipl3_DATA_END - dummy_ipl3_DATA_START); @@ -41,19 +41,19 @@ SECTIONS { FILL(0x00000000); boot_TEXT_START = .; - build/split/src/main.c.o(.text); - build/split/asm/handwritten.s.o(.text); + build/split/src/main.o(.text); + build/split/asm/handwritten.o(.text); . = ALIGN(., 16); boot_TEXT_END = .; boot_TEXT_SIZE = ABSOLUTE(boot_TEXT_END - boot_TEXT_START); boot_DATA_START = .; - main_data__s = .; - build/split/asm/data/main.data.s.o(.data); + main_data = .; + build/split/asm/data/main.data.o(.data); . = ALIGN(., 16); boot_DATA_END = .; boot_DATA_SIZE = ABSOLUTE(boot_DATA_END - boot_DATA_START); boot_RODATA_START = .; - build/split/asm/data/main.rodata.s.o(.rodata); + build/split/src/main.o(.rodata); . = ALIGN(., 16); boot_RODATA_END = .; boot_RODATA_SIZE = ABSOLUTE(boot_RODATA_END - boot_RODATA_START); @@ -63,7 +63,7 @@ SECTIONS { FILL(0x00000000); boot_BSS_START = .; - build/split/asm/data/main.bss.s.o(.bss); + build/split/asm/data/main.bss.o(.bss); . = ALIGN(., 16); boot_BSS_END = .; boot_BSS_SIZE = ABSOLUTE(boot_BSS_END - boot_BSS_START); diff --git a/test/basic_app/expected/src/main.c b/test/basic_app/expected/src/main.c index 41b2e705..9c22d6e6 100644 --- a/test/basic_app/expected/src/main.c +++ b/test/basic_app/expected/src/main.c @@ -1,5 +1,7 @@ #include "common.h" +INCLUDE_RODATA(const s32, "main", D_80000510); + INCLUDE_ASM(const s32, "main", func_80000400); INCLUDE_ASM(const s32, "main", func_800004A0); diff --git a/test/basic_app/expected/undefined_syms_auto.txt b/test/basic_app/expected/undefined_syms_auto.txt index 8b96b0cd..e69de29b 100644 --- a/test/basic_app/expected/undefined_syms_auto.txt +++ b/test/basic_app/expected/undefined_syms_auto.txt @@ -1 +0,0 @@ -jtbl_80000518 = 0x80000518; diff --git a/test/basic_app/main.c b/test/basic_app/main.c index cf119f7c..9a333314 100644 --- a/test/basic_app/main.c +++ b/test/basic_app/main.c @@ -10,7 +10,7 @@ unsigned long long bss_data[0x10]; // .data volatile int switch_arg = 0; -int do_switch() +int do_switch(void) { switch(switch_arg) { @@ -29,13 +29,13 @@ int do_switch() case 6: return 1; case 7: - return 0; + return 0; } return 0; } // c -void bootproc() +void bootproc(void) { do_switch(); for (;;) diff --git a/test/basic_app/splat.yaml b/test/basic_app/splat.yaml index d4d4a41c..e02695d6 100644 --- a/test/basic_app/splat.yaml +++ b/test/basic_app/splat.yaml @@ -13,6 +13,7 @@ options: undefined_syms_auto_path: split/undefined_syms_auto.txt asset_path: split/assets compiler: GCC + o_as_suffix: True segments: - name: header type: header @@ -32,6 +33,6 @@ segments: - [0x1000, c, main] - [0x10F0, hasm, handwritten] - [0x1100, data, main] - - [0x1110, rodata, main] - - { type: bss, vram: 0x80000540, name: main } - - [0x1138] + - [0x1110, .rodata, main] + - { start: 0x1140, type: bss, vram: 0x80000540, name: main } + - [0x1140] diff --git a/test/test_gen_expected.sh b/test/test_gen_expected.sh new file mode 100755 index 00000000..e0e27570 --- /dev/null +++ b/test/test_gen_expected.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e + +export SPIMDISASM_ASM_GENERATED_BY="False" + +# Ensure we start from a clean state +rm -rf test/basic_app/split + +python3 ./split.py test/basic_app/splat.yaml --use-cache + +rm -rf test/basic_app/expected +cp -r test/basic_app/split test/basic_app/expected diff --git a/test_gen_expected.sh b/test_gen_expected.sh deleted file mode 100644 index 1b4a629a..00000000 --- a/test_gen_expected.sh +++ /dev/null @@ -1,3 +0,0 @@ -docker run --rm -it -v $(pwd):/splat -w /splat/test/basic_app splat-build sh build.sh && \ -rm -rf $(pwd)/test/basic_app/expected && \ -cp -r $(pwd)/test/basic_app/split $(pwd)/test/basic_app/expected