test_tle_udp_event.h revision aa97dd1c
1a152c68eSDaniel Mrzyglod/*
2a152c68eSDaniel Mrzyglod * Copyright (c) 2016  Intel Corporation.
3a152c68eSDaniel Mrzyglod * Licensed under the Apache License, Version 2.0 (the "License");
4a152c68eSDaniel Mrzyglod * you may not use this file except in compliance with the License.
5a152c68eSDaniel Mrzyglod * You may obtain a copy of the License at:
6a152c68eSDaniel Mrzyglod *
7a152c68eSDaniel Mrzyglod *     http://www.apache.org/licenses/LICENSE-2.0
8a152c68eSDaniel Mrzyglod *
9a152c68eSDaniel Mrzyglod * Unless required by applicable law or agreed to in writing, software
10a152c68eSDaniel Mrzyglod * distributed under the License is distributed on an "AS IS" BASIS,
11a152c68eSDaniel Mrzyglod * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12a152c68eSDaniel Mrzyglod * See the License for the specific language governing permissions and
13a152c68eSDaniel Mrzyglod * limitations under the License.
14a152c68eSDaniel Mrzyglod */
15a152c68eSDaniel Mrzyglod
16a152c68eSDaniel Mrzyglod#ifndef TEST_TLE_UDP_EVENT_H_
17a152c68eSDaniel Mrzyglod#define TEST_TLE_UDP_EVENT_H_
18a152c68eSDaniel Mrzyglod
19a152c68eSDaniel Mrzyglod#include <gtest/gtest.h>
20a152c68eSDaniel Mrzyglod#include <rte_errno.h>
21aa97dd1cSKonstantin Ananyev#include <tle_ctx.h>
22a152c68eSDaniel Mrzyglod#include <tle_event.h>
23a152c68eSDaniel Mrzyglod
24a152c68eSDaniel Mrzyglodstruct event_state_active {
25a152c68eSDaniel Mrzyglod	enum tle_ev_state event_state;
26a152c68eSDaniel Mrzyglod};
27a152c68eSDaniel Mrzyglod
28a152c68eSDaniel Mrzyglodstruct event_state_active_twice {
29a152c68eSDaniel Mrzyglod	enum tle_ev_state first_state;
30a152c68eSDaniel Mrzyglod	enum tle_ev_state second_state;
31a152c68eSDaniel Mrzyglod	enum tle_ev_state result_state;
32a152c68eSDaniel Mrzyglod};
33a152c68eSDaniel Mrzyglod
34a152c68eSDaniel Mrzyglodclass udp_evq : public ::testing::Test {
35a152c68eSDaniel Mrzyglodprotected:
36a152c68eSDaniel Mrzyglod
37a152c68eSDaniel Mrzyglod	/* Can parameterize here for
38a152c68eSDaniel Mrzyglod	 * different socket_id and max_events values
39a152c68eSDaniel Mrzyglod	 */
40a152c68eSDaniel Mrzyglod	int32_t socket_id;
41a152c68eSDaniel Mrzyglod	uint32_t max_events;
42a152c68eSDaniel Mrzyglod	struct tle_evq_param evq_params;
43a152c68eSDaniel Mrzyglod	struct tle_evq *evq;
44a152c68eSDaniel Mrzyglod
45a152c68eSDaniel Mrzyglod	virtual void SetUp(void)
46a152c68eSDaniel Mrzyglod	{
47a152c68eSDaniel Mrzyglod		socket_id = SOCKET_ID_ANY;
48a152c68eSDaniel Mrzyglod		max_events = 10;
49a152c68eSDaniel Mrzyglod		rte_errno = 0;
50a152c68eSDaniel Mrzyglod		memset(&evq_params, 0, sizeof(struct tle_evq_param));
51a152c68eSDaniel Mrzyglod		evq_params.socket_id = socket_id;
52a152c68eSDaniel Mrzyglod		evq_params.max_events = max_events;
53a152c68eSDaniel Mrzyglod	}
54a152c68eSDaniel Mrzyglod
55a152c68eSDaniel Mrzyglod	virtual void TearDown(void)
56a152c68eSDaniel Mrzyglod	{
57a152c68eSDaniel Mrzyglod	}
58a152c68eSDaniel Mrzyglod};
59a152c68eSDaniel Mrzyglod
60a152c68eSDaniel Mrzyglodclass udp_event : public ::udp_evq {
61a152c68eSDaniel Mrzyglodprotected:
62a152c68eSDaniel Mrzyglod
63a152c68eSDaniel Mrzyglod	int fake_data;
64a152c68eSDaniel Mrzyglod	struct tle_event *event;
65a152c68eSDaniel Mrzyglod
66a152c68eSDaniel Mrzyglod	virtual void SetUp(void)
67a152c68eSDaniel Mrzyglod	{
68a152c68eSDaniel Mrzyglod		udp_evq::SetUp();
69a152c68eSDaniel Mrzyglod		evq = tle_evq_create(&evq_params);
70a152c68eSDaniel Mrzyglod		ASSERT_NE(evq, (struct tle_evq *) NULL);
71a152c68eSDaniel Mrzyglod		EXPECT_EQ(rte_errno, 0);
72a152c68eSDaniel Mrzyglod	}
73a152c68eSDaniel Mrzyglod
74a152c68eSDaniel Mrzyglod	virtual void TearDown(void)
75a152c68eSDaniel Mrzyglod	{
76a152c68eSDaniel Mrzyglod		tle_evq_destroy(evq);
77a152c68eSDaniel Mrzyglod	}
78a152c68eSDaniel Mrzyglod};
79a152c68eSDaniel Mrzyglod
80a152c68eSDaniel Mrzyglodclass udp_event_state : public ::udp_event {
81a152c68eSDaniel Mrzyglodprotected:
82a152c68eSDaniel Mrzyglod
83a152c68eSDaniel Mrzyglod	virtual void SetUp(void)
84a152c68eSDaniel Mrzyglod	{
85a152c68eSDaniel Mrzyglod		udp_event::SetUp();
86a152c68eSDaniel Mrzyglod		event = tle_event_alloc(evq, (void *) &fake_data);
87a152c68eSDaniel Mrzyglod		ASSERT_NE(event, (struct tle_event *) NULL);
88a152c68eSDaniel Mrzyglod	}
89a152c68eSDaniel Mrzyglod
90a152c68eSDaniel Mrzyglod	virtual void TearDown(void)
91a152c68eSDaniel Mrzyglod	{
92a152c68eSDaniel Mrzyglod		tle_event_free(event);
93a152c68eSDaniel Mrzyglod		udp_event::TearDown();
94a152c68eSDaniel Mrzyglod	}
95a152c68eSDaniel Mrzyglod};
96a152c68eSDaniel Mrzyglod
97a152c68eSDaniel Mrzyglodstruct udp_event_state_active : ::udp_event_state,
98a152c68eSDaniel Mrzyglodtesting::WithParamInterface < event_state_active > {
99a152c68eSDaniel Mrzyglod	udp_event_state_active() {}
100a152c68eSDaniel Mrzyglod};
101a152c68eSDaniel Mrzyglod
102a152c68eSDaniel Mrzyglodstruct udp_event_state_active_twice : ::udp_event_state,
103a152c68eSDaniel Mrzyglodtesting::WithParamInterface < event_state_active_twice > {
104a152c68eSDaniel Mrzyglod	udp_event_state_active_twice() {}
105a152c68eSDaniel Mrzyglod};
106a152c68eSDaniel Mrzyglod
107a152c68eSDaniel Mrzyglodstruct udp_event_state_idle : ::udp_event_state_active {
108a152c68eSDaniel Mrzyglod};
109a152c68eSDaniel Mrzyglod
110a152c68eSDaniel Mrzyglod#endif /* TEST_TLE_UDP_EVENT_H_ */
111