tests: Add new test test_sync_setgroups().
authorRobin Hack <hack.robin@gmail.com>
Tue, 21 Oct 2014 06:36:52 +0000 (08:36 +0200)
committerAndreas Schneider <asn@samba.org>
Wed, 7 Jan 2015 12:49:17 +0000 (13:49 +0100)
This test is almost same as test_sync_setgid but covers the setgroups
function.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
tests/test_glibc_thread_support.c

index 3f01bd5387e422164a381210cafe34e5d7d7a0db..4fb11a50df30f026ea3d76158de2b3f440ecccce 100644 (file)
@@ -11,6 +11,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <grp.h>
 
 #ifdef HAVE_SYS_SYSCALL_H
 #include <sys/syscall.h>
@@ -21,6 +22,8 @@
 
 #define NUM_THREADS 10
 
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
+
 struct parm {
        int id;
        int ready;
@@ -323,6 +326,71 @@ static void test_real_sync_setuid(void **state)
        assert_int_equal(u, 888);
 }
 
+static void *uwrap_setgroups(void *arg)
+{
+       gid_t glist[] = { 100, 200, 300, 400, 500 };
+       int rc;
+
+       (void) arg; /* unused */
+
+       rc = setgroups(ARRAY_SIZE(glist), glist);
+       assert_int_equal(rc, 0);
+
+       return NULL;
+}
+
+static void *uwrap_getgroups(void *arg)
+{
+       gid_t glist[] = { 100, 200, 300, 400, 500 };
+       gid_t rlist[16];
+       int rc;
+
+       (void) arg; /* unused */
+
+       rc = getgroups(ARRAY_SIZE(rlist), rlist);
+       assert_int_equal(rc, 5);
+
+       assert_memory_equal(glist, rlist, sizeof(glist));
+
+       return NULL;
+}
+
+static void test_sync_setgroups(void **state)
+{
+       gid_t glist[] = { 100, 200, 300, 400, 500 };
+       pthread_t threads[NUM_THREADS];
+       gid_t rlist[16];
+       int rc;
+       int i;
+
+       (void) state; /* unused */
+
+       for (i = 0; i < NUM_THREADS; i++) {
+               pthread_create(&threads[i],
+                              NULL,
+                              uwrap_setgroups,
+                              NULL);
+       }
+
+       /* wait for threaads */
+       for (i = 0; i < NUM_THREADS; i++) {
+               pthread_join(threads[i], NULL);
+       }
+
+       rc = getgroups(ARRAY_SIZE(rlist), rlist);
+       assert_int_equal(rc, 5);
+
+       assert_memory_equal(glist, rlist, sizeof(glist));
+
+       pthread_create(&threads[0],
+                      NULL,
+                      uwrap_getgroups,
+                      NULL);
+
+       pthread_join(threads[0], NULL);
+
+}
+
 int main(void) {
        int rc;
 
@@ -332,6 +400,7 @@ int main(void) {
                unit_test(test_sync_setgid),
                unit_test(test_sync_setgid_syscall),
                unit_test(test_real_sync_setuid),
+               unit_test(test_sync_setgroups),
        };
 
        rc = run_tests(tests);