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