9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit fc7ec07fdb7c1ba4ee2e53ab8fb777d59dadfbf9
parent 5de3a67adb01dcfa8f03550f3cdf4e3d5040d6e6
Author: Roberto E. Vargas Caballero <roberto@clue.aero>
Date:   Tue, 13 Aug 2019 09:24:02 +0200

[test/unit] Remove test002 and fix multiple errors

Test002 is not useful anymore and since the unit
tests were not maintained they had a lot of errors.
After this patch they are not still working but they
are in a bit better shape than they were.

Change-Id: I42a132bd6274915939d4507f768f6dfd14b73ef3

Diffstat:
Mtest/unit/001/Makefile | 8++++----
Mtest/unit/001/test.c | 5++---
Mtest/unit/002/Makefile | 9+++++----
Mtest/unit/002/descr | 2+-
Mtest/unit/002/test.c | 189++++++-------------------------------------------------------------------------
Dtest/unit/002/test.exp | 256-------------------------------------------------------------------------------
Mtest/unit/002/test.sh | 6+-----
Mtest/unit/003/Makefile | 4++--
Mtest/unit/003/descr | 2+-
Mtest/unit/003/test.c | 43++++++++++++++++++++++++++++++-------------
Rtest/unit/004/test.exp -> test/unit/003/test.exp | 0
Mtest/unit/003/test.sh | 6+++++-
Dtest/unit/004/Makefile | 16----------------
Dtest/unit/004/descr | 1-
Dtest/unit/004/test.c | 54------------------------------------------------------
Dtest/unit/004/test.sh | 9---------
Mtest/unit/Makefile | 2+-
17 files changed, 65 insertions(+), 547 deletions(-)

diff --git a/test/unit/001/Makefile b/test/unit/001/Makefile @@ -72,12 +72,12 @@ LIBOBJ = hdl_RMU_System_InterfaceVersion.o \ hdl_RMU_Granule_ImportInit.o \ hdl_RMU_Granule_Import.o \ -ROMOBJS = $(TARGETDIR)/crt/crt.o \ +ROMOBJS = $(LIBDIR)/crt.o \ $(TARGETDIR)/arch.o \ $(SRCDIR)/romfw/builtin.o \ test.o \ -RAMOBJS = $(TARGETDIR)/crt/crt.o \ +RAMOBJS = $(LIBDIR)/crt.o \ $(TARGETDIR)/arch.o \ $(SRCDIR)/ramfw/builtin.o \ test.o \ @@ -90,10 +90,10 @@ all: rmu run: $(TARGET) romfw: $(ROMOBJS) $(LIBDEP) libhdl.a - $(LD) -L. $(RCODE_LDFLAGS) $(ROMOBJS) $(RCODE_LDLIBS) -o $@ + $(LD) -L. $(PROJ_LDFLAGS) $(ROMOBJS) $(PROJ_LDLIBS) -o $@ ramfw: $(RAMOBJS) $(LIBDEP) libhdl.a - $(LD) -L. $(RCODE_LDFLAGS) $(RAMOBJS) $(RCODE_LDLIBS) -o $@ + $(LD) -L. $(PROJ_LDFLAGS) $(RAMOBJS) $(PROJ_LDLIBS) -o $@ libhdl.a: $(LIBOBJ) $(AR) $(ARFLAGS) $@ $? diff --git a/test/unit/001/test.c b/test/unit/001/test.c @@ -4,7 +4,7 @@ #include <stdlib.h> #include <libk.h> -#include <rcode.h> +#include <rcode/rcode.h> #include "../../../target/hosted/hosted.h" @@ -16,12 +16,11 @@ main(int argc, char *argv[]) unsigned i, j; Rmucmd cmd; - bss->fp = &frame; for (i = 0; i < 256; i++) { for (j = 0; j < 256; j++) { + cmd.fp = &frame; cmd.class = i; cmd.func = j; - bss->cmd = &cmd; dbg(kout, "%u\t%u\t", i, j); if (!setjmp(recover)) rmc(&cmd); diff --git a/test/unit/002/Makefile b/test/unit/002/Makefile @@ -3,13 +3,14 @@ PROJECTDIR = ../../.. include $(PROJECTDIR)/scripts/rules.mk include ../rules.mk -OBJS = $(TARGETDIR)/crt/crt.o test.o -LIBS = -ltypes -lc -LIBDEP = $(LIBDIR)/libtypes.a $(LIBDIR)/libc.a +OBJS = $(LIBDIR)/crt.o \ + $(TARGETDIR)/arch.o \ + $(SRCDIR)/romfw/builtin.o \ + test.o \ TARGET = run all: $(TARGET) $(TARGET): $(OBJS) $(LIBDEP) - $(LD) $(RCODE_LDFLAGS) $(OBJS) $(RCODE_LDLIBS) -o $@ + $(LD) $(PROJ_LDFLAGS) $(OBJS) $(PROJ_LDLIBS) -o $@ diff --git a/test/unit/002/descr b/test/unit/002/descr @@ -1 +1 @@ -Test various combinations of pack/unpack functions +Test RMU_System_InterfaceVersion() diff --git a/test/unit/002/test.c b/test/unit/002/test.c @@ -1,189 +1,26 @@ #include <assert.h> -#include <limits.h> +#include <setjmp.h> #include <stdio.h> -#include <stdint.h> #include <stdlib.h> -#include <string.h> -#include <types.h> +#include <rcode/rcode.h> -#define ITER 1048576*4 +#include "../../../src/romfw/ec.h" +#include "../../../target/hosted/hosted.h" -void -test_pack(void) -{ - uint64_t buf[2]; - unsigned long long v1 = 1, v2 = 0, msb; - int i; - - for (i = 0; i < 128; i++) { - pack(buf, "%64llu %64llu", v1, v2); - printf("0x%llx 0x%llx\n", buf[1], buf[0]); - msb = v1 & 1ull << 63; - v1 <<= 1; - v2 <<= 1; - v2 |= msb != 0; - } -} - -void -test_unpack(void) -{ - uint64_t buf[2]; - unsigned long long v1 = 1, v2 = 0, msb; - int i; - - buf[0] = 1; - buf[1] = 0; - for (i = 0; i < 128; i++) { - unpack(buf, "%64llu %64llu", &v1, &v2); - printf("0x%llx 0x%llx\n", v2, v1); - msb = buf[0] & 1ull << 63; - buf[0] <<= 1; - buf[1] <<= 1; - buf[1] |= msb != 0; - } -} - -long long -rand64(void) -{ - unsigned long long v, i; - - for (v = i = 0; i < sizeof(v); i++) { - v <<= CHAR_BIT; - v |= rand() % UCHAR_MAX; - } - return v; -} - -void -test_pack_unpack_c(uint64_t buf[]) -{ - char fmt[32]; - unsigned char v1, v2, v3, v4; - int b1, b2; - - v1 = rand64(); - v2 = rand64(); - b1 = (rand() % 8) + 1; - b2 = (rand() % 8) + 1; - v1 &= ~(~0ull << b1); - v2 &= ~(~0ull << b2); - snprintf(fmt, sizeof(fmt), "%%%dc %%%dc", b1, b2); - assert(pack(buf, fmt, v1, v2) != -1); - assert(unpack(buf, fmt, &v3, &v4) != -1); - assert(v1 == v3 && v2 == v4); -} - -void -test_pack_unpack_h(uint64_t buf[]) -{ - char fmt[32]; - unsigned short v1, v2, v3, v4; - int b1, b2; +struct trapframe frame; - v1 = rand64(); - v2 = rand64(); - b1 = (rand() % 16) + 1; - b2 = (rand() % 16) + 1; - v1 &= ~(~0ull << b1); - v2 &= ~(~0ull << b2); - snprintf(fmt, sizeof(fmt), "%%%dhu %%%dhu", b1, b2); - assert(pack(buf, fmt, v1, v2) != -1); - assert(unpack(buf, fmt, &v3, &v4) != -1); - assert(v1 == v3 && v2 == v4); -} - -void -test_pack_unpack_u(uint64_t buf[]) -{ - char fmt[32]; - unsigned int v1, v2, v3, v4; - int b1, b2; - - v1 = rand64(); - v2 = rand64(); - b1 = (rand() % 16) + 1; - b2 = (rand() % 16) + 1; - v1 &= ~(~0ull << b1); - v2 &= ~(~0ull << b2); - snprintf(fmt, sizeof(fmt), "%%%du %%%du", b1, b2); - assert(pack(buf, fmt, v1, v2) != -1); - assert(unpack(buf, fmt, &v3, &v4) != -1); - assert(v1 == v3 && v2 == v4); -} - -void -test_pack_unpack_lu(uint64_t buf[]) -{ - char fmt[32]; - unsigned long v1, v2, v3, v4; - int b1, b2; - - v1 = rand64(); - v2 = rand64(); - b1 = (rand() % 32) + 1; - b2 = (rand() % 32) + 1; - v1 &= ~(~0ull << b1); - v2 &= ~(~0ull << b2); - snprintf(fmt, sizeof(fmt), "%%%dlu %%%dlu", b1, b2); - assert(pack(buf, fmt, v1, v2) != -1); - assert(unpack(buf, fmt, &v3, &v4) != -1); - assert(v1 == v3 && v2 == v4); -} - -void -test_pack_unpack_llu(uint64_t buf[]) +int +main(void) { - char fmt[32]; - unsigned long long v1, v2, v3, v4; - int b1, b2; - - v1 = rand64(); - v2 = rand64(); - b1 = (rand() % 64) + 1; - b2 = (rand() % 64) + 1; - v1 &= ~(~0ull << b1); - v2 &= ~(~0ull << b2); - snprintf(fmt, sizeof(fmt), "%%%dllu %%%dllu", b1, b2); - assert(pack(buf, fmt, v1, v2) != -1); - assert(unpack(buf, fmt, &v3, &v4) != -1); - assert(v1 == v3 && v2 == v4); -} + frame.r[ESR] = RMC << 26; /* class = func = 0 */ -void -test_pack_unpack(void) -{ - uint64_t buf[2] = { 0 }; - unsigned long long i; + if (!setjmp(recover)) + trap(&frame); - for (i = 0; i < ITER; i++) { - switch (rand() % 5) { - case 0: - test_pack_unpack_c(buf); - break; - case 1: - test_pack_unpack_h(buf); - break; - case 2: - test_pack_unpack_u(buf); - break; - case 3: - test_pack_unpack_lu(buf); - break; - case 4: - test_pack_unpack_llu(buf); - break; - } - } -} + assert(frame.r[X0] == 0); + assert(frame.r[X1] == 0); + assert(frame.r[X2] == 1); -int -main(int argc, char *argv[]) -{ - test_pack(); - test_unpack(); - test_pack_unpack(); return 0; } diff --git a/test/unit/002/test.exp b/test/unit/002/test.exp @@ -1,256 +0,0 @@ -0x0 0x1 -0x0 0x2 -0x0 0x4 -0x0 0x8 -0x0 0x10 -0x0 0x20 -0x0 0x40 -0x0 0x80 -0x0 0x100 -0x0 0x200 -0x0 0x400 -0x0 0x800 -0x0 0x1000 -0x0 0x2000 -0x0 0x4000 -0x0 0x8000 -0x0 0x10000 -0x0 0x20000 -0x0 0x40000 -0x0 0x80000 -0x0 0x100000 -0x0 0x200000 -0x0 0x400000 -0x0 0x800000 -0x0 0x1000000 -0x0 0x2000000 -0x0 0x4000000 -0x0 0x8000000 -0x0 0x10000000 -0x0 0x20000000 -0x0 0x40000000 -0x0 0x80000000 -0x0 0x100000000 -0x0 0x200000000 -0x0 0x400000000 -0x0 0x800000000 -0x0 0x1000000000 -0x0 0x2000000000 -0x0 0x4000000000 -0x0 0x8000000000 -0x0 0x10000000000 -0x0 0x20000000000 -0x0 0x40000000000 -0x0 0x80000000000 -0x0 0x100000000000 -0x0 0x200000000000 -0x0 0x400000000000 -0x0 0x800000000000 -0x0 0x1000000000000 -0x0 0x2000000000000 -0x0 0x4000000000000 -0x0 0x8000000000000 -0x0 0x10000000000000 -0x0 0x20000000000000 -0x0 0x40000000000000 -0x0 0x80000000000000 -0x0 0x100000000000000 -0x0 0x200000000000000 -0x0 0x400000000000000 -0x0 0x800000000000000 -0x0 0x1000000000000000 -0x0 0x2000000000000000 -0x0 0x4000000000000000 -0x0 0x8000000000000000 -0x1 0x0 -0x2 0x0 -0x4 0x0 -0x8 0x0 -0x10 0x0 -0x20 0x0 -0x40 0x0 -0x80 0x0 -0x100 0x0 -0x200 0x0 -0x400 0x0 -0x800 0x0 -0x1000 0x0 -0x2000 0x0 -0x4000 0x0 -0x8000 0x0 -0x10000 0x0 -0x20000 0x0 -0x40000 0x0 -0x80000 0x0 -0x100000 0x0 -0x200000 0x0 -0x400000 0x0 -0x800000 0x0 -0x1000000 0x0 -0x2000000 0x0 -0x4000000 0x0 -0x8000000 0x0 -0x10000000 0x0 -0x20000000 0x0 -0x40000000 0x0 -0x80000000 0x0 -0x100000000 0x0 -0x200000000 0x0 -0x400000000 0x0 -0x800000000 0x0 -0x1000000000 0x0 -0x2000000000 0x0 -0x4000000000 0x0 -0x8000000000 0x0 -0x10000000000 0x0 -0x20000000000 0x0 -0x40000000000 0x0 -0x80000000000 0x0 -0x100000000000 0x0 -0x200000000000 0x0 -0x400000000000 0x0 -0x800000000000 0x0 -0x1000000000000 0x0 -0x2000000000000 0x0 -0x4000000000000 0x0 -0x8000000000000 0x0 -0x10000000000000 0x0 -0x20000000000000 0x0 -0x40000000000000 0x0 -0x80000000000000 0x0 -0x100000000000000 0x0 -0x200000000000000 0x0 -0x400000000000000 0x0 -0x800000000000000 0x0 -0x1000000000000000 0x0 -0x2000000000000000 0x0 -0x4000000000000000 0x0 -0x8000000000000000 0x0 -0x0 0x1 -0x0 0x2 -0x0 0x4 -0x0 0x8 -0x0 0x10 -0x0 0x20 -0x0 0x40 -0x0 0x80 -0x0 0x100 -0x0 0x200 -0x0 0x400 -0x0 0x800 -0x0 0x1000 -0x0 0x2000 -0x0 0x4000 -0x0 0x8000 -0x0 0x10000 -0x0 0x20000 -0x0 0x40000 -0x0 0x80000 -0x0 0x100000 -0x0 0x200000 -0x0 0x400000 -0x0 0x800000 -0x0 0x1000000 -0x0 0x2000000 -0x0 0x4000000 -0x0 0x8000000 -0x0 0x10000000 -0x0 0x20000000 -0x0 0x40000000 -0x0 0x80000000 -0x0 0x100000000 -0x0 0x200000000 -0x0 0x400000000 -0x0 0x800000000 -0x0 0x1000000000 -0x0 0x2000000000 -0x0 0x4000000000 -0x0 0x8000000000 -0x0 0x10000000000 -0x0 0x20000000000 -0x0 0x40000000000 -0x0 0x80000000000 -0x0 0x100000000000 -0x0 0x200000000000 -0x0 0x400000000000 -0x0 0x800000000000 -0x0 0x1000000000000 -0x0 0x2000000000000 -0x0 0x4000000000000 -0x0 0x8000000000000 -0x0 0x10000000000000 -0x0 0x20000000000000 -0x0 0x40000000000000 -0x0 0x80000000000000 -0x0 0x100000000000000 -0x0 0x200000000000000 -0x0 0x400000000000000 -0x0 0x800000000000000 -0x0 0x1000000000000000 -0x0 0x2000000000000000 -0x0 0x4000000000000000 -0x0 0x8000000000000000 -0x1 0x0 -0x2 0x0 -0x4 0x0 -0x8 0x0 -0x10 0x0 -0x20 0x0 -0x40 0x0 -0x80 0x0 -0x100 0x0 -0x200 0x0 -0x400 0x0 -0x800 0x0 -0x1000 0x0 -0x2000 0x0 -0x4000 0x0 -0x8000 0x0 -0x10000 0x0 -0x20000 0x0 -0x40000 0x0 -0x80000 0x0 -0x100000 0x0 -0x200000 0x0 -0x400000 0x0 -0x800000 0x0 -0x1000000 0x0 -0x2000000 0x0 -0x4000000 0x0 -0x8000000 0x0 -0x10000000 0x0 -0x20000000 0x0 -0x40000000 0x0 -0x80000000 0x0 -0x100000000 0x0 -0x200000000 0x0 -0x400000000 0x0 -0x800000000 0x0 -0x1000000000 0x0 -0x2000000000 0x0 -0x4000000000 0x0 -0x8000000000 0x0 -0x10000000000 0x0 -0x20000000000 0x0 -0x40000000000 0x0 -0x80000000000 0x0 -0x100000000000 0x0 -0x200000000000 0x0 -0x400000000000 0x0 -0x800000000000 0x0 -0x1000000000000 0x0 -0x2000000000000 0x0 -0x4000000000000 0x0 -0x8000000000000 0x0 -0x10000000000000 0x0 -0x20000000000000 0x0 -0x40000000000000 0x0 -0x80000000000000 0x0 -0x100000000000000 0x0 -0x200000000000000 0x0 -0x400000000000000 0x0 -0x800000000000000 0x0 -0x1000000000000000 0x0 -0x2000000000000000 0x0 -0x4000000000000000 0x0 -0x8000000000000000 0x0 diff --git a/test/unit/002/test.sh b/test/unit/002/test.sh @@ -2,8 +2,4 @@ set -e -tmp1=tmp.$$ -trap 'r=$?;rm -f $tmp1;exit $r' EXIT HUP INT QUIT TERM - -$EMUCMD ./run > $tmp1 -diff -u $tmp1 test.exp +$EMUCMD ./run diff --git a/test/unit/003/Makefile b/test/unit/003/Makefile @@ -3,7 +3,7 @@ PROJECTDIR = ../../.. include $(PROJECTDIR)/scripts/rules.mk include ../rules.mk -OBJS = $(TARGETDIR)/crt/crt.o \ +OBJS = $(LIBDIR)/crt.o \ $(TARGETDIR)/arch.o \ $(SRCDIR)/romfw/builtin.o \ test.o \ @@ -13,4 +13,4 @@ TARGET = run all: $(TARGET) $(TARGET): $(OBJS) $(LIBDEP) - $(LD) $(RCODE_LDFLAGS) $(OBJS) $(RCODE_LDLIBS) -o $@ + $(LD) $(PROJ_LDFLAGS) $(OBJS) $(PROJ_LDLIBS) -o $@ diff --git a/test/unit/003/descr b/test/unit/003/descr @@ -1 +1 @@ -Test RMU_System_InterfaceVersion() +Test panic() diff --git a/test/unit/003/test.c b/test/unit/003/test.c @@ -1,23 +1,40 @@ -#include <assert.h> -#include <setjmp.h> -#include <stdio.h> +#include <signal.h> #include <stdlib.h> +#include <rcode/rcode.h> -#include <rcode.h> - -#include "../../../src/ec.h" #include "../../../target/hosted/hosted.h" -struct trapframe frame; +void +cleanup(int signum) +{ + extern int halted; + + if (halted) + exit(0); +} + +static struct trapframe * +mockframe(void) +{ + int i; + static struct trapframe frame; + + for (i = 0; i < NR_REGS; i++) + frame.r[i] = i; + frame.r[ELR] = 0xdeadbeef; + frame.r[SP] = 0xdeadbabe; + + return &frame; +} int main(void) { - frame.esr = RMC << 26; /* class = func = 0 */ - if (!setjmp(recover)) - trap(&frame); - assert(frame.x0 == 0); - assert(frame.x1 == 0); - assert(frame.x2 == 1); + if (setjmp(recover)) + return -1; + signal(SIGABRT, cleanup); + getframe = mockframe; + + panic("oops"); return 0; } diff --git a/test/unit/004/test.exp b/test/unit/003/test.exp diff --git a/test/unit/003/test.sh b/test/unit/003/test.sh @@ -2,4 +2,8 @@ set -e -$EMUCMD ./run +tmp1=tmp.$$ +trap 'r=$?;rm -f $tmp1;exit $r' EXIT HUP INT QUIT TERM + +$EMUCMD ./run > $tmp1 +diff -u $tmp1 test.exp diff --git a/test/unit/004/Makefile b/test/unit/004/Makefile @@ -1,16 +0,0 @@ -.POSIX: -PROJECTDIR = ../../.. -include $(PROJECTDIR)/scripts/rules.mk -include ../rules.mk - -OBJS = $(TARGETDIR)/crt/crt.o \ - $(TARGETDIR)/arch.o \ - $(SRCDIR)/romfw/builtin.o \ - test.o \ - -TARGET = run - -all: $(TARGET) - -$(TARGET): $(OBJS) $(LIBDEP) - $(LD) $(RCODE_LDFLAGS) $(OBJS) $(RCODE_LDLIBS) -o $@ diff --git a/test/unit/004/descr b/test/unit/004/descr @@ -1 +0,0 @@ -Test panic() diff --git a/test/unit/004/test.c b/test/unit/004/test.c @@ -1,54 +0,0 @@ -#include <signal.h> -#include <stdlib.h> -#include <rcode.h> - -#include "../../../target/hosted/hosted.h" - -void -cleanup(int signum) -{ - extern int halted; - - if (halted) - exit(0); -} - -static struct trapframe * -mockframe(void) -{ - static struct trapframe frame; - - frame.x0 = 0, frame.x1 = 1; - frame.x2 = 2, frame.x3 = 3; - frame.x4 = 4, frame.x5 = 5; - frame.x6 = 6, frame.x7 = 7; - frame.x8 = 8, frame.x9 = 9; - frame.x10 = 10, frame.x11 = 11; - frame.x12 = 12, frame.x12 = 12; - frame.x13 = 13, frame.x14 = 14; - frame.x15 = 15, frame.x16 = 16; - frame.x17 = 17, frame.x18 = 18; - frame.x19 = 19, frame.x20 = 20; - frame.x21 = 21, frame.x22 = 22; - frame.x23 = 23, frame.x24 = 24; - frame.x25 = 25, frame.x26 = 26; - frame.x27 = 27, frame.x28 = 28; - frame.x29 = 29, frame.x30 = 30; - frame.elr = (void *)0xdeadbeef, frame.spsr = 32; - frame.esr = 33, frame.far = 34; - frame.sp = (void *)0xdeadbabe; - - return &frame; -} - -int -main(void) -{ - if (setjmp(recover)) - return -1; - signal(SIGABRT, cleanup); - getframe = mockframe; - - panic("oops"); - return 0; -} diff --git a/test/unit/004/test.sh b/test/unit/004/test.sh @@ -1,9 +0,0 @@ -#!/bin/sh - -set -e - -tmp1=tmp.$$ -trap 'r=$?;rm -f $tmp1;exit $r' EXIT HUP INT QUIT TERM - -$EMUCMD ./run > $tmp1 -diff -u $tmp1 test.exp diff --git a/test/unit/Makefile b/test/unit/Makefile @@ -2,7 +2,7 @@ PROJECTDIR = ../.. include $(PROJECTDIR)/scripts/rules.mk -DIRS = 001 002 003 004 +DIRS = 001 002 003 all: $(DIRS)