Пример #1
0
END_TEST

static void test_manifest_tell_seek(enum protocol protocol, int phase)
{
	struct slist *slist;
	struct manio *manio;
	struct sbuf *sb=NULL;
	man_off_t *offset=NULL;
	int entries=1000;
	prng_init(0);
	base64_init();
	hexmap_init();
	recursive_delete(path);

	slist=build_manifest(path, protocol, entries, phase);
	fail_unless(slist!=NULL);

	sb=slist->head;
	fail_unless((manio=do_manio_open(path, "rb", protocol, phase))!=NULL);
	read_manifest(&sb, manio, 0, entries/2, protocol, phase);
	fail_unless((offset=manio_tell(manio))!=NULL);
	fail_unless(sb!=NULL);
	fail_unless(!manio_close(&manio));

	fail_unless((manio=do_manio_open(path, "rb", protocol, phase))!=NULL);
	fail_unless(!manio_seek(manio, offset));
	read_manifest(&sb, manio, entries/2, entries, protocol, phase);
	fail_unless(sb==NULL);
	fail_unless(!manio_close(&manio));
	fail_unless(!manio);

	slist_free(&slist);
	man_off_t_free(&offset);
	tear_down();
}
Пример #2
0
static void run_test(int expected_ret,
	int manio_entries,
	int async_read_write_callback(struct async *as),
	void setup_asfds_callback(struct asfd *asfd, struct asfd *chfd,
		struct slist *slist))
{
	struct asfd *asfd;
	struct asfd *chfd;
	struct async *as;
	struct sdirs *sdirs;
	struct conf **confs;
	struct slist *slist=NULL;
	prng_init(0);
	base64_init();
	hexmap_init();
	setup(&as, &sdirs, &confs);
	asfd=asfd_mock_setup(&areads, &awrites);
	chfd=asfd_mock_setup(&creads, &cwrites);
	fail_unless((asfd->desc=strdup_w("a", __func__))!=NULL);
	fail_unless((chfd->desc=strdup_w("c", __func__))!=NULL);
	as->asfd_add(as, asfd);
	as->asfd_add(as, chfd);
	as->read_write=async_read_write_callback;

	if(manio_entries)
		slist=build_manifest(sdirs->phase1data,
			PROTO_2, manio_entries, 1 /*phase*/);
	setup_asfds_callback(asfd, chfd, slist);

	fail_unless(do_backup_phase2_server_protocol2(
		as,
		chfd,
		sdirs,
		0, // resume
		confs
	)==expected_ret);

	if(!expected_ret)
	{
		// FIX THIS: Should check for the presence and correctness of
		// changed and unchanged manios.
	}
	asfd_free(&asfd);
	asfd_free(&chfd);
	asfd_mock_teardown(&areads, &awrites);
	asfd_mock_teardown(&creads, &cwrites);
	slist_free(&slist);
	tear_down(&as, &sdirs, &confs);
}
Пример #3
0
static void run_test(
	int expected_result,
	int entries,
	void setup_datadir_tmp_callback(
		struct slist *slist, struct fdirs *fdirs, struct conf **confs))
{
	struct conf **confs;
	struct sdirs *sdirs;
	struct fdirs *fdirs;
	struct slist *slist;

	setup(&sdirs, &fdirs, &confs);

	build_storage_dirs(sdirs, sd1, ARR_LEN(sd1));
	slist=build_manifest(
		fdirs->manifest,
		PROTO_1,
		entries,
		/*phase*/ 3);

	setup_datadir_tmp_callback(slist, fdirs, confs);

clock_t start;
clock_t diff;
start = clock();
	fail_unless(backup_phase4_server_protocol1(sdirs, confs)
		==expected_result);
diff = clock() - start;
int msec = diff * 1000 / CLOCKS_PER_SEC;
printf("%d.%d\n", msec/1000, msec%1000);

	log_fzp_set(NULL, confs);

	assert_datadir(slist, fdirs);

	slist_free(&slist);
	tear_down(&sdirs, &fdirs, &confs);
}
Пример #4
0
static void run_test(int expected_ret,
	enum protocol protocol,
	int manio_entries,
	int blocks_per_file,
	void setup_asfds_callback(struct asfd *asfd, struct slist *slist))
{
        struct async *as;
        struct asfd *asfd;
        struct sdirs *sdirs;
        struct conf **confs;
        struct slist *slist=NULL;
	char *dir_for_notify=NULL;
        prng_init(0);
        base64_init();
        hexmap_init();
        setup(protocol, &as, &sdirs, &confs);
	set_string(confs[OPT_BACKUP], "1");
	set_protocol(confs, protocol);
        asfd=asfd_mock_setup(&reads, &writes);
	as->asfd_add(as, asfd);
	as->read_write=async_rw_simple;
	as->read_quick=async_rw_simple;
	asfd->as=as;

	build_storage_dirs(sdirs, sd1, ARR_LEN(sd1));
	if(manio_entries)
	{
		struct sbuf *s;
		if(protocol==PROTO_2)
			slist=build_manifest_with_data_files(sdirs->cmanifest,
				sdirs->data, manio_entries, blocks_per_file);
		else
		{
			slist=build_manifest(sdirs->cmanifest,
				protocol, manio_entries, 0 /*phase*/);
			for(s=slist->head; s; s=s->next)
			{
				char path[256];
				if(!sbuf_is_filedata(s))
					continue;
				snprintf(path, sizeof(path), "%s/%s%s",
					sdirs->currentdata,
					TREE_DIR, s->path.buf);
				build_file(path, "data");
			}
		}
	}
	setup_asfds_callback(asfd, slist);

	fail_unless(do_restore_server(
		asfd,
		sdirs,
		ACTION_RESTORE,
		0, // srestore
		&dir_for_notify,
		confs
	)==expected_ret);

	if(!expected_ret)
	{
		// FIX THIS: Should check for the presence and correctness of
		// changed and unchanged manios.
	}
	slist_free(&slist);
	free_w(&dir_for_notify);
	tear_down(&as, &asfd, &sdirs, &confs);
}