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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/vespalib/util/slaveproc.h>
using namespace vespalib;
class Test : public TestApp
{
public:
int Main() override;
private:
bool useProcessStarter() const override { return true; }
};
int Test::Main()
{
TEST_INIT("expectsignal_test");
EXPECT_EQUAL(_argc, 3);
ASSERT_TRUE(_argc == 3);
int retval = strtol(_argv[1], NULL, 0);
fprintf(stderr, "argc=%d : Running '%s' expecting signal %d\n", _argc, _argv[2], retval);
SlaveProc cmd(_argv[2]);
for(std::string line; cmd.readLine(line, 60000);) {
fprintf(stdout, "%s\n", line.c_str());
}
ASSERT_TRUE(cmd.wait(60000));
int exitCode = cmd.getExitCode();
if (exitCode == 65535) {
fprintf(stderr, "[ERROR] child killed (timeout)\n");
} else if (WIFEXITED(exitCode)) {
fprintf(stderr, "child terminated normally with exit code %u\n", WEXITSTATUS(exitCode));
} else if (WIFSIGNALED(exitCode)) {
fprintf(stderr, "child terminated by signal %u\n", WTERMSIG(exitCode));
if (WCOREDUMP(exitCode)) {
fprintf(stderr, "[WARNING] child dumped core\n");
}
} else {
fprintf(stderr, "[WARNING] strange exit code: %u\n", exitCode);
}
EXPECT_EQUAL(exitCode & 0x7f, retval);
TEST_DONE();
}
TEST_APPHOOK(Test)
|