selftests: timers: Remove local NSEC_PER_SEC and USEC_PER_SEC defines

Remove local NSEC_PER_SEC and USEC_PER_SEC defines. Pick them up from
include/vdso/time64.h. This requires -I $(top_srcdir) to the timers
Makefile to include the include/vdso/time64.h.

posix_timers test names the defines NSECS_PER_SEC and USECS_PER_SEC.
Change posix_timers test references to the defines to match the
defines in the header file.

Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Acked-by: John Stultz <jstultz@google.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
This commit is contained in:
Shuah Khan 2024-09-23 18:30:36 -06:00
parent 9852d85ec9
commit 2ab8930ec1
13 changed files with 19 additions and 28 deletions

View file

@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
CFLAGS += -O3 -Wl,-no-as-needed -Wall CFLAGS += -O3 -Wl,-no-as-needed -Wall -I $(top_srcdir)
LDLIBS += -lrt -lpthread -lm LDLIBS += -lrt -lpthread -lm
# these are all "safe" tests that don't modify # these are all "safe" tests that don't modify

View file

@ -22,14 +22,12 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/timex.h> #include <sys/timex.h>
#include <time.h> #include <time.h>
#include <include/vdso/time64.h>
#include "../kselftest.h" #include "../kselftest.h"
#define CLOCK_MONOTONIC_RAW 4 #define CLOCK_MONOTONIC_RAW 4
#define NSEC_PER_SEC 1000000000LL
#define USEC_PER_SEC 1000000
#define MILLION 1000000 #define MILLION 1000000
long systick; long systick;

View file

@ -28,6 +28,7 @@
#include <signal.h> #include <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h> #include <pthread.h>
#include <include/vdso/time64.h>
#include "../kselftest.h" #include "../kselftest.h"
#define CLOCK_REALTIME 0 #define CLOCK_REALTIME 0
@ -45,7 +46,6 @@
#define NR_CLOCKIDS 12 #define NR_CLOCKIDS 12
#define NSEC_PER_SEC 1000000000ULL
#define UNREASONABLE_LAT (NSEC_PER_SEC * 5) /* hopefully we resume in 5 secs */ #define UNREASONABLE_LAT (NSEC_PER_SEC * 5) /* hopefully we resume in 5 secs */
#define SUSPEND_SECS 15 #define SUSPEND_SECS 15

View file

@ -28,10 +28,10 @@
#include <sys/timex.h> #include <sys/timex.h>
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <include/vdso/time64.h>
#include "../kselftest.h" #include "../kselftest.h"
#define CALLS_PER_LOOP 64 #define CALLS_PER_LOOP 64
#define NSEC_PER_SEC 1000000000ULL
#define CLOCK_REALTIME 0 #define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 1 #define CLOCK_MONOTONIC 1

View file

@ -48,9 +48,9 @@
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
#include <include/vdso/time64.h>
#include "../kselftest.h" #include "../kselftest.h"
#define NSEC_PER_SEC 1000000000ULL
#define CLOCK_TAI 11 #define CLOCK_TAI 11
time_t next_leap; time_t next_leap;

View file

@ -29,9 +29,9 @@
#include <signal.h> #include <signal.h>
#include <errno.h> #include <errno.h>
#include <mqueue.h> #include <mqueue.h>
#include <include/vdso/time64.h>
#include "../kselftest.h" #include "../kselftest.h"
#define NSEC_PER_SEC 1000000000ULL
#define TARGET_TIMEOUT 100000000 /* 100ms in nanoseconds */ #define TARGET_TIMEOUT 100000000 /* 100ms in nanoseconds */
#define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */ #define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */

View file

@ -27,10 +27,9 @@
#include <sys/timex.h> #include <sys/timex.h>
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <include/vdso/time64.h>
#include "../kselftest.h" #include "../kselftest.h"
#define NSEC_PER_SEC 1000000000ULL
#define CLOCK_REALTIME 0 #define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 1 #define CLOCK_MONOTONIC 1
#define CLOCK_PROCESS_CPUTIME_ID 2 #define CLOCK_PROCESS_CPUTIME_ID 2

View file

@ -24,10 +24,9 @@
#include <sys/timex.h> #include <sys/timex.h>
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <include/vdso/time64.h>
#include "../kselftest.h" #include "../kselftest.h"
#define NSEC_PER_SEC 1000000000ULL
#define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */ #define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */

View file

@ -15,13 +15,12 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <include/vdso/time64.h>
#include <pthread.h> #include <pthread.h>
#include "../kselftest.h" #include "../kselftest.h"
#define DELAY 2 #define DELAY 2
#define USECS_PER_SEC 1000000
#define NSECS_PER_SEC 1000000000
static void __fatal_error(const char *test, const char *name, const char *what) static void __fatal_error(const char *test, const char *name, const char *what)
{ {
@ -82,9 +81,9 @@ static int check_diff(struct timeval start, struct timeval end)
long long diff; long long diff;
diff = end.tv_usec - start.tv_usec; diff = end.tv_usec - start.tv_usec;
diff += (end.tv_sec - start.tv_sec) * USECS_PER_SEC; diff += (end.tv_sec - start.tv_sec) * USEC_PER_SEC;
if (llabs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) { if (llabs(diff - DELAY * USEC_PER_SEC) > USEC_PER_SEC / 2) {
printf("Diff too high: %lld..", diff); printf("Diff too high: %lld..", diff);
return -1; return -1;
} }
@ -444,7 +443,7 @@ static inline int64_t calcdiff_ns(struct timespec t1, struct timespec t2)
{ {
int64_t diff; int64_t diff;
diff = NSECS_PER_SEC * (int64_t)((int) t1.tv_sec - (int) t2.tv_sec); diff = NSEC_PER_SEC * (int64_t)((int) t1.tv_sec - (int) t2.tv_sec);
diff += ((int) t1.tv_nsec - (int) t2.tv_nsec); diff += ((int) t1.tv_nsec - (int) t2.tv_nsec);
return diff; return diff;
} }
@ -475,7 +474,7 @@ static void check_sigev_none(int which, const char *name)
do { do {
if (clock_gettime(which, &now)) if (clock_gettime(which, &now))
fatal_error(name, "clock_gettime()"); fatal_error(name, "clock_gettime()");
} while (calcdiff_ns(now, start) < NSECS_PER_SEC); } while (calcdiff_ns(now, start) < NSEC_PER_SEC);
if (timer_gettime(timerid, &its)) if (timer_gettime(timerid, &its))
fatal_error(name, "timer_gettime()"); fatal_error(name, "timer_gettime()");
@ -532,7 +531,7 @@ static void check_gettime(int which, const char *name)
wraps++; wraps++;
prev = its; prev = its;
} while (calcdiff_ns(now, start) < NSECS_PER_SEC); } while (calcdiff_ns(now, start) < NSEC_PER_SEC);
if (timer_delete(timerid)) if (timer_delete(timerid))
fatal_error(name, "timer_delete()"); fatal_error(name, "timer_delete()");
@ -583,7 +582,7 @@ static void check_overrun(int which, const char *name)
do { do {
if (clock_gettime(which, &now)) if (clock_gettime(which, &now))
fatal_error(name, "clock_gettime()"); fatal_error(name, "clock_gettime()");
} while (calcdiff_ns(now, start) < NSECS_PER_SEC); } while (calcdiff_ns(now, start) < NSEC_PER_SEC);
/* Unblock it, which should deliver a signal */ /* Unblock it, which should deliver a signal */
if (sigprocmask(SIG_UNBLOCK, &set, NULL)) if (sigprocmask(SIG_UNBLOCK, &set, NULL))

View file

@ -25,10 +25,10 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/timex.h> #include <sys/timex.h>
#include <time.h> #include <time.h>
#include <include/vdso/time64.h>
#include "../kselftest.h" #include "../kselftest.h"
#define CLOCK_MONOTONIC_RAW 4 #define CLOCK_MONOTONIC_RAW 4
#define NSEC_PER_SEC 1000000000LL
#define shift_right(x, s) ({ \ #define shift_right(x, s) ({ \
__typeof__(x) __x = (x); \ __typeof__(x) __x = (x); \

View file

@ -27,10 +27,9 @@
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <sys/time.h> #include <sys/time.h>
#include <include/vdso/time64.h>
#include "../kselftest.h" #include "../kselftest.h"
#define NSEC_PER_SEC 1000000000LL
#define KTIME_MAX ((long long)~((unsigned long long)1 << 63)) #define KTIME_MAX ((long long)~((unsigned long long)1 << 63))
#define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC) #define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC)

View file

@ -28,6 +28,7 @@
#include <signal.h> #include <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h> #include <pthread.h>
#include <include/vdso/time64.h>
#include "../kselftest.h" #include "../kselftest.h"
#define CLOCK_REALTIME 0 #define CLOCK_REALTIME 0
@ -44,8 +45,6 @@
#define CLOCK_TAI 11 #define CLOCK_TAI 11
#define NR_CLOCKIDS 12 #define NR_CLOCKIDS 12
#define NSEC_PER_SEC 1000000000ULL
#define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */ #define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */
#define TIMER_SECS 1 #define TIMER_SECS 1

View file

@ -29,11 +29,9 @@
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
#include <include/vdso/time64.h>
#include "../kselftest.h" #include "../kselftest.h"
#define NSEC_PER_SEC 1000000000LL
#define USEC_PER_SEC 1000000LL
#define ADJ_SETOFFSET 0x0100 #define ADJ_SETOFFSET 0x0100
#include <sys/syscall.h> #include <sys/syscall.h>