From 2a24c7ee2008dc9cda5264df9dfcb4ae69d7880e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Wed, 21 Aug 2019 14:54:35 +0200 Subject: [PATCH] unittests/sht1x: decrease the amount of tested values on board Reduce the amount of tested values by a 100. This makes the testing time go from 3 minutes to 2 seconds on `frdm-kw41z`. Testing that the integer calculation matches the float one does not need to be performed on the full range on boards. Checking some values should be enough to detect overflow issues. The full range checking is kept on native. --- tests/unittests/tests-sht1x/tests-sht1x.c | 27 ++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/unittests/tests-sht1x/tests-sht1x.c b/tests/unittests/tests-sht1x/tests-sht1x.c index 337564f3eb..9b45db0801 100644 --- a/tests/unittests/tests-sht1x/tests-sht1x.c +++ b/tests/unittests/tests-sht1x/tests-sht1x.c @@ -16,6 +16,25 @@ static const int16_t max_diff_temp = 1; /** @brief Maximum difference from correct humidity value [in e-02 %] */ static const int16_t max_diff_hum = 10; +/* + * Configure tested values steps + * + * Verify less values on boards as without hwfloat it takes minutes to test. + * Checking that the trend is valid is enough to find int overflow + * or similar errors. + * + * Keep the full range test on native as it is "instant" + */ + +#ifdef CPU_NATIVE +#define TEMPERATURE_TEST_STEPS 1 +/* Use 0.13°c steps. */ +#define HUMIDITY_TEST_TEMP_STEPS 13 +#else /* CPU_NATIVE */ +#define TEMPERATURE_TEST_STEPS 100 +#define HUMIDITY_TEST_TEMP_STEPS 1300 +#endif /* CPU_NATIVE */ + static int16_t expected_temp(const sht1x_dev_t *dev, uint16_t _raw) { static const double d1_table[] = { -40.1, -39.8, -39.7, -39.6, -39.4 }; @@ -68,7 +87,8 @@ static void test_sht1x_conversion(void) uint16_t max_raw_hum = max_raw_hums[i_res]; for (size_t i_vdd = 0; i_vdd < ARRAY_SIZE(vdds); i_vdd++) { dev.vdd = vdds[i_vdd]; - for (uint16_t raw_temp = 0; raw_temp <= max_raw_temp; raw_temp++) { + for (uint16_t raw_temp = 0; raw_temp <= max_raw_temp; + raw_temp += TEMPERATURE_TEST_STEPS) { int16_t got_temp = sht1x_temperature(&dev, raw_temp); int16_t exp_temp = expected_temp(&dev, raw_temp); @@ -77,8 +97,9 @@ static void test_sht1x_conversion(void) } } - /* Testing for temperatures in -10.00°C and 65.00°C in steps of 0.13°C */ - for (int16_t temp = -1000; temp < 6500; temp += 13) { + /* Testing for temperatures between -10.00°C and 65.00°C */ + for (int16_t temp = -1000; temp < 6500; + temp += HUMIDITY_TEST_TEMP_STEPS) { for (uint16_t raw_hum = 0; raw_hum <= max_raw_hum; raw_hum++) { int16_t exp_hum = expected_hum(&dev, raw_hum, temp); if ((exp_hum < 0) || (exp_hum > 10000)) {