Skip to content

Commit adfb59b

Browse files
committed
core: event: add new 'loop' test interfaces
Signed-off-by: Eduardo Silva <[email protected]>
1 parent ed4ef23 commit adfb59b

File tree

4 files changed

+152
-1
lines changed

4 files changed

+152
-1
lines changed

core/event/loop/Makefile.in

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
NAME = qa
2+
CC = gcc
3+
CFLAGS = -g -Wall
4+
LDFLAGS =
5+
DEFS =
6+
INCDIR =
7+
OBJECTS = main.o

core/event/loop/main.c

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+
#include "webservice.h"
4+
5+
DUDA_REGISTER("Duda QA", "Unit Test");
6+
7+
int status_loop_create = -1;
8+
int status_timeout = -1;
9+
int status_channel_create = -1;
10+
int status_channel_rw = -1;
11+
int status_add = -1;
12+
int status_delete = -1;
13+
int status_check_timeout = -1;
14+
int status_check_ch_w = -1;
15+
int status_check_ch_r = -1;
16+
char *status_backend = NULL;
17+
18+
void *cb_worker(void *data)
19+
{
20+
int i;
21+
int n;
22+
int pfd[2];
23+
int ret;
24+
int fd_timeout;
25+
int fd_ch_r = -1;
26+
int fd_ch_w = -1;
27+
mk_event_loop_t *evl;
28+
29+
/* create the event loop */
30+
evl = event->loop_create(64);
31+
if (evl) {
32+
status_loop_create = 0;
33+
}
34+
35+
fd_timeout = event->loop_timeout_create(evl, 2);
36+
if (fd_timeout > 0) {
37+
status_timeout = 0;
38+
}
39+
40+
ret = event->loop_channel_create(evl, &fd_ch_r, &fd_ch_w);
41+
if (ret == 0) {
42+
status_channel_create = 0;
43+
}
44+
if (fd_ch_r > 0 && fd_ch_w > 0) {
45+
status_channel_rw = 0;
46+
}
47+
48+
pipe(pfd);
49+
ret = event->loop_add(evl, pfd[0], DUDA_EVENT_READ, NULL);
50+
if (ret == 0) {
51+
status_add = 0;
52+
}
53+
54+
ret = event->loop_delete(evl, pfd[0]);
55+
if (ret == 0) {
56+
status_delete = 0;
57+
}
58+
59+
status_backend = event->loop_backend();
60+
61+
while (1) {
62+
n = event->loop_wait(evl);
63+
for (i = 0; i < n; i ++) {
64+
int fd = evl->events[i].fd;
65+
uint64_t val;
66+
67+
if (fd == fd_timeout) {
68+
ret = read(fd_timeout, &val, sizeof(val));
69+
if (ret > 0) {
70+
status_check_timeout = 0;
71+
}
72+
73+
val = 0xdeadbeef;
74+
ret = write(fd_ch_w, &val, sizeof(val));
75+
if (ret > 0) {
76+
status_check_ch_w = 0;
77+
}
78+
}
79+
else if (fd == fd_ch_r) {
80+
ret = read(fd_ch_r, &val, sizeof(val));
81+
if (ret > 0 && val == 0xdeadbeef) {
82+
status_check_ch_r = 0;
83+
}
84+
}
85+
}
86+
}
87+
88+
return NULL;
89+
}
90+
91+
void cb_test(duda_request_t *dr)
92+
{
93+
/* silly delay to let the worker timeout do its job */
94+
sleep(3);
95+
96+
response->http_status(dr, 200);
97+
response->printf(dr, "status_loop_create=%i\n", status_loop_create);
98+
response->printf(dr, "status_timeout=%i\n", status_timeout);
99+
response->printf(dr, "status_channel_create=%i\n", status_channel_create);
100+
response->printf(dr, "status_channel_rw=%i\n", status_channel_rw);
101+
response->printf(dr, "status_add=%i\n", status_add);
102+
response->printf(dr, "status_delete=%i\n", status_delete);
103+
response->printf(dr, "status_check_timeout=%i\n", status_check_timeout);
104+
response->printf(dr, "status_check_ch_w=%i\n", status_check_ch_w);
105+
response->printf(dr, "status_check_ch_r=%i\n", status_check_ch_r);
106+
response->printf(dr, "status_backend=%s\n", status_backend);
107+
108+
response->end(dr, NULL);
109+
}
110+
111+
int duda_main()
112+
{
113+
worker->spawn(cb_worker, NULL);
114+
router->map("/test", cb_test);
115+
return 0;
116+
}

core/event/loop/qa.htt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
INCLUDE ../../../setup/httest.conf
2+
3+
CLIENT
4+
_REQ $HOST $PORT
5+
__GET /qa/test $HTTPVER
6+
__Host: $HOST
7+
__
8+
_EXPECT . "HTTP/1.1 200 OK"
9+
_EXPECT . "status_loop_create=0"
10+
_EXPECT . "status_timeout=0"
11+
_EXPECT . "status_channel_create=0"
12+
_EXPECT . "status_channel_rw=0"
13+
_EXPECT . "status_add=0"
14+
_EXPECT . "status_delete=0"
15+
_EXPECT . "status_check_timeout=0"
16+
_EXPECT . "status_check_ch_w=0"
17+
_EXPECT . "status_check_ch_r=0"
18+
_EXPECT . "status_backend=epoll"
19+
_WAIT
20+
END

run

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ CORE_UT = {'console': ['dashboard_01',
2121
'fconf': None,
2222
'event': ['signal_callback',
2323
'create_signal_fd',
24-
'events'
24+
'events',
25+
'loop'
2526
],
2627
'log_writer': None,
2728
'param': None,
@@ -114,6 +115,10 @@ def http_ping_wait():
114115

115116
return -1
116117

118+
def check_tcp_port():
119+
ret = subprocess.call('curl -i -s -o /dev/null http://localhost:9897', shell=True)
120+
print ret
121+
117122
# Evaluate a running service with it test scripts
118123
def qa_eval(proc, path):
119124
pre = None
@@ -157,6 +162,9 @@ def qa_eval(proc, path):
157162

158163
os.chdir(cpath)
159164

165+
166+
#print check_tcp_port()
167+
160168
# Run the tests
161169
for section in CORE_UT:
162170
print_info(section)

0 commit comments

Comments
 (0)