YARN-8437. Build oom-listener fails on older versions. (Miklos Szegedi via Haibo Chen)

This commit is contained in:
Haibo Chen 2018-06-20 10:35:52 -07:00
parent 2d87592fc6
commit 4939ffedb1
2 changed files with 19 additions and 18 deletions

View File

@ -188,5 +188,5 @@ add_executable(test-oom-listener
main/native/oom-listener/impl/oom_listener.h
main/native/oom-listener/test/oom_listener_test_main.cc
)
target_link_libraries(test-oom-listener gtest)
target_link_libraries(test-oom-listener gtest rt)
output_directory(test-oom-listener test)

View File

@ -20,6 +20,7 @@
extern "C" {
#include "oom_listener.h"
#include <time.h>
}
#include <gtest/gtest.h>
@ -49,10 +50,10 @@ int main(int argc, char **argv) {
class OOMListenerTest : public ::testing::Test {
private:
char cgroup[PATH_MAX] = {};
const char* cgroup_root = nullptr;
char cgroup[PATH_MAX];
const char* cgroup_root;
public:
OOMListenerTest() = default;
OOMListenerTest() : cgroup_root(NULL) {}
virtual ~OOMListenerTest() = default;
virtual const char* GetCGroup() { return cgroup; }
@ -99,7 +100,7 @@ public:
if (cgroup[0] != '\0') {
rmdir(cgroup);
}
if (cgroup_root != nullptr &&
if (cgroup_root != NULL &&
cgroup_root != cgroup_candidates[0]) {
rmdir(cgroup_root);
}
@ -184,7 +185,7 @@ TEST_F(OOMListenerTest, test_oom) {
std::cout << "Consuming too much memory" << std::endl;
for (;;) {
auto buffer = (char *) malloc(bufferSize);
if (buffer != nullptr) {
if (buffer != NULL) {
for (int i = 0; i < bufferSize; ++i) {
buffer[i] = (char) std::rand();
}
@ -213,15 +214,15 @@ TEST_F(OOMListenerTest, test_oom) {
if (listener == 0) {
// child listener forwarding cgroup events
_oom_listener_descriptors descriptors = {
.command = "test",
.event_fd = mock_oom_event_as_user,
.event_control_fd = -1,
.oom_control_fd = -1,
.event_control_path = {0},
.oom_control_path = {0},
.oom_command = {0},
.oom_command_len = 0,
.watch_timeout = 100
"test",
mock_oom_event_as_user,
-1,
-1,
{0},
{0},
{0},
0,
100
};
int ret = oom_listener(&descriptors, GetCGroup(), test_pipe[1]);
cleanup(&descriptors);
@ -256,7 +257,7 @@ TEST_F(OOMListenerTest, test_oom) {
__pid_t exited0 = wait(mem_hog_status);
ASSERT_EQ(mem_hog_pid, exited0)
<< "Wrong process exited";
ASSERT_EQ(nullptr, mem_hog_status)
ASSERT_EQ(NULL, mem_hog_status)
<< "Test process killed with invalid status";
if (mock_oom_event_as_user != -1) {
@ -275,7 +276,7 @@ TEST_F(OOMListenerTest, test_oom) {
__pid_t exited1 = wait(oom_listener_status);
ASSERT_EQ(listener, exited1)
<< "Wrong process exited";
ASSERT_EQ(nullptr, oom_listener_status)
ASSERT_EQ(NULL, oom_listener_status)
<< "Listener process exited with invalid status";
}
}