Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby committed Aug 3, 2024
1 parent 93f6421 commit a1aefe4
Show file tree
Hide file tree
Showing 18 changed files with 437 additions and 39 deletions.
9 changes: 8 additions & 1 deletion crates/fpvm/open_mips_tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,12 @@ OpenMIPS is licensed LGPLv3 (as seen in the root of the repository), see [`LICEN
Note that some build-system files from 2014/2015 in that repository by the same author are marked as BSD licensed,
but the build-system is not used here.

Requires https://github.com/sergev/LiteBSD/releases/download/tools/gcc-4.8.1-mips-macosx.tgz to build
## Building

**Requirements**:

- Docker

```sh
just make-tests
```
19 changes: 19 additions & 0 deletions crates/fpvm/open_mips_tests/builder.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM --platform=linux/amd64 ubuntu:22.04

ENV SHELL=/bin/bash
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update && apt-get install --assume-yes --no-install-recommends \
ca-certificates \
build-essential \
curl \
g++-mips-linux-gnu \
libc6-dev-mips-cross \
binutils-mips-linux-gnu \
llvm \
clang \
python3 \
python3-pip \
xxd

RUN python3 -m pip install capstone pyelftools
23 changes: 23 additions & 0 deletions crates/fpvm/open_mips_tests/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
set positional-arguments := true

help:
just --list

# Build the MIPS64 test case assembler image
build-image:
#!/bin/bash
docker build -f builder.dockerfile -t mips-test-builder:local .

# Assemble the test cases
make-tests *args='':
#!/bin/bash
if [ ! "$(docker images -q mips-test-builder:local 2> /dev/null)" ]; then
just build-image
fi

docker run \
--rm \
--platform linux/amd64 \
-v `pwd`/:/workdir \
-w="/workdir" \
mips-test-builder:local bash make_tests.sh {{args}}
42 changes: 42 additions & 0 deletions crates/fpvm/open_mips_tests/make_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

set -e

function maketest() {
local src="$1"
local out="$2"

printf "building %s -> %s" "$src" "$out"

# Create a temporary file
full_bin=$(mktemp)

# Assemble the full test vector
mips-linux-gnu-as -defsym big_endian=1 -march=mips64 -o "$full_bin" "$src"

# Copy the `.test` section data to a temporary file
section_data=$(mktemp)
mips-linux-gnu-objcopy --dump-section .test="$section_data" "$full_bin"

# Write the .test section data to the output file
cp "$section_data" "$out"

# Clean up the temporary files
rm "$full_bin" "$section_data"

printf " ✅\n"
}

mkdir -p /tmp/mips

if [ "$#" -gt 0 ]; then
maketest "$1" "test/bin/$(basename "$1" .asm).bin"
else
for d in test/*.asm;
do
[ -e "$d" ] || continue
maketest "$d" "test/bin/$(basename "$d" .asm).bin"
done

echo "[🧙] All tests built successfully. God speed, space cowboy."
fi
37 changes: 0 additions & 37 deletions crates/fpvm/open_mips_tests/maketests.py

This file was deleted.

Binary file added crates/fpvm/open_mips_tests/test/bin/dadd.bin
Binary file not shown.
Binary file added crates/fpvm/open_mips_tests/test/bin/daddi.bin
Binary file not shown.
Binary file added crates/fpvm/open_mips_tests/test/bin/daddiu.bin
Binary file not shown.
Binary file added crates/fpvm/open_mips_tests/test/bin/daddu.bin
Binary file not shown.
Binary file added crates/fpvm/open_mips_tests/test/bin/dsub.bin
Binary file not shown.
Binary file added crates/fpvm/open_mips_tests/test/bin/dsubu.bin
Binary file not shown.
58 changes: 58 additions & 0 deletions crates/fpvm/open_mips_tests/test/dadd.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
###############################################################################
# File : dadd.asm
# Author: : clabby (github.com/clabby)
#
# Standards/Formatting:
# MIPS gas, soft tab, 80 column
#
# Description:
# Test the functionality of the 'dadd' instruction.
#
###############################################################################


.section .test, "x"
.balign 4
.set noreorder
.global test
.ent test
test:
lui $s0, 0xbfff # Load the base address 0xbffffff0
ori $s0, 0xfff0
ori $s1, $0, 1 # Prepare the 'done' status

#### Test code start ####

# Check that overflow is detected
lui $t0, 0xffff # Load upper 48 bits into $t0 (0xFFFF_FFFF_FFFF_0000) - (top 32 bits are sign extended)
ori $t0, 0xfffd # Load lower 16 bits into $t0 (0xFFFF_FFFF_FFFF_FFFD)
ori $t1, $0, 0x3 # B = 0x3
dadd $t2, $t0, $t1 # C = A + B = 0
bne $t2, $0, $finish # If C != 0, fail
nop

# Add standard unsigned 64-bit numbers, no overflow
lui $t3, 0xffff # Load upper 48 bits into $t3 (0xFFFF_FFFF_FFFF_0000) - (top 32 bits are sign extended)
ori $t3, $t3, 0x3 # Load lower 16 bits into $t3 (0xFFFF_FFFF_FFFF_0003)

dsrl $t0, $t0, 16 # Shift $t0 right by 16 bits (0x0000_FFFF_FFFF_FFFF)
dsll $t0, $t0, 16 # Shift $t0 left by 16 bits (0xFFFF_FFFF_FFFF_0000)
ori $t1, $0, 0x3 # B = 0x3
dadd $t2, $t0, $t1 # C = A + B = 0xFFFF_FFFF_FFFF_0003
bne $t2, $t3, $finish # If C != 0xFFFF_FFFF_FFFF_0003, fail
nop

# Set success flag
ori $v0, $0, 1 # Set test result to success

#### Test code end ####

$finish:
sw $v0, 8($s0) # Set the test result
sw $s1, 4($s0) # Set 'done'

$done:
jr $ra
nop

.end test
56 changes: 56 additions & 0 deletions crates/fpvm/open_mips_tests/test/daddi.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
###############################################################################
# File : daddi.asm
# Author: : clabby (github.com/clabby)
#
# Standards/Formatting:
# MIPS gas, soft tab, 80 column
#
# Description:
# Test the functionality of the 'daddi' instruction.
#
###############################################################################


.section .test, "x"
.balign 4
.set noreorder
.global test
.ent test
test:
lui $s0, 0xbfff # Load the base address 0xbffffff0
ori $s0, 0xfff0
ori $s1, $0, 1 # Prepare the 'done' status

#### Test code start ####

# Check that overflow is detected
lui $t0, 0xffff # Load upper 48 bits into $t0 (0xFFFF_FFFF_FFFF_0000) - (top 32 bits are sign extended)
ori $t0, 0xfffd # Load lower 16 bits into $t0 (0xFFFF_FFFF_FFFF_FFFD)
daddi $t1, $t0, 0x3 # B = A + 3 = 0
bne $t1, $0, $finish # If B != 0, fail
nop

# Add standard unsigned 64-bit numbers, no overflow
lui $t2, 0xffff # Load upper 48 bits into $t3 (0xFFFF_FFFF_FFFF_0000) - (top 32 bits are sign extended)
ori $t2, $t2, 0x3 # Load lower 16 bits into $t3 (0xFFFF_FFFF_FFFF_0003)

dsrl $t0, $t0, 16 # Shift $t0 right by 16 bits (0x0000_FFFF_FFFF_FFFF)
dsll $t0, $t0, 16 # Shift $t0 left by 16 bits (0xFFFF_FFFF_FFFF_0000)
daddi $t1, $t0, 0x3 # B = A + 3 = 0xFFFF_FFFF_FFFF_0003
bne $t1, $t2, $finish # If B != 0xFFFF_FFFF_FFFF_0003, fail
nop

# Set success flag
ori $v0, $0, 1 # Set test result to success

#### Test code end ####

$finish:
sw $v0, 8($s0) # Set the test result
sw $s1, 4($s0) # Set 'done'

$done:
jr $ra
nop

.end test
56 changes: 56 additions & 0 deletions crates/fpvm/open_mips_tests/test/daddiu.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
###############################################################################
# File : daddiu.asm
# Author: : clabby (github.com/clabby)
#
# Standards/Formatting:
# MIPS gas, soft tab, 80 column
#
# Description:
# Test the functionality of the 'daddiu' instruction.
#
###############################################################################


.section .test, "x"
.balign 4
.set noreorder
.global test
.ent test
test:
lui $s0, 0xbfff # Load the base address 0xbffffff0
ori $s0, 0xfff0
ori $s1, $0, 1 # Prepare the 'done' status

#### Test code start ####

# Check that overflow is detected
lui $t0, 0xffff # Load upper 48 bits into $t0 (0xFFFF_FFFF_FFFF_0000) - (top 32 bits are sign extended)
ori $t0, 0xfffd # Load lower 16 bits into $t0 (0xFFFF_FFFF_FFFF_FFFD)
daddiu $t1, $t0, 0x3 # B = A + 3 = 0
bne $t1, $0, $finish # If B != 0, fail
nop

# Add standard unsigned 64-bit numbers, no overflow
lui $t2, 0xffff # Load upper 48 bits into $t3 (0xFFFF_FFFF_FFFF_0000) - (top 32 bits are sign extended)
ori $t2, $t2, 0x3 # Load lower 16 bits into $t3 (0xFFFF_FFFF_FFFF_0003)

dsrl $t0, $t0, 16 # Shift $t0 right by 16 bits (0x0000_FFFF_FFFF_FFFF)
dsll $t0, $t0, 16 # Shift $t0 left by 16 bits (0xFFFF_FFFF_FFFF_0000)
daddiu $t1, $t0, 0x3 # B = A + 3 = 0xFFFF_FFFF_FFFF_0003
bne $t1, $t2, $finish # If B != 0xFFFF_FFFF_FFFF_0003, fail
nop

# Set success flag
ori $v0, $0, 1 # Set test result to success

#### Test code end ####

$finish:
sw $v0, 8($s0) # Set the test result
sw $s1, 4($s0) # Set 'done'

$done:
jr $ra
nop

.end test
58 changes: 58 additions & 0 deletions crates/fpvm/open_mips_tests/test/daddu.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
###############################################################################
# File : daddu.asm
# Author: : clabby (github.com/clabby)
#
# Standards/Formatting:
# MIPS gas, soft tab, 80 column
#
# Description:
# Test the functionality of the 'daddu' instruction.
#
###############################################################################


.section .test, "x"
.balign 4
.set noreorder
.global test
.ent test
test:
lui $s0, 0xbfff # Load the base address 0xbffffff0
ori $s0, 0xfff0
ori $s1, $0, 1 # Prepare the 'done' status

#### Test code start ####

# Check that overflow is detected
lui $t0, 0xffff # Load upper 48 bits into $t0 (0xFFFF_FFFF_FFFF_0000) - (top 32 bits are sign extended)
ori $t0, 0xfffd # Load lower 16 bits into $t0 (0xFFFF_FFFF_FFFF_FFFD)
ori $t1, $0, 0x3 # B = 0x3
daddu $t2, $t0, $t1 # C = A + B = 0
bne $t2, $0, $finish # If C != 0, fail
nop

# Add standard unsigned 64-bit numbers, no overflow
lui $t3, 0xffff # Load upper 48 bits into $t3 (0xFFFF_FFFF_FFFF_0000) - (top 32 bits are sign extended)
ori $t3, $t3, 0x3 # Load lower 16 bits into $t3 (0xFFFF_FFFF_FFFF_0003)

dsrl $t0, $t0, 16 # Shift $t0 right by 16 bits (0x0000_FFFF_FFFF_FFFF)
dsll $t0, $t0, 16 # Shift $t0 left by 16 bits (0xFFFF_FFFF_FFFF_0000)
ori $t1, $0, 0x3 # B = 0x3
daddu $t2, $t0, $t1 # C = A + B = 0xFFFF_FFFF_FFFF_0003
bne $t2, $t3, $finish # If C != 0xFFFF_FFFF_FFFF_0003, fail
nop

# Set success flag
ori $v0, $0, 1 # Set test result to success

#### Test code end ####

$finish:
sw $v0, 8($s0) # Set the test result
sw $s1, 4($s0) # Set 'done'

$done:
jr $ra
nop

.end test
Loading

0 comments on commit a1aefe4

Please sign in to comment.