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");
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");
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");
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");
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");
__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");
int main(int argc, char **argv)
{
- int ret;
-
int menu;
printf("\n\n\n*** Peripheral-IO API Test (UTC) ***");
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();
__test_peripheral_pwm_run();
__test_peripheral_adc_run();
__test_peripheral_uart_run();
+ __test_peripheral_spi_run();
break;
case 2:
__test_peripheral_gpio_run();