posix/conformance/interfaces/fork/7-1: Fix test
PATCH 1/4 posix/conformance/interfaces/fork/7-1: Fix test
From: Joerg Vehlow <[email protected]>
The test could never fail:
It only checked for errno after executing getcats, but getcats never sets errno, instead it returns its forth parameter.
--- .../conformance/interfaces/fork/7-1.c | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c +19 -23
@@ -49,33 +49,22 @@#define MESSCAT_IN "messcat.txt"#define MESSCAT_OUT "messcat.cat" -static void read_catalog (nl_catd cat,char *who) +static int read_catalog (nl_catd cat) { +static const char *notfound ="not found" ;char *msg =NULL ;int i, j; -#if VERBOSE >0 -output ("Reading the message catalog from %s...\n" , who); -#endif - - errno =0 ; - -for (i =1 ; i <=2 ; i++) { +for (i =1 ; i <=3 ; i++) {for (j =1 ; j <=2 ; j++) { - msg =catgets (cat, i, j,"not found" ); - -if (errno !=0 ) -UNRESOLVED (errno,"catgets returned an error" ); -#if VERBOSE >1 -output ("set %i msg %i: %s\n" , i, j, msg); -#endif + msg =catgets (cat, i, j, notfound); +if (msg == notfound) { +return 1 ; + } } } - -#if VERBOSE >0 -output ("Message catalog read successfully in %s\n" , who); -#endif +return 0 ; } static char *messcat_in =
@@ -132,7 +121,10 @@ int main(void)if (messcat == (nl_catd) -1 )UNRESOLVED (errno,"Could not open ./" MESSCAT_OUT ); -read_catalog (messcat,"parent" ); +if (read_catalog (messcat)) { +printf ("UNRESOLVED: Unable to read message catalog in parent\n" ); +return PTS_UNRESOLVED ; + } child =fork ();
@@ -140,8 +132,11 @@ int main(void)UNRESOLVED (errno,"Failed to fork" );if (child ==0 ) { -read_catalog (messcat,"child" ); -exit (PTS_PASS ); +if (read_catalog (messcat)) { +printf ("FAILED: Unable to read message catalog in child\n" ); +return PTS_FAIL ; + } +return PTS_PASS ; } ctl =waitpid (child, &status,0 );
@@ -157,7 +152,8 @@ int main(void)if (ret !=0 )UNRESOLVED (errno,"Failed to close the message catalog" ); -system ("rm -f " MESSCAT_IN " " MESSCAT_OUT ); +unlink (MESSCAT_IN ); +unlink (MESSCAT_OUT );#if VERBOSE >0 output ("Test passed\n" );
Signature · 5 lines
2.25.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/4 posix/conformance/interfaces: Fix all unused variable warnings
From: Joerg Vehlow <[email protected]>
Either by marking them as unused or by removing them, if there is no sideffect.
--- .../conformance/interfaces/aio_read/9-1.c | 3 +-- .../conformance/interfaces/aio_write/7-1.c | 3 +-- .../conformance/interfaces/pthread_cond_init/2-1.c | 2 +- .../conformance/interfaces/pthread_exit/2-2.c | 2 +- .../conformance/interfaces/pthread_exit/3-2.c | 2 +- .../conformance/interfaces/pthread_mutex_init/3-1.c | 4 ++-- .../conformance/interfaces/pthread_mutex_timedlock/4-1.c | 4 +--- .../conformance/interfaces/pthread_mutex_timedlock/5-1.c | 4 +--- .../conformance/interfaces/pthread_mutex_timedlock/5-2.c | 4 +--- .../conformance/interfaces/pthread_mutex_timedlock/5-3.c | 4 +--- .../conformance/interfaces/pthread_mutex_trylock/4-3.c | 1 - .../conformance/interfaces/pthread_mutex_unlock/2-1.c | 4 ++-- .../conformance/interfaces/pthread_mutexattr_setpshared/1-1.c | 2 -- .../conformance/interfaces/pthread_once/4-1-buildonly.c | 3 ++- 14 files changed, 15 insertions(+), 27 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/aio_read/9-1.c +1 -2
@@ -48,7 +48,6 @@ int main(void)int i;struct aiocb aiocbs[NUM_AIOCBS ];int last_req; -int err;int ret; if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L
@@ -85,7 +84,7 @@ int main(void) }for (i =0 ; i < last_req -1 ; i++) { - err =aio_error (&aiocbs[i]); +aio_error (&aiocbs[i]); ret =aio_return (&aiocbs[i]); }
testcases/open_posix_testsuite/conformance/interfaces/aio_write/7-1.c +1 -2
@@ -48,7 +48,6 @@ int main(void)int i;struct aiocb aiocbs[NUM_AIOCBS ];int last_req; -int err;int ret; if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L
@@ -79,7 +78,7 @@ int main(void) }for (i =0 ; i < last_req -1 ; i++) { - err =aio_error (&aiocbs[i]); +aio_error (&aiocbs[i]); ret =aio_return (&aiocbs[i]); }
testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_init/2-1.c +1 -1
@@ -14,7 +14,7 @@#include <stdio.h> #include "posixtest.h" -static pthread_cond_t cond =PTHREAD_COND_INITIALIZER ; +static pthread_cond_t cond PTS_ATTRIBUTE_UNUSED = PTHREAD_COND_INITIALIZER;int main (void ) {
testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/2-2.c +1 -1
@@ -92,7 +92,7 @@static int global =0 ;static int tab[3 ]; -#define CLEANUP (n) static void clnp##n(void * arg)\ +#define CLEANUP (n) static void clnp##n(void * arg PTS_ATTRIBUTE_UNUSED)\ {\ tab[global]=n; \ global++; \
testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/3-2.c +1 -1
@@ -94,7 +94,7 @@ static int global = 0;static int tab[4 ];static pthread_key_t tld[3 ]; -#define CLEANUP (n) static void clnp##n(void * arg)\ +#define CLEANUP (n) static void clnp##n(void * arg PTS_ATTRIBUTE_UNUSED)\ {\ tab[global]=n; \ global++; \
testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_init/3-1.c +2 -2
@@ -5,7 +5,7 @@* of this license, see the COPYING file at the top level of this * source tree. -* Test that the macro PTHREAD_MUTEX_INITIALIZER can be sued to intiailize +* Test that the macro PTHREAD_MUTEX_INITIALIZER can be used to initialize * mutexes that are statically allocated. * */
@@ -20,7 +20,7 @@ typedef struct my_data {int value;/* Access protected by mutex */ } my_data_t; -static my_data_t data = {PTHREAD_MUTEX_INITIALIZER ,0 }; +static my_data_t data PTS_ATTRIBUTE_UNUSED = { PTHREAD_MUTEX_INITIALIZER, 0 };int main (void ) {
testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/4-1.c +1 -3
@@ -32,9 +32,7 @@ static void *f1(void *parm);static int ret;/* Save return value of pthread_mutex_timedlock(). */ static pthread_mutex_t mutex =PTHREAD_MUTEX_INITIALIZER ;/* The mutex */ -static time_t currsec1, currsec2;/* Variables for saving time before -and afer locking the mutex using -pthread_mutex_timedlock(). */ +/**************************** * * MAIN()
testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/5-1.c +1 -3
@@ -40,9 +40,7 @@ static void *f1(void *parm);static int ret;/* Save return value of pthread_mutex_timedlock(). */ static pthread_mutex_t mutex =PTHREAD_MUTEX_INITIALIZER ;/* The mutex */ -static time_t currsec1, currsec2;/* Variables for saving time before -and afer locking the mutex using -pthread_mutex_timedlock(). */ +/**************************** * * MAIN()
testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/5-2.c +1 -3
@@ -40,9 +40,7 @@ static void *f1(void *parm);static int ret;/* Save return value of pthread_mutex_timedlock(). */ static pthread_mutex_t mutex =PTHREAD_MUTEX_INITIALIZER ;/* The mutex */ -static time_t currsec1, currsec2;/* Variables for saving time before -and afer locking the mutex using -pthread_mutex_timedlock(). */ +/**************************** * * MAIN()
testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/5-3.c +1 -3
@@ -36,9 +36,7 @@ static void *f1(void *parm);static int ret;/* Save return value of pthread_mutex_timedlock(). */ static pthread_mutex_t mutex =PTHREAD_MUTEX_INITIALIZER ;/* The mutex */ -static time_t currsec1, currsec2;/* Variables for saving time before -and afer locking the mutex using -pthread_mutex_timedlock(). */ +/**************************** * * MAIN()
testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_trylock/4-3.c +0 -1
@@ -103,7 +103,6 @@ static struct _scenar {#define NSCENAR (sizeof(scenarii)/sizeof(scenarii[0]))static char do_it =1 ; -static char woken =0 ;static unsigned long count_ope =0 ;#ifdef WITH_SYNCHRO static sem_t semsig1;
testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_unlock/2-1.c +2 -2
@@ -39,13 +39,13 @@ static int value; /* value protected by mutex */int main (void ) { -int i, rc; +int i;pthread_t threads[THREAD_NUM ];/* Create threads */ fprintf (stderr,"Creating %d threads\n" ,THREAD_NUM );for (i =0 ; i <THREAD_NUM ; ++i) - rc =pthread_create (&threads[i],NULL , func,NULL ); +pthread_create (&threads[i],NULL , func,NULL );/* Wait to join all threads */ for (i =0 ; i <THREAD_NUM ; ++i)
testcases/open_posix_testsuite/conformance/interfaces/pthread_mutexattr_setpshared/1-1.c +0 -2
@@ -37,8 +37,6 @@#include <stdio.h> #include "posixtest.h" -static pthread_mutex_t new_mutex;/* The mutex. */ -int main (void ) {pthread_mutexattr_t mta;
testcases/open_posix_testsuite/conformance/interfaces/pthread_once/4-1-buildonly.c +2 -1
@@ -11,5 +11,6 @@*/ #include <pthread.h> +#include "posixtest.h" -static pthread_once_t dummy =PTHREAD_ONCE_INIT ; +static pthread_once_t dummy PTS_ATTRIBUTE_UNUSED = PTHREAD_ONCE_INIT;
Signature · 5 lines
2.25.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 3/4 posix/conformance/interfaces: Fix unused result for write
In reply to Joerg VehlowFrom: Joerg Vehlow <[email protected]>
Moved WRITE (as PTS_WRITE_MSG) macro to posixtest.h and suppress unused result error message.
--- .../conformance/interfaces/mmap/11-2.c | 6 ++---- .../conformance/interfaces/mmap/11-3.c | 6 ++---- .../conformance/interfaces/pthread_create/1-3.c | 8 +++----- .../conformance/interfaces/sigaction/19-1.c | 4 +--- .../conformance/interfaces/sigaction/19-10.c | 4 +--- .../conformance/interfaces/sigaction/19-11.c | 4 +--- .../conformance/interfaces/sigaction/19-12.c | 4 +--- .../conformance/interfaces/sigaction/19-13.c | 4 +--- .../conformance/interfaces/sigaction/19-14.c | 4 +--- .../conformance/interfaces/sigaction/19-15.c | 4 +--- .../conformance/interfaces/sigaction/19-16.c | 4 +--- .../conformance/interfaces/sigaction/19-17.c | 4 +--- .../conformance/interfaces/sigaction/19-18.c | 4 +--- .../conformance/interfaces/sigaction/19-19.c | 4 +--- .../conformance/interfaces/sigaction/19-2.c | 5 ++--- .../conformance/interfaces/sigaction/19-20.c | 4 +--- .../conformance/interfaces/sigaction/19-21.c | 4 +--- .../conformance/interfaces/sigaction/19-22.c | 4 +--- .../conformance/interfaces/sigaction/19-23.c | 4 +--- .../conformance/interfaces/sigaction/19-24.c | 4 +--- .../conformance/interfaces/sigaction/19-25.c | 4 +--- .../conformance/interfaces/sigaction/19-26.c | 4 +--- .../conformance/interfaces/sigaction/19-3.c | 4 +--- .../conformance/interfaces/sigaction/19-4.c | 4 +--- .../conformance/interfaces/sigaction/19-5.c | 4 +--- .../conformance/interfaces/sigaction/19-6.c | 4 +--- .../conformance/interfaces/sigaction/19-7.c | 4 +--- .../conformance/interfaces/sigaction/19-8.c | 4 +--- .../conformance/interfaces/sigaction/19-9.c | 4 +--- testcases/open_posix_testsuite/include/posixtest.h | 6 ++++++ 30 files changed, 40 insertions(+), 91 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/mmap/11-2.c +2 -4
@@ -33,13 +33,11 @@#include "posixtest.h" #include "tempfile.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static void sigbus_handler (int signum) {if (signum ==SIGBUS ) { -WRITE ("SIGBUS triggered\n" ); -WRITE ("Test PASSED\n" ); +PTS_WRITE_MSG ("SIGBUS triggered\n" ); +PTS_WRITE_MSG ("Test PASSED\n" );_exit (PTS_PASS ); } }
testcases/open_posix_testsuite/conformance/interfaces/mmap/11-3.c +2 -4
@@ -31,13 +31,11 @@#include <unistd.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static void sigbus_handler (int signum) {if (signum ==SIGBUS ) { -WRITE ("SIGBUS triggered\n" ); -WRITE ("Test PASSED\n" ); +PTS_WRITE_MSG ("SIGBUS triggered\n" ); +PTS_WRITE_MSG ("Test PASSED\n" );_exit (PTS_PASS ); } }
testcases/open_posix_testsuite/conformance/interfaces/pthread_create/1-3.c +3 -5
@@ -10,8 +10,8 @@* * Steps: * 1. Create a new thread that will go into a never-ending while loop. -* 2. If the thread is truly asynchronise, then the main function will -* continue instead of waiting for the thread to return (which in never +* 2. If the thread is truly asynchronous, then the main function will +* continue instead of waiting for the thread to return (which it never * does in this test case). * 3. An alarm is set to go off (i.e. send the SIGARLM signal) after 3 * seconds. This is done for 'timeing-out' reasons, in case main DOES
@@ -72,11 +72,9 @@ static void *a_thread_function()return NULL ; } -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -/* If this handler is called, that means that the test has failed. */ static void alarm_handler () { -WRITE ("Test FAILED: Alarm fired while waiting for cancelation\n" ); +PTS_WRITE_MSG ("Test FAILED: Alarm fired while waiting for cancelation\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-1.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGABRT ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-10.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGPIPE ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-11.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGQUIT ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-12.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGSEGV ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-13.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGTERM ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-14.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGTSTP ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-15.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGTTIN ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-16.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGTTOU ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-17.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGUSR1 ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-18.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGUSR2 ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-19.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGPOLL ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-2.c +2 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,13 +48,14 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGALRM ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); } called =1 ; } +int main (void ) {int ret;
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-20.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGPROF ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-21.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGSYS ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-22.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGTRAP ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-23.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGURG ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-24.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGVTALRM ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-25.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGXCPU ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-26.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGXFSZ ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-3.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGBUS ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-4.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGCHLD ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-5.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGCONT ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-6.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGFPE ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-7.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGHUP ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-8.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGILL ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-9.c +1 -3
@@ -40,8 +40,6 @@#include <errno.h> #include "posixtest.h" -#define WRITE (str) write(STDOUT_FILENO, str, sizeof(str) - 1) -static volatile sig_atomic_t called =0 ;static void handler (int sig,siginfo_t *info,void *context)
@@ -50,7 +48,7 @@ static void handler(int sig, siginfo_t *info, void *context) (void ) context;if (info->si_signo !=SIGINT ) { -WRITE ("Wrong signal generated?\n" ); +PTS_WRITE_MSG ("Wrong signal generated?\n" );_exit (PTS_FAIL ); }
testcases/open_posix_testsuite/include/posixtest.h +6 -0
@@ -23,3 +23,9 @@#define PTS_ATTRIBUTE_NORETURN __attribute__((noreturn))#define PTS_ATTRIBUTE_UNUSED __attribute__((unused))#define PTS_ATTRIBUTE_UNUSED_RESULT __attribute__((warn_unused_result)) + +#define PTS_WRITE_MSG(msg) do { \ + if (write(STDOUT_FILENO, msg, sizeof(msg) - 1)) { \ + /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425 */ \ + } \ +}while (0 )
Signature · 5 lines
2.25.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 4/4 posix/interface/conformance: Fix all unused-result warnings
In reply to Joerg VehlowFrom: Joerg Vehlow <[email protected]>
On error the failed function is printed and PTS_UNRESOLVED returned.
--- .../conformance/interfaces/clock_getcpuclockid/5-1.c | 10 ++++++++-- .../conformance/interfaces/kill/2-2.c | 5 ++++- .../conformance/interfaces/kill/3-1.c | 5 ++++- .../conformance/interfaces/mmap/18-1.c | 8 ++++++-- .../conformance/interfaces/mq_open/16-1.c | 8 ++++++-- .../conformance/interfaces/sched_setparam/2-1.c | 5 ++++- .../conformance/interfaces/sched_setparam/2-2.c | 5 ++++- .../conformance/interfaces/sched_yield/1-1.c | 9 ++++++--- .../conformance/interfaces/shm_open/26-2.c | 9 ++++++--- .../conformance/interfaces/shm_unlink/8-1.c | 3 ++- .../conformance/interfaces/shm_unlink/9-1.c | 6 ++++-- .../conformance/interfaces/sigaltstack/9-1.c | 5 ++++- testcases/open_posix_testsuite/include/affinity.h | 3 ++- 13 files changed, 60 insertions(+), 21 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/clock_getcpuclockid/5-1.c +8 -2
@@ -35,8 +35,14 @@ int main(void) pwd =getpwnam ("nobody" );if (pwd !=NULL ) { -setgid (pwd->pw_gid); -setuid (pwd->pw_uid); +if (setgid (pwd->pw_gid)) { +perror ("setgid" ); +return PTS_UNRESOLVED ; + } +if (setuid (pwd->pw_uid)) { +perror ("setuid" ); +return PTS_UNRESOLVED ; + } } }
testcases/open_posix_testsuite/conformance/interfaces/kill/2-2.c +4 -1
@@ -55,7 +55,10 @@ int main(void)*/ /* this is added incase user is root. If user is normal user, then it * has no effect on the tests */ -setuid (1 ); +if (setuid (1 )) { +perror ("setuid" ); +return PTS_UNRESOLVED ; + }if (-1 ==kill (1 ,0 )) {if (EPERM == errno) {
testcases/open_posix_testsuite/conformance/interfaces/kill/3-1.c +4 -1
@@ -23,7 +23,10 @@ int main(void) {/* this is added incase user is root. If user is normal user, then it * has no effect on the tests */ -setuid (1 ); +if (setuid (1 )) { +perror ("setuid" ); +return PTS_UNRESOLVED ; + }if (kill (1 ,0 ) !=-1 ) { printf
testcases/open_posix_testsuite/conformance/interfaces/mmap/18-1.c +6 -2
@@ -124,14 +124,18 @@ int main(void)* EAGAIN: * Lock all the memory by mlockall(). * Set resource limit setrlimit() -* Change the user to non-root then only setrmilit is applicable. +* Change the user to non-root then only setrlimit is applicable. */ pa =mmap (NULL , len,PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 );if (pa ==MAP_FAILED && errno ==EAGAIN ) {printf ("Got EAGAIN: %s\n" ,strerror (errno));printf ("Test PASSED\n" );/* Change user to root */ -seteuid (0 ); +if (seteuid (0 )) { +close (fd); +perror ("seteuid" ); +return PTS_UNRESOLVED ; + }close (fd);munmap (pa, len);return PTS_PASS ;
testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c +6 -2
@@ -61,10 +61,14 @@ int main(void)printf (TNAME " Error at open(): %s\n" ,strerror (errno));return PTS_UNRESOLVED ; } -/* file is empty now, will cause "Bus error" */ -write (fd, fname,sizeof (int ));unlink (fname); +if (ftruncate (fd,sizeof (int ))) { +perror ("ftruncate" ); +close (fd); +return PTS_UNRESOLVED ; + } + pa =mmap (NULL ,sizeof (int ),PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 );if (pa ==MAP_FAILED ) {printf (TNAME " Error at mmap: %s\n" ,strerror (errno));
testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/2-1.c +4 -1
@@ -125,7 +125,10 @@ int main(void)return PTS_UNRESOLVED ; } -pipe (the_pipe); +if (pipe (the_pipe)) { +perror ("pipe" ); +return PTS_UNRESOLVED ; + }for (i =0 ; i < nb_child; i++) { child_pid[i] =fork ();
testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/2-2.c +4 -1
@@ -129,7 +129,10 @@ int main(void)return PTS_UNRESOLVED ; } -pipe (the_pipe); +if (pipe (the_pipe)) { +perror ("pipe" ); +return PTS_UNRESOLVED ; + }for (i =0 ; i < nb_child; i++) { child_pid[i] =fork ();
testcases/open_posix_testsuite/conformance/interfaces/sched_yield/1-1.c +6 -3
@@ -45,18 +45,21 @@ static int child_busy(int fd)alarm (4 );/* Tell the parent we're ready */ -write (fd,"go" ,2 ); +if (write (fd,"go" ,2 ) ==-1 ) { +perror ("write" ); +exit (PTS_UNRESOLVED ); + }for (;;) { rc =sched_yield ();if (rc) {ERR_LOG ("child: sched_yield" , rc); -exit (1 ); +exit (PTS_FAIL ); } }/* should not get here */ -exit (2 ); +exit (PTS_UNRESOLVED ); }int main (void )
testcases/open_posix_testsuite/conformance/interfaces/shm_open/26-2.c +6 -3
@@ -95,19 +95,22 @@ int main(void) fd =shm_open (SHM_NAME ,O_RDWR |O_TRUNC ,0 );if (fd ==-1 ) {perror ("An error occurs when calling shm_open()" ); -seteuid (getuid ()); +if (seteuid (getuid ())) +perror ("seteuid" );shm_unlink (SHM_NAME );return PTS_UNRESOLVED ; }if (fstat (fd, &stat_buf) !=0 ) {perror ("An error occurs when calling fstat()" ); -seteuid (getuid ()); +if (seteuid (getuid ())) +perror ("seteuid" );shm_unlink (SHM_NAME );return PTS_UNRESOLVED ; } -seteuid (getuid ()); +if (seteuid (getuid ())) +perror ("seteuid" );shm_unlink (SHM_NAME );if (stat_buf.st_uid == old_uid && stat_buf.st_gid == old_gid) {
testcases/open_posix_testsuite/conformance/interfaces/shm_unlink/8-1.c +2 -1
@@ -86,7 +86,8 @@ int main(void)return PTS_UNRESOLVED ; } -seteuid (getuid ()); +if (seteuid (getuid ())) +perror ("seteuid" );if (fstat (fd, &stat_after) !=0 ) {perror ("An error occurs when calling fstat()" );
testcases/open_posix_testsuite/conformance/interfaces/shm_unlink/9-1.c +4 -2
@@ -69,12 +69,14 @@ int main(void) result =shm_unlink (SHM_NAME );if (result ==-1 && errno ==EACCES ) {printf ("Test PASSED\n" ); -seteuid (getuid ()); +if (seteuid (getuid ())) +perror ("seteuid" );shm_unlink (SHM_NAME );return PTS_PASS ; }else if (result ==-1 ) {perror ("Unexpected error" ); -seteuid (getuid ()); +if (seteuid (getuid ())) +perror ("seteuid" );shm_unlink (SHM_NAME );return PTS_FAIL ; }
testcases/open_posix_testsuite/conformance/interfaces/sigaltstack/9-1.c +4 -1
@@ -59,7 +59,10 @@ int main(int argc, char *argv[])/* Get abs path if needed and exec ourself */ if (*argv[0 ] !='/' ) { -getcwd (path,PATH_MAX ); +if (getcwd (path,PATH_MAX ) ==NULL ) { +perror ("getcwd" ); +exit (PTS_UNRESOLVED ); + }strcat (path,"/" );strcat (path, argv[0 ]); }else {
testcases/open_posix_testsuite/include/affinity.h +2 -1
@@ -46,7 +46,8 @@ static int get_online_cpu_from_sysfs(void) f =fopen ("/sys/devices/system/cpu/online" ,"r" );if (!f)return -1 ; -fscanf (f,"%d" , &cpu); +if (!fscanf (f,"%d" , &cpu)) + cpu =-1 ;fclose (f);return cpu;
Signature · 5 lines
2.25.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c line 54
Quoted 4 lines
testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c +2
-1-static void read_catalog (nl_catd cat,char *who) +static int read_catalog (nl_catd cat) { +static const char *notfound ="not found" ;
Why static here?
testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c line 58
Quoted 11 lines
testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c +1
-7char *msg =NULL ;int i, j; -#if VERBOSE >0 -output ("Reading the message catalog from %s...\n" , who); -#endif - - errno =0 ; - -for (i =1 ; i <=2 ; i++) { +for (i =1 ; i <=3 ; i++) {
Actually this change makes the test fail for me since there is no set 3.
Have you modified this to check if the test fails and then forget to change it back?
Other than these two the changes looks good to me. If you agreen I can fix the two small issues before pushing it to the repo.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Cytil,
Quoted 6 lines · Cyril Hrubis
Hi!
testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c line 54
Quoted 4 lines
testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c +2
-1-static void read_catalog (nl_catd cat,char *who) +static int read_catalog (nl_catd cat) { +static const char *notfound ="not found" ;Why static here?
Right, could be dropped. It doesn't really make a difference, but doesn't hurt either. Remove it if you like.
Quoted 14 lines
testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c line 58
Quoted 12 lines
char *msg = NULL; int i, j;testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c +1
-7-#if VERBOSE >0 -output ("Reading the message catalog from %s...\n" , who); -#endif - - errno =0 ; - -for (i =1 ; i <=2 ; i++) { +for (i =1 ; i <=3 ; i++) {Actually this change makes the test fail for me since there is no set 3.
Quoted 2 lines
Have you modified this to check if the test fails and then forget to change it back?
Yes sorry, that is exactly what happened...
Quoted 4 lines
Other than these two the changes looks good to me. If you agreen I can fix the two small issues before pushing it to the repo.
Perfect, thanks
Joerg
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 3 lines
Quoted 2 lines
Other than these two the changes looks good to me. If you agreen I can fix the two small issues before pushing it to the repo.
Perfect, thanks
Did that and also fixed trailing whitespace introduced in the posixtest.h and pushed the patches, thanks.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp