示例#1
0
TYPED_TEST_P(TcTest, TestHardLinks)
{
	EXPECT_TRUE(tc_rm_recursive("HardLinks"));
	tc_ensure_dir("HardLinks", 0755, NULL);
	const int NFILES = 8;
	std::vector<const char *> files(NFILES);
	std::vector<const char *> links(NFILES);
	std::vector<tc_iovec> olddata(NFILES);
	std::vector<tc_iovec> newdata(NFILES);
	for (int i = 0; i < NFILES; ++i) {
		files[i] = new_auto_path("HardLinks/file-%d", i);
		links[i] = new_auto_path("HardLinks/link-%d", i);
		olddata[i].file = tc_file_from_path(files[i]);
		newdata[i].file = tc_file_from_path(links[i]);
		olddata[i].offset = newdata[i].offset = 0;
		olddata[i].length = newdata[i].length = 4096;
		olddata[i].data = (char *)malloc(4096);
		newdata[i].data = (char *)malloc(4096);
	}

	tc_touchv(files.data(), files.size(), false);
	EXPECT_OK(tc_readv(olddata.data(), olddata.size(), false));

	EXPECT_OK(tc_hardlinkv(files.data(), links.data(), files.size(), false));
	EXPECT_OK(tc_unlinkv(files.data(), files.size()));

	EXPECT_OK(tc_readv(newdata.data(), newdata.size(), false));
	EXPECT_TRUE(compare_content(olddata.data(), newdata.data(), olddata.size()));

	for (int i = 0; i < NFILES; ++i) {
		free((char *)olddata[i].data);
		free((char *)newdata[i].data);
	}
}
示例#2
0
/**
 * TC-Read and Write test using
 * File Descriptor
 */
TYPED_TEST_P(TcTest, TestFileDesc)
{
	const int N = 4;
	const char *PATHS[] = { "TcTest-TestFileDesc1.txt",
				"TcTest-TestFileDesc2.txt",
				"TcTest-TestFileDesc3.txt",
				"TcTest-TestFileDesc4.txt" };
	char data[] = "abcd123";
	tc_res res;
	int i = 0;
	tc_file *files;

	Removev(PATHS, 4);

	files = tc_openv_simple(PATHS, N, O_RDWR | O_CREAT, 0);
	EXPECT_NOTNULL(files);

	struct tc_iovec *writev = NULL;
	writev = build_iovec(files, N, 0);
	EXPECT_FALSE(writev == NULL);

	EXPECT_OK(tc_writev(writev, N, false));

	struct tc_iovec *readv = NULL;
	readv = build_iovec(files, N, 0);
	EXPECT_FALSE(readv == NULL);

	EXPECT_OK(tc_readv(readv, N, false));

	EXPECT_TRUE(compare_content(writev, readv, N));

	tc_closev(files, N);
	free_iovec(writev, N);
	free_iovec(readv, N);
}
示例#3
0
/**
 * TC-Read and Write test using
 * File path
 */
TYPED_TEST_P(TcTest, WritevCanCreateFiles)
{
	const char *PATHS[] = { "WritevCanCreateFiles1.txt",
				"WritevCanCreateFiles2.txt",
				"WritevCanCreateFiles3.txt",
				"WritevCanCreateFiles4.txt" };
	const int count = sizeof(PATHS)/sizeof(PATHS[0]);

	Removev(PATHS, count);

	tc_iovec *writev = (tc_iovec *)malloc(sizeof(tc_iovec) * count);
	for (int i = 0; i < count; ++i) {
		tc_iov4creation(&writev[i], PATHS[i], 4096,
				getRandomBytes(4096));
	}

	EXPECT_OK(tc_writev(writev, count, false));

	tc_iovec *readv = (tc_iovec *)malloc(sizeof(tc_iovec) * count);
	for (int i = 0; i < count; ++i) {
		tc_iov2path(&readv[i], PATHS[i], 0, 4096,
			    (char *)malloc(4096));
	}

	EXPECT_OK(tc_readv(readv, count, false));

	EXPECT_TRUE(compare_content(writev, readv, count));

	free_iovec(writev, count);
	free_iovec(readv, count);
}
示例#4
0
static void CopyOrDupFiles(const char *dir, bool copy, int nfiles)
{
	const int N = 4096;
	std::vector<struct tc_extent_pair> pairs(nfiles);
	std::vector<struct tc_iovec> iovs(nfiles);
	std::vector<struct tc_iovec> read_iovs(nfiles);
	std::vector<std::string> src_paths(nfiles);
	std::vector<std::string> dst_paths(nfiles);
	char buf[PATH_MAX];

	EXPECT_TRUE(tc_rm_recursive(dir));
	EXPECT_OK(tc_ensure_dir(dir, 0755, NULL));

	for (int i = 0; i < nfiles; ++i) {
		src_paths[i].assign(
		    buf, snprintf(buf, PATH_MAX, "%s/src-%d.txt", dir, i));
		dst_paths[i].assign(
		    buf, snprintf(buf, PATH_MAX, "%s/dst-%d.txt", dir, i));
		tc_fill_extent_pair(&pairs[i], src_paths[i].c_str(), 0,
				    dst_paths[i].c_str(), 0, N);

		tc_iov4creation(&iovs[i], pairs[i].src_path, N,
				getRandomBytes(N));
		EXPECT_NOTNULL(iovs[i].data);

		tc_iov2path(&read_iovs[i], pairs[i].dst_path, 0, N,
			    (char *)malloc(N));
		EXPECT_NOTNULL(read_iovs[i].data);
	}

	EXPECT_OK(tc_writev(iovs.data(), nfiles, false));

	// copy or move files
	if (copy) {
		EXPECT_OK(tc_copyv(pairs.data(), nfiles, false));
	} else {
		EXPECT_OK(tc_dupv(pairs.data(), nfiles, false));
	}

	EXPECT_OK(tc_readv(read_iovs.data(), nfiles, false));

	compare_content(iovs.data(), read_iovs.data(), nfiles);

	for (int i = 0; i < nfiles; ++i) {
		free(iovs[i].data);
		free(read_iovs[i].data);
	}
}
int main (int argc, char *argv[])
{
	int i;
	char *groupname = NULL;
	char *configdir = NULL;
	int num = -1;
	osync_bool failed = FALSE;
	osync_bool tryrecover = FALSE;
	OSyncError *error = NULL;
	OSyncEngine *engine = NULL;
	
	if (argc <= 1)
		usage (argv[0], 1);

	groupname = argv[1];
	for (i = 2; i < argc; i++) {
		char *arg = argv[i];
		if (!strcmp (arg, "--configdir")) {
			configdir = argv[i + 1];
			i++;
			if (!configdir)
				usage (argv[0], 1);
		} else if (!strcmp (arg, "--num")) {
			num = atoi(argv[i + 1]);
			i++;
			if (num <= 0)
				usage (argv[0], 1);
		} else if (!strcmp (arg, "--help")) {
			usage (argv[0], 0);
		} else if (!strcmp (arg, "--tryrecover")) {
			tryrecover = TRUE;
		} else if (!strcmp (arg, "--")) {
			break;
		} else if (arg[0] == '-') {
			usage (argv[0], 1);
		} else {
			usage (argv[0], 1);
		}
	}
	
	loop = g_main_loop_new(NULL, TRUE);	
	if (!g_thread_supported ()) g_thread_init (NULL);
	
	osync_trace(TRACE_ENTRY, "++++ Started the sync stress test +++");
	OSyncEnv *osync = osync_env_new(NULL);
	osync_env_set_option(osync, "GROUPS_DIRECTORY", configdir);
	
	if (!osync_env_initialize(osync, &error)) {
		printf("Unable to initialize environment: %s\n", osync_error_print(&error));
		osync_error_unref(&error);
		goto error_free_env;
	}
	
	OSyncGroup *group = osync_env_find_group(osync, groupname);
	
	if (!group) {
		printf("Unable to find group with name \"%s\"\n", groupname);
		goto error_free_env;
	}
	
	if (!g_thread_supported ()) g_thread_init (NULL);
	working = g_mutex_new();
	int count = 0;
	while (1) {
		engine = osengine_new(group, &error);
		if (!engine) {
			printf("Error while creating syncengine: %s\n", osync_error_print(&error));
			osync_error_unref(&error);
			goto error_free_env;
		}
		
		if (!osengine_init(engine, &error)) {
			printf("Error while initializing syncengine: %s\n", osync_error_print(&error));
			osync_error_unref(&error);
			goto error_free_engine;
		}
		
		do {
			count++;
			printf("++++++++++++++++++++++++++++++\n");
			printf("Initializing new round #%i!\n", count);
			
			if (g_random_int_range(0, 5) == 0) {
				int i;
				OSyncFormatEnv *env = osync_group_get_format_env(group);
				for (i = 0; i < osync_conv_num_objtypes(env); i++) {
					if (g_random_int_range(0, 5) == 0) {
						OSyncObjType *type = osync_conv_nth_objtype(env, i);
						osync_group_set_slow_sync(group, osync_objtype_get_name(type), TRUE);
						printf("Requesting slow-sync for: %s\n", osync_objtype_get_name(type));
					}
				}
				osync_conv_env_free(env);
			}
			
			update_change_list(engine);
			
			if (!check_mappings(engine) || !check_hashtables(engine) || !compare_content(engine)) {
				if (failed) {
					printf("already failed last round...\n");
					goto error_free_engine;
				}
				failed = TRUE;
				if (!tryrecover) {
					printf("Failed. Not trying to recover\n");
					goto error_free_engine;
				} else {
					printf("Failed. Trying to recover!\n");
					osync_group_set_slow_sync(group, "data", TRUE);
				}
			} else {
				failed = FALSE;
			}
			
			change_content(engine);

			printf("Starting to synchronize\n");
			if (!osengine_sync_and_block(engine, &error)) {
				printf("Error while starting synchronization: %s\n", osync_error_print(&error));
				osync_error_unref(&error);
				goto error_free_engine;
			}
			
			if (!compare_content(engine))
				goto error_free_engine;
			
			sleep(2);
			printf("End of synchronization\n");
			
			if (count == num)
				goto out;
		} while (g_random_int_range(0, 3) != 0);
		
		printf("Finalizing engine\n");
		osengine_finalize(engine);
		osengine_free(engine);
	}
	
out:
	osync_trace(TRACE_EXIT, "Stress test successful");
	printf("Stress test successful\n");
	return 0;
	
error_free_engine:
	osengine_free(engine);
error_free_env:
	osync_env_free(osync);
	g_main_loop_unref(loop);
	osync_trace(TRACE_EXIT_ERROR, "Stress test failed");
	printf("ERROR: Stress test failed\n");
	return 1;
}