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 <afsconfig.h>
11 #include <afs/param.h>
15 #include <sys/types.h>
18 #include <afs/com_err.h>
20 #include <sys/ioctl.h>
21 #include <netinet/in.h>
24 #include "AFS_component_version_number.c"
28 static char *whoami = "TEST FAIL";
30 #define NULL (char *)0
31 #define PASS(str, err) printf("TEST: %s\n", str); \
34 printf("FAILURE: expected %u; got %u\n", err, code); \
35 if (code) com_err(whoami, code, ""); \
37 else printf("PASSED; got %u\n", err); \
40 #define PASSq(str, err) if (code != err) \
42 printf("TEST: %s\n", str); \
43 printf("FAILURE: expected %u; got %u\n", err, code); \
44 if (code) com_err(whoami, code, ""); \
50 char tapeBlock[16384];
59 char *tape = "testtape.0";
66 struct butm_tapeInfo tapeInfo;
67 struct tapeConfig tapeConfig;
69 struct butm_tapeLabel tapeLabelWrite, tapeLabelRead;
74 initialize_BUTM_error_table();
76 tapeInfo.structVersion = BUTM_MAJORVERSION;
78 strcpy(tapeConfig.device, "/dev/rmt0");
79 tapeConfig.capacity = 100;
80 tapeConfig.fileMarkSize = 16384;
81 tapeConfig.portOffset = 0;
82 tapeConfig.aixScsi = 0;
90 /* butm_file_Instantiate tests */
91 /* --------------------------- */
92 code = butm_file_Instantiate (NULL, &tapeConfig);
93 PASS("Bad info paramater", BUTM_BADARGUMENT)
95 code = butm_file_Instantiate (&tapeInfo, NULL);
96 PASS("Bad config parameter", BUTM_BADCONFIG);
98 tapeInfo.structVersion = 0;
99 code = butm_file_Instantiate (&tapeInfo, &tapeConfig);
100 PASS ("Bad version number", BUTM_OLDINTERFACE);
101 tapeInfo.structVersion = BUTM_MAJORVERSION;
103 tapeConfig.capacity = 0;
104 code = butm_file_Instantiate (&tapeInfo, &tapeConfig);
105 PASS ("zero capacity tape", BUTM_BADCONFIG);
106 tapeConfig.capacity = 100;
108 tapeConfig.fileMarkSize = 0;
109 code = butm_file_Instantiate (&tapeInfo, &tapeConfig);
110 PASS ("zero length filemark", BUTM_BADCONFIG);
111 tapeConfig.fileMarkSize = 16384;
113 strcpy(tapeConfig.device, "");
114 code = butm_file_Instantiate (&tapeInfo, &tapeConfig);
115 PASS ("no tape device name", BUTM_BADCONFIG);
116 strcpy(tapeConfig.device, "/dev/rmt0");
118 /* file_Mount and file_Dismount tests */
119 /* ---------------------------------- */
121 strcpy(tapeConfig.device, "/dev/Bogus");
122 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
123 PASSq("file Instantiate", 0);
124 strcpy(tapeConfig.device, "/dev/rmt0");
126 code = tapeInfo.ops.mount(NULL, "TAPE_NAME");
127 PASS ("Null tapeInfo ptr for mount", BUTM_BADARGUMENT);
129 code = tapeInfo.ops.dismount(NULL);
130 PASS ("Null info ptr for dismount", BUTM_BADARGUMENT);
134 code = tapeInfo.ops.mount(&tapeInfo, NULL);
135 PASS ("NULL virtual tape name", BUTM_BADARGUMENT);
137 code = tapeInfo.ops.mount(&tapeInfo, "-MORE_THAN_THIRTY_TWO_CHARACTERS-");
138 PASS (">32 character tape name", BUTM_BADARGUMENT);
140 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
141 PASS ("Bogus tape name", BUTM_MOUNTFAIL);
145 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
146 PASSq("file Instantiate", 0);
148 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
149 PASS ("Open tape drive", 0);
151 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
152 PASS ("Open tape drive 2nd time", BUTM_PARALLELMOUNTS);
154 code = tapeInfo.ops.dismount(&tapeInfo);
155 PASSq ("Unmount the tape drive", 0);
157 code = tapeInfo.ops.dismount(&tapeInfo);
158 PASS ("Unmount the tape drive which is not mounted", 0);
160 /* file_writeLabel and file_readLabel tests */
161 /* ---------------------------------------- */
163 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
164 PASSq("file Instantiate", 0);
166 code = tapeInfo.ops.create(NULL, &tapeLabelWrite, REWIND);
167 PASS ("NULL info to Write label", BUTM_BADARGUMENT);
169 code = tapeInfo.ops.readLabel(NULL, &tapeLabelWrite, REWIND);
170 PASS ("NULL info to Read Label", BUTM_BADARGUMENT);
174 code = tapeInfo.ops.create(&tapeInfo, &tapeLabelWrite, REWIND);
175 PASS ("Write label to unmounted tape", BUTM_NOMOUNT);
177 code = tapeInfo.ops.readLabel(&tapeInfo, &tapeLabelRead, REWIND);
178 PASS ("Read label of unmounted tape", BUTM_NOMOUNT);
182 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
183 PASSq ("Mount tape", 0);
185 memset(tapeLabelWrite, 0, sizeof(tapeLabelWrite));
186 tapeLabelWrite.structVersion = CUR_TAPE_VERSION;
187 tapeLabelWrite.creationTime = time(0);
188 tapeLabelWrite.expirationDate = time(0);
189 strcpy(tapeLabelWrite.name, "TAPE_LABEL_NAME");
190 /* tapeLabelWrite.creator. */
191 strcpy(tapeLabelWrite.cell, "CELLNAME");
192 tapeLabelWrite.dumpid = 999;
193 tapeLabelWrite.useCount = 8888;
194 strcpy(tapeLabelWrite.comment, "THIS IS THE COMMENT FIELD");
195 tapeLabelWrite.size = 77777;
196 strcpy(tapeLabelWrite.dumpPath, "/FULL/WEEK3/DAY4/HOUR7");
198 code = tapeInfo.ops.create(&tapeInfo, &tapeLabelWrite, REWIND);
199 PASS ("Write a label", 0);
201 code = tapeInfo.ops.readLabel(&tapeInfo, &tapeLabelRead, REWIND);
202 PASS ("Read a label", 0);
204 if ( memcmp(&tapeLabelWrite, &tapeLabelRead, sizeof(tapeLabelWrite)) )
205 printf("FAILURE: Label Read is not same as label Written\n");
207 printf("PASSED: Label Read is same as label Written\n");
209 code = tapeInfo.ops.dismount(&tapeInfo);
210 PASSq ("Unmount the tape drive", 0);
214 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
215 PASSq ("Mount tape", 0);
217 code = tapeInfo.ops.create(&tapeInfo, NULL, REWIND);
218 PASS ("Write a NULL label", BUTM_BADARGUMENT);
220 tapeLabelWrite.structVersion = 0;
221 code = tapeInfo.ops.create(&tapeInfo, &tapeLabelWrite, REWIND);
222 PASS ("Write label with bad version in it", BUTM_OLDINTERFACE);
223 tapeLabelWrite.structVersion = CUR_TAPE_VERSION;
225 code = tapeInfo.ops.dismount(&tapeInfo);
226 PASSq ("Unmount the tape drive", 0);
228 /* file_WriteFileBegin and file_ReadFileBegin tests */
229 /* file_WriteFileEnd and file_ReadFileEnd tests */
230 /* ------------------------------------------------ */
233 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
234 PASSq("file Instantiate", 0);
236 code = tapeInfo.ops.writeFileBegin(NULL);
237 PASS ("Null info ptr for writeFileBegin", BUTM_BADARGUMENT);
239 code = tapeInfo.ops.readFileBegin(NULL);
240 PASS ("Null info ptr for readFileBegin", BUTM_BADARGUMENT);
242 code = tapeInfo.ops.writeFileEnd(NULL);
243 PASS ("Null info ptr for writeFileEnd", BUTM_BADARGUMENT);
245 code = tapeInfo.ops.readFileEnd(NULL);
246 PASS ("Null info ptr for readFileEnd", BUTM_BADARGUMENT);
250 code = tapeInfo.ops.writeFileBegin(&tapeInfo);
251 PASS ("Tape not mounted for writeFileBegin", BUTM_NOMOUNT);
253 code = tapeInfo.ops.readFileBegin(&tapeInfo);
254 PASS ("Null info ptr for writeFileBegin", BUTM_NOMOUNT);
256 code = tapeInfo.ops.writeFileEnd(&tapeInfo);
257 PASS ("Tape not mounted for writeFileEnd", BUTM_NOMOUNT);
259 code = tapeInfo.ops.readFileEnd(&tapeInfo);
260 PASS ("Null info ptr for writeFileEnd", BUTM_NOMOUNT);
264 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
265 PASSq ("Mount tape", 0);
267 code = tapeInfo.ops.writeFileEnd(&tapeInfo);
268 PASS ("Write a fileEnd as first entry on tape", BUTM_BADOP);
270 code = tapeInfo.ops.readFileEnd(&tapeInfo);
271 PASS ("Read a fileEnd as first entry on tape", BUTM_BADOP);
273 code = tapeInfo.ops.dismount(&tapeInfo);
274 PASSq ("Unmount the tape drive", 0);
278 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
279 PASSq ("Mount tape", 0);
281 code = tapeInfo.ops.writeFileBegin(&tapeInfo);
282 PASS ("Write a fileBegin", 0);
284 code = tapeInfo.ops.writeFileEnd(&tapeInfo);
285 PASS ("Write a fileEnd", 0);
287 code = tapeInfo.ops.dismount(&tapeInfo);
288 PASSq ("Unmount the tape drive", 0);
292 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
293 PASSq ("Mount tape", 0);
295 code = tapeInfo.ops.readFileBegin(&tapeInfo);
296 PASS ("Read a fileBegin", 0);
298 code = tapeInfo.ops.readFileEnd(&tapeInfo);
299 PASS ("Read a fileEnd", 0);
301 code = tapeInfo.ops.dismount(&tapeInfo);
302 PASSq ("Unmount the tape drive", 0);
304 /* file_WriteFileData and file_ReadFileData tests */
305 /* ---------------------------------------------- */
307 dataBlock = &tapeBlock[sizeof(struct blockMark)];
308 dataSize = 16384 - sizeof(struct blockMark);
311 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
312 PASSq("file Instantiate", 0);
314 code = tapeInfo.ops.writeFileData(NULL, dataBlock, dataSize);
315 PASS ("Null info ptr for writeFileData", BUTM_BADARGUMENT);
317 code = tapeInfo.ops.readFileData(NULL, dataBlock, dataSize, nBytes);
318 PASS ("Null info ptr for readFileData", BUTM_BADARGUMENT);
322 code = tapeInfo.ops.writeFileData(&tapeInfo, NULL, dataSize);
323 PASS ("Null data ptr for writeFileData", BUTM_BADARGUMENT);
325 code = tapeInfo.ops.readFileData(&tapeInfo, NULL, dataSize, nBytes);
326 PASS ("Null data ptr for readFileData", BUTM_BADARGUMENT);
330 code = tapeInfo.ops.writeFileData(&tapeInfo, dataBlock, -1);
331 PASS ("Neg. data size for writeFileData", BUTM_BADARGUMENT);
333 code = tapeInfo.ops.readFileData(&tapeInfo, dataBlock, -1, nBytes);
334 PASS ("Neg. data size for readFileData", BUTM_BADARGUMENT);
338 code = tapeInfo.ops.writeFileData(&tapeInfo, dataBlock, dataSize + 1);
339 PASS ("Large data size for writeFileData", BUTM_BADARGUMENT);
341 code = tapeInfo.ops.readFileData(&tapeInfo, dataBlock, dataSize + 1, nBytes);
342 PASS ("Large data size for readFileData", BUTM_BADARGUMENT);
346 code = tapeInfo.ops.readFileData(&tapeInfo, dataBlock, dataSize, NULL);
347 PASS ("Null nBytes ptr for readFileData", BUTM_BADARGUMENT);
351 code = tapeInfo.ops.writeFileData(&tapeInfo, dataBlock, dataSize);
352 PASS ("First write for WriteFileData", BUTM_BADOP);
354 code = tapeInfo.ops.readFileData(&tapeInfo, dataBlock, dataSize, nBytes);
355 PASS ("First read for readFileData", BUTM_BADOP);