{"test_peripheral_io_spi_peripheral_spi_set_bit_order_p2", "rpi3"}
};
+static bool i2c_no_stub_driver = false;
+
+static char* skip_test_list_i2c_no_stub_driver[] = {
+ "test_peripheral_io_i2c_peripheral_i2c_open_p",
+ "test_peripheral_io_i2c_peripheral_i2c_close_p",
+ "test_peripheral_io_i2c_peripheral_i2c_read_p",
+ "test_peripheral_io_i2c_peripheral_i2c_read_n2",
+ "test_peripheral_io_i2c_peripheral_i2c_write_p",
+ "test_peripheral_io_i2c_peripheral_i2c_write_n2",
+ "test_peripheral_io_i2c_peripheral_i2c_read_register_byte_p",
+ "test_peripheral_io_i2c_peripheral_i2c_read_register_byte_n2",
+ "test_peripheral_io_i2c_peripheral_i2c_write_register_byte_p",
+ "test_peripheral_io_i2c_peripheral_i2c_read_register_word_p",
+ "test_peripheral_io_i2c_peripheral_i2c_read_register_word_n2",
+ "test_peripheral_io_i2c_peripheral_i2c_write_register_word_p"
+};
+
static int __get_model_name(char **model_name)
{
int ret = SYSTEM_INFO_ERROR_NONE;
for (int i = 0; i < n; ++i)
if (!strcmp(skip_test_list[i].model_name, model_name) && !strcmp(skip_test_list[i].test_name, name))
return true;
+
+ if (i2c_no_stub_driver) {
+ n = sizeof(skip_test_list_i2c_no_stub_driver) / sizeof(skip_test_list_i2c_no_stub_driver[0]);
+ for (int i = 0; i < n; i++)
+ if (!strcmp(skip_test_list_i2c_no_stub_driver[i], name))
+ return true;
+ }
return false;
}
static void __test_performance_for_function(const char *name, int (*function)(void))
{
+ if (i2c_no_stub_driver) {
+ printf(CYEL "[SKIP]" RESET " performance check for %s skipped.\n", name);
+ return;
+ }
+
struct timespec start, stop, elapsed;
clock_gettime(CLOCK_MONOTONIC, &start);
if (ret != PERIPHERAL_ERROR_NONE)
return;
+ ret = test_peripheral_io_i2c_find_stub_driver();
+ if (ret == PERIPHERAL_ERROR_NO_DEVICE) {
+ printf("Warning - stub driver not found. Tests requiring stub driver will be skipped. (To load the driver run `modprobe i2c-stub chip_addr=<addr>`)\n");
+ i2c_no_stub_driver = true;
+ } else 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");
ret = test_peripheral_io_i2c_peripheral_i2c_open_n1();
ret = test_peripheral_io_i2c_peripheral_i2c_write_register_word_n();
__error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_write_register_word_n");
__test_performance_for_function("open/close", test_peripheral_io_i2c_peripheral_i2c_open_p);
+
+ i2c_no_stub_driver = false;
}
static void __test_peripheral_pwm_run()
#include "test_peripheral_i2c.h"
#define I2C_BUS_INVALID -99
+#define I2C_BUS_MOCK 0 // value for when stub driver is not found, to allow tests that don't require the driver to run
#define I2C_ADDRESS 0x39
#define I2C_ADDRESS_INVALID -99
#define I2C_BUFFER_LEN 10
if (strcmp(model, "rpi3") != 0 && strcmp(model, "rpi4") != 0 && strcmp(model, "artik") != 0)
return PERIPHERAL_ERROR_NO_DEVICE;
+ address = I2C_ADDRESS;
+
+ return PERIPHERAL_ERROR_NONE;
+}
+
+int test_peripheral_io_i2c_find_stub_driver(void)
+{
bus = __find_stub_driver();
- if (bus == -1)
+ if (bus == -1) {
+ bus = I2C_BUS_MOCK;
return PERIPHERAL_ERROR_NO_DEVICE;
-
- address = I2C_ADDRESS;
+ }
return PERIPHERAL_ERROR_NONE;
}