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 <afs/com_err.h>
18 #include "AFS_component_version_number.c"
22 static char *whoami
= "TEST FAIL";
24 #define NULL (char *)0
25 #define PASS(str, err) printf("TEST: %s\n", str); \
28 printf("FAILURE: expected %u; got %u\n", err, code); \
29 if (code) afs_com_err(whoami, code, ""); \
31 else printf("PASSED; got %u\n", err); \
34 #define PASSq(str, err) if (code != err) \
36 printf("TEST: %s\n", str); \
37 printf("FAILURE: expected %u; got %u\n", err, code); \
38 if (code) afs_com_err(whoami, code, ""); \
44 char tapeBlock
[16384];
53 char *tape
= "testtape.0";
60 struct butm_tapeInfo tapeInfo
;
61 struct tapeConfig tapeConfig
;
63 struct butm_tapeLabel tapeLabelWrite
, tapeLabelRead
;
68 initialize_BUTM_error_table();
70 tapeInfo
.structVersion
= BUTM_MAJORVERSION
;
72 strcpy(tapeConfig
.device
, "/dev/rmt0");
73 tapeConfig
.capacity
= 100;
74 tapeConfig
.fileMarkSize
= 16384;
75 tapeConfig
.portOffset
= 0;
76 tapeConfig
.aixScsi
= 0;
84 /* butm_file_Instantiate tests */
85 /* --------------------------- */
86 code
= butm_file_Instantiate(NULL
, &tapeConfig
);
87 PASS("Bad info paramater", BUTM_BADARGUMENT
)
89 code
= butm_file_Instantiate(&tapeInfo
, NULL
);
90 PASS("Bad config parameter", BUTM_BADCONFIG
);
92 tapeInfo
.structVersion
= 0;
93 code
= butm_file_Instantiate(&tapeInfo
, &tapeConfig
);
94 PASS("Bad version number", BUTM_OLDINTERFACE
);
95 tapeInfo
.structVersion
= BUTM_MAJORVERSION
;
97 tapeConfig
.capacity
= 0;
98 code
= butm_file_Instantiate(&tapeInfo
, &tapeConfig
);
99 PASS("zero capacity tape", BUTM_BADCONFIG
);
100 tapeConfig
.capacity
= 100;
102 tapeConfig
.fileMarkSize
= 0;
103 code
= butm_file_Instantiate(&tapeInfo
, &tapeConfig
);
104 PASS("zero length filemark", BUTM_BADCONFIG
);
105 tapeConfig
.fileMarkSize
= 16384;
107 strcpy(tapeConfig
.device
, "");
108 code
= butm_file_Instantiate(&tapeInfo
, &tapeConfig
);
109 PASS("no tape device name", BUTM_BADCONFIG
);
110 strcpy(tapeConfig
.device
, "/dev/rmt0");
112 /* file_Mount and file_Dismount tests */
113 /* ---------------------------------- */
115 strcpy(tapeConfig
.device
, "/dev/Bogus");
116 code
= butm_file_Instantiate(&tapeInfo
, &tapeConfig
);
117 PASSq("file Instantiate", 0);
118 strcpy(tapeConfig
.device
, "/dev/rmt0");
120 code
= tapeInfo
.ops
.mount(NULL
, "TAPE_NAME");
121 PASS("Null tapeInfo ptr for mount", BUTM_BADARGUMENT
);
123 code
= tapeInfo
.ops
.dismount(NULL
);
124 PASS("Null info ptr for dismount", BUTM_BADARGUMENT
);
128 code
= tapeInfo
.ops
.mount(&tapeInfo
, NULL
);
129 PASS("NULL virtual tape name", BUTM_BADARGUMENT
);
131 code
= tapeInfo
.ops
.mount(&tapeInfo
, "-MORE_THAN_THIRTY_TWO_CHARACTERS-");
132 PASS(">32 character tape name", BUTM_BADARGUMENT
);
134 code
= tapeInfo
.ops
.mount(&tapeInfo
, "TAPE_NAME");
135 PASS("Bogus tape name", BUTM_MOUNTFAIL
);
139 code
= butm_file_Instantiate(&tapeInfo
, &tapeConfig
);
140 PASSq("file Instantiate", 0);
142 code
= tapeInfo
.ops
.mount(&tapeInfo
, "TAPE_NAME");
143 PASS("Open tape drive", 0);
145 code
= tapeInfo
.ops
.mount(&tapeInfo
, "TAPE_NAME");
146 PASS("Open tape drive 2nd time", BUTM_PARALLELMOUNTS
);
148 code
= tapeInfo
.ops
.dismount(&tapeInfo
);
149 PASSq("Unmount the tape drive", 0);
151 code
= tapeInfo
.ops
.dismount(&tapeInfo
);
152 PASS("Unmount the tape drive which is not mounted", 0);
154 /* file_writeLabel and file_readLabel tests */
155 /* ---------------------------------------- */
157 code
= butm_file_Instantiate(&tapeInfo
, &tapeConfig
);
158 PASSq("file Instantiate", 0);
160 code
= tapeInfo
.ops
.create(NULL
, &tapeLabelWrite
, REWIND
);
161 PASS("NULL info to Write label", BUTM_BADARGUMENT
);
163 code
= tapeInfo
.ops
.readLabel(NULL
, &tapeLabelWrite
, REWIND
);
164 PASS("NULL info to Read Label", BUTM_BADARGUMENT
);
168 code
= tapeInfo
.ops
.create(&tapeInfo
, &tapeLabelWrite
, REWIND
);
169 PASS("Write label to unmounted tape", BUTM_NOMOUNT
);
171 code
= tapeInfo
.ops
.readLabel(&tapeInfo
, &tapeLabelRead
, REWIND
);
172 PASS("Read label of unmounted tape", BUTM_NOMOUNT
);
176 code
= tapeInfo
.ops
.mount(&tapeInfo
, "TAPE_NAME");
177 PASSq("Mount tape", 0);
179 memset(tapeLabelWrite
, 0, sizeof(tapeLabelWrite
));
180 tapeLabelWrite
.structVersion
= CUR_TAPE_VERSION
;
181 tapeLabelWrite
.creationTime
= time(0);
182 tapeLabelWrite
.expirationDate
= time(0);
183 strcpy(tapeLabelWrite
.name
, "TAPE_LABEL_NAME");
184 /* tapeLabelWrite.creator. */
185 strcpy(tapeLabelWrite
.cell
, "CELLNAME");
186 tapeLabelWrite
.dumpid
= 999;
187 tapeLabelWrite
.useCount
= 8888;
188 strcpy(tapeLabelWrite
.comment
, "THIS IS THE COMMENT FIELD");
189 tapeLabelWrite
.size
= 77777;
190 strcpy(tapeLabelWrite
.dumpPath
, "/FULL/WEEK3/DAY4/HOUR7");
192 code
= tapeInfo
.ops
.create(&tapeInfo
, &tapeLabelWrite
, REWIND
);
193 PASS("Write a label", 0);
195 code
= tapeInfo
.ops
.readLabel(&tapeInfo
, &tapeLabelRead
, REWIND
);
196 PASS("Read a label", 0);
198 if (memcmp(&tapeLabelWrite
, &tapeLabelRead
, sizeof(tapeLabelWrite
)))
199 printf("FAILURE: Label Read is not same as label Written\n");
201 printf("PASSED: Label Read is same as label Written\n");
203 code
= tapeInfo
.ops
.dismount(&tapeInfo
);
204 PASSq("Unmount the tape drive", 0);
208 code
= tapeInfo
.ops
.mount(&tapeInfo
, "TAPE_NAME");
209 PASSq("Mount tape", 0);
211 code
= tapeInfo
.ops
.create(&tapeInfo
, NULL
, REWIND
);
212 PASS("Write a NULL label", BUTM_BADARGUMENT
);
214 tapeLabelWrite
.structVersion
= 0;
215 code
= tapeInfo
.ops
.create(&tapeInfo
, &tapeLabelWrite
, REWIND
);
216 PASS("Write label with bad version in it", BUTM_OLDINTERFACE
);
217 tapeLabelWrite
.structVersion
= CUR_TAPE_VERSION
;
219 code
= tapeInfo
.ops
.dismount(&tapeInfo
);
220 PASSq("Unmount the tape drive", 0);
222 /* file_WriteFileBegin and file_ReadFileBegin tests */
223 /* file_WriteFileEnd and file_ReadFileEnd tests */
224 /* ------------------------------------------------ */
227 code
= butm_file_Instantiate(&tapeInfo
, &tapeConfig
);
228 PASSq("file Instantiate", 0);
230 code
= tapeInfo
.ops
.writeFileBegin(NULL
);
231 PASS("Null info ptr for writeFileBegin", BUTM_BADARGUMENT
);
233 code
= tapeInfo
.ops
.readFileBegin(NULL
);
234 PASS("Null info ptr for readFileBegin", BUTM_BADARGUMENT
);
236 code
= tapeInfo
.ops
.writeFileEnd(NULL
);
237 PASS("Null info ptr for writeFileEnd", BUTM_BADARGUMENT
);
239 code
= tapeInfo
.ops
.readFileEnd(NULL
);
240 PASS("Null info ptr for readFileEnd", BUTM_BADARGUMENT
);
244 code
= tapeInfo
.ops
.writeFileBegin(&tapeInfo
);
245 PASS("Tape not mounted for writeFileBegin", BUTM_NOMOUNT
);
247 code
= tapeInfo
.ops
.readFileBegin(&tapeInfo
);
248 PASS("Null info ptr for writeFileBegin", BUTM_NOMOUNT
);
250 code
= tapeInfo
.ops
.writeFileEnd(&tapeInfo
);
251 PASS("Tape not mounted for writeFileEnd", BUTM_NOMOUNT
);
253 code
= tapeInfo
.ops
.readFileEnd(&tapeInfo
);
254 PASS("Null info ptr for writeFileEnd", BUTM_NOMOUNT
);
258 code
= tapeInfo
.ops
.mount(&tapeInfo
, "TAPE_NAME");
259 PASSq("Mount tape", 0);
261 code
= tapeInfo
.ops
.writeFileEnd(&tapeInfo
);
262 PASS("Write a fileEnd as first entry on tape", BUTM_BADOP
);
264 code
= tapeInfo
.ops
.readFileEnd(&tapeInfo
);
265 PASS("Read a fileEnd as first entry on tape", BUTM_BADOP
);
267 code
= tapeInfo
.ops
.dismount(&tapeInfo
);
268 PASSq("Unmount the tape drive", 0);
272 code
= tapeInfo
.ops
.mount(&tapeInfo
, "TAPE_NAME");
273 PASSq("Mount tape", 0);
275 code
= tapeInfo
.ops
.writeFileBegin(&tapeInfo
);
276 PASS("Write a fileBegin", 0);
278 code
= tapeInfo
.ops
.writeFileEnd(&tapeInfo
);
279 PASS("Write a fileEnd", 0);
281 code
= tapeInfo
.ops
.dismount(&tapeInfo
);
282 PASSq("Unmount the tape drive", 0);
286 code
= tapeInfo
.ops
.mount(&tapeInfo
, "TAPE_NAME");
287 PASSq("Mount tape", 0);
289 code
= tapeInfo
.ops
.readFileBegin(&tapeInfo
);
290 PASS("Read a fileBegin", 0);
292 code
= tapeInfo
.ops
.readFileEnd(&tapeInfo
);
293 PASS("Read a fileEnd", 0);
295 code
= tapeInfo
.ops
.dismount(&tapeInfo
);
296 PASSq("Unmount the tape drive", 0);
298 /* file_WriteFileData and file_ReadFileData tests */
299 /* ---------------------------------------------- */
301 dataBlock
= &tapeBlock
[sizeof(struct blockMark
)];
302 dataSize
= 16384 - sizeof(struct blockMark
);
305 code
= butm_file_Instantiate(&tapeInfo
, &tapeConfig
);
306 PASSq("file Instantiate", 0);
308 code
= tapeInfo
.ops
.writeFileData(NULL
, dataBlock
, dataSize
);
309 PASS("Null info ptr for writeFileData", BUTM_BADARGUMENT
);
311 code
= tapeInfo
.ops
.readFileData(NULL
, dataBlock
, dataSize
, nBytes
);
312 PASS("Null info ptr for readFileData", BUTM_BADARGUMENT
);
316 code
= tapeInfo
.ops
.writeFileData(&tapeInfo
, NULL
, dataSize
);
317 PASS("Null data ptr for writeFileData", BUTM_BADARGUMENT
);
319 code
= tapeInfo
.ops
.readFileData(&tapeInfo
, NULL
, dataSize
, nBytes
);
320 PASS("Null data ptr for readFileData", BUTM_BADARGUMENT
);
324 code
= tapeInfo
.ops
.writeFileData(&tapeInfo
, dataBlock
, -1);
325 PASS("Neg. data size for writeFileData", BUTM_BADARGUMENT
);
327 code
= tapeInfo
.ops
.readFileData(&tapeInfo
, dataBlock
, -1, nBytes
);
328 PASS("Neg. data size for readFileData", BUTM_BADARGUMENT
);
332 code
= tapeInfo
.ops
.writeFileData(&tapeInfo
, dataBlock
, dataSize
+ 1);
333 PASS("Large data size for writeFileData", BUTM_BADARGUMENT
);
336 tapeInfo
.ops
.readFileData(&tapeInfo
, dataBlock
, dataSize
+ 1, nBytes
);
337 PASS("Large data size for readFileData", BUTM_BADARGUMENT
);
341 code
= tapeInfo
.ops
.readFileData(&tapeInfo
, dataBlock
, dataSize
, NULL
);
342 PASS("Null nBytes ptr for readFileData", BUTM_BADARGUMENT
);
346 code
= tapeInfo
.ops
.writeFileData(&tapeInfo
, dataBlock
, dataSize
);
347 PASS("First write for WriteFileData", BUTM_BADOP
);
349 code
= tapeInfo
.ops
.readFileData(&tapeInfo
, dataBlock
, dataSize
, nBytes
);
350 PASS("First read for readFileData", BUTM_BADOP
);