Skip to content

Commit

Permalink
Rework tests a little bit (#318)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
AngheloAlf authored Dec 24, 2023
1 parent 46729c5 commit bf661e7
Show file tree
Hide file tree
Showing 20 changed files with 229 additions and 98 deletions.
25 changes: 16 additions & 9 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 0 additions & 8 deletions Dockerfile

This file was deleted.

11 changes: 0 additions & 11 deletions run_tests.sh

This file was deleted.

48 changes: 25 additions & 23 deletions test.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3

from spimdisasm.common import FileSectionType

from split import *
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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"},
],
}

Expand Down Expand Up @@ -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"},
],
}

Expand All @@ -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__":
Expand Down
3 changes: 3 additions & 0 deletions test/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -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.
76 changes: 76 additions & 0 deletions test/basic_app/Makefile
Original file line number Diff line number Diff line change
@@ -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
16 changes: 0 additions & 16 deletions test/basic_app/build.sh

This file was deleted.

2 changes: 0 additions & 2 deletions test/basic_app/clean.sh

This file was deleted.

Binary file modified test/basic_app/expected/.splache
Binary file not shown.
2 changes: 1 addition & 1 deletion test/basic_app/expected/asm/data/main.bss.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
.section .bss

glabel D_80000540
/* 1110 80000540 */ .space 0x78
/* 1140 80000540 */ .space 0x80
8 changes: 8 additions & 0 deletions test/basic_app/expected/asm/nonmatchings/main/D_80000510.s
Original file line number Diff line number Diff line change
@@ -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
33 changes: 25 additions & 8 deletions test/basic_app/expected/asm/nonmatchings/main/func_80000400.s
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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:
Expand Down
Loading

0 comments on commit bf661e7

Please sign in to comment.