int main(int argc, char *argv[]) { START(argc, argv, "obj_cpp_cond_var"); if (argc != 2) UT_FATAL("usage: %s file-name", argv[0]); const char *path = argv[1]; nvobj::pool<struct root> pop; try { pop = nvobj::pool<struct root>::create( path, LAYOUT, PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR); } catch (pmem::pool_error &pe) { UT_FATAL("!pool::create: %s %s", pe.what(), path); } cond_zero_test(pop); std::vector<reader_type> notify_functions( {reader_mutex, reader_mutex_pred, reader_lock, reader_lock_pred, reader_mutex_until, reader_mutex_until_pred, reader_lock_until, reader_lock_until_pred, reader_mutex_for, reader_mutex_for_pred, reader_lock_for, reader_lock_for_pred}); for (auto func : notify_functions) { int reset_value = 42; mutex_test(pop, true, false, write_notify, func); pop.get_root()->counter = reset_value; mutex_test(pop, true, true, write_notify, func); pop.get_root()->counter = reset_value; } std::vector<reader_type> not_notify_functions( {reader_mutex_until, reader_mutex_until_pred, reader_lock_until, reader_lock_until_pred, reader_mutex_for, reader_mutex_for_pred, reader_lock_for, reader_lock_for_pred}); for (auto func : not_notify_functions) { int reset_value = 42; mutex_test(pop, false, false, write_notify, func); pop.get_root()->counter = reset_value; mutex_test(pop, false, true, write_notify, func); pop.get_root()->counter = reset_value; } /* pmemcheck related persist */ pmemobj_persist(pop.get_handle(), &(pop.get_root()->counter), sizeof(pop.get_root()->counter)); pop.close(); DONE(nullptr); }
int main(int argc, char *argv[]) { if (argc < 2) fail("To few arguments for test case"); #ifndef ETHR_NO_THREAD_LIB { char *testcase; send_my_pid(); testcase = argv[1]; if (ethr_init(NULL) != 0 || ethr_late_init(NULL) != 0) fail("Failed to initialize the ethread library"); if (strcmp(testcase, "create_join_thread") == 0) create_join_thread_test(); else if (strcmp(testcase, "equal_tids") == 0) equal_tids_test(); else if (strcmp(testcase, "mutex") == 0) mutex_test(); else if (strcmp(testcase, "try_lock_mutex") == 0) try_lock_mutex_test(); else if (strcmp(testcase, "cond_wait") == 0) cond_wait_test(); else if (strcmp(testcase, "broadcast") == 0) broadcast_test(); else if (strcmp(testcase, "detached_thread") == 0) detached_thread_test(); else if (strcmp(testcase, "max_threads") == 0) max_threads_test(); else if (strcmp(testcase, "tsd") == 0) tsd_test(); else if (strcmp(testcase, "spinlock") == 0) spinlock_test(); else if (strcmp(testcase, "rwspinlock") == 0) rwspinlock_test(); else if (strcmp(testcase, "rwmutex") == 0) rwmutex_test(); else if (strcmp(testcase, "atomic") == 0) atomic_test(); else if (strcmp(testcase, "dw_atomic_massage") == 0) dw_atomic_massage_test(); else skip("Test case \"%s\" not implemented yet", testcase); succeed(NULL); } #else /* #ifndef ETHR_NO_THREAD_LIB */ skip("No ethread library to test"); #endif /* #ifndef ETHR_NO_THREAD_LIB */ return 0; }
int thread_tests(void) { mutex_test(); event_test(); thread_sleep(200); context_switch_test(); atomic_test(); return 0; }
int main(int argc, char *argv[]) { START(argc, argv, "obj_cpp_shared_mutex"); if (argc != 2) UT_FATAL("usage: %s file-name", argv[0]); const char *path = argv[1]; nvobj::pool<root> pop; try { pop = nvobj::pool<root>::create(path, LAYOUT, PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR); } catch (nvml::pool_error &pe) { UT_FATAL("!pool::create: %s %s", pe.what(), path); } int expected = num_threads * num_ops * 2; mutex_test(pop, writer, reader); UT_ASSERTeq(pop.get_root()->counter, expected); /* trylocks are not tested as exhaustively */ expected -= num_threads * 2; mutex_test(pop, writer_trylock, reader_trylock); UT_ASSERTeq(pop.get_root()->counter, expected); /* pmemcheck related persist */ pmemobj_persist(pop.get_handle(), &(pop.get_root()->counter), sizeof(pop.get_root()->counter)); pop.close(); DONE(NULL); }
int thread_tests(void) { mutex_test(); semaphore_test(); event_test(); spinlock_test(); atomic_test(); thread_sleep(200); context_switch_test(); preempt_test(); join_test(); return 0; }
/** * * @brief Perform all selected benchmarks * see config.h to select or to unselect * * @return N/A */ void BenchTask(void) { int autorun = 0, continuously = 0; init_output(&continuously, &autorun); bench_test_init(); PRINT_STRING(newline, output_file); do { PRINT_STRING(dashline, output_file); PRINT_STRING("| S I M P L E S E R V I C E " "M E A S U R E M E N T S | nsec |\n", output_file); PRINT_STRING(dashline, output_file); task_start(RECVTASK); call_test(); queue_test(); sema_test(); mutex_test(); memorymap_test(); mempool_test(); event_test(); mailbox_test(); pipe_test(); PRINT_STRING("| END OF TESTS " " |\n", output_file); PRINT_STRING(dashline, output_file); PRINT_STRING("PROJECT EXECUTION SUCCESSFUL\n",output_file); } while (continuously && !kbhit()); WAIT_FOR_USER(); if (autorun) { task_sleep(SECONDS(2)); } output_close(); }
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 test_inner(void) { pj_caching_pool caching_pool; const char *filename; int line; int rc = 0; mem = &caching_pool.factory; pj_log_set_level(3); pj_log_set_decor(param_log_decor); rc = pj_init(); if (rc != 0) { app_perror("pj_init() error!!", rc); return rc; } //pj_dump_config(); pj_caching_pool_init( &caching_pool, NULL, 0 ); #if INCLUDE_ERRNO_TEST DO_TEST( errno_test() ); #endif #if INCLUDE_EXCEPTION_TEST DO_TEST( exception_test() ); #endif #if INCLUDE_OS_TEST DO_TEST( os_test() ); #endif #if INCLUDE_RAND_TEST DO_TEST( rand_test() ); #endif #if INCLUDE_LIST_TEST DO_TEST( list_test() ); #endif #if INCLUDE_POOL_TEST DO_TEST( pool_test() ); #endif #if INCLUDE_POOL_PERF_TEST DO_TEST( pool_perf_test() ); #endif #if INCLUDE_STRING_TEST DO_TEST( string_test() ); #endif #if INCLUDE_FIFOBUF_TEST DO_TEST( fifobuf_test() ); #endif #if INCLUDE_RBTREE_TEST DO_TEST( rbtree_test() ); #endif #if INCLUDE_HASH_TEST DO_TEST( hash_test() ); #endif #if INCLUDE_TIMESTAMP_TEST DO_TEST( timestamp_test() ); #endif #if INCLUDE_ATOMIC_TEST DO_TEST( atomic_test() ); #endif #if INCLUDE_MUTEX_TEST DO_TEST( mutex_test() ); #endif #if INCLUDE_TIMER_TEST DO_TEST( timer_test() ); #endif #if INCLUDE_SLEEP_TEST DO_TEST( sleep_test() ); #endif #if INCLUDE_THREAD_TEST DO_TEST( thread_test() ); #endif #if INCLUDE_SOCK_TEST DO_TEST( sock_test() ); #endif #if INCLUDE_SOCK_PERF_TEST DO_TEST( sock_perf_test() ); #endif #if INCLUDE_SELECT_TEST DO_TEST( select_test() ); #endif #if INCLUDE_UDP_IOQUEUE_TEST DO_TEST( udp_ioqueue_test() ); #endif #if PJ_HAS_TCP && INCLUDE_TCP_IOQUEUE_TEST DO_TEST( tcp_ioqueue_test() ); #endif #if INCLUDE_IOQUEUE_PERF_TEST DO_TEST( ioqueue_perf_test() ); #endif #if INCLUDE_IOQUEUE_UNREG_TEST DO_TEST( udp_ioqueue_unreg_test() ); #endif #if INCLUDE_ACTIVESOCK_TEST DO_TEST( activesock_test() ); #endif #if INCLUDE_FILE_TEST DO_TEST( file_test() ); #endif #if INCLUDE_SSLSOCK_TEST DO_TEST( ssl_sock_test() ); #endif #if INCLUDE_ECHO_SERVER //echo_server(); //echo_srv_sync(); udp_echo_srv_ioqueue(); #elif INCLUDE_ECHO_CLIENT if (param_echo_sock_type == 0) param_echo_sock_type = pj_SOCK_DGRAM(); echo_client( param_echo_sock_type, param_echo_server, param_echo_port); #endif goto on_return; on_return: pj_caching_pool_destroy( &caching_pool ); PJ_LOG(3,("test", "")); pj_thread_get_stack_info(pj_thread_this(), &filename, &line); PJ_LOG(3,("test", "Stack max usage: %u, deepest: %s:%u", pj_thread_get_stack_max_usage(pj_thread_this()), filename, line)); if (rc == 0) PJ_LOG(3,("test", "Looks like everything is okay!..")); else PJ_LOG(3,("test", "Test completed with error(s)")); pj_shutdown(); 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; }
/** * \fn vm_segment_grow * \brief Grow the size of the segment * \param s * \param size * \brief The size by which we want the segment to grow * \return A standard error code * By the way, notice how it is only possible to grow a segment? * Indeed that's by design. Segments can only grow, not shrink. If they could, * they might cut into allocated data, and that's bad. If pages aren't in use * anymore, paging should take care of those, so no need to worry about it here. * * \todo implement swapping and destroying of pages that have gone out of use. */ int vm_segment_grow(struct vm_segment* s, size_t size) { if (s == NULL || size <= 0 || s->parent == NULL) return -E_INVALID_ARG; /* Round size up if necessary */ if (size % PAGE_ALLOC_FACTOR != 0) size += PAGE_ALLOC_FACTOR - size % PAGE_ALLOC_FACTOR; struct vm_descriptor* d = s->parent; retry: /* This stuff is all critical ... */ mutex_lock(&d->lock); int ns = s->size + size; addr_t nend = (addr_t)s->virt_base + ns; int ret = -E_OUTOFBOUNDS; struct vm_segment* i; /* Basically what we don't want is for our segments to overlap */ for (i = d->segments; i != NULL; i = i->next) { /* If we're verifying with our selves we are doing it wrong */ if (i == s) continue; addr_t start; addr_t end; if (mutex_test(&i->lock) == 0) { start = (addr_t)i->virt_base; end = (addr_t)(i->virt_base + i->size); } else { mutex_unlock(&d->lock); /** \todo Find a way to yield CPU time here */ goto retry; } /* * Do some overlapping checks */ if ((nend > start && nend <= end) || (ns >= start && ns < end)) goto err; if (ns <= start && nend >= end) goto err; } /* * Since we're not going to overlap, we can now complete the * transaction. Also set the return value to success. */ mutex_lock(&s->lock); s->size += size; mutex_unlock(&s->lock); ret = -E_SUCCESS; err: mutex_unlock(&d->lock); return ret; }