From: Shalom Toledo <shalomt@mellanox.com>
To: Vladimir Oltean <olteanv@gmail.com>, Ido Schimmel <idosch@idosch.org>
Cc: netdev <netdev@vger.kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Richard Cochran <richardcochran@gmail.com>,
Jiri Pirko <jiri@mellanox.com>, Petr Machata <petrm@mellanox.com>,
mlxsw <mlxsw@mellanox.com>, Ido Schimmel <idosch@mellanox.com>
Subject: Re: [PATCH net-next 9/9] selftests: ptp: Add Physical Hardware Clock test
Date: Tue, 11 Jun 2019 13:54:36 +0000 [thread overview]
Message-ID: <c880bdb6-1a79-1722-8401-9dcd4024155e@mellanox.com> (raw)
In-Reply-To: <CA+h21hrAzdb0Bnn4dbJqnqRAhgR-3r+DBEYyEUh=_rk6Jh3ouA@mail.gmail.com>
On 07/06/2019 14:15, Vladimir Oltean wrote:
> On Mon, 3 Jun 2019 at 15:25, Ido Schimmel <idosch@idosch.org> wrote:
>>
>> From: Shalom Toledo <shalomt@mellanox.com>
>>
>> Test the PTP Physical Hardware Clock functionality using the "phc_ctl" (a
>> part of "linuxptp").
>>
>> The test contains three sub-tests:
>> * "settime" test
>> * "adjtime" test
>> * "adjfreq" test
>>
>> "settime" test:
>> * set the PHC time to 0 seconds.
>> * wait for 120.5 seconds.
>> * check if PHC time equal to 120.XX seconds.
>>
>> "adjtime" test:
>> * set the PHC time to 0 seconds.
>> * adjust the time by 10 seconds.
>> * check if PHC time equal to 10.XX seconds.
>>
>> "adjfreq" test:
>> * adjust the PHC frequency to be 1% faster.
>> * set the PHC time to 0 seconds.
>> * wait for 100.5 seconds.
>> * check if PHC time equal to 101.XX seconds.
>>
>> Usage:
>> $ ./phc.sh /dev/ptp<X>
>>
>> It is possible to run a subset of the tests, for example:
>> * To run only the "settime" test:
>> $ TESTS="settime" ./phc.sh /dev/ptp<X>
>>
>> Signed-off-by: Shalom Toledo <shalomt@mellanox.com>
>> Reviewed-by: Petr Machata <petrm@mellanox.com>
>> Signed-off-by: Ido Schimmel <idosch@mellanox.com>
>> ---
>> tools/testing/selftests/ptp/phc.sh | 166 +++++++++++++++++++++++++++++
>> 1 file changed, 166 insertions(+)
>> create mode 100755 tools/testing/selftests/ptp/phc.sh
>>
>> diff --git a/tools/testing/selftests/ptp/phc.sh b/tools/testing/selftests/ptp/phc.sh
>> new file mode 100755
>> index 000000000000..ac6e5a6e1d3a
>> --- /dev/null
>> +++ b/tools/testing/selftests/ptp/phc.sh
>> @@ -0,0 +1,166 @@
>> +#!/bin/bash
>> +# SPDX-License-Identifier: GPL-2.0
>> +
>> +ALL_TESTS="
>> + settime
>> + adjtime
>> + adjfreq
>> +"
>> +DEV=$1
>> +
>> +##############################################################################
>> +# Sanity checks
>> +
>> +if [[ "$(id -u)" -ne 0 ]]; then
>> + echo "SKIP: need root privileges"
>> + exit 0
>> +fi
>> +
>> +if [[ "$DEV" == "" ]]; then
>> + echo "SKIP: PTP device not provided"
>> + exit 0
>> +fi
>> +
>> +require_command()
>> +{
>> + local cmd=$1; shift
>> +
>> + if [[ ! -x "$(command -v "$cmd")" ]]; then
>> + echo "SKIP: $cmd not installed"
>> + exit 1
>> + fi
>> +}
>> +
>> +phc_sanity()
>> +{
>> + phc_ctl $DEV get &> /dev/null
>> +
>> + if [ $? != 0 ]; then
>> + echo "SKIP: unknown clock $DEV: No such device"
>> + exit 1
>> + fi
>> +}
>> +
>> +require_command phc_ctl
>> +phc_sanity
>> +
>> +##############################################################################
>> +# Helpers
>> +
>> +# Exit status to return at the end. Set in case one of the tests fails.
>> +EXIT_STATUS=0
>> +# Per-test return value. Clear at the beginning of each test.
>> +RET=0
>> +
>> +check_err()
>> +{
>> + local err=$1
>> +
>> + if [[ $RET -eq 0 && $err -ne 0 ]]; then
>> + RET=$err
>> + fi
>> +}
>> +
>> +log_test()
>> +{
>> + local test_name=$1
>> +
>> + if [[ $RET -ne 0 ]]; then
>> + EXIT_STATUS=1
>> + printf "TEST: %-60s [FAIL]\n" "$test_name"
>> + return 1
>> + fi
>> +
>> + printf "TEST: %-60s [ OK ]\n" "$test_name"
>> + return 0
>> +}
>> +
>> +tests_run()
>> +{
>> + local current_test
>> +
>> + for current_test in ${TESTS:-$ALL_TESTS}; do
>> + $current_test
>> + done
>> +}
>> +
>> +##############################################################################
>> +# Tests
>> +
>> +settime_do()
>> +{
>> + local res
>> +
>> + res=$(phc_ctl $DEV set 0 wait 120.5 get 2> /dev/null \
>> + | awk '/clock time is/{print $5}' \
>> + | awk -F. '{print $1}')
>> +
>> + (( res == 120 ))
>> +}
>> +
>> +adjtime_do()
>> +{
>> + local res
>> +
>> + res=$(phc_ctl $DEV set 0 adj 10 get 2> /dev/null \
>> + | awk '/clock time is/{print $5}' \
>> + | awk -F. '{print $1}')
>> +
>> + (( res == 10 ))
>> +}
>> +
>> +adjfreq_do()
>> +{
>> + local res
>> +
>> + # Set the clock to be 1% faster
>> + res=$(phc_ctl $DEV freq 10000000 set 0 wait 100.5 get 2> /dev/null \
>> + | awk '/clock time is/{print $5}' \
>> + | awk -F. '{print $1}')
>> +
>> + (( res == 101 ))
>> +}
>> +
>> +##############################################################################
>> +
>> +cleanup()
>> +{
>> + phc_ctl $DEV freq 0.0 &> /dev/null
>> + phc_ctl $DEV set &> /dev/null
>> +}
>> +
>> +settime()
>> +{
>> + RET=0
>> +
>> + settime_do
>> + check_err $?
>> + log_test "settime"
>> + cleanup
>> +}
>> +
>> +adjtime()
>> +{
>> + RET=0
>> +
>> + adjtime_do
>> + check_err $?
>> + log_test "adjtime"
>> + cleanup
>> +}
>> +
>> +adjfreq()
>> +{
>> + RET=0
>> +
>> + adjfreq_do
>> + check_err $?
>> + log_test "adjfreq"
>> + cleanup
>> +}
>> +
>> +trap cleanup EXIT
>> +
>> +tests_run
>> +
>> +exit $EXIT_STATUS
>> --
>> 2.20.1
>>
>
> Cool testing framework, thanks!
> Some things to consider:
> - Why the .5 in the wait commands?
To make sure the clock get to the expected time. It's been tested on different
devices.
> - I suspect there's a huge margin of inaccuracy that the test is
> missing by only looking at the 'seconds' portion of the PHC time after
> the adjfreq operation (up to 10^9 - 1 ppb, in the worst case).
Correct, but this test does the work. It tests the basic functionality of PHC.
I'm just sending a v2 based on Richard comments, feel free to extended this
framework. All of us will get benefit from it.
>
> Tested-by: Vladimir Oltean <olteanv@gmail.com>
>
> Regards,
> -Vladimir
>
next prev parent reply other threads:[~2019-06-11 13:56 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-03 12:12 [PATCH net-next 0/9] mlxsw: Add support for physical hardware clock Ido Schimmel
2019-06-03 12:12 ` [PATCH net-next 1/9] mlxsw: cmd: Free running clock PCI BAR and offsets via query firmware Ido Schimmel
2019-06-03 12:12 ` [PATCH net-next 2/9] mlxsw: core: Add a new interface for reading the hardware free running clock Ido Schimmel
2019-06-03 12:12 ` [PATCH net-next 3/9] mlxsw: pci: Query free running clock PCI BAR and offsets Ido Schimmel
2019-06-03 12:12 ` [PATCH net-next 4/9] mlxsw: reg: Add Management UTC Register Ido Schimmel
2019-06-04 14:17 ` Richard Cochran
2019-06-05 11:30 ` Shalom Toledo
2019-06-05 17:23 ` Richard Cochran
2019-06-05 18:55 ` Shalom Toledo
2019-06-06 2:37 ` Richard Cochran
2019-06-06 9:11 ` Shalom Toledo
2019-06-06 10:12 ` Petr Machata
2019-06-03 12:12 ` [PATCH net-next 5/9] mlxsw: reg: Add Management Pulse Per Second Register Ido Schimmel
2019-06-03 12:12 ` [PATCH net-next 6/9] ptp: ptp_clock: Publish scaled_ppm_to_ppb Ido Schimmel
2019-06-04 14:21 ` Richard Cochran
2019-06-05 11:46 ` Shalom Toledo
2019-06-03 12:12 ` [PATCH net-next 7/9] mlxsw: spectrum_ptp: Add implementation for physical hardware clock operations Ido Schimmel
2019-06-04 14:28 ` Richard Cochran
2019-06-05 6:30 ` Jiri Pirko
2019-06-05 17:24 ` Richard Cochran
2019-06-05 11:44 ` Shalom Toledo
2019-06-05 17:40 ` Richard Cochran
2019-06-05 19:28 ` Shalom Toledo
2019-06-06 2:43 ` Richard Cochran
2019-06-06 8:50 ` Shalom Toledo
2019-06-06 8:57 ` Shalom Toledo
2019-06-04 17:03 ` Richard Cochran
2019-06-05 9:00 ` Petr Machata
2019-06-05 17:31 ` Richard Cochran
2019-06-06 10:21 ` Petr Machata
2019-06-03 12:12 ` [PATCH net-next 8/9] mlxsw: spectrum: PTP physical hardware clock initialization Ido Schimmel
2019-06-03 12:12 ` [PATCH net-next 9/9] selftests: ptp: Add Physical Hardware Clock test Ido Schimmel
2019-06-04 17:05 ` Richard Cochran
2019-06-07 11:15 ` Vladimir Oltean
2019-06-08 10:44 ` Vladimir Oltean
2019-06-11 13:54 ` Shalom Toledo [this message]
2019-06-03 17:35 ` [PATCH net-next 0/9] mlxsw: Add support for physical hardware clock David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c880bdb6-1a79-1722-8401-9dcd4024155e@mellanox.com \
--to=shalomt@mellanox.com \
--cc=davem@davemloft.net \
--cc=idosch@idosch.org \
--cc=idosch@mellanox.com \
--cc=jiri@mellanox.com \
--cc=mlxsw@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=petrm@mellanox.com \
--cc=richardcochran@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).