2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 /* usd_test.c: Tests the usd library by opening a tape device,
12 * writing a few blocks of data to it, doing a fsf, bsf
14 #include <afsconfig.h>
15 #include <afs/param.h>
27 #define USDTEST_DEBUG 0 /* set to 1, to print tape pos info */
29 static int err_exit(char *action, char *msg, int rcode);
30 static int bufeql(char *buf1, char *buf2, int size);
31 static int Rewind(usd_handle_t hTape);
32 static int WriteEOF(usd_handle_t hTape, int cnt);
33 static int ForwardSpace(usd_handle_t hTape, int cnt);
34 static int BackSpace(usd_handle_t hTape, int cnt);
35 static int PrepTape(usd_handle_t hTape);
36 static int ShutdownTape(usd_handle_t hTape);
37 static int PrintTapePos(usd_handle_t hTape);
40 main(int argc, char **argv)
44 char *filename = argv[1];
45 char buf1[1024], buf2[1024];
50 printf(" Usage: %s <tape device name>\n", whoami);
54 usd_Open(filename, (USD_OPEN_RDWR | USD_OPEN_WLOCK), 0777, &hTape);
57 printf("%s:Can't open device. Err %d\n", whoami, rcode);
66 /* Write test - write 10 blocks of random data */
67 printf("%s: Beginning Write Test\n", whoami);
69 for (i = 0; i < 10; i++) {
70 rcode = USD_WRITE(hTape, buf1, 1024, &xferd);
71 if (rcode || xferd != 1024) {
72 printf("%s: Write test failed. Err %d\n", whoami, rcode);
81 printf("%s: Write Test Passed.\n", whoami);
84 printf("%s: Rewind Test passed\n", whoami);
87 /* Read test - read the 10 blocks written */
88 printf("%s: Beginning read test\n", whoami);
89 for (i = 0; i < 10; i++) {
90 rcode = USD_READ(hTape, buf2, 1024, &xferd);
91 err_exit("read", "Read Test Failed", rcode);
94 err_exit("read", "Read Test Failed. Wrong no. of bytes read.", 1);
95 if (bufeql(buf1, buf2, 1024) == 0) {
96 printf("%s: Read test failed\n", whoami);
100 printf("%s: Read Test passed\n", whoami);
105 for (i = 0; i < 5; i++) {
106 /* write data block */
108 rcode = USD_WRITE(hTape, buf1, 1024, &xferd);
109 err_exit("Write", "Write EOF Test Failed", rcode);
112 rcode = WriteEOF(hTape, 1);
113 err_exit("WEOF", "Write EOF Test Failed", rcode);
116 printf("%s: WEOF Test passed\n", whoami);
120 ForwardSpace(hTape, 2);
122 rcode = USD_READ(hTape, buf2, 1024, &xferd);
123 err_exit("read", "FSF Test Failed", rcode);
125 err_exit("FSF", "FSF Test Failed", 1);
127 ForwardSpace(hTape, 2);
129 rcode = USD_READ(hTape, buf2, 1024, &xferd);
130 err_exit("read", "FSF Test Failed", rcode);
132 err_exit("FSF", "FSF Test Failed", 1);
134 printf("%s: FSF Test passed\n", whoami);
137 ForwardSpace(hTape, 1);
138 rcode = USD_READ(hTape, buf2, 1024, &xferd);
139 err_exit("read", "FSF Test Failed", rcode);
141 err_exit("BSF", "FSF Test Failed", 1);
143 printf("%s: BSF Test Passed\n", whoami);
146 rcode = USD_CLOSE(hTape);
148 printf("%s:Can't close device. Err %d\n", whoami, rcode);
151 printf("%s: usd library, all tests passed!\n", whoami);
156 err_exit(char *action, char *msg, int rcode)
160 printf("%s:Can't %s device. Err %d\n %s \n", whoami, action, rcode, msg);
162 /* Now shutdown and close the tape */
164 rcode = USD_CLOSE(hTape);
166 printf("%s:Can't close device. Err %d\n", whoami, rcode);
174 bufeql(char *buf1, char *buf2, int size)
188 Rewind(usd_handle_t hTape)
193 tapeop.tp_op = USDTAPE_REW;
195 rcode = USD_IOCTL(hTape, USD_IOCTL_TAPEOPERATION, (void *)&tapeop);
196 err_exit("rewind", "Rewind Test Failed", rcode);
201 WriteEOF(usd_handle_t hTape, int cnt)
206 tapeop.tp_op = USDTAPE_WEOF;
207 tapeop.tp_count = cnt;
208 rcode = USD_IOCTL(hTape, USD_IOCTL_TAPEOPERATION, (void *)&tapeop);
209 err_exit("rewind", "Rewind Test Failed", rcode);
214 ForwardSpace(usd_handle_t hTape, int cnt)
219 tapeop.tp_op = USDTAPE_FSF;
220 tapeop.tp_count = cnt;
221 rcode = USD_IOCTL(hTape, USD_IOCTL_TAPEOPERATION, (void *)&tapeop);
222 err_exit("FSF", "FSF Test Failed", rcode);
227 BackSpace(usd_handle_t hTape, int cnt)
232 tapeop.tp_op = USDTAPE_BSF;
233 tapeop.tp_count = cnt;
234 rcode = USD_IOCTL(hTape, USD_IOCTL_TAPEOPERATION, (void *)&tapeop);
235 err_exit("BSF", "BSF Test Failed", rcode);
240 PrepTape(usd_handle_t hTape)
245 tapeop.tp_op = USDTAPE_PREPARE;
247 rcode = USD_IOCTL(hTape, USD_IOCTL_TAPEOPERATION, (void *)&tapeop);
248 err_exit("PREPARE", "Tape Prepare Test Failed", rcode);
254 ShutdownTape(usd_handle_t hTape)
259 tapeop.tp_op = USDTAPE_SHUTDOWN;
261 rcode = USD_IOCTL(hTape, USD_IOCTL_TAPEOPERATION, (void *)&tapeop);
262 if (rcode) { /* can't call err_exit() here for fear of recursion */
263 printf("%s: Tape Shutdown Failed with code %d\n", whoami, rcode);
271 PrintTapePos(usd_handle_t hTape)
274 DWORD part, offLow, offHi;
277 GetTapePosition(hTape->handle, TAPE_ABSOLUTE_POSITION, &part, &offLow,
279 if (rcode != NO_ERROR)
280 err_exit("GetTapePosition", "Get Tape Pos test Failed", 1);
283 printf("%s: Cur Tape Block : %d \n", whoami, offLow);
289 PrintTapePos(usd_handle_t hTape)
291 afs_hyper_t startOff, stopOff;
294 hset64(startOff, 0, 0);
295 hset64(stopOff, 0, 0);
297 rcode = USD_SEEK(hTape, startOff, SEEK_CUR, &stopOff);
298 err_exit("Seek", "Tape Seek Test Failed", rcode);
301 printf("%s: Cur Tape Pos : %d bytes\n", whoami, stopOff.low);
303 return (stopOff.low);