diff mbox series

[12/19] Unify error handling in include/tst_safe_clocks.h

Message ID 20201026164756.30556-13-mdoucha@suse.cz
State Accepted
Headers show
Series Unify error handling in LTP library | expand

Commit Message

Martin Doucha Oct. 26, 2020, 4:47 p.m. UTC
- Properly format caller file:line location
- Pedantically check invalid syscall return values
- Always return success/failure value so that all SAFE_*() functions can be
  called in test cleanup

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
 include/tst_safe_clocks.h | 48 +++++++++++++++++++++++++++------------
 1 file changed, 33 insertions(+), 15 deletions(-)

Comments

Cyril Hrubis Nov. 10, 2020, 1:13 p.m. UTC | #1
Hi!
Pushed, thanks.
diff mbox series

Patch

diff --git a/include/tst_safe_clocks.h b/include/tst_safe_clocks.h
index 5909f4083..5661ce57b 100644
--- a/include/tst_safe_clocks.h
+++ b/include/tst_safe_clocks.h
@@ -15,44 +15,62 @@ 
 #include "lapi/syscalls.h"
 #include "lapi/posix_clocks.h"
 
-static inline void safe_clock_getres(const char *file, const int lineno,
+static inline int safe_clock_getres(const char *file, const int lineno,
 	clockid_t clk_id, struct timespec *res)
 {
 	int rval;
 
 	rval = clock_getres(clk_id, res);
-	if (rval != 0) {
-		tst_brk(TBROK | TERRNO,
-			"%s:%d clock_getres(%s) failed",
-			file, lineno, tst_clock_name(clk_id));
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"clock_getres(%s) failed", tst_clock_name(clk_id));
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid clock_getres(%s) return value %d",
+			tst_clock_name(clk_id), rval);
 	}
+
+	return rval;
 }
 
-static inline void safe_clock_gettime(const char *file, const int lineno,
+static inline int safe_clock_gettime(const char *file, const int lineno,
 	clockid_t clk_id, struct timespec *tp)
 {
 	int rval;
 
 	rval = clock_gettime(clk_id, tp);
-	if (rval != 0) {
-		tst_brk(TBROK | TERRNO,
-			"%s:%d clock_gettime(%s) failed",
-			file, lineno, tst_clock_name(clk_id));
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"clock_gettime(%s) failed", tst_clock_name(clk_id));
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid clock_gettime(%s) return value %d",
+			tst_clock_name(clk_id), rval);
 	}
+
+	return rval;
 }
 
 
-static inline void safe_clock_settime(const char *file, const int lineno,
+static inline int safe_clock_settime(const char *file, const int lineno,
 	clockid_t clk_id, struct timespec *tp)
 {
 	int rval;
 
 	rval = clock_settime(clk_id, tp);
-	if (rval != 0) {
-		tst_brk(TBROK | TERRNO,
-			"%s:%d clock_gettime(%s) failed",
-			file, lineno, tst_clock_name(clk_id));
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"clock_gettime(%s) failed", tst_clock_name(clk_id));
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid clock_gettime(%s) return value %d",
+			tst_clock_name(clk_id), rval);
 	}
+
+	return rval;
 }
 
 static inline int safe_timer_create(const char *file, const int lineno,