1
1
import csv
2
2
import json
3
+ import re
4
+ from dataclasses import dataclass
5
+
6
+ import pytest
3
7
4
8
5
9
def test_chrony (shell ):
@@ -66,7 +70,7 @@ def test_switch_configuration(shell, check):
66
70
assert global_v6 .endswith (v6_tail )
67
71
68
72
69
- def test_hostname (shell ):
73
+ def test_hostname (shell , check ):
70
74
"""Test whether the serial number is contained in the hostname"""
71
75
72
76
[serial_number ] = shell .run_check ("cat /sys/firmware/devicetree/base/chosen/baseboard-factory-data/serial-number" )
@@ -75,4 +79,87 @@ def test_hostname(shell):
75
79
76
80
[hostname ] = shell .run_check ("hostname" )
77
81
78
- assert serial_number in hostname
82
+ with check :
83
+ assert serial_number in hostname
84
+
85
+ [etc_hostname ] = shell .run_check ("cat /etc/hostname" )
86
+
87
+ with check :
88
+ assert etc_hostname != "localhost"
89
+
90
+ with check :
91
+ assert serial_number in etc_hostname
92
+
93
+
94
+ def test_system_running (shell ):
95
+ """
96
+ Test if the system state is running.
97
+ """
98
+
99
+ # This will exit non-zero if we have any other state than "running", but we are interested in the string output.
100
+ # So let's ignore the returncode.
101
+ [state ], _ , _ = shell .run ("systemctl is-system-running" )
102
+
103
+ assert state == "running"
104
+
105
+
106
+ @pytest .fixture
107
+ def clocktree (shell ):
108
+ """
109
+ Read the clock tree from the DUT and parse it into a data structure.
110
+ """
111
+ re_entry = re .compile (r"^\s*(\S+)\s+\d+\s+\d+\s+\d+\s+(\d+)\s+\d+\s+\d+\s+(\d+)\s+\S\s+(\S+)\s+" )
112
+ re_2nd = re .compile (r"^\s+(\S+)\s+\S+\s+$" )
113
+
114
+ @dataclass
115
+ class Clk :
116
+ clk_name : str
117
+ rate : int
118
+ duty : int
119
+ consumer : list
120
+
121
+ clks = {}
122
+ clk = None
123
+ for line in shell .run_check ("cat /sys/kernel/debug/clk/clk_summary" ):
124
+ if match := re_entry .match (line ):
125
+ if clk :
126
+ clks [clk .clk_name ] = clk
127
+ clk = Clk (clk_name = match .group (1 ), rate = int (match .group (2 )), duty = int (match .group (3 )), consumer = [])
128
+ if match .group (4 ) != "deviceless" :
129
+ clk .consumer .append (match .group (4 ))
130
+ continue
131
+
132
+ match = re_2nd .match (line )
133
+ if match and match .group (1 ) != "deviceless" :
134
+ clk .consumer .append (match .group (1 ))
135
+
136
+ return clks
137
+
138
+
139
+ @pytest .mark .parametrize (
140
+ "clock_name, rate, consumer" ,
141
+ (
142
+ # Ethernet Clocks: Needed for the communication with the phy to work
143
+ ("ethptp_k" , 125000000 , ("5800a000.ethernet" ,)),
144
+ ("ethck_k" , 125000000 , ("5800a000.ethernet" ,)),
145
+ ("ethrx" , 125000000 , ("5800a000.ethernet" ,)),
146
+ # CAN Clock: Chosen to be 48MHz for minimum baudrate error across all rates
147
+ ("fdcan_k" , 48000000 , ("4400f000.can" , "4400e000.can" )),
148
+ ),
149
+ )
150
+ def test_clocktree (clocktree , check , clock_name , rate , consumer ):
151
+ """
152
+ Make sure a few selected devices have their fixed clock rates applied.
153
+ In this test we check the association of the clock signal with the actual
154
+ device and the clocks rate.
155
+ """
156
+ assert clock_name in clocktree
157
+
158
+ clk = clocktree [clock_name ]
159
+
160
+ with check :
161
+ assert clk .rate == rate
162
+
163
+ for c in consumer :
164
+ with check :
165
+ assert c in clk .consumer
0 commit comments