示例#1
0
/* Simple sanity test to ensure low-level POSIX APIs work */
void sanity(void)
{
	char *buf;
	size_t len;
	int fd;

	fflush(stdout);
	len = asprintf(&buf, "%s/sanity", mount_dir);
	CU_ASSERT_NOT_EQUAL_FATAL(len, -1);
	CU_ASSERT_PTR_NOT_NULL(buf);

	unlink(buf);
	fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0600);
	CU_ASSERT_NOT_EQUAL_FATAL(fd, -1);

	do_write_tests(fd, buf, len);
	do_read_tests(buf, len);
	do_misc_tests(buf, len);
	do_large_io_test(buf, len);
	free(buf);
}
示例#2
0
int main (int argc, char *argv[]) {
	confdb_handle_t handle;
	int result;
	hdb_handle_t totem_handle;
	char key_value[256];
	size_t value_len;

	result = confdb_initialize (&handle, &callbacks);
	if (result != CS_OK) {
		printf ("Could not initialize Cluster Configuration Database API instance error %d\n", result);
		exit (1);
	}

	if (argv[1] && strcmp(argv[1], "write")==0)
		do_write_tests(handle);

	if (argv[1] && strcmp(argv[1], "reload")==0) {
		/* Test reload interface */
		result = confdb_reload(handle, 0, key_value, sizeof key_value);
		printf ("Try to reload the config (noflush): %d (should be 1)\n", result);

		result = confdb_reload(handle, 1, key_value, sizeof key_value);
		printf ("Try to reload the config (flush): %d (should be 1)\n", result);
	}

	/* Test iterators */
	print_config_tree(handle, OBJECT_PARENT_HANDLE, 0);

	/* Find "totem" and dump bits of it again, to test the direct APIs */
	result = confdb_object_find_start(handle, OBJECT_PARENT_HANDLE);
	if (result != CS_OK) {
		printf ("Could not start object_find %d\n", result);
		exit (1);
	}

	result = confdb_object_find(handle, OBJECT_PARENT_HANDLE, "totem", strlen("totem"), &totem_handle);
	if (result != CS_OK) {
		printf ("Could not object_find \"totem\": %d\n", result);
		exit (1);
	}

	result = confdb_key_get(handle, totem_handle, "version", strlen("version"), key_value, &value_len);
	if (result != CS_OK) {
		printf ("Could not get \"version\" key: %d\n", result);
		exit (1);
	}
	key_value[value_len] = '\0';
	printf("totem/version = '%s'\n", key_value);

	result = confdb_key_get(handle, totem_handle, "secauth", strlen("secauth"), key_value, &value_len);
	if (result != CS_OK) {
		printf ("Could not get \"secauth\" key: %d\n", result);
		exit (1);
	}
	key_value[value_len] = '\0';
	printf("totem/secauth = '%s'\n", key_value);

	/* Try a call that fails */
	result = confdb_key_get(handle, totem_handle, "grot", strlen("grot"), key_value, &value_len);
	printf ("Get \"grot\" key returned: %d (should fail)\n", result);

	result = confdb_finalize (handle);
	printf ("Finalize  result is %d (should be 1)\n", result);
	return (0);
}