Patchwork [PATCHv1,3/5] tests: fs-tests: check return value of functions

login
register
mail settings
Submitter Shevchenko Andriy (EXT-Teleca/Helsinki)
Date April 5, 2011, 1:55 p.m.
Message ID <aeae7a7b14f785f1bd3ee5fd74dea8e7521a160b.1302011698.git.ext-andriy.shevchenko@nokia.com>
Download mbox | patch
Permalink /patch/89865/
State New
Headers show

Comments

Shevchenko Andriy (EXT-Teleca/Helsinki) - April 5, 2011, 1:55 p.m.
chdir() returns negative value in case of error.
fscanf() returns amount of successfully parsed parameters.

Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
---
 tests/fs-tests/lib/tests.c           |    3 ++-
 tests/fs-tests/stress/atoms/pdfrun.c |    5 ++++-
 2 files changed, 6 insertions(+), 2 deletions(-)
Artem Bityutskiy - April 5, 2011, 2:17 p.m.
On Tue, 2011-04-05 at 16:55 +0300, Andy Shevchenko wrote:
> chdir() returns negative value in case of error.
> fscanf() returns amount of successfully parsed parameters.
> 
> Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
> ---
>  tests/fs-tests/lib/tests.c           |    3 ++-
>  tests/fs-tests/stress/atoms/pdfrun.c |    5 ++++-
>  2 files changed, 6 insertions(+), 2 deletions(-)

Pushed this one, thanks.

Patch

diff --git a/tests/fs-tests/lib/tests.c b/tests/fs-tests/lib/tests.c
index 00b94f9..8a6a5f5 100644
--- a/tests/fs-tests/lib/tests.c
+++ b/tests/fs-tests/lib/tests.c
@@ -1236,7 +1236,8 @@  void tests_try_to_clear_dir(const char *dir_name)
 			break;
 		}
 	}
-	chdir(buf);
+	if (chdir(buf) < 0)
+		perror("chdir");
 	closedir(dir);
 }
 
diff --git a/tests/fs-tests/stress/atoms/pdfrun.c b/tests/fs-tests/stress/atoms/pdfrun.c
index 3536580..46c70e1 100644
--- a/tests/fs-tests/stress/atoms/pdfrun.c
+++ b/tests/fs-tests/stress/atoms/pdfrun.c
@@ -40,8 +40,11 @@  void adjust_size(void)
 
 	total_memory = 0;
 	f = fopen("/proc/meminfo", "r");
-	fscanf(f, "%s %lu", dummy, &total_memory);
+	if (fscanf(f, "%s %lu", dummy, &total_memory) != 2)
+		perror("fscanf error");
 	fclose(f);
+
+
 	if (total_memory > 0 && tests_size_parameter > total_memory / 2)
 		tests_size_parameter = total_memory / 2;
 }