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>
17 #include <sys/types.h>
20 #include <afs/com_err.h>
22 #include <sys/ioctl.h>
23 #include <netinet/in.h>
26 #include "AFS_component_version_number.c"
30 static char *whoami = "TEST FAIL";
32 #define NULL (char *)0
33 #define PASS(str, err) printf("TEST: %s\n", str); \
36 printf("FAILURE: expected %u; got %u\n", err, code); \
37 if (code) com_err(whoami, code, ""); \
39 else printf("PASSED; got %u\n", err); \
42 #define PASSq(str, err) if (code != err) \
44 printf("TEST: %s\n", str); \
45 printf("FAILURE: expected %u; got %u\n", err, code); \
46 if (code) com_err(whoami, code, ""); \
52 char tapeBlock[16384];
61 char *tape = "testtape.0";
68 struct butm_tapeInfo tapeInfo;
69 struct tapeConfig tapeConfig;
71 struct butm_tapeLabel tapeLabelWrite, tapeLabelRead;
76 initialize_BUTM_error_table();
78 tapeInfo.structVersion = BUTM_MAJORVERSION;
80 strcpy(tapeConfig.device, "/dev/rmt0");
81 tapeConfig.capacity = 100;
82 tapeConfig.fileMarkSize = 16384;
83 tapeConfig.portOffset = 0;
84 tapeConfig.aixScsi = 0;
92 /* butm_file_Instantiate tests */
93 /* --------------------------- */
94 code = butm_file_Instantiate(NULL, &tapeConfig);
95 PASS("Bad info paramater", BUTM_BADARGUMENT)
97 code = butm_file_Instantiate(&tapeInfo, NULL);
98 PASS("Bad config parameter", BUTM_BADCONFIG);
100 tapeInfo.structVersion = 0;
101 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
102 PASS("Bad version number", BUTM_OLDINTERFACE);
103 tapeInfo.structVersion = BUTM_MAJORVERSION;
105 tapeConfig.capacity = 0;
106 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
107 PASS("zero capacity tape", BUTM_BADCONFIG);
108 tapeConfig.capacity = 100;
110 tapeConfig.fileMarkSize = 0;
111 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
112 PASS("zero length filemark", BUTM_BADCONFIG);
113 tapeConfig.fileMarkSize = 16384;
115 strcpy(tapeConfig.device, "");
116 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
117 PASS("no tape device name", BUTM_BADCONFIG);
118 strcpy(tapeConfig.device, "/dev/rmt0");
120 /* file_Mount and file_Dismount tests */
121 /* ---------------------------------- */
123 strcpy(tapeConfig.device, "/dev/Bogus");
124 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
125 PASSq("file Instantiate", 0);
126 strcpy(tapeConfig.device, "/dev/rmt0");
128 code = tapeInfo.ops.mount(NULL, "TAPE_NAME");
129 PASS("Null tapeInfo ptr for mount", BUTM_BADARGUMENT);
131 code = tapeInfo.ops.dismount(NULL);
132 PASS("Null info ptr for dismount", BUTM_BADARGUMENT);
136 code = tapeInfo.ops.mount(&tapeInfo, NULL);
137 PASS("NULL virtual tape name", BUTM_BADARGUMENT);
139 code = tapeInfo.ops.mount(&tapeInfo, "-MORE_THAN_THIRTY_TWO_CHARACTERS-");
140 PASS(">32 character tape name", BUTM_BADARGUMENT);
142 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
143 PASS("Bogus tape name", BUTM_MOUNTFAIL);
147 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
148 PASSq("file Instantiate", 0);
150 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
151 PASS("Open tape drive", 0);
153 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
154 PASS("Open tape drive 2nd time", BUTM_PARALLELMOUNTS);
156 code = tapeInfo.ops.dismount(&tapeInfo);
157 PASSq("Unmount the tape drive", 0);
159 code = tapeInfo.ops.dismount(&tapeInfo);
160 PASS("Unmount the tape drive which is not mounted", 0);
162 /* file_writeLabel and file_readLabel tests */
163 /* ---------------------------------------- */
165 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
166 PASSq("file Instantiate", 0);
168 code = tapeInfo.ops.create(NULL, &tapeLabelWrite, REWIND);
169 PASS("NULL info to Write label", BUTM_BADARGUMENT);
171 code = tapeInfo.ops.readLabel(NULL, &tapeLabelWrite, REWIND);
172 PASS("NULL info to Read Label", BUTM_BADARGUMENT);
176 code = tapeInfo.ops.create(&tapeInfo, &tapeLabelWrite, REWIND);
177 PASS("Write label to unmounted tape", BUTM_NOMOUNT);
179 code = tapeInfo.ops.readLabel(&tapeInfo, &tapeLabelRead, REWIND);
180 PASS("Read label of unmounted tape", BUTM_NOMOUNT);
184 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
185 PASSq("Mount tape", 0);
187 memset(tapeLabelWrite, 0, sizeof(tapeLabelWrite));
188 tapeLabelWrite.structVersion = CUR_TAPE_VERSION;
189 tapeLabelWrite.creationTime = time(0);
190 tapeLabelWrite.expirationDate = time(0);
191 strcpy(tapeLabelWrite.name, "TAPE_LABEL_NAME");
192 /* tapeLabelWrite.creator. */
193 strcpy(tapeLabelWrite.cell, "CELLNAME");
194 tapeLabelWrite.dumpid = 999;
195 tapeLabelWrite.useCount = 8888;
196 strcpy(tapeLabelWrite.comment, "THIS IS THE COMMENT FIELD");
197 tapeLabelWrite.size = 77777;
198 strcpy(tapeLabelWrite.dumpPath, "/FULL/WEEK3/DAY4/HOUR7");
200 code = tapeInfo.ops.create(&tapeInfo, &tapeLabelWrite, REWIND);
201 PASS("Write a label", 0);
203 code = tapeInfo.ops.readLabel(&tapeInfo, &tapeLabelRead, REWIND);
204 PASS("Read a label", 0);
206 if (memcmp(&tapeLabelWrite, &tapeLabelRead, sizeof(tapeLabelWrite)))
207 printf("FAILURE: Label Read is not same as label Written\n");
209 printf("PASSED: Label Read is same as label Written\n");
211 code = tapeInfo.ops.dismount(&tapeInfo);
212 PASSq("Unmount the tape drive", 0);
216 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
217 PASSq("Mount tape", 0);
219 code = tapeInfo.ops.create(&tapeInfo, NULL, REWIND);
220 PASS("Write a NULL label", BUTM_BADARGUMENT);
222 tapeLabelWrite.structVersion = 0;
223 code = tapeInfo.ops.create(&tapeInfo, &tapeLabelWrite, REWIND);
224 PASS("Write label with bad version in it", BUTM_OLDINTERFACE);
225 tapeLabelWrite.structVersion = CUR_TAPE_VERSION;
227 code = tapeInfo.ops.dismount(&tapeInfo);
228 PASSq("Unmount the tape drive", 0);
230 /* file_WriteFileBegin and file_ReadFileBegin tests */
231 /* file_WriteFileEnd and file_ReadFileEnd tests */
232 /* ------------------------------------------------ */
235 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
236 PASSq("file Instantiate", 0);
238 code = tapeInfo.ops.writeFileBegin(NULL);
239 PASS("Null info ptr for writeFileBegin", BUTM_BADARGUMENT);
241 code = tapeInfo.ops.readFileBegin(NULL);
242 PASS("Null info ptr for readFileBegin", BUTM_BADARGUMENT);
244 code = tapeInfo.ops.writeFileEnd(NULL);
245 PASS("Null info ptr for writeFileEnd", BUTM_BADARGUMENT);
247 code = tapeInfo.ops.readFileEnd(NULL);
248 PASS("Null info ptr for readFileEnd", BUTM_BADARGUMENT);
252 code = tapeInfo.ops.writeFileBegin(&tapeInfo);
253 PASS("Tape not mounted for writeFileBegin", BUTM_NOMOUNT);
255 code = tapeInfo.ops.readFileBegin(&tapeInfo);
256 PASS("Null info ptr for writeFileBegin", BUTM_NOMOUNT);
258 code = tapeInfo.ops.writeFileEnd(&tapeInfo);
259 PASS("Tape not mounted for writeFileEnd", BUTM_NOMOUNT);
261 code = tapeInfo.ops.readFileEnd(&tapeInfo);
262 PASS("Null info ptr for writeFileEnd", BUTM_NOMOUNT);
266 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
267 PASSq("Mount tape", 0);
269 code = tapeInfo.ops.writeFileEnd(&tapeInfo);
270 PASS("Write a fileEnd as first entry on tape", BUTM_BADOP);
272 code = tapeInfo.ops.readFileEnd(&tapeInfo);
273 PASS("Read a fileEnd as first entry on tape", BUTM_BADOP);
275 code = tapeInfo.ops.dismount(&tapeInfo);
276 PASSq("Unmount the tape drive", 0);
280 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
281 PASSq("Mount tape", 0);
283 code = tapeInfo.ops.writeFileBegin(&tapeInfo);
284 PASS("Write a fileBegin", 0);
286 code = tapeInfo.ops.writeFileEnd(&tapeInfo);
287 PASS("Write a fileEnd", 0);
289 code = tapeInfo.ops.dismount(&tapeInfo);
290 PASSq("Unmount the tape drive", 0);
294 code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
295 PASSq("Mount tape", 0);
297 code = tapeInfo.ops.readFileBegin(&tapeInfo);
298 PASS("Read a fileBegin", 0);
300 code = tapeInfo.ops.readFileEnd(&tapeInfo);
301 PASS("Read a fileEnd", 0);
303 code = tapeInfo.ops.dismount(&tapeInfo);
304 PASSq("Unmount the tape drive", 0);
306 /* file_WriteFileData and file_ReadFileData tests */
307 /* ---------------------------------------------- */
309 dataBlock = &tapeBlock[sizeof(struct blockMark)];
310 dataSize = 16384 - sizeof(struct blockMark);
313 code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
314 PASSq("file Instantiate", 0);
316 code = tapeInfo.ops.writeFileData(NULL, dataBlock, dataSize);
317 PASS("Null info ptr for writeFileData", BUTM_BADARGUMENT);
319 code = tapeInfo.ops.readFileData(NULL, dataBlock, dataSize, nBytes);
320 PASS("Null info ptr for readFileData", BUTM_BADARGUMENT);
324 code = tapeInfo.ops.writeFileData(&tapeInfo, NULL, dataSize);
325 PASS("Null data ptr for writeFileData", BUTM_BADARGUMENT);
327 code = tapeInfo.ops.readFileData(&tapeInfo, NULL, dataSize, nBytes);
328 PASS("Null data ptr for readFileData", BUTM_BADARGUMENT);
332 code = tapeInfo.ops.writeFileData(&tapeInfo, dataBlock, -1);
333 PASS("Neg. data size for writeFileData", BUTM_BADARGUMENT);
335 code = tapeInfo.ops.readFileData(&tapeInfo, dataBlock, -1, nBytes);
336 PASS("Neg. data size for readFileData", BUTM_BADARGUMENT);
340 code = tapeInfo.ops.writeFileData(&tapeInfo, dataBlock, dataSize + 1);
341 PASS("Large data size for writeFileData", BUTM_BADARGUMENT);
344 tapeInfo.ops.readFileData(&tapeInfo, dataBlock, dataSize + 1, nBytes);
345 PASS("Large data size for readFileData", BUTM_BADARGUMENT);
349 code = tapeInfo.ops.readFileData(&tapeInfo, dataBlock, dataSize, NULL);
350 PASS("Null nBytes ptr for readFileData", BUTM_BADARGUMENT);
354 code = tapeInfo.ops.writeFileData(&tapeInfo, dataBlock, dataSize);
355 PASS("First write for WriteFileData", BUTM_BADOP);
357 code = tapeInfo.ops.readFileData(&tapeInfo, dataBlock, dataSize, nBytes);
358 PASS("First read for readFileData", BUTM_BADOP);