diff --git a/api/mraa/initio.hpp b/api/mraa/initio.hpp index ce0862442..13c5f82c0 100644 --- a/api/mraa/initio.hpp +++ b/api/mraa/initio.hpp @@ -47,7 +47,7 @@ namespace mraa class MraaIo { private: - mraa_io_descriptor* descs; + mraa_io_descriptor* descs = nullptr; public: MraaIo(const std::string& initStr) : descs() @@ -109,39 +109,41 @@ class MraaIo ~MraaIo() { - if (descs->leftover_str) { - free(descs->leftover_str); - } - - if (descs->n_aio) { - free(descs->aios); - } - if (descs->n_gpio) { - free(descs->gpios); - } - if (descs->n_i2c) { - free(descs->i2cs); - } + if(descs != nullptr) { + if (descs->leftover_str) { + free(descs->leftover_str); + } + + if (descs->n_aio) { + free(descs->aios); + } + if (descs->n_gpio) { + free(descs->gpios); + } + if (descs->n_i2c) { + free(descs->i2cs); + } #if !defined(PERIPHERALMAN) - if (descs->n_iio) { - free(descs->iios); - } + if (descs->n_iio) { + free(descs->iios); + } #endif - if (descs->n_pwm) { - free(descs->pwms); - } - if (descs->n_spi) { - free(descs->spis); - } - if (descs->n_uart) { - free(descs->uarts); + if (descs->n_pwm) { + free(descs->pwms); + } + if (descs->n_spi) { + free(descs->spis); + } + if (descs->n_uart) { + free(descs->uarts); + } + if (descs->n_uart_ow) { + free(descs->uart_ows); + } + + /* Finally free the mraa_io_descriptor structure. */ + free(descs); } - if (descs->n_uart_ow) { - free(descs->uart_ows); - } - - /* Finally free the mraa_io_descriptor structure. */ - free(descs); } public: diff --git a/include/mock/mock_board.h b/include/mock/mock_board.h index 41b0fe3de..076e90465 100644 --- a/include/mock/mock_board.h +++ b/include/mock/mock_board.h @@ -30,7 +30,18 @@ extern "C" { #include "mraa_internal.h" -#define MRAA_MOCK_PINCOUNT 10 +#define MRAA_MOCK_GPIO_COUNT 1 +#define MRAA_MOCK_AIO_COUNT 1 +#define MRAA_MOCK_I2C_BUS_COUNT 1 +#define MRAA_MOCK_SPI_BUS_COUNT 1 +#define MRAA_MOCK_PWM_DEV_COUNT 1 +#define MRAA_MOCK_UART_DEV_COUNT 1 +#define MRAA_MOCK_PINCOUNT (MRAA_MOCK_GPIO_COUNT + MRAA_MOCK_AIO_COUNT + \ + 2 * MRAA_MOCK_I2C_BUS_COUNT + 4 * MRAA_MOCK_SPI_BUS_COUNT + \ + MRAA_MOCK_PWM_DEV_COUNT + 2 * MRAA_MOCK_UART_DEV_COUNT) + +#define MRAA_PWM_OFFSET (MRAA_MOCK_GPIO_COUNT + MRAA_MOCK_AIO_COUNT + \ + 2 * MRAA_MOCK_I2C_BUS_COUNT + 4 * MRAA_MOCK_SPI_BUS_COUNT) mraa_board_t* mraa_mock_board(); diff --git a/include/mock/mock_board_i2c.h b/include/mock/mock_board_i2c.h index 00d27ea89..cd94938d9 100644 --- a/include/mock/mock_board_i2c.h +++ b/include/mock/mock_board_i2c.h @@ -33,7 +33,7 @@ extern "C" { // Mock I2C device address #define MOCK_I2C_DEV_ADDR 0x33 // Mock I2C device data registers block length in bytes. Our code assumes it's >= 1. -#define MOCK_I2C_DEV_DATA_LEN 10 +#define MOCK_I2C_DEV_DATA_LEN 255 // Initial value for each byte in the mock I2C device data registers #define MOCK_I2C_DEV_DATA_INIT_BYTE 0xAB diff --git a/include/mock/mock_board_pwm.h b/include/mock/mock_board_pwm.h new file mode 100644 index 000000000..c7f086a2e --- /dev/null +++ b/include/mock/mock_board_pwm.h @@ -0,0 +1,50 @@ +/* + * Author: Adelin Dobre + * Copyright (c) 2019 Adelin Dobre. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "mraa_internal.h" + +mraa_result_t +mraa_mock_pwm_init_raw_replace(mraa_pwm_context dev, int pin); + +mraa_result_t +mraa_mock_pwm_write_period_replace(mraa_pwm_context dev, int period); + +mraa_result_t +mraa_mock_pwm_write_duty_replace(mraa_pwm_context dev, int duty); + +int +mraa_mock_pwm_read_duty_replace(mraa_pwm_context dev); + +mraa_result_t +mraa_mock_pwm_enable_replace(mraa_pwm_context dev, int enable); + +#ifdef __cplusplus +} +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 35c54888e..a37b25079 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -114,6 +114,7 @@ set (mraa_LIB_MOCK_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/mock/mock_board_gpio.c ${PROJECT_SOURCE_DIR}/src/mock/mock_board_aio.c ${PROJECT_SOURCE_DIR}/src/mock/mock_board_i2c.c + ${PROJECT_SOURCE_DIR}/src/mock/mock_board_pwm.c ${PROJECT_SOURCE_DIR}/src/mock/mock_board_spi.c ${PROJECT_SOURCE_DIR}/src/mock/mock_board_uart.c ) diff --git a/src/initio/initio.c b/src/initio/initio.c index ea0cf7232..66ec2ca80 100644 --- a/src/initio/initio.c +++ b/src/initio/initio.c @@ -787,7 +787,6 @@ mraa_io_init(const char* strdesc, mraa_io_descriptor** desc) strncat(new_desc->leftover_str, str_descs[i], strlen(str_descs[i])); } - strncat(new_desc->leftover_str, str_descs[i], strlen(str_descs[i])); leftover_str_len += strlen(str_descs[i]) + 1; new_desc->leftover_str[leftover_str_len - 1] = ','; new_desc->leftover_str[leftover_str_len] = '\0'; diff --git a/src/mock/mock_board.c b/src/mock/mock_board.c index 9b0768181..73a397eb9 100644 --- a/src/mock/mock_board.c +++ b/src/mock/mock_board.c @@ -24,6 +24,7 @@ #include #include +#include #include "common.h" #include "mock/mock_board.h" @@ -31,10 +32,12 @@ #include "mock/mock_board_aio.h" #include "mock/mock_board_i2c.h" #include "mock/mock_board_spi.h" +#include "mock/mock_board_pwm.h" #include "mock/mock_board_uart.h" #define PLATFORM_NAME "MRAA mock platform" #define UART_DEV_PATH "dummy" +#define PWM_DEV_PATH "dummy" mraa_board_t* mraa_mock_board() @@ -47,35 +50,54 @@ mraa_mock_board() // General board definitions b->platform_name = PLATFORM_NAME; b->phy_pin_count = MRAA_MOCK_PINCOUNT; - b->gpio_count = 1; - b->aio_count = 1; + b->gpio_count = MRAA_MOCK_GPIO_COUNT; + b->aio_count = MRAA_MOCK_AIO_COUNT; b->adc_raw = 12; b->adc_supported = 10; - b->i2c_bus_count = 1; - b->i2c_bus[0].bus_id = 0; - b->i2c_bus[0].sda = 2; - b->i2c_bus[0].scl = 3; + int i2c_offset = MRAA_MOCK_GPIO_COUNT + MRAA_MOCK_AIO_COUNT; + b->i2c_bus_count = MRAA_MOCK_I2C_BUS_COUNT; + + for(int index = 0; index < MRAA_MOCK_I2C_BUS_COUNT; index++) { + b->i2c_bus[index].bus_id = index; + b->i2c_bus[index].sda = i2c_offset + 2 * index; + b->i2c_bus[index].scl = i2c_offset + 2 * index + 1; + } b->def_i2c_bus = b->i2c_bus[0].bus_id; - b->spi_bus_count = 1; + int spi_offset = i2c_offset + 2 * MRAA_MOCK_I2C_BUS_COUNT; + b->spi_bus_count = MRAA_MOCK_SPI_BUS_COUNT; b->def_spi_bus = 0; - b->spi_bus[0].bus_id = 0; - b->spi_bus[0].slave_s = 0; - b->spi_bus[0].cs = 4; - b->spi_bus[0].mosi = 5; - b->spi_bus[0].miso = 6; - b->spi_bus[0].sclk = 7; - - b->pwm_default_period = 0; - b->pwm_max_period = 0; - b->pwm_min_period = 0; - - b->uart_dev_count = 1; + + for(int index = 0; index < MRAA_MOCK_SPI_BUS_COUNT; index++) { + b->spi_bus[index].bus_id = index; + b->spi_bus[index].slave_s = 0; + b->spi_bus[index].cs = spi_offset + 4 * index; + b->spi_bus[index].mosi = spi_offset + 4 * index + 1; + b->spi_bus[index].miso = spi_offset + 4 * index + 2; + b->spi_bus[index].sclk = spi_offset + 4 * index + 3; + } + + int pwm_offset = spi_offset + 4 * MRAA_MOCK_SPI_BUS_COUNT; + b->pwm_dev_count = MRAA_MOCK_PWM_DEV_COUNT; + b->pwm_default_period = 500; + b->pwm_max_period = 2147483; + b->pwm_min_period = 1; + + for(int index = 0; index < MRAA_MOCK_PWM_DEV_COUNT; index++) { + b->pwm_dev[index].index = pwm_offset + index; + b->pwm_dev[index].device_path = PWM_DEV_PATH; + } + + int uart_offset = pwm_offset + MRAA_MOCK_PWM_DEV_COUNT; + b->uart_dev_count = MRAA_MOCK_UART_DEV_COUNT; b->def_uart_dev = 0; - b->uart_dev[0].rx = 8; - b->uart_dev[0].tx = 9; - b->uart_dev[0].device_path = UART_DEV_PATH; + + for(int index = 0; index < MRAA_MOCK_UART_DEV_COUNT; index++) { + b->uart_dev[index].rx = uart_offset + 2 * index; + b->uart_dev[index].tx = uart_offset + 2 * index + 1; + b->uart_dev[index].device_path = UART_DEV_PATH; + } b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * MRAA_MOCK_PINCOUNT); if (b->pins == NULL) { @@ -125,6 +147,11 @@ mraa_mock_board() b->adv_func->spi_write_word_replace = &mraa_mock_spi_write_word_replace; b->adv_func->spi_transfer_buf_replace = &mraa_mock_spi_transfer_buf_replace; b->adv_func->spi_transfer_buf_word_replace = &mraa_mock_spi_transfer_buf_word_replace; + b->adv_func->pwm_init_raw_replace = &mraa_mock_pwm_init_raw_replace; + b->adv_func->pwm_period_replace = &mraa_mock_pwm_write_period_replace; + b->adv_func->pwm_write_replace = &mraa_mock_pwm_write_duty_replace; + b->adv_func->pwm_read_replace = &mraa_mock_pwm_read_duty_replace; + b->adv_func->pwm_enable_replace = &mraa_mock_pwm_enable_replace; b->adv_func->uart_init_raw_replace = &mraa_mock_uart_init_raw_replace; b->adv_func->uart_set_baudrate_replace = &mraa_mock_uart_set_baudrate_replace; b->adv_func->uart_flush_replace = &mraa_mock_uart_flush_replace; @@ -140,67 +167,86 @@ mraa_mock_board() // Pin definitions int pos = 0; - strncpy(b->pins[pos].name, "GPIO0", 8); - b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }; - b->pins[pos].gpio.pinmap = 0; - b->pins[pos].gpio.mux_total = 0; - pos++; - - strncpy(b->pins[pos].name, "ADC0", 8); - b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 }; - b->pins[pos].aio.pinmap = 0; - b->pins[pos].aio.mux_total = 0; - pos++; - - strncpy(b->pins[pos].name, "I2C0SDA", 8); - b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 }; - b->pins[pos].i2c.mux_total = 0; - b->pins[pos].i2c.pinmap = 0; - pos++; - - strncpy(b->pins[pos].name, "I2C0SCL", 8); - b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 }; - b->pins[pos].i2c.mux_total = 0; - b->pins[pos].i2c.pinmap = 0; - pos++; - - strncpy(b->pins[pos].name, "SPI0CS", 8); - b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 }; - b->pins[pos].spi.mux_total = 0; - b->pins[pos].spi.pinmap = 0; - pos++; - - strncpy(b->pins[pos].name, "SPI0MOSI", 8); - b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 }; - b->pins[pos].spi.mux_total = 0; - b->pins[pos].spi.pinmap = 0; - pos++; - - strncpy(b->pins[pos].name, "SPI0MISO", 8); - b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 }; - b->pins[pos].spi.mux_total = 0; - b->pins[pos].spi.pinmap = 0; - pos++; - - strncpy(b->pins[pos].name, "SPI0SCLK", 8); - b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 }; - b->pins[pos].spi.mux_total = 0; - b->pins[pos].spi.pinmap = 0; - pos++; - - strncpy(b->pins[pos].name, "UART0RX", 8); - b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 1 }; - b->pins[pos].uart.pinmap = 0; - b->pins[pos].uart.parent_id = 0; - b->pins[pos].uart.mux_total = 0; - pos++; - - strncpy(b->pins[pos].name, "UART0TX", 8); - b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 1 }; - b->pins[pos].uart.pinmap = 0; - b->pins[pos].uart.parent_id = 0; - b->pins[pos].uart.mux_total = 0; - pos++; + for(int index = 0; index < MRAA_MOCK_GPIO_COUNT; index++) { + snprintf(b->pins[pos].name, 8, "GPIO%d", index); + b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }; + b->pins[pos].gpio.pinmap = index; + b->pins[pos].gpio.mux_total = 0; + pos++; + } + + for(int index = 0; index < MRAA_MOCK_AIO_COUNT; index++) { + snprintf(b->pins[pos].name, 8, "ADC%d", index); + b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 1, 0 }; + b->pins[pos].aio.pinmap = 0; + b->pins[pos].aio.mux_total = 0; + pos++; + } + + for(int index = 0; index < MRAA_MOCK_I2C_BUS_COUNT; index++) { + snprintf(b->pins[pos].name, 8, "I2C%dSDA", index); + b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 }; + b->pins[pos].i2c.mux_total = 0; + b->pins[pos].i2c.pinmap = 0; + pos++; + + snprintf(b->pins[pos].name, 8, "I2C%dSCL", index); + b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 }; + b->pins[pos].i2c.mux_total = 0; + b->pins[pos].i2c.pinmap = 0; + pos++; + } + + for(int index = 0; index < MRAA_MOCK_SPI_BUS_COUNT; index++) { + snprintf(b->pins[pos].name, 8, "SPI%dCS", index); + b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 }; + b->pins[pos].spi.mux_total = 0; + b->pins[pos].spi.pinmap = 0; + pos++; + + snprintf(b->pins[pos].name, 9, "SPI%dMOSI", index); + b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 }; + b->pins[pos].spi.mux_total = 0; + b->pins[pos].spi.pinmap = 0; + pos++; + + snprintf(b->pins[pos].name, 9, "SPI%dMISO", index); + b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 }; + b->pins[pos].spi.mux_total = 0; + b->pins[pos].spi.pinmap = 0; + pos++; + + snprintf(b->pins[pos].name, 9, "SPI%dSCLK", index); + b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 }; + b->pins[pos].spi.mux_total = 0; + b->pins[pos].spi.pinmap = 0; + pos++; + } + + for(int index = 0; index < MRAA_MOCK_PWM_DEV_COUNT; index++) { + snprintf(b->pins[pos].name, 8, "PWM%d", index); + b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 }; + b->pins[pos].pwm.pinmap = index; + b->pins[pos].pwm.parent_id = 0; + b->pins[pos].pwm.mux_total = 0; + pos++; + } + + for(int index = 0; index < MRAA_MOCK_UART_DEV_COUNT; index++) { + snprintf(b->pins[pos].name, 8, "UART%dRX", index); + b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 1 }; + b->pins[pos].uart.pinmap = 0; + b->pins[pos].uart.parent_id = 0; + b->pins[pos].uart.mux_total = 0; + pos++; + + snprintf(b->pins[pos].name, 8, "UART%dTX", index); + b->pins[pos].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 1 }; + b->pins[pos].uart.pinmap = 0; + b->pins[pos].uart.parent_id = 0; + b->pins[pos].uart.mux_total = 0; + pos++; + } return b; diff --git a/src/mock/mock_board_pwm.c b/src/mock/mock_board_pwm.c new file mode 100644 index 000000000..74f8c0932 --- /dev/null +++ b/src/mock/mock_board_pwm.c @@ -0,0 +1,76 @@ +/* + * Author: Adelin Dobre + * Copyright (c) 2019 Adelin Dobre. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include + +#include "common.h" +#include "mock/mock_board_pwm.h" + +mraa_result_t +mraa_mock_pwm_init_raw_replace(mraa_pwm_context dev, int pin) +{ + if(dev->pin != pin) { + syslog(LOG_ERR, "pwm_init: Failed to initialize the pin"); + return MRAA_ERROR_INVALID_PARAMETER; + } + dev->owner = 1; + + return MRAA_SUCCESS; +} + +mraa_result_t +mraa_mock_pwm_write_period_replace(mraa_pwm_context dev, int period) +{ + dev->period = period; + + return MRAA_SUCCESS; +} + +mraa_result_t +mraa_mock_pwm_write_duty_replace(mraa_pwm_context dev, int duty) +{ + dev->duty_fp = duty; + + return MRAA_SUCCESS; +} + +int +mraa_mock_pwm_read_duty_replace(mraa_pwm_context dev) +{ + if(dev->duty_fp > INT_MAX || dev->duty_fp < INT_MIN) { + syslog(LOG_ERR, "pwm%i read_duty: Number is invalid", dev->pin); + return -1; + } + + return dev->duty_fp; +} + +mraa_result_t +mraa_mock_pwm_enable_replace(mraa_pwm_context dev, int enable) +{ + return MRAA_SUCCESS; +} + diff --git a/src/pwm/pwm.c b/src/pwm/pwm.c index e3be80ea1..fdefe8776 100644 --- a/src/pwm/pwm.c +++ b/src/pwm/pwm.c @@ -32,6 +32,7 @@ #include "pwm.h" #include "mraa_internal.h" +#include "mock/mock_board.h" #define MAX_SIZE 64 #define SYSFS_PWM "/sys/class/pwm" @@ -220,6 +221,11 @@ mraa_pwm_init(int pin) syslog(LOG_ERR, "pwm_init: Platform Not Initialised"); return NULL; } + +#if defined(MOCKPLAT) + pin += MRAA_PWM_OFFSET; +#endif + if (mraa_is_sub_platform_id(pin)) { syslog(LOG_NOTICE, "pwm_init: Using sub platform"); board = board->sub_platform; diff --git a/tests/mock/i2c_checks_read_bytes_data.py b/tests/mock/i2c_checks_read_bytes_data.py index 5c337e3b3..4398a8838 100755 --- a/tests/mock/i2c_checks_read_bytes_data.py +++ b/tests/mock/i2c_checks_read_bytes_data.py @@ -37,7 +37,7 @@ def tearDown(self): def test_i2c_read_bytes_data(self): self.i2c.address(MRAA_MOCK_I2C_ADDR) # Generate unique data bytes - data_to_write = bytearray([0xEE+i for i in range(MRAA_MOCK_I2C_DATA_LEN)]) + data_to_write = bytearray([0x00+i for i in range(MRAA_MOCK_I2C_DATA_LEN)]) self.i2c.write(data_to_write) # We expect to read the last two bytes expected_res = bytearray(data_to_write[-2:]) @@ -50,7 +50,7 @@ def test_i2c_read_bytes_data(self): def test_i2c_read_bytes_data_length_bigger_than_max(self): self.i2c.address(MRAA_MOCK_I2C_ADDR) # Generate unique data bytes - data_to_write = bytearray([0xEE+i for i in range(MRAA_MOCK_I2C_DATA_LEN)]) + data_to_write = bytearray([0x00+i for i in range(MRAA_MOCK_I2C_DATA_LEN)]) self.i2c.write(data_to_write) # We expect to read the last two bytes expected_res = bytearray(data_to_write[-2:]) diff --git a/tests/mock/i2c_checks_shared.py b/tests/mock/i2c_checks_shared.py index c667e31ae..5330b675a 100755 --- a/tests/mock/i2c_checks_shared.py +++ b/tests/mock/i2c_checks_shared.py @@ -25,5 +25,5 @@ MRAA_I2C_BUS_NUM = 0 # These are defined in mock_board.c MRAA_MOCK_I2C_ADDR = 0x33 -MRAA_MOCK_I2C_DATA_LEN = 10 +MRAA_MOCK_I2C_DATA_LEN = 255 MRAA_MOCK_I2C_DATA_INIT_BYTE = 0xAB diff --git a/tests/mock/platform_checks.py b/tests/mock/platform_checks.py index eceb8249a..f29f0f008 100755 --- a/tests/mock/platform_checks.py +++ b/tests/mock/platform_checks.py @@ -27,7 +27,7 @@ import mraa as m import unittest as u -PLATFORM_PINCOUNT = 10 +PLATFORM_PINCOUNT = 11 PLATFORM_STD_ADC_RES_BITS = 10 PLATFORM_MAX_ADC_RES_BITS = 12 diff --git a/tests/unit/api/api_common_h_unit.cxx b/tests/unit/api/api_common_h_unit.cxx index 73a013b26..5bc63b8aa 100644 --- a/tests/unit/api/api_common_h_unit.cxx +++ b/tests/unit/api/api_common_h_unit.cxx @@ -91,15 +91,15 @@ TEST_F(api_common_h_unit, test_libmraa_common_methods) /* No versioning for the mock platform */ ASSERT_STREQ(NULL, mraa_get_platform_version(0)); - /* Currently 10 pins in the mock platform */ - ASSERT_EQ(10, mraa_get_pin_count()); + /* Currently 11 pins in the mock platform */ + ASSERT_EQ(11, mraa_get_pin_count()); /* Test the other pin/bus counts for the mock platform */ EXPECT_EQ(1, mraa_get_aio_count()); EXPECT_EQ(1, mraa_get_gpio_count()); EXPECT_EQ(1, mraa_get_i2c_bus_count()); EXPECT_EQ(0, mraa_get_i2c_bus_id(0)); - EXPECT_EQ(0, mraa_get_pwm_count()); + EXPECT_EQ(1, mraa_get_pwm_count()); EXPECT_EQ(1, mraa_get_spi_bus_count()); EXPECT_EQ(1, mraa_get_uart_count()); diff --git a/tests/unit/api/api_common_hpp_unit.cxx b/tests/unit/api/api_common_hpp_unit.cxx index 7063b973d..2b201da6a 100644 --- a/tests/unit/api/api_common_hpp_unit.cxx +++ b/tests/unit/api/api_common_hpp_unit.cxx @@ -74,8 +74,8 @@ TEST_F(api_common_hpp_unit, test_libmraa_common_methods) /* No versioning for the mock platform */ ASSERT_EQ("", mraa::getPlatformVersion(0)); - /* Currently 10 pins in the mock platform */ - ASSERT_EQ(10, mraa::getPinCount()); + /* Currently 11 pins in the mock platform */ + ASSERT_EQ(11, mraa::getPinCount()); /* Test the other pin/bus counts for the mock platform */ /* Missing equivalent C++ methods */