[LTP] [PATCH 05/12] posix/conformance/interfaces: Fix all unused variable warnings

Joerg Vehlow lkml@jv-coder.de
Mon Nov 22 07:41:39 CET 2021


Hi Cyril,

On 11/19/2021 4:23 PM, Cyril Hrubis wrote:
> Hi!
>> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/aio_read/9-1.c b/testcases/open_posix_testsuite/conformance/interfaces/aio_read/9-1.c
>> index e1ae59e3b..cd1aa0318 100644
>> --- a/testcases/open_posix_testsuite/conformance/interfaces/aio_read/9-1.c
>> +++ b/testcases/open_posix_testsuite/conformance/interfaces/aio_read/9-1.c
>> @@ -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]);
>>   
>>   	}
> Looking at the test the whole loop here is pointless, can we remove it
> completely?
I thought the same, but I have never used aio, so I have no clue, if 
there are any side effects.
So I went for a minimal  change approach.
>> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c b/testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c
>> index aaf1403f9..9a0b148d9 100644
>> --- a/testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c
>> +++ b/testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c
>> @@ -51,7 +51,7 @@
>>   
>>   static void read_catalog(nl_catd cat, char *who)
>>   {
>> -	char *msg = NULL;
>> +	char *msg PTS_ATTRIBUTE_UNUSED = NULL;
>>   	int i, j;
> I guess that in this case the test is wrong as well. It does not seem
> that catgets() fails when it returns the pointer to the "not found"
> string and does not even touch errno.
Yes looks like you are right. Looks like this test can never fail.

I would fix it like this in a next revision:

diff --git 
a/testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c 
b/testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c
index 46350b7f0..5c03b04ed 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c
@@ -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 PTS_ATTRIBUTE_UNUSED = 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 (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");
+        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");
+            return PTS_FAIL;
+        }
+        return PTS_PASS;
      }

      ctl = waitpid(child, &status, 0);


Joerg


More information about the ltp mailing list