1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
5 #include <rte_common.h>
6 #include <rte_hexdump.h>
8 #include <rte_malloc.h>
9 #include <rte_memcpy.h>
10 #include <rte_cycles.h>
12 #include <rte_service.h>
13 #include <rte_service_component.h>
17 /* used as the service core ID */
18 static uint32_t slcore_id;
19 /* used as timestamp to detect if a service core is running */
20 static uint64_t service_tick;
21 /* used as a flag to check if a function was run */
22 static uint32_t service_remote_launch_flag;
24 #define SERVICE_DELAY 1
26 #define DUMMY_SERVICE_NAME "dummy_service"
27 #define MT_SAFE_SERVICE_NAME "mt_safe_service"
32 slcore_id = rte_get_next_lcore(/* start core */ -1,
40 testsuite_teardown(void)
42 /* release service cores? */
45 static int32_t dummy_cb(void *args)
49 rte_delay_ms(SERVICE_DELAY);
53 static int32_t dummy_mt_unsafe_cb(void *args)
55 /* before running test, the initialization has set pass_test to 1.
56 * If the cmpset in service-cores is working correctly, the code here
57 * should never fail to take the lock. If the lock *is* taken, fail the
58 * test, because two threads are concurrently in a non-MT safe callback.
60 uint32_t *test_params = args;
61 uint32_t *atomic_lock = &test_params[0];
62 uint32_t *pass_test = &test_params[1];
63 int lock_taken = rte_atomic32_cmpset(atomic_lock, 0, 1);
65 /* delay with the lock held */
67 rte_atomic32_clear((rte_atomic32_t *)atomic_lock);
69 /* 2nd thread will fail to take lock, so set pass flag */
77 static int32_t dummy_mt_safe_cb(void *args)
79 /* Atomic checks to ensure MT safe services allow > 1 thread to
80 * concurrently run the callback. The concept is as follows;
81 * 1) if lock is available, take the lock then delay
82 * 2) if first lock is taken, and a thread arrives in the CB, we know
83 * that 2 threads are running the callback at the same time: MT safe
85 uint32_t *test_params = args;
86 uint32_t *atomic_lock = &test_params[0];
87 uint32_t *pass_test = &test_params[1];
88 int lock_taken = rte_atomic32_cmpset(atomic_lock, 0, 1);
90 /* delay with the lock held */
92 rte_atomic32_clear((rte_atomic32_t *)atomic_lock);
94 /* 2nd thread will fail to take lock, so set pass flag */
101 /* unregister all services */
107 TEST_ASSERT_EQUAL(-EINVAL, rte_service_component_unregister(1000),
108 "Unregistered invalid service id");
110 uint32_t c = rte_service_get_count();
111 for (i = 0; i < c; i++) {
112 TEST_ASSERT_EQUAL(0, rte_service_component_unregister(i),
113 "Error unregistering a valid service");
116 rte_service_lcore_reset_all();
121 /* register a single dummy service */
125 /* make sure there are no remains from previous tests */
128 struct rte_service_spec service;
129 memset(&service, 0, sizeof(struct rte_service_spec));
131 TEST_ASSERT_EQUAL(-EINVAL,
132 rte_service_component_register(&service, NULL),
134 service.callback = dummy_cb;
136 TEST_ASSERT_EQUAL(-EINVAL,
137 rte_service_component_register(&service, NULL),
139 snprintf(service.name, sizeof(service.name), DUMMY_SERVICE_NAME);
142 TEST_ASSERT_EQUAL(0, rte_service_component_register(&service, &id),
143 "Failed to register valid service");
145 rte_service_component_runstate_set(id, 1);
150 /* verify get_by_name() service lookup */
152 service_get_by_name(void)
157 TEST_ASSERT_EQUAL(-ENODEV,
158 rte_service_get_by_name(DUMMY_SERVICE_NAME, &sid),
159 "get by name with invalid name should return -ENODEV");
160 TEST_ASSERT_EQUAL(-EINVAL,
161 rte_service_get_by_name(DUMMY_SERVICE_NAME, 0x0),
162 "get by name with NULL ptr should return -ENODEV");
164 /* register service */
165 struct rte_service_spec service;
166 memset(&service, 0, sizeof(struct rte_service_spec));
167 TEST_ASSERT_EQUAL(-EINVAL,
168 rte_service_component_register(&service, NULL),
170 service.callback = dummy_cb;
171 TEST_ASSERT_EQUAL(-EINVAL,
172 rte_service_component_register(&service, NULL),
174 snprintf(service.name, sizeof(service.name), DUMMY_SERVICE_NAME);
175 TEST_ASSERT_EQUAL(0, rte_service_component_register(&service, NULL),
176 "Failed to register valid service");
178 /* we unregistered all service, now registering 1, should be id 0 */
179 uint32_t service_id_as_expected = 0;
180 TEST_ASSERT_EQUAL(0, rte_service_get_by_name(DUMMY_SERVICE_NAME, &sid),
181 "Service get_by_name should return 0 on valid inputs");
182 TEST_ASSERT_EQUAL(service_id_as_expected, sid,
183 "Service get_by_name should equal expected id");
187 /* ensure after unregister, get_by_name returns NULL */
188 TEST_ASSERT_EQUAL(-ENODEV,
189 rte_service_get_by_name(DUMMY_SERVICE_NAME, &sid),
190 "get by name should return -ENODEV after unregister");
195 /* verify probe of capabilities */
197 service_probe_capability(void)
201 struct rte_service_spec service;
202 memset(&service, 0, sizeof(struct rte_service_spec));
203 service.callback = dummy_cb;
204 snprintf(service.name, sizeof(service.name), DUMMY_SERVICE_NAME);
205 service.capabilities |= RTE_SERVICE_CAP_MT_SAFE;
206 TEST_ASSERT_EQUAL(0, rte_service_component_register(&service, NULL),
207 "Register of MT SAFE service failed");
209 /* verify flag is enabled */
210 const uint32_t sid = 0;
211 int32_t mt = rte_service_probe_capability(sid, RTE_SERVICE_CAP_MT_SAFE);
212 TEST_ASSERT_EQUAL(1, mt, "MT SAFE capability flag not set.");
217 memset(&service, 0, sizeof(struct rte_service_spec));
218 service.callback = dummy_cb;
219 snprintf(service.name, sizeof(service.name), DUMMY_SERVICE_NAME);
220 TEST_ASSERT_EQUAL(0, rte_service_component_register(&service, NULL),
221 "Register of non-MT safe service failed");
223 /* verify flag is enabled */
224 mt = rte_service_probe_capability(sid, RTE_SERVICE_CAP_MT_SAFE);
225 TEST_ASSERT_EQUAL(0, mt, "MT SAFE cap flag set on non MT SAFE service");
227 return unregister_all();
230 /* verify the service name */
234 const char *name = rte_service_get_name(0);
235 int equal = strcmp(name, DUMMY_SERVICE_NAME);
236 TEST_ASSERT_EQUAL(0, equal, "Error: Service name not correct");
238 return unregister_all();
241 /* verify service attr get */
243 service_attr_get(void)
245 /* ensure all services unregistered so cycle counts are zero */
248 struct rte_service_spec service;
249 memset(&service, 0, sizeof(struct rte_service_spec));
250 service.callback = dummy_cb;
251 snprintf(service.name, sizeof(service.name), DUMMY_SERVICE_NAME);
252 service.capabilities |= RTE_SERVICE_CAP_MT_SAFE;
254 TEST_ASSERT_EQUAL(0, rte_service_component_register(&service, &id),
255 "Register of service failed");
256 rte_service_component_runstate_set(id, 1);
257 TEST_ASSERT_EQUAL(0, rte_service_runstate_set(id, 1),
258 "Error: Service start returned non-zero");
259 rte_service_set_stats_enable(id, 1);
261 uint32_t attr_id = UINT32_MAX;
262 uint32_t attr_value = 0xdead;
263 /* check error return values */
264 TEST_ASSERT_EQUAL(-EINVAL, rte_service_attr_get(id, attr_id,
266 "Invalid attr_id didn't return -EINVAL");
268 attr_id = RTE_SERVICE_ATTR_CYCLES;
269 TEST_ASSERT_EQUAL(-EINVAL, rte_service_attr_get(UINT32_MAX, attr_id,
271 "Invalid service id didn't return -EINVAL");
273 TEST_ASSERT_EQUAL(-EINVAL, rte_service_attr_get(id, attr_id, NULL),
274 "Invalid attr_value pointer id didn't return -EINVAL");
276 /* check correct (zero) return value and correct value (zero) */
277 TEST_ASSERT_EQUAL(0, rte_service_attr_get(id, attr_id, &attr_value),
278 "Valid attr_get() call didn't return success");
279 TEST_ASSERT_EQUAL(0, attr_value,
280 "attr_get() call didn't set correct cycles (zero)");
282 /* Call service to increment cycle count */
283 TEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_id),
284 "Service core add did not return zero");
285 TEST_ASSERT_EQUAL(0, rte_service_map_lcore_set(id, slcore_id, 1),
286 "Enabling valid service and core failed");
287 TEST_ASSERT_EQUAL(0, rte_service_lcore_start(slcore_id),
288 "Starting service core failed");
290 /* wait for the service lcore to run */
293 TEST_ASSERT_EQUAL(0, rte_service_attr_get(id, attr_id, &attr_value),
294 "Valid attr_get() call didn't return success");
295 int cycles_gt_zero = attr_value > 0;
296 TEST_ASSERT_EQUAL(1, cycles_gt_zero,
297 "attr_get() failed to get cycles (expected > zero)");
299 rte_service_lcore_stop(slcore_id);
301 TEST_ASSERT_EQUAL(0, rte_service_attr_reset_all(id),
302 "Valid attr_reset_all() return success");
304 TEST_ASSERT_EQUAL(0, rte_service_attr_get(id, attr_id, &attr_value),
305 "Valid attr_get() call didn't return success");
306 TEST_ASSERT_EQUAL(0, attr_value,
307 "attr_get() call didn't set correct cycles (zero)");
309 return unregister_all();
312 /* verify service dump */
316 const uint32_t sid = 0;
317 rte_service_set_stats_enable(sid, 1);
318 rte_service_dump(stdout, 0);
319 rte_service_set_stats_enable(sid, 0);
320 rte_service_dump(stdout, 0);
321 return unregister_all();
324 /* start and stop a service */
326 service_start_stop(void)
328 const uint32_t sid = 0;
330 /* runstate_get() returns if service is running and slcore is mapped */
331 TEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_id),
332 "Service core add did not return zero");
333 int ret = rte_service_map_lcore_set(sid, slcore_id, 1);
334 TEST_ASSERT_EQUAL(0, ret,
335 "Enabling service core, expected 0 got %d", ret);
337 TEST_ASSERT_EQUAL(0, rte_service_runstate_get(sid),
338 "Error: Service should be stopped");
340 TEST_ASSERT_EQUAL(0, rte_service_runstate_set(sid, 0),
341 "Error: Service stopped returned non-zero");
343 TEST_ASSERT_EQUAL(0, rte_service_runstate_get(sid),
344 "Error: Service is running - should be stopped");
346 TEST_ASSERT_EQUAL(0, rte_service_runstate_set(sid, 1),
347 "Error: Service start returned non-zero");
349 TEST_ASSERT_EQUAL(1, rte_service_runstate_get(sid),
350 "Error: Service is not running");
352 return unregister_all();
357 service_remote_launch_func(void *arg)
360 service_remote_launch_flag = 1;
364 /* enable and disable a lcore for a service */
366 service_lcore_en_dis_able(void)
368 const uint32_t sid = 0;
370 /* expected failure cases */
371 TEST_ASSERT_EQUAL(-EINVAL, rte_service_map_lcore_set(sid, 100000, 1),
372 "Enable on invalid core did not fail");
373 TEST_ASSERT_EQUAL(-EINVAL, rte_service_map_lcore_set(sid, 100000, 0),
374 "Disable on invalid core did not fail");
376 /* add service core to allow enabling */
377 TEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_id),
378 "Add service core failed when not in use before");
381 TEST_ASSERT_EQUAL(0, rte_service_map_lcore_set(sid, slcore_id, 1),
382 "Enabling valid service and core failed");
383 TEST_ASSERT_EQUAL(1, rte_service_map_lcore_get(sid, slcore_id),
384 "Enabled core returned not-enabled");
387 TEST_ASSERT_EQUAL(0, rte_service_map_lcore_set(sid, slcore_id, 0),
388 "Disabling valid service and lcore failed");
389 TEST_ASSERT_EQUAL(0, rte_service_map_lcore_get(sid, slcore_id),
390 "Disabled core returned enabled");
392 /* call remote_launch to verify that app can launch ex-service lcore */
393 service_remote_launch_flag = 0;
394 rte_eal_wait_lcore(slcore_id);
395 int ret = rte_eal_remote_launch(service_remote_launch_func, NULL,
397 TEST_ASSERT_EQUAL(0, ret, "Ex-service core remote launch failed.");
398 rte_eal_mp_wait_lcore();
399 TEST_ASSERT_EQUAL(1, service_remote_launch_flag,
400 "Ex-service core function call had no effect.");
402 return unregister_all();
406 service_lcore_running_check(void)
408 uint64_t tick = service_tick;
409 rte_delay_ms(SERVICE_DELAY * 100);
410 /* if (tick != service_tick) we know the lcore as polled the service */
411 return tick != service_tick;
415 service_lcore_add_del(void)
417 /* check initial count */
418 TEST_ASSERT_EQUAL(0, rte_service_lcore_count(),
419 "Service lcore count has value before adding a lcore");
421 /* check service lcore add */
422 TEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_id),
423 "Add service core failed when not in use before");
424 TEST_ASSERT_EQUAL(-EALREADY, rte_service_lcore_add(slcore_id),
425 "Add service core failed to refuse in-use lcore");
428 TEST_ASSERT_EQUAL(1, rte_service_lcore_count(),
429 "Service core count not equal to one");
431 /* retrieve core list, checking lcore ids */
432 const uint32_t size = 4;
433 uint32_t service_core_ids[size];
434 int32_t n = rte_service_lcore_list(service_core_ids, size);
435 TEST_ASSERT_EQUAL(1, n, "Service core list return should equal 1");
436 TEST_ASSERT_EQUAL(slcore_id, service_core_ids[0],
437 "Service core list lcore must equal slcore_id");
439 /* recheck count, add more cores, and check count */
440 TEST_ASSERT_EQUAL(1, rte_service_lcore_count(),
441 "Service core count not equal to one");
442 uint32_t slcore_1 = rte_get_next_lcore(/* start core */ -1,
445 TEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_1),
446 "Service core add did not return zero");
447 uint32_t slcore_2 = rte_get_next_lcore(/* start core */ slcore_1,
450 TEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_2),
451 "Service core add did not return zero");
453 uint32_t count = rte_service_lcore_count();
454 const uint32_t cores_at_this_point = 3;
455 TEST_ASSERT_EQUAL(cores_at_this_point, count,
456 "Service core count %d, expected %d", count,
457 cores_at_this_point);
459 /* check longer service core list */
460 n = rte_service_lcore_list(service_core_ids, size);
461 TEST_ASSERT_EQUAL(3, n, "Service core list return should equal 3");
462 TEST_ASSERT_EQUAL(slcore_id, service_core_ids[0],
463 "Service core list[0] lcore must equal 1");
464 TEST_ASSERT_EQUAL(slcore_1, service_core_ids[1],
465 "Service core list[1] lcore must equal 2");
466 TEST_ASSERT_EQUAL(slcore_2, service_core_ids[2],
467 "Service core list[2] lcore must equal 3");
469 /* recheck count, remove lcores, check remaining lcore_id is correct */
470 TEST_ASSERT_EQUAL(3, rte_service_lcore_count(),
471 "Service core count not equal to three");
472 TEST_ASSERT_EQUAL(0, rte_service_lcore_del(slcore_1),
473 "Service core add did not return zero");
474 TEST_ASSERT_EQUAL(0, rte_service_lcore_del(slcore_2),
475 "Service core add did not return zero");
476 TEST_ASSERT_EQUAL(1, rte_service_lcore_count(),
477 "Service core count not equal to one");
478 n = rte_service_lcore_list(service_core_ids, size);
479 TEST_ASSERT_EQUAL(1, n, "Service core list return should equal one");
480 TEST_ASSERT_EQUAL(slcore_id, service_core_ids[0],
481 "Service core list[0] lcore must equal %d",
484 return unregister_all();
488 service_threaded_test(int mt_safe)
492 /* add next 2 cores */
493 uint32_t slcore_1 = rte_get_next_lcore(/* start core */ -1,
496 TEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_1),
497 "mt safe lcore add fail");
498 uint32_t slcore_2 = rte_get_next_lcore(/* start core */ slcore_1,
501 TEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_2),
502 "mt safe lcore add fail");
504 /* Use atomic locks to verify that two threads are in the same function
505 * at the same time. These are passed to the unit tests through the
506 * callback userdata parameter
508 uint32_t test_params[2];
509 memset(test_params, 0, sizeof(uint32_t) * 2);
511 /* register MT safe service. */
512 struct rte_service_spec service;
513 memset(&service, 0, sizeof(struct rte_service_spec));
514 service.callback_userdata = test_params;
515 snprintf(service.name, sizeof(service.name), MT_SAFE_SERVICE_NAME);
518 service.callback = dummy_mt_safe_cb;
519 service.capabilities |= RTE_SERVICE_CAP_MT_SAFE;
521 service.callback = dummy_mt_unsafe_cb;
524 TEST_ASSERT_EQUAL(0, rte_service_component_register(&service, &id),
525 "Register of MT SAFE service failed");
527 const uint32_t sid = 0;
528 TEST_ASSERT_EQUAL(0, rte_service_runstate_set(sid, 1),
529 "Starting valid service failed");
530 TEST_ASSERT_EQUAL(0, rte_service_map_lcore_set(sid, slcore_1, 1),
531 "Failed to enable lcore 1 on mt safe service");
532 TEST_ASSERT_EQUAL(0, rte_service_map_lcore_set(sid, slcore_2, 1),
533 "Failed to enable lcore 2 on mt safe service");
534 rte_service_lcore_start(slcore_1);
535 rte_service_lcore_start(slcore_2);
537 /* wait for the worker threads to run */
539 rte_service_lcore_stop(slcore_1);
540 rte_service_lcore_stop(slcore_2);
542 TEST_ASSERT_EQUAL(0, test_params[1],
543 "Service run with component runstate = 0");
545 /* enable backend runstate: the service should run after this */
546 rte_service_component_runstate_set(id, 1);
548 /* initialize to pass, see callback comment for details */
552 /* wait for lcores before start() */
553 rte_eal_wait_lcore(slcore_1);
554 rte_eal_wait_lcore(slcore_2);
556 rte_service_lcore_start(slcore_1);
557 rte_service_lcore_start(slcore_2);
559 /* wait for the worker threads to run */
561 rte_service_lcore_stop(slcore_1);
562 rte_service_lcore_stop(slcore_2);
564 TEST_ASSERT_EQUAL(1, test_params[1],
565 "MT Safe service not run by two cores concurrently");
566 TEST_ASSERT_EQUAL(0, rte_service_runstate_set(sid, 0),
567 "Failed to stop MT Safe service");
569 rte_eal_wait_lcore(slcore_1);
570 rte_eal_wait_lcore(slcore_2);
573 /* return the value of the callback pass_test variable to caller */
574 return test_params[1];
577 /* tests an MT SAFE service with two cores. The callback function ensures that
578 * two threads access the callback concurrently.
581 service_mt_safe_poll(void)
584 TEST_ASSERT_EQUAL(1, service_threaded_test(mt_safe),
585 "Error: MT Safe service not run by two cores concurrently");
589 /* tests a NON mt safe service with two cores, the callback is serialized
590 * using the atomic cmpset.
593 service_mt_unsafe_poll(void)
596 TEST_ASSERT_EQUAL(1, service_threaded_test(mt_safe),
597 "Error: NON MT Safe service run by two cores concurrently");
602 delay_as_a_mt_safe_service(void *args)
605 uint32_t *params = args;
607 /* retrieve done flag and atomic lock to inc/dec */
608 uint32_t *done = ¶ms[0];
609 rte_atomic32_t *lock = (rte_atomic32_t *)¶ms[1];
612 rte_atomic32_inc(lock);
614 if (rte_atomic32_read(lock) > 1)
615 /* pass: second core has simultaneously incremented */
617 rte_atomic32_dec(lock);
624 delay_as_a_service(void *args)
626 uint32_t *done = (uint32_t *)args;
633 service_run_on_app_core_func(void *arg)
635 uint32_t *delay_service_id = (uint32_t *)arg;
636 return rte_service_run_iter_on_app_lcore(*delay_service_id, 1);
640 service_app_lcore_poll_impl(const int mt_safe)
642 uint32_t params[2] = {0};
644 struct rte_service_spec service;
645 memset(&service, 0, sizeof(struct rte_service_spec));
646 snprintf(service.name, sizeof(service.name), MT_SAFE_SERVICE_NAME);
648 service.callback = delay_as_a_mt_safe_service;
649 service.callback_userdata = params;
650 service.capabilities |= RTE_SERVICE_CAP_MT_SAFE;
652 service.callback = delay_as_a_service;
653 service.callback_userdata = ¶ms;
657 TEST_ASSERT_EQUAL(0, rte_service_component_register(&service, &id),
658 "Register of app lcore delay service failed");
660 rte_service_component_runstate_set(id, 1);
661 rte_service_runstate_set(id, 1);
663 uint32_t app_core2 = rte_get_next_lcore(slcore_id, 1, 1);
664 rte_eal_wait_lcore(app_core2);
665 int app_core2_ret = rte_eal_remote_launch(service_run_on_app_core_func,
670 int app_core1_ret = service_run_on_app_core_func(&id);
672 /* flag done, then wait for the spawned 2nd core to return */
674 rte_eal_mp_wait_lcore();
676 /* core two gets launched first - and should hold the service lock */
677 TEST_ASSERT_EQUAL(0, app_core2_ret,
678 "App core2 : run service didn't return zero");
681 /* mt safe should have both cores return 0 for success */
682 TEST_ASSERT_EQUAL(0, app_core1_ret,
683 "MT Safe: App core1 didn't return 0");
685 /* core one attempts to run later - should be blocked */
686 TEST_ASSERT_EQUAL(-EBUSY, app_core1_ret,
687 "MT Unsafe: App core1 didn't return -EBUSY");
696 service_app_lcore_mt_safe(void)
698 const int mt_safe = 1;
699 return service_app_lcore_poll_impl(mt_safe);
703 service_app_lcore_mt_unsafe(void)
705 const int mt_safe = 0;
706 return service_app_lcore_poll_impl(mt_safe);
709 /* start and stop a service core - ensuring it goes back to sleep */
711 service_lcore_start_stop(void)
713 /* start service core and service, create mapping so tick() runs */
714 const uint32_t sid = 0;
715 TEST_ASSERT_EQUAL(0, rte_service_runstate_set(sid, 1),
716 "Starting valid service failed");
717 TEST_ASSERT_EQUAL(-EINVAL, rte_service_map_lcore_set(sid, slcore_id, 1),
718 "Enabling valid service on non-service core must fail");
721 TEST_ASSERT_EQUAL(-EINVAL, rte_service_lcore_start(slcore_id),
722 "Service core start without add should return EINVAL");
723 TEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_id),
724 "Service core add did not return zero");
725 TEST_ASSERT_EQUAL(0, rte_service_map_lcore_set(sid, slcore_id, 1),
726 "Enabling valid service on valid core failed");
727 TEST_ASSERT_EQUAL(0, rte_service_lcore_start(slcore_id),
728 "Service core start after add failed");
729 TEST_ASSERT_EQUAL(-EALREADY, rte_service_lcore_start(slcore_id),
730 "Service core expected as running but was stopped");
732 /* ensures core really is running the service function */
733 TEST_ASSERT_EQUAL(1, service_lcore_running_check(),
734 "Service core expected to poll service but it didn't");
737 TEST_ASSERT_EQUAL(-EBUSY, rte_service_lcore_stop(slcore_id),
738 "Service core running a service should return -EBUSY");
739 TEST_ASSERT_EQUAL(0, rte_service_runstate_set(sid, 0),
740 "Stopping valid service failed");
741 TEST_ASSERT_EQUAL(-EINVAL, rte_service_lcore_stop(100000),
742 "Invalid Service core stop should return -EINVAL");
743 TEST_ASSERT_EQUAL(0, rte_service_lcore_stop(slcore_id),
744 "Service core stop expected to return 0");
745 TEST_ASSERT_EQUAL(-EALREADY, rte_service_lcore_stop(slcore_id),
746 "Already stopped service core should return -EALREADY");
748 /* ensure service is not longer running */
749 TEST_ASSERT_EQUAL(0, service_lcore_running_check(),
750 "Service core expected to poll service but it didn't");
752 TEST_ASSERT_EQUAL(0, rte_service_lcore_del(slcore_id),
753 "Service core del did not return zero");
755 return unregister_all();
758 static struct unit_test_suite service_tests = {
759 .suite_name = "service core test suite",
760 .setup = testsuite_setup,
761 .teardown = testsuite_teardown,
763 TEST_CASE_ST(dummy_register, NULL, unregister_all),
764 TEST_CASE_ST(dummy_register, NULL, service_name),
765 TEST_CASE_ST(dummy_register, NULL, service_get_by_name),
766 TEST_CASE_ST(dummy_register, NULL, service_dump),
767 TEST_CASE_ST(dummy_register, NULL, service_attr_get),
768 TEST_CASE_ST(dummy_register, NULL, service_probe_capability),
769 TEST_CASE_ST(dummy_register, NULL, service_start_stop),
770 TEST_CASE_ST(dummy_register, NULL, service_lcore_add_del),
771 TEST_CASE_ST(dummy_register, NULL, service_lcore_start_stop),
772 TEST_CASE_ST(dummy_register, NULL, service_lcore_en_dis_able),
773 TEST_CASE_ST(dummy_register, NULL, service_mt_unsafe_poll),
774 TEST_CASE_ST(dummy_register, NULL, service_mt_safe_poll),
775 TEST_CASE_ST(dummy_register, NULL, service_app_lcore_mt_safe),
776 TEST_CASE_ST(dummy_register, NULL, service_app_lcore_mt_unsafe),
777 TEST_CASES_END() /**< NULL terminate unit test array */
782 test_service_common(void)
784 return unit_test_suite_runner(&service_tests);
787 REGISTER_TEST_COMMAND(service_autotest, test_service_common);