Skip to contentSkip to conversation

nptl01: Fix "make check" warnings and errors

PATCH In review “Samir 2 participants 4 messages Apr 7 – Apr 28

lore
Share & tools
lore

“Samir

author
#0 lore raw

PATCH 1/1 nptl01: Fix "make check" warnings and errors

- Add SPDX-License-Identifier tag (GPL-2.0-or-later)
- Remove FSF mailing address from license header
- Fix function definitions to use (void) for no parameters
- Remove extern declaration from .c file (optarg)
- Remove unnecessary initialization of global variable idle_count
- Fix pointer declarations spacing (foo *bar instead of foo * bar)
- Separate assignments from if conditions (10 occurrences)
- Make cleanup() function static to avoid extern warning
- Use __func__ in usage() function instead of hardcoded string
- Add (void) casts for unused function parameters to suppress warnings

This resolves 23 "make check" errors, 4 "make check" warnings, and 3 compiler warnings about unused parameters.

---
 testcases/kernel/sched/nptl/nptl01.c | 77 +++++++++++++++-------------
 1 file changed, 40 insertions(+), 37 deletions(-)
testcases/kernel/sched/nptl/nptl01.c +40 -37
index e80f70cb7..b04b6f7f9 100644
@@ -1,18 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines  Corp., 2004.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
  */
 /**********************************************************
  *
@@ -51,14 +39,14 @@
 
 char *TCID = "nptl01";		/* Test program identifier.    */
 int TST_TOTAL = 1;		/* Total number of test cases. */
-void cleanup();
+static void cleanup(void);
 
 pthread_mutex_t req;
 pthread_mutex_t ack;
 pthread_mutex_t waitx;
 pthread_cond_t parent;
 pthread_cond_t child;
-int idle_count = 0;
+int idle_count;
 
 /*
  * The time to wait should be set appropriately so that the waiting thread
@@ -69,74 +57,82 @@ int idle_count = 0;
  */
 #define NSECS_TO_WAIT	(1)
 
-void call_mutex_init(pthread_mutex_t * mutex, char *buf, size_t buf_len)
+void call_mutex_init(pthread_mutex_t *mutex, char *buf, size_t buf_len)
 {
 	int ret;
 
-	if ((ret = pthread_mutex_init(mutex, NULL)) != 0) {
+	ret = pthread_mutex_init(mutex, NULL);
+	if (ret != 0) {
 		tst_brkm(TBROK, cleanup, "pthread_mutex_init failed: %s",
 			 strerror_r(ret, buf, buf_len));
 	}
 }
 
-void call_mutex_lock(pthread_mutex_t * mutex, char *buf, size_t buf_len)
+void call_mutex_lock(pthread_mutex_t *mutex, char *buf, size_t buf_len)
 {
 	int ret;
 
-	if ((ret = pthread_mutex_lock(mutex)) != 0) {
+	ret = pthread_mutex_lock(mutex);
+	if (ret != 0) {
 		tst_brkm(TBROK, cleanup, "pthread_mutex_lock failed: %s",
 			 strerror_r(ret, buf, buf_len));
 	}
 }
 
-void call_mutex_unlock(pthread_mutex_t * mutex, char *buf, size_t buf_len)
+void call_mutex_unlock(pthread_mutex_t *mutex, char *buf, size_t buf_len)
 {
 	int ret;
 
-	if ((ret = pthread_mutex_unlock(mutex)) != 0) {
+	ret = pthread_mutex_unlock(mutex);
+	if (ret != 0) {
 		tst_brkm(TBROK, cleanup, "pthread_mutex_unlock failed: %s",
 			 strerror_r(ret, buf, buf_len));
 	}
 }
 
-void call_cond_init(pthread_cond_t * cond, char *buf, size_t buf_len)
+void call_cond_init(pthread_cond_t *cond, char *buf, size_t buf_len)
 {
 	int ret;
 
-	if ((ret = pthread_cond_init(cond, NULL)) != 0) {
+	ret = pthread_cond_init(cond, NULL);
+	if (ret != 0) {
 		tst_brkm(TBROK, cleanup, "pthread_cond_init failed: %s",
 			 strerror_r(ret, buf, buf_len));
 	}
 }
 
-void call_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex,
+void call_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex,
 		    char *buf, size_t buf_len)
 {
 	int ret;
 
-	if ((ret = pthread_cond_wait(cond, mutex)) != 0) {
+	ret = pthread_cond_wait(cond, mutex);
+	if (ret != 0) {
 		tst_brkm(TBROK, cleanup, "pthread_cond_wait failed: %s",
 			 strerror_r(ret, buf, buf_len));
 	}
 }
 
-void call_cond_signal(pthread_cond_t * cond, char *buf, size_t buf_len)
+void call_cond_signal(pthread_cond_t *cond, char *buf, size_t buf_len)
 {
 	int ret;
 
-	if ((ret = pthread_cond_signal(cond)) != 0) {
+	ret = pthread_cond_signal(cond);
+	if (ret != 0) {
 		tst_brkm(TBROK, cleanup, "pthread_cond_signal failed: %s",
 			 strerror_r(ret, buf, buf_len));
 	}
 }
 
-void do_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
+void do_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
 		  char *buf, size_t buf_len, int i)
 {
 	struct timeval tv;
 	struct timespec ts;
 	int ret;
 
+	(void)i;
+
 	if (gettimeofday(&tv, NULL) != 0) {
 		tst_brkm(TBROK, cleanup, "gettimeofday failed: %s",
 			 strerror_r(errno, buf, buf_len));
@@ -148,7 +144,8 @@ void do_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
 	ts.tv_nsec = ts.tv_nsec % 1000000000;
 
 	call_mutex_lock(mutex, buf, buf_len);
-	if ((ret = pthread_cond_timedwait(cond, mutex, &ts)) != ETIMEDOUT) {
+	ret = pthread_cond_timedwait(cond, mutex, &ts);
+	if (ret != ETIMEDOUT) {
 #if DEBUG
 		tst_resm(TINFO,
 			 "Loop %d of 1000000: pthread_cond_timedwait() didn't timeout",
@@ -166,6 +163,8 @@ void *run(void *arg)
 {
 	char buf[1024];
 
+	(void)arg;
+
 	while (1) {
 		call_mutex_lock(&ack, buf, sizeof(buf));
 		idle_count = 1;
@@ -188,22 +187,25 @@ void create_child_thread(char *buf, size_t buf_len)
 	pthread_t child_tid;
 	int ret;
 
-	if ((ret = pthread_attr_init(&attr)) != 0) {
+	ret = pthread_attr_init(&attr);
+	if (ret != 0) {
 		tst_brkm(TBROK, cleanup, "pthread_attr_init failed: %s",
 			 strerror_r(ret, buf, buf_len));
 	}
-	if ((ret = pthread_attr_setdetachstate(&attr,
-					       PTHREAD_CREATE_DETACHED)) != 0) {
+	ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+	if (ret != 0) {
 		tst_brkm(TBROK, cleanup,
 			 "pthread_attr_setdetachstate failed: %s",
 			 strerror_r(ret, buf, buf_len));
 	}
-	if ((ret = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM)) != 0) {
+	ret = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
+	if (ret != 0) {
 		tst_brkm(TBROK, cleanup, "pthread_attr_setscope failed: %s",
 			 strerror_r(ret, buf, buf_len));
 	}
 
-	if ((ret = pthread_create(&child_tid, &attr, run, NULL)) != 0) {
+	ret = pthread_create(&child_tid, &attr, run, NULL);
+	if (ret != 0) {
 		tst_brkm(TBROK, cleanup, "pthread_create failed: %s",
 			 strerror_r(ret, buf, buf_len));
 	}
@@ -211,13 +213,15 @@ void create_child_thread(char *buf, size_t buf_len)
 
 void trap_alarm(int sig)
 {
+	(void)sig;
+
 	tst_brkm(TFAIL, cleanup, "Test hang longer than %d sec detected",
 		 MAXTIME);
 }
 
 static void usage(const char *progname)
 {
-	fprintf(stderr, "usage: %s -l loops\n", progname);
+	fprintf(stderr, "%s: %s -l loops\n", __func__, progname);
 	fprintf(stderr, "\t-l specify the number of loops to carry out\n");
 }
 
@@ -226,7 +230,6 @@ int main(int argc, char **argv)
 #ifdef USING_NPTL
 	char buf[1024];
 	int i;
-	extern char *optarg;
 	int numloops = NUMLOOPS;
 
 	while ((i = getopt(argc, argv, "l:")) != -1) {
@@ -297,7 +300,7 @@ int main(int argc, char **argv)
  *cleanup() -  performs all ONE TIME cleanup for this test at
  *              completion or premature exit.
  */
-void cleanup()
+static void cleanup(void)
 {
 
 	tst_exit();
Signature · 5 lines
2.52.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!
Again, no point in fixing the test without rewriting it into a new test API.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#2 lore raw
Quoted 4 lines · Cyril Hrubis

Hi!
Again, no point in fixing the test without rewriting it into a new test API.

Hi,

Thanks for the feedback. I'd like to rewrite this using the new API. Can you guide me on how to proceed?

Best regards,
Samir

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi!

Quoted 8 lines
Quoted 3 lines

Again, no point in fixing the test without rewriting it into a new test API.

Hi,

Thanks for the feedback. I'd like to rewrite this using the new API. Can you guide me on how to proceed?

You need to read the original code, understand what it does, and then rewrite it using the new API. There is a lot of documentation at
https://linux-test-project.readthedocs.io/ in the FOR DEVELOPERS section.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp