tests: Fix tests code and comments style
This patch applies clang-format settings to most of tests files. Some files were fixed "by-hand" to exclude some lines, which whould be less readable after automatic style fixing. Moreover, some comments (mostly in tests/lib/edid-test.c) were adjusted to match coreboot coding style guidelines. Change-Id: I69f25a7b6d8265800c731754e2fbb2255f482134 Signed-off-by: Jakub Czapiga <jacz@semihalf.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/60970 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
This commit is contained in:
committed by
Felix Held
parent
63ec2ac97a
commit
c08b6a7037
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user