int ostest_main(int argc, char *argv[]) { int result; /* Verify that stdio works first */ stdio_test(); #ifdef SDCC /* I am not yet certain why SDCC does not like the following initilizers. * It involves some issues with 2- vs 3-byte pointer types. */ g_argv[0] = arg1; g_argv[1] = arg2; g_argv[2] = arg3; g_argv[3] = arg4; g_argv[4] = NULL; #endif /* Set up some environment variables */ #ifndef CONFIG_DISABLE_ENVIRON printf("ostest_main: putenv(%s)\n", g_putenv_value); putenv(g_putenv_value); /* Varaible1=BadValue3 */ printf("ostest_main: setenv(%s, %s, TRUE)\n", g_var1_name, g_var1_value); setenv(g_var1_name, g_var1_value, TRUE); /* Variable1=GoodValue1 */ printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var2_name, g_bad_value1); setenv(g_var2_name, g_bad_value1, FALSE); /* Variable2=BadValue1 */ printf("ostest_main: setenv(%s, %s, TRUE)\n", g_var2_name, g_var2_value); setenv(g_var2_name, g_var2_value, TRUE); /* Variable2=GoodValue2 */ printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name); setenv(g_var3_name, g_var3_value, FALSE); /* Variable3=GoodValue3 */ printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name); setenv(g_var3_name, g_bad_value2, FALSE); /* Variable3=GoodValue3 */ show_environment(true, true, true); #endif /* Verify that we can spawn a new task */ #ifndef CONFIG_CUSTOM_STACK result = task_create("ostest", PRIORITY, STACKSIZE, user_main, g_argv); #else result = task_create("ostest", PRIORITY, user_main, g_argv); #endif if (result == ERROR) { printf("ostest_main: ERROR Failed to start user_main\n"); } else { printf("ostest_main: Started user_main at PID=%d\n", result); } printf("ostest_main: Exitting\n"); return 0; }
static int user_main(int argc, char *argv[]) #endif { int i; /* Sample the memory usage now */ #ifndef CONFIG_DISABLE_SIGNALS usleep(HALF_SECOND_USEC); #ifdef CONFIG_CAN_PASS_STRUCTS g_mmbefore = mallinfo(); g_mmprevious = g_mmbefore; #else (void)mallinfo(&g_mmbefore); memcpy(&g_mmprevious, &g_mmbefore, sizeof(struct mallinfo)); #endif #endif printf("\nuser_main: Begin argument test\n"); printf("user_main: Started with argc=%d\n", argc); /* Verify passed arguments */ if (argc != NARGS + 1) { printf("user_main: Error expected argc=%d got argc=%d\n", NARGS+1, argc); } for (i = 0; i <= NARGS; i++) { printf("user_main: argv[%d]=\"%s\"\n", i, argv[i]); } for (i = 1; i <= NARGS; i++) { if (strcmp(argv[i], g_argv[i-1]) != 0) { printf("user_main: ERROR argv[%d]: Expected \"%s\" found \"%s\"\n", i, g_argv[i-1], argv[i]); } } check_test_memory_usage(); /* If retention of child status is enable, then suppress it for this task. * This task may produce many, many children (especially if * CONFIG_EXAMPLES_OSTEST_LOOPS) and it does not harvest their exit status. * As a result, the test may fail inappropriately unless retention of * child exit status is disabled. * * So basically, this tests that child status can be disabled, but cannot * verify that status is retained correctly. */ #if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) { struct sigaction sa; int ret; sa.sa_handler = SIG_IGN; sa.sa_flags = SA_NOCLDWAIT; ret = sigaction(SIGCHLD, &sa, NULL); if (ret < 0) { printf("user_main: ERROR: sigaction failed: %d\n", errno); } } #endif /* Check environment variables */ #ifndef CONFIG_DISABLE_ENVIRON show_environment(true, true, true); unsetenv(g_var1_name); show_environment(false, true, true); check_test_memory_usage(); clearenv(); show_environment(false, false, false); check_test_memory_usage(); #endif /* Top of test loop */ #if CONFIG_EXAMPLES_OSTEST_LOOPS > 1 for (i = 0; i < CONFIG_EXAMPLES_OSTEST_LOOPS; i++) #elif CONFIG_EXAMPLES_OSTEST_LOOPS == 0 for (;;) #endif { #if CONFIG_NFILE_DESCRIPTORS > 0 /* Checkout /dev/null */ printf("\nuser_main: /dev/null test\n"); dev_null(); check_test_memory_usage(); #endif #ifdef CONFIG_ARCH_FPU /* Check that the FPU is properly supported during context switching */ printf("\nuser_main: FPU test\n"); fpu_test(); check_test_memory_usage(); #endif /* Checkout task_restart() */ printf("\nuser_main: task_restart test\n"); restart_test(); check_test_memory_usage(); #ifdef CONFIG_SCHED_WAITPID /* Check waitpid() and friends */ printf("\nuser_main: waitpid test\n"); waitpid_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthreads and pthread mutex */ printf("\nuser_main: mutex test\n"); mutex_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_MUTEX_TYPES) /* Verify recursive mutexes */ printf("\nuser_main: recursive mutex test\n"); recursive_mutex_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthread cancellation */ printf("\nuser_main: cancel test\n"); cancel_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthreads and semaphores */ printf("\nuser_main: semaphore test\n"); sem_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthreads and condition variables */ printf("\nuser_main: condition variable test\n"); #ifdef CONFIG_PRIORITY_INHERITANCE printf("\n Skipping, Test logic incompatible with priority inheritance\n"); #else cond_test(); check_test_memory_usage(); #endif #endif #if !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD) /* Verify pthreads and condition variable timed waits */ printf("\nuser_main: timed wait test\n"); timedwait_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_PTHREAD) /* Verify pthreads and message queues */ printf("\nuser_main: message queue test\n"); mqueue_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_PTHREAD) /* Verify pthreads and message queues */ printf("\nuser_main: timed message queue test\n"); timedmqueue_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_SIGNALS /* Verify signal handlers */ printf("\nuser_main: signal handler test\n"); sighand_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_POSIX_TIMERS) && !defined(CONFIG_DISABLE_SIGNALS) /* Verify posix timers */ printf("\nuser_main: POSIX timer test\n"); timer_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_PTHREAD) && CONFIG_RR_INTERVAL > 0 /* Verify round robin scheduling */ printf("\nuser_main: round-robin scheduler test\n"); rr_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthread barriers */ printf("\nuser_main: barrier test\n"); barrier_test(); check_test_memory_usage(); #endif #if defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD) /* Verify priority inheritance */ printf("\nuser_main: priority inheritance test\n"); priority_inheritance(); check_test_memory_usage(); #endif /* CONFIG_PRIORITY_INHERITANCE && !CONFIG_DISABLE_SIGNALS && !CONFIG_DISABLE_PTHREAD */ #if defined(CONFIG_ARCH_HAVE_VFORK) && defined(CONFIG_SCHED_WAITPID) && \ !defined(CONFIG_DISABLE_SIGNALS) printf("\nuser_main: vfork() test\n"); vfork_test(); #endif /* Compare memory usage at time ostest_main started until * user_main exits. These should not be identical, but should * be similar enough that we can detect any serious OS memory * leaks. */ #ifndef CONFIG_DISABLE_SIGNALS usleep(HALF_SECOND_USEC); #ifdef CONFIG_CAN_PASS_STRUCTS g_mmafter = mallinfo(); #else (void)mallinfo(&g_mmafter); #endif printf("\nFinal memory usage:\n"); show_memory_usage(&g_mmbefore, &g_mmafter); #endif } printf("user_main: Exitting\n"); return 0; }
static int user_main(int argc, char *argv[]) { int i; /* Sample the memory usage now */ #ifndef CONFIG_DISABLE_SIGNALS usleep(HALF_SECOND_USEC); #ifdef CONFIG_CAN_PASS_STRUCTS g_mmbefore = mallinfo(); g_mmprevious = g_mmbefore; #else (void)mallinfo(&g_mmbefore); memcpy(&g_mmprevious, &g_mmbefore, sizeof(struct mallinfo)); #endif #endif printf("\nuser_main: Begin argument test\n"); printf("user_main: Started with argc=%d\n", argc); /* Verify passed arguments */ if (argc != NARGS + 1) { printf("user_main: Error expected argc=%d got argc=%d\n", NARGS+1, argc); } for (i = 0; i <= NARGS; i++) { printf("user_main: argv[%d]=\"%s\"\n", i, argv[i]); } for (i = 1; i <= NARGS; i++) { if (strcmp(argv[i], g_argv[i-1]) != 0) { printf("user_main: ERROR argv[%d]: Expected \"%s\" found \"%s\"\n", i, g_argv[i-1], argv[i]); } } check_test_memory_usage(); /* Check environment variables */ #ifndef CONFIG_DISABLE_ENVIRON show_environment(true, true, true); unsetenv(g_var1_name); show_environment(false, true, true); check_test_memory_usage(); clearenv(); show_environment(false, false, false); check_test_memory_usage(); #endif /* Top of test loop */ #if CONFIG_EXAMPLES_OSTEST_LOOPS > 1 for (i = 0; i < CONFIG_EXAMPLES_OSTEST_LOOPS; i++) #elif CONFIG_EXAMPLES_OSTEST_LOOPS == 0 for (;;) #endif { #if CONFIG_NFILE_DESCRIPTORS > 0 /* Checkout /dev/null */ printf("\nuser_main: /dev/null test\n"); dev_null(); check_test_memory_usage(); #endif #ifdef CONFIG_ARCH_FPU /* Check that the FPU is properly supported during context switching */ printf("\nuser_main: FPU test\n"); fpu_test(); check_test_memory_usage(); #endif #ifdef CONFIG_SCHED_WAITPID /* Check waitpid() and friends */ printf("\nuser_main: waitpid test\n"); waitpid_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthreads and pthread mutex */ printf("\nuser_main: mutex test\n"); mutex_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_MUTEX_TYPES) /* Verify recursive mutexes */ printf("\nuser_main: recursive mutex test\n"); recursive_mutex_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthread cancellation */ printf("\nuser_main: cancel test\n"); cancel_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthreads and semaphores */ printf("\nuser_main: semaphore test\n"); sem_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthreads and condition variables */ printf("\nuser_main: condition variable test\n"); #ifdef CONFIG_PRIORITY_INHERITANCE printf("\n Skipping, Test logic incompatible with priority inheritance\n"); #else cond_test(); check_test_memory_usage(); #endif #endif #if !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_DISABLE_CLOCK) /* Verify pthreads and condition variable timed waits */ printf("\nuser_main: timed wait test\n"); timedwait_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_PTHREAD) /* Verify pthreads and message queues */ printf("\nuser_main: message queue test\n"); mqueue_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_DISABLE_CLOCK) /* Verify pthreads and message queues */ printf("\nuser_main: timed message queue test\n"); timedmqueue_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_SIGNALS /* Verify signal handlers */ printf("\nuser_main: signal handler test\n"); sighand_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_POSIX_TIMERS) && !defined(CONFIG_DISABLE_SIGNALS) /* Verify posix timers */ printf("\nuser_main: POSIX timer test\n"); timer_test(); check_test_memory_usage(); #endif #if !defined(CONFIG_DISABLE_PTHREAD) && CONFIG_RR_INTERVAL > 0 /* Verify round robin scheduling */ printf("\nuser_main: round-robin scheduler test\n"); rr_test(); check_test_memory_usage(); #endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthread barriers */ printf("\nuser_main: barrier test\n"); barrier_test(); check_test_memory_usage(); #endif #if defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD) /* Verify priority inheritance */ printf("\nuser_main: priority inheritance test\n"); priority_inheritance(); check_test_memory_usage(); #endif /* CONFIG_PRIORITY_INHERITANCE && !CONFIG_DISABLE_SIGNALS && !CONFIG_DISABLE_PTHREAD */ #ifdef CONFIG_ARCH_HAVE_VFORK printf("\nuser_main: vfork() test\n"); vfork_test(); #endif /* Compare memory usage at time ostest_main started until * user_main exits. These should not be identical, but should * be similar enough that we can detect any serious OS memory * leaks. */ #ifndef CONFIG_DISABLE_SIGNALS usleep(HALF_SECOND_USEC); #ifdef CONFIG_CAN_PASS_STRUCTS g_mmafter = mallinfo(); #else (void)mallinfo(&g_mmafter); #endif printf("\nFinal memory usage:\n"); show_memory_usage(&g_mmbefore, &g_mmafter); #endif } printf("user_main: Exitting\n"); return 0; }
int ostest_main(int argc, FAR char *argv[]) { int result; #ifdef CONFIG_EXAMPLES_OSTEST_WAITRESULT int ostest_result = ERROR; #else int ostest_result = OK; #endif /* Verify that stdio works first */ stdio_test(); #ifdef SDCC /* I am not yet certain why SDCC does not like the following initilizers. * It involves some issues with 2- vs 3-byte pointer types. */ g_argv[0] = arg1; g_argv[1] = arg2; g_argv[2] = arg3; g_argv[3] = arg4; g_argv[4] = NULL; #endif /* Set up some environment variables */ #ifndef CONFIG_DISABLE_ENVIRON printf("ostest_main: putenv(%s)\n", g_putenv_value); putenv(g_putenv_value); /* Varaible1=BadValue3 */ printf("ostest_main: setenv(%s, %s, TRUE)\n", g_var1_name, g_var1_value); setenv(g_var1_name, g_var1_value, TRUE); /* Variable1=GoodValue1 */ printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var2_name, g_bad_value1); setenv(g_var2_name, g_bad_value1, FALSE); /* Variable2=BadValue1 */ printf("ostest_main: setenv(%s, %s, TRUE)\n", g_var2_name, g_var2_value); setenv(g_var2_name, g_var2_value, TRUE); /* Variable2=GoodValue2 */ printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name); setenv(g_var3_name, g_var3_value, FALSE); /* Variable3=GoodValue3 */ printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name); setenv(g_var3_name, g_bad_value2, FALSE); /* Variable3=GoodValue3 */ show_environment(true, true, true); #endif /* Verify that we can spawn a new task */ result = task_create("ostest", PRIORITY, STACKSIZE, user_main, (FAR char * const *)g_argv); if (result == ERROR) { printf("ostest_main: ERROR Failed to start user_main\n"); ostest_result = ERROR; } else { printf("ostest_main: Started user_main at PID=%d\n", result); #ifdef CONFIG_EXAMPLES_OSTEST_WAITRESULT /* Wait for the test to complete to get the test result */ if (waitpid(result, &ostest_result, 0) != result) { printf("ostest_main: ERROR Failed to wait for user_main to terminate\n"); ostest_result = ERROR; } #endif } printf("ostest_main: Exiting with status %d\n", ostest_result); #ifdef CONFIG_EXAMPLES_OSTEST_POWEROFF /* Power down, providing the test result. This is really only an *interesting case when used with the NuttX simulator. In that case, * test management logic can received the result of the test. */ boardctl(BOARDIOC_POWEROFF, ostest_result); #endif return ostest_result; }