void pwrbtn_srv_test(void) { DRIVER_API_RC ret; #ifndef CONFIG_UI_SERVICE_IMPL pwrbtn_init(&pwrbtn_aon_0_alone, get_test_queue()); /* Wait pwrbtn unitialisation */ local_task_sleep_ms(1500); #endif cu_print("##################################################\n"); cu_print("# #\n"); cu_print("# !!! Pins AON %d and SS %d must be connected ! #\n", PWRBTN_TST_AON_INPUT_PIN, PWRBTN_TST_SS_OUTPUT_PIN); cu_print("# #\n"); cu_print("# Purpose of service : Validate power button #\n"); cu_print("##################################################\n"); ret = press_simulation(SS_GPIO_SERVICE_ID, PWRBTN_TST_AON_INPUT_PIN, PWRBTN_TST_SS_OUTPUT_PIN); CU_ASSERT("Test power button module failed", ret == DRV_RC_OK); CU_ASSERT("Press 700ms not notified", tst_very_short == 1); CU_ASSERT("Press 2500ms not notified", tst_short == 1); CU_ASSERT("Press 4000ms not notified", tst_single == 1); CU_ASSERT("Press 7000ms not notified", tst_long == 1); CU_ASSERT("Press 12000ms notified", tst_very_long == 0); CU_ASSERT("Double press not notified", tst_double == 1); CU_ASSERT("Press 700ms not notified", tst_double_fail_1 == 1); CU_ASSERT("Press 2700ms not notified", tst_double_fail_2 == 1); CU_ASSERT("Press 300ms notified", tst_too_short == 0); cu_print("##################################################\n"); cu_print("# Test module power button done #\n"); cu_print("##################################################\n"); }
static void trans_delay(void) { local_task_sleep_ms(100); }
int press_simulation(unsigned int service_id, unsigned int input_pin, unsigned int output_pin) { cfw_service_conn_t *gpio_service_conn = NULL; cfw_client_t *gpio_client = cfw_client_init( get_test_queue(), pwrbtn_tst_handle_msg, NULL); if (!cfw_service_registered(service_id)) { cu_print("TST_PWRBTN: ss gpio service not registered\n"); return DRV_RC_FAIL; } cfw_open_service_conn(gpio_client, service_id, &gpio_service_conn); SRV_WAIT((!gpio_service_conn), 2000); CU_ASSERT("TST_PWRBTN: can not open ss gpio service", (gpio_service_conn)); if (gpio_service_conn == NULL) { return DRV_RC_FAIL; } /* The configuration put the pin to 0 => the pin have to be set to 1 * before first press simulation */ TEST_PWRBTN(configure, "TST_PWRBTN: gpio configuration failed", gpio_service_conn, output_pin, 1, "SS pin 2 output"); SRV_WAIT((!tst_pwrbtn_configure), 2000); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait state response */ SRV_WAIT((!tst_pwrbtn_set_state), 2000); /* wait 3s */ local_task_sleep_ms(3000); tst_step = VERY_SH_PRESS; cu_print("Start pattern with press_duration = 700ms\n"); TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(700); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait pattern detection */ SRV_WAIT((!tst_very_short), 2000); /* wait 3s */ local_task_sleep_ms(3000); cu_print("Start pattern with press_duration = 2500ms\n"); tst_step = SH_PRESS; TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(2500); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait pattern detection */ SRV_WAIT((!tst_short), 2000); /* wait 3s */ local_task_sleep_ms(3000); cu_print("Start pattern with press_duration = 4000ms\n"); tst_step = SINGLE_PRESS; TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(4000); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait pattern detection */ SRV_WAIT((!tst_single), 2000); /* wait 3s */ local_task_sleep_ms(3000); cu_print("Start pattern with press_duration = 7000ms\n"); tst_step = L_PRESS; TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(7000); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait pattern detection */ SRV_WAIT((!tst_long), 2000); /* wait 3s */ local_task_sleep_ms(3000); cu_print("Start pattern with press_duration = 12000ms\n"); tst_step = VERY_L_PRESS; TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(12000); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait 3s */ local_task_sleep_ms(3000); /* Start failed double press pattern : very_short_press + 550 ms delay max + short_press */ cu_print("Start double pattern press failed...\n"); tst_step = DBLE_PRESS_FAIL_1; TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(700); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait pattern detection */ SRV_WAIT((!tst_double_fail_1), 2000); /* wait between the very short press */ local_task_sleep_ms(550); tst_step = DBLE_PRESS_FAIL_2; TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(2700); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait pattern detection */ SRV_WAIT((!tst_double_fail_2), 2000); /* wait 3s */ local_task_sleep_ms(3000); cu_print("Start too short pattern with duration = 300ms\n"); tst_step = TOO_SHORT_PRESS; TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(300); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait pattern detection */ SRV_WAIT((!tst_double_fail_2), 2000); /* wait 3s */ local_task_sleep_ms(3000); /* Start double press pattern : very_short_press + 350 ms delay max + very_short_press */ cu_print("Start double pattern press...\n"); tst_step = DBLE_PRESS; TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(700); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait between the very short press */ local_task_sleep_ms(350); TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(900); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait pattern detection */ SRV_WAIT((!tst_double), 2000); /* wait 2s */ local_task_sleep_ms(2000); cfw_close_service_conn(gpio_service_conn, NULL); return DRV_RC_OK; }