diff --git a/tests/phydat_dump/Makefile b/tests/phydat_dump/Makefile new file mode 100644 index 0000000000..1c1aeac913 --- /dev/null +++ b/tests/phydat_dump/Makefile @@ -0,0 +1,5 @@ +include ../Makefile.tests_common + +USEMODULE += phydat + +include $(RIOTBASE)/Makefile.include diff --git a/tests/phydat_dump/main.c b/tests/phydat_dump/main.c new file mode 100644 index 0000000000..b0c73f04a9 --- /dev/null +++ b/tests/phydat_dump/main.c @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2020 Gunar Schorcht + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * + * @file + * @brief Visual test for the conversion from phydat to a string + * + * @author Gunar Schorcht + * + */ + +#include + +#include "phydat.h" + +typedef struct { + phydat_t dat; + uint8_t dim; +} _phydat_test_t; + +_phydat_test_t _test_vector[] = +{ + { .dim = 1, .dat = { .val = { 1234 }, .unit = UNIT_TEMP_C, .scale = -2 } }, + { .dim = 1, .dat = { .val = { 1234 }, .unit = UNIT_TEMP_F, .scale = -2 } }, + { .dim = 1, .dat = { .val = { 1234 }, .unit = UNIT_TEMP_K, .scale = -1 } }, + { .dim = 1, .dat = { .val = { 1234 }, .unit = UNIT_LUX, .scale = -1 } }, + { .dim = 3, .dat = { .val = { 1234, 13456, -14567 }, .unit = UNIT_M, .scale = 0 } }, + { .dim = 3, .dat = { .val = { 1234, 13456, -14567 }, .unit = UNIT_M, .scale = 1 } }, + { .dim = 3, .dat = { .val = { 1234, 13456, -14567 }, .unit = UNIT_M, .scale = 3 } }, + { .dim = 3, .dat = { .val = { 1234, 13456, -14567 }, .unit = UNIT_M, .scale = -2 } }, + { .dim = 3, .dat = { .val = { 1234, 13456, -14567 }, .unit = UNIT_M, .scale = -3 } }, + { .dim = 1, .dat = { .val = { -12345 }, .unit = UNIT_M2, .scale = -5 } }, + { .dim = 1, .dat = { .val = { -12345 }, .unit = UNIT_M3, .scale = -6 } }, + { .dim = 3, .dat = { .val = { 12, 34, 5678}, .unit = UNIT_G, .scale = -2 } }, + { .dim = 3, .dat = { .val = { 123, 345, 678 }, .unit = UNIT_DPS, .scale = -3 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_GR, .scale = -1 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_A, .scale = 3 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_V, .scale = 6 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_W, .scale = 7 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_GS, .scale = -1 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_DBM, .scale = -3 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_COULOMB, .scale = 0 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_F, .scale = -6 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_F, .scale = -7 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_PH, .scale = -2 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_BAR, .scale = 0 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_PA, .scale = 2 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_CD, .scale = -2 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_CTS, .scale = -3 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_PERCENT, .scale = -3 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_PERMILL, .scale = -4 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_PPM, .scale = -6 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_PPB, .scale = -9 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_GPM3, .scale = -1 } }, + { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_CPM3, .scale = -1 } }, + { .dim = 3, .dat = { .val = { 56, 34, 12 }, .unit = UNIT_TIME, .scale = -1 } }, + { .dim = 3, .dat = { .val = { 27, 2, 2020 }, .unit = UNIT_DATE, .scale = -1 } }, +}; + +int main(void) +{ + puts("Visual phydat test application"); + + for (unsigned int i = 0; i < ARRAY_SIZE(_test_vector); i++) { + phydat_dump(&_test_vector[i].dat, _test_vector[i].dim); + } + return 0; +} diff --git a/tests/phydat_dump/tests/01-run.py b/tests/phydat_dump/tests/01-run.py new file mode 100755 index 0000000000..b17dbe7b82 --- /dev/null +++ b/tests/phydat_dump/tests/01-run.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2020 Gunar Schorcht +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. + +import sys +from testrunner import run + + +def testfunc(child): + child.expect('Visual phydat test application\r\n') + child.expect('Data:\t 12.34 °C\r\n') + child.expect('Data:\t 12.34 °F\r\n') + child.expect('Data:\t 123.4 K\r\n') + child.expect('Data:\t 123.4 lx\r\n') + child.expect('Data:\t\[0\] 1234 m\r\n') + child.expect('\t\[1\] 13456 m\r\n') + child.expect('\t\[2\] -14567 m\r\n') + child.expect('Data:\t\[0\] 1234e1 m\r\n') + child.expect('\t\[1\] 13456e1 m\r\n') + child.expect('\t\[2\] -14567e1 m\r\n') + child.expect('Data:\t\[0\] 1234 km\r\n') + child.expect('\t\[1\] 13456 km\r\n') + child.expect('\t\[2\] -14567 km\r\n') + child.expect('Data:\t\[0\] 12.34 m\r\n') + child.expect('\t\[1\] 134.56 m\r\n') + child.expect('\t\[2\] -145.67 m\r\n') + child.expect('Data:\t\[0\] 1234 mm\r\n') + child.expect('\t\[1\] 13456 mm\r\n') + child.expect('\t\[2\] -14567 mm\r\n') + child.expect('Data:\t -0.12345 m\^2\r\n') + child.expect('Data:\t -12345e-6 m\^3\r\n') + child.expect('Data:\t\[0\] 0.12 g\r\n') + child.expect('\t\[1\] 0.34 g\r\n') + child.expect('\t\[2\] 56.78 g\r\n') + child.expect('Data:\t\[0\] 123 mdps\r\n') + child.expect('\t\[1\] 345 mdps\r\n') + child.expect('\t\[2\] 678 mdps\r\n') + child.expect('Data:\t 1234.5 G\r\n') + child.expect('Data:\t 12345 kA\r\n') + child.expect('Data:\t 12345 MV\r\n') + child.expect('Data:\t 12345e7 W\r\n') + child.expect('Data:\t 1234.5 Gs\r\n') + child.expect('Data:\t 12.345 dBm\r\n') + child.expect('Data:\t 12345 C\r\n') + child.expect('Data:\t 12345 uF\r\n') + child.expect('Data:\t 12345e-7 F\r\n') + child.expect('Data:\t 123.45 pH\r\n') + child.expect('Data:\t 12345 Bar\r\n') + child.expect('Data:\t 12345 hPa\r\n') + child.expect('Data:\t 123.45 cd\r\n') + child.expect('Data:\t 12345 mcts\r\n') + child.expect('Data:\t 12.345 %\r\n') + child.expect('Data:\t 1.2345 permille\r\n') + child.expect('Data:\t 12345 uppm\r\n') + child.expect('Data:\t 12345 nppb\r\n') + child.expect('Data:\t 1234.5 g/m\^3\r\n') + child.expect('Data:\t 1234.5 #/m\^3\r\n') + child.expect('Data:\t12:34:56\r\n') + child.expect('Data:\t2020-02-27\r\n') + + +if __name__ == "__main__": + sys.exit(run(testfunc, timeout=10))