test: Init each test individually 36/231836/3
authorKonrad Kuchciak <k.kuchciak@samsung.com>
Fri, 24 Apr 2020 10:42:41 +0000 (12:42 +0200)
committerKonrad Kuchciak <k.kuchciak@samsung.com>
Fri, 24 Apr 2020 11:21:33 +0000 (13:21 +0200)
Change-Id: I2d26dbfa63f3d454a6cc30330ac5327468ecae58
Signed-off-by: Konrad Kuchciak <k.kuchciak@samsung.com>
test/peripheral-io-test.c

index d152203..9af0367 100644 (file)
@@ -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();