Page MenuHomeFreeBSD

D61066.1794699384.diff
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

D61066.1794699384.diff

diff --git a/tests/sys/capsicum/Makefile b/tests/sys/capsicum/Makefile
--- a/tests/sys/capsicum/Makefile
+++ b/tests/sys/capsicum/Makefile
@@ -9,14 +9,11 @@
.if ${MK_GOOGLETEST} != no
-GTESTS+= capsicum-test
-# This test script runs the same test suite twice, once as root and once as an
-# unprivileged user. Serialize them since some tests access global namespaces,
-# e.g., mqueuefs, and can trample on each other.
-TEST_METADATA.functional+= is_exclusive="true"
-TEST_METADATA.functional+= required_kmods="mqueuefs"
+GTESTS+= capsicum-test_privileged
+GTESTS+= capsicum-test_unprivileged
-SRCS.capsicum-test+= \
+# SRCS required for `capsicum-test*`.
+SRCS.capsicum-test= \
capsicum-test-main.cc \
capsicum-test.cc \
capability-fd.cc \
@@ -36,8 +33,20 @@
overhead.cc \
rename.cc
-LIBADD.capsicum-test+= gtest pthread procstat
-TEST_METADATA.capsicum-test= required_user="unprivileged"
+.for gtest in ${GTESTS}
+SRCS.${gtest}= ${SRCS.capsicum-test}
+
+LIBADD.${gtest}+= gtest pthread procstat
+
+# This test script runs the same test suite twice, once as root and once as an
+# unprivileged user. Serialize them since some tests access global namespaces,
+# e.g., mqueuefs, and can trample on each other.
+TEST_METADATA.${gtest}+= is_exclusive="true"
+TEST_METADATA.${gtest}+= required_kmods="mqueuefs"
+.endfor
+
+TEST_METADATA.capsicum-test_privileged+= required_user="root"
+TEST_METADATA.capsicum-test_unprivileged+= required_user="unprivileged"
.for p in mini-me mini-me.noexec mini-me.setuid
PROGS+= $p
diff --git a/tests/sys/capsicum/capsicum-test-main.cc b/tests/sys/capsicum/capsicum-test-main.cc
--- a/tests/sys/capsicum/capsicum-test-main.cc
+++ b/tests/sys/capsicum/capsicum-test-main.cc
@@ -136,6 +136,30 @@
}
}
+ // Last ditch effort to get an unprivileged user on the fly from /etc/passwd
+ // for testcases that need it.
+ //
+ // This must be done this way because the typical way of handling this (via
+ // the `-u` argument) isn't supported yet with kyua:
+ // https://github.com/freebsd/kyua/issues/354 .
+ //
+ // IMPORTANT:
+ // - this doesn't honor `unprivileged_user` in `kyua.conf`.
+ // - this doesn't fail because doing that could break all testing on systems
+ // where the `tests` user isn't available.
+ if (other_uid == 0) {
+ const char *test_user = "tests";
+
+ struct passwd *test_user_entry = getpwnam(test_user);
+
+ if (test_user_entry) {
+ other_uid = test_user_entry->pw_uid;
+ } else {
+ std::cerr << "Failed to get entry for " << test_user << ", errno=" << errno << "; some tests may fail" << std::endl;
+ }
+
+ }
+
testing::AddGlobalTestEnvironment(new SetupEnvironment());
return RUN_ALL_TESTS();
}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 14, 11:36 PM (2 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41734056
Default Alt Text
D61066.1794699384.diff (2 KB)

Event Timeline