197f17497SC.J. Collier/*-
297f17497SC.J. Collier *   BSD LICENSE
397f17497SC.J. Collier *
497f17497SC.J. Collier *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
597f17497SC.J. Collier *   All rights reserved.
697f17497SC.J. Collier *
797f17497SC.J. Collier *   Redistribution and use in source and binary forms, with or without
897f17497SC.J. Collier *   modification, are permitted provided that the following conditions
997f17497SC.J. Collier *   are met:
1097f17497SC.J. Collier *
1197f17497SC.J. Collier *     * Redistributions of source code must retain the above copyright
1297f17497SC.J. Collier *       notice, this list of conditions and the following disclaimer.
1397f17497SC.J. Collier *     * Redistributions in binary form must reproduce the above copyright
1497f17497SC.J. Collier *       notice, this list of conditions and the following disclaimer in
1597f17497SC.J. Collier *       the documentation and/or other materials provided with the
1697f17497SC.J. Collier *       distribution.
1797f17497SC.J. Collier *     * Neither the name of Intel Corporation nor the names of its
1897f17497SC.J. Collier *       contributors may be used to endorse or promote products derived
1997f17497SC.J. Collier *       from this software without specific prior written permission.
2097f17497SC.J. Collier *
2197f17497SC.J. Collier *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2297f17497SC.J. Collier *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2397f17497SC.J. Collier *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2497f17497SC.J. Collier *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2597f17497SC.J. Collier *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2697f17497SC.J. Collier *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2797f17497SC.J. Collier *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2897f17497SC.J. Collier *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2997f17497SC.J. Collier *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3097f17497SC.J. Collier *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3197f17497SC.J. Collier *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3297f17497SC.J. Collier */
3397f17497SC.J. Collier
3497f17497SC.J. Collier#include "test.h"
3597f17497SC.J. Collier#include "stdio.h"
3697f17497SC.J. Collier
3797f17497SC.J. Collier#include <unistd.h>
3897f17497SC.J. Collier#include <string.h>
3997f17497SC.J. Collier
4097f17497SC.J. Collier#include <rte_cycles.h>
4197f17497SC.J. Collier#include <rte_errno.h>
4297f17497SC.J. Collier#include <rte_mbuf.h>
4397f17497SC.J. Collier#include <rte_reorder.h>
4497f17497SC.J. Collier#include <rte_lcore.h>
4597f17497SC.J. Collier#include <rte_malloc.h>
4697f17497SC.J. Collier
4797f17497SC.J. Collier#include "test.h"
4897f17497SC.J. Collier
4997f17497SC.J. Collier#define BURST 32
5097f17497SC.J. Collier#define REORDER_BUFFER_SIZE 16384
5197f17497SC.J. Collier#define NUM_MBUFS (2*REORDER_BUFFER_SIZE)
5297f17497SC.J. Collier#define REORDER_BUFFER_SIZE_INVALID 2049
5397f17497SC.J. Collier
5497f17497SC.J. Collierstruct reorder_unittest_params {
5597f17497SC.J. Collier	struct rte_mempool *p;
5697f17497SC.J. Collier	struct rte_reorder_buffer *b;
5797f17497SC.J. Collier};
5897f17497SC.J. Collier
5997f17497SC.J. Collierstatic struct reorder_unittest_params default_params  = {
6097f17497SC.J. Collier	.p = NULL,
6197f17497SC.J. Collier	.b = NULL
6297f17497SC.J. Collier};
6397f17497SC.J. Collier
6497f17497SC.J. Collierstatic struct reorder_unittest_params *test_params = &default_params;
6597f17497SC.J. Collier
6697f17497SC.J. Collierstatic int
6797f17497SC.J. Colliertest_reorder_create(void)
6897f17497SC.J. Collier{
6997f17497SC.J. Collier	struct rte_reorder_buffer *b = NULL;
7097f17497SC.J. Collier
7197f17497SC.J. Collier	b = rte_reorder_create(NULL, rte_socket_id(), REORDER_BUFFER_SIZE);
7297f17497SC.J. Collier	TEST_ASSERT((b == NULL) && (rte_errno == EINVAL),
7397f17497SC.J. Collier			"No error on create() with NULL name");
7497f17497SC.J. Collier
7597f17497SC.J. Collier	b = rte_reorder_create("PKT", rte_socket_id(), REORDER_BUFFER_SIZE_INVALID);
7697f17497SC.J. Collier	TEST_ASSERT((b == NULL) && (rte_errno == EINVAL),
7797f17497SC.J. Collier			"No error on create() with invalid buffer size param.");
7897f17497SC.J. Collier
7997f17497SC.J. Collier	b = rte_reorder_create("PKT_RO1", rte_socket_id(), REORDER_BUFFER_SIZE);
8097f17497SC.J. Collier	TEST_ASSERT_EQUAL(b, test_params->b,
8197f17497SC.J. Collier			"New reorder instance created with already existing name");
8297f17497SC.J. Collier
8397f17497SC.J. Collier	return 0;
8497f17497SC.J. Collier}
8597f17497SC.J. Collier
8697f17497SC.J. Collierstatic int
8797f17497SC.J. Colliertest_reorder_init(void)
8897f17497SC.J. Collier{
8997f17497SC.J. Collier	struct rte_reorder_buffer *b = NULL;
9097f17497SC.J. Collier	unsigned int size;
9197f17497SC.J. Collier	/*
9297f17497SC.J. Collier	 * The minimum memory area size that should be passed to library is,
9397f17497SC.J. Collier	 * sizeof(struct rte_reorder_buffer) + (2 * size * sizeof(struct rte_mbuf *));
9497f17497SC.J. Collier	 * Otherwise error will be thrown
9597f17497SC.J. Collier	 */
9697f17497SC.J. Collier
9797f17497SC.J. Collier	size = 100;
9897f17497SC.J. Collier	b = rte_reorder_init(b, size, "PKT1", REORDER_BUFFER_SIZE);
9997f17497SC.J. Collier	TEST_ASSERT((b == NULL) && (rte_errno == EINVAL),
10097f17497SC.J. Collier			"No error on init with NULL buffer.");
10197f17497SC.J. Collier
10297f17497SC.J. Collier	b = rte_malloc(NULL, size, 0);
10397f17497SC.J. Collier	b = rte_reorder_init(b, size, "PKT1", REORDER_BUFFER_SIZE);
10497f17497SC.J. Collier	TEST_ASSERT((b == NULL) && (rte_errno == EINVAL),
10597f17497SC.J. Collier			"No error on init with invalid mem zone size.");
10697f17497SC.J. Collier	rte_free(b);
10797f17497SC.J. Collier
10897f17497SC.J. Collier	size = 262336;
10997f17497SC.J. Collier	b = rte_malloc(NULL, size, 0);
11097f17497SC.J. Collier	b = rte_reorder_init(b, size, "PKT1", REORDER_BUFFER_SIZE_INVALID);
11197f17497SC.J. Collier	TEST_ASSERT((b == NULL) && (rte_errno == EINVAL),
11297f17497SC.J. Collier			"No error on init with invalid buffer size param.");
11397f17497SC.J. Collier
11497f17497SC.J. Collier	b = rte_reorder_init(b, size, NULL, REORDER_BUFFER_SIZE);
11597f17497SC.J. Collier	TEST_ASSERT((b == NULL) && (rte_errno == EINVAL),
11697f17497SC.J. Collier			"No error on init with invalid name.");
11797f17497SC.J. Collier	rte_free(b);
11897f17497SC.J. Collier
11997f17497SC.J. Collier	return 0;
12097f17497SC.J. Collier}
12197f17497SC.J. Collier
12297f17497SC.J. Collierstatic int
12397f17497SC.J. Colliertest_reorder_find_existing(void)
12497f17497SC.J. Collier{
12597f17497SC.J. Collier	struct rte_reorder_buffer *b = NULL;
12697f17497SC.J. Collier
12797f17497SC.J. Collier	/* Try to find existing reorder buffer instance */
12897f17497SC.J. Collier	b = rte_reorder_find_existing("PKT_RO1");
12997f17497SC.J. Collier	TEST_ASSERT_EQUAL(b, test_params->b,
13097f17497SC.J. Collier			"existing reorder buffer instance not found");
13197f17497SC.J. Collier
13297f17497SC.J. Collier	/* Try to find non existing reorder buffer instance */
13397f17497SC.J. Collier	b = rte_reorder_find_existing("ro_find_non_existing");
13497f17497SC.J. Collier	TEST_ASSERT((b == NULL) && (rte_errno == ENOENT),
13597f17497SC.J. Collier			"non existing reorder buffer instance found");
13697f17497SC.J. Collier
13797f17497SC.J. Collier	return 0;
13897f17497SC.J. Collier}
13997f17497SC.J. Collier
14097f17497SC.J. Collierstatic int
14197f17497SC.J. Colliertest_reorder_free(void)
14297f17497SC.J. Collier{
14397f17497SC.J. Collier	struct rte_reorder_buffer *b1 = NULL, *b2 = NULL;
14497f17497SC.J. Collier	const char *name = "test_free";
14597f17497SC.J. Collier
14697f17497SC.J. Collier	b1 = rte_reorder_create(name, rte_socket_id(), 8);
14797f17497SC.J. Collier	TEST_ASSERT_NOT_NULL(b1, "Failed to create reorder buffer.");
14897f17497SC.J. Collier
14997f17497SC.J. Collier	b2 = rte_reorder_find_existing(name);
15097f17497SC.J. Collier	TEST_ASSERT_EQUAL(b1, b2, "Failed to find existing reorder buffer");
15197f17497SC.J. Collier
15297f17497SC.J. Collier	rte_reorder_free(b1);
15397f17497SC.J. Collier
15497f17497SC.J. Collier	b2 = rte_reorder_find_existing(name);
15597f17497SC.J. Collier	TEST_ASSERT((b2 == NULL) && (rte_errno == ENOENT),
15697f17497SC.J. Collier			"Found previously freed reorder buffer");
15797f17497SC.J. Collier
15897f17497SC.J. Collier	return 0;
15997f17497SC.J. Collier}
16097f17497SC.J. Collier
16197f17497SC.J. Collierstatic int
16297f17497SC.J. Colliertest_reorder_insert(void)
16397f17497SC.J. Collier{
16497f17497SC.J. Collier	struct rte_reorder_buffer *b = NULL;
16597f17497SC.J. Collier	struct rte_mempool *p = test_params->p;
16697f17497SC.J. Collier	const unsigned int size = 4;
16797f17497SC.J. Collier	const unsigned int num_bufs = 7;
16897f17497SC.J. Collier	struct rte_mbuf *bufs[num_bufs];
16997f17497SC.J. Collier	int ret = 0;
17097f17497SC.J. Collier	unsigned i;
17197f17497SC.J. Collier
17297f17497SC.J. Collier	/* This would create a reorder buffer instance consisting of:
17397f17497SC.J. Collier	 * reorder_seq = 0
17497f17497SC.J. Collier	 * ready_buf: RB[size] = {NULL, NULL, NULL, NULL}
17597f17497SC.J. Collier	 * order_buf: OB[size] = {NULL, NULL, NULL, NULL}
17697f17497SC.J. Collier	 */
17797f17497SC.J. Collier	b = rte_reorder_create("test_insert", rte_socket_id(), size);
17897f17497SC.J. Collier	TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
17997f17497SC.J. Collier
18043192222SLuca Boccassi	for (i = 0; i < num_bufs; i++) {
18143192222SLuca Boccassi		bufs[i] = rte_pktmbuf_alloc(p);
18243192222SLuca Boccassi		TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
18397f17497SC.J. Collier		bufs[i]->seqn = i;
18443192222SLuca Boccassi	}
18597f17497SC.J. Collier
18697f17497SC.J. Collier	/* This should fill up order buffer:
18797f17497SC.J. Collier	 * reorder_seq = 0
18897f17497SC.J. Collier	 * RB[] = {NULL, NULL, NULL, NULL}
18997f17497SC.J. Collier	 * OB[] = {0, 1, 2, 3}
19097f17497SC.J. Collier	 */
19197f17497SC.J. Collier	for (i = 0; i < size; i++) {
19297f17497SC.J. Collier		ret = rte_reorder_insert(b, bufs[i]);
19397f17497SC.J. Collier		if (ret != 0) {
19497f17497SC.J. Collier			printf("%s:%d: Error inserting packet with seqn less than size\n",
19597f17497SC.J. Collier					__func__, __LINE__);
19697f17497SC.J. Collier			ret = -1;
19797f17497SC.J. Collier			goto exit;
19897f17497SC.J. Collier		}
19943192222SLuca Boccassi		bufs[i] = NULL;
20097f17497SC.J. Collier	}
20197f17497SC.J. Collier
20297f17497SC.J. Collier	/* early packet - should move mbufs to ready buf and move sequence window
20397f17497SC.J. Collier	 * reorder_seq = 4
20497f17497SC.J. Collier	 * RB[] = {0, 1, 2, 3}
20597f17497SC.J. Collier	 * OB[] = {4, NULL, NULL, NULL}
20697f17497SC.J. Collier	 */
20797f17497SC.J. Collier	ret = rte_reorder_insert(b, bufs[4]);
20897f17497SC.J. Collier	if (ret != 0) {
20997f17497SC.J. Collier		printf("%s:%d: Error inserting early packet with seqn: size\n",
21097f17497SC.J. Collier				__func__, __LINE__);
21197f17497SC.J. Collier		ret = -1;
21297f17497SC.J. Collier		goto exit;
21397f17497SC.J. Collier	}
21443192222SLuca Boccassi	bufs[4] = NULL;
21597f17497SC.J. Collier
21697f17497SC.J. Collier	/* early packet from current sequence window - full ready buffer */
21797f17497SC.J. Collier	bufs[5]->seqn = 2 * size;
21897f17497SC.J. Collier	ret = rte_reorder_insert(b, bufs[5]);
21997f17497SC.J. Collier	if (!((ret == -1) && (rte_errno == ENOSPC))) {
22097f17497SC.J. Collier		printf("%s:%d: No error inserting early packet with full ready buffer\n",
22197f17497SC.J. Collier				__func__, __LINE__);
22297f17497SC.J. Collier		ret = -1;
22397f17497SC.J. Collier		goto exit;
22497f17497SC.J. Collier	}
22543192222SLuca Boccassi	bufs[5] = NULL;
22697f17497SC.J. Collier
22797f17497SC.J. Collier	/* late packet */
22897f17497SC.J. Collier	bufs[6]->seqn = 3 * size;
22997f17497SC.J. Collier	ret = rte_reorder_insert(b, bufs[6]);
23097f17497SC.J. Collier	if (!((ret == -1) && (rte_errno == ERANGE))) {
23197f17497SC.J. Collier		printf("%s:%d: No error inserting late packet with seqn:"
23297f17497SC.J. Collier				" 3 * size\n", __func__, __LINE__);
23397f17497SC.J. Collier		ret = -1;
23497f17497SC.J. Collier		goto exit;
23597f17497SC.J. Collier	}
23643192222SLuca Boccassi	bufs[6] = NULL;
23797f17497SC.J. Collier
23897f17497SC.J. Collier	ret = 0;
23997f17497SC.J. Collierexit:
24097f17497SC.J. Collier	rte_reorder_free(b);
24143192222SLuca Boccassi	for (i = 0; i < num_bufs; i++) {
24243192222SLuca Boccassi		if (bufs[i] != NULL)
24343192222SLuca Boccassi			rte_pktmbuf_free(bufs[i]);
24443192222SLuca Boccassi	}
24597f17497SC.J. Collier	return ret;
24697f17497SC.J. Collier}
24797f17497SC.J. Collier
24897f17497SC.J. Collierstatic int
24997f17497SC.J. Colliertest_reorder_drain(void)
25097f17497SC.J. Collier{
25197f17497SC.J. Collier	struct rte_reorder_buffer *b = NULL;
25297f17497SC.J. Collier	struct rte_mempool *p = test_params->p;
25397f17497SC.J. Collier	const unsigned int size = 4;
25497f17497SC.J. Collier	const unsigned int num_bufs = 8;
25597f17497SC.J. Collier	struct rte_mbuf *bufs[num_bufs];
25697f17497SC.J. Collier	struct rte_mbuf *robufs[num_bufs];
25797f17497SC.J. Collier	int ret = 0;
25897f17497SC.J. Collier	unsigned i, cnt;
25997f17497SC.J. Collier
26043192222SLuca Boccassi	/* initialize all robufs to NULL */
26143192222SLuca Boccassi	for (i = 0; i < num_bufs; i++)
26243192222SLuca Boccassi		robufs[i] = NULL;
26343192222SLuca Boccassi
26497f17497SC.J. Collier	/* This would create a reorder buffer instance consisting of:
26597f17497SC.J. Collier	 * reorder_seq = 0
26697f17497SC.J. Collier	 * ready_buf: RB[size] = {NULL, NULL, NULL, NULL}
26797f17497SC.J. Collier	 * order_buf: OB[size] = {NULL, NULL, NULL, NULL}
26897f17497SC.J. Collier	 */
26997f17497SC.J. Collier	b = rte_reorder_create("test_drain", rte_socket_id(), size);
27097f17497SC.J. Collier	TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");
27197f17497SC.J. Collier
27297f17497SC.J. Collier	/* Check no drained packets if reorder is empty */
27397f17497SC.J. Collier	cnt = rte_reorder_drain(b, robufs, 1);
27497f17497SC.J. Collier	if (cnt != 0) {
27597f17497SC.J. Collier		printf("%s:%d: drained packets from empty reorder buffer\n",
27697f17497SC.J. Collier				__func__, __LINE__);
27797f17497SC.J. Collier		ret = -1;
27897f17497SC.J. Collier		goto exit;
27997f17497SC.J. Collier	}
28097f17497SC.J. Collier
28143192222SLuca Boccassi	for (i = 0; i < num_bufs; i++) {
28243192222SLuca Boccassi		bufs[i] = rte_pktmbuf_alloc(p);
28343192222SLuca Boccassi		TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
28497f17497SC.J. Collier		bufs[i]->seqn = i;
28543192222SLuca Boccassi	}
28697f17497SC.J. Collier
28797f17497SC.J. Collier	/* Insert packet with seqn 1:
28897f17497SC.J. Collier	 * reorder_seq = 0
28997f17497SC.J. Collier	 * RB[] = {NULL, NULL, NULL, NULL}
29097f17497SC.J. Collier	 * OB[] = {1, NULL, NULL, NULL}
29197f17497SC.J. Collier	 */
29297f17497SC.J. Collier	rte_reorder_insert(b, bufs[1]);
29343192222SLuca Boccassi	bufs[1] = NULL;
29497f17497SC.J. Collier
29597f17497SC.J. Collier	cnt = rte_reorder_drain(b, robufs, 1);
29697f17497SC.J. Collier	if (cnt != 1) {
29797f17497SC.J. Collier		printf("%s:%d:%d: number of expected packets not drained\n",
29897f17497SC.J. Collier				__func__, __LINE__, cnt);
29997f17497SC.J. Collier		ret = -1;
30097f17497SC.J. Collier		goto exit;
30197f17497SC.J. Collier	}
30243192222SLuca Boccassi	if (robufs[0] != NULL)
303f7a9461eSLuca Boccassi		rte_pktmbuf_free(robufs[0]);
30497f17497SC.J. Collier
30597f17497SC.J. Collier	/* Insert more packets
30697f17497SC.J. Collier	 * RB[] = {NULL, NULL, NULL, NULL}
30797f17497SC.J. Collier	 * OB[] = {NULL, 2, 3, NULL}
30897f17497SC.J. Collier	 */
30997f17497SC.J. Collier	rte_reorder_insert(b, bufs[2]);
31097f17497SC.J. Collier	rte_reorder_insert(b, bufs[3]);
31143192222SLuca Boccassi	bufs[2] = NULL;
31243192222SLuca Boccassi	bufs[3] = NULL;
31397f17497SC.J. Collier
31497f17497SC.J. Collier	/* Insert more packets
31597f17497SC.J. Collier	 * RB[] = {NULL, NULL, NULL, NULL}
31697f17497SC.J. Collier	 * OB[] = {NULL, 2, 3, 4}
31797f17497SC.J. Collier	 */
31897f17497SC.J. Collier	rte_reorder_insert(b, bufs[4]);
31943192222SLuca Boccassi	bufs[4] = NULL;
32097f17497SC.J. Collier
32197f17497SC.J. Collier	/* Insert more packets
32297f17497SC.J. Collier	 * RB[] = {2, 3, 4, NULL}
32397f17497SC.J. Collier	 * OB[] = {NULL, NULL, 7, NULL}
32497f17497SC.J. Collier	 */
32597f17497SC.J. Collier	rte_reorder_insert(b, bufs[7]);
32643192222SLuca Boccassi	bufs[7] = NULL;
32797f17497SC.J. Collier
32897f17497SC.J. Collier	/* drained expected packets */
32997f17497SC.J. Collier	cnt = rte_reorder_drain(b, robufs, 4);
33097f17497SC.J. Collier	if (cnt != 3) {
33197f17497SC.J. Collier		printf("%s:%d:%d: number of expected packets not drained\n",
33297f17497SC.J. Collier				__func__, __LINE__, cnt);
33397f17497SC.J. Collier		ret = -1;
33497f17497SC.J. Collier		goto exit;
33597f17497SC.J. Collier	}
33643192222SLuca Boccassi	for (i = 0; i < 3; i++) {
33743192222SLuca Boccassi		if (robufs[i] != NULL)
33843192222SLuca Boccassi			rte_pktmbuf_free(robufs[i]);
33943192222SLuca Boccassi	}
34097f17497SC.J. Collier
34197f17497SC.J. Collier	/*
34297f17497SC.J. Collier	 * RB[] = {NULL, NULL, NULL, NULL}
34397f17497SC.J. Collier	 * OB[] = {NULL, NULL, 7, NULL}
34497f17497SC.J. Collier	 */
34597f17497SC.J. Collier	cnt = rte_reorder_drain(b, robufs, 1);
34697f17497SC.J. Collier	if (cnt != 0) {
34797f17497SC.J. Collier		printf("%s:%d:%d: number of expected packets not drained\n",
34897f17497SC.J. Collier				__func__, __LINE__, cnt);
34997f17497SC.J. Collier		ret = -1;
35097f17497SC.J. Collier		goto exit;
35197f17497SC.J. Collier	}
35297f17497SC.J. Collier	ret = 0;
35397f17497SC.J. Collierexit:
35497f17497SC.J. Collier	rte_reorder_free(b);
35543192222SLuca Boccassi	for (i = 0; i < num_bufs; i++) {
35643192222SLuca Boccassi		if (bufs[i] != NULL)
35743192222SLuca Boccassi			rte_pktmbuf_free(bufs[i]);
35843192222SLuca Boccassi		if (robufs[i] != NULL)
35943192222SLuca Boccassi			rte_pktmbuf_free(robufs[i]);
36043192222SLuca Boccassi	}
36197f17497SC.J. Collier	return ret;
36297f17497SC.J. Collier}
36397f17497SC.J. Collier
36497f17497SC.J. Collierstatic int
36597f17497SC.J. Colliertest_setup(void)
36697f17497SC.J. Collier{
36797f17497SC.J. Collier	/* reorder buffer instance creation */
36897f17497SC.J. Collier	if (test_params->b == NULL) {
36997f17497SC.J. Collier		test_params->b = rte_reorder_create("PKT_RO1", rte_socket_id(),
37097f17497SC.J. Collier							REORDER_BUFFER_SIZE);
37197f17497SC.J. Collier		if (test_params->b == NULL) {
37297f17497SC.J. Collier			printf("%s: Error creating reorder buffer instance b\n",
37397f17497SC.J. Collier					__func__);
37497f17497SC.J. Collier			return -1;
37597f17497SC.J. Collier		}
37697f17497SC.J. Collier	} else
37797f17497SC.J. Collier		rte_reorder_reset(test_params->b);
37897f17497SC.J. Collier
37997f17497SC.J. Collier	/* mempool creation */
38097f17497SC.J. Collier	if (test_params->p == NULL) {
38197f17497SC.J. Collier		test_params->p = rte_pktmbuf_pool_create("RO_MBUF_POOL",
38297f17497SC.J. Collier			NUM_MBUFS, BURST, 0, RTE_MBUF_DEFAULT_BUF_SIZE,
38397f17497SC.J. Collier			rte_socket_id());
38497f17497SC.J. Collier		if (test_params->p == NULL) {
38597f17497SC.J. Collier			printf("%s: Error creating mempool\n", __func__);
38697f17497SC.J. Collier			return -1;
38797f17497SC.J. Collier		}
38897f17497SC.J. Collier	}
38997f17497SC.J. Collier	return 0;
39097f17497SC.J. Collier}
39197f17497SC.J. Collier
39239157ec0SLuca Boccassistatic void
39339157ec0SLuca Boccassitest_teardown(void)
39439157ec0SLuca Boccassi{
39539157ec0SLuca Boccassi	rte_reorder_free(test_params->b);
39639157ec0SLuca Boccassi	test_params->b = NULL;
39739157ec0SLuca Boccassi	rte_mempool_free(test_params->p);
39839157ec0SLuca Boccassi	test_params->p = NULL;
39939157ec0SLuca Boccassi}
40039157ec0SLuca Boccassi
40139157ec0SLuca Boccassi
40297f17497SC.J. Collierstatic struct unit_test_suite reorder_test_suite  = {
40397f17497SC.J. Collier
40497f17497SC.J. Collier	.setup = test_setup,
40539157ec0SLuca Boccassi	.teardown = test_teardown,
40697f17497SC.J. Collier	.suite_name = "Reorder Unit Test Suite",
40797f17497SC.J. Collier	.unit_test_cases = {
40897f17497SC.J. Collier		TEST_CASE(test_reorder_create),
40997f17497SC.J. Collier		TEST_CASE(test_reorder_init),
41097f17497SC.J. Collier		TEST_CASE(test_reorder_find_existing),
41197f17497SC.J. Collier		TEST_CASE(test_reorder_free),
41297f17497SC.J. Collier		TEST_CASE(test_reorder_insert),
41397f17497SC.J. Collier		TEST_CASE(test_reorder_drain),
41497f17497SC.J. Collier		TEST_CASES_END()
41597f17497SC.J. Collier	}
41697f17497SC.J. Collier};
41797f17497SC.J. Collier
41897f17497SC.J. Collierstatic int
41997f17497SC.J. Colliertest_reorder(void)
42097f17497SC.J. Collier{
42197f17497SC.J. Collier	return unit_test_suite_runner(&reorder_test_suite);
42297f17497SC.J. Collier}
42397f17497SC.J. Collier
4245d4e5dcdSRicardo SalvetiREGISTER_TEST_COMMAND(reorder_autotest, test_reorder);
425