2 * Copyright (c) 2010 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;
76 if (!PREV_RT(hdr)) return 0;
80 #define PREV_RT rt_partnum
84 rt_compress(dumpfile_t *hdr)
86 if (TAPE_HEADER(hdr)) {
88 strcpy(hdr->comp_suffix, "");
89 if (!PREV_RT(hdr)) return 0;
92 strcpy(hdr->comp_suffix, "");
93 if (!PREV_RT(hdr)) return 0;
95 strcpy(hdr->comp_suffix, ".gz");
96 if (!PREV_RT(hdr)) return 0;
100 #define PREV_RT rt_compress
104 rt_encrypt(dumpfile_t *hdr)
106 if (TAPE_HEADER(hdr)) {
108 strcpy(hdr->encrypt_suffix, "");
109 if (!PREV_RT(hdr)) return 0;
112 strcpy(hdr->encrypt_suffix, "");
113 if (!PREV_RT(hdr)) return 0;
115 /* (note: Amanda seems to use 'enc' as the only suffix, and it doesn't
116 * really use it as a suffix; using .aes here ensures that the fileheader
117 * code can handle real suffixes, too */
119 strcpy(hdr->encrypt_suffix, ".aes");
120 if (!PREV_RT(hdr)) return 0;
124 #define PREV_RT rt_encrypt
128 rt_disk(dumpfile_t *hdr)
130 if (TAPE_HEADER(hdr)) {
131 strcpy(hdr->disk, "");
132 if (!PREV_RT(hdr)) return 0;
134 strcpy(hdr->disk, "/usr");
135 if (!PREV_RT(hdr)) return 0;
136 strcpy(hdr->disk, ""); /* should be quoted */
137 if (!PREV_RT(hdr)) return 0;
141 #define PREV_RT rt_disk
145 rt_partial(dumpfile_t *hdr)
147 if (TAPE_HEADER(hdr)) {
149 if (!PREV_RT(hdr)) return 0;
152 if (!PREV_RT(hdr)) return 0;
154 if (!PREV_RT(hdr)) return 0;
158 #define PREV_RT rt_partial
162 rt_application(dumpfile_t *hdr)
164 if (TAPE_HEADER(hdr)) {
165 strcpy(hdr->application, "");
166 if (!PREV_RT(hdr)) return 0;
168 strcpy(hdr->application, "MS-PAINT");
169 if (!PREV_RT(hdr)) return 0;
173 #define PREV_RT rt_application
177 rt_dle_str(dumpfile_t *hdr)
179 if (TAPE_HEADER(hdr)) {
180 strcpy(hdr->dle_str, "");
181 if (!PREV_RT(hdr)) return 0;
183 hdr->dle_str = g_strdup("");
184 if (!PREV_RT(hdr)) return 0;
185 hdr->dle_str = g_strdup("no-newline");
186 if (!PREV_RT(hdr)) return 0;
187 hdr->dle_str = g_strdup("ENDDLE\nmy dle\nENDDLE3");
188 if (!PREV_RT(hdr)) return 0;
192 #define PREV_RT rt_dle_str
196 rt_program(dumpfile_t *hdr)
198 if (TAPE_HEADER(hdr)) {
199 strcpy(hdr->program, "");
200 if (!PREV_RT(hdr)) return 0;
202 strcpy(hdr->program, "CHECK");
203 if (!PREV_RT(hdr)) return 0;
207 #define PREV_RT rt_program
211 rt_encrypt_prog(dumpfile_t *hdr)
213 /* only do this for F_DUMPFILE, just to spare some repetitive testing */
214 if (hdr->type == F_DUMPFILE) {
215 strcpy(hdr->srv_encrypt, "");
216 strcpy(hdr->clnt_encrypt, "");
217 strcpy(hdr->srv_decrypt_opt, "");
218 strcpy(hdr->clnt_decrypt_opt, "");
219 if (!PREV_RT(hdr)) return 0;
220 strcpy(hdr->srv_encrypt, "my-enc");
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, "-foo");
228 strcpy(hdr->clnt_decrypt_opt, "");
229 if (!PREV_RT(hdr)) return 0;
230 strcpy(hdr->srv_encrypt, "");
231 strcpy(hdr->clnt_encrypt, "its-enc");
232 strcpy(hdr->srv_decrypt_opt, "");
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, "-foo");
239 if (!PREV_RT(hdr)) return 0;
241 strcpy(hdr->srv_encrypt, "");
242 strcpy(hdr->clnt_encrypt, "");
243 strcpy(hdr->srv_decrypt_opt, "");
244 strcpy(hdr->clnt_decrypt_opt, "");
245 if (!PREV_RT(hdr)) return 0;
249 #define PREV_RT rt_encrypt_prog
253 rt_compprog(dumpfile_t *hdr)
255 /* only do this for F_DUMPFILE, just to spare some repetitive testing */
256 if (hdr->type == F_DUMPFILE) {
257 strcpy(hdr->srvcompprog, "");
258 strcpy(hdr->clntcompprog, "");
259 if (!PREV_RT(hdr)) return 0;
260 strcpy(hdr->srvcompprog, "my-comp-prog");
261 strcpy(hdr->clntcompprog, "");
262 if (!PREV_RT(hdr)) return 0;
263 strcpy(hdr->srvcompprog, "");
264 strcpy(hdr->clntcompprog, "its-comp-prog");
265 if (!PREV_RT(hdr)) return 0;
267 strcpy(hdr->srvcompprog, "");
268 strcpy(hdr->clntcompprog, "");
269 if (!PREV_RT(hdr)) return 0;
273 #define PREV_RT rt_compprog
277 rt_cmds(dumpfile_t *hdr)
279 /* only do this for F_SPLIT_DUMPFILE, just to spare some repetitive testing */
280 if (hdr->type == F_SPLIT_DUMPFILE) {
281 strcpy(hdr->recover_cmd, "");
282 strcpy(hdr->uncompress_cmd, "");
283 strcpy(hdr->decrypt_cmd, "");
284 if (!PREV_RT(hdr)) return 0;
285 strcpy(hdr->recover_cmd, "get my data back");
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, "make my data bigger |");
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, "unscramble it too |");
296 if (!PREV_RT(hdr)) return 0;
298 strcpy(hdr->recover_cmd, "");
299 strcpy(hdr->uncompress_cmd, "");
300 strcpy(hdr->decrypt_cmd, "");
301 if (!PREV_RT(hdr)) return 0;
305 #define PREV_RT rt_cmds
309 rt_cont_filename(dumpfile_t *hdr)
311 if (hdr->type == F_DUMPFILE || hdr->type == F_CONT_DUMPFILE) {
312 strcpy(hdr->cont_filename, "/next/file");
313 if (!PREV_RT(hdr)) return 0;
315 strcpy(hdr->cont_filename, "");
316 if (!PREV_RT(hdr)) return 0;
320 #define PREV_RT rt_cont_filename
324 rt_dumplevel(dumpfile_t *hdr)
326 if (TAPE_HEADER(hdr)) {
328 if (!PREV_RT(hdr)) return 0;
331 if (!PREV_RT(hdr)) return 0;
333 if (!PREV_RT(hdr)) return 0;
337 #define PREV_RT rt_dumplevel
341 rt_name(dumpfile_t *hdr)
343 if (hdr->type == F_TAPEEND)
344 strcpy(hdr->name, "");
345 else if (TAPE_HEADER(hdr))
346 strcpy(hdr->name, "TEST-LABEL");
348 strcpy(hdr->name, "batcave-web");
349 if (!PREV_RT(hdr)) return 0;
352 #define PREV_RT rt_name
356 rt_type(dumpfile_t *hdr)
358 hdr->type = F_DUMPFILE;
359 if (!PREV_RT(hdr)) return 0;
360 hdr->type = F_CONT_DUMPFILE;
361 if (!PREV_RT(hdr)) return 0;
362 hdr->type = F_SPLIT_DUMPFILE;
363 if (!PREV_RT(hdr)) return 0;
364 hdr->type = F_TAPESTART;
365 if (!PREV_RT(hdr)) return 0;
366 hdr->type = F_TAPEEND;
367 if (!PREV_RT(hdr)) return 0;
370 #define PREV_RT rt_type
373 /* one function for each field; each fn calls the one above */
381 /* set up some basic, constant values */
382 strcpy(hdr.datestamp, "20100102030405");
383 strcpy(hdr.name, "localhost");
386 tu_dbg("%d round-trips run\n", n_round_trips);
392 encrypted + encrypt_suffix (N special)
393 compressed + comp_suffix (N special)
395 partnum/totalparts interaction
396 {srv,clnt}{compprog,_encrypt} pairs
397 uncompress/decrypt_cmd invalid without recover_cmd
398 uncompress/decrypt_cmd require trailing |
399 default to uncompress if only 2 cmds
404 main(int argc, char **argv)
406 static TestUtilsTest tests[] = {
407 TU_TEST(test_roundtrip, 90),
410 return testutils_run_tests(argc, argv, tests);