]> granicus.if.org Git - esp-idf/commitdiff
pthreads local storage: add test for unique keys
authorAngus Gratton <angus@espressif.com>
Tue, 10 Oct 2017 00:50:02 +0000 (11:50 +1100)
committerAngus Gratton <gus@projectgus.com>
Tue, 17 Oct 2017 07:29:25 +0000 (15:29 +0800)
components/pthread/test/test_pthread_local_storage.c

index 5f83e87cba2d81d1dafbd706148f22fa4a2532ed..8be22ce57e0e13fd7eac46b576dc98e84aa7eb41 100644 (file)
@@ -27,6 +27,29 @@ TEST_CASE("pthread local storage basics", "[pthread]")
     TEST_ASSERT_EQUAL(0, pthread_key_delete(key));
 }
 
+TEST_CASE("pthread local storage unique keys", "[pthread]")
+{
+    const int NUM_KEYS = 10;
+    pthread_key_t keys[NUM_KEYS];
+
+    for (int i = 0; i < NUM_KEYS; i++) {
+        TEST_ASSERT_EQUAL(0, pthread_key_create(&keys[i], NULL));
+        printf("New key %d = %d\n", i, keys[i]);
+    }
+
+    for (int i = 0; i < NUM_KEYS; i++) {
+        for (int j = 0; j < NUM_KEYS; j++) {
+            if (i != j) {
+                TEST_ASSERT_NOT_EQUAL(keys[i], keys[j]);
+            }
+        }
+    }
+
+    for (int i = 0; i < NUM_KEYS; i++) {
+        TEST_ASSERT_EQUAL(0, pthread_key_delete(keys[i]));
+    }
+}
+
 static void test_pthread_destructor(void *);
 static void *expected_destructor_ptr;
 static void *actual_destructor_ptr;