From 2275f7da7370d5b403a5d4a9d558c34a38ee5c94 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 19 Feb 2016 18:14:20 -0800 Subject: adb: sysdeps_test: improve smoke test. Make sure that adb_poll sets revents for all of the structs passed in. Also, zero initialize all of the adb_pollfd structs in the tests. Change-Id: Ia639679a7e6f77483655f1552e89081c4673aa87 --- adb/sysdeps_test.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'adb') diff --git a/adb/sysdeps_test.cpp b/adb/sysdeps_test.cpp index 3904cc0b5..78efea8ad 100644 --- a/adb/sysdeps_test.cpp +++ b/adb/sysdeps_test.cpp @@ -122,12 +122,14 @@ class sysdeps_poll : public ::testing::Test { }; TEST_F(sysdeps_poll, smoke) { - adb_pollfd pfd[2]; + adb_pollfd pfd[2] = {}; pfd[0].fd = fds[0]; pfd[0].events = POLLRDNORM; pfd[1].fd = fds[1]; pfd[1].events = POLLWRNORM; + pfd[0].revents = -1; + pfd[1].revents = -1; EXPECT_EQ(1, adb_poll(pfd, 2, 0)); EXPECT_EQ(0, pfd[0].revents); EXPECT_EQ(POLLWRNORM, pfd[1].revents); @@ -135,16 +137,18 @@ TEST_F(sysdeps_poll, smoke) { ASSERT_TRUE(WriteFdExactly(fds[1], "foo", 4)); // Wait for the socketpair to be flushed. + pfd[0].revents = -1; EXPECT_EQ(1, adb_poll(pfd, 1, 100)); EXPECT_EQ(POLLRDNORM, pfd[0].revents); - + pfd[0].revents = -1; + pfd[1].revents = -1; EXPECT_EQ(2, adb_poll(pfd, 2, 0)); EXPECT_EQ(POLLRDNORM, pfd[0].revents); EXPECT_EQ(POLLWRNORM, pfd[1].revents); } TEST_F(sysdeps_poll, timeout) { - adb_pollfd pfd; + adb_pollfd pfd = {}; pfd.fd = fds[0]; pfd.events = POLLRDNORM; @@ -158,7 +162,7 @@ TEST_F(sysdeps_poll, timeout) { } TEST_F(sysdeps_poll, invalid_fd) { - adb_pollfd pfd[3]; + adb_pollfd pfd[3] = {}; pfd[0].fd = fds[0]; pfd[0].events = POLLRDNORM; pfd[1].fd = INT_MAX; @@ -179,7 +183,7 @@ TEST_F(sysdeps_poll, invalid_fd) { } TEST_F(sysdeps_poll, duplicate_fd) { - adb_pollfd pfd[2]; + adb_pollfd pfd[2] = {}; pfd[0].fd = fds[0]; pfd[0].events = POLLRDNORM; pfd[1] = pfd[0]; @@ -196,7 +200,7 @@ TEST_F(sysdeps_poll, duplicate_fd) { } TEST_F(sysdeps_poll, disconnect) { - adb_pollfd pfd; + adb_pollfd pfd = {}; pfd.fd = fds[0]; pfd.events = POLLIN; -- cgit v1.2.3