From 392d1bec43dcfb806fbdf77380c334f2cdc84778 Mon Sep 17 00:00:00 2001 From: Joshua Wise Date: Wed, 14 Jan 2009 02:10:56 -0500 Subject: [PATCH] tests: Add the new testbench. --- tests/ack.c | 25 +++++++ tests/corecurse.c | 25 +++++++ tests/j4cbo.c | 172 ++++++++++++++++++++++++++++++++++++++++++++ tests/ram.hex | 2 +- tests/testbench.c | 109 ++++++++++++++++++++++++++++ tests/testbench.hex | Bin 0 -> 9351 bytes 6 files changed, 332 insertions(+), 1 deletion(-) create mode 100644 tests/ack.c create mode 100644 tests/corecurse.c create mode 100644 tests/j4cbo.c create mode 100644 tests/testbench.c create mode 100644 tests/testbench.hex diff --git a/tests/ack.c b/tests/ack.c new file mode 100644 index 0000000..ab57018 --- /dev/null +++ b/tests/ack.c @@ -0,0 +1,25 @@ +//#test return 61 + +int ack(int m, int n) +{ + if(m == 0) { + return n + 1; + } + else if(n == 0) { + return ack(m - 1, 1); + } + else { + return ack(m - 1, ack(m, n - 1)); + } +} + +void acktest() +{ int x; + if ((x = ack(3, 3)) != 61) + { + puts("FAIL: Ack test did not return 61\n"); + puthex(x); + } + else + puts("PASS: Ack test returned 61\n"); +} diff --git a/tests/corecurse.c b/tests/corecurse.c new file mode 100644 index 0000000..33576fe --- /dev/null +++ b/tests/corecurse.c @@ -0,0 +1,25 @@ +int b(int x); +int a(int x); + +int a(int x) +{ + if (x) + return b(x/2) + a(x - 1); + return 1; +} + +int b(int x) +{ + if (x) + return a(x) + a(x - 1); + return 0; +} + +int corecurse() +{ + int v = a(35) + b(32) - 4450/28; + if (v == 15411) + puts("PASS\n"); + else + puts("FAIL\n"); +} \ No newline at end of file diff --git a/tests/j4cbo.c b/tests/j4cbo.c new file mode 100644 index 0000000..3a1382e --- /dev/null +++ b/tests/j4cbo.c @@ -0,0 +1,172 @@ +//#test return 151 + +/* example tree from http://en.wikipedia.org/wiki/Huffman_coding */ + +int getbyte(int byte) +{ + if (byte == 0) return 106; + if (byte == 1) return 139; + if (byte == 2) return 120; + if (byte == 3) return 183; + if (byte == 4) return 69; + if (byte == 5) return 197; + if (byte == 6) return 147; + if (byte == 7) return 207; + if (byte == 8) return 35; + if (byte == 9) return 155; + if (byte == 10) return 122; + if (byte == 11) return 244; + if (byte == 12) return 125; + if (byte == 13) return 215; + if (byte == 14) return 69; + if (byte == 15) return 219; + if (byte == 16) return 2; + if (byte == 17) return 224; + puts("FAIL [abort]: request for byte #"); + puthex(byte); + while(1); + return 0; +} + +int getbit(int bp) +{ + int byte; + byte = getbyte(bp/8); + return (byte >> (7 - (bp % 8))) & 1; +} + +int h(int bitpos) +{ + if (getbit(bitpos)) + return h1(bitpos+1); + else + return h0(bitpos+1); +} + +int h0(int bitpos) +{ + if (getbit(bitpos)) + return h01(bitpos+1); + else + return h00(bitpos+1); +} + +int h00(int bitpos) +{ + if (getbit(bitpos)) + return h001(bitpos+1); + else + return 69+h(bitpos+1); +} + +int h001(int bitpos) +{ + if (getbit(bitpos)) + return h0011(bitpos+1); + else + return 78+h(bitpos+1); +} + +int h0011(int bitpos) +{ + if (getbit(bitpos)) + return 79+h(bitpos+1); + else + return 85+h(bitpos+1); +} + +int h01(int bitpos) +{ + if (getbit(bitpos)) + return h011(bitpos+1); + else + return 65+h(bitpos+1); +} + +int h011(int bitpos) +{ + if (getbit(bitpos)) + return 77+h(bitpos+1); + else + return 84+h(bitpos+1); +} + +int h1(bitpos) +{ + if (getbit(bitpos)) + return h11(bitpos+1); + else + return h10(bitpos+1); +} + +int h10(bitpos) +{ + if (getbit(bitpos)) + return h101(bitpos+1); + else + return h100(bitpos+1); +} + +int h100(bitpos) +{ + if (getbit(bitpos)) + return h1001(bitpos+1); + else + return 73+h(bitpos+1); +} + +int h1001(bitpos) +{ + if (getbit(bitpos)) + return 80+h(bitpos+1); + else + return 88+h(bitpos+1); +} + +int h101(bitpos) +{ + if (getbit(bitpos)) + return h1011(bitpos+1); + else + return 72+h(bitpos+1); +} + +int h1011(bitpos) +{ + if (getbit(bitpos)) + return -2169; + else + return 83+h(bitpos+1); +} + +int h11(bitpos) +{ + if (getbit(bitpos)) + return 32+h(bitpos+1); + else + return h110(bitpos+1); +} + +int h110(bitpos) +{ + if (getbit(bitpos)) + return 70+h(bitpos+1); + else + return h1100(bitpos+1); +} + +int h1100(bitpos) +{ + if (getbit(bitpos)) + return 76+h(bitpos+1); + else + return 82+h(bitpos+1); +} + +void j4cbo() +{ + if (h(0) != 151) + puts("Result was not 151\r\n"); + else + puts("Result was 151\r\n"); +} diff --git a/tests/ram.hex b/tests/ram.hex index 0f379b7..0185b5b 120000 --- a/tests/ram.hex +++ b/tests/ram.hex @@ -1 +1 @@ -costas.hex \ No newline at end of file +testbench.hex \ No newline at end of file diff --git a/tests/testbench.c b/tests/testbench.c new file mode 100644 index 0000000..ff9f96c --- /dev/null +++ b/tests/testbench.c @@ -0,0 +1,109 @@ +extern void putc(unsigned char c); + +void puts(unsigned char *s) +{ + while (*s) + putc(*(s++)); +} + +void puthex(unsigned int x) +{ + unsigned char *hex = "0123456789ABCDEF"; + int i; + + for (i = 7; i >= 0; i--) + putc(hex[(x >> (i * 4)) & 0xF]); +} + +#define putchar putc +#include "ack.c" +#include "j4cbo.c" +#include "corecurse.c" + +int fact(int n) +{ + if (n == 0) + return 1; + else + return n * fact(n-1); +} + +void facttest() +{ + if (fact(10) != 3628800) + puts("FAIL\n"); + else + puts("PASS\n"); +} + +struct tests { + char *name; + void (*test)(); +}; + +extern int ldm_bonehead(); + +__asm__( +".globl ldm_bonehead\n" +"ldm_bonehead:;" +"mov r3, lr;" +"bl 1f;" +"nop;" +"nop;" +"nop;" +"nop;" +"nop;" +"nop;" +"nop;" +"nop;" +"nop;" +"mov pc, r3\n;" +"1:\n" +"ldr r2, =0x00002FE0;" +"ldr r1, =0x0000004C;" +"mov ip, sp;" +"stmdb sp!, {fp, ip, lr, pc};" +"mov r0, #0x00880000;" +"ldmia sp, {fp, sp, pc};" +"mul r0, r1, r2;" +"nop;" +"nop;\n" +); + +void ldm_tester() +{ + int x = ldm_bonehead(); + if (x != 0x00880000) + { + puts("FAIL: result was "); + puthex(x); + puts("\n"); + } else + puts("PASS\n"); +} + +struct tests tlist[] = { + {"ldm pc/mul", ldm_tester}, + {"fact", facttest}, + {"j4cbo", j4cbo}, + {"ack", acktest}, + {"corecurse", corecurse}, + {0, 0}}; + +int main() +{ + struct tests *t; + + puts("Testbench running\n"); + + for (t = tlist; t->name; t++) + { + puts("Running "); + puts(t->name); + puts(": "); + t->test(); + } + puts("Done!\n"); + + return 0; +} diff --git a/tests/testbench.hex b/tests/testbench.hex new file mode 100644 index 0000000000000000000000000000000000000000..ceab6f88c89620335204e864a8e0ae2b204dbd48 GIT binary patch literal 9351 zcmdT~ZF1}=4E*oY@MUZt$7AFBA7Q&CU@&Aelg-Pk>{M;7pFv3KZUly;dAm+yjwwBi zF@D9ve({&4l<;P@W=eK9moaI=zm2~x^ue3Mm~%>-JI~dij|&Gz2z)p(ARcCe7c}2# zXBND%4=-=#(|f#`>XXPMLd=gn;SK$>{uw zXrg+Z2CoAObQ_zBRfSiYb~LFu=9icg%zK{|VU*d#I88zYkcZ1Dbe|_k{ghHr!|0R% z?=sOMSgun~0*jSg_);s2X)gYY)%qB$+LYDG^;U}prqf(~4e&xFov%kN1;AOXX2x9L zRbQdE3UeRf4D-%v?yZi&Dzw#4eZ}5tgMRK924;GXaOtfmw$6%@xLd8gl^cBdk*}?{ z+6KP-$k*OmErT}v$k(H{x`=Zr=E9d7`8s;5h2{NjHS%@#R_CA%JMxu!t5F-zl3O)@ z^;YMAp&j@_{pr-pW%Qocvv?L?c9>tRkewCz`ncNMg1=W12OZYkg-Q#k);=FETNf3D zK5rJ8N)sNiBw=>}Qgo)6>49-jP5}ZR>;d&w?@|vJaAIn+?!>hOzOI1 z*D$yVG!K-WYTohAiuA(Vd}#g#-QP($lcHVxurk_P`_B)1qdR+j|IQ~ zBBOr(YkB8psmkx`0tnduRC5h}*zLR{fY4H)0$}ccNdR_hvgkl~p{HqIo z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