xref: /dpdk/app/test/test_meter.c (revision e0a8442ccd15bafbb7eb150c35331c8e3b828c53)
1a9de470cSBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2a9de470cSBruce Richardson  * Copyright(c) 2010-2014 Intel Corporation
3a9de470cSBruce Richardson  */
4a9de470cSBruce Richardson 
5a9de470cSBruce Richardson #include <stdlib.h>
6a9de470cSBruce Richardson #include <stdio.h>
7a9de470cSBruce Richardson #include <string.h>
8a9de470cSBruce Richardson #include <stdint.h>
9a9de470cSBruce Richardson #include <unistd.h>
10a9de470cSBruce Richardson 
11a9de470cSBruce Richardson #include "test.h"
12a9de470cSBruce Richardson 
13a9de470cSBruce Richardson #include <rte_cycles.h>
14a9de470cSBruce Richardson #include <rte_meter.h>
15a9de470cSBruce Richardson 
16a9de470cSBruce Richardson #define mlog(format, ...) do{\
17a9de470cSBruce Richardson 		printf("Line %d:",__LINE__);\
18a9de470cSBruce Richardson 		printf(format, ##__VA_ARGS__);\
19a9de470cSBruce Richardson 		printf("\n");\
20a9de470cSBruce Richardson 	}while(0);
21a9de470cSBruce Richardson 
22a9de470cSBruce Richardson #define melog(format, ...) do{\
23a9de470cSBruce Richardson 		printf("Line %d:",__LINE__);\
24a9de470cSBruce Richardson 		printf(format, ##__VA_ARGS__);\
25a9de470cSBruce Richardson 		printf(" failed!\n");\
26a9de470cSBruce Richardson 		return -1;\
27a9de470cSBruce Richardson 	}while(0);
28a9de470cSBruce Richardson 
29a9de470cSBruce Richardson #define TM_TEST_SRTCM_CIR_DF 46000000
30a9de470cSBruce Richardson #define TM_TEST_SRTCM_CBS_DF 2048
31a9de470cSBruce Richardson #define TM_TEST_SRTCM_EBS_DF 4096
32a9de470cSBruce Richardson 
33a9de470cSBruce Richardson #define TM_TEST_TRTCM_CIR_DF 46000000
34a9de470cSBruce Richardson #define TM_TEST_TRTCM_PIR_DF 69000000
35a9de470cSBruce Richardson #define TM_TEST_TRTCM_EIR_DF 69000000
36a9de470cSBruce Richardson #define TM_TEST_TRTCM_CBS_DF 2048
37a9de470cSBruce Richardson #define TM_TEST_TRTCM_PBS_DF 4096
38a9de470cSBruce Richardson #define TM_TEST_TRTCM_EBS_DF 4096
39a9de470cSBruce Richardson 
40a9de470cSBruce Richardson static struct rte_meter_srtcm_params sparams =
41a9de470cSBruce Richardson 				{.cir = TM_TEST_SRTCM_CIR_DF,
42a9de470cSBruce Richardson 				 .cbs = TM_TEST_SRTCM_CBS_DF,
43a9de470cSBruce Richardson 				 .ebs = TM_TEST_SRTCM_EBS_DF,};
44a9de470cSBruce Richardson 
45a9de470cSBruce Richardson static struct	rte_meter_trtcm_params tparams=
46a9de470cSBruce Richardson 				{.cir = TM_TEST_TRTCM_CIR_DF,
47a9de470cSBruce Richardson 				 .pir = TM_TEST_TRTCM_PIR_DF,
48a9de470cSBruce Richardson 				 .cbs = TM_TEST_TRTCM_CBS_DF,
49a9de470cSBruce Richardson 				 .pbs = TM_TEST_TRTCM_PBS_DF,};
50a9de470cSBruce Richardson 
51a9de470cSBruce Richardson static struct rte_meter_trtcm_rfc4115_params rfc4115params =
52a9de470cSBruce Richardson 				{.cir = TM_TEST_TRTCM_CIR_DF,
53a9de470cSBruce Richardson 				 .eir = TM_TEST_TRTCM_EIR_DF,
54a9de470cSBruce Richardson 				 .cbs = TM_TEST_TRTCM_CBS_DF,
55a9de470cSBruce Richardson 				 .ebs = TM_TEST_TRTCM_EBS_DF,};
56a9de470cSBruce Richardson 
57a9de470cSBruce Richardson /**
58a9de470cSBruce Richardson  * functional test for rte_meter_srtcm_config
59a9de470cSBruce Richardson  */
60a9de470cSBruce Richardson static inline int
tm_test_srtcm_config(void)61a9de470cSBruce Richardson tm_test_srtcm_config(void)
62a9de470cSBruce Richardson {
63a9de470cSBruce Richardson #define SRTCM_CFG_MSG "srtcm_config"
64a9de470cSBruce Richardson 	struct rte_meter_srtcm_profile sp;
65a9de470cSBruce Richardson 	struct  rte_meter_srtcm_params sparams1;
66a9de470cSBruce Richardson 
67a9de470cSBruce Richardson 	/* invalid parameter test */
68a9de470cSBruce Richardson 	if (rte_meter_srtcm_profile_config(NULL, NULL) == 0)
69a9de470cSBruce Richardson 		melog(SRTCM_CFG_MSG);
70a9de470cSBruce Richardson 	if (rte_meter_srtcm_profile_config(&sp, NULL) == 0)
71a9de470cSBruce Richardson 		melog(SRTCM_CFG_MSG);
72a9de470cSBruce Richardson 	if (rte_meter_srtcm_profile_config(NULL, &sparams) == 0)
73a9de470cSBruce Richardson 		melog(SRTCM_CFG_MSG);
74a9de470cSBruce Richardson 
75a9de470cSBruce Richardson 	/* cbs and ebs can't both be zero */
76a9de470cSBruce Richardson 	sparams1 = sparams;
77a9de470cSBruce Richardson 	sparams1.cbs = 0;
78a9de470cSBruce Richardson 	sparams1.ebs = 0;
79a9de470cSBruce Richardson 	if (rte_meter_srtcm_profile_config(&sp, &sparams1) == 0)
80a9de470cSBruce Richardson 		melog(SRTCM_CFG_MSG);
81a9de470cSBruce Richardson 
82a9de470cSBruce Richardson 	/* cir should never be 0 */
83a9de470cSBruce Richardson 	sparams1 = sparams;
84a9de470cSBruce Richardson 	sparams1.cir = 0;
85a9de470cSBruce Richardson 	if (rte_meter_srtcm_profile_config(&sp, &sparams1) == 0)
86a9de470cSBruce Richardson 		melog(SRTCM_CFG_MSG);
87a9de470cSBruce Richardson 
88a9de470cSBruce Richardson 	/* one of ebs and cbs can be zero, should be successful */
89a9de470cSBruce Richardson 	sparams1 = sparams;
90a9de470cSBruce Richardson 	sparams1.ebs = 0;
91a9de470cSBruce Richardson 	if (rte_meter_srtcm_profile_config(&sp, &sparams1) != 0)
92a9de470cSBruce Richardson 		melog(SRTCM_CFG_MSG);
93a9de470cSBruce Richardson 
94a9de470cSBruce Richardson 	sparams1 = sparams;
95a9de470cSBruce Richardson 	sparams1.cbs = 0;
96a9de470cSBruce Richardson 	if (rte_meter_srtcm_profile_config(&sp, &sparams1) != 0)
97a9de470cSBruce Richardson 		melog(SRTCM_CFG_MSG);
98a9de470cSBruce Richardson 
99a9de470cSBruce Richardson 	/* usual parameter, should be successful */
100a9de470cSBruce Richardson 	if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
101a9de470cSBruce Richardson 		melog(SRTCM_CFG_MSG);
102a9de470cSBruce Richardson 
103a9de470cSBruce Richardson 	return 0;
104a9de470cSBruce Richardson 
105a9de470cSBruce Richardson }
106a9de470cSBruce Richardson 
107a9de470cSBruce Richardson /**
108a9de470cSBruce Richardson  * functional test for rte_meter_trtcm_config
109a9de470cSBruce Richardson  */
110a9de470cSBruce Richardson static inline int
tm_test_trtcm_config(void)111a9de470cSBruce Richardson tm_test_trtcm_config(void)
112a9de470cSBruce Richardson {
113a9de470cSBruce Richardson 	struct rte_meter_trtcm_profile tp;
114a9de470cSBruce Richardson 	struct  rte_meter_trtcm_params tparams1;
115a9de470cSBruce Richardson #define TRTCM_CFG_MSG "trtcm_config"
116a9de470cSBruce Richardson 
117a9de470cSBruce Richardson 	/* invalid parameter test */
118a9de470cSBruce Richardson 	if (rte_meter_trtcm_profile_config(NULL, NULL) == 0)
119a9de470cSBruce Richardson 		melog(TRTCM_CFG_MSG);
120a9de470cSBruce Richardson 	if (rte_meter_trtcm_profile_config(&tp, NULL) == 0)
121a9de470cSBruce Richardson 		melog(TRTCM_CFG_MSG);
122a9de470cSBruce Richardson 	if (rte_meter_trtcm_profile_config(NULL, &tparams) == 0)
123a9de470cSBruce Richardson 		melog(TRTCM_CFG_MSG);
124a9de470cSBruce Richardson 
125a9de470cSBruce Richardson 	/* cir, cbs, pir and pbs never be zero */
126a9de470cSBruce Richardson 	tparams1 = tparams;
127a9de470cSBruce Richardson 	tparams1.cir = 0;
128a9de470cSBruce Richardson 	if (rte_meter_trtcm_profile_config(&tp, &tparams1) == 0)
129a9de470cSBruce Richardson 		melog(TRTCM_CFG_MSG);
130a9de470cSBruce Richardson 
131a9de470cSBruce Richardson 	tparams1 = tparams;
132a9de470cSBruce Richardson 	tparams1.cbs = 0;
133a9de470cSBruce Richardson 	if (rte_meter_trtcm_profile_config(&tp, &tparams1) == 0)
134a9de470cSBruce Richardson 		melog(TRTCM_CFG_MSG);
135a9de470cSBruce Richardson 
136a9de470cSBruce Richardson 	tparams1 = tparams;
137a9de470cSBruce Richardson 	tparams1.pbs = 0;
138a9de470cSBruce Richardson 	if (rte_meter_trtcm_profile_config(&tp, &tparams1) == 0)
139a9de470cSBruce Richardson 		melog(TRTCM_CFG_MSG);
140a9de470cSBruce Richardson 
141a9de470cSBruce Richardson 	tparams1 = tparams;
142a9de470cSBruce Richardson 	tparams1.pir = 0;
143a9de470cSBruce Richardson 	if (rte_meter_trtcm_profile_config(&tp, &tparams1) == 0)
144a9de470cSBruce Richardson 		melog(TRTCM_CFG_MSG);
145a9de470cSBruce Richardson 
146a9de470cSBruce Richardson 	/* pir should be greater or equal to cir */
147a9de470cSBruce Richardson 	tparams1 = tparams;
148a9de470cSBruce Richardson 	tparams1.pir = tparams1.cir - 1;
149a9de470cSBruce Richardson 	if (rte_meter_trtcm_profile_config(&tp, &tparams1) == 0)
150a9de470cSBruce Richardson 		melog(TRTCM_CFG_MSG" pir < cir test");
151a9de470cSBruce Richardson 
152a9de470cSBruce Richardson 	/* usual parameter, should be successful */
153a9de470cSBruce Richardson 	if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
154a9de470cSBruce Richardson 		melog(TRTCM_CFG_MSG);
155a9de470cSBruce Richardson 
156a9de470cSBruce Richardson 	return 0;
157a9de470cSBruce Richardson }
158a9de470cSBruce Richardson 
159a9de470cSBruce Richardson /**
160a9de470cSBruce Richardson  * functional test for rte_meter_trtcm_rfc4115_config
161a9de470cSBruce Richardson  */
162a9de470cSBruce Richardson static inline int
tm_test_trtcm_rfc4115_config(void)163a9de470cSBruce Richardson tm_test_trtcm_rfc4115_config(void)
164a9de470cSBruce Richardson {
165a9de470cSBruce Richardson 	struct rte_meter_trtcm_rfc4115_profile tp;
166a9de470cSBruce Richardson 	struct  rte_meter_trtcm_rfc4115_params rfc4115params1;
167a9de470cSBruce Richardson #define TRTCM_RFC4115_CFG_MSG "trtcm_rfc4115_config"
168a9de470cSBruce Richardson 
169a9de470cSBruce Richardson 	/* invalid parameter test */
170a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_profile_config(NULL, NULL) == 0)
171a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_CFG_MSG);
172a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_profile_config(&tp, NULL) == 0)
173a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_CFG_MSG);
174a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_profile_config(NULL, &rfc4115params) == 0)
175a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_CFG_MSG);
176a9de470cSBruce Richardson 
177a9de470cSBruce Richardson 	/*
178a9de470cSBruce Richardson 	 * cbs and pbs should be none-zero if cir and eir are none-zero
179a9de470cSBruce Richardson 	 * respectively
180a9de470cSBruce Richardson 	 */
181a9de470cSBruce Richardson 	rfc4115params1 = rfc4115params;
182a9de470cSBruce Richardson 	rfc4115params1.cbs = 0;
183a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params1) == 0)
184a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_CFG_MSG);
185a9de470cSBruce Richardson 
186a9de470cSBruce Richardson 	rfc4115params1 = rfc4115params;
187a9de470cSBruce Richardson 	rfc4115params1.ebs = 0;
188a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params1) == 0)
189a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_CFG_MSG);
190a9de470cSBruce Richardson 
191a9de470cSBruce Richardson 	/* usual parameter, should be successful */
192a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
193a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_CFG_MSG);
194a9de470cSBruce Richardson 
195a9de470cSBruce Richardson 	return 0;
196a9de470cSBruce Richardson }
197a9de470cSBruce Richardson 
198a9de470cSBruce Richardson /**
199a9de470cSBruce Richardson  * functional test for rte_meter_srtcm_color_blind_check
200a9de470cSBruce Richardson  */
201a9de470cSBruce Richardson static inline int
tm_test_srtcm_color_blind_check(void)202a9de470cSBruce Richardson tm_test_srtcm_color_blind_check(void)
203a9de470cSBruce Richardson {
204a9de470cSBruce Richardson #define SRTCM_BLIND_CHECK_MSG "srtcm_blind_check"
205a9de470cSBruce Richardson 	struct rte_meter_srtcm_profile sp;
206a9de470cSBruce Richardson 	struct rte_meter_srtcm sm;
207a9de470cSBruce Richardson 	uint64_t time;
208a9de470cSBruce Richardson 	uint64_t hz = rte_get_tsc_hz();
209a9de470cSBruce Richardson 
210a9de470cSBruce Richardson 	/* Test green */
211a9de470cSBruce Richardson 	if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
212a9de470cSBruce Richardson 		melog(SRTCM_BLIND_CHECK_MSG);
213a9de470cSBruce Richardson 	if (rte_meter_srtcm_config(&sm, &sp) != 0)
214a9de470cSBruce Richardson 		melog(SRTCM_BLIND_CHECK_MSG);
215a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
216a9de470cSBruce Richardson 	if (rte_meter_srtcm_color_blind_check(
217a9de470cSBruce Richardson 		&sm, &sp, time, TM_TEST_SRTCM_CBS_DF - 1)
218c1656328SJasvinder Singh 		!= RTE_COLOR_GREEN)
219a9de470cSBruce Richardson 		melog(SRTCM_BLIND_CHECK_MSG" GREEN");
220a9de470cSBruce Richardson 
221a9de470cSBruce Richardson 	/* Test yellow */
222a9de470cSBruce Richardson 	if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
223a9de470cSBruce Richardson 		melog(SRTCM_BLIND_CHECK_MSG);
224a9de470cSBruce Richardson 	if (rte_meter_srtcm_config(&sm, &sp) != 0)
225a9de470cSBruce Richardson 		melog(SRTCM_BLIND_CHECK_MSG);
226a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
227a9de470cSBruce Richardson 	if (rte_meter_srtcm_color_blind_check(
228a9de470cSBruce Richardson 		&sm, &sp, time, TM_TEST_SRTCM_CBS_DF + 1)
229c1656328SJasvinder Singh 		!= RTE_COLOR_YELLOW)
230a9de470cSBruce Richardson 		melog(SRTCM_BLIND_CHECK_MSG" YELLOW");
231a9de470cSBruce Richardson 
232a9de470cSBruce Richardson 	if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
233a9de470cSBruce Richardson 		melog(SRTCM_BLIND_CHECK_MSG);
234a9de470cSBruce Richardson 	if (rte_meter_srtcm_config(&sm, &sp) != 0)
235a9de470cSBruce Richardson 		melog(SRTCM_BLIND_CHECK_MSG);
236a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
237a9de470cSBruce Richardson 	if (rte_meter_srtcm_color_blind_check(
238c1656328SJasvinder Singh 		&sm, &sp, time, (uint32_t)sp.ebs - 1) != RTE_COLOR_YELLOW)
239a9de470cSBruce Richardson 		melog(SRTCM_BLIND_CHECK_MSG" YELLOW");
240a9de470cSBruce Richardson 
241a9de470cSBruce Richardson 	/* Test red */
242a9de470cSBruce Richardson 	if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
243a9de470cSBruce Richardson 		melog(SRTCM_BLIND_CHECK_MSG);
244a9de470cSBruce Richardson 	if (rte_meter_srtcm_config(&sm, &sp) != 0)
245a9de470cSBruce Richardson 		melog(SRTCM_BLIND_CHECK_MSG);
246a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
247a9de470cSBruce Richardson 	if (rte_meter_srtcm_color_blind_check(
248a9de470cSBruce Richardson 		&sm, &sp, time, TM_TEST_SRTCM_EBS_DF + 1)
249c1656328SJasvinder Singh 		!= RTE_COLOR_RED)
250a9de470cSBruce Richardson 		melog(SRTCM_BLIND_CHECK_MSG" RED");
251a9de470cSBruce Richardson 
252a9de470cSBruce Richardson 	return 0;
253a9de470cSBruce Richardson 
254a9de470cSBruce Richardson }
255a9de470cSBruce Richardson 
256a9de470cSBruce Richardson /**
257a9de470cSBruce Richardson  * functional test for rte_meter_trtcm_color_blind_check
258a9de470cSBruce Richardson  */
259a9de470cSBruce Richardson static inline int
tm_test_trtcm_color_blind_check(void)260a9de470cSBruce Richardson tm_test_trtcm_color_blind_check(void)
261a9de470cSBruce Richardson {
262a9de470cSBruce Richardson #define TRTCM_BLIND_CHECK_MSG "trtcm_blind_check"
263a9de470cSBruce Richardson 
264a9de470cSBruce Richardson 	uint64_t time;
265a9de470cSBruce Richardson 	struct rte_meter_trtcm_profile tp;
266a9de470cSBruce Richardson 	struct rte_meter_trtcm tm;
267a9de470cSBruce Richardson 	uint64_t hz = rte_get_tsc_hz();
268a9de470cSBruce Richardson 
269a9de470cSBruce Richardson 	/* Test green */
270a9de470cSBruce Richardson 	if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
271a9de470cSBruce Richardson 		melog(TRTCM_BLIND_CHECK_MSG);
272a9de470cSBruce Richardson 	if (rte_meter_trtcm_config(&tm, &tp) != 0)
273a9de470cSBruce Richardson 		melog(TRTCM_BLIND_CHECK_MSG);
274a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
275a9de470cSBruce Richardson 	if (rte_meter_trtcm_color_blind_check(
276a9de470cSBruce Richardson 		&tm, &tp, time, TM_TEST_TRTCM_CBS_DF - 1)
277c1656328SJasvinder Singh 		!= RTE_COLOR_GREEN)
278a9de470cSBruce Richardson 		melog(TRTCM_BLIND_CHECK_MSG" GREEN");
279a9de470cSBruce Richardson 
280a9de470cSBruce Richardson 	/* Test yellow */
281a9de470cSBruce Richardson 	if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
282a9de470cSBruce Richardson 		melog(TRTCM_BLIND_CHECK_MSG);
283a9de470cSBruce Richardson 	if (rte_meter_trtcm_config(&tm, &tp) != 0)
284a9de470cSBruce Richardson 		melog(TRTCM_BLIND_CHECK_MSG);
285a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
286a9de470cSBruce Richardson 	if (rte_meter_trtcm_color_blind_check(
287a9de470cSBruce Richardson 		&tm, &tp, time, TM_TEST_TRTCM_CBS_DF + 1)
288c1656328SJasvinder Singh 		!= RTE_COLOR_YELLOW)
289a9de470cSBruce Richardson 		melog(TRTCM_BLIND_CHECK_MSG" YELLOW");
290a9de470cSBruce Richardson 
291a9de470cSBruce Richardson 	if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
292a9de470cSBruce Richardson 		melog(TRTCM_BLIND_CHECK_MSG);
293a9de470cSBruce Richardson 	if (rte_meter_trtcm_config(&tm, &tp) != 0)
294a9de470cSBruce Richardson 		melog(TRTCM_BLIND_CHECK_MSG);
295a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
296a9de470cSBruce Richardson 	if (rte_meter_trtcm_color_blind_check(
297a9de470cSBruce Richardson 		&tm, &tp, time, TM_TEST_TRTCM_PBS_DF - 1)
298c1656328SJasvinder Singh 		!= RTE_COLOR_YELLOW)
299a9de470cSBruce Richardson 		melog(TRTCM_BLIND_CHECK_MSG" YELLOW");
300a9de470cSBruce Richardson 
301a9de470cSBruce Richardson 	/* Test red */
302a9de470cSBruce Richardson 	if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
303a9de470cSBruce Richardson 		melog(TRTCM_BLIND_CHECK_MSG);
304a9de470cSBruce Richardson 	if (rte_meter_trtcm_config(&tm, &tp) != 0)
305a9de470cSBruce Richardson 		melog(TRTCM_BLIND_CHECK_MSG);
306a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
307a9de470cSBruce Richardson 	if (rte_meter_trtcm_color_blind_check(
308a9de470cSBruce Richardson 		&tm, &tp, time, TM_TEST_TRTCM_PBS_DF + 1)
309c1656328SJasvinder Singh 		!= RTE_COLOR_RED)
310a9de470cSBruce Richardson 		melog(TRTCM_BLIND_CHECK_MSG" RED");
311a9de470cSBruce Richardson 
312a9de470cSBruce Richardson 	return 0;
313a9de470cSBruce Richardson }
314a9de470cSBruce Richardson 
315a9de470cSBruce Richardson /**
316a9de470cSBruce Richardson  * functional test for rte_meter_trtcm_rfc4115_color_blind_check
317a9de470cSBruce Richardson  */
318a9de470cSBruce Richardson static inline int
tm_test_trtcm_rfc4115_color_blind_check(void)319a9de470cSBruce Richardson tm_test_trtcm_rfc4115_color_blind_check(void)
320a9de470cSBruce Richardson {
321a9de470cSBruce Richardson #define TRTCM_RFC4115_BLIND_CHECK_MSG "trtcm_rfc4115_blind_check"
322a9de470cSBruce Richardson 
323a9de470cSBruce Richardson 	uint64_t time;
324a9de470cSBruce Richardson 	struct rte_meter_trtcm_rfc4115_profile tp;
325a9de470cSBruce Richardson 	struct rte_meter_trtcm_rfc4115 tm;
326a9de470cSBruce Richardson 	uint64_t hz = rte_get_tsc_hz();
327a9de470cSBruce Richardson 
328a9de470cSBruce Richardson 	/* Test green */
329a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
330a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
331a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
332a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
333a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
334a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_color_blind_check(
335a9de470cSBruce Richardson 		&tm, &tp, time, TM_TEST_TRTCM_CBS_DF - 1)
336c1656328SJasvinder Singh 		!= RTE_COLOR_GREEN)
337a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_BLIND_CHECK_MSG" GREEN");
338a9de470cSBruce Richardson 
339a9de470cSBruce Richardson 	/* Test yellow */
340a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
341a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
342a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
343a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
344a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
345a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_color_blind_check(
346a9de470cSBruce Richardson 		&tm, &tp, time, TM_TEST_TRTCM_CBS_DF + 1)
347c1656328SJasvinder Singh 		!= RTE_COLOR_YELLOW)
348a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_BLIND_CHECK_MSG" YELLOW");
349a9de470cSBruce Richardson 
350a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
351a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
352a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
353a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
354a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
355a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_color_blind_check(
356a9de470cSBruce Richardson 		&tm, &tp, time, TM_TEST_TRTCM_EBS_DF - 1)
357c1656328SJasvinder Singh 		!= RTE_COLOR_YELLOW)
358a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_BLIND_CHECK_MSG" YELLOW");
359a9de470cSBruce Richardson 
360a9de470cSBruce Richardson 	/* Test red */
361a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
362a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
363a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
364a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
365a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
366a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_color_blind_check(
367a9de470cSBruce Richardson 		&tm, &tp, time, TM_TEST_TRTCM_EBS_DF + 1)
368c1656328SJasvinder Singh 		!= RTE_COLOR_RED)
369a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_BLIND_CHECK_MSG" RED");
370a9de470cSBruce Richardson 
371a9de470cSBruce Richardson 	return 0;
372a9de470cSBruce Richardson }
373a9de470cSBruce Richardson 
374a9de470cSBruce Richardson 
375a9de470cSBruce Richardson /**
376a9de470cSBruce Richardson  * @in[4] : the flags packets carries.
377a9de470cSBruce Richardson  * @in[4] : the flags function expect to return.
378a9de470cSBruce Richardson  * It will do blind check at the time of 1 second from beginning.
379a9de470cSBruce Richardson  * At the time, it will use packets length of cbs -1, cbs + 1,
380a9de470cSBruce Richardson  * ebs -1 and ebs +1 with flag in[0], in[1], in[2] and in[3] to do
381a9de470cSBruce Richardson  * aware check, expect flag out[0], out[1], out[2] and out[3]
382a9de470cSBruce Richardson  */
383a9de470cSBruce Richardson 
384a9de470cSBruce Richardson static inline int
tm_test_srtcm_aware_check(enum rte_color in[4],enum rte_color out[4])385a9de470cSBruce Richardson tm_test_srtcm_aware_check
386c1656328SJasvinder Singh (enum rte_color in[4], enum rte_color out[4])
387a9de470cSBruce Richardson {
388a9de470cSBruce Richardson #define SRTCM_AWARE_CHECK_MSG "srtcm_aware_check"
389a9de470cSBruce Richardson 	struct rte_meter_srtcm_profile sp;
390a9de470cSBruce Richardson 	struct rte_meter_srtcm sm;
391a9de470cSBruce Richardson 	uint64_t time;
392a9de470cSBruce Richardson 	uint64_t hz = rte_get_tsc_hz();
393a9de470cSBruce Richardson 
394a9de470cSBruce Richardson 	if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
395a9de470cSBruce Richardson 		melog(SRTCM_AWARE_CHECK_MSG);
396a9de470cSBruce Richardson 	if (rte_meter_srtcm_config(&sm, &sp) != 0)
397a9de470cSBruce Richardson 		melog(SRTCM_AWARE_CHECK_MSG);
398a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
399a9de470cSBruce Richardson 	if (rte_meter_srtcm_color_aware_check(
400a9de470cSBruce Richardson 		&sm, &sp, time, TM_TEST_SRTCM_CBS_DF - 1, in[0]) != out[0])
401a9de470cSBruce Richardson 		melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[0], out[0]);
402a9de470cSBruce Richardson 
403a9de470cSBruce Richardson 	if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
404a9de470cSBruce Richardson 		melog(SRTCM_AWARE_CHECK_MSG);
405a9de470cSBruce Richardson 	if (rte_meter_srtcm_config(&sm, &sp) != 0)
406a9de470cSBruce Richardson 		melog(SRTCM_AWARE_CHECK_MSG);
407a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
408a9de470cSBruce Richardson 	if (rte_meter_srtcm_color_aware_check(
409a9de470cSBruce Richardson 		&sm, &sp, time, TM_TEST_SRTCM_CBS_DF + 1, in[1]) != out[1])
410a9de470cSBruce Richardson 		melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[1], out[1]);
411a9de470cSBruce Richardson 
412a9de470cSBruce Richardson 	if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
413a9de470cSBruce Richardson 		melog(SRTCM_AWARE_CHECK_MSG);
414a9de470cSBruce Richardson 	if (rte_meter_srtcm_config(&sm, &sp) != 0)
415a9de470cSBruce Richardson 		melog(SRTCM_AWARE_CHECK_MSG);
416a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
417a9de470cSBruce Richardson 	if (rte_meter_srtcm_color_aware_check(
418a9de470cSBruce Richardson 		&sm, &sp, time, TM_TEST_SRTCM_EBS_DF - 1, in[2]) != out[2])
419a9de470cSBruce Richardson 		melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[2], out[2]);
420a9de470cSBruce Richardson 
421a9de470cSBruce Richardson 	if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
422a9de470cSBruce Richardson 		melog(SRTCM_AWARE_CHECK_MSG);
423a9de470cSBruce Richardson 	if (rte_meter_srtcm_config(&sm, &sp) != 0)
424a9de470cSBruce Richardson 		melog(SRTCM_AWARE_CHECK_MSG);
425a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
426a9de470cSBruce Richardson 	if (rte_meter_srtcm_color_aware_check(
427a9de470cSBruce Richardson 		&sm, &sp, time, TM_TEST_SRTCM_EBS_DF + 1, in[3]) != out[3])
428a9de470cSBruce Richardson 		melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[3], out[3]);
429a9de470cSBruce Richardson 
430a9de470cSBruce Richardson 	return 0;
431a9de470cSBruce Richardson }
432a9de470cSBruce Richardson 
433a9de470cSBruce Richardson 
434a9de470cSBruce Richardson /**
435a9de470cSBruce Richardson  * functional test for rte_meter_srtcm_color_aware_check
436a9de470cSBruce Richardson  */
437a9de470cSBruce Richardson static inline int
tm_test_srtcm_color_aware_check(void)438a9de470cSBruce Richardson tm_test_srtcm_color_aware_check(void)
439a9de470cSBruce Richardson {
440c1656328SJasvinder Singh 	enum rte_color in[4], out[4];
441a9de470cSBruce Richardson 
442a9de470cSBruce Richardson 	/**
443a9de470cSBruce Richardson 	  * test 4 points that will produce green, yellow, yellow, red flag
444a9de470cSBruce Richardson 	  * if using blind check
445a9de470cSBruce Richardson 	  */
446a9de470cSBruce Richardson 
4474a6672c2SStephen Hemminger 	/* previously have a green, test points should keep unchanged */
448c1656328SJasvinder Singh 	in[0] = in[1] = in[2] = in[3] = RTE_COLOR_GREEN;
449c1656328SJasvinder Singh 	out[0] = RTE_COLOR_GREEN;
450c1656328SJasvinder Singh 	out[1] = RTE_COLOR_YELLOW;
451c1656328SJasvinder Singh 	out[2] = RTE_COLOR_YELLOW;
452c1656328SJasvinder Singh 	out[3] = RTE_COLOR_RED;
453a9de470cSBruce Richardson 	if (tm_test_srtcm_aware_check(in, out) != 0)
454a9de470cSBruce Richardson 		return -1;
455a9de470cSBruce Richardson 
456a9de470cSBruce Richardson 	/**
457a9de470cSBruce Richardson 	  * previously have a yellow, green & yellow = yellow
458a9de470cSBruce Richardson 	  * yellow & red = red
459a9de470cSBruce Richardson 	  */
460c1656328SJasvinder Singh 	in[0] = in[1] = in[2] = in[3] = RTE_COLOR_YELLOW;
461c1656328SJasvinder Singh 	out[0] = RTE_COLOR_YELLOW;
462c1656328SJasvinder Singh 	out[1] = RTE_COLOR_YELLOW;
463c1656328SJasvinder Singh 	out[2] = RTE_COLOR_YELLOW;
464c1656328SJasvinder Singh 	out[3] = RTE_COLOR_RED;
465a9de470cSBruce Richardson 	if (tm_test_srtcm_aware_check(in, out) != 0)
466a9de470cSBruce Richardson 		return -1;
467a9de470cSBruce Richardson 
468a9de470cSBruce Richardson 	/**
469a9de470cSBruce Richardson 	  * previously have a red, red & green = red
470a9de470cSBruce Richardson 	  * red & yellow = red
471a9de470cSBruce Richardson 	  */
472c1656328SJasvinder Singh 	in[0] = in[1] = in[2] = in[3] = RTE_COLOR_RED;
473c1656328SJasvinder Singh 	out[0] = RTE_COLOR_RED;
474c1656328SJasvinder Singh 	out[1] = RTE_COLOR_RED;
475c1656328SJasvinder Singh 	out[2] = RTE_COLOR_RED;
476c1656328SJasvinder Singh 	out[3] = RTE_COLOR_RED;
477a9de470cSBruce Richardson 	if (tm_test_srtcm_aware_check(in, out) != 0)
478a9de470cSBruce Richardson 		return -1;
479a9de470cSBruce Richardson 
480a9de470cSBruce Richardson 	return 0;
481a9de470cSBruce Richardson }
482a9de470cSBruce Richardson 
483a9de470cSBruce Richardson /**
484a9de470cSBruce Richardson  * @in[4] : the flags packets carries.
485a9de470cSBruce Richardson  * @in[4] : the flags function expect to return.
486a9de470cSBruce Richardson  * It will do blind check at the time of 1 second from beginning.
487a9de470cSBruce Richardson  * At the time, it will use packets length of cbs -1, cbs + 1,
488a9de470cSBruce Richardson  * ebs -1 and ebs +1 with flag in[0], in[1], in[2] and in[3] to do
489a9de470cSBruce Richardson  * aware check, expect flag out[0], out[1], out[2] and out[3]
490a9de470cSBruce Richardson  */
491a9de470cSBruce Richardson static inline int
tm_test_trtcm_aware_check(enum rte_color in[4],enum rte_color out[4])492a9de470cSBruce Richardson tm_test_trtcm_aware_check
493c1656328SJasvinder Singh (enum rte_color in[4], enum rte_color out[4])
494a9de470cSBruce Richardson {
495a9de470cSBruce Richardson #define TRTCM_AWARE_CHECK_MSG "trtcm_aware_check"
496a9de470cSBruce Richardson 	struct rte_meter_trtcm_profile tp;
497a9de470cSBruce Richardson 	struct rte_meter_trtcm tm;
498a9de470cSBruce Richardson 	uint64_t time;
499a9de470cSBruce Richardson 	uint64_t hz = rte_get_tsc_hz();
500a9de470cSBruce Richardson 
501a9de470cSBruce Richardson 	if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
502a9de470cSBruce Richardson 		melog(TRTCM_AWARE_CHECK_MSG);
503a9de470cSBruce Richardson 	if (rte_meter_trtcm_config(&tm, &tp) != 0)
504a9de470cSBruce Richardson 		melog(TRTCM_AWARE_CHECK_MSG);
505a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
506a9de470cSBruce Richardson 	if (rte_meter_trtcm_color_aware_check(
507a9de470cSBruce Richardson 		&tm, &tp, time, TM_TEST_TRTCM_CBS_DF - 1, in[0]) != out[0])
508a9de470cSBruce Richardson 		melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[0], out[0]);
509a9de470cSBruce Richardson 
510a9de470cSBruce Richardson 	if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
511a9de470cSBruce Richardson 		melog(TRTCM_AWARE_CHECK_MSG);
512a9de470cSBruce Richardson 	if (rte_meter_trtcm_config(&tm, &tp) != 0)
513a9de470cSBruce Richardson 		melog(TRTCM_AWARE_CHECK_MSG);
514a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
515a9de470cSBruce Richardson 	if (rte_meter_trtcm_color_aware_check(
516a9de470cSBruce Richardson 		&tm, &tp, time, TM_TEST_TRTCM_CBS_DF + 1, in[1]) != out[1])
517a9de470cSBruce Richardson 		melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[1], out[1]);
518a9de470cSBruce Richardson 
519a9de470cSBruce Richardson 	if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
520a9de470cSBruce Richardson 		melog(TRTCM_AWARE_CHECK_MSG);
521a9de470cSBruce Richardson 	if (rte_meter_trtcm_config(&tm, &tp) != 0)
522a9de470cSBruce Richardson 		melog(TRTCM_AWARE_CHECK_MSG);
523a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
524a9de470cSBruce Richardson 	if (rte_meter_trtcm_color_aware_check(
525a9de470cSBruce Richardson 		&tm, &tp, time, TM_TEST_TRTCM_PBS_DF - 1, in[2]) != out[2])
526a9de470cSBruce Richardson 		melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[2], out[2]);
527a9de470cSBruce Richardson 
528a9de470cSBruce Richardson 	if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
529a9de470cSBruce Richardson 		melog(TRTCM_AWARE_CHECK_MSG);
530a9de470cSBruce Richardson 	if (rte_meter_trtcm_config(&tm, &tp) != 0)
531a9de470cSBruce Richardson 		melog(TRTCM_AWARE_CHECK_MSG);
532a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
533a9de470cSBruce Richardson 	if (rte_meter_trtcm_color_aware_check(
534a9de470cSBruce Richardson 		&tm, &tp, time, TM_TEST_TRTCM_PBS_DF + 1, in[3]) != out[3])
535a9de470cSBruce Richardson 		melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[3], out[3]);
536a9de470cSBruce Richardson 
537a9de470cSBruce Richardson 	return 0;
538a9de470cSBruce Richardson }
539a9de470cSBruce Richardson 
540a9de470cSBruce Richardson 
541a9de470cSBruce Richardson /**
542a9de470cSBruce Richardson  * functional test for rte_meter_trtcm_color_aware_check
543a9de470cSBruce Richardson  */
544a9de470cSBruce Richardson 
545a9de470cSBruce Richardson static inline int
tm_test_trtcm_color_aware_check(void)546a9de470cSBruce Richardson tm_test_trtcm_color_aware_check(void)
547a9de470cSBruce Richardson {
548c1656328SJasvinder Singh 	enum rte_color in[4], out[4];
549a9de470cSBruce Richardson 	/**
550a9de470cSBruce Richardson 	  * test 4 points that will produce green, yellow, yellow, red flag
551a9de470cSBruce Richardson 	  * if using blind check
552a9de470cSBruce Richardson 	  */
553a9de470cSBruce Richardson 
5544a6672c2SStephen Hemminger 	/* previously have a green, test points should keep unchanged */
555c1656328SJasvinder Singh 	in[0] = in[1] = in[2] = in[3] = RTE_COLOR_GREEN;
556c1656328SJasvinder Singh 	out[0] = RTE_COLOR_GREEN;
557c1656328SJasvinder Singh 	out[1] = RTE_COLOR_YELLOW;
558c1656328SJasvinder Singh 	out[2] = RTE_COLOR_YELLOW;
559c1656328SJasvinder Singh 	out[3] = RTE_COLOR_RED;
560a9de470cSBruce Richardson 	if (tm_test_trtcm_aware_check(in, out) != 0)
561a9de470cSBruce Richardson 		return -1;
562a9de470cSBruce Richardson 
563c1656328SJasvinder Singh 	in[0] = in[1] = in[2] = in[3] = RTE_COLOR_YELLOW;
564c1656328SJasvinder Singh 	out[0] = RTE_COLOR_YELLOW;
565c1656328SJasvinder Singh 	out[1] = RTE_COLOR_YELLOW;
566c1656328SJasvinder Singh 	out[2] = RTE_COLOR_YELLOW;
567c1656328SJasvinder Singh 	out[3] = RTE_COLOR_RED;
568a9de470cSBruce Richardson 	if (tm_test_trtcm_aware_check(in, out) != 0)
569a9de470cSBruce Richardson 		return -1;
570a9de470cSBruce Richardson 
571c1656328SJasvinder Singh 	in[0] = in[1] = in[2] = in[3] = RTE_COLOR_RED;
572c1656328SJasvinder Singh 	out[0] = RTE_COLOR_RED;
573c1656328SJasvinder Singh 	out[1] = RTE_COLOR_RED;
574c1656328SJasvinder Singh 	out[2] = RTE_COLOR_RED;
575c1656328SJasvinder Singh 	out[3] = RTE_COLOR_RED;
576a9de470cSBruce Richardson 	if (tm_test_trtcm_aware_check(in, out) != 0)
577a9de470cSBruce Richardson 		return -1;
578a9de470cSBruce Richardson 
579a9de470cSBruce Richardson 	return 0;
580a9de470cSBruce Richardson }
581a9de470cSBruce Richardson 
582a9de470cSBruce Richardson /**
583a9de470cSBruce Richardson  * @in[4] : the flags packets carries.
584a9de470cSBruce Richardson  * @in[4] : the flags function expect to return.
585a9de470cSBruce Richardson  * It will do blind check at the time of 1 second from beginning.
586a9de470cSBruce Richardson  * At the time, it will use packets length of cbs -1, cbs + 1,
587a9de470cSBruce Richardson  * ebs -1 and ebs +1 with flag in[0], in[1], in[2] and in[3] to do
588a9de470cSBruce Richardson  * aware check, expect flag out[0], out[1], out[2] and out[3]
589a9de470cSBruce Richardson  */
590a9de470cSBruce Richardson static inline int
tm_test_trtcm_rfc4115_aware_check(enum rte_color in[4],enum rte_color out[4])591a9de470cSBruce Richardson tm_test_trtcm_rfc4115_aware_check
592c1656328SJasvinder Singh (enum rte_color in[4], enum rte_color out[4])
593a9de470cSBruce Richardson {
594a9de470cSBruce Richardson #define TRTCM_RFC4115_AWARE_CHECK_MSG "trtcm_rfc4115_aware_check"
595a9de470cSBruce Richardson 	struct rte_meter_trtcm_rfc4115_profile tp;
596a9de470cSBruce Richardson 	struct rte_meter_trtcm_rfc4115 tm;
597a9de470cSBruce Richardson 	uint64_t time;
598a9de470cSBruce Richardson 	uint64_t hz = rte_get_tsc_hz();
599a9de470cSBruce Richardson 
600a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
601a9de470cSBruce Richardson 		melog(TRTCM_AWARE_CHECK_MSG);
602a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
603a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
604a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
605a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_color_aware_check(
606a9de470cSBruce Richardson 		&tm, &tp, time, TM_TEST_TRTCM_CBS_DF - 1, in[0]) != out[0])
607a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_AWARE_CHECK_MSG" %u:%u", in[0], out[0]);
608a9de470cSBruce Richardson 
609a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
610a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
611a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
612a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
613a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
614a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_color_aware_check(
615a9de470cSBruce Richardson 		&tm, &tp, time, TM_TEST_TRTCM_CBS_DF + 1, in[1]) != out[1])
616a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_AWARE_CHECK_MSG" %u:%u", in[1], out[1]);
617a9de470cSBruce Richardson 
618a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
619a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
620a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
621a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
622a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
623a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_color_aware_check(
624a9de470cSBruce Richardson 		&tm, &tp, time, TM_TEST_TRTCM_EBS_DF - 1, in[2]) != out[2])
625a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_AWARE_CHECK_MSG" %u:%u", in[2], out[2]);
626a9de470cSBruce Richardson 
627a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
628a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
629a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
630a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
631a9de470cSBruce Richardson 	time = rte_get_tsc_cycles() + hz;
632a9de470cSBruce Richardson 	if (rte_meter_trtcm_rfc4115_color_aware_check(
633a9de470cSBruce Richardson 		&tm, &tp, time, TM_TEST_TRTCM_EBS_DF + 1, in[3]) != out[3])
634a9de470cSBruce Richardson 		melog(TRTCM_RFC4115_AWARE_CHECK_MSG" %u:%u", in[3], out[3]);
635a9de470cSBruce Richardson 
636a9de470cSBruce Richardson 	return 0;
637a9de470cSBruce Richardson }
638a9de470cSBruce Richardson 
639a9de470cSBruce Richardson /**
640a9de470cSBruce Richardson  * functional test for rte_meter_trtcm_rfc4115_color_aware_check
641a9de470cSBruce Richardson  */
642a9de470cSBruce Richardson static inline int
tm_test_trtcm_rfc4115_color_aware_check(void)643a9de470cSBruce Richardson tm_test_trtcm_rfc4115_color_aware_check(void)
644a9de470cSBruce Richardson {
645c1656328SJasvinder Singh 	enum rte_color in[4], out[4];
646a9de470cSBruce Richardson 	/**
647a9de470cSBruce Richardson 	  * test 4 points that will produce green, yellow, yellow, red flag
648a9de470cSBruce Richardson 	  * if using blind check
649a9de470cSBruce Richardson 	  */
650a9de470cSBruce Richardson 
6514a6672c2SStephen Hemminger 	/* previously have a green, test points should keep unchanged */
652c1656328SJasvinder Singh 	in[0] = in[1] = in[2] = in[3] = RTE_COLOR_GREEN;
653c1656328SJasvinder Singh 	out[0] = RTE_COLOR_GREEN;
654c1656328SJasvinder Singh 	out[1] = RTE_COLOR_YELLOW;
655c1656328SJasvinder Singh 	out[2] = RTE_COLOR_YELLOW;
656c1656328SJasvinder Singh 	out[3] = RTE_COLOR_RED;
657a9de470cSBruce Richardson 	if (tm_test_trtcm_rfc4115_aware_check(in, out) != 0)
658a9de470cSBruce Richardson 		return -1;
659a9de470cSBruce Richardson 
660c1656328SJasvinder Singh 	in[0] = in[1] = in[2] = in[3] = RTE_COLOR_YELLOW;
661c1656328SJasvinder Singh 	out[0] = RTE_COLOR_YELLOW;
662c1656328SJasvinder Singh 	out[1] = RTE_COLOR_YELLOW;
663c1656328SJasvinder Singh 	out[2] = RTE_COLOR_YELLOW;
664c1656328SJasvinder Singh 	out[3] = RTE_COLOR_RED;
665a9de470cSBruce Richardson 	if (tm_test_trtcm_rfc4115_aware_check(in, out) != 0)
666a9de470cSBruce Richardson 		return -1;
667a9de470cSBruce Richardson 
668c1656328SJasvinder Singh 	in[0] = in[1] = in[2] = in[3] = RTE_COLOR_RED;
669c1656328SJasvinder Singh 	out[0] = RTE_COLOR_RED;
670c1656328SJasvinder Singh 	out[1] = RTE_COLOR_RED;
671c1656328SJasvinder Singh 	out[2] = RTE_COLOR_RED;
672c1656328SJasvinder Singh 	out[3] = RTE_COLOR_RED;
673a9de470cSBruce Richardson 	if (tm_test_trtcm_rfc4115_aware_check(in, out) != 0)
674a9de470cSBruce Richardson 		return -1;
675a9de470cSBruce Richardson 
676a9de470cSBruce Richardson 	return 0;
677a9de470cSBruce Richardson }
678a9de470cSBruce Richardson 
679a9de470cSBruce Richardson /**
680a9de470cSBruce Richardson  * test main entrance for library meter
681a9de470cSBruce Richardson  */
682a9de470cSBruce Richardson static int
test_meter(void)683a9de470cSBruce Richardson test_meter(void)
684a9de470cSBruce Richardson {
685a9de470cSBruce Richardson 	if (tm_test_srtcm_config() != 0)
686a9de470cSBruce Richardson 		return -1;
687a9de470cSBruce Richardson 
688a9de470cSBruce Richardson 	if (tm_test_trtcm_config() != 0)
689a9de470cSBruce Richardson 		return -1;
690a9de470cSBruce Richardson 
691a9de470cSBruce Richardson 	if (tm_test_trtcm_rfc4115_config() != 0)
692a9de470cSBruce Richardson 		return -1;
693a9de470cSBruce Richardson 
694a9de470cSBruce Richardson 	if (tm_test_srtcm_color_blind_check() != 0)
695a9de470cSBruce Richardson 		return -1;
696a9de470cSBruce Richardson 
697a9de470cSBruce Richardson 	if (tm_test_trtcm_color_blind_check() != 0)
698a9de470cSBruce Richardson 		return -1;
699a9de470cSBruce Richardson 
700a9de470cSBruce Richardson 	if (tm_test_trtcm_rfc4115_color_blind_check() != 0)
701a9de470cSBruce Richardson 		return -1;
702a9de470cSBruce Richardson 
703a9de470cSBruce Richardson 	if (tm_test_srtcm_color_aware_check() != 0)
704a9de470cSBruce Richardson 		return -1;
705a9de470cSBruce Richardson 
706a9de470cSBruce Richardson 	if (tm_test_trtcm_color_aware_check() != 0)
707a9de470cSBruce Richardson 		return -1;
708a9de470cSBruce Richardson 
709a9de470cSBruce Richardson 	if (tm_test_trtcm_rfc4115_color_aware_check() != 0)
710a9de470cSBruce Richardson 		return -1;
711a9de470cSBruce Richardson 
712a9de470cSBruce Richardson 	return 0;
713a9de470cSBruce Richardson 
714a9de470cSBruce Richardson }
715a9de470cSBruce Richardson 
716*e0a8442cSBruce Richardson REGISTER_FAST_TEST(meter_autotest, true, true, test_meter);
717