|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Copyright (C) 2023 Inria |
| 4 | +# |
| 5 | +# This file is subject to the terms and conditions of the GNU Lesser |
| 6 | +# General Public License v2.1. See the file LICENSE in the top level |
| 7 | +# directory for more details. |
| 8 | + |
| 9 | +import sys |
| 10 | +from testrunner import run |
| 11 | + |
| 12 | + |
| 13 | +ERROR_MS = 50 # This is large enough to pass the test on IoT-LAB nrf52dk |
| 14 | + |
| 15 | + |
| 16 | +def testfunc(child): |
| 17 | + child.expect(r"Testing gnrc_mac timeout module \(start time = (\d+) ms\)") |
| 18 | + start = int(child.match.group(1)) |
| 19 | + child.expect(r"Set timeout_1, should be expired at (\d+) ms\)") |
| 20 | + timeout_1 = int(child.match.group(1)) |
| 21 | + child.expect(r"Set timeout_2, should be expired at (\d+) ms\)") |
| 22 | + timeout_2 = int(child.match.group(1)) |
| 23 | + child.expect(r"Set timeout_3, should be expired at (\d+) ms\)") |
| 24 | + timeout_3 = int(child.match.group(1)) |
| 25 | + child.expect_exact("Are the reception times of all 3 msgs close to the supposed values?") |
| 26 | + |
| 27 | + child.expect_exact("If yes, the tests were successful") |
| 28 | + child.expect( |
| 29 | + r"At (\d+) ms received msg 1: " |
| 30 | + r"timeout_1 \(set at {start} ms\) expired, supposed to be {timeout_1} ms\!" |
| 31 | + .format(start=start, timeout_1=timeout_1) |
| 32 | + ) |
| 33 | + timeout_1_measured = int(child.match.group(1)) |
| 34 | + assert timeout_1_measured - timeout_1 < ERROR_MS |
| 35 | + child.expect_exact(f"At {timeout_1_measured} ms: timeout_1 is not running.") |
| 36 | + child.expect_exact(f"At {timeout_1_measured} ms: timeout_2 is running.") |
| 37 | + child.expect_exact(f"At {timeout_1_measured} ms: timeout_3 is running.") |
| 38 | + child.expect( |
| 39 | + r"At (\d+) ms received msg 2: " |
| 40 | + r"timeout_2 \(set at {start} ms\) expired, supposed to be {timeout_2} ms\!" |
| 41 | + .format(start=start, timeout_2=timeout_2) |
| 42 | + ) |
| 43 | + timeout_2_measured = int(child.match.group(1)) |
| 44 | + assert timeout_2_measured - timeout_2 < ERROR_MS |
| 45 | + child.expect_exact(f"At {timeout_2_measured} ms: timeout_1 is not running.") |
| 46 | + child.expect_exact(f"At {timeout_2_measured} ms: timeout_2 is not running.") |
| 47 | + child.expect_exact(f"At {timeout_2_measured} ms: timeout_3 is running.") |
| 48 | + child.expect( |
| 49 | + r"At (\d+) ms received msg 3: " |
| 50 | + r"timeout_3 \(set at {start} ms\) expired, supposed to be {timeout_3} ms\!" |
| 51 | + .format(start=start, timeout_3=timeout_3) |
| 52 | + ) |
| 53 | + timeout_3_measured = int(child.match.group(1)) |
| 54 | + assert timeout_3_measured - timeout_3 < ERROR_MS |
| 55 | + child.expect_exact(f"At {timeout_3_measured} ms: timeout_1 is not running.") |
| 56 | + child.expect_exact(f"At {timeout_3_measured} ms: timeout_2 is not running.") |
| 57 | + child.expect_exact(f"At {timeout_3_measured} ms: timeout_3 is not running.") |
| 58 | + |
| 59 | + |
| 60 | +if __name__ == "__main__": |
| 61 | + sys.exit(run(testfunc)) |
0 commit comments