diff --git a/Makefile b/Makefile index fac3c85..70fb47e 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ unity: print_args clean check_unity_path $(Q) find $(UNITY_PATH) -name '*.[hc]' \( -path '*extras*' -a -path '*src*' -or -path '*src*' -a \! -path '*example*' \) -exec \cp {} build \; $(Q) find src/utils -name '*.[hc]*' -exec \cp {} build \; $(Q) find src -maxdepth 1 -name '*.[hc]*' -exec \cp {} build \; - $(Q) find ../ -maxdepth 1 -name 'test_config.*' -exec \cp {} build \; + $(Q) find ../../tests -maxdepth 1 -name 'test_config.*' -exec \cp {} build \; $(Q) cp src/test_main.ino build/build.ino # Helper to extract the second word from the target name diff --git a/src/corelibs/analogio/test_analogio_adc.cpp b/src/corelibs/analogio/test_analogio_adc.cpp index 2595089..b00da0d 100644 --- a/src/corelibs/analogio/test_analogio_adc.cpp +++ b/src/corelibs/analogio/test_analogio_adc.cpp @@ -77,19 +77,34 @@ static TEST_SETUP(analogio_adc) { * @brief Tear down method called by Unity after every test in this test group. */ static TEST_TEAR_DOWN(analogio_adc) { + analogReadResolution(TEST_ADC_RESOLUTION); } #ifdef TEST_PIN_ANALOG_IO_VREF /** - * @brief Verify ADC value for the DEFAULT volatage reference on the pin that is connected to VDDA + * @brief Verify ADC value for the DEFAULT volatage reference on the pin that is connected to VDDA with various resolution values */ TEST_IFX(analogio_adc, test_adc_read_default_vdda_vref_pin) { analogReference(DEFAULT); int adc_value = analogRead(TEST_PIN_ANALOG_IO_VREF); - int expected_value = TEST_ADC_RESOLUTION; - TEST_ASSERT_TRUE_MESSAGE(validate_adc_raw_value(expected_value, adc_value), "ADC value is not within the expected range"); + int expected_value = TEST_ADC_MAX_VALUE; + TEST_ASSERT_TRUE_MESSAGE(validate_adc_raw_value(expected_value, adc_value), "ADC value is not within the expected range for default resolution"); + + const int resolutions[] = {8, 10, 12}; + const int num_resolutions = sizeof(resolutions) / sizeof(resolutions[0]); + + for (int i = 0; i < num_resolutions; i++) + { + int resolution = resolutions[i]; + analogReadResolution(resolution); + + adc_value = analogRead(TEST_PIN_ANALOG_IO_VREF); // Perform ADC read + + int expected_value = (1 << resolution) - 1; // 2^resolution - 1 + TEST_ASSERT_TRUE_MESSAGE(validate_adc_raw_value(expected_value, adc_value), "ADC value does not match expected resolution range"); + } } #endif // TEST_PIN_ANALOG_IO_VREF @@ -97,14 +112,30 @@ TEST_IFX(analogio_adc, test_adc_read_default_vdda_vref_pin) #ifdef TEST_PIN_ANALOG_IO_DIVIDER /** - * @brief Verify ADC value for the DEFAULT volatage reference on the pin that is connected to voltage divider. + * @brief Verify ADC value for the DEFAULT volatage reference on the pin that is connected to voltage divider with various resolution values. */ TEST_IFX(analogio_adc, test_adc_read_default_vdda_divider_pin) { analogReference(DEFAULT); // Configure reference to VDDA int adc_value = analogRead(TEST_PIN_ANALOG_IO_DIVIDER); - int expected_value = TEST_ADC_RESOLUTION / 2; - TEST_ASSERT_TRUE_MESSAGE(validate_adc_raw_value(expected_value, adc_value), "ADC value is not within the expected range"); + int expected_value = TEST_ADC_MAX_VALUE / 2; + TEST_ASSERT_TRUE_MESSAGE(validate_adc_raw_value(expected_value, adc_value), "ADC value is not within the expected range for default resolution"); + + const int resolutions[] = {8, 10, 12}; + const int num_resolutions = sizeof(resolutions) / sizeof(resolutions[0]); + + for (int i = 0; i < num_resolutions; i++) + { + int resolution = resolutions[i]; + analogReadResolution(resolution); + + adc_value = analogRead(TEST_PIN_ANALOG_IO_DIVIDER); + + int expected_value = (1 << resolution) - 1; // 2^resolution - 1 + expected_value = expected_value / 2; + + TEST_ASSERT_TRUE_MESSAGE(validate_adc_raw_value(expected_value, adc_value), "ADC value does not match expected resolution range"); + } } #endif // TEST_PIN_ANALOG_IO_DIVIDER diff --git a/src/corelibs/spi/test_spi_connected1_loopback.cpp b/src/corelibs/spi/test_spi_connected1_loopback.cpp index ca8a2a2..181210c 100644 --- a/src/corelibs/spi/test_spi_connected1_loopback.cpp +++ b/src/corelibs/spi/test_spi_connected1_loopback.cpp @@ -73,7 +73,6 @@ TEST_IFX(spi_connected1_loopback, test_spi_mode_configuration) { TEST_IFX(spi_connected1_loopback, test_spi_reinitialization) { spi->end(); spi->begin(); - TEST_ASSERT_EQUAL_MESSAGE(CY_RSLT_SUCCESS, spi->status, "SPI reinitialization failed"); } // Define test runner for the SPI test group diff --git a/src/corelibs/uart/test_uart_connected2_rx.cpp b/src/corelibs/uart/test_uart_connected2_rx.cpp index 282292e..671f95a 100644 --- a/src/corelibs/uart/test_uart_connected2_rx.cpp +++ b/src/corelibs/uart/test_uart_connected2_rx.cpp @@ -51,7 +51,6 @@ static void uart_connected2_rx_suite_setup() { // Method invoked after a test suite is run. static void uart_connected2_rx_suite_teardown() { - uart->end(); // End UART communication } // define test group name diff --git a/src/corelibs/uart/test_uart_connected2_tx.cpp b/src/corelibs/uart/test_uart_connected2_tx.cpp index 331ac95..b0048aa 100644 --- a/src/corelibs/uart/test_uart_connected2_tx.cpp +++ b/src/corelibs/uart/test_uart_connected2_tx.cpp @@ -53,7 +53,6 @@ static void uart_connected2_tx_suite_setup() { // Method invoked after a test suite is run. static void uart_connected2_tx_suite_teardown() { - uart->end(); // End UART communication } // define test group name diff --git a/src/corelibs/uart/test_uart_rx.cpp b/src/corelibs/uart/test_uart_rx.cpp index 6e8f0e7..ec5cc52 100644 --- a/src/corelibs/uart/test_uart_rx.cpp +++ b/src/corelibs/uart/test_uart_rx.cpp @@ -208,9 +208,5 @@ TEST_GROUP_RUNNER(uart_rx) { RUN_TEST_CASE(uart_rx, check_no_available_read_peek); RUN_TEST_CASE(uart_rx, write_reply_back); RUN_TEST_CASE(uart_rx, end); - /* Wait forever for now. */ - /* This allows to check the rx - test manually. */ - while(true) {}; } diff --git a/src/corelibs/uart/test_uart_tx.cpp b/src/corelibs/uart/test_uart_tx.cpp index 03a325c..431169a 100644 --- a/src/corelibs/uart/test_uart_tx.cpp +++ b/src/corelibs/uart/test_uart_tx.cpp @@ -214,8 +214,4 @@ TEST_GROUP_RUNNER(uart_tx) { RUN_TEST_CASE(uart_tx, read_reply); RUN_TEST_CASE(uart_tx, end); uart_tx_suite_teardown(); - /* Wait forever for now. */ - /* This allows to check the tx - test manually. */ - while(true) {}; }