From: Angus Gratton Date: Tue, 10 Oct 2017 00:50:02 +0000 (+1100) Subject: pthreads local storage: add test for unique keys X-Git-Tag: v3.1-dev~156^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3f4c8f7174cedfa9d4a1baf46885ac1c0f98a4f0;p=esp-idf pthreads local storage: add test for unique keys --- diff --git a/components/pthread/test/test_pthread_local_storage.c b/components/pthread/test/test_pthread_local_storage.c index 5f83e87cba..8be22ce57e 100644 --- a/components/pthread/test/test_pthread_local_storage.c +++ b/components/pthread/test/test_pthread_local_storage.c @@ -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;