Exemplo n.º 1
0
static void run_test(int expected_ret,
	void setup_asfds_callback(struct asfd *sfd,
		struct asfd *in, struct asfd *out))
{
	struct async *as;
	struct asfd *sfd;
	struct asfd *in;
	struct asfd *out;

	as=setup();

	sfd=asfd_mock_setup(&areads, &awrites);
	in=asfd_mock_setup(&ireads, &iwrites);
	out=asfd_mock_setup(&oreads, &owrites);

	fail_unless((sfd->desc=strdup_w("main_socket", __func__))!=NULL);
	fail_unless((in->desc=strdup_w("stdin", __func__))!=NULL);
	fail_unless((out->desc=strdup_w("stdout", __func__))!=NULL);
	as->asfd_add(as, sfd);
	as->asfd_add(as, in);
	as->asfd_add(as, out);
	as->read_write=async_rw_both;

	setup_asfds_callback(sfd, in, out);

	fail_unless(monitor_client_main_loop(as)==expected_ret);

	asfd_free(&in);
	asfd_free(&out);
	asfd_free(&sfd);
	asfd_mock_teardown(&areads, &awrites);
	asfd_mock_teardown(&ireads, &iwrites);
	asfd_mock_teardown(&oreads, &owrites);
	tear_down(&as);
}
Exemplo n.º 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);
}
Exemplo n.º 3
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);
}