-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathprocess.cc
65 lines (55 loc) · 1.12 KB
/
process.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
55
56
57
58
59
60
61
62
63
64
65
#include "tests.h"
#include "crucible/process.h"
#include <ios>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <stdexcept>
#include <unistd.h>
using namespace crucible;
using namespace std;
static inline
int
return_value(int val)
{
// cerr << "pid " << getpid() << " returning " << val << endl;
return val;
}
static inline
int
return_value_2(int val, int val2)
{
return val + val2;
}
static inline
void
test_fork_return(int val)
{
Pid child(return_value, val);
assert(child == child->get_id());
assert(child == child->native_handle());
int status = child->join();
int rv_status = WEXITSTATUS(status);
assert(WIFEXITED(status));
assert(rv_status == val);
}
static inline
void
test_fork_return(int val, int val2)
{
Pid child(return_value_2, val, val2);
int status = child->join();
int rv_status = WEXITSTATUS(status);
assert(WIFEXITED(status));
assert(rv_status == val + val2);
}
int
main(int, char**)
{
RUN_A_TEST(test_fork_return(0));
RUN_A_TEST(test_fork_return(1));
RUN_A_TEST(test_fork_return(9));
RUN_A_TEST(test_fork_return(2, 3));
RUN_A_TEST(test_fork_return(7, 9));
exit(EXIT_SUCCESS);
}