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