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.
This commit is contained in:
Martine Lenders 2021-04-12 11:39:10 +02:00 committed by Martine S. Lenders
parent e28ec7907b
commit fc6dc25da4
3 changed files with 11 additions and 9 deletions

View File

@ -23,5 +23,3 @@ else
SAMPLES ?= 1024
endif
CFLAGS += -DSAMPLES=$(SAMPLES)
$(call target-export-variables, test, SAMPLES)

View File

@ -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;
}

View File

@ -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__":