tests: Add the new testbench.
[firearm.git] / tests / testbench.c
1 extern void putc(unsigned char c);
2
3 void puts(unsigned char *s)
4 {
5         while (*s)
6                 putc(*(s++));
7 }
8
9 void 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
23 int fact(int n)
24 {
25         if (n == 0)
26                 return 1;
27         else
28                 return n * fact(n-1);
29 }
30
31 void facttest()
32 {
33         if (fact(10) != 3628800)
34                 puts("FAIL\n");
35         else
36                 puts("PASS\n");
37 }
38
39 struct tests {
40         char *name;
41         void (*test)();
42 };
43
44 extern int ldm_bonehead();
45
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 );
72
73 void ldm_tester()
74 {
75         int x = ldm_bonehead();
76         if (x != 0x00880000)
77         {
78                 puts("FAIL: result was ");
79                 puthex(x);
80                 puts("\n");
81         } else
82                 puts("PASS\n");
83 }
84
85 struct tests tlist[] = {
86         {"ldm pc/mul", ldm_tester},
87         {"fact", facttest},
88         {"j4cbo", j4cbo},
89         {"ack", acktest},
90         {"corecurse", corecurse},
91         {0, 0}};
92
93 int main()
94 {
95         struct tests *t;
96         
97         puts("Testbench running\n");
98         
99         for (t = tlist; t->name; t++)
100         {
101                 puts("Running ");
102                 puts(t->name);
103                 puts(": ");
104                 t->test();
105         }
106         puts("Done!\n");
107         
108         return 0;
109 }
This page took 0.02267 seconds and 4 git commands to generate.