Ejemplo n.º 1
0
static void dump_data(uint8_t * data, int len)
{
    int i;
    for (i=0; i < len ; i++) {
        if (i%8 == 0) cu_print("\n");
        cu_print("%x ", data[i]);
    }
    cu_print("\n");
}
Ejemplo n.º 2
0
/**
 * Callback function for gpio service response
 */
void pwrbtn_tst_handle_msg(struct cfw_message *msg, void *data)
{
	switch (CFW_MESSAGE_ID(msg)) {
	case MSG_ID_CFW_OPEN_SERVICE_RSP:
		*((cfw_service_conn_t **)(msg->priv)) =
			(cfw_service_conn_t *)((cfw_open_conn_rsp_msg_t *)msg)
			->
			service_conn;
		cu_print("TST_PWRBTN service opened \n");
		break;
	case MSG_ID_GPIO_SERVICE_CONFIGURE_RSP:
		cu_print("TST_PWRBTN %s state=%d\n", msg->priv,
			 ((gpio_service_configure_rsp_msg_t *)msg)->status);
		tst_pwrbtn_configure = 1;
		break;
	case MSG_ID_GPIO_SERVICE_SET_STATE_RSP:
		tst_pwrbtn_set_state = 1;
		cu_print("TST_PWRBTN %s: state=%d\n", msg->priv,
			 ((gpio_service_set_state_rsp_msg_t *)msg)->status);
		break;
	case MSG_ID_GPIO_SERVICE_GET_STATE_RSP:
		tst_pwrbtn_get_state = 1;
		tst_pwrbtn_get_value =
			((gpio_service_get_state_rsp_msg_t *)msg)->state;
		cu_print("TST_PWRBTN %s: state=%d, pin=0x%x\n", msg->priv,
			 ((gpio_service_set_state_rsp_msg_t *)msg)->status,
			 ((gpio_service_get_state_rsp_msg_t *)msg)->state);
	case MSG_ID_GPIO_SERVICE_GET_BANK_STATE_RSP:
		tst_pwrbtn_get_bank_state = 1;
		tst_pwrbtn_get_bank_value =
			((gpio_service_get_bank_state_rsp_msg_t *)msg)->state;
		cu_print("TST_PWRBTN %s: state=%d, pin=0x%x\n", msg->priv,
			 ((gpio_service_set_state_rsp_msg_t *)msg)->status,
			 ((gpio_service_get_bank_state_rsp_msg_t *)msg)->state);
		break;
	case MSG_ID_GPIO_SERVICE_LISTEN_RSP:
		tst_pwrbtn_listen = 1;
		cu_print("TST_PWRBTN %s: state=%d, pin=%d\n", msg->priv,
			 ((gpio_service_listen_rsp_msg_t *)msg)->status,
			 ((gpio_service_listen_rsp_msg_t *)msg)->index);
		break;
	case MSG_ID_GPIO_SERVICE_UNLISTEN_RSP:
		tst_pwrbtn_unlisten = 1;
		cu_print("TST_PWRBTN %s: state=%d, pin=%d\n", msg->priv,
			 ((gpio_service_unlisten_rsp_msg_t *)msg)->status,
			 ((gpio_service_listen_rsp_msg_t *)msg)->index);
		break;
	case MSG_ID_GPIO_SERVICE_EVT:
		tst_pwrbtn_event = 1;
		cu_print("TST_PWRBTN EVT %s: state=%d, pin=%d\n", msg->priv,
			 ((gpio_service_listen_evt_msg_t *)msg)->pin_state,
			 ((gpio_service_listen_evt_msg_t *)msg)->index);
		break;
	default:
		cu_print("default cfw handler\n");
		break;
	}
	cfw_msg_free(msg);
}
Ejemplo n.º 3
0
void generic_gpio_srv_test(uint8_t service_id, uint8_t inputPin, uint8_t outputPin, char* portLabel)
{
    DRIVER_API_RC ret;
    char* outputString = balloc(55, NULL) ;
    char* border = "##################################################\n";
    cfw_client_t * gpio_client = cfw_client_init(get_test_queue(), gpio_tst_handle_msg, NULL);

    ret = tst_gpio_srv_test_single_edge(gpio_client, service_id, inputPin, outputPin);
    sprintf(outputString, "Test for %s gpio single edge", portLabel);
    CU_ASSERT(outputString , ret == DRV_RC_OK);
    if(ret == DRV_RC_OK)
    {
        cu_print("%s", border);
        cu_print("#       Test GPIO %s gpio single edge OK        #\n", portLabel);
        cu_print("%s", border);
    }

    ret = tst_gpio_srv_test_double_edge(gpio_client, service_id, inputPin, outputPin);
    sprintf(outputString, "Test for %s gpio double edge", portLabel);
    CU_ASSERT(outputString, ret == DRV_RC_OK);
    if(ret == DRV_RC_OK)
    {
        cu_print("%s", border);
        cu_print("#       Test GPIO %s gpio double edge OK         #\n", portLabel);
        cu_print("%s", border);
    }
}
Ejemplo n.º 4
0
void gpio_aon_test(void)
{
    uint8_t init_tst_input_pin_mode = GET_PIN_MODE(TST_SOC_AON_INPUT_PIN);
    uint8_t init_tst_output_pin_mode = GET_PIN_MODE(TST_SOC_AON_OUTPUT_PIN);

    cu_print("##################################################\n");
    cu_print("#                                                #\n");
    cu_print("#    !!! Pins %d and %d must be connected !!!      #\n", TST_SOC_AON_INPUT_PIN, TST_SOC_AON_OUTPUT_PIN);
    cu_print("#                                                #\n");
    cu_print("#  Purpose of aon GPIOs tests on port %d:         #\n", TST_SOC_AON_PORT);
    cu_print("#            Validate input/output ports         #\n");
    cu_print("#            Validate interrupts (edge low)      #\n");
    cu_print("#            Validate interrupts (edge high)     #\n");
    cu_print("#            Validate interrupts (double edge)   #\n");
    cu_print("##################################################\n");

    DRIVER_API_RC ret;
    struct device *aon_dev = &pf_device_soc_gpio_aon;

    /* Change Pin Mode of pin 5 and 6 to be as GPIO */
    SET_PIN_MODE(TST_SOC_AON_INPUT_PIN, QRK_PMUX_SEL_MODEA);
    SET_PIN_MODE(TST_SOC_AON_OUTPUT_PIN, QRK_PMUX_SEL_MODEA);

    ret = soc_gpio_test_pin(aon_dev, TST_SOC_AON_INPUT_PIN, TST_SOC_AON_OUTPUT_PIN);
    CU_ASSERT("Test for gpio pin failed", ret == DRV_RC_OK);

    ret = soc_gpio_test_port(aon_dev, TST_SOC_AON_INPUT_PIN, TST_SOC_AON_OUTPUT_PIN);
    CU_ASSERT("Test for gpio port failed", ret == DRV_RC_OK);

    ret = soc_gpio_test_pin_int(aon_dev, TST_SOC_AON_INPUT_PIN, TST_SOC_AON_OUTPUT_PIN);
    CU_ASSERT("Test for gpio pin interrupt failed", ret == DRV_RC_OK);

    ret = soc_gpio_test_port_int(aon_dev, TST_SOC_AON_INPUT_PIN, TST_SOC_AON_OUTPUT_PIN);
    CU_ASSERT("Test for gpio port interrupt failed", ret == DRV_RC_OK);

    /* Restore default configuration for AON pins */
    SET_PIN_MODE(TST_SOC_AON_INPUT_PIN, init_tst_input_pin_mode);
    SET_PIN_MODE(TST_SOC_AON_OUTPUT_PIN, init_tst_output_pin_mode);
}
Ejemplo n.º 5
0
void spi_read_reg(SPI_CONTROLLER spi_controller, uint8_t reg, uint8_t expected_val)
{
    DRIVER_API_RC ret = DRV_RC_OK;
    uint8_t read_data = 0;

    reset_callback();

    ret = ss_spi_transfer(spi_controller, &reg, 1, &read_data , 1, spi_cfg.slave_enable);
    CU_ASSERT ("SPI read failure", ret == DRV_RC_OK);
    wait_xfer_or_err();
#ifdef DEBUG
    cu_print("read value %x expected value %x\n", read_data, expected_val);
#endif
    CU_ASSERT ("SPI expected value differs from the read value", expected_val == read_data);
}
Ejemplo n.º 6
0
void read_block_spi(SPI_CONTROLLER spi_controller)
{
    uint8_t read_buffer[HUM_LSB - CALLIB_0] = {0xff};
    DRIVER_API_RC ret = 0;
    //uint32_t idx;
    cu_print("read block 2 : %d bytes\n", sizeof(read_buffer));
    reset_callback();
    ret = ss_spi_transfer(spi_controller, 0, 0, read_buffer, \
                          sizeof(read_buffer), spi_cfg.slave_enable);
    wait_xfer_or_err();
    CU_ASSERT("Sending block bytes TX buffer failed\n", (ret == DRV_RC_OK));
#ifdef DEBUG
    dump_data(read_buffer, sizeof(read_buffer));
#endif
}
Ejemplo n.º 7
0
/**
 * \fn void gpio_tst_handle_msg(struct cfw_message * msg, void * data)
 *
 * \brief Callback function for gpio service test
 */
void gpio_tst_handle_msg(struct cfw_message * msg, void * data)
{
    switch (CFW_MESSAGE_ID(msg)) {
    case MSG_ID_CFW_OPEN_SERVICE_RSP:
        *((cfw_service_conn_t **)(msg->priv))  = (cfw_service_conn_t *)((cfw_open_conn_rsp_msg_t*)msg)->service_conn;
        cu_print("TST_GPIO open\n");
        break;
    case MSG_ID_GPIO_CONFIGURE_RSP:
        cu_print("TST_GPIO %s state=%d\n", msg->priv, ((gpio_configure_rsp_msg_t*)msg)->rsp_header.status);
        tst_gpio_configure = 1;
        break;
    case MSG_ID_GPIO_SET_RSP:
        tst_gpio_set_state = 1;
        cu_print("TST_GPIO %s: state=%d\n", msg->priv, ((gpio_set_rsp_msg_t*)msg)->rsp_header.status);
        break;
    case MSG_ID_GPIO_GET_RSP:
        tst_gpio_get_state = 1;
        tst_gpio_get_value = ((gpio_get_rsp_msg_t*)msg)->state;
        cu_print("TST_GPIO %s: state=%d, pin=0x%x\n", msg->priv,
                                            ((gpio_set_rsp_msg_t*)msg)->rsp_header.status,
                                            ((gpio_get_rsp_msg_t*)msg)->state);
        break;
    case MSG_ID_GPIO_LISTEN_RSP:
        tst_gpio_listen = 1;
        cu_print("TST_GPIO %s: state=%d, pin=%d\n", msg->priv,((gpio_listen_rsp_msg_t*)msg)->rsp_header.status,
                ((gpio_listen_rsp_msg_t*)msg)->index);
        break;
    case MSG_ID_GPIO_UNLISTEN_RSP:
        tst_gpio_unlisten = 1;
        cu_print("TST_GPIO %s: state=%d, pin=%d\n", msg->priv,((gpio_unlisten_rsp_msg_t*)msg)->rsp_header.status,
                ((gpio_listen_rsp_msg_t*)msg)->index);
        break;
    case MSG_ID_GPIO_EVT:
        tst_gpio_event = 1;
        cu_print("TST_GPIO EVT %s: state=%d, pin=%d\n", msg->priv,((gpio_listen_evt_msg_t*)msg)->pin_state,
                ((gpio_listen_evt_msg_t*)msg)->index);
        break;
    default:
        cu_print("default cfw handler\n");
        break;
    }
    cfw_msg_free(msg);
}
Ejemplo n.º 8
0
void transfer_block_spi(SPI_CONTROLLER spi_controller)
{
    uint8_t write_buffer[1] = {CALLIB_0};
    uint8_t read_buffer[HUM_LSB - CALLIB_0] = {0};
    DRIVER_API_RC ret = 0;
    //uint32_t idx;
    cu_print("read %d bytes\n", sizeof(read_buffer));
    reset_callback();
    ret = ss_spi_transfer(spi_controller, write_buffer, 1, read_buffer, \
                          sizeof(read_buffer), spi_cfg.slave_enable);
    CU_ASSERT("Sending block bytes TX buffer failed\n", (ret == DRV_RC_OK));
    wait_xfer_or_err();
#ifdef DEBUG
    dump_data(read_buffer, sizeof(read_buffer));
#endif
    CU_ASSERT("ss spi written value differs from the read value", read_buffer[CTRL_MEAS - CALLIB_0] == 0x04);
    CU_ASSERT("ss spi written value differs from the read value", read_buffer[CONFIG - CALLIB_0] == 0x40);
}
Ejemplo n.º 9
0
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");
}
Ejemplo n.º 10
0
DRIVER_API_RC tst_gpio_srv_test_single_edge(cfw_client_t *gpio_client, unsigned int service_id, unsigned int input_pin, unsigned int output_pin)
{
    cfw_service_conn_t *gpio_service_conn = NULL;

    if (!cfw_service_registered(service_id)) {
        cu_print("soc gpio register failed\n");
        return DRV_RC_FAIL;
    }

    cfw_open_service_conn(gpio_client, service_id, &gpio_service_conn);
    SRV_WAIT((!gpio_service_conn), 1000);
    CU_ASSERT("TST_GPIO open service failed", (gpio_service_conn));
    if(gpio_service_conn == NULL) {
        return DRV_RC_FAIL;
    }

    TEST_GPIO(configure, "TST_GPIO config failed", gpio_service_conn, output_pin, 1, "cfg_output single edge");

    // ********************************
    // *      Test rising edge        *
    // ********************************
    TEST_GPIO(set_state, "TST_GPIO set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1 re");
    TEST_GPIO(listen, "TST_GPIO listen failed (re)", gpio_service_conn, input_pin, RISING_EDGE, DEB_OFF, "listen re");

    tst_gpio_event = 0;
    TEST_GPIO(set_state, "TST_GPIO set 2 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0 re");
    // Check no event
    CU_ASSERT("TST_GPIO RE irq wrong detected", (tst_gpio_event == 0));
    if(tst_gpio_event) {
        return DRV_RC_FAIL;
    }
    // Check GPIO port value
    TEST_GPIO(get_state, "TST_GPIO get 1 failed (re)", gpio_service_conn, "get_output 1 re");
    CU_ASSERT("TST_GPIO RE wrong port state detected (should be LOW)", (!(tst_gpio_get_value & (1<<input_pin))));
    if(tst_gpio_get_value & (1<<input_pin)) {
        return DRV_RC_FAIL;
    }

    TEST_GPIO(set_state, "TST_GPIO set 3 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1 re");
    // Check event
    CU_ASSERT("TST_GPIO RE irq RE not detected", (tst_gpio_event == 1));
    if(tst_gpio_event != 1) {
        return DRV_RC_FAIL;
    }
    // Check GPIO port value
    TEST_GPIO(get_state, "TST_GPIO get 2 failed (re)", gpio_service_conn, "get_output 2 re");
    CU_ASSERT("TST_GPIO RE wrong port state detected (should be HIGH)", (tst_gpio_get_value & (1<<input_pin)));
    if(!(tst_gpio_get_value & (1<<input_pin))) {
        return DRV_RC_FAIL;
    }

    TEST_GPIO(unlisten, "TST_GPIO unlisten failed (re)", gpio_service_conn, input_pin, "unlisten re");

    // ********************************
    // *      Test falling edge       *
    // ********************************
    TEST_GPIO(set_state, "TST_GPIO set 1 failed (fe)", gpio_service_conn, output_pin, 0, "set_output 1 fe");
    TEST_GPIO(listen, "TST_GPIO listen failed (fe)", gpio_service_conn, input_pin, FALLING_EDGE, DEB_OFF, "listen fe");
    tst_gpio_event = 0;
    // Check no event
    TEST_GPIO(set_state, "TST_GPIO set 2 failed (fe)", gpio_service_conn, output_pin, 1, "set_output 0 fe");
    CU_ASSERT("TST_GPIO FE irq wrong detected", (tst_gpio_event == 0));
    if(tst_gpio_event) {
        return DRV_RC_FAIL;
    }
    // Check GPIO port value
    TEST_GPIO(get_state, "TST_GPIO get 1 failed (fe)", gpio_service_conn, "get_output 1 fe");
    CU_ASSERT("TST_GPIO FE wrong port state detected (should be HIGH)", (tst_gpio_get_value & (1<<input_pin)));
    if(!(tst_gpio_get_value & (1<<input_pin))) {
        return DRV_RC_FAIL;
    }

    // Check event
    TEST_GPIO(set_state, "TST_GPIO set 3 failed (fe)", gpio_service_conn, output_pin, 0, "set_output 1 fe");
    CU_ASSERT("TST_GPIO FE irq not detected", (tst_gpio_event == 1));
    if(tst_gpio_event != 1) {
        return DRV_RC_FAIL;
    }
    // Check GPIO port value
    TEST_GPIO(get_state, "TST_GPIO get 2 failed (fe)", gpio_service_conn, "get_output 2 fe");
    CU_ASSERT("TST_GPIO FE wrong port state detected (should be LOW)", (!(tst_gpio_get_value & (1<<input_pin))));
    if(tst_gpio_get_value & (1<<input_pin)) {
        return DRV_RC_FAIL;
    }

    TEST_GPIO(unlisten, "TST_GPIO unlisten failed (fe)", gpio_service_conn, input_pin, "unlisten fe");

    // Deconfigure output pin
    TEST_GPIO(set_state, "TST_GPIO set deconfig failed", gpio_service_conn, output_pin, 0, "set_output 0");
    TEST_GPIO(configure, "TST_GPIO end config failed", gpio_service_conn, output_pin, 0, "cfg_input single edge");

    cu_print("GPIO single edge test done\n");
    return DRV_RC_OK;
}
Ejemplo n.º 11
0
/*
 * \brief Stub that replaces the panic function for testing purpose
 */
void panic (int err)
{
    cu_print("** PANIC - test stub  - %d **\n", err);
    g_Panic = true ;
}
Ejemplo n.º 12
0
void properties_storage_test(void)
{
	cu_print(
		"##############################################################\n");
	cu_print(
		"# Properties_storage test                                    #\n");
	cu_print(
		"##############################################################\n");

	properties_storage_format_all();

	const uint8_t *data = "Random Test Data";
	const uint8_t *data2 = "132456789";
	uint8_t rdata[PROPERTIES_STORAGE_MAX_VALUE_LEN + 50];
	uint16_t readlen;
	properties_storage_status_t ret;

	/* Read from empty storage */
	ret = properties_storage_get(42, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Key correctly not found",
		  ret == PROPERTIES_STORAGE_KEY_NOT_FOUND_ERROR);

	/* Basic read write test, non persistent */
	ret = properties_storage_set(42, data, 8, false);
	CU_ASSERT("Write OK", ret == PROPERTIES_STORAGE_SUCCESS);
	ret = properties_storage_get(42, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Read OK", ret == PROPERTIES_STORAGE_SUCCESS);
	CU_ASSERT("Read Length OK", readlen == 8);
	CU_ASSERT("Read content correct", strncmp(data, rdata, 8) == 0);

	ret = properties_storage_set(66, data, 13, false);
	CU_ASSERT("Write OK", ret == PROPERTIES_STORAGE_SUCCESS);
	ret = properties_storage_get(66, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Read OK", ret == PROPERTIES_STORAGE_SUCCESS);
	CU_ASSERT("Read Length OK", readlen == 13);
	CU_ASSERT("Read content correct", strncmp(data, rdata, 13) == 0);

	/* Check integrity of previous entry */
	ret = properties_storage_get(42, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Read OK", ret == PROPERTIES_STORAGE_SUCCESS);
	CU_ASSERT("Read Length OK", readlen == 8);
	CU_ASSERT("Read content correct", strncmp(data, rdata, 8) == 0);

	/* Overwrite value of property 42 */
	ret = properties_storage_set(42, data2, 3, false);
	CU_ASSERT("Write OK", ret == PROPERTIES_STORAGE_SUCCESS);
	ret = properties_storage_get(42, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Read OK", ret == PROPERTIES_STORAGE_SUCCESS);
	CU_ASSERT("Read Length OK", readlen == 3);
	CU_ASSERT("Read content correct", strncmp(data2, rdata, 3) == 0);

	/* Fill the partition with a lot of values so that we switch to a new block */
	for (int i = 0; i < 2048 / 13 + 15; ++i) {
		ret = properties_storage_set(42, data, 13, false);
		CU_ASSERT("Write OK", ret == PROPERTIES_STORAGE_SUCCESS);
	}
	ret = properties_storage_get(42, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Read OK", ret == PROPERTIES_STORAGE_SUCCESS);
	CU_ASSERT("Read Length OK", readlen == 13);
	CU_ASSERT("Read content correct", strncmp(data, rdata, 13) == 0);

	/* Fill the partition even more so that we need to clear a previous block */
	for (int i = 0; i < 3 * 2048 / 13 + 15; ++i) {
		ret = properties_storage_set(42, data, 13, false);
		CU_ASSERT("Write OK", ret == PROPERTIES_STORAGE_SUCCESS);
	}
	ret = properties_storage_get(42, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Read OK", ret == PROPERTIES_STORAGE_SUCCESS);
	CU_ASSERT("Read Length OK", readlen == 13);
	CU_ASSERT("Read content correct", strncmp(data, rdata, 13) == 0);

	ret = properties_storage_get(66, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Read OK", ret == PROPERTIES_STORAGE_SUCCESS);
	CU_ASSERT("Read Length OK", readlen == 13);
	CU_ASSERT("Read content correct", strncmp(data, rdata, 13) == 0);

	/* Reinit the storage to validate that we correctly end up with the same
	 * items */
	properties_storage_init();
	ret = properties_storage_get(42, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Read OK", ret == PROPERTIES_STORAGE_SUCCESS);
	CU_ASSERT("Read Length OK", readlen == 13);
	CU_ASSERT("Read content correct", strncmp(data, rdata, 13) == 0);

	ret = properties_storage_get(66, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Read OK", ret == PROPERTIES_STORAGE_SUCCESS);
	CU_ASSERT("Read Length OK", readlen == 13);
	CU_ASSERT("Read content correct", strncmp(data, rdata, 13) == 0);

	properties_storage_format_all();

	uint8_t large_buf[PROPERTIES_STORAGE_MAX_VALUE_LEN + 50];
	for (int i = 0; i < sizeof(large_buf); ++i)
		large_buf[i] = i % 50 + 'a';

	ret = properties_storage_set(42, data2, 3, false);
	CU_ASSERT("Write OK", ret == PROPERTIES_STORAGE_SUCCESS);
	ret = properties_storage_get(42, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Read OK", ret == PROPERTIES_STORAGE_SUCCESS);
	CU_ASSERT("Read Length OK", readlen == 3);
	CU_ASSERT("Read content correct", strncmp(data2, rdata, 3) == 0);

	/* Write a property with maximum property size */
	ret =
		properties_storage_set(42, large_buf,
				       PROPERTIES_STORAGE_MAX_VALUE_LEN,
				       false);
	CU_ASSERT("Write OK", ret == PROPERTIES_STORAGE_SUCCESS);
	ret = properties_storage_get(42, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Read OK", ret == PROPERTIES_STORAGE_SUCCESS);
	CU_ASSERT("Read Length OK", readlen == PROPERTIES_STORAGE_MAX_VALUE_LEN);
	CU_ASSERT("Read content correct",
		  strncmp(large_buf, rdata,
			  PROPERTIES_STORAGE_MAX_VALUE_LEN) == 0);

	/* Check error when property is larger than maximum property size */
	ret =
		properties_storage_set(42, large_buf,
				       PROPERTIES_STORAGE_MAX_VALUE_LEN +
				       1,
				       false);
	CU_ASSERT("Write NOK", ret == PROPERTIES_STORAGE_INVALID_ARG);

	/* Fill a block with only different properties (not deprecated data) */
	for (int i = 0; i < 2048 / PROPERTIES_STORAGE_MAX_VALUE_LEN + 1; ++i) {
		ret =
			properties_storage_set(i, large_buf,
					       PROPERTIES_STORAGE_MAX_VALUE_LEN,
					       false);
		CU_ASSERT("Write OK", ret == PROPERTIES_STORAGE_SUCCESS);
	}

	/* Then make sure the partition is fully written causing block shifts */
	for (int i = 0; i < 3 * 2048 / 13 + 15; ++i) {
		ret = properties_storage_set(999999, data, 13, false);
		CU_ASSERT("Write OK", ret == PROPERTIES_STORAGE_SUCCESS);
	}

	for (int i = 0; i < 2048 / PROPERTIES_STORAGE_MAX_VALUE_LEN + 1; ++i) {
		ret = properties_storage_get(i, rdata, sizeof(rdata), &readlen);
		CU_ASSERT("Read OK", ret == PROPERTIES_STORAGE_SUCCESS);
		CU_ASSERT("Read Length OK",
			  readlen == PROPERTIES_STORAGE_MAX_VALUE_LEN);
		CU_ASSERT("Read content correct",
			  strncmp(large_buf, rdata,
				  PROPERTIES_STORAGE_MAX_VALUE_LEN) == 0);
	}

	/* Test property delete */
	ret = properties_storage_delete(999999);
	CU_ASSERT("Delete OK", ret == PROPERTIES_STORAGE_SUCCESS);
	ret = properties_storage_get(999999, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Get NOK", ret == PROPERTIES_STORAGE_KEY_NOT_FOUND_ERROR);

	ret = properties_storage_delete(42);
	CU_ASSERT("Delete OK", ret == PROPERTIES_STORAGE_SUCCESS);
	ret = properties_storage_get(42, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Get NOK", ret == PROPERTIES_STORAGE_KEY_NOT_FOUND_ERROR);
	for (int i = 0; i < 2048 / PROPERTIES_STORAGE_MAX_VALUE_LEN + 1; ++i) {
		ret = properties_storage_delete(i);
		CU_ASSERT("Delete OK", ret == PROPERTIES_STORAGE_SUCCESS);
		ret = properties_storage_get(i, rdata, sizeof(rdata), &readlen);
		CU_ASSERT("Get NOK",
			  ret == PROPERTIES_STORAGE_KEY_NOT_FOUND_ERROR);
	}

	/* Re-write a property after deleting many */
	ret =
		properties_storage_set(42, large_buf,
				       PROPERTIES_STORAGE_MAX_VALUE_LEN,
				       false);
	CU_ASSERT("Write OK", ret == PROPERTIES_STORAGE_SUCCESS);
	ret = properties_storage_get(42, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Read OK", ret == PROPERTIES_STORAGE_SUCCESS);
	CU_ASSERT("Read Length OK", readlen == PROPERTIES_STORAGE_MAX_VALUE_LEN);
	CU_ASSERT("Read content correct",
		  strncmp(large_buf, rdata,
			  PROPERTIES_STORAGE_MAX_VALUE_LEN) == 0);

	/* Basic read write test, persistent */
	ret = properties_storage_set(142, data, 8, true);
	CU_ASSERT("Write OK", ret == PROPERTIES_STORAGE_SUCCESS);
	ret = properties_storage_get(142, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Read OK", ret == PROPERTIES_STORAGE_SUCCESS);
	CU_ASSERT("Read Length OK", readlen == 8);
	CU_ASSERT("Read content correct", strncmp(data, rdata, 8) == 0);

	ret = properties_storage_set(166, data, 13, true);
	CU_ASSERT("Write OK", ret == PROPERTIES_STORAGE_SUCCESS);
	ret = properties_storage_get(166, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Read OK", ret == PROPERTIES_STORAGE_SUCCESS);
	CU_ASSERT("Read Length OK", readlen == 13);
	CU_ASSERT("Read content correct", strncmp(data, rdata, 13) == 0);

	/* Check integrity of previous entry */
	ret = properties_storage_get(142, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Read OK", ret == PROPERTIES_STORAGE_SUCCESS);
	CU_ASSERT("Read Length OK", readlen == 8);
	CU_ASSERT("Read content correct", strncmp(data, rdata, 8) == 0);

	/* Overwrite value of property 42 */
	ret = properties_storage_set(142, data2, 3, true);
	CU_ASSERT("Write OK", ret == PROPERTIES_STORAGE_SUCCESS);
	ret = properties_storage_get(142, rdata, sizeof(rdata), &readlen);
	CU_ASSERT("Read OK", ret == PROPERTIES_STORAGE_SUCCESS);
	CU_ASSERT("Read Length OK", readlen == 3);
	CU_ASSERT("Read content correct", strncmp(data2, rdata, 3) == 0);

	properties_storage_format_all();

	/* Check the behaviour when the maximum number of properties is reached */
	for (int i = 0; i < PROPERTIES_STORAGE_MAX_NB_PROPERTIES; ++i) {
		ret = properties_storage_set(i, data, 13, false);
		CU_ASSERT("Write OK", ret == PROPERTIES_STORAGE_SUCCESS);
	}

	ret = properties_storage_set(999999, data, 13, false);
	CU_ASSERT("Write NOK", ret == PROPERTIES_STORAGE_BOUNDS_ERROR);

	/* Format the partition: later unit tests rely on it being not full.. */
	properties_storage_format_all();
}
Ejemplo n.º 13
0
void ss_unit_spi(void)
{

    cu_print("#######################################\n");
    cu_print("# Purpose of SS SPI tests :           #\n");
    cu_print("#     BME280 is connected to ss spi0  #\n");
    cu_print("#     1 - Read BME280 ID              #\n");
    cu_print("#     2 - Write BME280 registers      #\n");
    cu_print("#######################################\n");

    init_spi((struct sba_master_cfg_data*)(pf_bus_sba_ss_spi_0.priv),
	     SPI_SE_1, SPI_BUSMODE_0, 0);
    cu_print("read register\n");
    spi_read_reg(SPI_SENSING_0, ID_REG, 0x60);

    cu_print("write register\n");
    spi_write_reg(SPI_SENSING_0, CTRL_MEAS, 0x08);
    spi_read_reg(SPI_SENSING_0, CTRL_MEAS, 0x08);

    cu_print("write word register\n");
    spi_write_word_reg(SPI_SENSING_0, CTRL_MEAS, 0x4004);

    cu_print("read word register\n");
    spi_read_word_reg(SPI_SENSING_0, CTRL_MEAS, 0x4004);

    cu_print("read block\n");
    transfer_block_spi(SPI_SENSING_0);

    ss_spi_deconfig((struct sba_master_cfg_data*)(pf_bus_sba_ss_spi_0.priv));
}
Ejemplo n.º 14
0
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;
}
Ejemplo n.º 15
0
void pwrbtn_notify_callback(btn_press_pattern event, int duration)
{
	switch (tst_step) {
	case VERY_SH_PRESS:
		CU_ASSERT("Bad event identification received",
			  event == ONCE_PRESSED);
		CU_ASSERT("Duration is wrong",
			  ((duration < 800) && (duration > 700)));
		tst_very_short = 1;
		cu_print("PATTERN SINGLE PRESS RECEIVED\n");
		break;
	case SH_PRESS:
		CU_ASSERT("Bad event identification received",
			  event == ONCE_PRESSED);
		CU_ASSERT("Duration for SHORT PRESS is wrong",
			  ((duration < 2600) && (duration > 2500)));
		tst_short = 1;
		cu_print("PATTERN SINGLE PRESS RECEIVED\n");
		break;
	case SINGLE_PRESS:
		CU_ASSERT("Bad event identification received",
			  event == ONCE_PRESSED);
		CU_ASSERT("Duration is wrong",
			  ((duration < 4100) && (duration > 4000)));
		tst_single = 1;
		cu_print("PATTERN SINGLE PRESS RECEIVED\n");
		break;
	case L_PRESS:
		CU_ASSERT("Bad event identification received",
			  event == ONCE_PRESSED);
		CU_ASSERT("Duration is wrong",
			  ((duration < 7100) && (duration > 7000)));
		tst_long = 1;
		cu_print("PATTERN SINGLE PRESS RECEIVED\n");
		break;
	case VERY_L_PRESS:
		/* Should not receive pattern with duration = 12000ms */
		tst_very_long = 1;
		break;
	case DBLE_PRESS:
		CU_ASSERT("Bad event identification received",
			  event == TWICE_PRESSED);
		CU_ASSERT("Duration  is wrong",
			  ((duration < 800) && (duration > 700)));
		tst_double = 1;
		cu_print("PATTERN DOUBLE PRESS RECEIVED\n");
		break;
	case DBLE_PRESS_FAIL_1:
		CU_ASSERT("Bad event identification received",
			  event == ONCE_PRESSED);
		CU_ASSERT("Duration is wrong",
			  ((duration < 800) && (duration > 700)));
		tst_double_fail_1 = 1;
		cu_print("PATTERN SINGLE PRESS RECEIVED\n");
		break;
	case DBLE_PRESS_FAIL_2:
		CU_ASSERT("Bad event identification received",
			  event == ONCE_PRESSED);
		CU_ASSERT("Duration is wrong",
			  ((duration < 2800) && (duration > 2700)));
		tst_double_fail_2 = 1;
		cu_print("PATTERN SINGLE PRESS RECEIVED\n");
		break;
	case TOO_SHORT_PRESS:
		/* Should not receive pattern with duration = 300ms */
		tst_too_short = 1;
		break;
	default:
		CU_ASSERT("Test step invalid", tst_step > 9);
	}
}
Ejemplo n.º 16
0
/* This test is really buggy, it relies on specific pool alignment and
 * on a specific memory_pool_list.def file */
void test_malloc_and_free_2(void)
{
	uint8_t *p;
	static uint8_t *ptr[NB_OF_MEMORY_POOL] = { 0 };
	static uint32_t count[NB_OF_MEMORY_POOL] = { 0 };
	static uint32_t size[NB_OF_MEMORY_POOL] = { 0 };  /* element/block size */
	OS_ERR_TYPE err = E_OS_OK;
	uint8_t i, j, k, idx;
	uint32_t index = 0;

	cu_print("NB_OF_MEMORY_POOL %d\n", NB_OF_MEMORY_POOL);

	/* run the test twice */
	for (k = 0; k < 2; k++) {
		uint32_t previous_max_size = 0xFFFFFFFF;

		/* for each pool allocate all the memory by starting by the largest pool and set a pattern */
		for (i = 0; i < NB_OF_MEMORY_POOL; i++) {
			uint32_t max_size = 0;
			uint32_t not_allocated = 0;

			/* sort the pool from the largest to the smallest one */
			for (j = 0; j < NB_OF_MEMORY_POOL; j++) {
				if (all_pools[j].size > max_size &&
				    all_pools[j].size < previous_max_size) {
					max_size = all_pools[j].size;
					index = j;
					size[i] = all_pools[j].size;
				}
			}
			previous_max_size = max_size;

			/* allocate all the memory for this pool */
			for (j = 0; j < all_pools[index].nb_elem; j++) {
				p = balloc(all_pools[index].size, &err);
				if (p) {
					cu_print("allocated %d bytes addr %x\n",
						 all_pools[index].size,
						 p);
					ptr[i] = p;
					count[i]++;
					CU_ASSERT("no error returned.",
						  err == E_OS_OK);

					/* fill the block */
					for (idx = 0;
					     idx < all_pools[index].size;
					     idx++) {
						/* write pattern */
						p[idx] =
							(uint8_t)(0xFF &
								  (((uint32_t)(
									    p +
									    idx))
								   + idx));
					}
				} else {
					not_allocated++;
					CU_ASSERT("no error returned.",
						  err == E_OS_ERR_NO_MEMORY);
				}
			}

			CU_ASSERT(
				"check number of allocated blocks are correct",
				all_pools[index].nb_elem ==
				(count[i] + not_allocated));
			p = ptr[i];
		}

		/* free each pool */
		for (i = 0; i < NB_OF_MEMORY_POOL; i++) {
			p = ptr[i];
			/* verify each block */
			for (j = 0; j < count[i]; j++) {
				for (idx = 0; idx < size[i]; idx++) {
					CU_ASSERT("verif data", (*(p + idx)) ==
						  (uint8_t)(((0xFF) &
							     (((uint32_t)(p +
									  idx))
							      + idx))));                                                      /* check pattern */
					p[idx] = 0; /* clear memory data */
				}
				p -= size[i]; /* go to next block/element */
			}

			/* free all the memory */
			do {
				err = bfree(ptr[i]);
				if (err == E_OS_OK) {
					count[i]--;
					ptr[i] -= size[i];
				}
			} while (err == E_OS_OK && count[i] != 0);

			CU_ASSERT("free fail", count[i] == 0);
		}
	}
}
Ejemplo n.º 17
0
void lib_math_test()
{
	cu_print("##############################################################\n");
	cu_print("# Purpose of the lib math test:                               #\n");
	cu_print("# Check that all implemented functions in math.h return the   #\n");
	cu_print("# right results for a set of input values                     #\n");
	cu_print("##############################################################\n");

	int i;
	float input, result;

	/* arccos */
	for (i = 0; i <= 10; i++)
	{
		input = -1 + i * 0.2;
		result = acos(input);
		CU_ASSERT("acos", resultcheck(result, acos_table[i]));
	}

	/* arcsin */
	for (i = 0; i <= 10; i++)
	{
		input = -1 + i * 0.2;
		result = asin(input);
		CU_ASSERT("asin", resultcheck(result, asin_table[i]));
	}

	/* arctan */
	for (i = 0; i <= 10; i++)
	{
		input = -100 + i * 20;
		result = atan(input);
		CU_ASSERT("atan", resultcheck(result, atan_table[i]));
	}

	float input2;
	int j;
	/* arctan2 */
	for (i = 0; i <= 6; i++)
	{
		input = -90 + i * 30;
		for (j = 0; j <= 6; j++)
		{
			if (i == 3 && j == 3)
				continue;
			input2 = -90 + j * 30;
			result = atan2(input, input2);
			CU_ASSERT("atan2", resultcheck(result, atan2_table[7 * i + j]));
		}
	}

	/* cos */
	for (i = 0; i <= 12; i++)
	{
		input = -PI + i * PI / 6;
		result = cos(input);
		CU_ASSERT("cos", resultcheck(result, cos_table[i]));
	}

	/* cosh */
	for (i = 0; i <= 10; i++)
	{
		input = -5 + i;
		result = cosh(input);
		CU_ASSERT("cosh", resultcheck(result, cosh_table[i]));
	}

	/* sin */
	for (i = 0; i <= 12; i++)
	{
		input = -PI + i * PI / 6;
		result = sin(input);
		CU_ASSERT("sin", resultcheck(result, sin_table[i]));
	}

	/* sinh */
	for (i = 0; i <= 10; i++)
	{
		input = -5 + i;
		result = sinh(input);
		CU_ASSERT("sinh", resultcheck(result, sinh_table[i]));
	}

	/* tan */
	for (i = 0; i <= 12; i++)
	{
		input = -PI + i * PI / 6;
		result = tan(input);
		CU_ASSERT("tan", resultcheck(result, tan_table[i]));
	}

	/* tanh */
	for (i = 0; i <= 10; i++)
	{
		input = -5 + i;
		result = tanh(input);
		CU_ASSERT("tanh", resultcheck(result, tanh_table[i]));
	}

	/* exp */
	for (i = 0; i <= 10; i++)
	{
		input = -5 + i;
		result = exp(input);
		CU_ASSERT("exp", resultcheck(result, exp_table[i]));
	}

	int exponent;

	/* frexp */
	for (i = 0; i <= 5; i++)
	{
		input = -12.6 + i * 3.4;
		result = frexp(input, &exponent);
		CU_ASSERT("frexp", resultcheck(result, frexp_table[i][0]) ||
			  resultcheck(exponent, frexp_table[i][1]));
	}

	/* ldexp */
	for (i = 0; i <= 5; i++)
	{
		input = -12.6 + i * 3.4;
		exponent = -2 + i;
		result = ldexp(input, exponent);
		CU_ASSERT("ldexp", resultcheck(result, ldexp_table[i]));
	}

	/* log */
	for (i = 0; i <= 10; i++)
	{
		input = 0.5 + i * 0.4;
		result = log(input);
		CU_ASSERT("log", resultcheck(result, log_table[i]));
	}

	/* log10 */
	for (i = 0; i <= 10; i++)
	{
		input = 0.5 + i * 0.4;
		result = log10(input);
		CU_ASSERT("log10", resultcheck(result, log10_table[i]));
	}

	float integer;
	/* modf */
	for (i = 0; i <= 5; i++)
	{
		input = -12.6 + i * 3.4;
		result = modf(input, &integer);
		CU_ASSERT("modf", resultcheck(result, modf_table[i][0]) ||
			  resultcheck(integer, modf_table[i][1]));
	}

	/* pow */
	for (i = 0; i <= 5; i++)
	{
		input = -12.6 + i * 3.4;
		for (j = 0; j <= 2; j++)
		{
			if (input < 0)
				input2 = 1 + j;
			else
				input2 = -2.3 + j * 2.1;

			result = pow(input, input2);
			CU_ASSERT("pow", resultcheck(result, pow_table[3 * i + j]));
		}
	}

	/* square root */
	for (i = 0; i <= 10; i++)
	{
		input = 0.5 + i * 0.4;
		result = sqrt(input);
		CU_ASSERT("sqrt", resultcheck(result, sqrt_table[i]));
	}

	/* ceil */
	for (i = 0; i <= 5; i++)
	{
		input = -12.6 + i * 3.4;
		result = ceil(input);
		CU_ASSERT("ceil", resultcheck(result, ceil_table[i]));
	}

	/* fabs */
	for (i = 0; i <= 5; i++)
	{
		input = -12.6 + i * 3.4;
		result = fabs(input);
		CU_ASSERT("fabs", resultcheck(result, fabs_table[i]));
	}

	/* floor */
	for (i = 0; i <= 5; i++)
	{
		input = -12.6 + i * 3.4;
		result = floor(input);
		CU_ASSERT("floor", resultcheck(result, floor_table[i]));
	}

	/* fmod */
	for (i = 0; i <= 5; i++)
	{
		input = -12.6 + i * 3.4;
		for (j = 0; j <= 2; j++)
		{
			input2 = -0.4 + j * 0.66;
			result = fmod(input, input2);
			CU_ASSERT("fmod", resultcheck(result, fmod_table[3 * i + j]));
		}
	}

}
Ejemplo n.º 18
0
static DRIVER_API_RC soc_gpio_test_port_int(struct device *dev, unsigned int input_pin, unsigned int output_pin)
{
    uint32_t priv = PRIV_KEY;
    gpio_port_cfg_data_t port_cfg;

    // -----------------------------
    // Test ACTIVE_LOW interrupt
    // -----------------------------
    port_cfg.gpio_type = 1<<output_pin; // All input except output bit
    port_cfg.is_interrupt = 0; // No interrupts
    port_cfg.int_type = 1<<input_pin; // edge interrupt on input pin
    port_cfg.int_bothedge = 0; // Only one edge
    port_cfg.int_polarity = ACTIVE_LOW;
    port_cfg.int_debounce = DEBOUNCE_OFF;
    port_cfg.gpio_cb[input_pin] = my_callback;
    port_cfg.gpio_cb_arg[input_pin] = &priv;

    soc_gpio_set_port_config(dev, &port_cfg);
    soc_gpio_write_port(dev, 0);
    trans_delay(); // Delay a little bit

    // Enable interrupt
    my_callback_counter = 0;
    port_cfg.is_interrupt = 1<<input_pin;
    soc_gpio_set_port_config(dev, &port_cfg);
    trans_delay(); // Delay a little bit
    soc_gpio_write_port(dev, 1 << output_pin);
    trans_delay(); // Delay a little bit

    // Check that interrupt is not triggered
    if(my_callback_counter != 0) {
        cu_print("Error: interrupt occured %d\n", my_callback_counter);
        goto fail;
    }

    // Trigger interrupt (active low)
    soc_gpio_write_port(dev, 0);
    trans_delay(); // Delay a little bit
    // Check that interrupt is triggered
    if(my_callback_counter != 1) {
        cu_print("Error: interrupt test for ACTIVE_LOW returned %d\n", my_callback_counter);
        goto fail;
    }
    // Check that pin state returned in IRQ callback is valid
    if(my_callback_state != false) {
        cu_print("Error: pin state not valid\n");
        goto fail;
    }

    // deconfigure port for next test (active high)
    soc_gpio_port_deconfig(dev);

    // -----------------------------
    // Test ACTIVE_HIGH interrupt
    // -----------------------------
    port_cfg.gpio_type = 1<<output_pin; // All input except output bit
    port_cfg.is_interrupt = 0;
    port_cfg.int_type = 1<<input_pin; // edge interrupt on input pin
    port_cfg.int_bothedge = 0; // Only one edge
    port_cfg.int_polarity = 1<<input_pin; // ACTIVE_HIGH
    port_cfg.int_debounce = 0; // this is default
    port_cfg.gpio_cb[input_pin] = my_callback;
    port_cfg.gpio_cb_arg[input_pin] = &priv;

    soc_gpio_set_port_config(dev, &port_cfg);
    soc_gpio_write_port(dev, 1 << output_pin);
    trans_delay(); // Delay a little bit

    // Enable interrupt
    my_callback_counter = 0;
    port_cfg.is_interrupt = 1<<input_pin;
    soc_gpio_set_port_config(dev, &port_cfg);
    trans_delay(); // Delay a little bit
    soc_gpio_write_port(dev, 0);
    trans_delay(); // Delay a little bit

    if(my_callback_counter != 0) {
        cu_print("Error: interrupt test for ACTIVE_HIGH returned %d (should be 0)\n", my_callback_counter);
        goto fail;
    }
    // Check that interrupt is triggered (active high)
    soc_gpio_write_port(dev, 1 << output_pin);
    trans_delay(); // Delay a little bit
    if(my_callback_counter != 1) {
        cu_print("Error: interrupt test for ACTIVE_HIGH returned %d (should be 1)\n", my_callback_counter);
        goto fail;
    }
    // Check that pin state returned in IRQ callback is valid
    if(my_callback_state != true) {
        cu_print("Error: pin state not valid\n");
        goto fail;
    }

    // deconfigure port for next test
    soc_gpio_port_deconfig(dev);

    // -----------------------------
    // Test BOTH_EDGE interrupt
    // -----------------------------
    port_cfg.gpio_type = 1<<output_pin; // All input except output bit
    port_cfg.is_interrupt = 0;
    port_cfg.int_type = 1<<input_pin; // edge interrupt on input pin
    port_cfg.int_bothedge = 1<<input_pin;
    port_cfg.int_polarity = 1<<input_pin; // ACTIVE_HIGH
    port_cfg.int_debounce = 0; // this is default
    port_cfg.gpio_cb[input_pin] = my_callback;
    port_cfg.gpio_cb_arg[input_pin] = &priv;

    soc_gpio_set_port_config(dev, &port_cfg);
    soc_gpio_write_port(dev, 1 << output_pin);
    trans_delay(); // Delay a little bit

    // Enable interrupt
    my_callback_counter = 0;
    port_cfg.is_interrupt = 1<<input_pin;
    soc_gpio_set_port_config(dev, &port_cfg);
    trans_delay(); // Delay a little bit
    soc_gpio_write_port(dev, 0);
    trans_delay(); // Delay a little bit

    // Check that interrupt is triggered
    if(my_callback_counter != 1) {
        cu_print("Error: interrupt test for DOUBLE_EDGE returned %d (should be 1)\n", my_callback_counter);
        goto fail;
    }
    // Check that pin state returned in IRQ callback is valid
    if(my_callback_state != false) {
        cu_print("Error: pin state not valid\n");
        goto fail;
    }
    // Check that interrupt is triggered (double edge)
    soc_gpio_write_port(dev, 1<<output_pin);
    trans_delay(); // Delay a little bit
    // Check that interrupt is not triggered
    if(my_callback_counter != 2) {
        cu_print("Error: interrupt test for DOUBLE_EDGE returned %d (should be 2)\n", my_callback_counter);
        goto fail;
    }
    // Check that pin state returned in IRQ callback is valid
    if(my_callback_state != true) {
        cu_print("Error: pin state not valid\n");
        goto fail;
    }

    soc_gpio_port_deconfig(dev);
    return DRV_RC_OK;

fail:
    soc_gpio_port_deconfig(dev);
    return DRV_RC_FAIL;
}
Ejemplo n.º 19
0
static DRIVER_API_RC soc_gpio_test_pin_int(struct device *dev, unsigned int input_pin, unsigned int output_pin)
{
    uint32_t priv = PRIV_KEY;
    gpio_cfg_data_t in_pin_cfg;
    gpio_cfg_data_t out_pin_cfg;

    out_pin_cfg.gpio_type = GPIO_OUTPUT;
    out_pin_cfg.int_type = LEVEL;
    out_pin_cfg.int_polarity = ACTIVE_LOW;
    out_pin_cfg.int_debounce = DEBOUNCE_OFF;
    out_pin_cfg.gpio_cb = NULL;

    // TODO: test return value. It should be ok if previous tests worked
    soc_gpio_set_config(dev, output_pin, &out_pin_cfg);

    // -----------------------------
    // Test ACTIVE_LOW interrupt
    // -----------------------------
    in_pin_cfg.gpio_type = GPIO_INTERRUPT;
    in_pin_cfg.int_type = EDGE;
    in_pin_cfg.int_polarity = ACTIVE_LOW;
    in_pin_cfg.int_debounce = DEBOUNCE_OFF;
    in_pin_cfg.gpio_cb = my_callback;
    in_pin_cfg.gpio_cb_arg = &priv;

    soc_gpio_write(dev, output_pin, 0);
    trans_delay(); // Delay a little bit
    my_callback_counter = 0;
    soc_gpio_set_config(dev, input_pin, &in_pin_cfg);
    trans_delay(); // Delay a little bit
    soc_gpio_write(dev, output_pin, 1);
    trans_delay(); // Delay a little bit

    // Check that interrupt is not triggered
    if(my_callback_counter != 0) {
        cu_print("Error: interrupt occured %d\n", my_callback_counter);
        goto fail;
    }

    // Trigger interrupt (active low)
    soc_gpio_write(dev, output_pin, 0);
    trans_delay(); // Delay a little bit
    // Check that interrupt is triggered
    if(my_callback_counter != 1) {
        cu_print("Error: interrupt test for ACTIVE_LOW returned %d\n", my_callback_counter);
        goto fail;
    }
    // Check that pin state returned in IRQ callback is valid
    if(my_callback_state != false) {
        cu_print("Error: pin state not valid\n");
        goto fail;
    }

    // deconfigure input pin for next test (active high)
    soc_gpio_deconfig(dev, input_pin);

    // -----------------------------
    // Test ACTIVE_HIGH interrupt
    // -----------------------------
    in_pin_cfg.gpio_type = GPIO_INTERRUPT;
    in_pin_cfg.int_type = EDGE;
    in_pin_cfg.int_polarity = ACTIVE_HIGH;
    in_pin_cfg.int_debounce = DEBOUNCE_OFF;
    in_pin_cfg.gpio_cb = my_callback;

    // Test LOW
    soc_gpio_write(dev, output_pin, 1);
    trans_delay(); // Delay a little bit
    my_callback_counter = 0;
    soc_gpio_set_config(dev, input_pin, &in_pin_cfg);
    soc_gpio_write(dev, output_pin, 0);
    trans_delay(); // Delay a little bit
    // Check that interrupt is not triggered
    if(my_callback_counter != 0) {
        cu_print("Error: interrupt test for ACTIVE_HIGH returned %d (should be 0)\n", my_callback_counter);
        goto fail;
    }
    // Check that interrupt is triggered (active high)
    soc_gpio_write(dev, output_pin, 1);
    trans_delay(); // Delay a little bit
    if(my_callback_counter != 1) {
        cu_print("Error: interrupt test for ACTIVE_HIGH returned %d (should be 1)\n", my_callback_counter);
        goto fail;
    }
    // Check that pin state returned in IRQ callback is valid
    if(my_callback_state != true) {
        cu_print("Error: pin state not valid\n");
        goto fail;
    }

    // deconfigure input pin for next test (double edge)
    soc_gpio_deconfig(dev, input_pin);

    // -----------------------------
    // Test BOTH_EDGE interrupt
    // -----------------------------
    in_pin_cfg.gpio_type = GPIO_INTERRUPT;
    in_pin_cfg.int_type = DOUBLE_EDGE;
    in_pin_cfg.int_polarity = ACTIVE_HIGH;
    in_pin_cfg.int_debounce = DEBOUNCE_OFF;
    in_pin_cfg.gpio_cb = my_callback;

    // Test LOW
    soc_gpio_write(dev, output_pin, 0);
    trans_delay(); // Delay a little bit
    soc_gpio_set_config(dev, input_pin, &in_pin_cfg);
    my_callback_counter = 0;
    soc_gpio_write(dev, output_pin, 1);
    trans_delay(); // Delay a little bit
    // Check that interrupt is triggered
    if(my_callback_counter != 1) {
        cu_print("Error: interrupt test for DOUBLE_EDGE returned %d (should be 1)\n", my_callback_counter);
        goto fail;
    }
    // Check that pin state returned in IRQ callback is valid
    if(my_callback_state != true) {
        cu_print("Error: pin state not valid\n");
        goto fail;
    }
    // Check that interrupt is triggered (double edge)
    soc_gpio_write(dev, output_pin, 0);
    trans_delay(); // Delay a little bit
    // Check that interrupt is not triggered
    if(my_callback_counter != 2) {
        cu_print("Error: interrupt test for DOUBLE_EDGE returned %d (should be 2)\n", my_callback_counter);
        goto fail;
    }
    // Check that pin state returned in IRQ callback is valid
    if(my_callback_state != false) {
        cu_print("Error: pin state not valid\n");
        goto fail;
    }

    soc_gpio_deconfig(dev, output_pin);
    soc_gpio_deconfig(dev, input_pin);
    return DRV_RC_OK;

fail:
    soc_gpio_deconfig(dev, output_pin);
    soc_gpio_deconfig(dev, input_pin);
    return DRV_RC_FAIL;
}
Ejemplo n.º 20
0
static DRIVER_API_RC soc_gpio_test_port(struct device *dev, unsigned int input_pin, unsigned int output_pin)
{
    DRIVER_API_RC ret;
    uint32_t value;

    gpio_port_cfg_data_t port_cfg;

    /* fill in settings and defaults for un-needed settings */
    port_cfg.gpio_type = 1<<output_pin; // All input except output bit
    port_cfg.is_interrupt = 0; // No interrupts
    // Interrupts are not enabled here. We don t care about next parameters
    port_cfg.int_type = 0; // this is default
    port_cfg.int_bothedge = 0; // this is default
    port_cfg.int_polarity = 0; // this is default
    port_cfg.int_debounce = 0; // this is default
    port_cfg.int_ls_sync = 0; // this is default

    if((ret =  soc_gpio_set_port_config(dev, &port_cfg)) != DRV_RC_OK) {
        cu_print("Error port config (%d)\n", ret);
        return ret;
    }

    // Test LOW
    value = 0;
    if((ret =  soc_gpio_write_port(dev, value)) != DRV_RC_OK) {
        cu_print("Error port write 1 (%d)\n", ret);
        soc_gpio_port_deconfig(dev);
        return ret;
    }
    trans_delay();
    if((ret =  soc_gpio_read_port(dev, &value)) != DRV_RC_OK) {
        cu_print("Error port read 1 (%d)\n", ret);
        soc_gpio_port_deconfig(dev);
        return ret;
    }
    if(value & (1<<input_pin)) {
        cu_print("Error port is 0x%x, 0x%x expected (Test Low)\n", value, (value & ~(1<<input_pin)));
        soc_gpio_port_deconfig(dev);
        return DRV_RC_FAIL;
    }

    // Test HIGH
    value = (1<<output_pin);
    if((ret =  soc_gpio_write_port(dev, value)) != DRV_RC_OK) {
        cu_print("Error port write 2 (%d)\n", ret);
        soc_gpio_port_deconfig(dev);
        return ret;
    }
    trans_delay();
    if((ret =  soc_gpio_read_port(dev, &value)) != DRV_RC_OK) {
        cu_print("Error port read 2 (%d)\n", ret);
        soc_gpio_port_deconfig(dev);
        return ret;
    }
    if(!(value & (1<<input_pin)) ) {
        cu_print("Error port is 0x%x, 0x%x expected (Test High)\n", value, (value | (1<<input_pin)));
        soc_gpio_port_deconfig(dev);
        return DRV_RC_FAIL;
    }

    soc_gpio_port_deconfig(dev);

    return DRV_RC_OK;
}
Ejemplo n.º 21
0
static DRIVER_API_RC soc_gpio_test_pin(struct device *dev, unsigned int input_pin, unsigned int output_pin)
{
    DRIVER_API_RC ret;
    bool value;

    gpio_cfg_data_t in_pin_cfg;
    gpio_cfg_data_t out_pin_cfg;

    in_pin_cfg.gpio_type = GPIO_INPUT;
    in_pin_cfg.int_type = LEVEL;
    in_pin_cfg.int_polarity = ACTIVE_LOW;
    in_pin_cfg.int_debounce = DEBOUNCE_OFF;
    in_pin_cfg.int_ls_sync = LS_SYNC_OFF;
    in_pin_cfg.gpio_cb = NULL;

    out_pin_cfg.gpio_type = GPIO_OUTPUT;
    out_pin_cfg.int_type = LEVEL;
    out_pin_cfg.int_polarity = ACTIVE_LOW;
    out_pin_cfg.int_debounce = DEBOUNCE_OFF;
    out_pin_cfg.int_ls_sync = LS_SYNC_OFF;
    out_pin_cfg.gpio_cb = NULL;

    if((ret =  soc_gpio_set_config(dev, input_pin, &in_pin_cfg)) != DRV_RC_OK) {
        cu_print("Error pin %d config (%d)\n", input_pin, ret);
        return ret;
    }
    if((ret =  soc_gpio_set_config(dev, output_pin, &out_pin_cfg)) != DRV_RC_OK) {
        cu_print("Error pin %d config (%d)\n", output_pin, ret);
        soc_gpio_deconfig(dev, input_pin);
        return ret;
    }

    // Test LOW
    if((ret =  soc_gpio_write(dev, output_pin, 0)) != DRV_RC_OK) {
        cu_print("Error pin %d write 1 (%d)\n", output_pin, ret);
        soc_gpio_deconfig(dev, output_pin);
        soc_gpio_deconfig(dev, input_pin);
        return ret;
    }
    trans_delay(); // Delay a little bit
    if((ret =  soc_gpio_read(dev, input_pin, &value)) != DRV_RC_OK) {
        cu_print("Error pin %d read 1 (%d)\n", input_pin, ret);
        soc_gpio_deconfig(dev, output_pin);
        soc_gpio_deconfig(dev, input_pin);
        return ret;
    }
    if(value) {
        cu_print("Error pin %d is at 1, 0 expected\n", input_pin);
        soc_gpio_deconfig(dev, output_pin);
        soc_gpio_deconfig(dev, input_pin);
        return DRV_RC_FAIL;
    }

    // Test HIGH
    if((ret =  soc_gpio_write(dev, output_pin, 1)) != DRV_RC_OK) {
        cu_print("Error pin %d write 2 (%d)\n", output_pin, ret);
        soc_gpio_deconfig(dev, output_pin);
        soc_gpio_deconfig(dev, input_pin);
        return ret;
    }
    trans_delay(); // Delay a little bit
    if((ret =  soc_gpio_read(dev, input_pin, &value)) != DRV_RC_OK) {
        cu_print("Error pin %d read 2 (%d)\n", input_pin, ret);
        soc_gpio_deconfig(dev, output_pin);
        soc_gpio_deconfig(dev, input_pin);
        return ret;
    }
    if(!value) {
        cu_print("Error pin %d is at 0, 1 expected\n", input_pin);
        soc_gpio_deconfig(dev, output_pin);
        soc_gpio_deconfig(dev, input_pin);
        return DRV_RC_FAIL;
    }

    soc_gpio_deconfig(dev, output_pin);
    soc_gpio_deconfig(dev, input_pin);

    return DRV_RC_OK;
}
Ejemplo n.º 22
0
int test_balib(void)
{
	int i = 0, j = 0;
	int nRet, nOk, nRightRet;
	pFun1 pTmpFun1;
	pFun2 pTmpFun2;
	float *pfRightRes = NULL;

	cu_print(
		"##############################################################\n");
	cu_print(
		"# Purpose of the balib test:                                   #\n");
	cu_print(
		"# Check that all implemented functions in balib package       #\n");
	cu_print(
		"# return the right results for a set of input values          #\n");
	cu_print(
		"##############################################################\n");

	int nTestSampleNum = sizeof(DataLen) / sizeof(int);
	cu_print("nTestSampleNum == %d\n", nTestSampleNum);
	for (j = 0; j < FUN1_NUM; j++) {
		pTmpFun1 = apFun1[j];
		pfRightRes = apfRightRes1[j];
		nOk = 0;
		for (i = 0; i < nTestSampleNum; i++) {
			nRightRet = 0;
			if (fabs(pfRightRes[i] - ERR_INVALIDPARAMTER_VALUE) <
			    1) nRightRet = ERR_INVALID_PARAMTER;
			else if (fabs(pfRightRes[i] -
				      ERR_DEVIDED_BY_ZERO_VALUE) <
				 1) nRightRet =
					ERR_DEVIDED_BY_ZERO;

			nRet = pTmpFun1(pTestData[i], DataLen[i], nRightRet,
					pfRightRes[i]);
			CU_ASSERT("balib statiscs", nRet == SUCCESS);
		}
	}
	cu_print(
		"The first half of statistics function test of balib test is done\n");
	for (j = 0; j < FUN2_NUM; j++) {
		pTmpFun2 = apFun2[j];
		nOk = 0;
		pfRightRes = apfRightRes2[j];
		for (i = 0; i < nTestSampleNum; i++) {
			nRightRet = 0;
			if (fabs(pfRightRes[i] - ERR_INVALIDPARAMTER_VALUE) <
			    1) nRightRet = ERR_INVALID_PARAMTER;
			else if (fabs(pfRightRes[i] -
				      ERR_DEVIDED_BY_ZERO_VALUE) <
				 1) nRightRet =
					ERR_DEVIDED_BY_ZERO;
			nRet =
				pTmpFun2(pTestData[i], DataLen[i], anFlag[j],
					 nRightRet,
					 pfRightRes[i]);
			CU_ASSERT("balib statiscs", nRet == SUCCESS);
		}
	}
	cu_print(
		"The second half of statistics function test of balib test is done\n");

	int nSortTestSampleNum = 3;
	for (i = 0; i < nSortTestSampleNum; i++) {
		nRet = fsort_test(i);
		CU_ASSERT("balib fsort", nRet == SUCCESS);
	}
	cu_print("fsort of balib test is done\n");

	int fft_testcase = 0;
	for (fft_testcase = 0; fft_testcase < 5; fft_testcase++) {
		nRet = fft_test_sw(fft_testcase);
		CU_ASSERT("balib fft", nRet == SUCCESS);
	}
	cu_print("fft test of balib is done\n");

	int wavelet_testcase = 0;
	for (wavelet_testcase = 0; wavelet_testcase < 10; wavelet_testcase++) {
		nRet = wavelet_test(wavelet_testcase);
		CU_ASSERT("balib wavelet", nRet == SUCCESS);
	}
	cu_print("wavelet of balib test is done\n");
	return 0;
}