Skip to content

Commit

Permalink
Update CCTRL 2.2 to not potentially use uninitialized variables in th…
Browse files Browse the repository at this point in the history
…e class on teardown (#34955)

* Do not use uninitialized bits in teardown

* Extra guard for file remove

* Fix a few more instances of app_process

---------

Co-authored-by: Andrei Litvin <andreilitvin@google.com>
  • Loading branch information
2 people authored and pull[bot] committed Jan 17, 2025
1 parent 413435e commit 900898b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
15 changes: 11 additions & 4 deletions src/python_testing/TC_BRBINFO_4_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ async def setup_class(self):
self.set_of_dut_endpoints_before_adding_device = set(root_part_list)

super().setup_class()
self.app_process = None
app = self.user_params.get("th_server_app_path", None)
if not app:
asserts.fail('This test requires a TH_SERVER app. Specify app path with --string-arg th_server_app_path:<path_to_app>')
Expand Down Expand Up @@ -135,10 +136,16 @@ async def setup_class(self):
params.commissioningParameters.setupManualCode, params.commissioningParameters.setupQRCode)

def teardown_class(self):
logging.warning("Stopping app with SIGTERM")
self.app_process.send_signal(signal.SIGTERM.value)
self.app_process.wait()
os.remove(self.kvs)
# In case the th_server_app_path does not exist, then we failed the test
# and there is nothing to remove
if self.app_process is not None:
logging.warning("Stopping app with SIGTERM")
self.app_process.send_signal(signal.SIGTERM.value)
self.app_process.wait()

if os.path.exists(self.kvs):
os.remove(self.kvs)

super().teardown_class()

#
Expand Down
14 changes: 10 additions & 4 deletions src/python_testing/TC_CCTRL_2_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class TC_CCTRL_2_2(MatterBaseTest):
async def setup_class(self):
super().setup_class()
# TODO: confirm whether we can open processes like this on the TH
self.app_process = None
app = self.user_params.get("th_server_app_path", None)
if not app:
asserts.fail('This test requires a TH_SERVER app. Specify app path with --string-arg th_server_app_path:<path_to_app>')
Expand Down Expand Up @@ -73,11 +74,16 @@ async def setup_class(self):
logging.info("Commissioning TH_SERVER complete")

def teardown_class(self):
logging.warning("Stopping app with SIGTERM")
self.app_process.send_signal(signal.SIGTERM.value)
self.app_process.wait()
# In case the th_server_app_path does not exist, then we failed the test
# and there is nothing to remove
if self.app_process is not None:
logging.warning("Stopping app with SIGTERM")
self.app_process.send_signal(signal.SIGTERM.value)
self.app_process.wait()

if os.path.exists(self.kvs):
os.remove(self.kvs)

os.remove(self.kvs)
super().teardown_class()

def steps_TC_CCTRL_2_2(self) -> list[TestStep]:
Expand Down
15 changes: 10 additions & 5 deletions src/python_testing/TC_MCORE_FS_1_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class TC_MCORE_FS_1_1(MatterBaseTest):
async def setup_class(self):
super().setup_class()
# TODO: confirm whether we can open processes like this on the TH
self.app_process = None
app = self.user_params.get("th_server_app_path", None)
if not app:
asserts.fail('This test requires a TH_SERVER app. Specify app path with --string-arg th_server_app_path:<path_to_app>')
Expand Down Expand Up @@ -64,11 +65,15 @@ async def setup_class(self):
logging.info("Commissioning TH_SERVER complete")

def teardown_class(self):
logging.warning("Stopping app with SIGTERM")
self.app_process.send_signal(signal.SIGTERM.value)
self.app_process.wait()

os.remove(self.kvs)
# In case the th_server_app_path does not exist, then we failed the test
# and there is nothing to remove
if self.app_process is not None:
logging.warning("Stopping app with SIGTERM")
self.app_process.send_signal(signal.SIGTERM.value)
self.app_process.wait()

if os.path.exists(self.kvs):
os.remove(self.kvs)
super().teardown_class()

def steps_TC_MCORE_FS_1_1(self) -> list[TestStep]:
Expand Down

0 comments on commit 900898b

Please sign in to comment.