From b68d46c8a06db4819d161a1fc564cd1e9059b091 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Sat, 6 Feb 2021 09:04:06 +1100 Subject: [PATCH] deep sleep example: Extend test coverage to ESP32-S2 * Modify the example on ESP32-S2 to print same output pattern as ESP32 * Add example test verification that "fast booting" (skipping of verification) is working --- .gitlab/ci/target-test.yml | 1 + examples/system/deep_sleep/example_test.py | 42 ++++++++++++++----- .../deep_sleep/main/deep_sleep_example_main.c | 10 +++-- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/.gitlab/ci/target-test.yml b/.gitlab/ci/target-test.yml index a2f8e0179f..865745b642 100644 --- a/.gitlab/ci/target-test.yml +++ b/.gitlab/ci/target-test.yml @@ -318,6 +318,7 @@ test_app_test_003: test_app_test_004: extends: .test_app_esp32s2_template + parallel: 2 tags: - ESP32S2 - Example_GENERIC diff --git a/examples/system/deep_sleep/example_test.py b/examples/system/deep_sleep/example_test.py index e89a8ca0bc..dfc90cdd70 100644 --- a/examples/system/deep_sleep/example_test.py +++ b/examples/system/deep_sleep/example_test.py @@ -1,25 +1,35 @@ from __future__ import unicode_literals import re +import time import ttfw_idf -touch_wake_up_support = ['esp32'] +touch_wake_up_support = ['esp32', 'esp32s2'] -@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3']) +@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32s2', 'esp32c3']) def test_examples_deep_sleep(env, extra_data): dut = env.get_dut('deep_sleep', 'examples/system/deep_sleep') dut.start_app() def expect_enable_deep_sleep_touch(): - dut.expect_all('Enabling timer wakeup, 20s', - re.compile(r'Touch pad #8 average: \d+, wakeup threshold set to \d+.'), - re.compile(r'Touch pad #9 average: \d+, wakeup threshold set to \d+.'), - 'Enabling touch pad wakeup', - 'Entering deep sleep', - timeout=10) + # different targets configure different wake pin(s) + wake_pads = { + 'esp32': [8,9], + 'esp32s2': [9], + }[dut.TARGET] + + print('Expecting to see wakeup configured on pad(s): {}'.format(wake_pads)) + + expect_items = ['Enabling timer wakeup, 20s'] + for pad in wake_pads: + expect_items += [re.compile(r'Touch pad #{} average: \d+, wakeup threshold set to \d+.'.format(pad))] + expect_items += ['Enabling touch pad wakeup', + 'Entering deep sleep'] + + dut.expect_all(*expect_items, timeout=10) def expect_enable_deep_sleep_no_touch(): dut.expect_all('Enabling timer wakeup, 20s', @@ -34,8 +44,20 @@ def test_examples_deep_sleep(env, extra_data): dut.expect('Not a deep sleep reset', timeout=30) expect_enable_deep_sleep() - # Check that it spent 2xxxxms in deep sleep, i.e at least 20 seconds: - dut.expect(re.compile(r'Wake up from timer. Time spent in deep sleep: 2\d{4}ms'), timeout=30) + start_sleep = time.time() + print('Waiting for wakeup...') + dut.expect('boot: ESP-IDF', timeout=30) # first output that's the same on all chips + + sleep_time = time.time() - start_sleep + print('Host measured sleep time at {:.2f}s'.format(sleep_time)) + assert 19 < sleep_time < 22 # note: high tolerance as measuring time on the host may have some timing skew + + # This line indicates that the CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP option set in sdkconfig.defaults + # has correctly allowed skipping verification on wakeup + dut.expect('boot: Fast booting app from partition', timeout=2) + + # Check that it measured 2xxxxms in deep sleep, i.e at least 20 seconds: + dut.expect(re.compile(r'Wake up from timer. Time spent in deep sleep: 2\d{4}ms'), timeout=2) expect_enable_deep_sleep() diff --git a/examples/system/deep_sleep/main/deep_sleep_example_main.c b/examples/system/deep_sleep/main/deep_sleep_example_main.c index 1250894a86..a53a8f939e 100644 --- a/examples/system/deep_sleep/main/deep_sleep_example_main.c +++ b/examples/system/deep_sleep/main/deep_sleep_example_main.c @@ -245,11 +245,13 @@ void app_main(void) touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); touch_pad_fsm_start(); vTaskDelay(100 / portTICK_RATE_MS); - /* read sleep touch pad value */ - uint32_t touch_value; + + /* set touchpad wakeup threshold */ + uint32_t touch_value, wake_threshold; touch_pad_sleep_channel_read_smooth(TOUCH_PAD_NUM9, &touch_value); - touch_pad_sleep_set_threshold(TOUCH_PAD_NUM9, touch_value * 0.1); //10% - printf("test init: touch pad [%d] slp %d, thresh %d\n", + wake_threshold = touch_value * 0.1; // wakeup when touch sensor crosses 10% of background level + touch_pad_sleep_set_threshold(TOUCH_PAD_NUM9, wake_threshold); + printf("Touch pad #%d average: %d, wakeup threshold set to %d\n", TOUCH_PAD_NUM9, touch_value, (uint32_t)(touch_value * 0.1)); #endif printf("Enabling touch pad wakeup\n");