-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_ioproc.cc
54 lines (44 loc) · 1019 Bytes
/
test_ioproc.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "gtest/gtest.h"
#include "ten/ioproc.hh"
#include "ten/descriptors.hh"
using namespace ten;
static void ioproc_sleeper() {
ioproc io;
int ret = iocall(io, std::bind(usleep, 100));
EXPECT_EQ(ret, 0);
}
TEST(IoProc, Sleep) {
task::main([] {
task::spawn(ioproc_sleeper);
});
}
static void test_pool() {
ioproc io{nostacksize, 4};
iochannel reply_chan;
for (int i=0; i<4; ++i) {
iocallasync(io, std::bind(usleep, 100), reply_chan);
}
for (int i=0; i<4; ++i) {
int r = iowait<int>(reply_chan);
// usleep should return 0
EXPECT_EQ(0, r);
}
}
TEST(IoProc, ThreadPool) {
task::main([] {
task::spawn(test_pool);
});
}
static void fail() {
throw std::runtime_error("fail has failed");
}
static void ioproc_failure() {
ioproc io;
std::string errmsg;
EXPECT_THROW(iocall(io, fail), std::runtime_error);
}
TEST(IoProc, Failure) {
task::main([] {
task::spawn(ioproc_failure);
});
}