1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
|
/*
* Copyright (c) 2010-2012 Zmanda Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*
* Contact information: Carbonite Inc., 756 N Pastoria Ave
* Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
*/
#include "amanda.h"
#include "testutils.h"
#include "fileheader.h"
#define TAPE_HEADER(hdr) ((hdr)->type == F_TAPESTART || (hdr)->type == F_TAPEEND)
static int n_round_trips = 0;
/* actually test the round trip */
static int
try_rt(dumpfile_t *hdr)
{
char *strval;
size_t size;
dumpfile_t hdr2;
size = 0;
strval = build_header(hdr, &size, 32768);
g_assert(strval != NULL);
fh_init(&hdr2);
parse_file_header(strval, &hdr2, size);
if (!headers_are_equal(hdr, &hdr2)) {
tu_dbg("*** build_header of:\n");
dump_dumpfile_t(hdr);
tu_dbg("*** gives:\n");
tu_dbg("%s", strval);
tu_dbg("*** which becomes:\n");
dump_dumpfile_t(&hdr2);
return 0;
}
n_round_trips++;
dumpfile_free_data(&hdr2);
g_free(strval);
return 1;
#define PREV_RT try_rt
}
static int
rt_partnum(dumpfile_t *hdr)
{
if (hdr->type == F_SPLIT_DUMPFILE) {
hdr->partnum = 1;
hdr->totalparts = 2;
if (!PREV_RT(hdr)) return 0;
hdr->partnum = 2;
hdr->totalparts = 2;
if (!PREV_RT(hdr)) return 0;
hdr->partnum = 2;
hdr->totalparts = -1;
if (!PREV_RT(hdr)) return 0;
} else if (hdr->type == F_DUMPFILE) {
hdr->partnum = 1;
hdr->totalparts = 1;
if (!PREV_RT(hdr)) return 0;
} else {
hdr->partnum = 0;
hdr->totalparts = 0;
if (!PREV_RT(hdr)) return 0;
}
return 1;
#undef PREV_RT
#define PREV_RT rt_partnum
}
static int
rt_compress(dumpfile_t *hdr)
{
if (TAPE_HEADER(hdr)) {
hdr->compressed = 0;
strcpy(hdr->comp_suffix, "");
if (!PREV_RT(hdr)) return 0;
} else {
hdr->compressed = 0;
strcpy(hdr->comp_suffix, "");
if (!PREV_RT(hdr)) return 0;
hdr->compressed = 1;
strcpy(hdr->comp_suffix, ".gz");
if (!PREV_RT(hdr)) return 0;
}
return 1;
#undef PREV_RT
#define PREV_RT rt_compress
}
static int
rt_encrypt(dumpfile_t *hdr)
{
if (TAPE_HEADER(hdr)) {
hdr->encrypted = 0;
strcpy(hdr->encrypt_suffix, "");
if (!PREV_RT(hdr)) return 0;
} else {
hdr->encrypted = 0;
strcpy(hdr->encrypt_suffix, "");
if (!PREV_RT(hdr)) return 0;
/* (note: Amanda seems to use 'enc' as the only suffix, and it doesn't
* really use it as a suffix; using .aes here ensures that the fileheader
* code can handle real suffixes, too */
hdr->encrypted = 1;
strcpy(hdr->encrypt_suffix, ".aes");
if (!PREV_RT(hdr)) return 0;
}
return 1;
#undef PREV_RT
#define PREV_RT rt_encrypt
}
static int
rt_disk(dumpfile_t *hdr)
{
if (TAPE_HEADER(hdr)) {
strcpy(hdr->disk, "");
if (!PREV_RT(hdr)) return 0;
} else {
strcpy(hdr->disk, "/usr");
if (!PREV_RT(hdr)) return 0;
strcpy(hdr->disk, ""); /* should be quoted */
if (!PREV_RT(hdr)) return 0;
}
return 1;
#undef PREV_RT
#define PREV_RT rt_disk
}
static int
rt_partial(dumpfile_t *hdr)
{
if (TAPE_HEADER(hdr)) {
hdr->is_partial = 0;
if (!PREV_RT(hdr)) return 0;
} else {
hdr->is_partial = 1;
if (!PREV_RT(hdr)) return 0;
hdr->is_partial = 0;
if (!PREV_RT(hdr)) return 0;
}
return 1;
#undef PREV_RT
#define PREV_RT rt_partial
}
static int
rt_application(dumpfile_t *hdr)
{
if (TAPE_HEADER(hdr)) {
strcpy(hdr->application, "");
if (!PREV_RT(hdr)) return 0;
} else {
strcpy(hdr->application, "MS-PAINT");
if (!PREV_RT(hdr)) return 0;
}
return 1;
#undef PREV_RT
#define PREV_RT rt_application
}
static int
rt_dle_str(dumpfile_t *hdr)
{
if (TAPE_HEADER(hdr)) {
strcpy(hdr->dle_str, "");
if (!PREV_RT(hdr)) return 0;
} else {
hdr->dle_str = g_strdup("");
if (!PREV_RT(hdr)) return 0;
hdr->dle_str = g_strdup("no-newline");
if (!PREV_RT(hdr)) return 0;
hdr->dle_str = g_strdup("ENDDLE\nmy dle\nENDDLE3");
if (!PREV_RT(hdr)) return 0;
}
return 1;
#undef PREV_RT
#define PREV_RT rt_dle_str
}
static int
rt_program(dumpfile_t *hdr)
{
if (TAPE_HEADER(hdr)) {
strcpy(hdr->program, "");
if (!PREV_RT(hdr)) return 0;
} else {
strcpy(hdr->program, "CHECK");
if (!PREV_RT(hdr)) return 0;
}
return 1;
#undef PREV_RT
#define PREV_RT rt_program
}
static int
rt_encrypt_prog(dumpfile_t *hdr)
{
/* only do this for F_DUMPFILE, just to spare some repetitive testing */
if (hdr->type == F_DUMPFILE) {
strcpy(hdr->srv_encrypt, "");
strcpy(hdr->clnt_encrypt, "");
strcpy(hdr->srv_decrypt_opt, "");
strcpy(hdr->clnt_decrypt_opt, "");
if (!PREV_RT(hdr)) return 0;
strcpy(hdr->srv_encrypt, "my-enc");
strcpy(hdr->clnt_encrypt, "");
strcpy(hdr->srv_decrypt_opt, "");
strcpy(hdr->clnt_decrypt_opt, "");
if (!PREV_RT(hdr)) return 0;
strcpy(hdr->srv_encrypt, "my-enc");
strcpy(hdr->clnt_encrypt, "");
strcpy(hdr->srv_decrypt_opt, "-foo");
strcpy(hdr->clnt_decrypt_opt, "");
if (!PREV_RT(hdr)) return 0;
strcpy(hdr->srv_encrypt, "");
strcpy(hdr->clnt_encrypt, "its-enc");
strcpy(hdr->srv_decrypt_opt, "");
strcpy(hdr->clnt_decrypt_opt, "");
if (!PREV_RT(hdr)) return 0;
strcpy(hdr->srv_encrypt, "");
strcpy(hdr->clnt_encrypt, "its-enc");
strcpy(hdr->srv_decrypt_opt, "");
strcpy(hdr->clnt_decrypt_opt, "-foo");
if (!PREV_RT(hdr)) return 0;
} else {
strcpy(hdr->srv_encrypt, "");
strcpy(hdr->clnt_encrypt, "");
strcpy(hdr->srv_decrypt_opt, "");
strcpy(hdr->clnt_decrypt_opt, "");
if (!PREV_RT(hdr)) return 0;
}
return 1;
#undef PREV_RT
#define PREV_RT rt_encrypt_prog
}
static int
rt_compprog(dumpfile_t *hdr)
{
/* only do this for F_DUMPFILE, just to spare some repetitive testing */
if (hdr->type == F_DUMPFILE) {
strcpy(hdr->srvcompprog, "");
strcpy(hdr->clntcompprog, "");
if (!PREV_RT(hdr)) return 0;
strcpy(hdr->srvcompprog, "my-comp-prog");
strcpy(hdr->clntcompprog, "");
if (!PREV_RT(hdr)) return 0;
strcpy(hdr->srvcompprog, "");
strcpy(hdr->clntcompprog, "its-comp-prog");
if (!PREV_RT(hdr)) return 0;
} else {
strcpy(hdr->srvcompprog, "");
strcpy(hdr->clntcompprog, "");
if (!PREV_RT(hdr)) return 0;
}
return 1;
#undef PREV_RT
#define PREV_RT rt_compprog
}
static int
rt_cmds(dumpfile_t *hdr)
{
/* only do this for F_SPLIT_DUMPFILE, just to spare some repetitive testing */
if (hdr->type == F_SPLIT_DUMPFILE) {
strcpy(hdr->recover_cmd, "");
strcpy(hdr->uncompress_cmd, "");
strcpy(hdr->decrypt_cmd, "");
if (!PREV_RT(hdr)) return 0;
strcpy(hdr->recover_cmd, "get my data back");
strcpy(hdr->uncompress_cmd, "");
strcpy(hdr->decrypt_cmd, "");
if (!PREV_RT(hdr)) return 0;
strcpy(hdr->recover_cmd, "get my data back");
strcpy(hdr->uncompress_cmd, "make my data bigger |");
strcpy(hdr->decrypt_cmd, "");
if (!PREV_RT(hdr)) return 0;
strcpy(hdr->recover_cmd, "get my data back");
strcpy(hdr->uncompress_cmd, "make my data bigger |");
strcpy(hdr->decrypt_cmd, "unscramble it too |");
if (!PREV_RT(hdr)) return 0;
} else {
strcpy(hdr->recover_cmd, "");
strcpy(hdr->uncompress_cmd, "");
strcpy(hdr->decrypt_cmd, "");
if (!PREV_RT(hdr)) return 0;
}
return 1;
#undef PREV_RT
#define PREV_RT rt_cmds
}
static int
rt_cont_filename(dumpfile_t *hdr)
{
if (hdr->type == F_DUMPFILE || hdr->type == F_CONT_DUMPFILE) {
strcpy(hdr->cont_filename, "/next/file");
if (!PREV_RT(hdr)) return 0;
} else {
strcpy(hdr->cont_filename, "");
if (!PREV_RT(hdr)) return 0;
}
return 1;
#undef PREV_RT
#define PREV_RT rt_cont_filename
}
static int
rt_dumplevel(dumpfile_t *hdr)
{
if (TAPE_HEADER(hdr)) {
hdr->dumplevel = 0;
if (!PREV_RT(hdr)) return 0;
} else {
hdr->dumplevel = 0;
if (!PREV_RT(hdr)) return 0;
hdr->dumplevel = 1;
if (!PREV_RT(hdr)) return 0;
}
return 1;
#undef PREV_RT
#define PREV_RT rt_dumplevel
}
static int
rt_name(dumpfile_t *hdr)
{
if (hdr->type == F_TAPEEND)
strcpy(hdr->name, "");
else if (TAPE_HEADER(hdr))
strcpy(hdr->name, "TEST-LABEL");
else
strcpy(hdr->name, "batcave-web");
if (!PREV_RT(hdr)) return 0;
return 1;
#undef PREV_RT
#define PREV_RT rt_name
}
static int
rt_type(dumpfile_t *hdr)
{
hdr->type = F_DUMPFILE;
if (!PREV_RT(hdr)) return 0;
hdr->type = F_CONT_DUMPFILE;
if (!PREV_RT(hdr)) return 0;
hdr->type = F_SPLIT_DUMPFILE;
if (!PREV_RT(hdr)) return 0;
hdr->type = F_TAPESTART;
if (!PREV_RT(hdr)) return 0;
hdr->type = F_TAPEEND;
if (!PREV_RT(hdr)) return 0;
return 1;
#undef PREV_RT
#define PREV_RT rt_type
}
/* one function for each field; each fn calls the one above */
static gboolean
test_roundtrip(void)
{
int rv;
dumpfile_t hdr;
fh_init(&hdr);
/* set up some basic, constant values */
strcpy(hdr.datestamp, "20100102030405");
strcpy(hdr.name, "localhost");
rv = PREV_RT(&hdr);
tu_dbg("%d round-trips run\n", n_round_trips);
dumpfile_free_data(&hdr);
return (rv) ? TRUE : FALSE;
}
/* doc
encrypted + encrypt_suffix (N special)
compressed + comp_suffix (N special)
blocksize not parsed
partnum/totalparts interaction
{srv,clnt}{compprog,_encrypt} pairs
uncompress/decrypt_cmd invalid without recover_cmd
uncompress/decrypt_cmd require trailing |
default to uncompress if only 2 cmds
*/
int
main(int argc, char **argv)
{
static TestUtilsTest tests[] = {
TU_TEST(test_roundtrip, 90),
TU_END()
};
glib_init();
return testutils_run_tests(argc, argv, tests);
}
|