DCache/ICache: reg i -> integer i
[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 #include "miniblarg.c"
23
24 int fact(int n)
25 {
26         if (n == 0)
27                 return 1;
28         else
29                 return n * fact(n-1);
30 }
31
32 void facttest()
33 {
34         if (fact(10) != 3628800)
35                 puts("FAIL\n");
36         else
37                 puts("PASS\n");
38 }
39
40 struct tests {
41         char *name;
42         void (*test)();
43 };
44
45 extern int ldm_bonehead();
46
47 #ifndef X86
48 int shnasto()
49 {
50 __asm__ volatile(
51 ".globl ldm_bonehead\n"
52 "ldm_bonehead:;"
53 "mov r3, lr;"
54 "bl 1f;"
55 "nop;"
56 "nop;"
57 "nop;"
58 "nop;"
59 "nop;"
60 "nop;"
61 "nop;"
62 "nop;"
63 "nop;"
64 "mov pc, r3\n;"
65 "1:\n"
66 "mov r2, #0x00002F00;"
67 "orr r2, r2, #0x000000E0;"
68 "mov r1, #0x0000004C;"
69 "mov ip, sp;"
70 "stmdb sp!, {fp, ip, lr, pc};"
71 "mov r0, #0x00880000;"
72 "ldmia sp, {fp, sp, pc};"
73 "mul r0, r1, r2;"
74 "nop;"
75 "nop;\n"
76 );
77 }
78 #endif
79
80 void ldm_tester()
81 {
82 #ifdef X86
83         int x = 0x00880000;
84 #else
85         int x = ldm_bonehead();
86 #endif
87         if (x != 0x00880000)
88         {
89                 puts("FAIL: result was ");
90                 puthex(x);
91                 puts("\n");
92         } else
93                 puts("PASS\n");
94 }
95
96 struct tests tlist[] = {
97         {"ldm pc/mul", ldm_tester},
98         {"fact", facttest},
99         {"j4cbo", j4cbo},
100         {"ack", acktest},
101         {"miniblarg", testmain},
102         {"corecurse", corecurse},
103         {0, 0}};
104
105 int main()
106 {
107         struct tests *t;
108         
109         puts("Testbench running\n");
110         
111         for (t = tlist; t->name; t++)
112         {
113                 puts("Running ");
114                 puts(t->name);
115                 puts(": ");
116                 t->test();
117         }
118         puts("Done!\n");
119         
120         return 0;
121 }
This page took 0.026196 seconds and 4 git commands to generate.