예제 #1
0
// test encode/decode.
static void encode_decode_test(void) {
  char buffer[BUF_SIZE];
  struct census_tag_set *cts =
      census_tag_set_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL);
  size_t print_bsize;
  size_t bin_bsize;
  // Test with too small a buffer
  GPR_ASSERT(census_tag_set_encode(cts, buffer, 2, &print_bsize, &bin_bsize) ==
             NULL);
  char *b_buffer =
      census_tag_set_encode(cts, buffer, BUF_SIZE, &print_bsize, &bin_bsize);
  GPR_ASSERT(b_buffer != NULL && print_bsize > 0 && bin_bsize > 0 &&
             print_bsize + bin_bsize <= BUF_SIZE &&
             b_buffer == buffer + print_bsize);
  census_tag_set *cts2 =
      census_tag_set_decode(buffer, print_bsize, b_buffer, bin_bsize);
  GPR_ASSERT(cts2 != NULL);
  const census_tag_set_create_status *status =
      census_tag_set_get_create_status(cts2);
  census_tag_set_create_status expected = {2, 2, 0, 0, 0, 0, 0, 0};
  GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0);
  for (int i = 0; i < BASIC_TAG_COUNT; i++) {
    census_tag tag;
    if (CENSUS_TAG_IS_PROPAGATED(basic_tags[i].flags)) {
      GPR_ASSERT(census_tag_set_get_tag_by_key(cts2, basic_tags[i].key, &tag) ==
                 1);
      GPR_ASSERT(compare_tag(&tag, &basic_tags[i]));
    } else {
      GPR_ASSERT(census_tag_set_get_tag_by_key(cts2, basic_tags[i].key, &tag) ==
                 0);
    }
  }
  census_tag_set_destroy(cts2);
  census_tag_set_destroy(cts);
}
예제 #2
0
파일: svadm.c 프로젝트: 0xffea/illumos-gate
/* LINT - not static as fwcadm uses it */
static void
compare_one_sv(char *path)
{
	sv_get_maxdevs();
	sv_check_cluster(NULL);
	sv_cfg_open(CFG_WRLOCK);

	compare_tag(path);

	sv_cfg_close();
}
예제 #3
0
// add a single new tag.
static void add_tag_test(void) {
  struct census_tag_set *cts =
      census_tag_set_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL);
  const census_tag_set_create_status *status;
  struct census_tag_set *cts2 =
      census_tag_set_create(cts, modify_tags + ADD_TAG_OFFSET, 1, &status);
  census_tag_set_create_status expected = {2, 2, 5, 0, 1, 0, 0, 0};
  GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0);
  census_tag tag;
  GPR_ASSERT(census_tag_set_get_tag_by_key(
                 cts2, modify_tags[ADD_TAG_OFFSET].key, &tag) == 1);
  GPR_ASSERT(compare_tag(&tag, &modify_tags[ADD_TAG_OFFSET]));
  census_tag_set_destroy(cts);
  census_tag_set_destroy(cts2);
}
예제 #4
0
파일: context_test.c 프로젝트: An-mol/grpc
// replace a single tags flags
static void replace_flags_test(void) {
  struct census_context *context =
      census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL);
  const census_context_status *status;
  struct census_context *context2 = census_context_create(
      context, modify_tags + REPLACE_FLAG_OFFSET, 1, &status);
  census_context_status expected = {1, 2, 5, 0, 0, 1, 0, 0};
  GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0);
  census_tag tag;
  GPR_ASSERT(census_context_get_tag(
                 context2, modify_tags[REPLACE_FLAG_OFFSET].key, &tag) == 1);
  GPR_ASSERT(compare_tag(&tag, &modify_tags[REPLACE_FLAG_OFFSET]));
  census_context_destroy(context);
  census_context_destroy(context2);
}
예제 #5
0
// Make a copy of a tag set
static void copy_test(void) {
  struct census_tag_set *cts =
      census_tag_set_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL);
  const census_tag_set_create_status *status;
  struct census_tag_set *cts2 = census_tag_set_create(cts, NULL, 0, &status);
  census_tag_set_create_status expected = {2, 2, 4, 0, 0, 0, 0, 0};
  GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0);
  for (int i = 0; i < BASIC_TAG_COUNT; i++) {
    census_tag tag;
    GPR_ASSERT(census_tag_set_get_tag_by_key(cts2, basic_tags[i].key, &tag) ==
               1);
    GPR_ASSERT(compare_tag(&tag, &basic_tags[i]));
  }
  census_tag_set_destroy(cts);
  census_tag_set_destroy(cts2);
}
예제 #6
0
파일: context_test.c 프로젝트: An-mol/grpc
// Test census_context_get_tag().
static void lookup_by_key_test(void) {
  struct census_context *context =
      census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL);
  census_tag tag;
  for (int i = 0; i < BASIC_TAG_COUNT; i++) {
    GPR_ASSERT(census_context_get_tag(context, basic_tags[i].key, &tag) == 1);
    GPR_ASSERT(compare_tag(&tag, &basic_tags[i]));
  }
  // non-existent keys
  GPR_ASSERT(census_context_get_tag(context, "key", &tag) == 0);
  GPR_ASSERT(census_context_get_tag(context, "key01", &tag) == 0);
  GPR_ASSERT(census_context_get_tag(context, "k9", &tag) == 0);
  GPR_ASSERT(census_context_get_tag(context, "random", &tag) == 0);
  GPR_ASSERT(census_context_get_tag(context, "", &tag) == 0);
  census_context_destroy(context);
}
예제 #7
0
// Test create and iteration over basic tag set.
static void basic_test(void) {
  const census_tag_set_create_status *status;
  struct census_tag_set *cts =
      census_tag_set_create(NULL, basic_tags, BASIC_TAG_COUNT, &status);
  census_tag_set_create_status expected = {2, 2, 4, 0, 8, 0, 0, 0};
  GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0);
  census_tag_set_iterator it;
  census_tag_set_initialize_iterator(cts, &it);
  census_tag tag;
  while (census_tag_set_next_tag(&it, &tag)) {
    // can't rely on tag return order: make sure it matches exactly one.
    int matches = 0;
    for (int i = 0; i < BASIC_TAG_COUNT; i++) {
      if (compare_tag(&tag, &basic_tags[i])) matches++;
    }
    GPR_ASSERT(matches == 1);
  }
  census_tag_set_destroy(cts);
}
예제 #8
0
// Utility function to validate a tag exists in tag set.
static bool validate_tag(const census_tag_set *cts, const census_tag *tag) {
  census_tag tag2;
  if (census_tag_set_get_tag_by_key(cts, tag->key, &tag2) != 1) return false;
  return compare_tag(tag, &tag2);
}
예제 #9
0
파일: svadm.c 프로젝트: 0xffea/illumos-gate
/* LINT - not static as fwcadm uses it */
static void
compare_sv(char *conf_file)
{
	sv_name_t *svn_config;		/* Devices in config file */
	sv_name_t *svn_system;		/* Devices in system */
	sv_name_t *enable;		/* Devices that need enabled */
	sv_list_t svl_system;
	int config_cnt;
	int sys_cnt = 0;
	int setnumber, i, j;
	int index = 0;	/* Index in enable[] */
	int found;
	int fd0;

	svn_config = sv_alloc_svnames();
	svn_system = sv_alloc_svnames();
	enable = sv_alloc_svnames();

	bzero(svn_system, sizeof (svn_system));
	bzero(&svl_system, sizeof (svl_system));
	bzero(enable, sizeof (enable));

	/*
	 * Read the configuration file
	 * The return value is the number of entries
	 */
	config_cnt = read_config_file(conf_file, svn_config);

	if ((fd0 = open(sv_rpath, O_RDONLY)) < 0)
		error(NULL, gettext("unable to open %s: %s"),
			sv_rpath, strerror(errno));

	/* Grab the system list from the driver */
	svl_system.svl_count = sv_max_devices;
	svl_system.svl_names = &svn_system[0];
	svl_system.svl_error = spcs_s_ucreate();

	if (ioctl(fd0, SVIOC_LIST, &svl_system) < 0) {
		error(&svl_system.svl_error, gettext("unable to get list"));
	}

	spcs_s_ufree(&svl_system.svl_error);
	(void) close(fd0);

	/*
	 * Count the number of devices in the system.
	 * The last entry in the array has '\0' for a path name.
	 */
	for (j = 0; j < sv_max_devices; j++) {
		if (svn_system[j].svn_path[0] != '\0') {
			sys_cnt++;
		} else {
			break;
		}
	}
	/*
	 * Compare the configuration array with the system array.
	 * Mark any differences and disable conflicting devices.
	 */
	for (i = 0; i < config_cnt; i++) {
		found = 0;
		for (j = 0; j < sys_cnt; j++) {
			if (svn_system[j].svn_path[0] == '\0' ||
			    svn_system[j].svn_mode == 0)
				continue;

			/*  Check to see if path matches */
			if (strcmp(svn_system[j].svn_path,
			    svn_config[i].svn_path) == 0) {
				/*  Found a match  */
				svn_system[j].svn_path[0] = '\0';
				found++;
				break;
			}
		}

		if (!found) {
			/* Minor number not in system  = > enable device */
			enable[index].svn_mode = svn_config[i].svn_mode;
			(void) strcpy(enable[index].svn_path,
			    svn_config[i].svn_path);
			index++;
		}
	}

	/* Disable any devices that weren't in the config file */
	for (j = 0; j < sys_cnt; j++) {
		sv_check_cluster(NULL);
		sv_cfg_open(CFG_WRLOCK);
		create_cfg_hash();
		if (svn_system[j].svn_path[0] != '\0' &&
		    svn_system[j].svn_mode != 0) {
			(void) printf(gettext("%s: disabling sv: %s\n"),
			    program, svn_system[j].svn_path);
			if (disable_dev(svn_system[j].svn_path) == 0) {
				setnumber =
					find_in_hash(svn_system[j].svn_path);
				if (setnumber != -1) {
					/* the volume was found in cfg store */
					remove_from_cfgfile(
					svn_system[j].svn_path, setnumber);
				}
			}
		}
		sv_cfg_close();
		destroy_hashtable();
	}

	while (index) {
		/*
		 * Config file doesn't match system => enable the devices
		 * in enable[]
		 */
		index--;
		(void) printf(gettext("%s: enabling new sv: %s\n"),
		    program, enable[index].svn_path);
		(void) enable_dev(&enable[index]);
	}

	/*
	 * Search for entries where the cluster tag has changed.
	 */
	sv_check_cluster(NULL);
	sv_cfg_open(CFG_WRLOCK);

	for (i = 0; i < sv_max_devices; i++) {
		if (svn_config[i].svn_path[0] == '\0')
			break;

		compare_tag(svn_config[i].svn_path);
	}

	sv_cfg_close();
}
예제 #10
0
파일: context_test.c 프로젝트: An-mol/grpc
// Utility function to validate a tag exists in context.
static bool validate_tag(const census_context *context, const census_tag *tag) {
  census_tag tag2;
  if (census_context_get_tag(context, tag->key, &tag2) != 1) return false;
  return compare_tag(tag, &tag2);
}