expansion.library: Don't #define SysBase
[AROS.git] / test / testide.c
blob0b2632e961a546be920cdf7fb72b50bc658c57bd
1 #include <exec/types.h>
2 #include <exec/io.h>
3 #include <exec/memory.h>
4 #include <devices/trackdisk.h>
6 #include <proto/exec.h>
8 #include <sys/time.h>
10 #include <stdio.h>
11 #include <stdlib.h>
13 /*
14 Yes, I know. This is the ugliest hack you have ever seen.
15 However, it does its job, and you are not supposed to be running
16 this anyways :)
19 UBYTE *buffer;
20 UBYTE *buff2;
21 struct MsgPort *mp;
22 struct IOExtTD *io;
24 void verify( void )
26 ULONG foo,bar;
28 printf("Comparing\n");
29 for (foo=0;foo<256;foo++)
31 for (bar=0;bar<512;bar++)
33 if (buffer[(foo*512)+bar] != buff2[(foo*512)+bar])
35 printf("Mismatch in sector %d\n",(int)bar);
41 int main ( int argc, char *argv[] )
43 ULONG x,y;
44 struct timeval tv1,tv2;
45 double elapsed;
46 ULONG base;
48 if (argc != 2)
50 printf("Usage: testide <startblock>\n\n");
51 printf("Be warned, this tool WILL irrevocably destroy data on\n");
52 printf("data on the primary master IDE harddisk. Do not run this\n");
53 printf("on a computer holding any important data whatsoever.\n");
54 return 0;
57 base = atoi(argv[1])*512;
59 printf("ide.device test tool\n");
60 printf("Allocating two 128 KiB buffers\n");
62 buffer = AllocMem(131072,MEMF_PUBLIC);
63 buff2 = AllocMem(131072,MEMF_PUBLIC);
65 printf("Initializing buffer\n");
66 for (x=0;x<256;x++)
67 for (y=0;y<512;y++)
68 buffer[(x*512)+y] = x;
70 printf("Creating MsgPort\n");
71 mp = CreateMsgPort();
72 if (!mp)
74 printf("Failed, aborting\n");
75 return 1;
78 printf("Creating IORequest\n");
79 io = (struct IOExtTD *)CreateIORequest(mp,sizeof(struct IOExtTD));
80 if (!io)
82 printf("Failed, aborting\n");
83 return 1;
86 printf("Opening ide.device\n");
87 if (OpenDevice("ide.device",0L,(struct IORequest *)io,0L))
89 printf("Failed, aborting\n");
90 return 1;
93 printf("Writing single blocks\n");
94 for (x=0;x<256;x++)
96 io->iotd_Req.io_Length = 512;
97 io->iotd_Req.io_Data = (buffer+(x*512));
98 io->iotd_Req.io_Offset = (x*512)+base;
99 io->iotd_Req.io_Command = CMD_WRITE;
100 DoIO((struct IORequest *)io);
103 printf("Reading single blocks\n");
104 for (x=0;x<256;x++)
106 io->iotd_Req.io_Length = 512;
107 io->iotd_Req.io_Data = (buff2+(x*512));
108 io->iotd_Req.io_Offset = (x*512)+base;
109 io->iotd_Req.io_Command = CMD_READ;
110 DoIO((struct IORequest *)io);
113 verify();
115 printf("Writing entire buffer\n");
116 io->iotd_Req.io_Length = 131072;
117 io->iotd_Req.io_Data = buffer;
118 io->iotd_Req.io_Offset = base;
119 io->iotd_Req.io_Command = CMD_WRITE;
120 DoIO((struct IORequest *)io);
122 verify();
124 printf("Writing single blocks\n");
125 for (x=0;x<256;x++)
127 io->iotd_Req.io_Length = 512;
128 io->iotd_Req.io_Data = (buffer+(x*512));
129 io->iotd_Req.io_Offset = (x*512)+base;
130 io->iotd_Req.io_Command = CMD_WRITE;
131 DoIO((struct IORequest *)io);
134 printf("Reading entire buffer\n");
135 io->iotd_Req.io_Length = 131072;
136 io->iotd_Req.io_Data = buff2;
137 io->iotd_Req.io_Offset = base;
138 io->iotd_Req.io_Command = CMD_READ;
139 DoIO((struct IORequest *)io);
141 verify();
143 printf("Benching\n");
145 gettimeofday(&tv1,NULL);
146 for (x=0;x<80;x++)
148 io->iotd_Req.io_Length = 131072;
149 io->iotd_Req.io_Data = (buffer+(x*512));
150 io->iotd_Req.io_Offset = (x*512)+base;
151 io->iotd_Req.io_Command = CMD_READ;
152 DoIO((struct IORequest *)io);
154 gettimeofday(&tv2,NULL);
155 elapsed = ((double)(((tv2.tv_sec * 1000000) + tv2.tv_usec) - ((tv1.tv_sec * 1000000) + tv1.tv_usec)))/1000000.;
157 printf(" Read 10 MiB in %f seconds (%f MiB/s\n",elapsed,(10/elapsed));
159 gettimeofday(&tv1,NULL);
160 for (x=0;x<80;x++)
162 io->iotd_Req.io_Length = 131072;
163 io->iotd_Req.io_Data = (buffer+(x*512));
164 io->iotd_Req.io_Offset = (x*512)+base;
165 io->iotd_Req.io_Command = CMD_WRITE;
166 DoIO((struct IORequest *)io);
168 gettimeofday(&tv2,NULL);
169 elapsed = ((double)(((tv2.tv_sec * 1000000) + tv2.tv_usec) - ((tv1.tv_sec * 1000000) + tv1.tv_usec)))/1000000.;
171 printf("Wrote 10 MiB in %f seconds (%f MiB/s\n",elapsed,(10/elapsed));
172 return 0;