Skip to content

Commit

Permalink
add eventfd test in unit_test of fiber module.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengshuxin committed Dec 29, 2022
1 parent 8ab8682 commit 7dab9ca
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib_fiber/unit_test/io/eventfd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "stdafx.h"
#include "test_io.h"


int test_eventfd(AUT_LINE *test_line acl_unused, void *arg acl_unused)
{
#ifdef __linux__
int fd = eventfd(0, 0);

if (fd == -1) {
printf("create eventfd error %s\r\n", acl::last_serror());
return -1;
}

go[=] {
long long n;
ssize_t ret = read(fd, &n, sizeof(n));
if (ret != sizeof(n)) {
printf("read from eventfd %d error %s\r\n",
fd, acl::last_serror());
return -1;
}
};

go[=] {
long long n = 1000000;
ssize_t ret = write(fd, &n, sizeof(n));
if (ret != sizeof(n)) {
printf("write to eventfd %d error %s\r\n",
fd, acl::last_serror());
return -1;
}
};

acl::fiber::schedule();
#else
printf("eventfd only be supported on Linux\r\n");
return 0;
#endif
}
8 changes: 8 additions & 0 deletions lib_fiber/unit_test/io/io_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "stdafx.h"
#include "test_io.h"
#include "test_io_tab.h"

void io_register(void)
{
aut_register(__test_fn_tab);
}
7 changes: 7 additions & 0 deletions lib_fiber/unit_test/io/test_io.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

/* In io_main.cpp */
void io_register(void);

/* In eventfd.cpp */
int test_eventfd(AUT_LINE *test_line, void *arg);
10 changes: 10 additions & 0 deletions lib_fiber/unit_test/io/test_io_tab.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

static AUT_FN_ITEM __test_fn_tab[] = {
/* 命令字名称 函数提示名 回调函数名称 回调参数 是否是内部命令 */

/* In eventfd.cpp */
{ "test_eventfd", "test_eventfd", test_eventfd, NULL, 0 },

{ NULL, NULL, NULL, NULL, 0 },
};
1 change: 1 addition & 0 deletions lib_fiber/unit_test/test.cf
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ tbox_mixed_consume|0|0|threads_consumer=1,threads_producer=1,threads_consumer_al
tbox_mixed_consume|0|0|threads_consumer=2,threads_producer=2,threads_consumer_alone=2,threads_producer_alone=2,fibers=10,delay=500,count=1000
file_load|0|0|filename=main.cpp
file_load|0|0|filename=Makefile.in,show=1
test_eventfd|0|0|
2 changes: 2 additions & 0 deletions lib_fiber/unit_test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "tbox/test_tbox.h"
#include "file/test_file.h"
#include "io/test_io.h"

typedef struct {
const char *label;
Expand All @@ -11,6 +12,7 @@ typedef struct {
static TEST_ENTRY __test_entry_tab[] = {
{ "test_tbox", tbox_register },
{ "test_file", file_register },
{ "test_io", io_register },

{ NULL, NULL },
};

0 comments on commit 7dab9ca

Please sign in to comment.