Merge "task_profiles_test: Skip this test if cgroups is read-only" am: 229d3d27d8

Original change: https://android-review.googlesource.com/c/platform/system/core/+/2549390

Change-Id: I339db85d4bb3435c5589315a5d045d23f3498cf6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot 2023-04-20 00:44:07 +00:00 committed by Automerger Merge Worker
commit b9fd48a4e6

View file

@ -16,6 +16,7 @@
#include "task_profiles.h"
#include <android-base/logging.h>
#include <android-base/strings.h>
#include <gtest/gtest.h>
#include <mntent.h>
#include <processgroup/processgroup.h>
@ -29,13 +30,14 @@ using ::android::base::LogFunction;
using ::android::base::LogId;
using ::android::base::LogSeverity;
using ::android::base::SetLogger;
using ::android::base::Split;
using ::android::base::VERBOSE;
using ::testing::TestWithParam;
using ::testing::Values;
namespace {
bool IsCgroupV2Mounted() {
bool IsCgroupV2MountedRw() {
std::unique_ptr<FILE, int (*)(FILE*)> mnts(setmntent("/proc/mounts", "re"), endmntent);
if (!mnts) {
LOG(ERROR) << "Failed to open /proc/mounts";
@ -43,9 +45,11 @@ bool IsCgroupV2Mounted() {
}
struct mntent* mnt;
while ((mnt = getmntent(mnts.get()))) {
if (strcmp(mnt->mnt_type, "cgroup2") == 0) {
return true;
if (strcmp(mnt->mnt_type, "cgroup2") != 0) {
continue;
}
const std::vector<std::string> options = Split(mnt->mnt_opts, ",");
return std::count(options.begin(), options.end(), "ro") == 0;
}
return false;
}
@ -145,8 +149,9 @@ class SetAttributeFixture : public TestWithParam<TestParam> {
};
TEST_P(SetAttributeFixture, SetAttribute) {
// Treehugger runs host tests inside a container without cgroupv2 support.
if (!IsCgroupV2Mounted()) {
// Treehugger runs host tests inside a container either without cgroupv2
// support or with the cgroup filesystem mounted read-only.
if (!IsCgroupV2MountedRw()) {
GTEST_SKIP();
return;
}