int main() { tellmeall(); if (!printf_test()) return -1; if (!set_get_test()) return -1; if (!and_or_test()) return -1; if (!xor_test()) return -1; if (!andnot_test()) return -1; if (!to_uint32_array_test()) return -1; printf("[%s] your code might be ok.\n", __FILE__); return 0; }
int pthread_condattr_test(){ pthread_condattr_t attr; clockid_t id; printf("Test pthread_condattr_init()..."); if ( pthread_condattr_init(&attr) < 0 ){ fflush(stdout); perror("failed"); return -1; } printf("passed\n"); if ( set_get_test("pthread_condattr_set/getpshared()", (int (*)(void*,int))pthread_condattr_setpshared, (int (*)(void*,int*))pthread_condattr_getpshared, &attr, pshareds, PSHARED_TOTAL, 0) ){ return -1; } if ( set_get_test("pthread_condattr_set/getclock()", (int (*)(void*,int))pthread_condattr_setclock, (int (*)(void*,int*))pthread_condattr_getclock, &attr, clock_cases, CLOCK_TOTAL, 0) ){ return -1; } printf("Test pthread_condattr_getclock()..."); if ( pthread_condattr_getclock(&attr, &id) < 0 ){ fflush(stdout); perror("failed"); return -1; } if ( id != CLOCK_REALTIME ){ printf("failed to get\n"); return -1; } printf("passed\n"); printf("Test pthread_condattr_destroy()..."); if ( pthread_condattr_destroy(&attr) < 0 ){ fflush(stdout); perror("failed"); return -1; } printf("passed\n"); printf("Stress Test pthread_condattr_destroy()..."); if ( pthread_condattr_destroy(&attr) == 0 ){ printf("failed\n"); return -1; } if ( errno == EINVAL ){ errno = 0; printf("passed\n"); } else { printf("failed errno is %d not %d\n", errno, EINVAL); } return 0; }
int pthread_mutexattr_test(){ pthread_mutexattr_t attr; int tmp; int i; printf("Test pthread_mutexattr_init()..."); if ( pthread_mutexattr_init(&attr) < 0 ){ fflush(stdout); perror("failed"); return -1; } printf("passed\n"); printf("Test pthread_mutexattr_set/getprioceiling()..."); for(i = sched_get_priority_min(SCHED_OTHER); i <= sched_get_priority_max(SCHED_OTHER); i++ ){ if ( pthread_mutexattr_setprioceiling(&attr, i) < 0 ){ fflush(stdout); perror("failed"); return -1; } if ( pthread_mutexattr_getprioceiling(&attr, &tmp) < 0 ){ fflush(stdout); perror("failed"); return -1; } if ( tmp != i ){ printf("failed to set/get (%d != %d)\n", tmp, i); return -1; } } printf("passed\n"); if ( set_get_test("pthread_mutexattr_set/getprotocol()", (int (*)(void*,int))pthread_mutexattr_setprotocol, (int (*)(void*,int*))pthread_mutexattr_getprotocol, &attr, protocols, PROTOCOLS_TOTAL, 0) ){ return -1; } printf("Test pthread_mutexattr_set/getpshared()..."); tmp = 1; if ( pthread_mutexattr_setpshared(&attr, tmp) < 0 ){ fflush(stdout); perror("failed"); return -1; } if ( pthread_mutexattr_getpshared(&attr, &tmp) < 0 ){ fflush(stdout); perror("failed"); return -1; } if ( tmp != 1 ){ fflush(stdout); perror("failed"); return -1; } printf("passed\n"); if ( set_get_test("pthread_mutexattr_set/gettype()", (int (*)(void*,int))pthread_mutexattr_settype, (int (*)(void*,int*))pthread_mutexattr_gettype, &attr, types, TYPES_TOTAL, 0) ){ return -1; } printf("Test pthread_mutexattr_destroy()..."); if ( pthread_mutexattr_destroy(&attr) < 0 ){ fflush(stdout); perror("failed"); return -1; } printf("passed\n"); printf("Stress Test pthread_mutexattr_destroy()..."); if ( pthread_mutexattr_destroy(&attr) == 0 ){ printf("should have failed\n"); return -1; } errno = 0; printf("passed\n"); return 0; }
int pthread_attr_test(void){ pthread_attr_t attr; int tmp; void * stackaddr; int i; printf("Test pthread_attr_init()..."); if ( pthread_attr_init(&attr) < 0 ){ fflush(stdout); perror("failed"); return -1; } printf("passed\n"); if ( set_get_test("pthread_attr_set/getdetachstate()", (int (*)(void*,int))pthread_attr_setdetachstate, (int (*)(void*,int*))pthread_attr_getdetachstate, &attr, detachstates, DETACHSTATE_TOTAL, 0) ){ return -1; } printf("Test pthread_attr_getguardsize()..."); if ( pthread_attr_getguardsize(&attr, (size_t*)&tmp) < 0 ){ fflush(stdout); perror("failed"); return -1; } printf("passed\n"); if ( set_get_test("pthread_attr_set/getinheritsched()", (int (*)(void*,int))pthread_attr_setinheritsched, (int (*)(void*,int*))pthread_attr_getinheritsched, &attr, inheritscheds, INHERITSCHED_TOTAL, 0) ){ return -1; } if ( set_get_test("pthread_attr_set/getschedpolicy()", (int (*)(void*,int))pthread_attr_setschedpolicy, (int (*)(void*,int*))pthread_attr_getschedpolicy, &attr, schedpolicies, SCHEDPOLICY_TOTAL, 0) ){ return -1; } printf("Test pthread_attr_set/getschedparam() with SCHED_FIFO..."); pthread_attr_setschedpolicy(&attr, SCHED_FIFO); for(i=sched_get_priority_min(SCHED_FIFO); i <= sched_get_priority_max(SCHED_FIFO); i++){ if ( test_schedparam(&attr, i, 0) < 0 ){ return -1; } } if ( test_schedparam(&attr, sched_get_priority_max(SCHED_FIFO) + 1, EINVAL) < 0 ){ return -1; } if ( test_schedparam(&attr, sched_get_priority_min(SCHED_FIFO) - 1, EINVAL) < 0 ){ return -1; } printf("passed\n"); printf("Test pthread_attr_set/getschedparam() with SCHED_RR..."); pthread_attr_setschedpolicy(&attr, SCHED_RR); for(i=sched_get_priority_min(SCHED_RR); i <= sched_get_priority_max(SCHED_RR); i++){ if ( test_schedparam(&attr, i, 0) < 0 ){ return -1; } } if ( test_schedparam(&attr, sched_get_priority_max(SCHED_RR) + 1, EINVAL) < 0 ){ return -1; } if ( test_schedparam(&attr, sched_get_priority_min(SCHED_RR) - 1, EINVAL) < 0 ){ return -1; } printf("passed\n"); printf("Test pthread_attr_set/getschedparam() with SCHED_OTHER..."); pthread_attr_setschedpolicy(&attr, SCHED_OTHER); for(i=sched_get_priority_min(SCHED_OTHER); i <= sched_get_priority_max(SCHED_OTHER); i++){ if ( test_schedparam(&attr, i, 0) < 0 ){ return -1; } } if ( test_schedparam(&attr, sched_get_priority_max(SCHED_OTHER) + 1, EINVAL) < 0 ){ return -1; } if ( test_schedparam(&attr, sched_get_priority_min(SCHED_OTHER) - 1, EINVAL) < 0 ){ return -1; } printf("passed\n"); if ( set_get_test("pthread_attr_set/getscope()", (int (*)(void*,int))pthread_attr_setscope, (int (*)(void*,int*))pthread_attr_getscope, &attr, scopes, SCOPE_TOTAL, 0) ){ return -1; } printf("Test pthread_attr_getstackaddr()..."); if ( pthread_attr_getstackaddr(&attr, &stackaddr) ){ fflush(stdout); perror("failed"); return -1; } printf("passed\n"); printf("Test pthread_attr_destroy()..."); if ( pthread_attr_destroy(&attr) ){ fflush(stdout); perror("failed"); return -1; } printf("passed\n"); printf("Stress Test pthread_attr_destroy()..."); if ( pthread_attr_destroy(&attr) == 0){ printf("should have failed\n"); return -1; } if ( errno != EINVAL ){ printf("errno should be %d not %d\n", EINVAL, errno); return -1; } printf("passed\n"); return 0; }