pitest-2: Use time_t instead of unsigned long / int.
PATCH 1/3 pitest-2: Use time_t instead of unsigned long / int.
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).
--- .../functional/threads/pi_test/pitest-2.c | 10 +++------- 1 files changed, 3 insertions(+), 7 deletions(-)
testcases/open_posix_testsuite/functional/threads/pi_test/pitest-2.c +3 -7
@@ -196,7 +196,6 @@ void *thread_sample(void *arg) }void *thread_tb1 (void *arg) { -unsigned long timeoutsec;struct timespec boost_time;double t0, t1;int rc;
@@ -207,8 +206,7 @@ void *thread_tb1(void *arg)DPRINTF (stdout,"#EVENT %f TB1 Thread 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 ();
@@ -227,7 +225,6 @@ void *thread_tb1(void *arg)void *thread_tb2 (void *arg) { -unsigned long timeoutsec;struct timespec boost_time;double t0, t1;int rc;
@@ -238,8 +235,7 @@ void *thread_tb2(void *arg)DPRINTF (stdout,"#EVENT %f TB2 Thread 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 ();
@@ -323,7 +319,7 @@ int main(int argc, char **argv)sleep (base_time + multiplier *30 -seconds_read ());/* Start TB1 thread (boosting thread) */ -int timeout = multiplier *20 ; +time_t timeout = multiplier *20 ; rc =pthread_create (&threadtb1, &threadattr, thread_tb1, &timeout);if (rc !=0 ) {
Signature · 13 lines
1.7.0.4 ------------------------------------------------------------------------------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Hi Garrett,
Would you pick up this patchset?
Gui
Quoted 56 lines · Gui Jianfeng
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_tis 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-2.c | 10 +++------- 1 files changed, 3 insertions(+), 7 deletions(-)testcases/open_posix_testsuite/functional/threads/pi_test/pitest-2.c +2
-6@@ -196,7 +196,6 @@ void *thread_sample(void *arg) }void *thread_tb1 (void *arg) { -unsigned long timeoutsec;struct timespec boost_time;double t0, t1;int rc;@@ -207,8 +206,7 @@ void *thread_tb1(void *arg)DPRINTF (stdout,"#EVENT %f TB1 Thread 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 ();@@ -227,7 +225,6 @@ void *thread_tb1(void *arg)void *thread_tb2 (void *arg) { -unsigned long timeoutsec;struct timespec boost_time;double t0, t1;int rc;@@ -238,8 +235,7 @@ void *thread_tb2(void *arg)DPRINTF (stdout,"#EVENT %f TB2 Thread 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 ();
testcases/open_posix_testsuite/functional/threads/pi_test/pitest-2.c int main(int argc, char **argv) · line 325
Quoted 8 lines
testcases/open_posix_testsuite/functional/threads/pi_test/pitest-2.c +1
-1@@ -323,7 +319,7 @@ int main(int argc, char **argv)sleep (base_time + multiplier *30 -seconds_read ());/* Start TB1 thread (boosting thread) */ -int timeout = multiplier *20 ; +time_t timeout = multiplier *20 ; rc =pthread_create (&threadtb1, &threadattr, thread_tb1, &timeout);if (rc !=0 ) {
------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list