tests: Extend test_sync_setgid in test_glibc_thread_support.c
authorRobin Hack <hack.robin@gmail.com>
Sun, 28 Sep 2014 19:19:13 +0000 (21:19 +0200)
committerAndreas Schneider <asn@samba.org>
Mon, 6 Oct 2014 14:16:18 +0000 (16:16 +0200)
Extend test to case when thread changes gid of main process.
After this change main process start new thread which should have
same gid set as a main process.

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 a4baf06b6abacf30635161423e9e2f81453aaeb4..540338dedc10f27df29357ee5e4df0348cdae6b6 100644 (file)
@@ -200,12 +200,24 @@ static void *uwrap_setgid(void *arg)
        return NULL;
 }
 
+static void *uwrap_getgid(void *arg)
+{
+       gid_t g;
+       (void) arg; /* unused */
+
+       g = getgid();
+       assert_int_equal(g, 1999);
+
+       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;
+       int rc;
 
        (void) state; /* unused */
 
@@ -226,6 +238,19 @@ static void test_sync_setgid(void **state)
        g = getgid();
        assert_int_equal(g, 999);
 
+       rc = setgid(1999);
+       assert_int_equal(rc, 0);
+
+       pthread_create(&threads[0],
+                      &pthread_custom_attr,
+                      uwrap_getgid,
+                      NULL);
+
+       pthread_join(threads[0], NULL);
+
+       g = getgid();
+       assert_int_equal(g, 1999);
+
        pthread_attr_destroy(&pthread_custom_attr);
 }