bool_t _wait_event (cond_t * c, bool_t i) { bool_t res = 0; if (!cond_test (c)) { if (current == &task [0]) panic ("task 0 waits condition %x", (int) c); wait_set ((struct wait_queue *) c); while (1) { current->state = i ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE; if (cond_test (c)) break; schedule (); if (i && current->signal) { // Interrupted by signal res = 1; break; } } current->state = TASK_RUNNING; wait_clear ((struct wait_queue *) c); } return res; }
ARMSIM_INSTRUCTION * as_execute_instruction(ARMSIM_CTX *ctx, ARMSIM_INSTRUCTION * cooked_instruction){ as_log(ctx, "Entering as_execute_instruction\n",0); if(cooked_instruction == 0){ as_log(ctx, "Leaving as_execute_instruction\n",0); return 0; } char * string = (char*)malloc(sizeof(char) * LOG_STRING_LENGTH); char * instruction_string = instruction_to_string(cooked_instruction); if(cond_test(cooked_instruction->condition, get_cpsr(ctx->registers)) != 0){ sprintf(string, "EXECUTING([%s] %x)", instruction_string, get_mode(ctx->registers)); actually_execute_instruction(cooked_instruction); } else{ sprintf(string, "SKIPPING([%s] %x)", instruction_string, get_mode(ctx->registers)); } as_log(ctx, string, 0); free(string); free(instruction_string); as_log(ctx, "Leaving as_execute_instruction\n",0); return cooked_instruction; }
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; }
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; }