]> Joshua Wise's Git repositories - firearm.git/blame - tests/testbench.c
tests/Makefile: Add CFLAGS for LOL2FAST2FURIOUS.
[firearm.git] / tests / testbench.c
CommitLineData
392d1bec
JW
1extern void putc(unsigned char c);
2
3void puts(unsigned char *s)
4{
5 while (*s)
6 putc(*(s++));
7}
8
9void puthex(unsigned int x)
10{
11 unsigned char *hex = "0123456789ABCDEF";
12 int i;
13
14 for (i = 7; i >= 0; i--)
15 putc(hex[(x >> (i * 4)) & 0xF]);
16}
17
18#define putchar putc
19#include "ack.c"
20#include "j4cbo.c"
21#include "corecurse.c"
22
23int fact(int n)
24{
25 if (n == 0)
26 return 1;
27 else
28 return n * fact(n-1);
29}
30
31void facttest()
32{
33 if (fact(10) != 3628800)
34 puts("FAIL\n");
35 else
36 puts("PASS\n");
37}
38
39struct tests {
40 char *name;
41 void (*test)();
42};
43
44extern int ldm_bonehead();
4ad5ab91 45#ifndef X86
392d1bec
JW
46__asm__(
47".globl ldm_bonehead\n"
48"ldm_bonehead:;"
49"mov r3, lr;"
50"bl 1f;"
51"nop;"
52"nop;"
53"nop;"
54"nop;"
55"nop;"
56"nop;"
57"nop;"
58"nop;"
59"nop;"
60"mov pc, r3\n;"
61"1:\n"
62"ldr r2, =0x00002FE0;"
63"ldr r1, =0x0000004C;"
64"mov ip, sp;"
65"stmdb sp!, {fp, ip, lr, pc};"
66"mov r0, #0x00880000;"
67"ldmia sp, {fp, sp, pc};"
68"mul r0, r1, r2;"
69"nop;"
70"nop;\n"
71);
4ad5ab91 72#endif
392d1bec
JW
73void ldm_tester()
74{
4ad5ab91
JW
75#ifdef X86
76 int x = 0x00880000;
77#else
392d1bec 78 int x = ldm_bonehead();
4ad5ab91 79#endif
392d1bec
JW
80 if (x != 0x00880000)
81 {
82 puts("FAIL: result was ");
83 puthex(x);
84 puts("\n");
85 } else
86 puts("PASS\n");
87}
88
89struct tests tlist[] = {
90 {"ldm pc/mul", ldm_tester},
91 {"fact", facttest},
92 {"j4cbo", j4cbo},
93 {"ack", acktest},
94 {"corecurse", corecurse},
95 {0, 0}};
96
97int main()
98{
99 struct tests *t;
100
101 puts("Testbench running\n");
102
103 for (t = tlist; t->name; t++)
104 {
105 puts("Running ");
106 puts(t->name);
107 puts(": ");
108 t->test();
109 }
110 puts("Done!\n");
111
112 return 0;
113}
This page took 0.027848 seconds and 4 git commands to generate.