Skip to content

Commit

Permalink
Fix ESP32 platform manager shutdown.
Browse files Browse the repository at this point in the history
The QEMU ESP32 tests start and stop the platform manager several times, and the
lack of a shutdown implementation was putting things in a bad state.

Also adjusts the test runner script to trigger a test failure when we do end up
in that bad state: we were passing even though we crashed quite early in the
test run and most of the tests did not run.
  • Loading branch information
bzbarsky-apple committed Sep 6, 2022
1 parent 58fd10a commit 86dc30f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,17 @@ void GenericPlatformManagerImpl_FreeRTOS<ImplClass>::PostEventFromISR(const Chip
template <class ImplClass>
void GenericPlatformManagerImpl_FreeRTOS<ImplClass>::_Shutdown(void)
{
GenericPlatformManagerImpl<ImplClass>::_Shutdown();

if (mChipEventQueue != NULL) {
vQueueDelete(mChipEventQueue);
mChipEventQueue = NULL;
}

if (mChipStackLock != NULL) {
vSemaphoreDelete(mChipStackLock);
mChipStackLock = NULL;
}
}

template <class ImplClass>
Expand Down
2 changes: 2 additions & 0 deletions src/platform/ESP32/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ void PlatformManagerImpl::_Shutdown()
}

Internal::GenericPlatformManagerImpl_FreeRTOS<PlatformManagerImpl>::_Shutdown();

esp_event_loop_delete_default();
}

void PlatformManagerImpl::HandleESPSystemEvent(void * arg, esp_event_base_t eventBase, int32_t eventId, void * eventData)
Expand Down
2 changes: 1 addition & 1 deletion src/system/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ chip_test_suite("tests") {
"TestTimeSource.cpp",
]

if (chip_device_platform != "esp32" && chip_device_platform != "fake") {
if (chip_device_platform != "fake") {
test_sources += [ "TestSystemScheduleWork.cpp" ]
}

Expand Down
27 changes: 26 additions & 1 deletion src/test_driver/esp32/run_qemu_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import click
import logging
import os
import re
import sys
import subprocess

Expand Down Expand Up @@ -104,19 +105,41 @@ def main(log_level, no_log_timestamps, image, file_image_list, qemu, verbose):
(path, status.returncode))

# Parse output of the unit test. Generally expect things like:
# I (3034) CHIP-tests: Starting CHIP tests!
# ...
# Various test lines, none ending with "] : FAILED"
# ...
# Failed Tests: 0 / 5
# Failed Asserts: 0 / 77
# I (3034) CHIP-tests: CHIP test status: 0
in_test = False
for line in output.split('\n'):
if line.endswith('CHIP-tests: Starting CHIP tests!'):
in_test = True

if line.startswith('Failed Tests:') and not line.startswith('Failed Tests: 0 /'):
raise Exception("Tests seem failed: %s" % line)

if line.startswith('Failed Asserts:') and not line.startswith('Failed Asserts: 0 /'):
raise Exception("Asserts seem failed: %s" % line)

if 'CHIP test status: ' in line and 'CHIP test status: 0' not in line:
if 'CHIP-tests: CHIP test status: 0' in line:
in_test = False
elif 'CHIP-tests: CHIP test status: ' in line:
raise Exception("CHIP test status is NOT 0: %s" % line)

# Ignore FAILED messages not in the middle of a test, to reduce
# the chance of false posisitves from other logging.
if in_test and re.match('.*] : FAILED$', line):
raise Exception("Step failed: %s" % line)

# TODO: Figure out why exit(0) in man_app.cpp's tester_task is aborting and fix that.
if in_test and line.startswith('abort() was called at PC'):
raise Exception("Unexpected crash: %s" % line)

if in_test:
raise Exception('Not expected to be in the middle of a test when the log ends')

if verbose:
print("========== TEST OUTPUT BEGIN ============")
print(output)
Expand All @@ -125,7 +148,9 @@ def main(log_level, no_log_timestamps, image, file_image_list, qemu, verbose):
logging.info("Image %s PASSED", path)
except:
# make sure output is visible in stdout
print("========== TEST OUTPUT BEGIN ============")
print(output)
print("========== TEST OUTPUT END ============")
raise


Expand Down

0 comments on commit 86dc30f

Please sign in to comment.