@@ -32,8 +32,8 @@ def change_domain_check(dom, pci_addr, def_dom):
3232 Check if the domain changed successfully to "dom" for "pci_addr"
3333
3434 :param dom: domain type
35- :param def_dom: default domain of pci device (pci_addr)
36- :param pci_addr: pci device
35+ :param def_dom: default domain of pci address (pci_addr)
36+ :param pci_addr: full pci address including domain (0000:03:00.0)
3737 return: bool
3838 """
3939 output = genio .read_one_line (
@@ -49,7 +49,7 @@ def reset_check(pci_addr):
4949 """
5050 Check if reset for "pci_addr" is successful
5151
52- :param pci_addr: pci device
52+ :param pci_addr: full pci address including domain (0000:03:00.0)
5353 return: bool
5454 """
5555 cmd = f"lspci -vvs { pci_addr } "
@@ -64,7 +64,7 @@ def rescan_check(pci_addr):
6464 """
6565 Check if rescan for pci_addr is successful
6666
67- :param pci_addr: pci device
67+ :param pci_addr: full pci address including domain (0000:03:00.0)
6868 return: bool
6969 """
7070 cmd = f"lspci -vvs { pci_addr } "
@@ -81,7 +81,7 @@ class IommuTest(Test):
8181 reset and rescan is used to form sub-tests that test and exercise iommu
8282 code.
8383
84- :param device: Name of the pci device
84+ :param device: full pci address including domain (0000:03:00.0)
8585 """
8686
8787 def setUp (self ):
@@ -91,13 +91,22 @@ def setUp(self):
9191 self .pci_devices = self .params .get ('pci_devices' , default = None )
9292 self .count = int (self .params .get ('count' , default = 1 ))
9393 self .domains = ["DMA" , "DMA-FQ" , "identity" , "auto" ]
94+ self .dmesg_grep = self .params .get ('dmesg_grep' , default = '' )
9495 if not self .pci_devices :
9596 self .cancel ("No pci device given" )
9697 smm = SoftwareManager ()
9798 if not smm .check_installed ("pciutils" ) and not smm .install ("pciutils" ):
9899 self .cancel ("pciutils package not found and installing failed" )
100+
99101 # Check the number of devices in iommu-group for pci device passed.
100102 for pci_addr in self .pci_devices .split (" " ):
103+
104+ # Check if device input is valid
105+ cmd = f"lspci -s { pci_addr } "
106+ out = process .run (cmd , ignore_status = True , shell = True ).stdout_text
107+ if not out :
108+ self .cancel (f"{ pci_addr } not found on the system" )
109+
101110 driver = pci .get_driver (pci_addr )
102111 if driver is None :
103112 self .cancel ("Device passed is not bound to any driver" )
@@ -112,16 +121,17 @@ def setUp(self):
112121 self .cancel (f"{ pci_addr } belongs to iommu group having more "
113122 "than one device but system does not support "
114123 "domain type change for such device" )
115- cmd = "dmesg -C"
124+
125+ cmd = "dmesg -T --level=alert,crit,err,warn > dmesg_initial.txt"
116126 process .run (cmd , ignore_status = True , shell = True , sudo = True )
117127
118128 # TODO: Need to push this to avocado utils later
119129 def unbind (self , driver , pci_addr ):
120130 """
121131 Unbind the device
122132
123- :param driver: driver of the pci device (pci_addr)
124- :param pci_addr: pci device to be unbind from driver
133+ :param driver: driver of the pci address (pci_addr)
134+ :param pci_addr: full pci address including domain (0000:03:00.0)
125135 return: None
126136 """
127137 genio .write_file (f'/sys/bus/pci/drivers/{ driver } /unbind' , pci_addr )
@@ -137,8 +147,8 @@ def change_domain(self, dom, def_dom, pci_addr):
137147 Change the domain of device to dom
138148
139149 :param dom: domain type
140- :param def_dom: default domain of pci device (pci_addr)
141- :param pci_addr: pci device
150+ :param def_dom: default domain of pci address (pci_addr)
151+ :param pci_addr: full pci address including domain (0000:03:00.0)
142152 return: None
143153 """
144154 genio .write_file (f'/sys/bus/pci/devices/{ pci_addr } /iommu_group/type' ,
@@ -154,8 +164,8 @@ def bind(self, driver, pci_addr):
154164 """
155165 Bind the device to driver
156166
157- :param driver: driver of the pci device (pci_addr)
158- :param pci_addr: pci device
167+ :param driver: driver of the pci address (pci_addr)
168+ :param pci_addr: full pci address including domain (0000:03:00.0)
159169 return: None
160170 """
161171 genio .write_file (f"/sys/bus/pci/drivers/{ driver } /bind" , pci_addr )
@@ -171,7 +181,7 @@ def reset(self, pci_addr):
171181 """
172182 Remove the device
173183
174- :param pci_addr: pci device
184+ :param pci_addr: full pci address including domain (0000:03:00.0)
175185 return: None
176186 """
177187 genio .write_file (f'/sys/bus/pci/devices/{ pci_addr } /remove' , '1' )
@@ -185,7 +195,7 @@ def rescan(self, pci_addr):
185195 """
186196 Rescan the system
187197
188- :param pci_addr: pci device
198+ :param pci_addr: full pci address including domain (0000:03:00.0)
189199 return: None
190200 """
191201 genio .write_file ('/sys/bus/pci/rescan' , '1' )
@@ -198,9 +208,9 @@ def get_params(self, pci_addr):
198208 """
199209 Get device parameter-driver, group, default domain(def_dom)
200210
201- :param pci_addr: pci device
202- return: driver (driver of pci device ),
203- def_dom (default domain of pci device )
211+ :param pci_addr: full pci address including domain (0000:03:00.0)
212+ return: driver (driver of pci address (pci_addr) ),
213+ def_dom (default domain of pci address (pci_addr) )
204214 """
205215 driver = pci .get_driver (pci_addr )
206216
@@ -217,9 +227,9 @@ def check(self, def_dom, pci_addr, driver):
217227 """
218228 Check if the PCI device is in default domain
219229
220- :param def_dom: default domain of pci device (pci_addr)
221- :param pci_addr: pci device
222- :param driver: driver of the pci device (pci_addr)
230+ :param def_dom: default domain of pci address (pci_addr)
231+ :param pci_addr: full pci address including domain (0000:03:00.0)
232+ :param driver: driver of the pci address (pci_addr)
223233 return: None
224234 """
225235 output = genio .read_one_line (
@@ -383,8 +393,19 @@ def check_dmesg(self):
383393 """
384394 Checks for any error or failure messages in dmesg after test
385395 """
386- cmd = "dmesg -T --level=alert,crit,err,warn"
387- out = process .run (cmd , ignore_status = True , shell = True , sudo = True )
388- output = out .stdout_text
389- if output :
390- self .fail (f"Kernel Errors: { output } " )
396+
397+ cmd = "dmesg -T --level=alert,crit,err,warn > dmesg_final.txt"
398+ process .run (cmd , ignore_status = True , shell = True , sudo = True )
399+
400+ cmd = "diff dmesg_final.txt dmesg_initial.txt"
401+ if self .dmesg_grep != '' :
402+ cmd = f"{ cmd } | grep -i -e '{ self .dmesg_grep } '"
403+ dmesg_diff = process .run (cmd , ignore_status = True , shell = True , sudo = True ).stdout_text
404+ if dmesg_diff != '' :
405+ self .whiteboard = f"{ dmesg_diff } "
406+ self .fail ("Running test logged warn,err,alert,crit logs in dmesg. "
407+ "Please refer whiteboard of the test result" )
408+
409+ # Clean temprorary files created
410+ cmd = "rm dmesg_final.txt dmesg_initial.txt"
411+ process .run (cmd , ignore_status = True , shell = True , sudo = True )
0 commit comments