]> git.sesse.net Git - pistorm/blob - buptest.c
Merge pull request #12 from beeanyew/wip-crap
[pistorm] / buptest.c
1 #include <assert.h>
2 #include <dirent.h>
3 #include <endian.h>
4 #include <fcntl.h>
5 #include <pthread.h>
6 #include <sched.h>
7 #include <signal.h>
8 #include <stdint.h>
9 #include <stdio.h>
10 #include <time.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <sys/mman.h>
14 #include <sys/stat.h>
15 #include <sys/types.h>
16 #include <unistd.h>
17 #include <sys/ioctl.h>
18 #include "emulator.h"
19 #include "gpio/ps_protocol.h"
20 #include "platforms/amiga/gayle-ide/ide.h"
21
22 #define SIZE_KILO 1024
23 #define SIZE_MEGA (1024 * 1024)
24 #define SIZE_GIGA (1024 * 1024 * 1024)
25
26 uint8_t garbege_datas[2 * SIZE_MEGA];
27
28 struct timespec f2;
29
30 uint8_t gayle_int;
31 uint32_t mem_fd;
32 uint32_t errors = 0;
33 uint8_t loop_tests = 0, total_errors = 0;
34
35 void sigint_handler(int sig_num) {
36   printf("Received sigint %d, exiting.\n", sig_num);
37   printf("Total number of transaction errors occured: %d\n", total_errors);
38   if (mem_fd)
39     close(mem_fd);
40
41   exit(0);
42 }
43
44 int main(int argc, char *argv[]) {
45     uint32_t test_size = 512 * SIZE_KILO, cur_loop = 0;
46
47     clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &f2);
48     srand((unsigned int)f2.tv_nsec);
49
50     signal(SIGINT, sigint_handler);
51
52     ps_setup_protocol();
53     ps_reset_state_machine();
54     ps_pulse_reset();
55
56     usleep(1500);
57
58     write8(0xbfe201, 0x0101);       //CIA OVL
59         write8(0xbfe001, 0x0000);       //CIA OVL LOW
60
61     if (argc > 1) {
62         test_size = atoi(argv[1]) * SIZE_KILO;
63         if (test_size == 0 || test_size > 2 * SIZE_MEGA) {
64             test_size = 512 * SIZE_KILO;
65         }
66         printf("Testing %d KB of memory.\n", test_size / SIZE_KILO);
67         if (argc > 2) {
68             if (strcmp(argv[2], "l") == 0) {
69                 printf("Looping tests.\n");
70                 loop_tests = 1;
71             }
72         }
73     }
74
75 test_loop:;
76     printf("Writing garbege datas.\n");
77     for (uint32_t i = 0; i < test_size; i++) {
78         while(garbege_datas[i] == 0x00)
79             garbege_datas[i] = (uint8_t)(rand() % 0xFF);
80         write8(i, (uint32_t)garbege_datas[i]);
81     }
82
83     printf("Reading back garbege datas, read8()...\n");
84     for (uint32_t i = 0; i < test_size; i++) {
85         uint32_t c = read8(i);
86         if (c != garbege_datas[i]) {
87             if (errors < 512)
88                 printf("READ8: Garbege data mismatch at $%.6X: %.2X should be %.2X.\n", i, c, garbege_datas[i]);
89             errors++;
90         }
91     }
92     printf("read8 errors total: %d.\n", errors);
93     total_errors += errors;
94     errors = 0;
95     sleep (1);
96
97     printf("Reading back garbege datas, read16(), even addresses...\n");
98     for (uint32_t i = 0; i < (test_size) - 2; i += 2) {
99         uint32_t c = be16toh(read16(i));
100         if (c != *((uint16_t *)&garbege_datas[i])) {
101             if (errors < 512)
102                 printf("READ16_EVEN: Garbege data mismatch at $%.6X: %.4X should be %.4X.\n", i, c, *((uint16_t *)&garbege_datas[i]));
103             errors++;
104         }
105     }
106     printf("read16 even errors total: %d.\n", errors);
107     total_errors += errors;
108     errors = 0;
109     sleep (1);
110
111     printf("Reading back garbege datas, read16(), odd addresses...\n");
112     for (uint32_t i = 1; i < (test_size) - 2; i += 2) {
113         uint32_t c = be16toh((read8(i) << 8) | read8(i + 1));
114         if (c != *((uint16_t *)&garbege_datas[i])) {
115             if (errors < 512)
116                 printf("READ16_ODD: Garbege data mismatch at $%.6X: %.4X should be %.4X.\n", i, c, *((uint16_t *)&garbege_datas[i]));
117             errors++;
118         }
119     }
120     printf("read16 odd errors total: %d.\n", errors);
121     errors = 0;
122     sleep (1);
123
124     printf("Reading back garbege datas, read32(), even addresses...\n");
125     for (uint32_t i = 0; i < (test_size) - 4; i += 2) {
126         uint32_t c = be32toh(read32(i));
127         if (c != *((uint32_t *)&garbege_datas[i])) {
128             if (errors < 512)
129                 printf("READ32_EVEN: Garbege data mismatch at $%.6X: %.8X should be %.8X.\n", i, c, *((uint32_t *)&garbege_datas[i]));
130             errors++;
131         }
132     }
133     printf("read32 even errors total: %d.\n", errors);
134     total_errors += errors;
135     errors = 0;
136     sleep (1);
137
138     printf("Reading back garbege datas, read32(), odd addresses...\n");
139     for (uint32_t i = 1; i < (test_size) - 4; i += 2) {
140         uint32_t c = read8(i);
141         c |= (be16toh(read16(i + 1)) << 8);
142         c |= (read8(i + 3) << 24);
143         if (c != *((uint32_t *)&garbege_datas[i])) {
144             if (errors < 512)
145                 printf("READ32_ODD: Garbege data mismatch at $%.6X: %.8X should be %.8X.\n", i, c, *((uint32_t *)&garbege_datas[i]));
146             errors++;
147         }
148     }
149     printf("read32 odd errors total: %d.\n", errors);
150     total_errors += errors;
151     errors = 0;
152     sleep (1);
153
154     printf("Clearing %d KB of Chip again\n", test_size / SIZE_KILO);
155     for (uint32_t i = 0; i < test_size; i++) {
156         write8(i, (uint32_t)0x0);
157     }
158
159     printf("[WORD] Writing garbege datas to Chip, unaligned...\n");
160     for (uint32_t i = 1; i < (test_size) - 2; i += 2) {
161         uint16_t v = *((uint16_t *)&garbege_datas[i]);
162         write8(i, (v & 0x00FF));
163         write8(i + 1, (v >> 8));
164     }
165
166     sleep (1);
167     printf("Reading back garbege datas, read16(), odd addresses...\n");
168     for (uint32_t i = 1; i < (test_size) - 2; i += 2) {
169         uint32_t c = be16toh((read8(i) << 8) | read8(i + 1));
170         if (c != *((uint16_t *)&garbege_datas[i])) {
171             if (errors < 512)
172                 printf("READ16_ODD: Garbege data mismatch at $%.6X: %.4X should be %.4X.\n", i, c, *((uint16_t *)&garbege_datas[i]));
173             errors++;
174         }
175     }
176     printf("read16 odd errors total: %d.\n", errors);
177     total_errors += errors;
178     errors = 0;
179
180     printf("Clearing %d KB of Chip again\n", test_size / SIZE_KILO);
181     for (uint32_t i = 0; i < test_size; i++) {
182         write8(i, (uint32_t)0x0);
183     }
184
185     printf("[LONG] Writing garbege datas to Chip, unaligned...\n");
186     for (uint32_t i = 1; i < (test_size) - 4; i += 4) {
187         uint32_t v = *((uint32_t *)&garbege_datas[i]);
188         write8(i , v & 0x0000FF);
189         write16(i + 1, htobe16(((v & 0x00FFFF00) >> 8)));
190         write8(i + 3 , (v & 0xFF000000) >> 24);
191     }
192
193     sleep (1);
194     printf("Reading back garbege datas, read32(), odd addresses...\n");
195     for (uint32_t i = 1; i < (test_size) - 4; i += 4) {
196         uint32_t c = read8(i);
197         c |= (be16toh(read16(i + 1)) << 8);
198         c |= (read8(i + 3) << 24);
199         if (c != *((uint32_t *)&garbege_datas[i])) {
200             if (errors < 512)
201                 printf("READ32_ODD: Garbege data mismatch at $%.6X: %.8X should be %.8X.\n", i, c, *((uint32_t *)&garbege_datas[i]));
202             errors++;
203         }
204     }
205     printf("read32 odd errors total: %d.\n", errors);
206     total_errors += errors;
207     errors = 0;
208
209     if (loop_tests) {
210         printf ("Loop %d done. Begin loop %d.\n", cur_loop + 1, cur_loop + 2);
211         printf ("Current total errors: %d.\n", total_errors);
212         goto test_loop;
213     }
214
215     return 0;
216 }
217
218 void m68k_set_irq(unsigned int level) {
219 }
220
221 struct ide_controller *get_ide(int index) {
222     return NULL;
223 }