chiark / gitweb /
test: do not use last cap from kernel in test-cap-list
authorFilipe Brandenburger <filbranden@google.com>
Tue, 23 Dec 2014 21:51:40 +0000 (13:51 -0800)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 25 Dec 2014 15:55:41 +0000 (10:55 -0500)
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.

src/shared/cap-list.c
src/shared/cap-list.h
src/test/test-cap-list.c

index 56d1488f483df0c636c361c912af49c5b744db84..8033e8c7b2781d8a9a88e367581313bdbbc77595 100644 (file)
@@ -60,3 +60,7 @@ int capability_from_name(const char *name) {
 
         return sc->id;
 }
 
         return sc->id;
 }
+
+int capability_list_length(void) {
+        return (int) ELEMENTSOF(capability_names);
+}
index c699e466a7330c32c8c08860afcf02e311afe9d1..9824fad70f1edc6f0d984a8964cfbb9ef887f6df 100644 (file)
@@ -23,3 +23,4 @@
 
 const char *capability_to_name(int id);
 int capability_from_name(const char *name);
 
 const char *capability_to_name(int id);
 int capability_from_name(const char *name);
+int capability_list_length(void);
index 7c5ae18b25aa38331c074318807c479206decb9e..4e7513649821df17cfdc12f9a8d20ac0c3e5831f 100644 (file)
@@ -19,6 +19,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include "util.h"
 #include "log.h"
 #include "cap-list.h"
 #include "capability.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));
         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));
                 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);
 
         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;
                 _cleanup_cap_free_charp_ char *a = NULL;
                 const char *b;
                 unsigned u;