Merge ~liaou3/checkbox-iiotg/+git/checkbox-provider-intliotg:refactor_tsn into ~checkbox-dev/checkbox-iiotg/+git/checkbox-provider-intliotg:master

Proposed by Vincent Liao
Status: Merged
Approved by: Vincent Liao
Approved revision: 268d59e3fc5a183428b27c7618160802c719c706
Merged at revision: c82ff7fa22cb083ca6e1afd8b01fc165a45c4af4
Proposed branch: ~liaou3/checkbox-iiotg/+git/checkbox-provider-intliotg:refactor_tsn
Merge into: ~checkbox-dev/checkbox-iiotg/+git/checkbox-provider-intliotg:master
Diff against target: 307 lines (+130/-64)
4 files modified
bin/tsn_phc2sys.sh (+59/-0)
bin/tsn_time_sync.sh (+12/-10)
units/tsn/jobs.pxu (+58/-53)
units/tsn/test-plan.pxu (+1/-1)
Reviewer Review Type Date Requested Status
Rick Wu Approve
PeiYao Chang Approve
StanleyHuang Pending
Patrick Liu Pending
Vic Liu Pending
Review via email: mp+455020@code.launchpad.net

Commit message

Modify: make tsn-ieee802.1as-2011 tests automated

Description of the change

This MR is to do the automation of tsn-ieee802.1as-2011.

submission: https://certification.canonical.com/hardware/202306-31658/submission/341151/

To post a comment you must log in.
Revision history for this message
PeiYao Chang (baconyao) wrote :

Please see my inline comments

review: Needs Fixing
Revision history for this message
Vincent Liao (liaou3) wrote :

> Please see my inline comments
Fixed. Thanks!

Revision history for this message
PeiYao Chang (baconyao) wrote :

LGTM

review: Approve
Revision history for this message
Rick Wu (rickwu4444) wrote :

@Vincent,
Please see my inline comment.

review: Needs Information
Revision history for this message
Vincent Liao (liaou3) wrote :

> @Vincent,
> Please see my inline comment.
I forgot to add them into environ field. Thanks for the reminder.

Revision history for this message
Rick Wu (rickwu4444) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/tsn_phc2sys.sh b/bin/tsn_phc2sys.sh
2new file mode 100755
3index 0000000..e848864
4--- /dev/null
5+++ b/bin/tsn_phc2sys.sh
6@@ -0,0 +1,59 @@
7+#!/bin/bash
8+
9+set -e
10+
11+timeout=$1
12+mode=$2
13+eth_interface=$3
14+server_user=$4
15+server_ip=$5
16+server_pwd=$6
17+server_eth_interface=$7
18+
19+# Start time sync as ${mode}
20+tsn_time_sync.sh "$timeout" "$mode" "$eth_interface" "$server_user" "$server_ip" "$server_pwd" "$server_eth_interface" > /dev/null &
21+
22+# start sync time between physical hardware clock and system clock
23+out=$(mktemp)
24+# Use phc2sys here instead of linuxptp-rt.phc2sys is because there are some issue with the second one.
25+timeout "$timeout" phc2sys -s "$eth_interface" -O 0 -c CLOCK_REALTIME --step_threshold=1 --transportSpecific=1 -w -m | tee "$out"
26+echo ""
27+
28+# Checking the last 10 seconds is because the offset value is not stable enough in the beginning
29+lines=$(tail -n 10 "$out")
30+exit_code=0
31+while read -r line
32+do
33+ offset=$(echo "$line" | grep -o 'phc offset.*freq' | awk '{print $3}')
34+ state=$(echo "$line" | grep -o 'phc offset.*freq' | awk '{print $4}')
35+ delay=$(echo "$line" | awk '{print $10}')
36+ if [ -n "$offset_failed" ] && [ "$offset" -gt 100 ] || [ "$offset" -lt -100 ]; then
37+ echo "FAIL: phc offset is not within -100 to 100 for the last 10 seconds"
38+ echo "phc offset is the offset between system clock and physical hardware clock"
39+ echo ""
40+ offset_failed=1
41+ exit_code=1
42+ fi
43+ if [ -n "$state_failed" ] && [ "$state" != "s2" ]; then
44+ echo "FAIL: state is not equal to s2 for the last 10 seconds"
45+ echo "s0: unsynced"
46+ echo "s1: syncing"
47+ echo "s2: synced"
48+ echo ""
49+ state_failed=1
50+ exit_code=1
51+ fi
52+ if [ -n "$delay_failed" ] && [ "$delay" -ne 0 ]; then
53+ echo "FAIL: path delay is not equal to 0 for the last 10 seconds"
54+ echo "path delay should be 0 if using hardware cross timestamping"
55+ echo ""
56+ delay_failed=1
57+ exit_code=1
58+ fi
59+done <<< "$lines"
60+
61+if [ $exit_code -eq 0 ]; then
62+ echo "PASS: phc offset is within -100 to 100 for the last 10 seconds"
63+ echo "PASS: state is equal to s2 (synced)"
64+ echo "PASS: path delay is equal to 0"
65+fi
66diff --git a/bin/tsn_time_sync.sh b/bin/tsn_time_sync.sh
67index c8e3ce9..9b18793 100755
68--- a/bin/tsn_time_sync.sh
69+++ b/bin/tsn_time_sync.sh
70@@ -4,23 +4,25 @@ set -e
71
72 timeout=$1
73 mode=$2
74-config_path=$3
75-eth_interface=$4
76-server_user=$5
77-server_ip=$6
78-server_pwd=$7
79-server_eth_interface=$8
80+eth_interface=$3
81+server_user=$4
82+server_ip=$5
83+server_pwd=$6
84+server_eth_interface=$7
85+
86+master_config="/snap/linuxptp-rt/current/etc/automotive-master.cfg"
87+client_config="/snap/linuxptp-rt/current/etc/automotive-slave.cfg"
88
89 # This will clear any queue discipline configuration on the devices. If there was no configuration, you will get an error, but you can ignore it.
90 sshpass -p "$server_pwd" ssh -o StrictHostKeyChecking=no "$server_user"@"$server_ip" "echo ${server_pwd} | sudo -S tc qdisc del dev $server_eth_interface root" || true
91 tc qdisc del dev "$eth_interface" root || true
92
93 if [ "$mode" == "client" ]; then
94- sshpass -p "$server_pwd" ssh -o StrictHostKeyChecking=no "$server_user"@"$server_ip" "echo ${server_pwd} | sudo -S timeout $timeout ptp4l -P2Hi $server_eth_interface -f $config_path --step_threshold=1 --first_step_threshold=0.0" &
95- timeout "$timeout" ptp4l -P2Hi "$eth_interface" -f "$config_path" --step_threshold=1 -m -s --first_step_threshold=0.0
96+ sshpass -p "$server_pwd" ssh -o StrictHostKeyChecking=no "$server_user"@"$server_ip" "echo ${server_pwd} | sudo -S timeout $timeout linuxptp-rt.ptp4l -i $server_eth_interface -f $master_config --step_threshold=1" &
97+ timeout "$timeout" linuxptp-rt.ptp4l -i "$eth_interface" -f $client_config --step_threshold=1 -m -s --first_step_threshold=0.0
98 elif [ "$mode" == "master" ]; then
99- timeout "$timeout" ptp4l -P2Hi "$eth_interface" -f "$config_path" --step_threshold=1 --first_step_threshold=0.0 &
100- sshpass -p "$server_pwd" ssh -o StrictHostKeyChecking=no "$server_user"@"$server_ip" "echo ${server_pwd} | sudo -S timeout $timeout ptp4l -m -s -P2Hi $server_eth_interface -f $config_path --step_threshold=1 --first_step_threshold=0.0"
101+ timeout "$timeout" linuxptp-rt.ptp4l -i "$eth_interface" -f "$master_config" --step_threshold=1 &
102+ sshpass -p "$server_pwd" ssh -o StrictHostKeyChecking=no "$server_user"@"$server_ip" "echo ${server_pwd} | sudo -S timeout $timeout linuxptp-rt.ptp4l -m -s -i $server_eth_interface -f $client_config --step_threshold=1"
103 else
104 echo "Wrong argument for $mode. It should be either client or master"
105 exit 1
106diff --git a/units/tsn/jobs.pxu b/units/tsn/jobs.pxu
107index 3bd09c6..de2cbae 100644
108--- a/units/tsn/jobs.pxu
109+++ b/units/tsn/jobs.pxu
110@@ -144,120 +144,125 @@ command:
111 unit: template
112 template-resource: tsn/tsn-devices
113 template-unit: job
114-id: tsn/ieee802.1as-2011/time-sync-between-two-system-as-client-{interface}
115+template-engine: jinja2
116+id: tsn/ieee802.1as-2011/time-sync-between-two-system-as-client-{{ interface }}
117 category_id: tsn
118 _summary:
119- Check establish time-sync with another machine as client via {interface}
120+ Check establish time-sync with another machine as client via {{ interface }}
121 _purpose:
122- Use {interface} on the SUT to achieve time sync with the second machine as client
123+ Use {{ interface }} on the SUT to achieve time sync with the second machine as client
124 depends:
125 tsn/tsn-detected
126 tsn/testing-snap-install-check
127-plugin: user-interact-verify
128+plugin: shell
129 user: root
130 environ:
131 TSN_SERVER_IP
132 TSN_SERVER_USER
133 TSN_SERVER_PWD
134 TSN_SERVER_INTERFACE
135- GPTP_CONFIG_PATH
136+ TSN_MAX_MASTER_OFFSET
137+ TSN_SYNC_TIME
138 command:
139- tsn_time_sync.sh 60 client "${{GPTP_CONFIG_PATH:-/usr/share/gPTP.cfg}}" {interface} "$TSN_SERVER_USER" "$TSN_SERVER_IP" "$TSN_SERVER_PWD" "$TSN_SERVER_INTERFACE"
140-_verification:
141- Is the `rms` value within 100ns?
142+ set -e
143+ out=$(mktemp)
144+ tsn_time_sync.sh ${TSN_SYNC_TIME:-60} client {{ interface }} "$TSN_SERVER_USER" "$TSN_SERVER_IP" "$TSN_SERVER_PWD" "$TSN_SERVER_INTERFACE" | tee "$out"
145+ echo ""
146+ lines=$(tail -n 10 "$out")
147+ while read -r line
148+ do
149+ offset=$(echo "$line" | grep -o 'master offset\s*-\?[0-9]\+ s' | awk '{print $3}')
150+ if [ "$offset" -gt "${TSN_MAX_MASTER_OFFSET:-200}" ] || [ "$offset" -lt -"${TSN_MAX_MASTER_OFFSET:-200}" ]; then
151+ echo "FAIL: master offset is not within -"${TSN_MAX_MASTER_OFFSET:-200}" to "${TSN_MAX_MASTER_OFFSET:-200}" for the last 10 seconds."
152+ exit 1
153+ fi
154+ done <<< "$lines"
155+ echo "PASS: master offset is within -"${TSN_MAX_MASTER_OFFSET:-200}" to "${TSN_MAX_MASTER_OFFSET:-200}" for the last 10 seconds."
156
157 unit: template
158 template-resource: tsn/tsn-devices
159 template-unit: job
160-id: tsn/ieee802.1as-2011/time-sync-between-two-system-as-master-{interface}
161+template-engine: jinja2
162+id: tsn/ieee802.1as-2011/time-sync-between-two-system-as-master-{{ interface }}
163 category_id: tsn
164 _summary:
165- Check establish time-sync with another machine as master via {interface}
166+ Check establish time-sync with another machine as master via {{ interface }}
167 _purpose:
168- Use {interface} on the SUT to achieve time sync with the second machine as master
169+ Use {{ interface }} on the SUT to achieve time sync with the second machine as master
170 depends:
171 tsn/tsn-detected
172- tsn/testing-snap-install-check
173-plugin: user-interact-verify
174+plugin: shell
175 user: root
176 environ:
177 TSN_SERVER_IP
178 TSN_SERVER_USER
179 TSN_SERVER_PWD
180 TSN_SERVER_INTERFACE
181- GPTP_CONFIG_PATH
182+ TSN_MAX_MASTER_OFFSET
183+ TSN_SYNC_TIME
184 command:
185- tsn_time_sync.sh 60 master "${{GPTP_CONFIG_PATH:-/usr/share/gPTP.cfg}}" {interface} "$TSN_SERVER_USER" "$TSN_SERVER_IP" "$TSN_SERVER_PWD" "$TSN_SERVER_INTERFACE"
186-_verification:
187- Is the `rms` value within 100ns?
188+ set -e
189+ out=$(mktemp)
190+ tsn_time_sync.sh ${TSN_SYNC_TIME:-60} master {{ interface }} "$TSN_SERVER_USER" "$TSN_SERVER_IP" "$TSN_SERVER_PWD" "$TSN_SERVER_INTERFACE" | tee "$out"
191+ echo ""
192+ lines=$(tail -n 10 "$out")
193+ while read -r line
194+ do
195+ offset=$(echo "$line" | grep -o 'master offset\s*-\?[0-9]\+ s' | awk '{print $3}')
196+ if [ "$offset" -gt "${TSN_MAX_MASTER_OFFSET:-200}" ] || [ "$offset" -lt -"${TSN_MAX_MASTER_OFFSET:-200}" ]; then
197+ echo "FAIL: master offset is not within -"${TSN_MAX_MASTER_OFFSET:-200}" to "${TSN_MAX_MASTER_OFFSET:-200}" for the last 10 seconds."
198+ exit 1
199+ fi
200+ done <<< "$lines"
201+ echo "PASS: master offset is within -"${TSN_MAX_MASTER_OFFSET:-200}" to "${TSN_MAX_MASTER_OFFSET:-200}" for the last 10 seconds."
202
203 unit: template
204 template-resource: tsn/tsn-devices
205 template-unit: job
206-id: tsn/ieee802.1as-2011/time-sync-system-clock-with-PHC-as-client-{interface}
207+template-engine: jinja2
208+id: tsn/ieee802.1as-2011/time-sync-system-clock-with-PHC-as-client-{{ interface }}
209 category_id: tsn
210 _summary:
211- Check system time sync with PTP hardware clock as client
212+ System time sync with PTP hardware clock as client
213 depends:
214 tsn/tsn-detected
215- tsn/testing-snap-install-check
216- tsn/ieee802.1as-2011/time-sync-between-two-system-as-client-{interface}
217-plugin: user-interact-verify
218+ tsn/ieee802.1as-2011/time-sync-between-two-system-as-client-{{ interface }}
219+plugin: shell
220 user: root
221 _purpose:
222- To check if the system can sync time between system clock and PTP hardware clock as client
223+ To check if the system can sync time between system clock and PTP hardware clock as client via {{ interface }}
224 environ:
225 TSN_SERVER_IP
226 TSN_SERVER_USER
227 TSN_SERVER_PWD
228 TSN_SERVER_INTERFACE
229- GPTP_CONFIG_PATH
230+ TSN_SYNC_TIME
231 command:
232- tsn_time_sync.sh 60 client "${{GPTP_CONFIG_PATH:-/usr/share/gPTP.cfg}}" {interface} "$TSN_SERVER_USER" "$TSN_SERVER_IP" "$TSN_SERVER_PWD" "$TSN_SERVER_INTERFACE" > /dev/null &
233- pmc -u -b 0 -t 1 "SET GRANDMASTER_SETTINGS_NP clockClass 248\
234- clockAccuracy 0xfe offsetScaledLogVariance 0xffff currentUtcOffset 37\
235- leap61 0 leap59 0 currentUtcOffsetValid 1 ptpTimescale 1 timeTraceable 1\
236- frequencyTraceable 0 timeSource 0xa0"
237- timeout 60 phc2sys -s {interface} -O 0 -c CLOCK_REALTIME --step_threshold=1 \
238- --transportSpecific=1 -w -m --first_step_threshold=0.0
239-_verification:
240- Is the `phc offset` value within `100ns`?
241- Is the `State` value equal to `S2`?
242- Is the `Path Delay` equal to `0`
243+ tsn_phc2sys.sh ${TSN_SYNC_TIME:-60} client {{ interface }} "$TSN_SERVER_USER" "$TSN_SERVER_IP" "$TSN_SERVER_PWD" "$TSN_SERVER_INTERFACE"
244
245 unit: template
246 template-resource: tsn/tsn-devices
247 template-unit: job
248-id: tsn/ieee802.1as-2011/time-sync-system-clock-with-PHC-as-master-{interface}
249+template-engine: jinja2
250+id: tsn/ieee802.1as-2011/time-sync-system-clock-with-PHC-as-master-{{ interface }}
251 category_id: tsn
252 _summary:
253- Check system time sync with PTP hardware clock as client
254+ System time sync with PTP hardware clock as master
255 depends:
256 tsn/tsn-detected
257- tsn/testing-snap-install-check
258- tsn/ieee802.1as-2011/time-sync-between-two-system-as-master-{interface}
259-plugin: user-interact-verify
260+ tsn/ieee802.1as-2011/time-sync-between-two-system-as-master-{{ interface }}
261+plugin: shell
262 user: root
263 _purpose:
264- To check if the system can sync time between system clock and PTP hardware clock as master
265+ To check if the system can sync time between system clock and PTP hardware clock as master via {{ interface }}
266 environ:
267 TSN_SERVER_IP
268 TSN_SERVER_USER
269 TSN_SERVER_PWD
270 TSN_SERVER_INTERFACE
271- GPTP_CONFIG_PATH
272+ TSN_SYNC_TIME
273 command:
274- tsn_time_sync.sh 60 master "${{GPTP_CONFIG_PATH:-/usr/share/gPTP.cfg}}" {interface} "$TSN_SERVER_USER" "$TSN_SERVER_IP" "$TSN_SERVER_PWD" "$TSN_SERVER_INTERFACE" > /dev/null &
275- pmc -u -b 0 -t 1 "SET GRANDMASTER_SETTINGS_NP clockClass 248\
276- clockAccuracy 0xfe offsetScaledLogVariance 0xffff currentUtcOffset 37\
277- leap61 0 leap59 0 currentUtcOffsetValid 1 ptpTimescale 1 timeTraceable 1\
278- frequencyTraceable 0 timeSource 0xa0"
279- timeout 60 phc2sys -s {interface} -O 0 -c CLOCK_REALTIME --step_threshold=1 \
280- --transportSpecific=1 -w -m --first_step_threshold=0.0
281-_verification:
282- Is the `phc offset` value within `100ns`?
283- Is the `State` value equal to `S2`?
284- Is the `Path Delay` equal to `0`
285+ tsn_phc2sys.sh ${TSN_SYNC_TIME:-60} master {{ interface }} "$TSN_SERVER_USER" "$TSN_SERVER_IP" "$TSN_SERVER_PWD" "$TSN_SERVER_INTERFACE"
286
287 unit: template
288 template-resource: tsn/tsn-devices
289diff --git a/units/tsn/test-plan.pxu b/units/tsn/test-plan.pxu
290index fd5653c..025bb18 100644
291--- a/units/tsn/test-plan.pxu
292+++ b/units/tsn/test-plan.pxu
293@@ -18,7 +18,6 @@ include:
294 tsn/test-env-setup-for-.*
295 tsn/testing-snap-install-check
296 nested_part:
297- tsn-ieee802.1as-2011
298 tsn-time-based-shaping
299 tsn-ieee802.1qbv
300
301@@ -32,6 +31,7 @@ include:
302 tsn/test-env-setup-for-.*
303 tsn/testing-snap-install-check
304 nested_part:
305+ tsn-ieee802.1as-2011
306 tsn-ieee802.1qav
307 tsn-ieee802.1qbu
308

Subscribers

People subscribed via source and target branches