[dpdk-dev,v6,19/23] test: exercise event timer arm and expiry
Checks
Commit Message
Add a test that creates an event timer and detects the generation of a
timer expiry event being scheduled through the software event device.
Signed-off-by: Erik Gabriel Carrillo <erik.g.carrillo@intel.com>
---
test/test/test_event_timer_adapter.c | 106 +++++++++++++++++++++++++++++++++++
1 file changed, 106 insertions(+)
Comments
On Wed, Jan 10, 2018 at 06:21:10PM -0600, Erik Gabriel Carrillo wrote:
> Add a test that creates an event timer and detects the generation of a
> timer expiry event being scheduled through the software event device.
>
> Signed-off-by: Erik Gabriel Carrillo <erik.g.carrillo@intel.com>
> ---
> test/test/test_event_timer_adapter.c | 106 +++++++++++++++++++++++++++++++++++
> 1 file changed, 106 insertions(+)
>
Please consider following common_code -> sw_dev -> test -> doc so that it would
be easy to review. Some patches could be squashed into one.
<snip>
@@ -319,6 +319,111 @@ adapter_start_stop(void)
return TEST_SUCCESS;
}
+#define BATCH_SIZE 16
+static int
+event_timer_expiry(void)
+{
+ uint16_t n;
+ uint32_t evdev_service_id, adapter_service_id;
+ int ret;
+ struct rte_event_timer_adapter *adapter = g_adapter;
+ struct rte_event_timer *evtim = NULL;
+ struct rte_event_timer *evtim2 = NULL;
+ struct rte_event evs[BATCH_SIZE];
+
+ TEST_ASSERT_SUCCESS(rte_event_dev_service_id_get(evdev,
+ &evdev_service_id), "Failed to get "
+ "event device service id");
+
+ TEST_ASSERT(rte_service_lcore_count() > 0, "Need one or more service "
+ "cores to perform this test");
+
+ TEST_ASSERT_SUCCESS(rte_event_timer_adapter_service_id_get(g_adapter,
+ &adapter_service_id), "Failed to get "
+ "event timer adapter service id");
+
+ /* Could map using service_id, but just do default mapping */
+ ret = rte_service_start_with_defaults();
+ TEST_ASSERT_SUCCESS(ret, "Failed to start services");
+
+ if (rte_event_dev_start(evdev) < 0) {
+ printf("Failed to start event device\n");
+ return TEST_FAILED;
+ }
+
+ ret = rte_event_timer_adapter_start(adapter);
+ if (ret < 0) {
+ printf("Failed to start adapter\n");
+ return TEST_FAILED;
+ }
+
+ /* Set up an event timer */
+ rte_mempool_get(g_event_timer_pool, (void **)&evtim);
+ if (evtim == NULL) {
+ /* Failed to get an event timer object */
+ return TEST_FAILED;
+ }
+
+ rte_event_timer_init(evtim);
+
+ evtim->ev.event_ptr = evtim;
+ evtim->ev.queue_id = TEST_QUEUE_ID;
+ evtim->ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
+ evtim->timeout_ticks = 30; // expire in 3 sec
+
+ ret = rte_event_timer_arm_burst(adapter, &evtim, 1);
+ if (ret != 1) {
+ printf("Failed to arm event timer: %s\n",
+ rte_strerror(rte_errno));
+ return TEST_FAILED;
+ }
+
+ rte_delay_ms(2999);
+
+ n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), 0);
+ TEST_ASSERT_EQUAL(n, 0, "Dequeued unexpected timer expiry event");
+
+ /* Delay 1 more millisecond and run the services again - should let us
+ * dequeue one event
+ */
+ rte_delay_ms(1);
+
+ n = rte_event_dequeue_burst(evdev, TEST_PORT_ID, evs, RTE_DIM(evs), 0);
+ if (n == 0) {
+ printf("Failed to dequeue timer expiry event\n");
+ return TEST_FAILED;
+ }
+
+ if (n > 1) {
+ printf("Dequeued incorrect number (%d) of timer expiry "
+ "events\n", n);
+ return TEST_FAILED;
+ }
+
+ if (evs[0].event_type != RTE_EVENT_TYPE_TIMER) {
+ printf("Dequeued unexpected type of event\n");
+ return TEST_FAILED;
+ }
+
+ /* Check that we recover the original event timer and then free it */
+ evtim2 = evs[0].event_ptr;
+ TEST_ASSERT_EQUAL(evtim, evtim2,
+ "Failed to recover pointer to original event timer");
+ rte_mempool_put(g_event_timer_pool, evtim2);
+
+ ret = rte_event_timer_adapter_stop(adapter);
+ if (ret < 0) {
+ printf("Failed to stop event adapter\n");
+ return TEST_FAILED;
+ }
+
+ rte_event_dev_stop(evdev);
+
+ rte_service_lcore_reset_all();
+
+ return TEST_SUCCESS;
+}
+
static struct unit_test_suite adapter_tests = {
.suite_name = "event timer adapter test suite",
.setup = testsuite_setup,
@@ -326,6 +431,7 @@ static struct unit_test_suite adapter_tests = {
.unit_test_cases = {
TEST_CASE(adapter_create_free),
TEST_CASE_ST(adapter_create, adapter_free, adapter_start_stop),
+ TEST_CASE_ST(adapter_create, adapter_free, event_timer_expiry),
TEST_CASES_END() /**< NULL terminate unit test array */
}
};