aboutsummaryrefslogtreecommitdiff
path: root/test/validation/classification/odp_classification_basic.c
blob: 99202eefc356998479d65713fe6f43d8570d9965 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* Copyright (c) 2015, Linaro Limited
 * All rights reserved.
 *
 * SPDX-License-Identifier:	BSD-3-Clause
 */

#include "odp_classification_testsuites.h"

#define PMR_SET_NUM	5

static void classification_test_create_cos(void)
{
	odp_cos_t cos;
	char name[ODP_COS_NAME_LEN];
	sprintf(name, "ClassOfService");
	cos = odp_cos_create(name);
	CU_ASSERT_FATAL(cos != ODP_COS_INVALID);
	CU_ASSERT(odp_cos_to_u64(cos) != odp_cos_to_u64(ODP_COS_INVALID));
	odp_cos_destroy(cos);
}

static void classification_test_destroy_cos(void)
{
	odp_cos_t cos;
	char name[ODP_COS_NAME_LEN];
	int retval;
	sprintf(name, "ClassOfService");
	cos = odp_cos_create(name);
	CU_ASSERT_FATAL(cos != ODP_COS_INVALID);
	retval = odp_cos_destroy(cos);
	CU_ASSERT(retval == 0);
	retval = odp_cos_destroy(ODP_COS_INVALID);
	CU_ASSERT(retval < 0);
}

static void classification_test_create_pmr_match(void)
{
	odp_pmr_t pmr;
	uint16_t val;
	uint16_t mask;
	val = 1024;
	mask = 0xffff;
	pmr = odp_pmr_create(ODP_PMR_TCP_SPORT, &val, &mask, sizeof(val));
	CU_ASSERT(pmr != ODP_PMR_INVAL);
	CU_ASSERT(odp_pmr_to_u64(pmr) != odp_pmr_to_u64(ODP_PMR_INVAL));
	odp_pmr_destroy(pmr);
}

static void classification_test_destroy_pmr(void)
{
	odp_pmr_t pmr;
	uint16_t val;
	uint16_t mask;
	int retval;
	val = 1024;
	mask = 0xffff;
	pmr = odp_pmr_create(ODP_PMR_TCP_SPORT, &val, &mask, sizeof(val));
	retval = odp_pmr_destroy(pmr);
	CU_ASSERT(retval == 0);
	retval = odp_pmr_destroy(ODP_PMR_INVAL);
	retval = odp_pmr_destroy(ODP_PMR_INVAL);
	CU_ASSERT(retval < 0);
}

static void classification_test_cos_set_queue(void)
{
	int retval;
	char cosname[ODP_COS_NAME_LEN];
	char queuename[ODP_QUEUE_NAME_LEN];
	odp_queue_param_t qparam;
	odp_queue_t queue_cos;
	odp_cos_t cos_queue;
	sprintf(cosname, "CoSQueue");
	cos_queue = odp_cos_create(cosname);
	CU_ASSERT_FATAL(cos_queue != ODP_COS_INVALID);

	qparam.sched.prio = ODP_SCHED_PRIO_HIGHEST;
	qparam.sched.sync = ODP_SCHED_SYNC_NONE;
	qparam.sched.group = ODP_SCHED_GROUP_ALL;
	sprintf(queuename, "%s", "QueueCoS");

	queue_cos = odp_queue_create(queuename,
				     ODP_QUEUE_TYPE_SCHED, &qparam);
	retval = odp_cos_set_queue(cos_queue, queue_cos);
	CU_ASSERT(retval == 0);
	odp_cos_destroy(cos_queue);
	odp_queue_destroy(queue_cos);
}

static void classification_test_cos_set_drop(void)
{
	int retval;
	char cosname[ODP_COS_NAME_LEN];
	sprintf(cosname, "CoSDrop");
	odp_cos_t cos_drop;
	cos_drop = odp_cos_create(cosname);
	CU_ASSERT_FATAL(cos_drop != ODP_COS_INVALID);

	retval = odp_cos_set_drop(cos_drop, ODP_COS_DROP_POOL);
	CU_ASSERT(retval == 0);
	retval = odp_cos_set_drop(cos_drop, ODP_COS_DROP_NEVER);
	CU_ASSERT(retval == 0);
	odp_cos_destroy(cos_drop);
}

static void classification_test_pmr_match_set_create(void)
{
	odp_pmr_set_t pmr_set;
	int retval;
	odp_pmr_match_t pmr_terms[PMR_SET_NUM];
	uint16_t val = 1024;
	uint16_t mask = 0xffff;
	int i;
	for (i = 0; i < PMR_SET_NUM; i++) {
		pmr_terms[i].term = ODP_PMR_TCP_DPORT;
		pmr_terms[i].val = &val;
		pmr_terms[i].mask = &mask;
		pmr_terms[i].val_sz = sizeof(val);
	}

	retval = odp_pmr_match_set_create(PMR_SET_NUM, pmr_terms, &pmr_set);
	CU_ASSERT(retval > 0);
	CU_ASSERT(odp_pmr_set_to_u64(pmr_set) !=
		  odp_pmr_set_to_u64(ODP_PMR_SET_INVAL));

	retval = odp_pmr_match_set_destroy(pmr_set);
	CU_ASSERT(retval == 0);
}

static void classification_test_pmr_match_set_destroy(void)
{
	odp_pmr_set_t pmr_set;
	int retval;
	odp_pmr_match_t pmr_terms[PMR_SET_NUM];
	uint16_t val = 1024;
	uint16_t mask = 0xffff;
	int i;

	retval = odp_pmr_match_set_destroy(ODP_PMR_SET_INVAL);
	CU_ASSERT(retval < 0);

	for (i = 0; i < PMR_SET_NUM; i++) {
		pmr_terms[i].term = ODP_PMR_TCP_DPORT;
		pmr_terms[i].val = &val;
		pmr_terms[i].mask = &mask;
		pmr_terms[i].val_sz = sizeof(val);
	}

	retval = odp_pmr_match_set_create(PMR_SET_NUM, pmr_terms, &pmr_set);
	CU_ASSERT(retval > 0);

	retval = odp_pmr_match_set_destroy(pmr_set);
	CU_ASSERT(retval == 0);
}

CU_TestInfo classification_suite_basic[] = {
	_CU_TEST_INFO(classification_test_create_cos),
	_CU_TEST_INFO(classification_test_destroy_cos),
	_CU_TEST_INFO(classification_test_create_pmr_match),
	_CU_TEST_INFO(classification_test_destroy_pmr),
	_CU_TEST_INFO(classification_test_cos_set_queue),
	_CU_TEST_INFO(classification_test_cos_set_drop),
	_CU_TEST_INFO(classification_test_pmr_match_set_create),
	_CU_TEST_INFO(classification_test_pmr_match_set_destroy),
	CU_TEST_INFO_NULL,
};