Exemplo n.º 1
0
/*
  called when a loadfile completes
 */
static void loadfile_callback(struct composite_context *ctx) 
{
	struct offline_state *state = ctx->async.private_data;
	NTSTATUS status;
	int i;

	status = smb_composite_loadfile_recv(ctx, state->mem_ctx);
	if (!NT_STATUS_IS_OK(status)) {
		printf("Failed to read file '%s' - %s\n", 
		       state->loadfile->in.fname, nt_errstr(status));
		test_failed++;
	}

	/* check the data is correct */
	if (state->loadfile->out.size != FILE_SIZE) {
		printf("Wrong file size %u - expected %u\n", 
		       state->loadfile->out.size, FILE_SIZE);
		test_failed++;
		return;
	}

	for (i=0;i<FILE_SIZE;i++) {
		if (state->loadfile->out.data[i] != 1+(state->fnumber % 255)) {
			printf("Bad data in file %u (got %u expected %u)\n", 
			       state->fnumber, 
			       state->loadfile->out.data[i],
			       1+(state->fnumber % 255));
			test_failed++;
			return;
		}
	}
	
	talloc_steal(state->loadfile, state->loadfile->out.data);

	state->count++;
	talloc_free(state->loadfile);
	state->loadfile = NULL;

	if (!test_finished) {
		test_offline(state);
	}
}
Exemplo n.º 2
0
/*
  test a simple savefile/loadfile combination
*/
static bool test_loadfile(struct smbcli_state *cli, struct torture_context *tctx)
{
	const char *fname = BASEDIR "\\test.txt";
	NTSTATUS status;
	struct smb_composite_savefile io1;
	struct smb_composite_loadfile io2;
	struct composite_context **c;
	uint8_t *data;
	size_t len = random() % 100000;
	const int num_ops = 50;
	int i;
	int *count = talloc_zero(tctx, int);

	data = talloc_array(tctx, uint8_t, len);

	generate_random_buffer(data, len);

	io1.in.fname = fname;
	io1.in.data  = data;
	io1.in.size  = len;

	printf("testing savefile\n");

	status = smb_composite_savefile(cli->tree, &io1);
	if (!NT_STATUS_IS_OK(status)) {
		printf("(%s) savefile failed: %s\n", __location__,nt_errstr(status));
		return false;
	}

	io2.in.fname = fname;

	printf("testing parallel loadfile with %d ops\n", num_ops);

	c = talloc_array(tctx, struct composite_context *, num_ops);

	for (i=0;i<num_ops;i++) {
		c[i] = smb_composite_loadfile_send(cli->tree, &io2);
		c[i]->async.fn = loadfile_complete;
		c[i]->async.private_data = count;
	}

	printf("waiting for completion\n");
	while (*count != num_ops) {
		event_loop_once(cli->transport->socket->event.ctx);
		if (torture_setting_bool(tctx, "progress", true)) {
			printf("(%s) count=%d\r", __location__, *count);
			fflush(stdout);
		}
	}
	printf("count=%d\n", *count);
	
	for (i=0;i<num_ops;i++) {
		status = smb_composite_loadfile_recv(c[i], tctx);
		if (!NT_STATUS_IS_OK(status)) {
			printf("(%s) loadfile[%d] failed - %s\n", __location__, i, nt_errstr(status));
			return false;
		}

		if (io2.out.size != len) {
			printf("(%s) wrong length in returned data - %d should be %d\n",__location__,
			       io2.out.size, (int)len);
			return false;
		}
		
		if (memcmp(io2.out.data, data, len) != 0) {
			printf("(%s) wrong data in loadfile!\n",__location__);
			return false;
		}
	}

	talloc_free(data);

	return true;
}