Test(scratch_buffers, stats_counters_are_updated)
{
  GString *str;

  for (gint count = 1; count <= ITERATIONS; count++)
    {
      str = scratch_buffers_alloc();
      cr_assert_not_null(str);

      /* check through accessor functions */
      cr_assert(scratch_buffers_get_local_usage_count() == count,
                "get_local_usage_count() not returning proper value, value=%d, expected=%d",
                scratch_buffers_get_local_usage_count(), count);

      cr_assert(scratch_buffers_get_local_allocation_bytes() == count * DEFAULT_ALLOC_SIZE,
                "get_local_allocation_bytes() not returning proper value, value=%ld, expected=%ld",
                scratch_buffers_get_local_allocation_bytes(), count * DEFAULT_ALLOC_SIZE);

      /* check through metrics */
      cr_assert(stats_counter_get(stats_scratch_buffers_count) == count,
                "Statistic scratch_buffers_count is not updated properly, value=%d, expected=%d",
                (gint) stats_counter_get(stats_scratch_buffers_count), count);

      /* check if byte counter is updated */
      scratch_buffers_update_stats();
      cr_assert_eq(stats_counter_get(stats_scratch_buffers_bytes), count * DEFAULT_ALLOC_SIZE);
    }
}
Test(scratch_buffers, alloc_returns_a_gstring_instance)
{
  GString *str = scratch_buffers_alloc();

  cr_assert_not_null(str);
  _do_something_with_a_gstring(str);
  cr_assert_eq(scratch_buffers_get_local_usage_count(), 1);
}
Test(scratch_buffers, local_usage_metrics_measure_allocs)
{
  GString *str;

  str = scratch_buffers_alloc();
  cr_assert_not_null(str);
  _do_something_with_a_gstring(str);

  cr_assert_eq(scratch_buffers_get_local_usage_count(), 1);
  cr_assert_eq(scratch_buffers_get_local_allocation_bytes(), DEFAULT_ALLOC_SIZE);

  str = scratch_buffers_alloc();
  cr_assert_not_null(str);
  _do_something_with_a_gstring(str);
  cr_assert_eq(scratch_buffers_get_local_usage_count(), 2);
  cr_assert_eq(scratch_buffers_get_local_allocation_bytes(), 2*DEFAULT_ALLOC_SIZE);
}
Test(scratch_buffers, reclaim_marked_allocs)
{
  ScratchBuffersMarker marker;
  GString *str;

  str = scratch_buffers_alloc();
  cr_assert_not_null(str);
  _do_something_with_a_gstring(str);

  scratch_buffers_mark(&marker);

  for (gint i = 0; i < ITERATIONS; i++)
    {
      str = scratch_buffers_alloc();
      cr_assert_not_null(str);
      _do_something_with_a_gstring(str);
    }
  cr_assert_eq(scratch_buffers_get_local_usage_count(), ITERATIONS + 1);
  scratch_buffers_reclaim_marked(marker);
  cr_assert_eq(scratch_buffers_get_local_usage_count(), 1);
}
Test(scratch_buffers, reclaim_allocations_drops_all_allocs)
{
  for (gint i = 0; i < ITERATIONS; i++)
    {
      GString *str = scratch_buffers_alloc();
      cr_assert_not_null(str);
      _do_something_with_a_gstring(str);
    }
  cr_assert_eq(scratch_buffers_get_local_usage_count(), ITERATIONS);
  scratch_buffers_reclaim_allocations();
  cr_assert_eq(scratch_buffers_get_local_usage_count(), 0);
}
Exemple #6
0
/******************************************************************************
* Begin test running routines
******************************************************************************/
void do_getname(void)
{
	int i, ret;
	size_t addrlen;
	void *addr;
	struct gnix_ep_name *src_addr;

	ret = fi_getname(get_fid[ep_type](0), NULL, NULL);
	cr_assert(ret == -FI_EINVAL, "fi_getname returned: %s",
		  fi_strerror(-ret));

	for (i = 0; i < NUMEPS; i++) {
		ret = fi_getname(get_fid[ep_type](i), NULL, &addrlen);
		cr_assert(ret == -FI_ETOOSMALL, "fi_getname returned: %s",
			  fi_strerror(-ret));
		if (use_str_fmt) {
			cr_assert(addrlen == GNIX_FI_ADDR_STR_LEN,
				  "addrlen: %lu does not match size for "
					  "FI_ADDR_STR", addrlen);
		} else {
			cr_assert(addrlen == sizeof(struct gnix_ep_name),
				  "addrlen: %lu does not match the size for"
					  " FI_ADDR_GNI", addrlen);
		}

		addr = malloc(addrlen);
		ret = errno;
		cr_assert_not_null(addr, "malloc returned: %s", strerror(ret));

		ret = fi_getname(get_fid[ep_type](i), addr, &addrlen);
		cr_assert(ret == FI_SUCCESS, "fi_getname returned: %s",
			  fi_strerror(-ret));

		if (use_str_fmt) {
			cr_assert(addrlen == GNIX_FI_ADDR_STR_LEN,
				  "addrlen: %lu does not match size for "
					  "FI_ADDR_STR", addrlen);
		} else {
			cr_assert(addrlen == sizeof(struct gnix_ep_name),
				  "addrlen: %lu does not match the size for "
					  "FI_ADDR_GNI", addrlen);
		}

		get_fid_ep(i, NULL, NULL, (void **) &src_addr);

		dbg_printf(BLUE "ep_name = %p\n" COLOR_RESET, src_addr);

		if (use_str_fmt)
			check_ep_name_str(*src_addr, addr, ep_name_len[i]);
		free(addr);
	}
}
Exemple #7
0
void do_getpeer(void)
{
	int i = 0, ret;
	size_t addrlen;
	void *addr;
	struct gnix_ep_name *dest_addr, rebuilt;
	struct fid_ep *ep_fid;

	ret = fi_getpeer(get_fid_ep(0, NULL, NULL, NULL), NULL, NULL);
	cr_assert(ret == -FI_EINVAL, "fi_getpeer returned: %s",
		  fi_strerror(-ret));

	for (i = 0; i < NUMEPS; i++) {
		ep_fid = get_fid_ep(i, NULL, (void **) &dest_addr, NULL);
		addrlen = ep_name_len[i];
		addr = malloc(addrlen);
		ret = errno;
		cr_assert_not_null(addr, "malloc returned: %s", strerror(ret));
		init_bufs(&addr, 1, addrlen);

		addrlen = 0;
		ret = fi_getpeer(ep_fid, addr, &addrlen);
		cr_assert(ret == -FI_ETOOSMALL, "fi_getpeer returned: %s",
			  fi_strerror(-ret));

		ret = fi_getpeer(ep_fid, addr, &addrlen);
		cr_assert(ret == FI_SUCCESS, "fi_getpeer returned: %s",
			  fi_strerror(-ret));

		if (use_str_fmt) {
			dbg_printf(BLUE "strlen(addr) = %lu\n" COLOR_RESET,
				   strlen(addr));

			fas_to_ep_name(addr, &rebuilt);
			check_ep_name(*dest_addr, rebuilt);
		} else {
			check_ep_name(*dest_addr,
				      ((struct gnix_ep_name *) addr)[0]);
		}

		free(addr);
	}
}
Exemple #8
0
void do_setname(void)
{
	int i, ret;
	void *addr;
	struct gnix_ep_name *src_addr = NULL, rebuilt;
	struct fi_info *info = NULL;

	ret = fi_setname(get_fid[ep_type](0), NULL, 0xbabbbcbd);
	cr_assert(ret == -FI_EINVAL, "fi_setname returned: %s",
		  fi_strerror(-ret));

	for (i = 0; i < NUMEPS; i++) {
		addr = malloc(ep_name_len[i]);
		ret = errno;
		cr_assert_not_null(addr, "malloc returned: %s", strerror(ret));

		if (use_str_fmt)
			generate_rand_fas((char **) &addr);
		else
			init_bufs(&addr, 1, ep_name_len[i]);

		ret = fi_setname(get_fid[ep_type](i), addr, ep_name_len[i]);
		cr_assert(ret == FI_SUCCESS, "fi_setname returned: %s",
			  fi_strerror(-ret));

		get_fid_ep(i, (void **) &info, (void **) NULL, (void **)
			&src_addr);

		/* Ensure that the address was set properly. */
		if (use_str_fmt) {
			fas_to_ep_name(addr, &rebuilt);
			check_ep_name(rebuilt, *src_addr);
		} else {
			check_ep_name(((struct gnix_ep_name *)addr)[0],
				      *src_addr);
		}


		free(addr);
	}
}
Exemple #9
0
/******************************************************************************
* Begin verification routines
******************************************************************************/
static void fas_to_ep_name(char *ep_name_str, struct gnix_ep_name *rebuilt)
{
	char *buf;

	dbg_printf(BLUE
			   "ep_name_str(%p) = %s.\n"
			   COLOR_RESET, ep_name_str, ep_name_str);

	buf = strtok(ep_name_str, ";");

	cr_assert_not_null(buf, "address family not found");

	dbg_printf(BLUE
			   "buf = %s\nbuf_len = %lu\n"
			   COLOR_RESET, buf,
		   strlen(buf));
	cr_assert(!memcmp(buf, "gni", 3));

	buf = strtok(NULL, ";");
	cr_assert_not_null(buf, "node not found");
	dbg_printf(BLUE
			   "buf = %s\nbuf_len = %lu\n"
			   COLOR_RESET, buf,
		   strlen(buf));

	buf = strtok(NULL, ";");
	cr_assert_not_null(buf, "service not found");
	dbg_printf(BLUE
			   "buf = %s\nbuf_len = %lu\n"
			   COLOR_RESET, buf, strlen(buf));


	buf = strtok(NULL, ";");
	cr_assert_not_null(buf, "zeroth additional field "
		"(GNIX_AV_STR_ADDR_VERSION) not found");
	dbg_printf(BLUE
			   "buf = %s\nbuf_len = %lu\n"
			   COLOR_RESET, buf, strlen(buf));

	buf = strtok(NULL, ";");
	cr_assert_not_null(buf, "first additional field (device address) not "
		"found");
	rebuilt->gnix_addr.device_addr = strtol(buf, NULL, 16);
	dbg_printf(BLUE
			   "buf = %s\nbuf_len = %lu\n"
			   COLOR_RESET, buf, strlen(buf));

	buf = strtok(NULL, ";");
	cr_assert_not_null(buf, "second additional field (cdm id) not found");
	rebuilt->gnix_addr.cdm_id = strtol(buf, NULL, 16);
	dbg_printf(BLUE
			   "buf = %s\nbuf_len = %lu\n"
			   COLOR_RESET, buf, strlen(buf));

	buf = strtok(NULL, ";");
	cr_assert_not_null(buf, "third additional field (name type) not found");
	rebuilt->name_type = strtol(buf, NULL, 10);
	dbg_printf(BLUE
			   "buf = %s\nbuf_len = %lu\n"
			   COLOR_RESET, buf, strlen(buf));

	buf = strtok(NULL, ";");
	cr_assert_not_null(buf, "forth additional field (cm_nic_cdm_id) not "
		"found");
	rebuilt->cm_nic_cdm_id = strtol(buf, NULL, 16);
	dbg_printf(BLUE
			   "buf = %s\nbuf_len = %lu\n"
			   COLOR_RESET, buf, strlen(buf));

	buf = strtok(NULL, ";");
	cr_assert_not_null(buf, "fifth additional field (cookie) not found");
	rebuilt->cookie = strtol(buf, NULL, 16);
	dbg_printf(BLUE
			   "buf = %s\nbuf_len = %lu\n"
			   COLOR_RESET, buf, strlen(buf));

	buf = strtok(NULL, ";");
	cr_assert_not_null(buf, "sixth additional field (rx_ctx_cnt) not "
		"found");
	rebuilt->rx_ctx_cnt = strtol(buf, NULL, 10);
	dbg_printf(BLUE
			   "buf = %s\nbuf_len = %lu\n"
			   COLOR_RESET, buf, strlen(buf));
}
Exemple #10
0
static void straddr_test(void)
{
	const char *buf;
#define ADDRSTR_LEN 128
	char addrstr[ADDRSTR_LEN];
	size_t addrstr_len;
	char *pend;
	long int value;

	addrstr_len = 10; /* too short */
	buf = fi_av_straddr(av, &simple_ep_names[0], addrstr, &addrstr_len);
	cr_assert_eq(buf, addrstr);
	cr_assert_eq(addrstr_len, 10);

	addrstr_len = ADDRSTR_LEN;
	buf = fi_av_straddr(av, &simple_ep_names[0], addrstr, &addrstr_len);
	cr_assert_eq(buf, addrstr);
	cr_assert_eq(addrstr_len, GNIX_AV_MAX_STR_ADDR_LEN);

	/* extract the first component */
	buf = strtok(addrstr, ":");
	cr_assert_not_null(buf, "version not found");

	value = strtol(buf, &pend, 16);

	/* verify the version has been returned. */
	cr_assert_eq(GNIX_AV_STR_ADDR_VERSION, value, "Invalid version");

	/* extract the second component */
	buf = strtok(NULL, ":");
	cr_assert_not_null(buf, "device_addr not found");

	value = strtol(buf, &pend, 16);

	/* verify the device addrstr has been returned. */
	cr_assert_eq(simple_ep_names[0].gnix_addr.device_addr, value,
		    "Invalid device_addr");

	/* extract the third component */
	buf = strtok(NULL, ":");
	cr_assert_not_null(buf, "cdm_id not found");

	value = strtol(buf, &pend, 16);

	/* verify the cdm_id has been returned. */
	cr_assert_eq(simple_ep_names[0].gnix_addr.cdm_id, value,
		     "Invalid cdm_id");

	/* extract the fourth component */
	buf = strtok(NULL, ":");
	cr_assert_not_null(buf, "name_type not found");

	value = strtol(buf, &pend, 10);

	/* verify the name_type has been returned. */
	cr_assert_eq(simple_ep_names[0].name_type, value, "Invalid name_type");

	/* extract the fifth component */
	buf = strtok(NULL, ":");
	cr_assert_not_null(buf, "cm_nic_cdm_id not found");

	value = strtol(buf, &pend, 16);

	/* verify the cm_nic_cdm_id has been returned. */
	cr_assert_eq(simple_ep_names[0].cm_nic_cdm_id, value,
		     "Invalid cm_nic_cdm_id");

	/* extract the sixth component */
	buf = strtok(NULL, ":");
	cr_assert_not_null(buf, "cookie not found");

	value = strtol(buf, &pend, 16);

	/* verify the cookie has been returned. */
	cr_assert_eq(simple_ep_names[0].cookie, value, "Invalid cookie");

	/* check to see if additional component are specified */
	buf = strtok(NULL, ":");
	cr_assert_null(buf, "extra values specified");
}