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
10 #include <afs/param.h>
11 #include <sys/types.h>
14 #include <afs/com_err.h>
16 #include <sys/ioctl.h>
17 #include <netinet/in.h>
20 #include "AFS_component_version_number.c"
24 static char *whoami = "TEST FAIL";
26 #define NULL (char *)0
27 #define PASS(str, err) printf("TEST: %s\n", str); \
30 printf("FAILURE: expected %u; got %u\n", err, code); \
31 if (code) com_err(whoami, code, ""); \
33 else printf("PASSED; got %u\n", err); \
36 #define PASSq(str, err) if (code != err) \
38 printf("TEST: %s\n", str); \
39 printf("FAILURE: expected %u; got %u\n", err, code); \
40 if (code) com_err(whoami, code, ""); \
46 char tapeBlock[16384];
55 char *tape = "testtape.0";
62 struct butm_tapeInfo tapeInfo;
63 struct tapeConfig tapeConfig;
65 struct butm_tapeLabel tapeLabelWrite, tapeLabelRead;
70 initialize_butm_error_table();
72 tapeInfo.structVersion = BUTM_MAJORVERSION;
74 strcpy(tapeConfig.device, "/dev/rmt0");
75 tapeConfig.capacity = 100;
76 tapeConfig.fileMarkSize = 16384;
77 tapeConfig.portOffset = 0;
78 tapeConfig.aixScsi = 0;
86 /* butm_file_Instantiate tests */
87 /* --------------------------- */
88 code = butm_file_Instantiate (NULL, &tapeConfig);
89 PASS("Bad info paramater", BUTM_BADARGUMENT)
91 code = butm_file_Instantiate (&tapeInfo, NULL);
92 PASS("Bad config parameter", BUTM_BADCONFIG);
94 tapeInfo.structVersion = 0;
95 code = butm_file_Instantiate (&tapeInfo, &tapeConfig);
96 PASS ("Bad version number", BUTM_OLDINTERFACE);
97 tapeInfo.structVersion = BUTM_MAJORVERSION;
99 tapeConfig.capacity = 0;
100 code = butm_file_Instantiate (&tapeInfo, &tapeConfig);
101 PASS ("zero capacity tape", BUTM_BADCONFIG);
102 tapeConfig.capacity = 100;
104 tapeConfig.fileMarkSize = 0;
105 code = butm_file_Instantiate (&tapeInfo, &tapeConfig);
106 PASS ("zero length filemark", BUTM_BADCONFIG);
107 tapeConfig.fileMarkSize = 16384;
109 strcpy(tapeConfig.device, "");
110 code = butm_file_Instantiate (&tapeInfo, &tapeConfig);
111 PASS ("no tape device name", BUTM_BADCONFIG);
112 strcpy(tapeConfig.device, "/dev/rmt0");
114 /* file_Mount and file_Dismount tests */
115 /* ---------------------------------- */
117 strcpy(tapeConfig.device, "/dev/Bogus");
118 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
119 PASSq("file Instantiate", 0);
120 strcpy(tapeConfig.device, "/dev/rmt0");
122 code = tapeInfo.ops.mount(NULL, "TAPE_NAME");
123 PASS ("Null tapeInfo ptr for mount", BUTM_BADARGUMENT);
125 code = tapeInfo.ops.dismount(NULL);
126 PASS ("Null info ptr for dismount", BUTM_BADARGUMENT);
130 code = tapeInfo.ops.mount(&tapeInfo, NULL);
131 PASS ("NULL virtual tape name", BUTM_BADARGUMENT);
133 code = tapeInfo.ops.mount(&tapeInfo, "-MORE_THAN_THIRTY_TWO_CHARACTERS-");
134 PASS (">32 character tape name", BUTM_BADARGUMENT);
136 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
137 PASS ("Bogus tape name", BUTM_MOUNTFAIL);
141 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
142 PASSq("file Instantiate", 0);
144 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
145 PASS ("Open tape drive", 0);
147 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
148 PASS ("Open tape drive 2nd time", BUTM_PARALLELMOUNTS);
150 code = tapeInfo.ops.dismount(&tapeInfo);
151 PASSq ("Unmount the tape drive", 0);
153 code = tapeInfo.ops.dismount(&tapeInfo);
154 PASS ("Unmount the tape drive which is not mounted", 0);
156 /* file_writeLabel and file_readLabel tests */
157 /* ---------------------------------------- */
159 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
160 PASSq("file Instantiate", 0);
162 code = tapeInfo.ops.create(NULL, &tapeLabelWrite, REWIND);
163 PASS ("NULL info to Write label", BUTM_BADARGUMENT);
165 code = tapeInfo.ops.readLabel(NULL, &tapeLabelWrite, REWIND);
166 PASS ("NULL info to Read Label", BUTM_BADARGUMENT);
170 code = tapeInfo.ops.create(&tapeInfo, &tapeLabelWrite, REWIND);
171 PASS ("Write label to unmounted tape", BUTM_NOMOUNT);
173 code = tapeInfo.ops.readLabel(&tapeInfo, &tapeLabelRead, REWIND);
174 PASS ("Read label of unmounted tape", BUTM_NOMOUNT);
178 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
179 PASSq ("Mount tape", 0);
181 bzero(tapeLabelWrite, sizeof(tapeLabelWrite));
182 tapeLabelWrite.structVersion = CUR_TAPE_VERSION;
183 tapeLabelWrite.creationTime = time(0);
184 tapeLabelWrite.expirationDate = time(0);
185 strcpy(tapeLabelWrite.name, "TAPE_LABEL_NAME");
186 /* tapeLabelWrite.creator. */
187 strcpy(tapeLabelWrite.cell, "CELLNAME");
188 tapeLabelWrite.dumpid = 999;
189 tapeLabelWrite.useCount = 8888;
190 strcpy(tapeLabelWrite.comment, "THIS IS THE COMMENT FIELD");
191 tapeLabelWrite.size = 77777;
192 strcpy(tapeLabelWrite.dumpPath, "/FULL/WEEK3/DAY4/HOUR7");
194 code = tapeInfo.ops.create(&tapeInfo, &tapeLabelWrite, REWIND);
195 PASS ("Write a label", 0);
197 code = tapeInfo.ops.readLabel(&tapeInfo, &tapeLabelRead, REWIND);
198 PASS ("Read a label", 0);
200 if ( bcmp(&tapeLabelWrite, &tapeLabelRead, sizeof(tapeLabelWrite)) )
201 printf("FAILURE: Label Read is not same as label Written\n");
203 printf("PASSED: Label Read is same as label Written\n");
205 code = tapeInfo.ops.dismount(&tapeInfo);
206 PASSq ("Unmount the tape drive", 0);
210 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
211 PASSq ("Mount tape", 0);
213 code = tapeInfo.ops.create(&tapeInfo, NULL, REWIND);
214 PASS ("Write a NULL label", BUTM_BADARGUMENT);
216 tapeLabelWrite.structVersion = 0;
217 code = tapeInfo.ops.create(&tapeInfo, &tapeLabelWrite, REWIND);
218 PASS ("Write label with bad version in it", BUTM_OLDINTERFACE);
219 tapeLabelWrite.structVersion = CUR_TAPE_VERSION;
221 code = tapeInfo.ops.dismount(&tapeInfo);
222 PASSq ("Unmount the tape drive", 0);
224 /* file_WriteFileBegin and file_ReadFileBegin tests */
225 /* file_WriteFileEnd and file_ReadFileEnd tests */
226 /* ------------------------------------------------ */
229 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
230 PASSq("file Instantiate", 0);
232 code = tapeInfo.ops.writeFileBegin(NULL);
233 PASS ("Null info ptr for writeFileBegin", BUTM_BADARGUMENT);
235 code = tapeInfo.ops.readFileBegin(NULL);
236 PASS ("Null info ptr for readFileBegin", BUTM_BADARGUMENT);
238 code = tapeInfo.ops.writeFileEnd(NULL);
239 PASS ("Null info ptr for writeFileEnd", BUTM_BADARGUMENT);
241 code = tapeInfo.ops.readFileEnd(NULL);
242 PASS ("Null info ptr for readFileEnd", BUTM_BADARGUMENT);
246 code = tapeInfo.ops.writeFileBegin(&tapeInfo);
247 PASS ("Tape not mounted for writeFileBegin", BUTM_NOMOUNT);
249 code = tapeInfo.ops.readFileBegin(&tapeInfo);
250 PASS ("Null info ptr for writeFileBegin", BUTM_NOMOUNT);
252 code = tapeInfo.ops.writeFileEnd(&tapeInfo);
253 PASS ("Tape not mounted for writeFileEnd", BUTM_NOMOUNT);
255 code = tapeInfo.ops.readFileEnd(&tapeInfo);
256 PASS ("Null info ptr for writeFileEnd", BUTM_NOMOUNT);
260 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
261 PASSq ("Mount tape", 0);
263 code = tapeInfo.ops.writeFileEnd(&tapeInfo);
264 PASS ("Write a fileEnd as first entry on tape", BUTM_BADOP);
266 code = tapeInfo.ops.readFileEnd(&tapeInfo);
267 PASS ("Read a fileEnd as first entry on tape", BUTM_BADOP);
269 code = tapeInfo.ops.dismount(&tapeInfo);
270 PASSq ("Unmount the tape drive", 0);
274 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
275 PASSq ("Mount tape", 0);
277 code = tapeInfo.ops.writeFileBegin(&tapeInfo);
278 PASS ("Write a fileBegin", 0);
280 code = tapeInfo.ops.writeFileEnd(&tapeInfo);
281 PASS ("Write a fileEnd", 0);
283 code = tapeInfo.ops.dismount(&tapeInfo);
284 PASSq ("Unmount the tape drive", 0);
288 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
289 PASSq ("Mount tape", 0);
291 code = tapeInfo.ops.readFileBegin(&tapeInfo);
292 PASS ("Read a fileBegin", 0);
294 code = tapeInfo.ops.readFileEnd(&tapeInfo);
295 PASS ("Read a fileEnd", 0);
297 code = tapeInfo.ops.dismount(&tapeInfo);
298 PASSq ("Unmount the tape drive", 0);
300 /* file_WriteFileData and file_ReadFileData tests */
301 /* ---------------------------------------------- */
303 dataBlock = &tapeBlock[sizeof(struct blockMark)];
304 dataSize = 16384 - sizeof(struct blockMark);
307 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
308 PASSq("file Instantiate", 0);
310 code = tapeInfo.ops.writeFileData(NULL, dataBlock, dataSize);
311 PASS ("Null info ptr for writeFileData", BUTM_BADARGUMENT);
313 code = tapeInfo.ops.readFileData(NULL, dataBlock, dataSize, nBytes);
314 PASS ("Null info ptr for readFileData", BUTM_BADARGUMENT);
318 code = tapeInfo.ops.writeFileData(&tapeInfo, NULL, dataSize);
319 PASS ("Null data ptr for writeFileData", BUTM_BADARGUMENT);
321 code = tapeInfo.ops.readFileData(&tapeInfo, NULL, dataSize, nBytes);
322 PASS ("Null data ptr for readFileData", BUTM_BADARGUMENT);
326 code = tapeInfo.ops.writeFileData(&tapeInfo, dataBlock, -1);
327 PASS ("Neg. data size for writeFileData", BUTM_BADARGUMENT);
329 code = tapeInfo.ops.readFileData(&tapeInfo, dataBlock, -1, nBytes);
330 PASS ("Neg. data size for readFileData", BUTM_BADARGUMENT);
334 code = tapeInfo.ops.writeFileData(&tapeInfo, dataBlock, dataSize + 1);
335 PASS ("Large data size for writeFileData", BUTM_BADARGUMENT);
337 code = tapeInfo.ops.readFileData(&tapeInfo, dataBlock, dataSize + 1, nBytes);
338 PASS ("Large data size for readFileData", BUTM_BADARGUMENT);
342 code = tapeInfo.ops.readFileData(&tapeInfo, dataBlock, dataSize, NULL);
343 PASS ("Null nBytes ptr for readFileData", BUTM_BADARGUMENT);
347 code = tapeInfo.ops.writeFileData(&tapeInfo, dataBlock, dataSize);
348 PASS ("First write for WriteFileData", BUTM_BADOP);
350 code = tapeInfo.ops.readFileData(&tapeInfo, dataBlock, dataSize, nBytes);
351 PASS ("First read for readFileData", BUTM_BADOP);