This is an automated email from the ASF dual-hosted git repository.
bmahler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
The following commit(s) were added to refs/heads/master by this push:
new 6b3a12370 [cgroups2] Adds cgroups2_tests.cpp.
6b3a12370 is described below
commit 6b3a123700c317d204e20deea9bb1d9ee1c6a7a7
Author: Devin Leamy <[email protected]>
AuthorDate: Tue Feb 27 13:05:06 2024 -0500
[cgroups2] Adds cgroups2_tests.cpp.
- Introduces cgroups2_tests.cpp which will hold the cgroups2 tests.
- Introduces Cgroups2Filter that will enable cgroups2 tests only if
cgroups2 is enabled on the system and the user is "root".
- Adds a test that checks that cgroups2 is enabled on the testing host.
Review: https://reviews.apache.org/r/74871/
---
src/Makefile.am | 1 +
src/tests/CMakeLists.txt | 1 +
src/tests/containerizer/cgroups2_tests.cpp | 35 ++++++++++++++++++++++++++++++
src/tests/environment.cpp | 30 ++++++++++++++++++++++++-
4 files changed, 66 insertions(+), 1 deletion(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index 03aa881e8..20c32ad93 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2860,6 +2860,7 @@ mesos_tests_SOURCES +=
\
tests/containerizer/capabilities_test_helper.cpp \
tests/containerizer/cgroups_isolator_tests.cpp \
tests/containerizer/cgroups_tests.cpp \
+ tests/containerizer/cgroups2_tests.cpp \
tests/containerizer/cni_isolator_tests.cpp \
tests/containerizer/docker_volume_isolator_tests.cpp \
tests/containerizer/linux_devices_isolator_tests.cpp \
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 6beb74e38..ee95153d6 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -232,6 +232,7 @@ if (LINUX)
containerizer/capabilities_tests.cpp
containerizer/cgroups_isolator_tests.cpp
containerizer/cgroups_tests.cpp
+ containerizer/cgroups2_tests.cpp
containerizer/cni_isolator_tests.cpp
containerizer/docker_volume_isolator_tests.cpp
containerizer/fs_tests.cpp
diff --git a/src/tests/containerizer/cgroups2_tests.cpp
b/src/tests/containerizer/cgroups2_tests.cpp
new file mode 100644
index 000000000..4981e9588
--- /dev/null
+++ b/src/tests/containerizer/cgroups2_tests.cpp
@@ -0,0 +1,35 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <stout/tests/utils.hpp>
+
+#include "linux/cgroups2.hpp"
+
+namespace mesos {
+namespace internal {
+namespace tests {
+
+class Cgroups2Test : public TemporaryDirectoryTest {};
+
+TEST_F(Cgroups2Test, ROOT_CGROUPS2_Enabled)
+{
+ EXPECT_TRUE(cgroups2::enabled());
+}
+
+} // namespace tests {
+} // namespace internal {
+} // namespace mesos {
+
diff --git a/src/tests/environment.cpp b/src/tests/environment.cpp
index 737c2d916..6e1af5e74 100644
--- a/src/tests/environment.cpp
+++ b/src/tests/environment.cpp
@@ -60,6 +60,7 @@
#ifdef __linux__
#include "linux/cgroups.hpp"
+#include "linux/cgroups2.hpp"
#include "linux/fs.hpp"
#include "linux/perf.hpp"
#endif
@@ -194,7 +195,8 @@ public:
bool disable(const ::testing::TestInfo* test) const override
{
- if (matches(test, "CGROUPS_") || matches(test, "Cgroups")) {
+ if (matches(test, "CGROUPS_") ||
+ (matches(test, "Cgroups") && !matches(test, "Cgroups2"))) {
#ifdef __linux__
Result<string> user = os::user();
CHECK_SOME(user);
@@ -219,6 +221,31 @@ private:
};
+class Cgroups2Filter : public TestFilter
+{
+public:
+ Cgroups2Filter() {}
+
+ // We disable cgroups2 tests if cgroups2 is not enabled or the user is
+ // not root.
+ bool disable(const ::testing::TestInfo* test) const override
+ {
+
+ if (matches(test, "CGROUPS2_") || matches(test, "Cgroups2")) {
+#ifdef __linux__
+ Result<string> user = os::user();
+ CHECK_SOME(user);
+ return *user != "root" || !cgroups2::enabled();
+#else
+ return true;
+#endif // __linux__
+ }
+
+ return false;
+ }
+};
+
+
class CurlFilter : public TestFilter
{
public:
@@ -1103,6 +1130,7 @@ Environment::Environment(const Flags& _flags)
std::make_shared<BenchmarkFilter>(),
std::make_shared<CfsFilter>(),
std::make_shared<CgroupsFilter>(),
+ std::make_shared<Cgroups2Filter>(),
std::make_shared<CurlFilter>(),
std::make_shared<DockerFilter>(),
std::make_shared<DtypeFilter>(),