From: Konrad Kuchciak Date: Fri, 24 Apr 2020 10:42:41 +0000 (+0200) Subject: test: Init each test individually X-Git-Tag: accepted/tizen/6.0/unified/20201030.121328~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F36%2F231836%2F3;p=platform%2Fcore%2Fapi%2Fperipheral-io.git test: Init each test individually Change-Id: I2d26dbfa63f3d454a6cc30330ac5327468ecae58 Signed-off-by: Konrad Kuchciak --- diff --git a/test/peripheral-io-test.c b/test/peripheral-io-test.c index d152203..9af0367 100644 --- a/test/peripheral-io-test.c +++ b/test/peripheral-io-test.c @@ -71,67 +71,45 @@ static int __get_feature(const char *key, bool *feature) return PERIPHERAL_ERROR_NONE; } -static int __test_peripheral_init() +static int __test_peripheral_init(const char *test_name, const char *key_feature, int (*init_fn)(char *, bool)) { - int ret = PERIPHERAL_ERROR_NONE; - char *model_name = NULL; bool feature = false; + int ret; + + printf("\n[Message] Initializing %s test\n", test_name); ret = __get_model_name(&model_name); - if (ret != PERIPHERAL_ERROR_NONE) + if (ret != PERIPHERAL_ERROR_NONE) { + printf("[Message] Failed to get model name: %d\n", ret); return ret; + } - ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_GPIO, &feature); - if (ret != PERIPHERAL_ERROR_NONE) - goto ERR; - ret = test_peripheral_io_gpio_initialize(model_name, feature); - if (ret != PERIPHERAL_ERROR_NONE) - goto ERR; - - ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_I2C, &feature); - if (ret != PERIPHERAL_ERROR_NONE) - goto ERR; - ret = test_peripheral_io_i2c_initialize(model_name, feature); - if (ret != PERIPHERAL_ERROR_NONE) - goto ERR; - - ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_PWM, &feature); - if (ret != PERIPHERAL_ERROR_NONE) - goto ERR; - ret = test_peripheral_io_pwm_initialize(model_name, feature); - if (ret != PERIPHERAL_ERROR_NONE) - goto ERR; - - ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_ADC, &feature); - if (ret != PERIPHERAL_ERROR_NONE) - goto ERR; - ret = test_peripheral_io_adc_initialize(model_name, feature); - if (ret != PERIPHERAL_ERROR_NONE) - goto ERR; - - ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_UART, &feature); - if (ret != PERIPHERAL_ERROR_NONE) - goto ERR; - ret = test_peripheral_io_uart_initialize(model_name, feature); - if (ret != PERIPHERAL_ERROR_NONE) - goto ERR; + ret = __get_feature(key_feature, &feature); + if (ret != PERIPHERAL_ERROR_NONE) { + free(model_name); + printf("[Message] Feature %s not supported\n", key_feature); + return ret; + } - ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_SPI, &feature); - if (ret != PERIPHERAL_ERROR_NONE) - goto ERR; - ret = test_peripheral_io_spi_initialize(model_name, feature); - if (ret != PERIPHERAL_ERROR_NONE) - goto ERR; + ret = init_fn(model_name, feature); + if (ret != PERIPHERAL_ERROR_NONE) { + free(model_name); + printf("[Message] Failed to initialize %s test: %d\n", test_name, ret); + return ret; + } -ERR: free(model_name); - return ret; + return PERIPHERAL_ERROR_NONE; } static void __test_peripheral_gpio_run() { - int ret = PERIPHERAL_ERROR_NONE; + int ret = __test_peripheral_init("GPIO", KEY_FEATURE_PERIPHERAL_IO_GPIO, + test_peripheral_io_gpio_initialize); + + if (ret != PERIPHERAL_ERROR_NONE) + return; ret = test_peripheral_io_gpio_peripheral_gpio_open_p(); __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_open_p"); @@ -197,7 +175,11 @@ static void __test_peripheral_gpio_run() static void __test_peripheral_i2c_run() { - int ret = PERIPHERAL_ERROR_NONE; + int ret = __test_peripheral_init("I2C", KEY_FEATURE_PERIPHERAL_IO_I2C, + test_peripheral_io_i2c_initialize); + + if (ret != PERIPHERAL_ERROR_NONE) + return; ret = test_peripheral_io_i2c_peripheral_i2c_open_p(); __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_open_p"); @@ -247,7 +229,11 @@ static void __test_peripheral_i2c_run() static void __test_peripheral_pwm_run() { - int ret = PERIPHERAL_ERROR_NONE; + int ret = __test_peripheral_init("PWM", KEY_FEATURE_PERIPHERAL_IO_PWM, + test_peripheral_io_pwm_initialize); + + if (ret != PERIPHERAL_ERROR_NONE) + return; ret = test_peripheral_io_pwm_peripheral_pwm_open_p(); __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_open_p"); @@ -289,7 +275,11 @@ static void __test_peripheral_pwm_run() static void __test_peripheral_adc_run() { - int ret = PERIPHERAL_ERROR_NONE; + int ret = __test_peripheral_init("ADC", KEY_FEATURE_PERIPHERAL_IO_ADC, + test_peripheral_io_adc_initialize); + + if (ret != PERIPHERAL_ERROR_NONE) + return; ret = test_peripheral_io_adc_peripheral_adc_open_p(); __error_check(ret, "test_peripheral_io_adc_peripheral_adc_open_p"); @@ -313,7 +303,11 @@ static void __test_peripheral_adc_run() static void __test_peripheral_uart_run() { - int ret = PERIPHERAL_ERROR_NONE; + int ret = __test_peripheral_init("UART", KEY_FEATURE_PERIPHERAL_IO_UART, + test_peripheral_io_uart_initialize); + + if (ret != PERIPHERAL_ERROR_NONE) + return; ret = test_peripheral_io_uart_peripheral_uart_open_p(); __error_check(ret, "test_peripheral_io_uart_peripheral_uart_open_p"); @@ -435,9 +429,14 @@ static void __test_peripheral_uart_run() __error_check(ret, "test_peripheral_io_uart_peripheral_uart_write_n2"); } + static void __test_peripheral_spi_run() { - int ret = PERIPHERAL_ERROR_NONE; + int ret = __test_peripheral_init("SPI", KEY_FEATURE_PERIPHERAL_IO_SPI, + test_peripheral_io_spi_initialize); + + if (ret != PERIPHERAL_ERROR_NONE) + return; ret = test_peripheral_io_spi_peripheral_spi_open_p(); __error_check(ret, "test_peripheral_io_spi_peripheral_spi_open_p"); @@ -509,8 +508,6 @@ static void __test_peripheral_spi_run() int main(int argc, char **argv) { - int ret; - int menu; printf("\n\n\n*** Peripheral-IO API Test (UTC) ***"); @@ -531,12 +528,6 @@ int main(int argc, char **argv) fail_count = 0; pass_count = 0; - ret = __test_peripheral_init(); - if (ret != PERIPHERAL_ERROR_NONE) { - printf("[Message] Failed test init...\n\n"); - return -1; - } - switch (menu) { case 1: __test_peripheral_gpio_run(); @@ -544,6 +535,7 @@ int main(int argc, char **argv) __test_peripheral_pwm_run(); __test_peripheral_adc_run(); __test_peripheral_uart_run(); + __test_peripheral_spi_run(); break; case 2: __test_peripheral_gpio_run();