The test was using a mish-mash of unsigned long and int types to pass
data between the thread and evaluate values, so the problem lied in
potential truncation of data.

time_t is a 32-bit type or 64-bit type on some OSes, so it's best to
remain consistent with a single fixed data type instead of moving
between int (which can be 32-bit or 64-bit, depending on the OS and
architecture) and unsigned long (which can be 32-bit or 64-bit,
depending on the OS and architecture).

Signed-off-by: Gui Jianfeng <[email protected]>
---
 .../functional/threads/pi_test/pitest-4.c          |   22 ++-----------------
 1 files changed, 3 insertions(+), 19 deletions(-)

diff --git 
a/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-4.c 
b/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-4.c
index e6bff3f..da6623e 100644
--- a/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-4.c
+++ b/testcases/open_posix_testsuite/functional/threads/pi_test/pitest-4.c
@@ -176,7 +176,6 @@ void *thread_sample(void *arg)
 
 void *thread_tb1(void *arg)
 {
-       unsigned long timeoutsec; 
        struct timespec boost_time;
        double t0, t1;
        int rc;
@@ -188,8 +187,7 @@ void *thread_tb1(void *arg)
 
        pthread_mutex_lock(&mutex2);
  
-       timeoutsec = *(unsigned long*) arg;
-       boost_time.tv_sec = time(NULL) + (time_t)timeoutsec;
+       boost_time.tv_sec = time(NULL) + *(time_t*) arg;
        boost_time.tv_nsec = 0;
        t0 = seconds_read();
        rc = pthread_mutex_timedlock(&mutex1, &boost_time);     
@@ -198,12 +196,6 @@ void *thread_tb1(void *arg)
        DPRINTF(stdout, "#EVENT %f TB1 Waited on mutex1 for %.2f s\n", 
                t1 - base_time, t1 - t0);
 
-       if (rc == 0) {
-               EPRINTF("UNRESOLVED: Thread TB1: lock mutex1 success, "
-                       "slept %f", t1 - t0);
-               exit(UNRESOLVED);
-       }
-
        if (rc != ETIMEDOUT) {
                EPRINTF("FAIL: Thread TB1: lock returned %d %s, "
                        "slept %f", rc, strerror(rc), t1 - t0);
@@ -217,7 +209,6 @@ void *thread_tb1(void *arg)
 
 void *thread_tb2(void *arg)
 {
-       unsigned long timeoutsec; 
        struct timespec boost_time;
        double t0, t1;
        int rc;
@@ -227,8 +218,7 @@ void *thread_tb2(void *arg)
        DPRINTF(stdout, "#EVENT %f Thread TB2 Started\n", 
                seconds_read() - base_time);
 
-       timeoutsec = *(unsigned long*) arg;
-       boost_time.tv_sec = time(NULL) + (time_t)timeoutsec;
+       boost_time.tv_sec = time(NULL) + *(time_t*) arg;
        boost_time.tv_nsec = 0;
 
        t0 = seconds_read();
@@ -238,12 +228,6 @@ void *thread_tb2(void *arg)
        DPRINTF(stdout, "#EVENT %f Thread TB2 Waited on mutex2 for %.2f s\n", 
                t1 - base_time, t1 - t0);
 
-       if (rc == 0) {
-               EPRINTF("UNRESOLVED: Thread TB2: lock mutex2 success, "
-                       "slept %f", t1 - t0);
-               exit(UNRESOLVED);
-       }
-
        if (rc != ETIMEDOUT) {
                EPRINTF("FAIL: Thread TB2: lock mutex2 returned %d %s, "
                        "slept %f", rc, strerror(rc), t1 - t0);
@@ -319,7 +303,7 @@ int main(int argc, char **argv)
        sleep(base_time + multiplier * 30 - seconds_read());
 
        /* Start TB1 thread (the lowest priority thread) */
-       int timeout = multiplier * 40;
+       time_t timeout = multiplier * 40;
        rc = pthread_create(&threadtb1, &threadattr, thread_tb1, 
                            &timeout);
         if (rc != 0) {
-- 
1.7.0.4



_______________________________________________
ltt-dev mailing list
[email protected]
http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev

Reply via email to