mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests/pthread_tls: some cleanup
This commit is contained in:
parent
c1a08451e3
commit
8b71893714
@ -30,7 +30,8 @@ void *run(void *parameter)
|
||||
|
||||
(void)parameter;
|
||||
|
||||
printf("\n-= TEST 1 - create %d tls with sequencial values 0...%d =-\n", NUMBER_OF_TLS, NUMBER_OF_TLS - 1);
|
||||
printf("\n-= TEST 1 - create %d tls with sequencial values 0...%d =-\n",
|
||||
NUMBER_OF_TLS, NUMBER_OF_TLS - 1);
|
||||
|
||||
for (int i = 0; i < NUMBER_OF_TLS; ++i) {
|
||||
aTLS_values[i] = i;
|
||||
@ -44,11 +45,12 @@ void *run(void *parameter)
|
||||
aTLS_values[i]++;
|
||||
}
|
||||
|
||||
printf("pick deliberate storage (key[3]:%d) and change the value\n", (int)aKeys[3]);
|
||||
printf("pick deliberate storage (key[3]:%d) and change the value\n",
|
||||
(int)aKeys[3]);
|
||||
void *val = pthread_getspecific(aKeys[3]);
|
||||
*((int *)val) = 42;
|
||||
|
||||
printf("show tls values:\n");
|
||||
puts("show tls values:");
|
||||
|
||||
for (int i = 0; i < NUMBER_OF_TLS; ++i) {
|
||||
void *val = pthread_getspecific(aKeys[i]);
|
||||
@ -56,10 +58,11 @@ void *run(void *parameter)
|
||||
printf("key[%d]: %d, val: %d\n",i, (int)aKeys[i], x);
|
||||
}
|
||||
|
||||
printf("\n -= TEST 2 - delete deliberate key (key[5]:%d) =-\n", (int)aKeys[5]);
|
||||
printf("\n -= TEST 2 - delete deliberate key (key[5]:%d) =-\n",
|
||||
(int)aKeys[5]);
|
||||
pthread_key_delete(aKeys[5]);
|
||||
|
||||
printf("show tls values:\n");
|
||||
puts("show tls values:");
|
||||
|
||||
for (int i = 0; i < NUMBER_OF_TLS; ++i) {
|
||||
void *val = pthread_getspecific(aKeys[i]);
|
||||
@ -70,7 +73,8 @@ void *run(void *parameter)
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n-= TEST 3 - create new tls =-\n");
|
||||
puts("");
|
||||
puts("-= TEST 3 - create new tls =-");
|
||||
int new_val = 99;
|
||||
pthread_key_t new_key;
|
||||
pthread_key_create(&new_key, NULL);
|
||||
@ -88,7 +92,8 @@ void *run(void *parameter)
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n-= TEST 4 - delete all keys =-\n");
|
||||
puts("");
|
||||
puts("-= TEST 4 - delete all keys =-");
|
||||
|
||||
for (int i = 0; i < NUMBER_OF_TLS; ++i) {
|
||||
pthread_key_delete(aKeys[i]);
|
||||
@ -105,17 +110,22 @@ void *run(void *parameter)
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n-= TEST 5 - try delete non-existing key =-\n");
|
||||
printf("try to delete returns: %d\n", pthread_key_delete((pthread_key_t)99));
|
||||
puts("");
|
||||
puts("-= TEST 5 - try delete non-existing key =-");
|
||||
printf("try to delete returns: %d\n",
|
||||
pthread_key_delete((pthread_key_t)99));
|
||||
|
||||
puts("");
|
||||
puts("-= TEST 6 - add key and delete without a tls =-");
|
||||
|
||||
printf("\n-= TEST 6 - add key and delete without a tls =-\n");
|
||||
pthread_key_create(&new_key, NULL);
|
||||
printf("crated key: %d\n", (int)new_key);
|
||||
printf("created key: %d\n", (int)new_key);
|
||||
printf("try to delete returns: %d\n", pthread_key_delete(new_key));
|
||||
|
||||
printf("\n-= TEST 7 - add key without tls =-\n");
|
||||
puts("");
|
||||
puts("-= TEST 7 - add key without tls =-");
|
||||
pthread_key_create(&new_key, NULL);
|
||||
printf("crated key: %d\n", (int)new_key);
|
||||
printf("created key: %d\n", (int)new_key);
|
||||
void* test_7_val = pthread_getspecific(new_key);
|
||||
printf("test_7_val: %p\n", test_7_val);
|
||||
|
||||
@ -125,6 +135,7 @@ void *run(void *parameter)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
puts("START");
|
||||
pthread_t th_id;
|
||||
pthread_attr_t th_attr;
|
||||
|
||||
@ -133,6 +144,13 @@ int main(void)
|
||||
|
||||
size_t res;
|
||||
pthread_join(th_id, (void **) &res);
|
||||
puts("\ntls tests finished.");
|
||||
puts("tls tests finished.");
|
||||
|
||||
if (res == 0) {
|
||||
puts("SUCCESS");
|
||||
}
|
||||
else {
|
||||
puts("FAILURE");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user