예제 #1
0
/*
 * Test test_jthread_set_and_get_local_storage
 */
int test_jthread_set_and_get_local_storage(void)
{
    void * data;
    hythread_t hythread;
    tested_thread_sturct_t *tts;

    // Initialize tts structures and run all tested threads
    tested_threads_run(default_run_for_test);
    
    reset_tested_thread_iterator(&tts);
    while (next_tested_thread(&tts)) {
        hythread = jthread_get_native_thread(tts->java_thread);
        tf_assert(hythread);
        tf_assert_same(hythread_tls_set(hythread, TEST_TLS_KEY, tts),
                       TM_ERROR_NONE);
    }
    reset_tested_thread_iterator(&tts);
    while (next_tested_thread(&tts)) {
        hythread = jthread_get_native_thread(tts->java_thread);
        tf_assert(hythread);
        data = hythread_tls_get(hythread, TEST_TLS_KEY);
        tf_assert_same(data, tts);
    }

    // Terminate all threads and clear tts structures
    tested_threads_destroy();

    return TEST_PASSED;
}
int check_phase(tested_thread_sturct_t *tts, int phase) {
    
    tf_assert(tts->phase != TT_PHASE_ERROR);
    if (phase == TT_PHASE_ANY) {
        tf_assert(tts->phase != TT_PHASE_NONE);
    } else if (tts->phase != phase) {
        log_info("Expected phase %d, but got %d", phase, tts->phase);
        tf_assert_same(tts->phase, phase);
    }
    return TEST_PASSED;
}
int test_jthread_holds_lock(void) {

    tested_thread_sturct_t *tts;
    tested_thread_sturct_t *critical_tts = NULL;
    int blocked_count;
    int i;

    hysem_create(&mon_enter, 0, 1);

    // Initialize tts structures and run all tested threads
    tested_threads_run(run_for_test_jthread_holds_lock);
    

    for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
        blocked_count = 0;
        critical_tts = NULL;

        hysem_wait(mon_enter);

        reset_tested_thread_iterator(&tts);
        while(next_tested_thread(&tts)){
            while(tts->phase == TT_PHASE_NONE) {
                // thread is not started yet
                hythread_yield();
            }
            if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
                tf_assert(jthread_holds_lock(tts->java_thread, tts->monitor) > 0);
                tf_assert_null(critical_tts);
                critical_tts = tts;
            } else if (tts->phase != TT_PHASE_DEAD){
                check_tested_thread_phase(tts, TT_PHASE_WAITING_ON_MONITOR);
                tf_assert(jthread_holds_lock(tts->java_thread, tts->monitor) == 0);
                if (tts->phase == TT_PHASE_WAITING_ON_MONITOR){
                    blocked_count++;
                }
            }
        }
        tf_assert(critical_tts); // thread in critical section found
        tf_assert_same(blocked_count, MAX_TESTED_THREAD_NUMBER - i - 1);
        tested_thread_send_stop_request(critical_tts);
        tested_thread_wait_ended(critical_tts);
        check_tested_thread_phase(critical_tts, TT_PHASE_DEAD);
    }

    // Terminate all threads and clear tts structures
    tested_threads_destroy();

    return TEST_PASSED;
}
int check_structure(tested_thread_sturct_t *tts){

    jthread java_thread = tts->java_thread;
    vm_thread_t vm_thread;
    jvmti_thread_t jvmti_thread;
    hythread_t hythread;

    vm_thread = jthread_get_vm_thread_from_java(java_thread);
    tf_assert(vm_thread);
    hythread = (hythread_t)vm_thread;
    tf_assert_same(hythread, tts->native_thread);
    jvmti_thread = &(vm_thread->jvmti_thread);
    tf_assert(jvmti_thread);
    return TEST_PASSED;
}
예제 #5
0
int testEmptyInput(void) {
    char *input = "";
    char *expected = "";
    char output[MAXLINE] = "";
    tf_assert(strcmp(fold(input, output, FOLDPOINT), expected) == 0, "Expected '%s' was '%s'", expected, output);
    tf_passed();
}
예제 #6
0
int testSkipAFoldPoint(void) {
    char *input = "a b c de f";
    char *expected = "a b.c de.f";
    char output[MAXLINE] = "";
    tf_assert(strcmp(fold(input, output, FOLDPOINT), expected) == 0, "Expected '%s' was '%s'", expected, output);
    tf_passed();
}
예제 #7
0
int testBasicFolding(void) {
    char *input = "abc def";
    char *expected = "abc.def";
    char output[MAXLINE] = "";
    tf_assert(strcmp(fold(input, output, FOLDPOINT), expected) == 0, "Expected '%s' was '%s'", expected, output);
    tf_passed();
}
예제 #8
0
int testOverLongWord(void) {
    char *input = "abcde";
    char *expected = "abcd.e";
    char output[MAXLINE] = "";
    tf_assert(strcmp(fold(input, output, FOLDPOINT), expected) == 0, "Expected '%s' was '%s'", expected, output);
    tf_passed();
}
int test_jthread_get_owned_monitors(void) {

    tested_thread_sturct_t *tts;
    tested_thread_sturct_t *critical_tts;
    int i;
    jint owned_monitors_count;
    jobject *owned_monitors = NULL;

    hysem_create(&mon_enter, 0, 1);

    // Initialize tts structures and run all tested threads
    tested_threads_run(run_for_test_jthread_get_owned_monitors);
    
    for (i = 0; i < MAX_TESTED_THREAD_NUMBER; i++){
        critical_tts = NULL;

        hysem_wait(mon_enter);

        reset_tested_thread_iterator(&tts);
        while(next_tested_thread(&tts)) {
            while(tts->phase == TT_PHASE_NONE) {
                // thread is not started yet
                hythread_yield();
            }
            if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
                tf_assert_same(jthread_get_owned_monitors (tts->java_thread,
                    &owned_monitors_count, &owned_monitors), TM_ERROR_NONE);
                tf_assert(critical_tts == NULL);
                critical_tts = tts;
                tf_assert_same(owned_monitors_count, 1);
                tf_assert_same(owned_monitors[0]->object, tts->monitor->object);
            } else if (tts->phase == TT_PHASE_WAITING_ON_MONITOR){
                tf_assert_same(jthread_get_owned_monitors (tts->java_thread,
                    &owned_monitors_count, &owned_monitors), TM_ERROR_NONE);
                tf_assert_same(owned_monitors_count, 0);
            }
        }
        tf_assert(critical_tts);
        tested_thread_send_stop_request(critical_tts);
        tested_thread_wait_ended(critical_tts);
    }
    // Terminate all threads and clear tts structures
    tested_threads_destroy();

    return TEST_PASSED;
}
int compare_threads(jthread *threads, int thread_nmb, int compare_from_end) {

    int i;
    int j;
    int found;
    int tested_thread_start;
    jthread java_thread;

    // Check that all thread_nmb threads are different

    //printf("----------------------------------------------- %i %i\n", thread_nmb, compare_from_end);
    //for (j = 0; j < MAX_TESTED_THREAD_NUMBER; j++){
    //      printf("[%i] %p\n",j,tested_threads[j].java_thread->object);
    //}
    //printf("\n");
    //for (i = 0; i < thread_nmb; i++){
    //      printf("!!! %p\n", (*(threads + i))->object);
    //}
    for (i = 0; i < thread_nmb - 1; i++){
        java_thread = *(threads + i);
        for (j = i + 1; j < thread_nmb; j++){
            if (*(threads + j) == java_thread){
                return TM_ERROR_INTERNAL;
            }
        }
    }

    // Check that the set of threads are equal to the set of the first 
    // or the last thread_nmb tested threads

    tested_thread_start = compare_from_end ? MAX_TESTED_THREAD_NUMBER - thread_nmb : 0;
    for (i = 0; i < thread_nmb; i++){
        java_thread = *(threads + i);
        found = 0;
        for (j = tested_thread_start; j < thread_nmb + tested_thread_start; j++){
            if (tested_threads[j].java_thread->object == java_thread->object){
                found = 1;
                break;
            }
        }
        tf_assert(found);
    }
    return TM_ERROR_NONE;
}
int demo_test_pass()
{
	tf_assert(true(), "This demo_test should pass silently");
	tf_passed();
}
int demo_test_fail()
{
	tf_assert(false(), "This demo_test should fail and emit this message to the log file");
	tf_passed();
}