Convert kernel/sched/pthreads/*.c to use the standard message output
functions instead of printf().
Convert kernel/sched/pthreads/pth_str01.c and pth_str03.c to use stdout
consistently for debug output instead of an occasional use of stderr.
---
testcases/kernel/sched/pthreads/pth_str01.c | 61 +++++++++++-------------
testcases/kernel/sched/pthreads/pth_str02.c | 16 +++---
testcases/kernel/sched/pthreads/pth_str03.c | 71 +++++++++++++---------------
3 files changed, 72 insertions(+), 76 deletions(-)
--- ltp-full-20070531.orig/testcases/kernel/sched/pthreads/pth_str01.c
+++ ltp-full-20070531/testcases/kernel/sched/pthreads/pth_str01.c
@@ -37,6 +37,7 @@
#include <errno.h>
#include <stdint.h>
#include <sys/types.h>
+#include "test.h"
#include "pth_str01.h"
int depth = 3;
@@ -55,12 +56,15 @@ int num_nodes(int, int);
int synchronize_children(c_info *);
int doit(c_info *);
+char *TCID = "pth_str01";
+int TST_TOTAL = 1;
+
void testexit(int value)
{
if (value == 0)
- printf("pth_str01: Test Passed\n");
+ tst_resm(TPASS, "Test passed");
else
- printf("pth_str01: Test Failed\n");
+ tst_resm(TFAIL, "Test failed");
exit(value);
}
@@ -178,8 +182,7 @@ int synchronize_children( c_info *parent
pthread_mutex_lock( &node_mutex );
my_index = node_count++;
- printf( "thread %d started\n", my_index );
- fflush( stdout );
+ tst_resm( TINFO, "thread %d started", my_index );
/*
* Get a pointer into the array of thread structures which will
@@ -269,7 +272,7 @@ int synchronize_children( c_info *parent
timer.tv_nsec = (unsigned long)0;
if ((rc = pthread_cond_timedwait(&node_condvar, &node_mutex,
&timer))) {
- fprintf( stderr, "pthread_cond_timedwait (sync) %d: %s\n",
+ tst_resm( TINFO, "pthread_cond_timedwait (sync) %d: %s\n",
my_index, strerror(rc) );
testexit( 2 );
}
@@ -363,8 +366,7 @@ int doit( c_info *parent ) {
* we need to create another level of children.
*/
- printf( "thread %d creating kids, cdepth=%d\n", my_index, cdepth );
- fflush( stdout );
+ tst_resm( TINFO, "thread %d creating kids, cdepth=%d", my_index,
cdepth );
/*
* Create breadth children.
@@ -377,7 +379,7 @@ int doit( c_info *parent ) {
}
if ((rc = pthread_create(&(info_p->threads[child]), &attr,
(void *)doit, (void *)info_p))) {
- fprintf( stderr, "pthread_create (doit): %s\n",
+ tst_resm( TINFO, "pthread_create (doit): %s\n",
strerror(rc) );
testexit( 3 );
} else {
@@ -406,10 +408,10 @@ int doit( c_info *parent ) {
}
if ((rc = pthread_join((info_p->threads[child]), &status))) {
if ( debug ) {
- fprintf( stderr,
+ printf(
"join failed on thread %d, status addr=%p: %s\n",
my_index, status, strerror(rc) );
- fflush( stderr );
+ fflush( stdout );
}
testexit( 4 );
} else {
@@ -427,8 +429,7 @@ int doit( c_info *parent ) {
* This is the leaf node case. These children don't create
* any kids; they just talk amongst themselves.
*/
- printf( "thread %d is a leaf node, depth=%d\n", my_index, cdepth );
- fflush( stdout );
+ tst_resm( TINFO, "thread %d is a leaf node, depth=%d", my_index,
cdepth );
/*
* Talk to siblings (children of the same parent node).
@@ -455,7 +456,7 @@ int doit( c_info *parent ) {
}
if ((rc = pthread_cond_broadcast(
&parent->child_ptrs[child]->talk_condvar))) {
- fprintf( stderr, "pthread_cond_broadcast: %s\n",
+ tst_resm( TINFO, "pthread_cond_broadcast: %s\n",
strerror(rc) );
testexit( 5 );
}
@@ -486,7 +487,7 @@ int doit( c_info *parent ) {
timer.tv_nsec = (unsigned long)0;
if ((rc = pthread_cond_timedwait(&info_p->talk_condvar,
&info_p->talk_mutex, &timer))) {
- fprintf( stderr,
+ tst_resm( TINFO,
"pthread_cond_timedwait (leaf) %d: %s\n",
my_index, strerror(rc) );
testexit( 6 );
@@ -501,9 +502,8 @@ int doit( c_info *parent ) {
/*
* Our work is done. We're outta here.
*/
- printf( "thread %d exiting, depth=%d, status=%d, addr=%p\n", my_index,
+ tst_resm( TINFO, "thread %d exiting, depth=%d, status=%d, addr=%p",
my_index,
cdepth, info_p->status, info_p);
- fflush( stdout );
pthread_exit( 0 );
@@ -522,7 +522,7 @@ int main( int argc, char *argv[] ) {
* Initialize node mutex.
*/
if ((rc = pthread_mutex_init(&node_mutex, NULL))) {
- fprintf( stderr, "pthread_mutex_init(node_mutex): %s\n",
+ tst_resm( TINFO, "pthread_mutex_init(node_mutex): %s\n",
strerror(rc) );
testexit( 7 );
}
@@ -531,7 +531,7 @@ int main( int argc, char *argv[] ) {
* Initialize node condition variable.
*/
if ((rc = pthread_cond_init(&node_condvar, NULL))) {
- fprintf( stderr, "pthread_cond_init(node_condvar): %s\n",
+ tst_resm( TINFO, "pthread_cond_init(node_condvar): %s\n",
strerror(rc) );
testexit( 8 );
}
@@ -540,8 +540,7 @@ int main( int argc, char *argv[] ) {
* Allocate pthread info structure array.
*/
total = num_nodes( breadth, depth );
- printf( "Allocating %d nodes.\n", total );
- fflush( stdout );
+ tst_resm( TINFO, "Allocating %d nodes.", total );
if ( (child_info = (c_info *)malloc( total * sizeof(c_info) ))
== NULL ) {
perror( "malloc child_info" );
@@ -577,21 +576,21 @@ int main( int argc, char *argv[] ) {
if ((rc = pthread_mutex_init(&child_info[ind].child_mutex,
NULL))) {
- fprintf( stderr, "pthread_mutex_init child_mutex: %s\n",
+ tst_resm( TINFO, "pthread_mutex_init child_mutex: %s\n",
strerror(rc) );
testexit( 13 );
}
if ((rc = pthread_mutex_init(&child_info[ind].talk_mutex,
NULL))) {
- fprintf( stderr, "pthread_mutex_init talk_mutex: %s\n",
+ tst_resm( TINFO, "pthread_mutex_init talk_mutex: %s\n",
strerror(rc) );
testexit( 14 );
}
if ((rc = pthread_cond_init(&child_info[ind].child_condvar,
NULL))) {
- fprintf( stderr,
+ tst_resm( TINFO,
"pthread_cond_init child_condvar: %s\n",
strerror(rc) );
testexit( 15 );
@@ -599,7 +598,7 @@ int main( int argc, char *argv[] ) {
if ((rc = pthread_cond_init(&child_info[ind].talk_condvar,
NULL))) {
- fprintf( stderr, "pthread_cond_init talk_condvar: %s\n",
+ tst_resm( TINFO, "pthread_cond_init talk_condvar: %s\n",
strerror(rc) );
testexit( 16 );
}
@@ -611,11 +610,10 @@ int main( int argc, char *argv[] ) {
}
- printf( "Creating root thread attributes via pthread_attr_init.\n" );
- fflush( stdout );
+ tst_resm( TINFO, "Creating root thread attributes via
pthread_attr_init." );
if ((rc = pthread_attr_init(&attr))) {
- fprintf( stderr, "pthread_attr_init: %s\n", strerror(rc) );
+ tst_resm( TINFO, "pthread_attr_init: %s\n", strerror(rc) );
testexit( 17 );
}
@@ -626,16 +624,15 @@ int main( int argc, char *argv[] ) {
*/
if ((rc = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE))
) {
- fprintf( stderr, "pthread_attr_setdetachstate: %s\n",
+ tst_resm( TINFO, "pthread_attr_setdetachstate: %s\n",
strerror(rc) );
testexit( 18 );
}
- printf( "Creating root thread via pthread_create.\n" );
- fflush( stdout );
+ tst_resm( TINFO, "Creating root thread via pthread_create." );
if ((rc = pthread_create(&root_thread, &attr, (void *)doit, NULL))) {
- fprintf( stderr, "pthread_create: %s\n", strerror(rc) );
+ tst_resm( TINFO, "pthread_create: %s\n", strerror(rc) );
testexit( 19 );
}
@@ -648,7 +645,7 @@ int main( int argc, char *argv[] ) {
* Wait for the root child to exit.
*/
if (( rc = pthread_join(root_thread, NULL) )) {
- fprintf( stderr, "pthread_join: %s\n", strerror(rc) );
+ tst_resm( TINFO, "pthread_join: %s\n", strerror(rc) );
testexit( 20 );
}
--- ltp-full-20070531.orig/testcases/kernel/sched/pthreads/pth_str02.c
+++ ltp-full-20070531/testcases/kernel/sched/pthreads/pth_str02.c
@@ -32,6 +32,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include "test.h"
/* Defines
@@ -69,6 +70,8 @@ int num_threads = DEFAULT_NUM_THREADS;
int test_limit = 0;
int debug = 0;
+char *TCID = "pth_str02";
+int TST_TOTAL = 1;
/*---------------------------------------------------------------------+
| main () |
@@ -85,17 +88,16 @@ int main (int argc, char **argv)
parse_args (argc, argv);
if(test_limit) {
- printf ("\n Creating as many threads as possible\n\n");
+ tst_resm (TINFO, "Creating as many threads as possible");
} else {
- printf ("\n Creating %d threads\n\n", num_threads);
+ tst_resm (TINFO, "Creating %d threads", num_threads);
}
thread (0);
/*
* Program completed successfully...
*/
- printf ("pth_str02: Test Passed\n");
- fflush (stdout);
+ tst_resm(TPASS, "Test passed");
exit (0);
}
@@ -136,11 +138,11 @@ void *thread (void *parm)
pcrterr = pthread_create (&th, &attr, thread, (void *)(num +
1));
if (pcrterr != 0) {
if (test_limit) {
- printf ("Testing pthread limit, %d pthreads
created.\n", (int)num);
+ tst_resm (TINFO, "Testing pthread limit, %d pthreads
created.", (int)num);
pthread_exit(0);
}
if (pcrterr == EAGAIN) {
- fprintf (stderr, "Thread [%d]: unable to create
more threads!\n", (int)num);
+ tst_resm (TINFO, "Thread [%d]: unable to create
more threads!", (int)num);
return NULL;
}
else
@@ -221,6 +223,6 @@ static void sys_error (const char *msg,
static void error (const char *msg, int line)
{
fprintf (stderr, "ERROR [line: %d] %s\n", line, msg);
- printf("pth_str02: Test Failed\n");
+ tst_resm(TFAIL, "Test failed");
exit (-1);
}
--- ltp-full-20070531.orig/testcases/kernel/sched/pthreads/pth_str03.c
+++ ltp-full-20070531/testcases/kernel/sched/pthreads/pth_str03.c
@@ -37,6 +37,7 @@
#include <errno.h>
#include <stdint.h>
#include <sys/types.h>
+#include "test.h"
#define MAXTHREADS 1000
@@ -74,12 +75,15 @@ int num_nodes(int, int);
int synchronize_children(c_info *) ;
void *doit(void *);
+char *TCID = "pth_str03";
+int TST_TOTAL = 1;
+
void testexit(int value)
{
if (value == 0)
- printf("pth_str03: Test Passed\n");
+ tst_resm(TPASS, "Test passed");
else
- printf("pth_str03: Test Failed\n");
+ tst_resm(TFAIL, "Test failed");
exit(value);
}
@@ -198,8 +202,7 @@ int synchronize_children( c_info *parent
pthread_mutex_lock( &node_mutex );
my_index = node_count++;
- printf( "thread %d started\n", my_index );
- fflush( stdout );
+ tst_resm(TINFO, "thread %d started", my_index);
/* Get a pointer into the array of thread structures which will be
"me". */
info_p = &child_info[my_index];
@@ -277,7 +280,7 @@ int synchronize_children( c_info *parent
timer.tv_nsec = (unsigned long)0;
if ((rc = pthread_cond_timedwait(&node_condvar, &node_mutex,
&timer))) {
- fprintf( stderr, "pthread_cond_timedwait (sync) %d: %s\n",
+ tst_resm( TINFO, "pthread_cond_timedwait (sync) %d: %s",
my_index, strerror(rc) );
testexit( 2 );
}
@@ -362,13 +365,12 @@ void *doit( void *param )
/* Since the tree is not yet complete (it is not yet tall enough),
* we need to create another level of children. */
- printf( "thread %d creating kids, cdepth=%d\n", my_index, cdepth );
- fflush( stdout );
+ tst_resm(TINFO, "thread %d creating kids, cdepth=%d", my_index,
cdepth);
/* Create breadth children. */
for ( child = 0; child < breadth; child++ ) {
if ((rc = pthread_create(&(info_p->threads[child]), &attr,
doit, (void *) info_p))) {
- fprintf( stderr, "pthread_create (doit): %s\n",
+ tst_resm( TINFO, "pthread_create (doit): %s",
strerror(rc) );
testexit( 3 );
} else {
@@ -395,10 +397,10 @@ void *doit( void *param )
}
if ((rc = pthread_join((info_p->threads[child]), &status))) {
if ( debug ) {
- fprintf( stderr,
+ printf(
"join failed on thread %d, status addr=%p: %s\n",
my_index, status, strerror(rc) );
- fflush( stderr );
+ fflush( stdout );
}
testexit( 4 );
} else {
@@ -409,7 +411,7 @@ void *doit( void *param )
/* Add all childrens indexes to your index value */
info_p->sum += info_p->child_ptrs[child]->sum;
- printf("thread %d adding child thread %d to sum = %ld\n",
+ tst_resm(TINFO, "thread %d adding child thread %d to sum =
%ld",
my_index, info_p->child_ptrs[child]->index, (long
int)info_p->sum);
}
}
@@ -418,8 +420,7 @@ void *doit( void *param )
/* This is the leaf node case. These children don't create
* any kids; they just talk amongst themselves. */
- printf( "thread %d is a leaf node, depth=%d\n", my_index, cdepth );
- fflush( stdout );
+ tst_resm( TINFO, "thread %d is a leaf node, depth=%d", my_index,
cdepth );
/* Talk to siblings (children of the same parent node). */
if ( breadth > 1 ) {
@@ -441,7 +442,7 @@ void *doit( void *param )
}
if ((rc = pthread_cond_broadcast(
&parent->child_ptrs[child]->talk_condvar))) {
- fprintf( stderr, "pthread_cond_broadcast: %s\n",
+ tst_resm( TINFO, "pthread_cond_broadcast: %s",
strerror(rc) );
testexit( 5 );
}
@@ -469,8 +470,8 @@ void *doit( void *param )
timer.tv_nsec = (unsigned long)0;
if ((rc = pthread_cond_timedwait(&info_p->talk_condvar,
&info_p->talk_mutex, &timer))) {
- fprintf( stderr,
- "pthread_cond_timedwait (leaf) %d: %s\n",
+ tst_resm( TINFO,
+ "pthread_cond_timedwait (leaf) %d: %s",
my_index, strerror(rc) );
testexit( 6 );
}
@@ -482,9 +483,8 @@ void *doit( void *param )
}
/* Our work is done. We're outta here. */
- printf( "thread %d exiting, depth=%d, status=%d, addr=%p\n", my_index,
+ tst_resm(TINFO, "thread %d exiting, depth=%d, status=%d, addr=%p",
my_index,
cdepth, info_p->status, info_p);
- fflush( stdout );
pthread_exit( 0 );
}
@@ -503,26 +503,25 @@ int main( int argc, char *argv[] )
/* Initialize node mutex. */
if ((rc = pthread_mutex_init(&node_mutex, NULL))) {
- fprintf( stderr, "pthread_mutex_init(node_mutex): %s\n",
+ tst_resm( TINFO, "pthread_mutex_init(node_mutex): %s",
strerror(rc) );
testexit( 7 );
}
/* Initialize node condition variable. */
if ((rc = pthread_cond_init(&node_condvar, NULL))) {
- fprintf( stderr, "pthread_cond_init(node_condvar): %s\n",
+ tst_resm( TINFO, "pthread_cond_init(node_condvar): %s",
strerror(rc) );
testexit( 8 );
}
/* Allocate pthread info structure array. */
if ( (total = num_nodes( breadth, depth )) > MAXTHREADS ) {
- fprintf( stderr, "Can't create %d threads; max is %d.\n",
+ tst_resm( TINFO, "Can't create %d threads; max is %d.",
total, MAXTHREADS );
testexit( 9 );
}
- printf( "Allocating %d nodes.\n", total );
- fflush( stdout );
+ tst_resm( TINFO, "Allocating %d nodes.", total );
if ( (child_info = (c_info *)malloc( total * sizeof(c_info) )) == NULL
) {
perror( "malloc child_info" );
testexit( 10 );
@@ -553,26 +552,26 @@ int main( int argc, char *argv[] )
breadth * sizeof(c_info *) );
if ((rc = pthread_mutex_init(&child_info[ind].child_mutex,
NULL))) {
- fprintf( stderr, "pthread_mutex_init child_mutex: %s\n",
+ tst_resm( TINFO, "pthread_mutex_init child_mutex: %s",
strerror(rc) );
testexit( 13 );
}
if ((rc = pthread_mutex_init(&child_info[ind].talk_mutex,
NULL))) {
- fprintf( stderr, "pthread_mutex_init talk_mutex: %s\n",
+ tst_resm( TINFO, "pthread_mutex_init talk_mutex: %s",
strerror(rc) );
testexit( 14 );
}
if ((rc = pthread_cond_init(&child_info[ind].child_condvar,
NULL))) {
- fprintf( stderr,
- "pthread_cond_init child_condvar: %s\n",
+ tst_resm( TINFO,
+ "pthread_cond_init child_condvar: %s",
strerror(rc) );
testexit( 15 );
}
if ((rc = pthread_cond_init(&child_info[ind].talk_condvar,
NULL))) {
- fprintf( stderr, "pthread_cond_init talk_condvar: %s\n",
+ tst_resm( TINFO, "pthread_cond_init talk_condvar: %s",
strerror(rc) );
testexit( 16 );
}
@@ -584,11 +583,10 @@ int main( int argc, char *argv[] )
}
- printf( "Creating root thread attributes via pthread_attr_init.\n" );
- fflush( stdout );
+ tst_resm( TINFO, "Creating root thread attributes via
pthread_attr_init." );
if ((rc = pthread_attr_init(&attr))) {
- fprintf( stderr, "pthread_attr_init: %s\n", strerror(rc) );
+ tst_resm( TINFO, "pthread_attr_init: %s", strerror(rc) );
testexit( 17 );
}
@@ -596,16 +594,15 @@ int main( int argc, char *argv[] )
* PTHREAD_CREATE_JOINABLE attribute. If they don't, then the
* pthread_join call will sometimes fail and cause mass confusion. */
if ((rc = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE)))
{
- fprintf( stderr, "pthread_attr_setdetachstate: %s\n",
+ tst_resm( TINFO, "pthread_attr_setdetachstate: %s",
strerror(rc) );
testexit( 18 );
}
- printf( "Creating root thread via pthread_create.\n" );
- fflush( stdout );
+ tst_resm( TINFO, "Creating root thread via pthread_create." );
if ((rc = pthread_create(&root_thread, &attr, doit, NULL))) {
- fprintf( stderr, "pthread_create: %s\n", strerror(rc) );
+ tst_resm( TINFO, "pthread_create: %s", strerror(rc) );
testexit( 19 );
}
@@ -616,7 +613,7 @@ int main( int argc, char *argv[] )
/* Wait for the root child to exit. */
if ((rc = pthread_join(root_thread, NULL))) {
- fprintf( stderr, "pthread_join: %s\n", strerror(rc) );
+ tst_resm( TINFO, "pthread_join: %s", strerror(rc) );
testexit( 20 );
}
@@ -625,7 +622,7 @@ int main( int argc, char *argv[] )
fflush( stdout );
}
- printf("\n\nThe sum of tree (breadth %d, depth %d) is %ld\n",
+ tst_resm(TINFO, "The sum of tree (breadth %d, depth %d) is %ld",
breadth, depth, child_info[0].sum);
testexit( 0 );
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list