Skip to content

Commit cb05d6c

Browse files
mdouchametan-ucw
authored andcommitted
Unify error handling in include/tst_safe_clocks.h
- 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 <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]>
1 parent 853602d commit cb05d6c

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

include/tst_safe_clocks.h

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,62 @@
1515
#include "lapi/syscalls.h"
1616
#include "lapi/posix_clocks.h"
1717

18-
static inline void safe_clock_getres(const char *file, const int lineno,
18+
static inline int safe_clock_getres(const char *file, const int lineno,
1919
clockid_t clk_id, struct timespec *res)
2020
{
2121
int rval;
2222

2323
rval = clock_getres(clk_id, res);
24-
if (rval != 0) {
25-
tst_brk(TBROK | TERRNO,
26-
"%s:%d clock_getres(%s) failed",
27-
file, lineno, tst_clock_name(clk_id));
24+
25+
if (rval == -1) {
26+
tst_brk_(file, lineno, TBROK | TERRNO,
27+
"clock_getres(%s) failed", tst_clock_name(clk_id));
28+
} else if (rval) {
29+
tst_brk_(file, lineno, TBROK | TERRNO,
30+
"Invalid clock_getres(%s) return value %d",
31+
tst_clock_name(clk_id), rval);
2832
}
33+
34+
return rval;
2935
}
3036

31-
static inline void safe_clock_gettime(const char *file, const int lineno,
37+
static inline int safe_clock_gettime(const char *file, const int lineno,
3238
clockid_t clk_id, struct timespec *tp)
3339
{
3440
int rval;
3541

3642
rval = clock_gettime(clk_id, tp);
37-
if (rval != 0) {
38-
tst_brk(TBROK | TERRNO,
39-
"%s:%d clock_gettime(%s) failed",
40-
file, lineno, tst_clock_name(clk_id));
43+
44+
if (rval == -1) {
45+
tst_brk_(file, lineno, TBROK | TERRNO,
46+
"clock_gettime(%s) failed", tst_clock_name(clk_id));
47+
} else if (rval) {
48+
tst_brk_(file, lineno, TBROK | TERRNO,
49+
"Invalid clock_gettime(%s) return value %d",
50+
tst_clock_name(clk_id), rval);
4151
}
52+
53+
return rval;
4254
}
4355

4456

45-
static inline void safe_clock_settime(const char *file, const int lineno,
57+
static inline int safe_clock_settime(const char *file, const int lineno,
4658
clockid_t clk_id, struct timespec *tp)
4759
{
4860
int rval;
4961

5062
rval = clock_settime(clk_id, tp);
51-
if (rval != 0) {
52-
tst_brk(TBROK | TERRNO,
53-
"%s:%d clock_gettime(%s) failed",
54-
file, lineno, tst_clock_name(clk_id));
63+
64+
if (rval == -1) {
65+
tst_brk_(file, lineno, TBROK | TERRNO,
66+
"clock_gettime(%s) failed", tst_clock_name(clk_id));
67+
} else if (rval) {
68+
tst_brk_(file, lineno, TBROK | TERRNO,
69+
"Invalid clock_gettime(%s) return value %d",
70+
tst_clock_name(clk_id), rval);
5571
}
72+
73+
return rval;
5674
}
5775

5876
static inline int safe_timer_create(const char *file, const int lineno,

0 commit comments

Comments
 (0)