33 */
44
55#include <rte_common.h>
6+ #include <rte_cycles.h>
67#include <rte_hexdump.h>
7- #include <rte_mbuf.h>
88#include <rte_malloc.h>
9+ #include <rte_mbuf.h>
910#include <rte_memcpy.h>
10- #include <rte_cycles .h>
11+ #include <rte_random .h>
1112
1213#include <rte_service.h>
1314#include <rte_service_component.h>
1617
1718/* used as the service core ID */
1819static uint32_t slcore_id ;
19- /* used as timestamp to detect if a service core is running */
20- static uint64_t service_tick ;
20+ /* track service call count */
21+ static uint64_t service_calls ;
22+ static uint64_t service_idle_calls ;
23+ static uint64_t service_error_calls ;
2124/* used as a flag to check if a function was run */
2225static uint32_t service_remote_launch_flag ;
2326
@@ -46,9 +49,21 @@ testsuite_teardown(void)
4649static int32_t dummy_cb (void * args )
4750{
4851 RTE_SET_USED (args );
49- service_tick ++ ;
52+
53+ service_calls ++ ;
54+
55+ switch (rte_rand_max (3 )) {
56+ case 0 :
57+ return 0 ;
58+ case 1 :
59+ service_idle_calls ++ ;
60+ return - EAGAIN ;
61+ default :
62+ service_error_calls ++ ;
63+ return - ENOENT ;
64+ }
65+
5066 rte_delay_ms (SERVICE_DELAY );
51- return 0 ;
5267}
5368
5469static int32_t dummy_mt_unsafe_cb (void * args )
@@ -121,6 +136,10 @@ unregister_all(void)
121136 rte_service_lcore_reset_all ();
122137 rte_eal_mp_wait_lcore ();
123138
139+ service_calls = 0 ;
140+ service_idle_calls = 0 ;
141+ service_error_calls = 0 ;
142+
124143 return TEST_SUCCESS ;
125144}
126145
@@ -295,12 +314,19 @@ service_attr_get(void)
295314 "Valid attr_get() call didn't return success" );
296315 TEST_ASSERT_EQUAL (0 , attr_value ,
297316 "attr_get() call didn't set correct cycles (zero)" );
298- /* check correct call count */
317+ /* check correct call counts */
299318 const int attr_calls = RTE_SERVICE_ATTR_CALL_COUNT ;
300319 TEST_ASSERT_EQUAL (0 , rte_service_attr_get (id , attr_calls , & attr_value ),
301320 "Valid attr_get() call didn't return success" );
302- TEST_ASSERT_EQUAL (0 , attr_value ,
303- "attr_get() call didn't get call count (zero)" );
321+ TEST_ASSERT_EQUAL (0 , attr_value , "Call count was not zero" );
322+ const int attr_idle_calls = RTE_SERVICE_ATTR_IDLE_CALL_COUNT ;
323+ TEST_ASSERT_EQUAL (0 , rte_service_attr_get (id , attr_idle_calls , & attr_value ),
324+ "Valid attr_get() call didn't return success" );
325+ TEST_ASSERT_EQUAL (0 , attr_value , "Idle call count was not zero" );
326+ const int attr_error_calls = RTE_SERVICE_ATTR_ERROR_CALL_COUNT ;
327+ TEST_ASSERT_EQUAL (0 , rte_service_attr_get (id , attr_error_calls , & attr_value ),
328+ "Valid attr_get() call didn't return success" );
329+ TEST_ASSERT_EQUAL (0 , attr_value , "Error call count was not zero" );
304330
305331 /* Call service to increment cycle count */
306332 TEST_ASSERT_EQUAL (0 , rte_service_lcore_add (slcore_id ),
@@ -331,8 +357,13 @@ service_attr_get(void)
331357
332358 TEST_ASSERT_EQUAL (0 , rte_service_attr_get (id , attr_calls , & attr_value ),
333359 "Valid attr_get() call didn't return success" );
334- TEST_ASSERT_EQUAL (1 , (attr_value > 0 ),
335- "attr_get() call didn't get call count (zero)" );
360+ TEST_ASSERT_EQUAL (service_calls , attr_value , "Unexpected call count" );
361+ TEST_ASSERT_EQUAL (0 , rte_service_attr_get (id , attr_idle_calls , & attr_value ),
362+ "Valid attr_get() call didn't return success" );
363+ TEST_ASSERT_EQUAL (service_idle_calls , attr_value , "Unexpected idle call count" );
364+ TEST_ASSERT_EQUAL (0 , rte_service_attr_get (id , attr_error_calls , & attr_value ),
365+ "Valid attr_get() call didn't return success" );
366+ TEST_ASSERT_EQUAL (service_error_calls , attr_value , "Unexpected error call count" );
336367
337368 TEST_ASSERT_EQUAL (0 , rte_service_attr_reset_all (id ),
338369 "Valid attr_reset_all() return success" );
@@ -341,11 +372,16 @@ service_attr_get(void)
341372 "Valid attr_get() call didn't return success" );
342373 TEST_ASSERT_EQUAL (0 , attr_value ,
343374 "attr_get() call didn't set correct cycles (zero)" );
344- /* ensure call count > zero */
375+ /* ensure call counts are zero */
345376 TEST_ASSERT_EQUAL (0 , rte_service_attr_get (id , attr_calls , & attr_value ),
346377 "Valid attr_get() call didn't return success" );
347- TEST_ASSERT_EQUAL (0 , (attr_value > 0 ),
348- "attr_get() call didn't get call count (zero)" );
378+ TEST_ASSERT_EQUAL (0 , attr_value , "Call count was not reset" );
379+ TEST_ASSERT_EQUAL (0 , rte_service_attr_get (id , attr_idle_calls , & attr_value ),
380+ "Valid attr_get() call didn't return success" );
381+ TEST_ASSERT_EQUAL (0 , attr_value , "Idle call count was not reset" );
382+ TEST_ASSERT_EQUAL (0 , rte_service_attr_get (id , attr_error_calls , & attr_value ),
383+ "Valid attr_get() call didn't return success" );
384+ TEST_ASSERT_EQUAL (0 , attr_value , "Error call count was not reset" );
349385
350386 return unregister_all ();
351387}
@@ -533,10 +569,10 @@ service_lcore_en_dis_able(void)
533569static int
534570service_lcore_running_check (void )
535571{
536- uint64_t tick = service_tick ;
572+ uint64_t calls = service_calls ;
537573 rte_delay_ms (SERVICE_DELAY * 100 );
538- /* if (tick != service_tick) we know the lcore as polled the service */
539- return tick != service_tick ;
574+ bool service_polled = calls != service_calls ;
575+ return service_polled ;
540576}
541577
542578static int
0 commit comments