lib: Move tst_clock_name() to tst_clock.c
PATCH 1/12 lib: Move tst_clock_name() to tst_clock.c
Move tst_clock_name() from tst_timer.c to tst_clock.c and add a few missing clocks.
Signed-off-by Cyril Hrubis <[email protected]>
--- include/tst_clocks.h | 5 +++++ include/tst_timer.h | 5 ----- lib/tst_clocks.c | 31 +++++++++++++++++++++++++++++++ lib/tst_timer.c | 24 ------------------------ 4 files changed, 36 insertions(+), 29 deletions(-)
include/tst_clocks.h +5 -0
@@ -28,4 +28,9 @@ int tst_clock_gettime(clockid_t clk_id, struct timespec *ts);int tst_clock_settime (clockid_t clk_id,struct timespec *ts); +/* +* Converts clock id to a readable name. +*/ +const char *tst_clock_name (clockid_t clk_id); +#endif /* TST_CLOCKS__ */
include/tst_timer.h +0 -5
@@ -332,9 +332,4 @@ static inline long long tst_timer_elapsed_us(void) return tst_timespec_to_us(tst_timer_elapsed()); } -/* -* Returns a string containing given clock type name -*/ -const char *tst_clock_name (clockid_t ); -#endif /* TST_TIMER */
lib/tst_clocks.c +31 -0
@@ -9,6 +9,7 @@#include "tst_test.h" #include "tst_clocks.h" #include "lapi/syscalls.h" +#include "lapi/posix_clocks.h" int tst_clock_getres (clockid_t clk_id,struct timespec *res) {
@@ -24,3 +25,33 @@ int tst_clock_settime(clockid_t clk_id, struct timespec *ts) {return tst_syscall (__NR_clock_settime, clk_id, ts); } + +const char *tst_clock_name (clockid_t clk_id) +{ +switch (clk_id) { +case CLOCK_REALTIME : +return "CLOCK_REALTIME" ; +case CLOCK_MONOTONIC : +return "CLOCK_MONOTONIC" ; +case CLOCK_PROCESS_CPUTIME_ID : +return "CLOCK_PROCESS_CPUTIME_ID" ; +case CLOCK_THREAD_CPUTIME_ID : +return "CLOCK_THREAD_CPUTIME_ID" ; +case CLOCK_MONOTONIC_RAW : +return "CLOCK_MONOTONIC_RAW" ; +case CLOCK_REALTIME_COARSE : +return "CLOCK_REALTIME_COARSE" ; +case CLOCK_MONOTONIC_COARSE : +return "CLOCK_MONOTONIC_COARSE" ; +case CLOCK_BOOTTIME : +return "CLOCK_BOOTTIME" ; +case CLOCK_REALTIME_ALARM : +return "CLOCK_REALTIME_ALARM" ; +case CLOCK_BOOTTIME_ALARM : +return "CLOCK_BOOTTIME_ALARM" ; +case CLOCK_TAI : +return "CLOCK_TAI" ; +default : +return "INVALID/UNKNOWN CLOCK" ; + } +}
lib/tst_timer.c +0 -24
@@ -15,30 +15,6 @@static struct timespec start_time, stop_time;static clockid_t clock_id; -const char *tst_clock_name (clockid_t clk_id) -{ -switch (clk_id) { -case CLOCK_REALTIME : -return "CLOCK_REALTIME" ; -case CLOCK_REALTIME_COARSE : -return "CLOCK_REALTIME_COARSE" ; -case CLOCK_MONOTONIC : -return "CLOCK_MONOTONIC" ; -case CLOCK_MONOTONIC_COARSE : -return "CLOCK_MONOTONIC_COARSE" ; -case CLOCK_MONOTONIC_RAW : -return "CLOCK_MONOTONIC_RAW" ; -case CLOCK_BOOTTIME : -return "CLOCK_BOOTTIME" ; -case CLOCK_PROCESS_CPUTIME_ID : -return "CLOCK_PROCESS_CPUTIME_ID" ; -case CLOCK_THREAD_CPUTIME_ID : -return "CLOCK_THREAD_CPUTIME_ID" ; -default : -return "UNKNOWN/INVALID" ; - } -} -void tst_timer_check (clockid_t clk_id) {if (tst_clock_gettime (clk_id, &start_time)) {
Signature · 1 line
2.24.1
PATCH 2/12 include/tst_safe_clocks.h: Make use of tst_clock_name()
Signed-off-by Cyril Hrubis <[email protected]>
--- include/tst_safe_clocks.h | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
include/tst_safe_clocks.h +17 -9
@@ -11,6 +11,7 @@#include <time.h> #include <sys/timex.h> #include "tst_test.h" +#include "tst_clocks.h" #include "lapi/syscalls.h" #include "lapi/posix_clocks.h"
@@ -20,10 +21,11 @@ static inline void safe_clock_getres(const char *file, const int lineno,int rval; rval =clock_getres (clk_id, res); -if (rval !=0 ) +if (rval !=0 ) {tst_brk (TBROK |TERRNO , -"%s:%d clock_getres() failed" , file, lineno); - +"%s:%d clock_getres(%s) failed" , + file, lineno,tst_clock_name (clk_id)); + } } static inline void safe_clock_gettime(const char *file, const int lineno,
@@ -32,9 +34,11 @@ static inline void safe_clock_gettime(const char *file, const int lineno,int rval; rval =clock_gettime (clk_id, tp); -if (rval !=0 ) +if (rval !=0 ) {tst_brk (TBROK |TERRNO , -"%s:%d clock_gettime() failed" , file, lineno); +"%s:%d clock_gettime(%s) failed" , + file, lineno,tst_clock_name (clk_id)); + } }
@@ -44,9 +48,11 @@ static inline void safe_clock_settime(const char *file, const int lineno,int rval; rval =clock_settime (clk_id, tp); -if (rval !=0 ) +if (rval !=0 ) {tst_brk (TBROK |TERRNO , -"%s:%d clock_gettime() failed" , file, lineno); +"%s:%d clock_gettime(%s) failed" , + file, lineno,tst_clock_name (clk_id)); + } } static inline int safe_clock_adjtime(const char *file, const int lineno,
@@ -55,9 +61,11 @@ static inline int safe_clock_adjtime(const char *file, const int lineno,int rval; rval =tst_syscall (__NR_clock_adjtime, clk_id, txc); -if (rval <0 ) +if (rval <0 ) {tst_brk (TBROK |TERRNO , -"%s:%d clock_adjtime() failed %i" , file, lineno, rval); +"%s:%d clock_adjtime(%s) failed %i" , + file, lineno,tst_clock_name (clk_id), rval); + }return rval; }
Signature · 1 line
2.24.1
PATCH 2/12 include/tst_safe_clocks.h: Make use of tst_clock_name()
PATCH 2/12 include/tst_safe_clocks.h: Make use of tst_clock_name()
Hi!
Both pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/12 lib: Move tst_clock_name() to tst_clock.c
In reply to Cyril HrubisHi Cyril,
Quoted 2 lines
Move
tst_clock_name()fromtst_timer.ctotst_clock.cand add a few missing clocks.
Reviewed-by Petr Vorel <[email protected]>
Kind regards,
Petr