From fc6dc25da42782f9804ecf7e7f55b31277af3dd2 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Mon, 12 Apr 2021 11:39:10 +0200 Subject: [PATCH] tests/periph_rtt_min: harden test - Better self-containment: read number of expected samples from output rather than the environment - Less reliance on `stdout` timing: Count samples in application and output it rather then counting flushed dots. --- tests/periph_rtt_min/Makefile | 2 -- tests/periph_rtt_min/main.c | 5 ++++- tests/periph_rtt_min/tests/01-run.py | 13 +++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/periph_rtt_min/Makefile b/tests/periph_rtt_min/Makefile index 82af2f49db..894f3ac1ce 100644 --- a/tests/periph_rtt_min/Makefile +++ b/tests/periph_rtt_min/Makefile @@ -23,5 +23,3 @@ else SAMPLES ?= 1024 endif CFLAGS += -DSAMPLES=$(SAMPLES) - -$(call target-export-variables, test, SAMPLES) diff --git a/tests/periph_rtt_min/main.c b/tests/periph_rtt_min/main.c index 369b61e203..6c86b26e7a 100644 --- a/tests/periph_rtt_min/main.c +++ b/tests/periph_rtt_min/main.c @@ -44,6 +44,7 @@ void cb(void *arg) int main(void) { uint32_t value = 0; + uint32_t samples = 0; /* mutex starts out locked, and each time an rtt callback is successfully called it will be locked again for the next iteration */ mutex_t lock = MUTEX_INIT_LOCKED; @@ -69,10 +70,12 @@ int main(void) } printf("."); fflush(stdout); + samples++; } printf("\n"); - printf("RTT_MIN_OFFSET for %s: %" PRIu32 "\n", RIOT_BOARD, value); + printf("RTT_MIN_OFFSET for %s over %" PRIu32 " samples: %" PRIu32 "\n", + RIOT_BOARD, samples, value); return 0; } diff --git a/tests/periph_rtt_min/tests/01-run.py b/tests/periph_rtt_min/tests/01-run.py index 17ba5eaba5..1a9f27c490 100755 --- a/tests/periph_rtt_min/tests/01-run.py +++ b/tests/periph_rtt_min/tests/01-run.py @@ -6,18 +6,19 @@ # General Public License v2.1. See the file LICENSE in the top level # directory for more details. -import os import sys from testrunner import run -SAMPLES = int(os.getenv("SAMPLES", "1024")) - def testfunc(child): - for _ in range(0, SAMPLES): - child.expect_exact('.') - child.expect(r'RTT_MIN_OFFSET for [a-zA-Z\-\_0-9]+: \d+') + child.expect(r"Evaluate RTT_MIN_OFFSET over (\d+) samples") + + exp_samples = int(child.match.group(1)) + child.expect( + r'RTT_MIN_OFFSET for [a-zA-Z\-\_0-9]+ over {samples} samples: \d+' + .format(samples=exp_samples) + ) if __name__ == "__main__":