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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/ptp/phc.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ 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.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0
  3 
  4 ALL_TESTS="
  5         settime
  6         adjtime
  7         adjfreq
  8 "
  9 DEV=$1
 10 
 11 ##############################################################################
 12 # Sanity checks
 13 
 14 if [[ "$(id -u)" -ne 0 ]]; then
 15         echo "SKIP: need root privileges"
 16         exit 0
 17 fi
 18 
 19 if [[ "$DEV" == "" ]]; then
 20         echo "SKIP: PTP device not provided"
 21         exit 0
 22 fi
 23 
 24 require_command()
 25 {
 26         local cmd=$1; shift
 27 
 28         if [[ ! -x "$(command -v "$cmd")" ]]; then
 29                 echo "SKIP: $cmd not installed"
 30                 exit 1
 31         fi
 32 }
 33 
 34 phc_sanity()
 35 {
 36         phc_ctl $DEV get &> /dev/null
 37 
 38         if [ $? != 0 ]; then
 39                 echo "SKIP: unknown clock $DEV: No such device"
 40                 exit 1
 41         fi
 42 }
 43 
 44 require_command phc_ctl
 45 phc_sanity
 46 
 47 ##############################################################################
 48 # Helpers
 49 
 50 # Exit status to return at the end. Set in case one of the tests fails.
 51 EXIT_STATUS=0
 52 # Per-test return value. Clear at the beginning of each test.
 53 RET=0
 54 
 55 check_err()
 56 {
 57         local err=$1
 58 
 59         if [[ $RET -eq 0 && $err -ne 0 ]]; then
 60                 RET=$err
 61         fi
 62 }
 63 
 64 log_test()
 65 {
 66         local test_name=$1
 67 
 68         if [[ $RET -ne 0 ]]; then
 69                 EXIT_STATUS=1
 70                 printf "TEST: %-60s  [FAIL]\n" "$test_name"
 71                 return 1
 72         fi
 73 
 74         printf "TEST: %-60s  [ OK ]\n" "$test_name"
 75         return 0
 76 }
 77 
 78 tests_run()
 79 {
 80         local current_test
 81 
 82         for current_test in ${TESTS:-$ALL_TESTS}; do
 83                 $current_test
 84         done
 85 }
 86 
 87 ##############################################################################
 88 # Tests
 89 
 90 settime_do()
 91 {
 92         local res
 93 
 94         res=$(phc_ctl $DEV set 0 wait 120.5 get 2> /dev/null \
 95                 | awk '/clock time is/{print $5}' \
 96                 | awk -F. '{print $1}')
 97 
 98         (( res == 120 ))
 99 }
100 
101 adjtime_do()
102 {
103         local res
104 
105         res=$(phc_ctl $DEV set 0 adj 10 get 2> /dev/null \
106                 | awk '/clock time is/{print $5}' \
107                 | awk -F. '{print $1}')
108 
109         (( res == 10 ))
110 }
111 
112 adjfreq_do()
113 {
114         local res
115 
116         # Set the clock to be 1% faster
117         res=$(phc_ctl $DEV freq 10000000 set 0 wait 100.5 get 2> /dev/null \
118                 | awk '/clock time is/{print $5}' \
119                 | awk -F. '{print $1}')
120 
121         (( res == 101 ))
122 }
123 
124 ##############################################################################
125 
126 cleanup()
127 {
128         phc_ctl $DEV freq 0.0 &> /dev/null
129         phc_ctl $DEV set &> /dev/null
130 }
131 
132 settime()
133 {
134         RET=0
135 
136         settime_do
137         check_err $?
138         log_test "settime"
139         cleanup
140 }
141 
142 adjtime()
143 {
144         RET=0
145 
146         adjtime_do
147         check_err $?
148         log_test "adjtime"
149         cleanup
150 }
151 
152 adjfreq()
153 {
154         RET=0
155 
156         adjfreq_do
157         check_err $?
158         log_test "adjfreq"
159         cleanup
160 }
161 
162 trap cleanup EXIT
163 
164 tests_run
165 
166 exit $EXIT_STATUS

~ [ 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