2 * Copyright (c) 2010-2012 Zmanda Inc. All Rights Reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12 * License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
19 * Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
23 #include "testutils.h"
24 #include "fileheader.h"
26 #define TAPE_HEADER(hdr) ((hdr)->type == F_TAPESTART || (hdr)->type == F_TAPEEND)
28 static int n_round_trips = 0;
30 /* actually test the round trip */
32 try_rt(dumpfile_t *hdr)
39 strval = build_header(hdr, &size, 32768);
40 g_assert(strval != NULL);
42 parse_file_header(strval, &hdr2, size);
44 if (!headers_are_equal(hdr, &hdr2)) {
45 tu_dbg("*** build_header of:\n");
47 tu_dbg("*** gives:\n");
49 tu_dbg("*** which becomes:\n");
50 dump_dumpfile_t(&hdr2);
56 dumpfile_free_data(&hdr2);
58 #define PREV_RT try_rt
62 rt_partnum(dumpfile_t *hdr)
64 if (hdr->type == F_SPLIT_DUMPFILE) {
67 if (!PREV_RT(hdr)) return 0;
70 if (!PREV_RT(hdr)) return 0;
73 if (!PREV_RT(hdr)) return 0;
74 } else if (hdr->type == F_DUMPFILE) {
77 if (!PREV_RT(hdr)) return 0;
81 if (!PREV_RT(hdr)) return 0;
85 #define PREV_RT rt_partnum
89 rt_compress(dumpfile_t *hdr)
91 if (TAPE_HEADER(hdr)) {
93 strcpy(hdr->comp_suffix, "");
94 if (!PREV_RT(hdr)) return 0;
97 strcpy(hdr->comp_suffix, "");
98 if (!PREV_RT(hdr)) return 0;
100 strcpy(hdr->comp_suffix, ".gz");
101 if (!PREV_RT(hdr)) return 0;
105 #define PREV_RT rt_compress
109 rt_encrypt(dumpfile_t *hdr)
111 if (TAPE_HEADER(hdr)) {
113 strcpy(hdr->encrypt_suffix, "");
114 if (!PREV_RT(hdr)) return 0;
117 strcpy(hdr->encrypt_suffix, "");
118 if (!PREV_RT(hdr)) return 0;
120 /* (note: Amanda seems to use 'enc' as the only suffix, and it doesn't
121 * really use it as a suffix; using .aes here ensures that the fileheader
122 * code can handle real suffixes, too */
124 strcpy(hdr->encrypt_suffix, ".aes");
125 if (!PREV_RT(hdr)) return 0;
129 #define PREV_RT rt_encrypt
133 rt_disk(dumpfile_t *hdr)
135 if (TAPE_HEADER(hdr)) {
136 strcpy(hdr->disk, "");
137 if (!PREV_RT(hdr)) return 0;
139 strcpy(hdr->disk, "/usr");
140 if (!PREV_RT(hdr)) return 0;
141 strcpy(hdr->disk, ""); /* should be quoted */
142 if (!PREV_RT(hdr)) return 0;
146 #define PREV_RT rt_disk
150 rt_partial(dumpfile_t *hdr)
152 if (TAPE_HEADER(hdr)) {
154 if (!PREV_RT(hdr)) return 0;
157 if (!PREV_RT(hdr)) return 0;
159 if (!PREV_RT(hdr)) return 0;
163 #define PREV_RT rt_partial
167 rt_application(dumpfile_t *hdr)
169 if (TAPE_HEADER(hdr)) {
170 strcpy(hdr->application, "");
171 if (!PREV_RT(hdr)) return 0;
173 strcpy(hdr->application, "MS-PAINT");
174 if (!PREV_RT(hdr)) return 0;
178 #define PREV_RT rt_application
182 rt_dle_str(dumpfile_t *hdr)
184 if (TAPE_HEADER(hdr)) {
185 strcpy(hdr->dle_str, "");
186 if (!PREV_RT(hdr)) return 0;
188 hdr->dle_str = g_strdup("");
189 if (!PREV_RT(hdr)) return 0;
190 hdr->dle_str = g_strdup("no-newline");
191 if (!PREV_RT(hdr)) return 0;
192 hdr->dle_str = g_strdup("ENDDLE\nmy dle\nENDDLE3");
193 if (!PREV_RT(hdr)) return 0;
197 #define PREV_RT rt_dle_str
201 rt_program(dumpfile_t *hdr)
203 if (TAPE_HEADER(hdr)) {
204 strcpy(hdr->program, "");
205 if (!PREV_RT(hdr)) return 0;
207 strcpy(hdr->program, "CHECK");
208 if (!PREV_RT(hdr)) return 0;
212 #define PREV_RT rt_program
216 rt_encrypt_prog(dumpfile_t *hdr)
218 /* only do this for F_DUMPFILE, just to spare some repetitive testing */
219 if (hdr->type == F_DUMPFILE) {
220 strcpy(hdr->srv_encrypt, "");
221 strcpy(hdr->clnt_encrypt, "");
222 strcpy(hdr->srv_decrypt_opt, "");
223 strcpy(hdr->clnt_decrypt_opt, "");
224 if (!PREV_RT(hdr)) return 0;
225 strcpy(hdr->srv_encrypt, "my-enc");
226 strcpy(hdr->clnt_encrypt, "");
227 strcpy(hdr->srv_decrypt_opt, "");
228 strcpy(hdr->clnt_decrypt_opt, "");
229 if (!PREV_RT(hdr)) return 0;
230 strcpy(hdr->srv_encrypt, "my-enc");
231 strcpy(hdr->clnt_encrypt, "");
232 strcpy(hdr->srv_decrypt_opt, "-foo");
233 strcpy(hdr->clnt_decrypt_opt, "");
234 if (!PREV_RT(hdr)) return 0;
235 strcpy(hdr->srv_encrypt, "");
236 strcpy(hdr->clnt_encrypt, "its-enc");
237 strcpy(hdr->srv_decrypt_opt, "");
238 strcpy(hdr->clnt_decrypt_opt, "");
239 if (!PREV_RT(hdr)) return 0;
240 strcpy(hdr->srv_encrypt, "");
241 strcpy(hdr->clnt_encrypt, "its-enc");
242 strcpy(hdr->srv_decrypt_opt, "");
243 strcpy(hdr->clnt_decrypt_opt, "-foo");
244 if (!PREV_RT(hdr)) return 0;
246 strcpy(hdr->srv_encrypt, "");
247 strcpy(hdr->clnt_encrypt, "");
248 strcpy(hdr->srv_decrypt_opt, "");
249 strcpy(hdr->clnt_decrypt_opt, "");
250 if (!PREV_RT(hdr)) return 0;
254 #define PREV_RT rt_encrypt_prog
258 rt_compprog(dumpfile_t *hdr)
260 /* only do this for F_DUMPFILE, just to spare some repetitive testing */
261 if (hdr->type == F_DUMPFILE) {
262 strcpy(hdr->srvcompprog, "");
263 strcpy(hdr->clntcompprog, "");
264 if (!PREV_RT(hdr)) return 0;
265 strcpy(hdr->srvcompprog, "my-comp-prog");
266 strcpy(hdr->clntcompprog, "");
267 if (!PREV_RT(hdr)) return 0;
268 strcpy(hdr->srvcompprog, "");
269 strcpy(hdr->clntcompprog, "its-comp-prog");
270 if (!PREV_RT(hdr)) return 0;
272 strcpy(hdr->srvcompprog, "");
273 strcpy(hdr->clntcompprog, "");
274 if (!PREV_RT(hdr)) return 0;
278 #define PREV_RT rt_compprog
282 rt_cmds(dumpfile_t *hdr)
284 /* only do this for F_SPLIT_DUMPFILE, just to spare some repetitive testing */
285 if (hdr->type == F_SPLIT_DUMPFILE) {
286 strcpy(hdr->recover_cmd, "");
287 strcpy(hdr->uncompress_cmd, "");
288 strcpy(hdr->decrypt_cmd, "");
289 if (!PREV_RT(hdr)) return 0;
290 strcpy(hdr->recover_cmd, "get my data back");
291 strcpy(hdr->uncompress_cmd, "");
292 strcpy(hdr->decrypt_cmd, "");
293 if (!PREV_RT(hdr)) return 0;
294 strcpy(hdr->recover_cmd, "get my data back");
295 strcpy(hdr->uncompress_cmd, "make my data bigger |");
296 strcpy(hdr->decrypt_cmd, "");
297 if (!PREV_RT(hdr)) return 0;
298 strcpy(hdr->recover_cmd, "get my data back");
299 strcpy(hdr->uncompress_cmd, "make my data bigger |");
300 strcpy(hdr->decrypt_cmd, "unscramble it too |");
301 if (!PREV_RT(hdr)) return 0;
303 strcpy(hdr->recover_cmd, "");
304 strcpy(hdr->uncompress_cmd, "");
305 strcpy(hdr->decrypt_cmd, "");
306 if (!PREV_RT(hdr)) return 0;
310 #define PREV_RT rt_cmds
314 rt_cont_filename(dumpfile_t *hdr)
316 if (hdr->type == F_DUMPFILE || hdr->type == F_CONT_DUMPFILE) {
317 strcpy(hdr->cont_filename, "/next/file");
318 if (!PREV_RT(hdr)) return 0;
320 strcpy(hdr->cont_filename, "");
321 if (!PREV_RT(hdr)) return 0;
325 #define PREV_RT rt_cont_filename
329 rt_dumplevel(dumpfile_t *hdr)
331 if (TAPE_HEADER(hdr)) {
333 if (!PREV_RT(hdr)) return 0;
336 if (!PREV_RT(hdr)) return 0;
338 if (!PREV_RT(hdr)) return 0;
342 #define PREV_RT rt_dumplevel
346 rt_name(dumpfile_t *hdr)
348 if (hdr->type == F_TAPEEND)
349 strcpy(hdr->name, "");
350 else if (TAPE_HEADER(hdr))
351 strcpy(hdr->name, "TEST-LABEL");
353 strcpy(hdr->name, "batcave-web");
354 if (!PREV_RT(hdr)) return 0;
357 #define PREV_RT rt_name
361 rt_type(dumpfile_t *hdr)
363 hdr->type = F_DUMPFILE;
364 if (!PREV_RT(hdr)) return 0;
365 hdr->type = F_CONT_DUMPFILE;
366 if (!PREV_RT(hdr)) return 0;
367 hdr->type = F_SPLIT_DUMPFILE;
368 if (!PREV_RT(hdr)) return 0;
369 hdr->type = F_TAPESTART;
370 if (!PREV_RT(hdr)) return 0;
371 hdr->type = F_TAPEEND;
372 if (!PREV_RT(hdr)) return 0;
375 #define PREV_RT rt_type
378 /* one function for each field; each fn calls the one above */
386 /* set up some basic, constant values */
387 strcpy(hdr.datestamp, "20100102030405");
388 strcpy(hdr.name, "localhost");
391 tu_dbg("%d round-trips run\n", n_round_trips);
392 return (rv) ? TRUE : FALSE;
397 encrypted + encrypt_suffix (N special)
398 compressed + comp_suffix (N special)
400 partnum/totalparts interaction
401 {srv,clnt}{compprog,_encrypt} pairs
402 uncompress/decrypt_cmd invalid without recover_cmd
403 uncompress/decrypt_cmd require trailing |
404 default to uncompress if only 2 cmds
409 main(int argc, char **argv)
411 static TestUtilsTest tests[] = {
412 TU_TEST(test_roundtrip, 90),
415 return testutils_run_tests(argc, argv, tests);