Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4f2d97cd authored by Alan Stokes's avatar Alan Stokes
Browse files

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
parent 4febfd6d
Loading
Loading
Loading
Loading
+10 −8
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <sys/statvfs.h>
#include <sys/statvfs.h>
#include <sys/stat.h>
#include <sys/xattr.h>
#include <sys/xattr.h>


#include <android-base/file.h>
#include <android-base/file.h>
@@ -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) {
static void mkdir(const char* path, uid_t owner, gid_t group, mode_t mode) {
    const std::string fullPath = get_full_path(path);
    const std::string fullPath = get_full_path(path);
    ::mkdir(fullPath.c_str(), mode);
    EXPECT_EQ(::mkdir(fullPath.c_str(), mode), 0);
    ::chown(fullPath.c_str(), owner, group);
    EXPECT_EQ(::chown(fullPath.c_str(), owner, group), 0);
    ::chmod(fullPath.c_str(), mode);
    EXPECT_EQ(::chmod(fullPath.c_str(), mode), 0);
}
}


static void touch(const char* path, uid_t owner, gid_t group, mode_t mode) {
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);
    int fd = ::open(get_full_path(path).c_str(), O_RDWR | O_CREAT, mode);
    ::fchown(fd, owner, group);
    EXPECT_NE(fd, -1);
    ::fchmod(fd, mode);
    EXPECT_EQ(::fchown(fd, owner, group), 0);
    ::close(fd);
    EXPECT_EQ(::fchmod(fd, mode), 0);
    EXPECT_EQ(::close(fd), 0);
}
}


static int stat_gid(const char* path) {
static int stat_gid(const char* path) {
    struct stat buf;
    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;
    return buf.st_gid;
}
}


static int stat_mode(const char* path) {
static int stat_mode(const char* path) {
    struct stat buf;
    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);
    return buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISGID);
}
}