move core probing to postinit
[AROS.git] / test / testide.c
blobae51b3b22eb01ee6000426519a1954be3c5c98a3
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <exec/types.h>
7 #include <exec/io.h>
8 #include <exec/memory.h>
9 #include <devices/trackdisk.h>
11 #include <proto/exec.h>
13 #include <sys/time.h>
15 #include <stdio.h>
16 #include <stdlib.h>
18 /*
19 Yes, I know. This is the ugliest hack you have ever seen.
20 However, it does its job, and you are not supposed to be running
21 this anyways :)
24 UBYTE *buffer;
25 UBYTE *buff2;
26 struct MsgPort *mp;
27 struct IOExtTD *io;
29 void verify( void )
31 ULONG foo,bar;
33 printf("Comparing\n");
34 for (foo=0;foo<256;foo++)
36 for (bar=0;bar<512;bar++)
38 if (buffer[(foo*512)+bar] != buff2[(foo*512)+bar])
40 printf("Mismatch in sector %d\n",(int)bar);
46 int main ( int argc, char *argv[] )
48 ULONG x,y;
49 struct timeval tv1,tv2;
50 double elapsed;
51 ULONG base;
53 if (argc != 2)
55 printf("Usage: testide <startblock>\n\n");
56 printf("Be warned, this tool WILL irrevocably destroy data on\n");
57 printf("the primary master IDE hard disk. Do not run this\n");
58 printf("on a computer holding any important data whatsoever.\n");
59 return 0;
62 base = atoi(argv[1])*512;
64 printf("ide.device test tool\n");
65 printf("Allocating two 128 KiB buffers\n");
67 buffer = AllocMem(131072,MEMF_PUBLIC);
68 buff2 = AllocMem(131072,MEMF_PUBLIC);
70 printf("Initializing buffer\n");
71 for (x=0;x<256;x++)
72 for (y=0;y<512;y++)
73 buffer[(x*512)+y] = x;
75 printf("Creating MsgPort\n");
76 mp = CreateMsgPort();
77 if (!mp)
79 printf("Failed, aborting\n");
80 return 1;
83 printf("Creating IORequest\n");
84 io = (struct IOExtTD *)CreateIORequest(mp,sizeof(struct IOExtTD));
85 if (!io)
87 printf("Failed, aborting\n");
88 return 1;
91 printf("Opening ide.device\n");
92 if (OpenDevice("ide.device",0L,(struct IORequest *)io,0L))
94 printf("Failed, aborting\n");
95 return 1;
98 printf("Writing single blocks\n");
99 for (x=0;x<256;x++)
101 io->iotd_Req.io_Length = 512;
102 io->iotd_Req.io_Data = (buffer+(x*512));
103 io->iotd_Req.io_Offset = (x*512)+base;
104 io->iotd_Req.io_Command = CMD_WRITE;
105 DoIO((struct IORequest *)io);
108 printf("Reading single blocks\n");
109 for (x=0;x<256;x++)
111 io->iotd_Req.io_Length = 512;
112 io->iotd_Req.io_Data = (buff2+(x*512));
113 io->iotd_Req.io_Offset = (x*512)+base;
114 io->iotd_Req.io_Command = CMD_READ;
115 DoIO((struct IORequest *)io);
118 verify();
120 printf("Writing entire buffer\n");
121 io->iotd_Req.io_Length = 131072;
122 io->iotd_Req.io_Data = buffer;
123 io->iotd_Req.io_Offset = base;
124 io->iotd_Req.io_Command = CMD_WRITE;
125 DoIO((struct IORequest *)io);
127 verify();
129 printf("Writing single blocks\n");
130 for (x=0;x<256;x++)
132 io->iotd_Req.io_Length = 512;
133 io->iotd_Req.io_Data = (buffer+(x*512));
134 io->iotd_Req.io_Offset = (x*512)+base;
135 io->iotd_Req.io_Command = CMD_WRITE;
136 DoIO((struct IORequest *)io);
139 printf("Reading entire buffer\n");
140 io->iotd_Req.io_Length = 131072;
141 io->iotd_Req.io_Data = buff2;
142 io->iotd_Req.io_Offset = base;
143 io->iotd_Req.io_Command = CMD_READ;
144 DoIO((struct IORequest *)io);
146 verify();
148 printf("Benching\n");
150 gettimeofday(&tv1,NULL);
151 for (x=0;x<80;x++)
153 io->iotd_Req.io_Length = 131072;
154 io->iotd_Req.io_Data = (buffer+(x*512));
155 io->iotd_Req.io_Offset = (x*512)+base;
156 io->iotd_Req.io_Command = CMD_READ;
157 DoIO((struct IORequest *)io);
159 gettimeofday(&tv2,NULL);
160 elapsed = ((double)(((tv2.tv_sec * 1000000) + tv2.tv_usec) - ((tv1.tv_sec * 1000000) + tv1.tv_usec)))/1000000.;
162 printf(" Read 10 MiB in %f seconds (%f MiB/s\n",elapsed,(10/elapsed));
164 gettimeofday(&tv1,NULL);
165 for (x=0;x<80;x++)
167 io->iotd_Req.io_Length = 131072;
168 io->iotd_Req.io_Data = (buffer+(x*512));
169 io->iotd_Req.io_Offset = (x*512)+base;
170 io->iotd_Req.io_Command = CMD_WRITE;
171 DoIO((struct IORequest *)io);
173 gettimeofday(&tv2,NULL);
174 elapsed = ((double)(((tv2.tv_sec * 1000000) + tv2.tv_usec) - ((tv1.tv_sec * 1000000) + tv1.tv_usec)))/1000000.;
176 printf("Wrote 10 MiB in %f seconds (%f MiB/s\n",elapsed,(10/elapsed));
177 return 0;