diff options
author | Manuel Bentele | 2020-09-11 11:48:48 +0200 |
---|---|---|
committer | Manuel Bentele | 2020-09-16 07:37:56 +0200 |
commit | a4215c3632c13218bb389d1f066549ab783028e3 (patch) | |
tree | 0468836ef5303f6eb94b876189ccaa60a7a2b453 /kernel/tests/include/lapi/common_timers.h | |
parent | Updated README with documentation of general information and build options (diff) | |
download | xloop-a4215c3632c13218bb389d1f066549ab783028e3.tar.gz xloop-a4215c3632c13218bb389d1f066549ab783028e3.tar.xz xloop-a4215c3632c13218bb389d1f066549ab783028e3.zip |
Added testcases from the Linux testing project (LTP)
Diffstat (limited to 'kernel/tests/include/lapi/common_timers.h')
-rw-r--r-- | kernel/tests/include/lapi/common_timers.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/kernel/tests/include/lapi/common_timers.h b/kernel/tests/include/lapi/common_timers.h new file mode 100644 index 0000000..b783bef --- /dev/null +++ b/kernel/tests/include/lapi/common_timers.h @@ -0,0 +1,81 @@ +/* + * File: common_timers.h + * + * Keep all the common defines/checks for the timer tests here + */ + +#ifndef __COMMON_TIMERS_H__ +#define __COMMON_TIMERS_H__ + +#include "config.h" +#include "lapi/syscalls.h" +#include "lapi/posix_clocks.h" + +#ifndef NSEC_PER_SEC +#define NSEC_PER_SEC (1000000000L) +#endif + +static const clock_t clock_list[] = { + CLOCK_REALTIME, + CLOCK_MONOTONIC, + CLOCK_PROCESS_CPUTIME_ID, + CLOCK_THREAD_CPUTIME_ID, + CLOCK_BOOTTIME, + CLOCK_BOOTTIME_ALARM, + CLOCK_REALTIME_ALARM, + CLOCK_TAI, +}; +/* CLOCKS_DEFINED is the number of clock sources defined for sure */ +#define CLOCKS_DEFINED (sizeof(clock_list) / sizeof(*clock_list)) +/* MAX_CLOCKS is the maximum number of clock sources supported by kernel */ +#define MAX_CLOCKS 16 + +#define CLOCK_TO_STR(def_name) \ + case def_name: \ + return #def_name; + +static inline const char *get_clock_str(const int clock_id) +{ + switch (clock_id) { + CLOCK_TO_STR(CLOCK_REALTIME); + CLOCK_TO_STR(CLOCK_MONOTONIC); + CLOCK_TO_STR(CLOCK_PROCESS_CPUTIME_ID); + CLOCK_TO_STR(CLOCK_THREAD_CPUTIME_ID); + CLOCK_TO_STR(CLOCK_BOOTTIME); + CLOCK_TO_STR(CLOCK_BOOTTIME_ALARM); + CLOCK_TO_STR(CLOCK_REALTIME_ALARM); + CLOCK_TO_STR(CLOCK_TAI); + default: + return "CLOCK_!?!?!?"; + } +} + +static inline int possibly_unsupported(clock_t clock) +{ + switch (clock) { + case CLOCK_BOOTTIME: + case CLOCK_BOOTTIME_ALARM: + case CLOCK_REALTIME_ALARM: + case CLOCK_TAI: + return 1; + default: + return 0; + } +} + +static inline int have_cputime_timers(void) +{ + return tst_kvercmp(2, 6, 12) >= 0; +} + +#include "lapi/syscalls.h" + +#include <time.h> +#include <unistd.h> + +/* timer_t in kernel(int) is different from Glibc definition(void*). + * Use the kernel definition for syscall tests + */ +typedef int kernel_timer_t; + +#endif |