2 * Copyright (c) 2010-2012 Zmanda Inc. All Rights Reserved.
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 2.1 as
6 * published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
11 * License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18 * Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
22 #include "testutils.h"
23 #include "fileheader.h"
25 #define TAPE_HEADER(hdr) ((hdr)->type == F_TAPESTART || (hdr)->type == F_TAPEEND)
27 static int n_round_trips = 0;
29 /* actually test the round trip */
31 try_rt(dumpfile_t *hdr)
38 strval = build_header(hdr, &size, 32768);
39 g_assert(strval != NULL);
41 parse_file_header(strval, &hdr2, size);
43 if (!headers_are_equal(hdr, &hdr2)) {
44 tu_dbg("*** build_header of:\n");
46 tu_dbg("*** gives:\n");
48 tu_dbg("*** which becomes:\n");
49 dump_dumpfile_t(&hdr2);
55 dumpfile_free_data(&hdr2);
57 #define PREV_RT try_rt
61 rt_partnum(dumpfile_t *hdr)
63 if (hdr->type == F_SPLIT_DUMPFILE) {
66 if (!PREV_RT(hdr)) return 0;
69 if (!PREV_RT(hdr)) return 0;
72 if (!PREV_RT(hdr)) return 0;
73 } else if (hdr->type == F_DUMPFILE) {
76 if (!PREV_RT(hdr)) return 0;
80 if (!PREV_RT(hdr)) return 0;
84 #define PREV_RT rt_partnum
88 rt_compress(dumpfile_t *hdr)
90 if (TAPE_HEADER(hdr)) {
92 strcpy(hdr->comp_suffix, "");
93 if (!PREV_RT(hdr)) return 0;
96 strcpy(hdr->comp_suffix, "");
97 if (!PREV_RT(hdr)) return 0;
99 strcpy(hdr->comp_suffix, ".gz");
100 if (!PREV_RT(hdr)) return 0;
104 #define PREV_RT rt_compress
108 rt_encrypt(dumpfile_t *hdr)
110 if (TAPE_HEADER(hdr)) {
112 strcpy(hdr->encrypt_suffix, "");
113 if (!PREV_RT(hdr)) return 0;
116 strcpy(hdr->encrypt_suffix, "");
117 if (!PREV_RT(hdr)) return 0;
119 /* (note: Amanda seems to use 'enc' as the only suffix, and it doesn't
120 * really use it as a suffix; using .aes here ensures that the fileheader
121 * code can handle real suffixes, too */
123 strcpy(hdr->encrypt_suffix, ".aes");
124 if (!PREV_RT(hdr)) return 0;
128 #define PREV_RT rt_encrypt
132 rt_disk(dumpfile_t *hdr)
134 if (TAPE_HEADER(hdr)) {
135 strcpy(hdr->disk, "");
136 if (!PREV_RT(hdr)) return 0;
138 strcpy(hdr->disk, "/usr");
139 if (!PREV_RT(hdr)) return 0;
140 strcpy(hdr->disk, ""); /* should be quoted */
141 if (!PREV_RT(hdr)) return 0;
145 #define PREV_RT rt_disk
149 rt_partial(dumpfile_t *hdr)
151 if (TAPE_HEADER(hdr)) {
153 if (!PREV_RT(hdr)) return 0;
156 if (!PREV_RT(hdr)) return 0;
158 if (!PREV_RT(hdr)) return 0;
162 #define PREV_RT rt_partial
166 rt_application(dumpfile_t *hdr)
168 if (TAPE_HEADER(hdr)) {
169 strcpy(hdr->application, "");
170 if (!PREV_RT(hdr)) return 0;
172 strcpy(hdr->application, "MS-PAINT");
173 if (!PREV_RT(hdr)) return 0;
177 #define PREV_RT rt_application
181 rt_dle_str(dumpfile_t *hdr)
183 if (TAPE_HEADER(hdr)) {
184 strcpy(hdr->dle_str, "");
185 if (!PREV_RT(hdr)) return 0;
187 hdr->dle_str = g_strdup("");
188 if (!PREV_RT(hdr)) return 0;
189 hdr->dle_str = g_strdup("no-newline");
190 if (!PREV_RT(hdr)) return 0;
191 hdr->dle_str = g_strdup("ENDDLE\nmy dle\nENDDLE3");
192 if (!PREV_RT(hdr)) return 0;
196 #define PREV_RT rt_dle_str
200 rt_program(dumpfile_t *hdr)
202 if (TAPE_HEADER(hdr)) {
203 strcpy(hdr->program, "");
204 if (!PREV_RT(hdr)) return 0;
206 strcpy(hdr->program, "CHECK");
207 if (!PREV_RT(hdr)) return 0;
211 #define PREV_RT rt_program
215 rt_encrypt_prog(dumpfile_t *hdr)
217 /* only do this for F_DUMPFILE, just to spare some repetitive testing */
218 if (hdr->type == F_DUMPFILE) {
219 strcpy(hdr->srv_encrypt, "");
220 strcpy(hdr->clnt_encrypt, "");
221 strcpy(hdr->srv_decrypt_opt, "");
222 strcpy(hdr->clnt_decrypt_opt, "");
223 if (!PREV_RT(hdr)) return 0;
224 strcpy(hdr->srv_encrypt, "my-enc");
225 strcpy(hdr->clnt_encrypt, "");
226 strcpy(hdr->srv_decrypt_opt, "");
227 strcpy(hdr->clnt_decrypt_opt, "");
228 if (!PREV_RT(hdr)) return 0;
229 strcpy(hdr->srv_encrypt, "my-enc");
230 strcpy(hdr->clnt_encrypt, "");
231 strcpy(hdr->srv_decrypt_opt, "-foo");
232 strcpy(hdr->clnt_decrypt_opt, "");
233 if (!PREV_RT(hdr)) return 0;
234 strcpy(hdr->srv_encrypt, "");
235 strcpy(hdr->clnt_encrypt, "its-enc");
236 strcpy(hdr->srv_decrypt_opt, "");
237 strcpy(hdr->clnt_decrypt_opt, "");
238 if (!PREV_RT(hdr)) return 0;
239 strcpy(hdr->srv_encrypt, "");
240 strcpy(hdr->clnt_encrypt, "its-enc");
241 strcpy(hdr->srv_decrypt_opt, "");
242 strcpy(hdr->clnt_decrypt_opt, "-foo");
243 if (!PREV_RT(hdr)) return 0;
245 strcpy(hdr->srv_encrypt, "");
246 strcpy(hdr->clnt_encrypt, "");
247 strcpy(hdr->srv_decrypt_opt, "");
248 strcpy(hdr->clnt_decrypt_opt, "");
249 if (!PREV_RT(hdr)) return 0;
253 #define PREV_RT rt_encrypt_prog
257 rt_compprog(dumpfile_t *hdr)
259 /* only do this for F_DUMPFILE, just to spare some repetitive testing */
260 if (hdr->type == F_DUMPFILE) {
261 strcpy(hdr->srvcompprog, "");
262 strcpy(hdr->clntcompprog, "");
263 if (!PREV_RT(hdr)) return 0;
264 strcpy(hdr->srvcompprog, "my-comp-prog");
265 strcpy(hdr->clntcompprog, "");
266 if (!PREV_RT(hdr)) return 0;
267 strcpy(hdr->srvcompprog, "");
268 strcpy(hdr->clntcompprog, "its-comp-prog");
269 if (!PREV_RT(hdr)) return 0;
271 strcpy(hdr->srvcompprog, "");
272 strcpy(hdr->clntcompprog, "");
273 if (!PREV_RT(hdr)) return 0;
277 #define PREV_RT rt_compprog
281 rt_cmds(dumpfile_t *hdr)
283 /* only do this for F_SPLIT_DUMPFILE, just to spare some repetitive testing */
284 if (hdr->type == F_SPLIT_DUMPFILE) {
285 strcpy(hdr->recover_cmd, "");
286 strcpy(hdr->uncompress_cmd, "");
287 strcpy(hdr->decrypt_cmd, "");
288 if (!PREV_RT(hdr)) return 0;
289 strcpy(hdr->recover_cmd, "get my data back");
290 strcpy(hdr->uncompress_cmd, "");
291 strcpy(hdr->decrypt_cmd, "");
292 if (!PREV_RT(hdr)) return 0;
293 strcpy(hdr->recover_cmd, "get my data back");
294 strcpy(hdr->uncompress_cmd, "make my data bigger |");
295 strcpy(hdr->decrypt_cmd, "");
296 if (!PREV_RT(hdr)) return 0;
297 strcpy(hdr->recover_cmd, "get my data back");
298 strcpy(hdr->uncompress_cmd, "make my data bigger |");
299 strcpy(hdr->decrypt_cmd, "unscramble it too |");
300 if (!PREV_RT(hdr)) return 0;
302 strcpy(hdr->recover_cmd, "");
303 strcpy(hdr->uncompress_cmd, "");
304 strcpy(hdr->decrypt_cmd, "");
305 if (!PREV_RT(hdr)) return 0;
309 #define PREV_RT rt_cmds
313 rt_cont_filename(dumpfile_t *hdr)
315 if (hdr->type == F_DUMPFILE || hdr->type == F_CONT_DUMPFILE) {
316 strcpy(hdr->cont_filename, "/next/file");
317 if (!PREV_RT(hdr)) return 0;
319 strcpy(hdr->cont_filename, "");
320 if (!PREV_RT(hdr)) return 0;
324 #define PREV_RT rt_cont_filename
328 rt_dumplevel(dumpfile_t *hdr)
330 if (TAPE_HEADER(hdr)) {
332 if (!PREV_RT(hdr)) return 0;
335 if (!PREV_RT(hdr)) return 0;
337 if (!PREV_RT(hdr)) return 0;
341 #define PREV_RT rt_dumplevel
345 rt_name(dumpfile_t *hdr)
347 if (hdr->type == F_TAPEEND)
348 strcpy(hdr->name, "");
349 else if (TAPE_HEADER(hdr))
350 strcpy(hdr->name, "TEST-LABEL");
352 strcpy(hdr->name, "batcave-web");
353 if (!PREV_RT(hdr)) return 0;
356 #define PREV_RT rt_name
360 rt_type(dumpfile_t *hdr)
362 hdr->type = F_DUMPFILE;
363 if (!PREV_RT(hdr)) return 0;
364 hdr->type = F_CONT_DUMPFILE;
365 if (!PREV_RT(hdr)) return 0;
366 hdr->type = F_SPLIT_DUMPFILE;
367 if (!PREV_RT(hdr)) return 0;
368 hdr->type = F_TAPESTART;
369 if (!PREV_RT(hdr)) return 0;
370 hdr->type = F_TAPEEND;
371 if (!PREV_RT(hdr)) return 0;
374 #define PREV_RT rt_type
377 /* one function for each field; each fn calls the one above */
385 /* set up some basic, constant values */
386 strcpy(hdr.datestamp, "20100102030405");
387 strcpy(hdr.name, "localhost");
390 tu_dbg("%d round-trips run\n", n_round_trips);
391 return (rv) ? TRUE : FALSE;
396 encrypted + encrypt_suffix (N special)
397 compressed + comp_suffix (N special)
399 partnum/totalparts interaction
400 {srv,clnt}{compprog,_encrypt} pairs
401 uncompress/decrypt_cmd invalid without recover_cmd
402 uncompress/decrypt_cmd require trailing |
403 default to uncompress if only 2 cmds
408 main(int argc, char **argv)
410 static TestUtilsTest tests[] = {
411 TU_TEST(test_roundtrip, 90),
414 return testutils_run_tests(argc, argv, tests);