📄 main.c
字号:
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#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"); cond_test(); check_test_memory_usage();#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 /* Compare memory usage at time user_start 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(500*1000);#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;}/**************************************************************************** * Name: stdio_test ****************************************************************************/static void stdio_test(void){ /* Verify that we can communicate */#if CONFIG_NFILE_DESCRIPTORS > 0 write(1, write_data1, sizeof(write_data1)-1);#endif printf("stdio_test: Standard I/O Check: printf\n");#if CONFIG_NFILE_DESCRIPTORS > 1 write(2, write_data2, sizeof(write_data2)-1);#endif#if CONFIG_NFILE_STREAMS > 0 fprintf(stderr, "stdio_test: Standard I/O Check: fprintf to stderr\n");#endif}/**************************************************************************** * Public Functions ****************************************************************************//**************************************************************************** * user_initialize ****************************************************************************/void user_initialize(void){ /* stub */}/**************************************************************************** * user_start ****************************************************************************/int user_start(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("user_start: putenv(%s)\n", g_putenv_value); putenv(g_putenv_value); /* Varaible1=BadValue3 */ printf("user_start: setenv(%s, %s, TRUE)\n", g_var1_name, g_var1_value); setenv(g_var1_name, g_var1_value, TRUE); /* Variable1=GoodValue1 */ printf("user_start: setenv(%s, %s, FALSE)\n", g_var2_name, g_bad_value1); setenv(g_var2_name, g_bad_value1, FALSE); /* Variable2=BadValue1 */ printf("user_start: setenv(%s, %s, TRUE)\n", g_var2_name, g_var2_value); setenv(g_var2_name, g_var2_value, TRUE); /* Variable2=GoodValue2 */ printf("user_start: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name); setenv(g_var3_name, g_var3_value, FALSE); /* Variable3=GoodValue3 */ printf("user_start: 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("user_start: ERROR Failed to start user_main\n"); } else { printf("user_start: Started user_main at PID=%d\n", result); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -