Exemple #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);
}
static void do_snapshot_test(
	const char *orig_client,
	int expected_ret,
	void setup_callback(
		struct asfd *csin,
		struct asfd *csout,
		struct asfd *so_asfd
	)
)
{
	struct asfd *csin;
	struct asfd *csout;
	struct asfd *so_asfd;
	struct async *as;
	struct sel *sel;

	as=setup_async();
	csin=asfd_mock_setup(&reads_csin, &writes_csin);
	csout=asfd_mock_setup(&reads_csout, &writes_csout);
	so_asfd=asfd_mock_setup(&reads_so, &writes_so);
        fail_unless((csin->desc=strdup_w("csin", __func__))!=NULL);
        fail_unless((csout->desc=strdup_w("csout", __func__))!=NULL);
        fail_unless((so_asfd->desc=strdup_w("so_asfd", __func__))!=NULL);
	as->asfd_add(as, csin);
	as->asfd_add(as, csout);
	as->asfd_add(as, so_asfd);
	as->read_write=async_rw_simple;
	as->write=async_write_simple;
	setup_callback(csin, csout, so_asfd);

	fail_unless((sel=sel_alloc())!=NULL);

	fail_unless(!status_client_ncurses_init(ACTION_STATUS_SNAPSHOT));
	fail_unless(status_client_ncurses_main_loop(
		as,
		so_asfd,
		sel,
		orig_client
	)==expected_ret);

	sel_free(&sel);
	asfd_free(&csin);
	asfd_free(&csout);
	asfd_free(&so_asfd);
	asfd_mock_teardown(&reads_csin, &writes_csin);
	asfd_mock_teardown(&reads_csout, &writes_csout);
	asfd_mock_teardown(&reads_so, &writes_so);
	async_free(&as);

	alloc_check();
}
Exemple #3
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);
}
Exemple #4
0
static void tear_down(struct asfd **asfd, struct sdirs **sdirs)
{
	asfd_free(asfd);
	asfd_mock_teardown(&reads, &writes);
	sdirs_free(sdirs);
	fail_unless(recursive_delete(BASE)==0);
	alloc_check();
}
Exemple #5
0
static void tear_down(struct asfd **asfd, struct conf ***confs)
{
	asfd_free(asfd);
	confs_free(confs);
	asfd_mock_teardown(&reads, &writes);
//printf("%d %d\n", alloc_count, free_count);
	alloc_check();
	fail_unless(recursive_delete(BASE)==0);
}
Exemple #6
0
static void tear_down(struct sbuf **sb, struct cntr **cntr,
	struct conf ***confs, struct asfd **asfd)
{
	clean();
	sbuf_free(sb);
	cntr_free(cntr);
	confs_free(confs);
	asfd_free(asfd);
	asfd_mock_teardown(&areads, &awrites);
	alloc_check();
}
Exemple #7
0
static void tear_down(struct async **as, struct asfd **asfd,
	struct sdirs **sdirs, struct conf ***confs)
{
	async_free(as);
	asfd_free(asfd);
	sdirs_free(sdirs);
	asfd_mock_teardown(&reads, &writes);
	confs_free(confs);
//printf("%d %d\n", alloc_count, free_count);
	alloc_check();
}
static void do_simple_test(
	const char *orig_client,
	int expected_ret,
	void setup_callback(struct asfd *asfd),
	void setup_stdout_callback(struct asfd *asfd)
)
{
	struct asfd *asfd;
	struct asfd *so_asfd;
	struct async *as;

	as=setup_async();
	asfd=asfd_mock_setup(&reads, &writes);
	so_asfd=asfd_mock_setup(&reads_so, &writes_so);
	as->asfd_add(as, asfd);
	as->asfd_add(as, so_asfd);
	asfd->as=as;
	as->read_write=async_rw_simple;
	as->write=async_write_simple;
	setup_callback(asfd);
	if(setup_stdout_callback)
		setup_stdout_callback(so_asfd);

	fail_unless(!status_client_ncurses_init(ACTION_STATUS_SNAPSHOT));
	fail_unless(status_client_ncurses_main_loop(
		as,
		so_asfd,
		orig_client
	)==expected_ret);
	asfd_free(&asfd);
	asfd_free(&so_asfd);
	asfd_mock_teardown(&reads, &writes);
	asfd_mock_teardown(&reads_so, &writes_so);
	async_free(&as);

	alloc_check();
}
Exemple #9
0
END_TEST

START_TEST(test_phase2_unset_chfd)
{
	struct asfd *asfd;
	struct async *as;
	struct sdirs *sdirs;
	struct conf **confs;
	setup(&as, &sdirs, &confs);
	asfd=asfd_mock_setup(&areads, &awrites);
	as->asfd_add(as, asfd);

	fail_unless(do_backup_phase2_server_protocol2(
		as,
		NULL, // chfd
		sdirs,
		0, // resume
		confs
	)==-1);
	asfd_free(&asfd);
	asfd_mock_teardown(&areads, &awrites);
	tear_down(&as, &sdirs, &confs);
}
END_TEST

static void do_status_test(
	const char *orig_client,
	int expected_ret,
	void setup_callback(
		struct asfd *csin,
		struct asfd *csout,
		struct asfd *nin,
		struct asfd *so_asfd
	),
	void check_sel_callback(
		struct sel *sel
	)
)
{
	struct asfd *csin;
	struct asfd *csout;
	struct asfd *nin;
	struct asfd *so_asfd;
	struct async *as;
	struct sel *sel;

	as=setup_async();
	csin=asfd_mock_setup(&reads_csin, &writes_csin);
	csout=asfd_mock_setup(&reads_csout, &writes_csout);
	nin=asfd_mock_setup(&reads_nin, &writes_nin);
	so_asfd=asfd_mock_setup(&reads_so, &writes_so);

        fail_unless((csin->desc=strdup_w("csin", __func__))!=NULL);
        fail_unless((csout->desc=strdup_w("csout", __func__))!=NULL);
        fail_unless((nin->desc=strdup_w("nin", __func__))!=NULL);
        fail_unless((so_asfd->desc=strdup_w("so_asfd", __func__))!=NULL);
	nin->streamtype=ASFD_STREAM_NCURSES_STDIN;

	as->asfd_add(as, csin);
	as->asfd_add(as, csout);
	as->asfd_add(as, nin);
	as->asfd_add(as, so_asfd);
	as->read_write=async_rw_both;
	as->write=async_write_simple;
	setup_callback(csin, csout, nin, so_asfd);

	fail_unless((sel=sel_alloc())!=NULL);

	fail_unless(!status_client_ncurses_init(ACTION_STATUS));
	fail_unless(status_client_ncurses_main_loop(
		as,
		so_asfd,
		sel,
		orig_client
	)==expected_ret);

	if(check_sel_callback)
		check_sel_callback(sel);
	sel_free(&sel);

	asfd_free(&csin);
	asfd_free(&csout);
	asfd_free(&nin);
	asfd_free(&so_asfd);
	asfd_mock_teardown(&reads_csin, &writes_csin);
	asfd_mock_teardown(&reads_csout, &writes_csout);
	asfd_mock_teardown(&reads_nin, &writes_nin);
	asfd_mock_teardown(&reads_so, &writes_so);
	async_free(&as);

	alloc_check();
}
Exemple #11
0
static void tear_down(struct asfd **asfd)
{
	asfd_free(asfd);
	asfd_mock_teardown(&reads, &writes);
	alloc_check();
}