~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/vDSO/vdso_test_clock_getres.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  2 /*
  3  * vdso_clock_getres.c: Sample code to test clock_getres.
  4  * Copyright (c) 2019 Arm Ltd.
  5  *
  6  * Compile with:
  7  * gcc -std=gnu99 vdso_clock_getres.c
  8  *
  9  * Tested on ARM, ARM64, MIPS32, x86 (32-bit and 64-bit),
 10  * Power (32-bit and 64-bit), S390x (32-bit and 64-bit).
 11  * Might work on other architectures.
 12  */
 13 
 14 #define _GNU_SOURCE
 15 #include <elf.h>
 16 #include <err.h>
 17 #include <fcntl.h>
 18 #include <stdint.h>
 19 #include <stdio.h>
 20 #include <stdlib.h>
 21 #include <time.h>
 22 #include <sys/auxv.h>
 23 #include <sys/mman.h>
 24 #include <sys/time.h>
 25 #include <unistd.h>
 26 #include <sys/syscall.h>
 27 
 28 #include "../kselftest.h"
 29 
 30 static long syscall_clock_getres(clockid_t _clkid, struct timespec *_ts)
 31 {
 32         long ret;
 33 
 34         ret = syscall(SYS_clock_getres, _clkid, _ts);
 35 
 36         return ret;
 37 }
 38 
 39 const char *vdso_clock_name[12] = {
 40         "CLOCK_REALTIME",
 41         "CLOCK_MONOTONIC",
 42         "CLOCK_PROCESS_CPUTIME_ID",
 43         "CLOCK_THREAD_CPUTIME_ID",
 44         "CLOCK_MONOTONIC_RAW",
 45         "CLOCK_REALTIME_COARSE",
 46         "CLOCK_MONOTONIC_COARSE",
 47         "CLOCK_BOOTTIME",
 48         "CLOCK_REALTIME_ALARM",
 49         "CLOCK_BOOTTIME_ALARM",
 50         "CLOCK_SGI_CYCLE",
 51         "CLOCK_TAI",
 52 };
 53 
 54 /*
 55  * This function calls clock_getres in vdso and by system call
 56  * with different values for clock_id.
 57  *
 58  * Example of output:
 59  *
 60  * clock_id: CLOCK_REALTIME [PASS]
 61  * clock_id: CLOCK_BOOTTIME [PASS]
 62  * clock_id: CLOCK_TAI [PASS]
 63  * clock_id: CLOCK_REALTIME_COARSE [PASS]
 64  * clock_id: CLOCK_MONOTONIC [PASS]
 65  * clock_id: CLOCK_MONOTONIC_RAW [PASS]
 66  * clock_id: CLOCK_MONOTONIC_COARSE [PASS]
 67  */
 68 static inline int vdso_test_clock(unsigned int clock_id)
 69 {
 70         struct timespec x, y;
 71 
 72         printf("clock_id: %s", vdso_clock_name[clock_id]);
 73         clock_getres(clock_id, &x);
 74         syscall_clock_getres(clock_id, &y);
 75 
 76         if ((x.tv_sec != y.tv_sec) || (x.tv_nsec != y.tv_nsec)) {
 77                 printf(" [FAIL]\n");
 78                 return KSFT_FAIL;
 79         }
 80 
 81         printf(" [PASS]\n");
 82         return KSFT_PASS;
 83 }
 84 
 85 int main(int argc, char **argv)
 86 {
 87         int ret = 0;
 88 
 89 #if _POSIX_TIMERS > 0
 90 
 91 #ifdef CLOCK_REALTIME
 92         ret += vdso_test_clock(CLOCK_REALTIME);
 93 #endif
 94 
 95 #ifdef CLOCK_BOOTTIME
 96         ret += vdso_test_clock(CLOCK_BOOTTIME);
 97 #endif
 98 
 99 #ifdef CLOCK_TAI
100         ret += vdso_test_clock(CLOCK_TAI);
101 #endif
102 
103 #ifdef CLOCK_REALTIME_COARSE
104         ret += vdso_test_clock(CLOCK_REALTIME_COARSE);
105 #endif
106 
107 #ifdef CLOCK_MONOTONIC
108         ret += vdso_test_clock(CLOCK_MONOTONIC);
109 #endif
110 
111 #ifdef CLOCK_MONOTONIC_RAW
112         ret += vdso_test_clock(CLOCK_MONOTONIC_RAW);
113 #endif
114 
115 #ifdef CLOCK_MONOTONIC_COARSE
116         ret += vdso_test_clock(CLOCK_MONOTONIC_COARSE);
117 #endif
118 
119 #endif
120         if (ret > 0)
121                 return KSFT_FAIL;
122 
123         return KSFT_PASS;
124 }
125 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php