bu*: Tidy header includes
[openafs.git] / src / butm / butm_test.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
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
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 #include <roken.h>
14
15 #include <afs/com_err.h>
16 #include <lwp.h>
17 #include <afs/butm.h>
18 #include "AFS_component_version_number.c"
19
20
21
22 static char *whoami = "TEST FAIL";
23
24 #define NULL (char *)0
25 #define PASS(str, err) printf("TEST: %s\n", str); \
26                        if (code != err) \
27                        { \
28                           printf("FAILURE: expected %u; got %u\n", err, code); \
29                           if (code) afs_com_err(whoami, code, ""); \
30                        } \
31                        else printf("PASSED; got %u\n", err); \
32                        printf("\n");
33
34 #define PASSq(str, err) if (code != err) \
35                         { \
36                            printf("TEST: %s\n", str); \
37                            printf("FAILURE: expected %u; got %u\n", err, code); \
38                            if (code) afs_com_err(whoami, code, ""); \
39                            printf("\n"); \
40                         }
41 #define NOREWIND 0
42 #define REWIND   1
43
44 char tapeBlock[16384];
45 char *dataBlock;
46 long dataSize;
47
48 main(argc, argv)
49      int argc;
50      char *argv[];
51 {
52     char *config = 0;
53     char *tape = "testtape.0";
54     long code;
55     char **files;
56     int nFiles;
57     int i;
58     int past;
59
60     struct butm_tapeInfo tapeInfo;
61     struct tapeConfig tapeConfig;
62
63     struct butm_tapeLabel tapeLabelWrite, tapeLabelRead;
64
65     /* -------------
66      * General Setup
67      * ------------- */
68     initialize_BUTM_error_table();
69
70     tapeInfo.structVersion = BUTM_MAJORVERSION;
71
72     strcpy(tapeConfig.device, "/dev/rmt0");
73     tapeConfig.capacity = 100;
74     tapeConfig.fileMarkSize = 16384;
75     tapeConfig.portOffset = 0;
76     tapeConfig.aixScsi = 0;
77
78     goto start;
79
80     /* ------------- */
81     /* START TESTING */
82     /* ------------- */
83
84     /* butm_file_Instantiate tests */
85     /* --------------------------- */
86     code = butm_file_Instantiate(NULL, &tapeConfig);
87     PASS("Bad info paramater", BUTM_BADARGUMENT)
88
89         code = butm_file_Instantiate(&tapeInfo, NULL);
90     PASS("Bad config parameter", BUTM_BADCONFIG);
91
92     tapeInfo.structVersion = 0;
93     code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
94     PASS("Bad version number", BUTM_OLDINTERFACE);
95     tapeInfo.structVersion = BUTM_MAJORVERSION;
96
97     tapeConfig.capacity = 0;
98     code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
99     PASS("zero capacity tape", BUTM_BADCONFIG);
100     tapeConfig.capacity = 100;
101
102     tapeConfig.fileMarkSize = 0;
103     code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
104     PASS("zero length filemark", BUTM_BADCONFIG);
105     tapeConfig.fileMarkSize = 16384;
106
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");
111
112     /* file_Mount and file_Dismount tests */
113     /* ---------------------------------- */
114
115     strcpy(tapeConfig.device, "/dev/Bogus");
116     code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
117     PASSq("file Instantiate", 0);
118     strcpy(tapeConfig.device, "/dev/rmt0");
119
120     code = tapeInfo.ops.mount(NULL, "TAPE_NAME");
121     PASS("Null tapeInfo ptr for mount", BUTM_BADARGUMENT);
122
123     code = tapeInfo.ops.dismount(NULL);
124     PASS("Null info ptr for dismount", BUTM_BADARGUMENT);
125
126     /* --------- */
127
128     code = tapeInfo.ops.mount(&tapeInfo, NULL);
129     PASS("NULL virtual tape name", BUTM_BADARGUMENT);
130
131     code = tapeInfo.ops.mount(&tapeInfo, "-MORE_THAN_THIRTY_TWO_CHARACTERS-");
132     PASS(">32 character tape name", BUTM_BADARGUMENT);
133
134     code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
135     PASS("Bogus tape name", BUTM_MOUNTFAIL);
136
137     /* --------- */
138
139     code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
140     PASSq("file Instantiate", 0);
141
142     code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
143     PASS("Open tape drive", 0);
144
145     code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
146     PASS("Open tape drive 2nd time", BUTM_PARALLELMOUNTS);
147
148     code = tapeInfo.ops.dismount(&tapeInfo);
149     PASSq("Unmount the tape drive", 0);
150
151     code = tapeInfo.ops.dismount(&tapeInfo);
152     PASS("Unmount the tape drive which is not mounted", 0);
153
154     /* file_writeLabel and file_readLabel tests */
155     /* ---------------------------------------- */
156
157     code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
158     PASSq("file Instantiate", 0);
159
160     code = tapeInfo.ops.create(NULL, &tapeLabelWrite, REWIND);
161     PASS("NULL info to Write label", BUTM_BADARGUMENT);
162
163     code = tapeInfo.ops.readLabel(NULL, &tapeLabelWrite, REWIND);
164     PASS("NULL info to Read Label", BUTM_BADARGUMENT);
165
166     /* ---------- */
167
168     code = tapeInfo.ops.create(&tapeInfo, &tapeLabelWrite, REWIND);
169     PASS("Write label to unmounted tape", BUTM_NOMOUNT);
170
171     code = tapeInfo.ops.readLabel(&tapeInfo, &tapeLabelRead, REWIND);
172     PASS("Read label of unmounted tape", BUTM_NOMOUNT);
173
174     /* ---------- */
175
176     code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
177     PASSq("Mount tape", 0);
178
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");
191
192     code = tapeInfo.ops.create(&tapeInfo, &tapeLabelWrite, REWIND);
193     PASS("Write a label", 0);
194
195     code = tapeInfo.ops.readLabel(&tapeInfo, &tapeLabelRead, REWIND);
196     PASS("Read a label", 0);
197
198     if (memcmp(&tapeLabelWrite, &tapeLabelRead, sizeof(tapeLabelWrite)))
199         printf("FAILURE: Label Read is not same as label Written\n");
200     else
201         printf("PASSED: Label Read is same as label Written\n");
202
203     code = tapeInfo.ops.dismount(&tapeInfo);
204     PASSq("Unmount the tape drive", 0);
205
206     /* ---------- */
207
208     code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
209     PASSq("Mount tape", 0);
210
211     code = tapeInfo.ops.create(&tapeInfo, NULL, REWIND);
212     PASS("Write a NULL label", BUTM_BADARGUMENT);
213
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;
218
219     code = tapeInfo.ops.dismount(&tapeInfo);
220     PASSq("Unmount the tape drive", 0);
221
222     /* file_WriteFileBegin and file_ReadFileBegin tests */
223     /* file_WriteFileEnd   and file_ReadFileEnd   tests */
224     /* ------------------------------------------------ */
225
226   start:
227     code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
228     PASSq("file Instantiate", 0);
229
230     code = tapeInfo.ops.writeFileBegin(NULL);
231     PASS("Null info ptr for writeFileBegin", BUTM_BADARGUMENT);
232
233     code = tapeInfo.ops.readFileBegin(NULL);
234     PASS("Null info ptr for readFileBegin", BUTM_BADARGUMENT);
235
236     code = tapeInfo.ops.writeFileEnd(NULL);
237     PASS("Null info ptr for writeFileEnd", BUTM_BADARGUMENT);
238
239     code = tapeInfo.ops.readFileEnd(NULL);
240     PASS("Null info ptr for readFileEnd", BUTM_BADARGUMENT);
241
242     /* ---------- */
243
244     code = tapeInfo.ops.writeFileBegin(&tapeInfo);
245     PASS("Tape not mounted for writeFileBegin", BUTM_NOMOUNT);
246
247     code = tapeInfo.ops.readFileBegin(&tapeInfo);
248     PASS("Null info ptr for writeFileBegin", BUTM_NOMOUNT);
249
250     code = tapeInfo.ops.writeFileEnd(&tapeInfo);
251     PASS("Tape not mounted for writeFileEnd", BUTM_NOMOUNT);
252
253     code = tapeInfo.ops.readFileEnd(&tapeInfo);
254     PASS("Null info ptr for writeFileEnd", BUTM_NOMOUNT);
255
256     /* ---------- */
257
258     code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
259     PASSq("Mount tape", 0);
260
261     code = tapeInfo.ops.writeFileEnd(&tapeInfo);
262     PASS("Write a fileEnd as first entry on tape", BUTM_BADOP);
263
264     code = tapeInfo.ops.readFileEnd(&tapeInfo);
265     PASS("Read a fileEnd as first entry on tape", BUTM_BADOP);
266
267     code = tapeInfo.ops.dismount(&tapeInfo);
268     PASSq("Unmount the tape drive", 0);
269
270     /* ---------- */
271
272     code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
273     PASSq("Mount tape", 0);
274
275     code = tapeInfo.ops.writeFileBegin(&tapeInfo);
276     PASS("Write a fileBegin", 0);
277
278     code = tapeInfo.ops.writeFileEnd(&tapeInfo);
279     PASS("Write a fileEnd", 0);
280
281     code = tapeInfo.ops.dismount(&tapeInfo);
282     PASSq("Unmount the tape drive", 0);
283
284     /* ---------- */
285
286     code = tapeInfo.ops.mount(&tapeInfo, "TAPE_NAME");
287     PASSq("Mount tape", 0);
288
289     code = tapeInfo.ops.readFileBegin(&tapeInfo);
290     PASS("Read a fileBegin", 0);
291
292     code = tapeInfo.ops.readFileEnd(&tapeInfo);
293     PASS("Read a fileEnd", 0);
294
295     code = tapeInfo.ops.dismount(&tapeInfo);
296     PASSq("Unmount the tape drive", 0);
297
298     /* file_WriteFileData and file_ReadFileData tests */
299     /* ---------------------------------------------- */
300
301     dataBlock = &tapeBlock[sizeof(struct blockMark)];
302     dataSize = 16384 - sizeof(struct blockMark);
303
304
305     code = butm_file_Instantiate(&tapeInfo, &tapeConfig);
306     PASSq("file Instantiate", 0);
307
308     code = tapeInfo.ops.writeFileData(NULL, dataBlock, dataSize);
309     PASS("Null info ptr for writeFileData", BUTM_BADARGUMENT);
310
311     code = tapeInfo.ops.readFileData(NULL, dataBlock, dataSize, nBytes);
312     PASS("Null info ptr for readFileData", BUTM_BADARGUMENT);
313
314     /* ---------- */
315
316     code = tapeInfo.ops.writeFileData(&tapeInfo, NULL, dataSize);
317     PASS("Null data ptr for writeFileData", BUTM_BADARGUMENT);
318
319     code = tapeInfo.ops.readFileData(&tapeInfo, NULL, dataSize, nBytes);
320     PASS("Null data ptr for readFileData", BUTM_BADARGUMENT);
321
322     /* ---------- */
323
324     code = tapeInfo.ops.writeFileData(&tapeInfo, dataBlock, -1);
325     PASS("Neg. data size for writeFileData", BUTM_BADARGUMENT);
326
327     code = tapeInfo.ops.readFileData(&tapeInfo, dataBlock, -1, nBytes);
328     PASS("Neg. data size for readFileData", BUTM_BADARGUMENT);
329
330     /* ---------- */
331
332     code = tapeInfo.ops.writeFileData(&tapeInfo, dataBlock, dataSize + 1);
333     PASS("Large data size for writeFileData", BUTM_BADARGUMENT);
334
335     code =
336         tapeInfo.ops.readFileData(&tapeInfo, dataBlock, dataSize + 1, nBytes);
337     PASS("Large data size for readFileData", BUTM_BADARGUMENT);
338
339     /* ---------- */
340
341     code = tapeInfo.ops.readFileData(&tapeInfo, dataBlock, dataSize, NULL);
342     PASS("Null nBytes ptr for readFileData", BUTM_BADARGUMENT);
343
344     /* ---------- */
345
346     code = tapeInfo.ops.writeFileData(&tapeInfo, dataBlock, dataSize);
347     PASS("First write for WriteFileData", BUTM_BADOP);
348
349     code = tapeInfo.ops.readFileData(&tapeInfo, dataBlock, dataSize, nBytes);
350     PASS("First read for readFileData", BUTM_BADOP);
351
352   end:return;
353 }