Example #1
0
static void test_brick_core_refcount(void)
{
	struct pg_error *error = NULL;
	struct pg_brick *brick;
	struct pg_brick_config *config = pg_brick_config_new("mybrick", 2, 2,
							     PG_MULTIPOLE);

	brick = pg_brick_new("nop", config, &error);
	g_assert(brick);
	g_assert(!error);

	/* Use the brick twice */
	pg_brick_incref(brick);
	pg_brick_incref(brick);

	/* Release it twice */
	brick = pg_brick_decref(brick, &error);
	g_assert(brick);
	g_assert(!error);
	brick = pg_brick_decref(brick, &error);
	g_assert(brick);
	g_assert(!error);

	/* finally destroy the brick */
	brick = pg_brick_decref(brick, &error);
	g_assert(!brick);
	g_assert(!error);

	pg_brick_config_free(config);
}
Example #2
0
static void test_brick_core_simple_lifecycle(void)
{
	struct pg_error *error = NULL;
	struct pg_brick *brick;
	struct pg_brick_config *config = pg_brick_config_new("mybrick", 2, 2,
							     PG_MULTIPOLE);

	brick = pg_brick_new("foo", config, &error);
	g_assert(!brick);
	g_assert(error);
	g_assert(error->message);
	g_assert_cmpstr(error->message, ==, "Brick 'foo' not found");
	pg_error_free(error);
	error = NULL;

	brick = pg_brick_new("nop", config, &error);
	g_assert(brick);
	g_assert(!error);

	pg_brick_decref(brick, &error);
	g_assert(!error);

	brick = pg_brick_decref(NULL, &error);
	g_assert(!brick);
	g_assert(error);
	g_assert(error->message);
	g_assert_cmpstr(error->message, ==, "NULL brick");
	pg_error_free(error);
	error = NULL;

	pg_brick_config_free(config);
}
Example #3
0
struct pg_brick *pg_nop_new(const char *name,
			    struct pg_error **errp)
{
	struct pg_brick_config *config = pg_brick_config_new(name, 1, 1,
							     PG_DIPOLE);
	struct pg_brick *ret = pg_brick_new("nop", config, errp);

	pg_brick_config_free(config);

	return ret;
}
Example #4
0
struct pg_brick *pg_fail_new(const char *name,
                             struct pg_error **errp)
{
    struct pg_brick_config *config;

    config = pg_brick_config_new(name, 1, 1, PG_MONOPOLE);
    struct pg_brick *ret = pg_brick_new("fail", config, errp);

    pg_brick_config_free(config);
    return ret;
}
Example #5
0
struct pg_brick *pg_packetsgen_new(const char *name,
				   uint32_t west_max,
				   uint32_t east_max,
				   enum pg_side output,
				   struct rte_mbuf **packets,
				   uint16_t packets_nb,
				   struct pg_error **errp)
{
	struct pg_brick_config *config;

	config = packetsgen_config_new(name,
				       west_max,
				       east_max,
				       packets,
				       packets_nb,
				       output);
	struct pg_brick *ret = pg_brick_new("packetsgen", config, errp);

	pg_brick_config_free(config);
	return ret;
}
Example #6
0
static void test_brick_core_multiple_unlink_edge(void)
{
	int i;
	struct pg_brick *west[4];
	struct pg_brick *middle;
	struct pg_brick *east[4];
	struct pg_error *error = NULL;
	struct pg_brick_config *config = pg_brick_config_new("mybrick", 4, 4,
							     PG_MULTIPOLE);

	middle = pg_brick_new("nop", config, &error);
	g_assert(middle);
	g_assert(!error);
	for (i = 0; i < 4; i++) {
		west[i] = pg_brick_new("nop", config, &error);
		g_assert(west[i]);
		g_assert(!error);
		east[i] = pg_brick_new("nop", config, &error);
		g_assert(east[i]);
		g_assert(!error);
	}

	for (int i = 0; i < 10; i++)
		test_brick_core_multiple_unlink_edge_(west, middle, east);

	/* destroy */
	for (i = 0; i < 4; i++) {
		pg_brick_decref(west[i], &error);
		g_assert(!error);
		pg_brick_decref(east[i], &error);
		g_assert(!error);
	}
	pg_brick_decref(middle, &error);
	g_assert(!error);

	pg_brick_config_free(config);
}
Example #7
0
static void test_brick_flow_west(void)
{
	struct pg_brick_config *config = pg_brick_config_new("mybrick", 4, 4);
	struct pg_brick *brick1, *brick2, *collect_west, *collect_east;
	struct rte_mbuf mbufs[NB_PKTS];
	struct rte_mbuf **result_pkts;
	struct rte_mbuf *pkts[NB_PKTS];
	uint16_t i;
	uint64_t pkts_mask;
	struct pg_error *error = NULL;

	/* prepare the packets to send */
	for (i = 0; i < NB_PKTS; i++) {
		mbufs[i].udata64 = i;
		pkts[i] = &mbufs[i];
	}

	/* create a chain of a few nop brick with collectors on each sides */
	brick1 = pg_brick_new("nop", config, &error);
	g_assert(!error);
	brick2 = pg_brick_new("nop", config, &error);
	g_assert(!error);
	collect_west = pg_brick_new("collect", config, &error);
	g_assert(!error);
	g_assert(collect_west);
	collect_east = pg_brick_new("collect", config, &error);
	g_assert(!error);
	g_assert(collect_east);

	pg_brick_link(collect_west, brick1, &error);
	g_assert(!error);
	pg_brick_link(brick1, brick2, &error);
	g_assert(!error);
	pg_brick_link(brick2, collect_east, &error);
	g_assert(!error);

	/* send a pkts to the west from the eastest nope brick */
	pg_brick_burst_to_west(brick2, 0, pkts, NB_PKTS,
			       pg_mask_firsts(NB_PKTS), &error);
	g_assert(!error);

	/* check pkts counter */
	g_assert(pg_brick_pkts_count_get(collect_east, WEST_SIDE) == 0);
	g_assert(pg_brick_pkts_count_get(collect_east, EAST_SIDE) == 0);
	g_assert(pg_brick_pkts_count_get(collect_west, WEST_SIDE) == 3);
	g_assert(pg_brick_pkts_count_get(collect_west, EAST_SIDE) == 0);
	g_assert(pg_brick_pkts_count_get(brick1, WEST_SIDE) == 3);
	g_assert(pg_brick_pkts_count_get(brick1, EAST_SIDE) == 0);
	g_assert(pg_brick_pkts_count_get(brick2, WEST_SIDE) == 3);
	g_assert(pg_brick_pkts_count_get(brick2, EAST_SIDE) == 0);

	/* check no packet ended on the east */
	result_pkts = pg_brick_west_burst_get(collect_east, &pkts_mask, &error);
	g_assert(!error);
	g_assert(!pkts_mask);
	g_assert(!result_pkts);
	result_pkts = pg_brick_east_burst_get(collect_east, &pkts_mask, &error);
	g_assert(!error);
	g_assert(!pkts_mask);
	g_assert(!result_pkts);

	/* collect pkts on the west */
	result_pkts = pg_brick_west_burst_get(collect_west, &pkts_mask, &error);
	g_assert(!error);
	g_assert(!pkts_mask);
	g_assert(!result_pkts);

	result_pkts = pg_brick_east_burst_get(collect_west, &pkts_mask, &error);
	g_assert(!error);
	g_assert(pkts_mask == pg_mask_firsts(NB_PKTS));
	g_assert(result_pkts);
	for (i = 0; i < NB_PKTS; i++)
		g_assert(result_pkts[i]->udata64 == i);

	/* break the chain */
	pg_brick_unlink(brick1, &error);
	g_assert(!error);
	pg_brick_unlink(brick2, &error);
	g_assert(!error);
	pg_brick_unlink(collect_west, &error);
	g_assert(!error);
	pg_brick_unlink(collect_east, &error);
	g_assert(!error);

	/* destroy */
	pg_brick_decref(brick1, &error);
	g_assert(!error);
	pg_brick_decref(brick2, &error);
	g_assert(!error);
	pg_brick_decref(collect_west, &error);
	g_assert(!error);
	pg_brick_decref(collect_east, &error);
	g_assert(!error);

	pg_brick_config_free(config);
}
Example #8
0
static void test_brick_core_link(void)
{
	struct pg_error *error = NULL;
	struct pg_brick *west_brick, *middle_brick, *east_brick;
	struct pg_brick_config *config = pg_brick_config_new("mybrick", 4, 4,
							     PG_MULTIPOLE);
	int64_t refcount;
	int ret;

	west_brick = pg_brick_new("nop", config, &error);
	g_assert(west_brick);
	g_assert(!error);

	middle_brick = pg_brick_new("nop", config, &error);
	g_assert(middle_brick);
	g_assert(!error);

	east_brick = pg_brick_new("nop", config, &error);
	g_assert(east_brick);
	g_assert(!error);

	ret = pg_brick_link(west_brick, middle_brick,  &error);
	g_assert(ret == 0);
	g_assert(!error);

	ret = pg_brick_link(middle_brick, east_brick, &error);
	g_assert(ret == 0);
	g_assert(!error);

	refcount = pg_brick_refcount(west_brick);
	g_assert(refcount == 2);
	refcount = pg_brick_refcount(middle_brick);
	g_assert(refcount == 3);
	refcount = pg_brick_refcount(east_brick);
	g_assert(refcount == 2);

	pg_brick_unlink(west_brick, &error);
	g_assert(!error);
	refcount = pg_brick_refcount(west_brick);
	g_assert(refcount == 1);
	refcount = pg_brick_refcount(middle_brick);
	g_assert(refcount == 2);
	refcount = pg_brick_refcount(east_brick);
	g_assert(refcount == 2);

	pg_brick_unlink(east_brick, &error);
	g_assert(!error);
	refcount = pg_brick_refcount(west_brick);
	g_assert(refcount == 1);
	refcount = pg_brick_refcount(middle_brick);
	g_assert(refcount == 1);
	refcount = pg_brick_refcount(east_brick);
	g_assert(refcount == 1);

	/* destroy */
	pg_brick_decref(west_brick, &error);
	g_assert(!error);
	pg_brick_decref(middle_brick, &error);
	g_assert(!error);
	pg_brick_decref(east_brick, &error);
	g_assert(!error);

	pg_brick_config_free(config);
}
Example #9
0
static void test_brick_core_verify_multiple_link(void)
{
	struct pg_brick *west_brick, *middle_brick, *east_brick;
	struct pg_brick_config *config = pg_brick_config_new("mybrick", 4, 4,
							     PG_MULTIPOLE);
	uint32_t links_count;
	struct pg_error *error = NULL;

	west_brick = pg_brick_new("nop", config, &error);
	g_assert(!error);
	middle_brick = pg_brick_new("nop", config, &error);
	g_assert(!error);
	east_brick = pg_brick_new("nop", config, &error);
	g_assert(!error);

	/* create a few links */
	pg_brick_link(west_brick, middle_brick, &error);
	g_assert(!error);
	pg_brick_link(west_brick, middle_brick, &error);
	g_assert(!error);
	pg_brick_link(middle_brick, east_brick, &error);
	g_assert(!error);
	pg_brick_link(middle_brick, east_brick, &error);
	g_assert(!error);
	pg_brick_link(middle_brick, east_brick, &error);
	g_assert(!error);

	/* sanity checks */
	test_brick_sanity_check(west_brick);
	test_brick_sanity_check(middle_brick);
	test_brick_sanity_check(east_brick);

	/* check the link count */
	links_count = pg_brick_links_count_get(west_brick, west_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);
	links_count = pg_brick_links_count_get(west_brick, middle_brick, &error);
	g_assert(!error);
	g_assert(links_count == 2);
	links_count = pg_brick_links_count_get(west_brick, east_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);

	links_count = pg_brick_links_count_get(middle_brick, middle_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);
	links_count = pg_brick_links_count_get(middle_brick, west_brick, &error);
	g_assert(!error);
	g_assert(links_count == 2);
	links_count = pg_brick_links_count_get(middle_brick, east_brick, &error);
	g_assert(!error);
	g_assert(links_count == 3);

	links_count = pg_brick_links_count_get(east_brick, east_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);
	links_count = pg_brick_links_count_get(east_brick, west_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);
	links_count = pg_brick_links_count_get(east_brick, middle_brick, &error);
	g_assert(!error);
	g_assert(links_count == 3);

	/* unlink the west brick */
	pg_brick_unlink(west_brick, &error);

	/* sanity checks */
	test_brick_sanity_check(west_brick);
	test_brick_sanity_check(middle_brick);
	test_brick_sanity_check(east_brick);

	/* check again */
	links_count = pg_brick_links_count_get(west_brick, west_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);
	links_count = pg_brick_links_count_get(west_brick, middle_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);
	links_count = pg_brick_links_count_get(west_brick, east_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);

	links_count = pg_brick_links_count_get(middle_brick, middle_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);
	links_count = pg_brick_links_count_get(middle_brick, west_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);
	links_count = pg_brick_links_count_get(middle_brick, east_brick, &error);
	g_assert(!error);
	g_assert(links_count == 3);

	links_count = pg_brick_links_count_get(east_brick, east_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);
	links_count = pg_brick_links_count_get(east_brick, west_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);
	links_count = pg_brick_links_count_get(east_brick, middle_brick, &error);
	g_assert(!error);
	g_assert(links_count == 3);

	/* unlink the east brick */
	pg_brick_unlink(east_brick, &error);
	g_assert(!error);

	/* sanity checks */
	test_brick_sanity_check(west_brick);
	test_brick_sanity_check(middle_brick);
	test_brick_sanity_check(east_brick);

	/* check again */
	links_count = pg_brick_links_count_get(west_brick, west_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);
	links_count = pg_brick_links_count_get(west_brick, middle_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);
	links_count = pg_brick_links_count_get(west_brick, east_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);

	links_count = pg_brick_links_count_get(middle_brick, middle_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);
	links_count = pg_brick_links_count_get(middle_brick, west_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);
	links_count = pg_brick_links_count_get(middle_brick, east_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);

	links_count = pg_brick_links_count_get(east_brick, east_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);
	links_count = pg_brick_links_count_get(east_brick, west_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);
	links_count = pg_brick_links_count_get(east_brick, middle_brick, &error);
	g_assert(!error);
	g_assert(links_count == 0);

	/* destroy */
	pg_brick_decref(west_brick, &error);
	g_assert(!error);
	pg_brick_decref(middle_brick, &error);
	g_assert(!error);
	pg_brick_decref(east_brick, &error);
	g_assert(!error);

	pg_brick_config_free(config);
}