diff options
Diffstat (limited to 'tests/device')
-rw-r--r-- | tests/device/ddr4-test.c | 4 | ||||
-rw-r--r-- | tests/device/i2c-test.c | 90 |
2 files changed, 42 insertions, 52 deletions
diff --git a/tests/device/ddr4-test.c b/tests/device/ddr4-test.c index 3ee1e79f1d..d5d7ee7d36 100644 --- a/tests/device/ddr4-test.c +++ b/tests/device/ddr4-test.c @@ -33,9 +33,7 @@ static void ddr4_speed_mhz_to_mts_test(void **state) int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(ddr4_speed_mhz_to_mts_test) - }; + const struct CMUnitTest tests[] = {cmocka_unit_test(ddr4_speed_mhz_to_mts_test)}; return cb_run_group_tests(tests, NULL, NULL); } diff --git a/tests/device/i2c-test.c b/tests/device/i2c-test.c index 010b8688f9..4b96d940f9 100644 --- a/tests/device/i2c-test.c +++ b/tests/device/i2c-test.c @@ -18,20 +18,27 @@ typedef struct { } i2c_ex_devs_t; i2c_ex_devs_t i2c_ex_devs[] = { - {.bus = 0, .slave = 0xA, .regs = { - {.reg = 0x0, .data = 0xB}, - {.reg = 0x1, .data = 0x6}, - {.reg = 0x2, .data = 0xF}, - } }, - {.bus = 0, .slave = 0x3, .regs = { - {.reg = 0x0, .data = 0xDE}, - {.reg = 0x1, .data = 0xAD}, - {.reg = 0x2, .data = 0xBE}, - } }, + { + .bus = 0, + .slave = 0xA, + .regs = { + {.reg = 0x0, .data = 0xB}, + {.reg = 0x1, .data = 0x6}, + {.reg = 0x2, .data = 0xF}, + } + }, + { + .bus = 0, + .slave = 0x3, + .regs = { + {.reg = 0x0, .data = 0xDE}, + {.reg = 0x1, .data = 0xAD}, + {.reg = 0x2, .data = 0xBE}, + } + }, }; -int platform_i2c_transfer(unsigned int bus, struct i2c_msg *segments, - int count) +int platform_i2c_transfer(unsigned int bus, struct i2c_msg *segments, int count) { int i; int reg; @@ -73,22 +80,19 @@ int platform_i2c_transfer(unsigned int bus, struct i2c_msg *segments, static void mock_expect_params_platform_i2c_transfer(void) { - unsigned long int expected_flags[] = {0, I2C_M_RD, I2C_M_TEN, - I2C_M_RECV_LEN, I2C_M_NOSTART}; + unsigned long int expected_flags[] = {0, I2C_M_RD, I2C_M_TEN, I2C_M_RECV_LEN, + I2C_M_NOSTART}; /* Flags should always be only within supported range */ - expect_in_set_count(platform_i2c_transfer, segments->flags, - expected_flags, -1); + expect_in_set_count(platform_i2c_transfer, segments->flags, expected_flags, -1); - expect_not_value_count(platform_i2c_transfer, segments->buf, - NULL, -1); + expect_not_value_count(platform_i2c_transfer, segments->buf, NULL, -1); - expect_in_range_count(platform_i2c_transfer, count, 1, INT_MAX, - -1); + expect_in_range_count(platform_i2c_transfer, count, 1, INT_MAX, -1); } -#define MASK 0x3 -#define SHIFT 0x1 +#define MASK 0x3 +#define SHIFT 0x1 static void i2c_read_field_test(void **state) { @@ -101,21 +105,17 @@ static void i2c_read_field_test(void **state) with expected value. */ for (i = 0; i < ARRAY_SIZE(i2c_ex_devs); i++) for (j = 0; j < ARRAY_SIZE(i2c_ex_devs[0].regs); j++) { - i2c_read_field(i2c_ex_devs[i].bus, - i2c_ex_devs[i].slave, - i2c_ex_devs[i].regs[j].reg, - &buf, MASK, SHIFT); - assert_int_equal((i2c_ex_devs[i].regs[j].data & - (MASK << SHIFT)) >> SHIFT, buf); + i2c_read_field(i2c_ex_devs[i].bus, i2c_ex_devs[i].slave, + i2c_ex_devs[i].regs[j].reg, &buf, MASK, SHIFT); + assert_int_equal( + (i2c_ex_devs[i].regs[j].data & (MASK << SHIFT)) >> SHIFT, buf); }; /* Read whole registers */ for (i = 0; i < ARRAY_SIZE(i2c_ex_devs); i++) for (j = 0; j < ARRAY_SIZE(i2c_ex_devs[0].regs); j++) { - i2c_read_field(i2c_ex_devs[i].bus, - i2c_ex_devs[i].slave, - i2c_ex_devs[i].regs[j].reg, - &buf, 0xFF, 0); + i2c_read_field(i2c_ex_devs[i].bus, i2c_ex_devs[i].slave, + i2c_ex_devs[i].regs[j].reg, &buf, 0xFF, 0); assert_int_equal(i2c_ex_devs[i].regs[j].data, buf); }; } @@ -133,36 +133,28 @@ static void i2c_write_field_test(void **state) for (j = 0; j < ARRAY_SIZE(i2c_ex_devs[0].regs); j++) { buf = 0x0; tmp = i2c_ex_devs[i].regs[j].data; - i2c_write_field(i2c_ex_devs[i].bus, - i2c_ex_devs[i].slave, - i2c_ex_devs[i].regs[j].reg, - buf, MASK, SHIFT); + i2c_write_field(i2c_ex_devs[i].bus, i2c_ex_devs[i].slave, + i2c_ex_devs[i].regs[j].reg, buf, MASK, SHIFT); assert_int_equal(i2c_ex_devs[i].regs[j].data, - (tmp & ~(MASK << SHIFT)) | (buf << SHIFT)); + (tmp & ~(MASK << SHIFT)) | (buf << SHIFT)); }; /* Set all bits in all registers, this time verify using i2c_read_field() accessor. */ for (i = 0; i < ARRAY_SIZE(i2c_ex_devs); i++) for (j = 0; j < ARRAY_SIZE(i2c_ex_devs[0].regs); j++) { - i2c_write_field(i2c_ex_devs[i].bus, - i2c_ex_devs[i].slave, - i2c_ex_devs[i].regs[j].reg, - 0xFF, 0xFF, 0); - i2c_read_field(i2c_ex_devs[i].bus, - i2c_ex_devs[i].slave, - i2c_ex_devs[i].regs[j].reg, - &buf, 0xFF, 0); + i2c_write_field(i2c_ex_devs[i].bus, i2c_ex_devs[i].slave, + i2c_ex_devs[i].regs[j].reg, 0xFF, 0xFF, 0); + i2c_read_field(i2c_ex_devs[i].bus, i2c_ex_devs[i].slave, + i2c_ex_devs[i].regs[j].reg, &buf, 0xFF, 0); assert_int_equal(buf, 0xFF); }; } int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(i2c_read_field_test), - cmocka_unit_test(i2c_write_field_test) - }; + const struct CMUnitTest tests[] = {cmocka_unit_test(i2c_read_field_test), + cmocka_unit_test(i2c_write_field_test)}; return cb_run_group_tests(tests, NULL, NULL); } |