[systemd-devel] [PATCHv2] test: do not use last cap from kernel in test-cap-list
Filipe Brandenburger
filbranden at google.com
Tue Dec 23 13:51:40 PST 2014
The new test-cap-list introduced in commit 2822da4fb7f891 uses the included
table of capabilities. However, it uses cap_last_cap() which probes the kernel
for the last available capability. On an older kernel (e.g. 3.10 from RHEL 7)
that causes the test to fail with the following message:
Assertion '!capability_to_name(cap_last_cap()+1)' failed at src/test/test-cap-list.c:30, function main(). Aborting.
Fix it by exporting the size of the static table and using it in the test
instead of the dynamic one from the current kernel.
Tested by successfully running ./test-cap-list and the whole `make check` test
suite with this patch on a RHEL 7 host.
---
v2: Updated the patch to also consider the changes introduced in commit
4b7c1d5d6a0060 ("test-cap-list: always check libcap comes to the same names...")
src/shared/cap-list.c | 4 ++++
src/shared/cap-list.h | 1 +
src/test/test-cap-list.c | 7 ++++---
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/shared/cap-list.c b/src/shared/cap-list.c
index 56d1488..8033e8c 100644
--- a/src/shared/cap-list.c
+++ b/src/shared/cap-list.c
@@ -60,3 +60,7 @@ int capability_from_name(const char *name) {
return sc->id;
}
+
+int capability_list_length(void) {
+ return (int) ELEMENTSOF(capability_names);
+}
diff --git a/src/shared/cap-list.h b/src/shared/cap-list.h
index c699e46..9824fad 100644
--- a/src/shared/cap-list.h
+++ b/src/shared/cap-list.h
@@ -23,3 +23,4 @@
const char *capability_to_name(int id);
int capability_from_name(const char *name);
+int capability_list_length(void);
diff --git a/src/test/test-cap-list.c b/src/test/test-cap-list.c
index 7c5ae18..4e75136 100644
--- a/src/test/test-cap-list.c
+++ b/src/test/test-cap-list.c
@@ -19,6 +19,7 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "util.h"
#include "log.h"
#include "cap-list.h"
#include "capability.h"
@@ -27,9 +28,9 @@ int main(int argc, char *argv[]) {
int i;
assert_se(!capability_to_name(-1));
- assert_se(!capability_to_name(cap_last_cap()+1));
+ assert_se(!capability_to_name(capability_list_length()));
- for (i = 0; i <= (int) cap_last_cap(); i++) {
+ for (i = 0; i < capability_list_length(); i++) {
const char *n;
assert_se(n = capability_to_name(i));
@@ -45,7 +46,7 @@ int main(int argc, char *argv[]) {
assert_se(capability_from_name("15") == 15);
assert_se(capability_from_name("-1") == -EINVAL);
- for (i = 0; i <= (int) cap_last_cap(); i++) {
+ for (i = 0; i < capability_list_length(); i++) {
_cleanup_cap_free_charp_ char *a = NULL;
const char *b;
unsigned u;
--
1.8.3.1
More information about the systemd-devel
mailing list