From 4f2d97cda16de377e9b8e13919d7763e8be6f8f2 Mon Sep 17 00:00:00 2001 From: Alan Stokes Date: Tue, 5 Feb 2019 17:53:24 +0000 Subject: [PATCH] Add missing error checks in tests. To ensure we don't get tests spuriously passing when setup has failed. Test: atest installd_service_test Bug: 78442602 Change-Id: I32c8dc4f3d2b9d6dc0f289b170fd13198c87cac3 --- cmds/installd/tests/installd_service_test.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cmds/installd/tests/installd_service_test.cpp b/cmds/installd/tests/installd_service_test.cpp index 73277100d1..ed1a0f4e4c 100644 --- a/cmds/installd/tests/installd_service_test.cpp +++ b/cmds/installd/tests/installd_service_test.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -70,27 +71,28 @@ static std::string get_full_path(const char* path) { static void mkdir(const char* path, uid_t owner, gid_t group, mode_t mode) { const std::string fullPath = get_full_path(path); - ::mkdir(fullPath.c_str(), mode); - ::chown(fullPath.c_str(), owner, group); - ::chmod(fullPath.c_str(), mode); + EXPECT_EQ(::mkdir(fullPath.c_str(), mode), 0); + EXPECT_EQ(::chown(fullPath.c_str(), owner, group), 0); + EXPECT_EQ(::chmod(fullPath.c_str(), mode), 0); } static void touch(const char* path, uid_t owner, gid_t group, mode_t mode) { int fd = ::open(get_full_path(path).c_str(), O_RDWR | O_CREAT, mode); - ::fchown(fd, owner, group); - ::fchmod(fd, mode); - ::close(fd); + EXPECT_NE(fd, -1); + EXPECT_EQ(::fchown(fd, owner, group), 0); + EXPECT_EQ(::fchmod(fd, mode), 0); + EXPECT_EQ(::close(fd), 0); } static int stat_gid(const char* path) { struct stat buf; - ::stat(get_full_path(path).c_str(), &buf); + EXPECT_EQ(::stat(get_full_path(path).c_str(), &buf), 0); return buf.st_gid; } static int stat_mode(const char* path) { struct stat buf; - ::stat(get_full_path(path).c_str(), &buf); + EXPECT_EQ(::stat(get_full_path(path).c_str(), &buf), 0); return buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISGID); } -- 2.11.0