1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00
sortix--sortix/regress/test-pthread-argv.c

67 lines
1.7 KiB
C
Raw Normal View History

/*
* Copyright (c) 2014 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* test-pthread-argv.c
* Tests if the argument vector and environment dies with the main thread.
*/
2014-07-11 11:41:22 -04:00
#include <pthread.h>
#include <string.h>
#include "test.h"
pthread_t main_thread;
char** global_argv;
char** global_envp;
size_t answer = 0;
2016-02-28 17:18:13 -05:00
void* thread_routine(void* ctx)
2014-07-11 11:41:22 -04:00
{
2016-02-28 17:18:13 -05:00
(void) ctx;
2017-02-26 08:41:25 -05:00
test_assertp(pthread_join(main_thread, NULL));
2014-07-11 11:41:22 -04:00
size_t recount = 0;
for ( int i = 0; global_argv[i]; i++ )
recount += strlen(global_argv[i]);
for ( int i = 0; global_envp[i]; i++ )
recount += strlen(global_envp[i]);
2017-02-26 08:41:25 -05:00
test_assertx(answer == recount);
2014-07-11 11:41:22 -04:00
exit(0);
}
2016-02-28 17:18:13 -05:00
int main(int argc, char* argv[], char* envp[])
2014-07-11 11:41:22 -04:00
{
2016-02-28 17:18:13 -05:00
(void) argc;
2014-07-11 11:41:22 -04:00
for ( int i = 0; argv[i]; i++ )
answer += strlen(argv[i]);
for ( int i = 0; envp[i]; i++ )
answer += strlen(envp[i]);
global_argv = argv;
global_envp = envp;
main_thread = pthread_self();
pthread_t thread;
2017-02-26 08:41:25 -05:00
test_assertp(pthread_create(&thread, NULL, &thread_routine, NULL));
2014-07-11 11:41:22 -04:00
pthread_exit(NULL);
}