int test_hytime_hires_clock(struct HyPortLibrary *hyportLibrary) { U_64 hires,hires2; hires = hyportLibrary->time_hires_clock(hyportLibrary); printf("hires = %llu\n", hires); hythread_sleep(1000); hires2 = hyportLibrary->time_hires_clock(hyportLibrary); printf("hires2 = %llu\n", hires2); return 0; }
void test_thread_join(hythread_t native_thread, int index) { int i = 0; do { hythread_sleep(SLEEP_TIME); if(!hythread_is_alive(native_thread)) { break; } if (!i && (i % (MAX_TIME_TO_WAIT / SLEEP_TIME)) == 0) { printf("Thread %i isn't dead after %i milliseconds", index, (++i * SLEEP_TIME)); } } while(1); }
int test_hytime_hires_delta(struct HyPortLibrary *hyportLibrary) { U_64 delta,hires,hires2,freq; hires = hyportLibrary->time_hires_clock(hyportLibrary); printf("hires = %llu\n", hires); freq = hyportLibrary->time_hires_frequency(hyportLibrary); printf("freq = %llu\n", freq); hythread_sleep(1000); hires2 = hyportLibrary->time_hires_clock(hyportLibrary); printf("hires2 = %llu\n", hires2); delta = hyportLibrary->time_hires_delta(hyportLibrary, hires, hires2, HYPORT_TIME_DELTA_IN_MICROSECONDS); printf("delta = %llu\n", delta); if (delta <= 0) { Hytest_setErrMsg(hyportLibrary, "hires_clock did not increment after 1s sleep\n"); return -1; } return 0; }
void test_java_thread_setup(int argc, char *argv[]) { create_java_vm_func CreateJavaVM; JavaVMInitArgs args; JNIEnv * jni_env; int i; CreateJavaVM = test_get_java_vm_ptr(); assert(CreateJavaVM); args.version = JNI_VERSION_1_2; args.nOptions = argc; args.options = (JavaVMOption *) malloc(args.nOptions * sizeof(JavaVMOption)); args.options[0].optionString = "-Djava.class.path=."; for (i = 1; i < argc; i++) { args.options[i].optionString = argv[i]; args.options[i].extraInfo = NULL; } log_debug("test_java_thread_init()"); hythread_sleep(1000); CreateJavaVM(&GLOBAL_VM, &jni_env, &args); }
void sleep_a_click(void){ hythread_sleep(CLICK_TIME_MSEC); }
int test_hythread_thread_suspend_all(void) { void **args; hythread_t thread_list[THREAD_COUNT]; hythread_thin_monitor_t lock; hythread_thin_monitor_t monitor; IDATA status; int i; // create monitors status = hythread_thin_monitor_create(&monitor); tf_assert_same(status, TM_ERROR_NONE); status = hythread_thin_monitor_create(&lock); tf_assert_same(status, TM_ERROR_NONE); // alloc and set thread start procedure args args = (void**)calloc(3, sizeof(void*)); args[0] = &lock; args[1] = &monitor; args[2] = 0; // create threads hythread_suspend_disable(); status = hythread_thin_monitor_enter(&lock); tf_assert_same(status, TM_ERROR_NONE); hythread_suspend_enable(); started_thread_count = 0; for(i = 0; i < THREAD_COUNT; i++) { thread_list[i] = NULL; status = hythread_create(&thread_list[i], 0, 0, 0, (hythread_entrypoint_t)start_proc, args); tf_assert_same(status, TM_ERROR_NONE); log_info("%d thread is started", i + 1); } // waiting start of tested thread hythread_suspend_disable(); while (started_thread_count < 10) { status = hythread_thin_monitor_wait(&lock); tf_assert_same(status, TM_ERROR_NONE); } status = hythread_thin_monitor_exit(&lock); tf_assert_same(status, TM_ERROR_NONE); hythread_suspend_enable(); // suspend tested thread status = hythread_suspend_all(NULL, ((HyThread_public*)hythread_self())->group); tf_assert_same(status, TM_ERROR_NONE); log_info("all threads are suspended"); // notify tested threads hythread_suspend_disable(); status = hythread_thin_monitor_enter(&monitor); tf_assert_same(status, TM_ERROR_NONE); status = hythread_thin_monitor_notify_all(&monitor); tf_assert_same(status, TM_ERROR_NONE); status = hythread_thin_monitor_exit(&monitor); tf_assert_same(status, TM_ERROR_NONE); hythread_suspend_enable(); log_info("notify all suspended threads"); // check tested argument for(i = 0; i < 1000; i++) { tf_assert_same(args[2], 0); hythread_sleep(1); } // resume thread status = hythread_resume_all(((HyThread_public*)hythread_self())->group); tf_assert_same(status, TM_ERROR_NONE); log_info("resume all suspended threads"); for(i = 0; i < THREAD_COUNT; i++) { test_thread_join(thread_list[i], i); log_info("%d thread is terminated", i + 1); } tf_assert_same((IDATA)args[2], THREAD_COUNT); return 0; }
int test_hythread_thread_suspend(void){ void **args; hythread_t thread = NULL; hythread_thin_monitor_t lock; hythread_thin_monitor_t monitor; IDATA status; int i; // create monitors status = hythread_thin_monitor_create(&lock); tf_assert_same(status, TM_ERROR_NONE); status = hythread_thin_monitor_create(&monitor); tf_assert_same(status, TM_ERROR_NONE); // alloc and set thread start procedure args args = (void**)calloc(3, sizeof(void*)); args[0] = &lock; args[1] = &monitor; args[2] = 0; // create thread hythread_suspend_disable(); status = hythread_thin_monitor_enter(&lock); tf_assert_same(status, TM_ERROR_NONE); hythread_suspend_enable(); status = hythread_create(&thread, 0, 0, 0, (hythread_entrypoint_t)start_proc, args); tf_assert_same(status, TM_ERROR_NONE); // waiting start of tested thread hythread_suspend_disable(); status = hythread_thin_monitor_wait(&lock); tf_assert_same(status, TM_ERROR_NONE); status = hythread_thin_monitor_exit(&lock); tf_assert_same(status, TM_ERROR_NONE); hythread_suspend_enable(); // suspend tested thread status = hythread_suspend_other(thread); tf_assert_same(status, TM_ERROR_NONE); // notify tested thread hythread_suspend_disable(); status = hythread_thin_monitor_enter(&monitor); tf_assert_same(status, TM_ERROR_NONE); status = hythread_thin_monitor_notify_all(&monitor); tf_assert_same(status, TM_ERROR_NONE); status = hythread_thin_monitor_exit(&monitor); tf_assert_same(status, TM_ERROR_NONE); hythread_suspend_enable(); // check tested argument for(i = 0; i < 1000; i++) { tf_assert_same(args[2], 0); hythread_sleep(1); } // resume thread hythread_resume(thread); test_thread_join(thread, 1); tf_assert_same((IDATA)args[2], 1); return 0; }