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