tests: Added two new tests aimed to setgid() and getgid() functions.
authorRobin Hack <hack.robin@gmail.com>
Fri, 26 Sep 2014 14:17:18 +0000 (16:17 +0200)
committerAndreas Schneider <asn@samba.org>
Mon, 6 Oct 2014 14:16:09 +0000 (16:16 +0200)
New tests:
 * test_sync_setgid - test if call of setgid() in thread changes gid
                      of main process
 * test_sync_setgid_syscall - test setgid() syscall

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 f45cd146210ec8801d0e76729b02993c41d04503..0f0a39942a25db23c59ddb796956aa24a359d5a9 100644 (file)
@@ -134,12 +134,106 @@ static void test_sync_setreuid(void **state)
        free(p);
 }
 
+static void *uwrap_setgid_syscall(void *arg)
+{
+       int rc;
+       gid_t g;
+       gid_t *gmp = (gid_t *) arg;
+
+       rc = syscall(SYS_setgid, 999);
+       assert_int_equal(rc, 0);
+
+       g = getgid();
+       assert_int_equal(g, *gmp);
+
+       return NULL;
+}
+
+static void test_sync_setgid_syscall(void **state)
+{
+       pthread_attr_t pthread_custom_attr;
+       pthread_t threads[NUM_THREADS];
+       gid_t go, gn;
+       gid_t *gtp;
+       int i;
+
+       gtp = malloc(sizeof(gid_t));
+       assert_non_null(gtp);
+
+       (void) state; /* unused */
+
+       pthread_attr_init(&pthread_custom_attr);
+
+       go = getgid();
+       *gtp = go;
+
+       for (i = 0; i < NUM_THREADS; i++) {
+               pthread_create(&threads[i],
+                              &pthread_custom_attr,
+                              uwrap_setgid_syscall,
+                              gtp);
+       }
+
+       /* wait for threaads */
+       for (i = 0; i < NUM_THREADS; i++) {
+               pthread_join(threads[i], NULL);
+       }
+
+       gn = getgid();
+       assert_int_equal(gn, go);
+
+       free(gtp);
+       pthread_attr_destroy(&pthread_custom_attr);
+}
+
+static void *uwrap_setgid(void *arg)
+{
+       int rc;
+       (void) arg; /* unused */
+
+       rc = setgid(999);
+       assert_int_equal(rc, 0);
+
+       return NULL;
+}
+
+static void test_sync_setgid(void **state)
+{
+       pthread_attr_t pthread_custom_attr;
+       pthread_t threads[NUM_THREADS];
+       gid_t g;
+       int i;
+
+       (void) state; /* unused */
+
+       pthread_attr_init(&pthread_custom_attr);
+
+       for (i = 0; i < NUM_THREADS; i++) {
+               pthread_create(&threads[i],
+                              &pthread_custom_attr,
+                              uwrap_setgid,
+                              NULL);
+       }
+
+       /* wait for threaads */
+       for (i = 0; i < NUM_THREADS; i++) {
+               pthread_join(threads[i], NULL);
+       }
+
+       g = getgid();
+       assert_int_equal(g, 999);
+
+       pthread_attr_destroy(&pthread_custom_attr);
+}
+
 int main(void) {
        int rc;
 
        const UnitTest tests[] = {
                unit_test(test_syscall_setreuid),
                unit_test(test_sync_setreuid),
+               unit_test(test_sync_setgid),
+               unit_test(test_sync_setgid_syscall),
        };
 
        rc = run_tests(tests);