DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH] test/cfgfile: add check for file removal
Date: Wed, 20 Nov 2024 08:50:34 -0800	[thread overview]
Message-ID: <20241120165034.69466-1-stephen@networkplumber.org> (raw)

The test makes temporary files for parsing and then cleans up.
It was not checking the return value from the remove step
which makes Coverity unhappy.

Coverity ID: 451207
Coverity ID: 451209
Coverity ID: 451212
Coverity ID: 451213
Coverity ID: 451215
Coverity ID: 451217
Coverity ID: 451222
Coverity ID: 451225

Fixes: be22019a58c4 ("test: restore cfgfile tests")

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test/test_cfgfile.c | 41 ++++++++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 11 deletions(-)

diff --git a/app/test/test_cfgfile.c b/app/test/test_cfgfile.c
index 8146435033..b189d9d7a5 100644
--- a/app/test/test_cfgfile.c
+++ b/app/test/test_cfgfile.c
@@ -108,7 +108,8 @@ test_cfgfile_sample1(void)
 	ret = rte_cfgfile_close(cfgfile);
 	TEST_ASSERT_SUCCESS(ret, "Failed to close cfgfile");
 
-	remove(filename);
+	ret = remove(filename);
+	TEST_ASSERT_SUCCESS(ret, "Failed to remove file");
 
 	return 0;
 }
@@ -137,7 +138,8 @@ test_cfgfile_sample2(void)
 	ret = rte_cfgfile_close(cfgfile);
 	TEST_ASSERT_SUCCESS(ret, "Failed to close cfgfile");
 
-	remove(filename);
+	ret = remove(filename);
+	TEST_ASSERT_SUCCESS(ret, "Failed to remove file");
 
 	return 0;
 }
@@ -173,7 +175,8 @@ test_cfgfile_realloc_sections(void)
 	TEST_ASSERT(strcmp("value8_section9", value) == 0,
 		    "key unexpected value: %s", value);
 
-	remove(filename);
+	ret = remove(filename);
+	TEST_ASSERT_SUCCESS(ret, "Failed to remove file");
 
 	char tmp[PATH_MAX] = "/tmp/";
 #ifdef RTE_EXEC_ENV_WINDOWS
@@ -184,7 +187,9 @@ test_cfgfile_realloc_sections(void)
 
 	ret = rte_cfgfile_save(cfgfile, filename);
 	TEST_ASSERT_SUCCESS(ret, "Failed to save to %s", filename);
-	remove(filename);
+
+	ret = remove(filename);
+	TEST_ASSERT_SUCCESS(ret, "Failed to remove file");
 
 	ret = rte_cfgfile_close(cfgfile);
 	TEST_ASSERT_SUCCESS(ret, "Failed to close cfgfile");
@@ -205,7 +210,9 @@ test_cfgfile_invalid_section_header(void)
 	cfgfile = rte_cfgfile_load(filename, 0);
 	TEST_ASSERT_NULL(cfgfile, "Expected failure did not occur");
 
-	remove(filename);
+	ret = remove(filename);
+	TEST_ASSERT_SUCCESS(ret, "Failed to remove file");
+
 	return 0;
 }
 
@@ -227,7 +234,9 @@ test_cfgfile_invalid_comment(void)
 	cfgfile = rte_cfgfile_load_with_params(filename, 0, &params);
 	TEST_ASSERT_NULL(cfgfile, "Expected failure did not occur");
 
-	remove(filename);
+	ret = remove(filename);
+	TEST_ASSERT_SUCCESS(ret, "Failed to remove file");
+
 	return 0;
 }
 
@@ -244,7 +253,9 @@ test_cfgfile_invalid_key_value_pair(void)
 	cfgfile = rte_cfgfile_load(filename, 0);
 	TEST_ASSERT_NULL(cfgfile, "Expected failure did not occur");
 
-	remove(filename);
+	ret = remove(filename);
+	TEST_ASSERT_SUCCESS(ret, "Failed to remove file");
+
 	return 0;
 }
 
@@ -277,7 +288,9 @@ test_cfgfile_empty_key_value_pair(void)
 	ret = rte_cfgfile_close(cfgfile);
 	TEST_ASSERT_SUCCESS(ret, "Failed to close cfgfile");
 
-	remove(filename);
+	ret = remove(filename);
+	TEST_ASSERT_SUCCESS(ret, "Failed to remove file");
+
 	return 0;
 }
 
@@ -294,7 +307,9 @@ test_cfgfile_missing_section(void)
 	cfgfile = rte_cfgfile_load(filename, 0);
 	TEST_ASSERT_NULL(cfgfile, "Expected failure did not occur");
 
-	remove(filename);
+	ret = remove(filename);
+	TEST_ASSERT_SUCCESS(ret, "Failed to remove file");
+
 	return 0;
 }
 
@@ -328,7 +343,9 @@ test_cfgfile_global_properties(void)
 	ret = rte_cfgfile_close(cfgfile);
 	TEST_ASSERT_SUCCESS(ret, "Failed to close cfgfile");
 
-	remove(filename);
+	ret = remove(filename);
+	TEST_ASSERT_SUCCESS(ret, "Failed to remove file");
+
 	return 0;
 }
 
@@ -351,7 +368,9 @@ test_cfgfile_empty_file(void)
 	ret = rte_cfgfile_close(cfgfile);
 	TEST_ASSERT_SUCCESS(ret, "Failed to close cfgfile");
 
-	remove(filename);
+	ret = remove(filename);
+	TEST_ASSERT_SUCCESS(ret, "Failed to remove file");
+
 	return 0;
 }
 
-- 
2.45.2


             reply	other threads:[~2024-11-20 16:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-20 16:50 Stephen Hemminger [this message]
2024-11-26 22:43 ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241120165034.69466-1-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).