-
Notifications
You must be signed in to change notification settings - Fork 936
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add eventfd test in unit_test of fiber module.
- Loading branch information
1 parent
8ab8682
commit 7dab9ca
Showing
6 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters