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:
parent
63ec2ac97a
commit
c08b6a7037
|
@ -13,7 +13,7 @@ static u32 decode_package_length(const char *ptr)
|
||||||
{
|
{
|
||||||
const u8 *aml = (u8 *)ptr;
|
const u8 *aml = (u8 *)ptr;
|
||||||
const u32 offset = (aml[0] == EXT_OP_PREFIX ? 2 : 1);
|
const u32 offset = (aml[0] == EXT_OP_PREFIX ? 2 : 1);
|
||||||
u32 byte_zero_mask = 0x3F; /* Bits [0:5] */
|
u32 byte_zero_mask = 0x3F; /* Bits [0:5] */
|
||||||
u32 byte_count = aml[offset] >> 6;
|
u32 byte_count = aml[offset] >> 6;
|
||||||
u32 package_length = 0;
|
u32 package_length = 0;
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ static void test_acpigen_nested_ifs(void **state)
|
||||||
|
|
||||||
for (int i = 0; i < nesting_level; ++i)
|
for (int i = 0; i < nesting_level; ++i)
|
||||||
assert_int_equal(decode_package_length(block_start[i]),
|
assert_int_equal(decode_package_length(block_start[i]),
|
||||||
block_end[i] - block_start[i] - 1);
|
block_end[i] - block_start[i] - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_acpigen_write_package(void **state)
|
static void test_acpigen_write_package(void **state)
|
||||||
|
@ -203,14 +203,14 @@ static void test_acpigen_scope_with_contents(void **state)
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
const struct CMUnitTest tests[] = {
|
const struct CMUnitTest tests[] = {
|
||||||
cmocka_unit_test_setup_teardown(test_acpigen_single_if,
|
cmocka_unit_test_setup_teardown(test_acpigen_single_if, setup_acpigen,
|
||||||
setup_acpigen, teardown_acpigen),
|
teardown_acpigen),
|
||||||
cmocka_unit_test_setup_teardown(test_acpigen_nested_ifs,
|
cmocka_unit_test_setup_teardown(test_acpigen_nested_ifs, setup_acpigen,
|
||||||
setup_acpigen, teardown_acpigen),
|
teardown_acpigen),
|
||||||
cmocka_unit_test_setup_teardown(test_acpigen_write_package,
|
cmocka_unit_test_setup_teardown(test_acpigen_write_package, setup_acpigen,
|
||||||
setup_acpigen, teardown_acpigen),
|
teardown_acpigen),
|
||||||
cmocka_unit_test_setup_teardown(test_acpigen_scope_with_contents,
|
cmocka_unit_test_setup_teardown(test_acpigen_scope_with_contents, setup_acpigen,
|
||||||
setup_acpigen, teardown_acpigen),
|
teardown_acpigen),
|
||||||
};
|
};
|
||||||
|
|
||||||
return cb_run_group_tests(tests, NULL, NULL);
|
return cb_run_group_tests(tests, NULL, NULL);
|
||||||
|
|
|
@ -14,30 +14,30 @@ static void test_region(void **state)
|
||||||
assert_true(VAL(5) + VAL(10) > VAL(10));
|
assert_true(VAL(5) + VAL(10) > VAL(10));
|
||||||
assert_true(VAL(7) + VAL(10) < VAL(10));
|
assert_true(VAL(7) + VAL(10) < VAL(10));
|
||||||
|
|
||||||
struct region outer = { .offset = VAL(2), .size = VAL(4) };
|
struct region outer = {.offset = VAL(2), .size = VAL(4)};
|
||||||
assert_int_equal(region_offset(&outer), VAL(2));
|
assert_int_equal(region_offset(&outer), VAL(2));
|
||||||
assert_int_equal(region_sz(&outer), VAL(4));
|
assert_int_equal(region_sz(&outer), VAL(4));
|
||||||
assert_int_equal(region_end(&outer), VAL(6));
|
assert_int_equal(region_end(&outer), VAL(6));
|
||||||
|
|
||||||
struct region inner = { .offset = VAL(3), .size = VAL(2) };
|
struct region inner = {.offset = VAL(3), .size = VAL(2)};
|
||||||
assert_true(region_is_subregion(&outer, &inner));
|
assert_true(region_is_subregion(&outer, &inner));
|
||||||
|
|
||||||
struct region touching_bottom = { .offset = VAL(2), .size = VAL(1) };
|
struct region touching_bottom = {.offset = VAL(2), .size = VAL(1)};
|
||||||
assert_true(region_is_subregion(&outer, &touching_bottom));
|
assert_true(region_is_subregion(&outer, &touching_bottom));
|
||||||
|
|
||||||
struct region touching_top = { .offset = VAL(5), .size = VAL(1) };
|
struct region touching_top = {.offset = VAL(5), .size = VAL(1)};
|
||||||
assert_true(region_is_subregion(&outer, &touching_top));
|
assert_true(region_is_subregion(&outer, &touching_top));
|
||||||
|
|
||||||
struct region overlap_bottom = { .offset = VAL(1), .size = VAL(2) };
|
struct region overlap_bottom = {.offset = VAL(1), .size = VAL(2)};
|
||||||
assert_false(region_is_subregion(&outer, &overlap_bottom));
|
assert_false(region_is_subregion(&outer, &overlap_bottom));
|
||||||
|
|
||||||
struct region overlap_top = { .offset = VAL(5), .size = VAL(2) };
|
struct region overlap_top = {.offset = VAL(5), .size = VAL(2)};
|
||||||
assert_false(region_is_subregion(&outer, &overlap_top));
|
assert_false(region_is_subregion(&outer, &overlap_top));
|
||||||
|
|
||||||
struct region below = { .offset = 0, .size = VAL(1) };
|
struct region below = {.offset = 0, .size = VAL(1)};
|
||||||
assert_false(region_is_subregion(&outer, &below));
|
assert_false(region_is_subregion(&outer, &below));
|
||||||
|
|
||||||
struct region above = { .offset = VAL(0xf), .size = VAL(1) };
|
struct region above = {.offset = VAL(0xf), .size = VAL(1)};
|
||||||
assert_false(region_is_subregion(&outer, &above));
|
assert_false(region_is_subregion(&outer, &above));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,8 +58,8 @@ static int mock_unmap(const struct region_device *rdev, void *mapping)
|
||||||
return mock();
|
return mock();
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t mock_readat(const struct region_device *rdev, void *buffer,
|
static ssize_t mock_readat(const struct region_device *rdev, void *buffer, size_t offset,
|
||||||
size_t offset, size_t size)
|
size_t size)
|
||||||
{
|
{
|
||||||
check_expected_ptr(rdev);
|
check_expected_ptr(rdev);
|
||||||
check_expected_ptr(buffer);
|
check_expected_ptr(buffer);
|
||||||
|
@ -73,8 +73,8 @@ static ssize_t mock_readat(const struct region_device *rdev, void *buffer,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t mock_writeat(const struct region_device *rdev, const void *buffer,
|
static ssize_t mock_writeat(const struct region_device *rdev, const void *buffer, size_t offset,
|
||||||
size_t offset, size_t size)
|
size_t size)
|
||||||
{
|
{
|
||||||
check_expected_ptr(rdev);
|
check_expected_ptr(rdev);
|
||||||
check_expected_ptr(buffer);
|
check_expected_ptr(buffer);
|
||||||
|
@ -365,7 +365,7 @@ static void test_mem_rdev(void **state)
|
||||||
|
|
||||||
/* Test read/write/erase of larger chunk. */
|
/* Test read/write/erase of larger chunk. */
|
||||||
size_t offs = 0x47;
|
size_t offs = 0x47;
|
||||||
size_t chunk = 0x72;
|
size_t chunk = 0x72;
|
||||||
memset(backing, 0, size);
|
memset(backing, 0, size);
|
||||||
memset(scratch, 0, size);
|
memset(scratch, 0, size);
|
||||||
memset(scratch + offs, 0x39, chunk);
|
memset(scratch + offs, 0x39, chunk);
|
||||||
|
|
|
@ -42,7 +42,7 @@ static void test_console_log_level(void **state)
|
||||||
for (int i = 0; i < ARRAY_SIZE(combinations); i++) {
|
for (int i = 0; i < ARRAY_SIZE(combinations); i++) {
|
||||||
console_loglevel = combinations[i].log_lvl;
|
console_loglevel = combinations[i].log_lvl;
|
||||||
assert_int_equal(combinations[i].behavior,
|
assert_int_equal(combinations[i].behavior,
|
||||||
console_log_level(combinations[i].msg_lvl));
|
console_log_level(combinations[i].msg_lvl));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +61,7 @@ static int teardown_console_log_level(void **state)
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
const struct CMUnitTest tests[] = {
|
const struct CMUnitTest tests[] = {
|
||||||
cmocka_unit_test_setup_teardown(test_console_log_level,
|
cmocka_unit_test_setup_teardown(test_console_log_level, setup_console_log_level,
|
||||||
setup_console_log_level,
|
|
||||||
teardown_console_log_level),
|
teardown_console_log_level),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,7 @@ static void ddr4_speed_mhz_to_mts_test(void **state)
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
const struct CMUnitTest tests[] = {
|
const struct CMUnitTest tests[] = {cmocka_unit_test(ddr4_speed_mhz_to_mts_test)};
|
||||||
cmocka_unit_test(ddr4_speed_mhz_to_mts_test)
|
|
||||||
};
|
|
||||||
|
|
||||||
return cb_run_group_tests(tests, NULL, NULL);
|
return cb_run_group_tests(tests, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,20 +18,27 @@ typedef struct {
|
||||||
} i2c_ex_devs_t;
|
} i2c_ex_devs_t;
|
||||||
|
|
||||||
i2c_ex_devs_t i2c_ex_devs[] = {
|
i2c_ex_devs_t i2c_ex_devs[] = {
|
||||||
{.bus = 0, .slave = 0xA, .regs = {
|
{
|
||||||
{.reg = 0x0, .data = 0xB},
|
.bus = 0,
|
||||||
{.reg = 0x1, .data = 0x6},
|
.slave = 0xA,
|
||||||
{.reg = 0x2, .data = 0xF},
|
.regs = {
|
||||||
} },
|
{.reg = 0x0, .data = 0xB},
|
||||||
{.bus = 0, .slave = 0x3, .regs = {
|
{.reg = 0x1, .data = 0x6},
|
||||||
{.reg = 0x0, .data = 0xDE},
|
{.reg = 0x2, .data = 0xF},
|
||||||
{.reg = 0x1, .data = 0xAD},
|
}
|
||||||
{.reg = 0x2, .data = 0xBE},
|
},
|
||||||
} },
|
{
|
||||||
|
.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 platform_i2c_transfer(unsigned int bus, struct i2c_msg *segments, int count)
|
||||||
int count)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int reg;
|
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)
|
static void mock_expect_params_platform_i2c_transfer(void)
|
||||||
{
|
{
|
||||||
unsigned long int expected_flags[] = {0, I2C_M_RD, I2C_M_TEN,
|
unsigned long int expected_flags[] = {0, I2C_M_RD, I2C_M_TEN, I2C_M_RECV_LEN,
|
||||||
I2C_M_RECV_LEN, I2C_M_NOSTART};
|
I2C_M_NOSTART};
|
||||||
|
|
||||||
/* Flags should always be only within supported range */
|
/* Flags should always be only within supported range */
|
||||||
expect_in_set_count(platform_i2c_transfer, segments->flags,
|
expect_in_set_count(platform_i2c_transfer, segments->flags, expected_flags, -1);
|
||||||
expected_flags, -1);
|
|
||||||
|
|
||||||
expect_not_value_count(platform_i2c_transfer, segments->buf,
|
expect_not_value_count(platform_i2c_transfer, segments->buf, NULL, -1);
|
||||||
NULL, -1);
|
|
||||||
|
|
||||||
expect_in_range_count(platform_i2c_transfer, count, 1, INT_MAX,
|
expect_in_range_count(platform_i2c_transfer, count, 1, INT_MAX, -1);
|
||||||
-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MASK 0x3
|
#define MASK 0x3
|
||||||
#define SHIFT 0x1
|
#define SHIFT 0x1
|
||||||
|
|
||||||
static void i2c_read_field_test(void **state)
|
static void i2c_read_field_test(void **state)
|
||||||
{
|
{
|
||||||
|
@ -101,21 +105,17 @@ static void i2c_read_field_test(void **state)
|
||||||
with expected value. */
|
with expected value. */
|
||||||
for (i = 0; i < ARRAY_SIZE(i2c_ex_devs); i++)
|
for (i = 0; i < ARRAY_SIZE(i2c_ex_devs); i++)
|
||||||
for (j = 0; j < ARRAY_SIZE(i2c_ex_devs[0].regs); j++) {
|
for (j = 0; j < ARRAY_SIZE(i2c_ex_devs[0].regs); j++) {
|
||||||
i2c_read_field(i2c_ex_devs[i].bus,
|
i2c_read_field(i2c_ex_devs[i].bus, i2c_ex_devs[i].slave,
|
||||||
i2c_ex_devs[i].slave,
|
i2c_ex_devs[i].regs[j].reg, &buf, MASK, SHIFT);
|
||||||
i2c_ex_devs[i].regs[j].reg,
|
assert_int_equal(
|
||||||
&buf, MASK, SHIFT);
|
(i2c_ex_devs[i].regs[j].data & (MASK << SHIFT)) >> SHIFT, buf);
|
||||||
assert_int_equal((i2c_ex_devs[i].regs[j].data &
|
|
||||||
(MASK << SHIFT)) >> SHIFT, buf);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Read whole registers */
|
/* Read whole registers */
|
||||||
for (i = 0; i < ARRAY_SIZE(i2c_ex_devs); i++)
|
for (i = 0; i < ARRAY_SIZE(i2c_ex_devs); i++)
|
||||||
for (j = 0; j < ARRAY_SIZE(i2c_ex_devs[0].regs); j++) {
|
for (j = 0; j < ARRAY_SIZE(i2c_ex_devs[0].regs); j++) {
|
||||||
i2c_read_field(i2c_ex_devs[i].bus,
|
i2c_read_field(i2c_ex_devs[i].bus, i2c_ex_devs[i].slave,
|
||||||
i2c_ex_devs[i].slave,
|
i2c_ex_devs[i].regs[j].reg, &buf, 0xFF, 0);
|
||||||
i2c_ex_devs[i].regs[j].reg,
|
|
||||||
&buf, 0xFF, 0);
|
|
||||||
assert_int_equal(i2c_ex_devs[i].regs[j].data, buf);
|
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++) {
|
for (j = 0; j < ARRAY_SIZE(i2c_ex_devs[0].regs); j++) {
|
||||||
buf = 0x0;
|
buf = 0x0;
|
||||||
tmp = i2c_ex_devs[i].regs[j].data;
|
tmp = i2c_ex_devs[i].regs[j].data;
|
||||||
i2c_write_field(i2c_ex_devs[i].bus,
|
i2c_write_field(i2c_ex_devs[i].bus, i2c_ex_devs[i].slave,
|
||||||
i2c_ex_devs[i].slave,
|
i2c_ex_devs[i].regs[j].reg, buf, MASK, SHIFT);
|
||||||
i2c_ex_devs[i].regs[j].reg,
|
|
||||||
buf, MASK, SHIFT);
|
|
||||||
assert_int_equal(i2c_ex_devs[i].regs[j].data,
|
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
|
/* Set all bits in all registers, this time verify using
|
||||||
i2c_read_field() accessor. */
|
i2c_read_field() accessor. */
|
||||||
for (i = 0; i < ARRAY_SIZE(i2c_ex_devs); i++)
|
for (i = 0; i < ARRAY_SIZE(i2c_ex_devs); i++)
|
||||||
for (j = 0; j < ARRAY_SIZE(i2c_ex_devs[0].regs); j++) {
|
for (j = 0; j < ARRAY_SIZE(i2c_ex_devs[0].regs); j++) {
|
||||||
i2c_write_field(i2c_ex_devs[i].bus,
|
i2c_write_field(i2c_ex_devs[i].bus, i2c_ex_devs[i].slave,
|
||||||
i2c_ex_devs[i].slave,
|
i2c_ex_devs[i].regs[j].reg, 0xFF, 0xFF, 0);
|
||||||
i2c_ex_devs[i].regs[j].reg,
|
i2c_read_field(i2c_ex_devs[i].bus, i2c_ex_devs[i].slave,
|
||||||
0xFF, 0xFF, 0);
|
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(buf, 0xFF);
|
assert_int_equal(buf, 0xFF);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
const struct CMUnitTest tests[] = {
|
const struct CMUnitTest tests[] = {cmocka_unit_test(i2c_read_field_test),
|
||||||
cmocka_unit_test(i2c_read_field_test),
|
cmocka_unit_test(i2c_write_field_test)};
|
||||||
cmocka_unit_test(i2c_write_field_test)
|
|
||||||
};
|
|
||||||
|
|
||||||
return cb_run_group_tests(tests, NULL, NULL);
|
return cb_run_group_tests(tests, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ struct edid_raw {
|
||||||
/* Basic display parameters */
|
/* Basic display parameters */
|
||||||
uint8_t video_input_type;
|
uint8_t video_input_type;
|
||||||
uint8_t horizontal_size; /* [cm] */
|
uint8_t horizontal_size; /* [cm] */
|
||||||
uint8_t vertical_size; /* [cm] */
|
uint8_t vertical_size; /* [cm] */
|
||||||
uint8_t display_gamma;
|
uint8_t display_gamma;
|
||||||
uint8_t supported_features;
|
uint8_t supported_features;
|
||||||
|
|
||||||
|
@ -46,157 +46,152 @@ struct edid_raw {
|
||||||
uint8_t checksum;
|
uint8_t checksum;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
_Static_assert(sizeof(struct edid_raw) == 128,
|
_Static_assert(sizeof(struct edid_raw) == 128, "assert failed: edid_raw size mismatch");
|
||||||
"assert failed: edid_raw size mismatch");
|
|
||||||
|
|
||||||
#define EDID_HEADER_RAW { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00 }
|
#define EDID_HEADER_RAW \
|
||||||
#define EDID_HEADER_INVALID_RAW { 0, 0, 0, 0, 0, 0, 0, 0 }
|
{ \
|
||||||
|
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00 \
|
||||||
|
}
|
||||||
|
#define EDID_HEADER_INVALID_RAW \
|
||||||
|
{ \
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0 \
|
||||||
|
}
|
||||||
|
|
||||||
#define EDID_MANUFACTURER_ID 0xcb55
|
#define EDID_MANUFACTURER_ID 0xcb55
|
||||||
#define EDID_MANUFACTURER_NAME "UNK"
|
#define EDID_MANUFACTURER_NAME "UNK"
|
||||||
#define EDID_PRODUCT_CODE 0x1234
|
#define EDID_PRODUCT_CODE 0x1234
|
||||||
#define EDID_SERIAL_NUMBER 0x56789ABC
|
#define EDID_SERIAL_NUMBER 0x56789ABC
|
||||||
#define EDID_MANUFACTURE_WEEK 23u
|
#define EDID_MANUFACTURE_WEEK 23u
|
||||||
#define EDID_MANUFACTURE_NO_WEEK 0u
|
#define EDID_MANUFACTURE_NO_WEEK 0u
|
||||||
#define EDID_MANUFACTURE_YEAR (2015u - 1990u)
|
#define EDID_MANUFACTURE_YEAR (2015u - 1990u)
|
||||||
|
|
||||||
/* Video Input Definition for Analog Video Signal Interface */
|
/* Video Input Definition for Analog Video Signal Interface */
|
||||||
#define EDID_ANALOG_VSI (0u << 7)
|
#define EDID_ANALOG_VSI (0u << 7)
|
||||||
#define EDID_SIGNAL_LEVEL_0 0u
|
#define EDID_SIGNAL_LEVEL_0 0u
|
||||||
#define EDID_SIGNAL_LEVEL_1 (1u << 5)
|
#define EDID_SIGNAL_LEVEL_1 (1u << 5)
|
||||||
#define EDID_SIGNAL_LEVEL_2 (2u << 5)
|
#define EDID_SIGNAL_LEVEL_2 (2u << 5)
|
||||||
#define EDID_SIGNAL_LEVEL_3 (3u << 5)
|
#define EDID_SIGNAL_LEVEL_3 (3u << 5)
|
||||||
#define EDID_VIDEO_SETUP_BLANK_EQ_BLACK 0u
|
#define EDID_VIDEO_SETUP_BLANK_EQ_BLACK 0u
|
||||||
#define EDID_VIDEO_SETUP_BLANK_TO_BLACK (1u << 4)
|
#define EDID_VIDEO_SETUP_BLANK_TO_BLACK (1u << 4)
|
||||||
#define EDID_SEPARATE_SYNC_H_AND_V(v) ((v != 0 ? 0x1 : 0x0) << 3)
|
#define EDID_SEPARATE_SYNC_H_AND_V(v) ((v != 0 ? 0x1 : 0x0) << 3)
|
||||||
#define EDID_COMPOSITE_SYNC_H(v) ((v != 0 ? 0x1 : 0x0) << 2)
|
#define EDID_COMPOSITE_SYNC_H(v) ((v != 0 ? 0x1 : 0x0) << 2)
|
||||||
#define EDID_COMPOSITE_SYNC_ON_GREEN(v) ((v != 0 ? 0x1 : 0x0) << 1)
|
#define EDID_COMPOSITE_SYNC_ON_GREEN(v) ((v != 0 ? 0x1 : 0x0) << 1)
|
||||||
#define EDID_SERRATION_VSYNC(v) (v != 0 ? 0x1 : 0x0)
|
#define EDID_SERRATION_VSYNC(v) (v != 0 ? 0x1 : 0x0)
|
||||||
|
|
||||||
/* Video Input Definition for Digital Video Signal Interface */
|
/* Video Input Definition for Digital Video Signal Interface */
|
||||||
#define EDID_DIGITAL_VSI (1u << 7)
|
#define EDID_DIGITAL_VSI (1u << 7)
|
||||||
#define EDID_COLOR_BIT_DEPTH_UNDEFINED 0u
|
#define EDID_COLOR_BIT_DEPTH_UNDEFINED 0u
|
||||||
#define EDID_COLOR_BIT_DEPTH_6B (1u << 4)
|
#define EDID_COLOR_BIT_DEPTH_6B (1u << 4)
|
||||||
#define EDID_COLOR_BIT_DEPTH_8B (2u << 4)
|
#define EDID_COLOR_BIT_DEPTH_8B (2u << 4)
|
||||||
#define EDID_COLOR_BIT_DEPTH_10B (3u << 4)
|
#define EDID_COLOR_BIT_DEPTH_10B (3u << 4)
|
||||||
#define EDID_COLOR_BIT_DEPTH_12B (4u << 4)
|
#define EDID_COLOR_BIT_DEPTH_12B (4u << 4)
|
||||||
#define EDID_COLOR_BIT_DEPTH_14B (5u << 4)
|
#define EDID_COLOR_BIT_DEPTH_14B (5u << 4)
|
||||||
#define EDID_COLOR_BIT_DEPTH_16B (6u << 4)
|
#define EDID_COLOR_BIT_DEPTH_16B (6u << 4)
|
||||||
#define EDID_INTERFACE_UNDEFINED 0u
|
#define EDID_INTERFACE_UNDEFINED 0u
|
||||||
#define EDID_INTERFACE_DVI 1u
|
#define EDID_INTERFACE_DVI 1u
|
||||||
#define EDID_INTERFACE_HDMI_A 2u
|
#define EDID_INTERFACE_HDMI_A 2u
|
||||||
#define EDID_INTERFACE_HDMI_B 3u
|
#define EDID_INTERFACE_HDMI_B 3u
|
||||||
#define EDID_INTERFACE_MDDI 4u
|
#define EDID_INTERFACE_MDDI 4u
|
||||||
#define EDID_INTERFACE_DP 5u
|
#define EDID_INTERFACE_DP 5u
|
||||||
|
|
||||||
/* BEGIN Supported features */
|
/* BEGIN Supported features */
|
||||||
#define EDID_STANDBY_MODE(v) ((v != 0 ? 0x1 : 0x0) << 7)
|
#define EDID_STANDBY_MODE(v) ((v != 0 ? 0x1 : 0x0) << 7)
|
||||||
#define EDID_SUSPEND_MODE(v) ((v != 0 ? 0x1 : 0x0) << 6)
|
#define EDID_SUSPEND_MODE(v) ((v != 0 ? 0x1 : 0x0) << 6)
|
||||||
#define EDID_ACTIVE_OFF(v) ((v != 0 ? 0x1 : 0x0) << 5)
|
#define EDID_ACTIVE_OFF(v) ((v != 0 ? 0x1 : 0x0) << 5)
|
||||||
/* For analog interface */
|
/* For analog interface */
|
||||||
#define EDID_COLOR_TYPE_MONO 0u
|
#define EDID_COLOR_TYPE_MONO 0u
|
||||||
#define EDID_COLOR_TYPE_RGB (1u << 3)
|
#define EDID_COLOR_TYPE_RGB (1u << 3)
|
||||||
#define EDID_COLOR_TYPE_NON_RGB (2u << 3)
|
#define EDID_COLOR_TYPE_NON_RGB (2u << 3)
|
||||||
#define EDID_COLOR_TYPE_UNDEFINED (3u << 3)
|
#define EDID_COLOR_TYPE_UNDEFINED (3u << 3)
|
||||||
/* For digital interface */
|
/* For digital interface */
|
||||||
#define EDID_COLOR_FORMAT_RGB444 0u
|
#define EDID_COLOR_FORMAT_RGB444 0u
|
||||||
#define EDID_COLOR_FORMAT_RGB444_YCRCB444 (1u << 3)
|
#define EDID_COLOR_FORMAT_RGB444_YCRCB444 (1u << 3)
|
||||||
#define EDID_COLOR_FORMAT_RGB444_YCRCB422 (2u << 3)
|
#define EDID_COLOR_FORMAT_RGB444_YCRCB422 (2u << 3)
|
||||||
#define EDID_COLOR_FORMAT_RGB444_YCRCB422_YCRCB422 (3u << 3)
|
#define EDID_COLOR_FORMAT_RGB444_YCRCB422_YCRCB422 (3u << 3)
|
||||||
|
|
||||||
#define EDID_SRGB_SUPPORTED(v) (((v) == 0 ? 0u : 1u) << 2)
|
#define EDID_SRGB_SUPPORTED(v) (((v) == 0 ? 0u : 1u) << 2)
|
||||||
#define EDID_PREFERRED_TIMING_EXTENDED_INFO (1u << 1)
|
#define EDID_PREFERRED_TIMING_EXTENDED_INFO (1u << 1)
|
||||||
#define EDID_PREFERRED_TIMING_NO_EXTENDED_INFO 0u
|
#define EDID_PREFERRED_TIMING_NO_EXTENDED_INFO 0u
|
||||||
#define EDID_DISPLAY_FREQUENCY_CONTINUOUS 1u
|
#define EDID_DISPLAY_FREQUENCY_CONTINUOUS 1u
|
||||||
#define EDID_DISPLAY_FREQUENCY_NON_CONTINUOUS 0u
|
#define EDID_DISPLAY_FREQUENCY_NON_CONTINUOUS 0u
|
||||||
/* END Supported features */
|
/* END Supported features */
|
||||||
|
|
||||||
/* Red X 0.640 */
|
/* Red X 0.640 */
|
||||||
#define EDID_COLOR_R_X 0x25
|
#define EDID_COLOR_R_X 0x25
|
||||||
/* Red Y 0.330 */
|
/* Red Y 0.330 */
|
||||||
#define EDID_COLOR_R_Y 0x152
|
#define EDID_COLOR_R_Y 0x152
|
||||||
/* Green X 0.300 */
|
/* Green X 0.300 */
|
||||||
#define EDID_COLOR_G_X 0x13a
|
#define EDID_COLOR_G_X 0x13a
|
||||||
/* Green Y 0.600 */
|
/* Green Y 0.600 */
|
||||||
#define EDID_COLOR_G_Y 0x267
|
#define EDID_COLOR_G_Y 0x267
|
||||||
/* Blue X 0.150 */
|
/* Blue X 0.150 */
|
||||||
#define EDID_COLOR_B_X 0x9a
|
#define EDID_COLOR_B_X 0x9a
|
||||||
/* Blue Y 0.060 */
|
/* Blue Y 0.060 */
|
||||||
#define EDID_COLOR_B_Y 0x3e
|
#define EDID_COLOR_B_Y 0x3e
|
||||||
/* White X 0.3125 */
|
/* White X 0.3125 */
|
||||||
#define EDID_COLOR_W_X 0xa
|
#define EDID_COLOR_W_X 0xa
|
||||||
/* White Y 0.3291 */
|
/* White Y 0.3291 */
|
||||||
#define EDID_COLOR_W_Y 0x22a
|
#define EDID_COLOR_W_Y 0x22a
|
||||||
|
|
||||||
/* 1 and 0 bits of each color */
|
/* 1 and 0 bits of each color */
|
||||||
#define EDID_COLOR_R_X10_Y10 (((EDID_COLOR_R_X & 0x3) << 2) | (EDID_COLOR_R_Y & 0x3))
|
#define EDID_COLOR_R_X10_Y10 (((EDID_COLOR_R_X & 0x3) << 2) | (EDID_COLOR_R_Y & 0x3))
|
||||||
#define EDID_COLOR_G_X10_Y10 (((EDID_COLOR_G_X & 0x3) << 2) | (EDID_COLOR_G_Y & 0x3))
|
#define EDID_COLOR_G_X10_Y10 (((EDID_COLOR_G_X & 0x3) << 2) | (EDID_COLOR_G_Y & 0x3))
|
||||||
#define EDID_COLOR_B_X10_Y10 (((EDID_COLOR_B_X & 0x3) << 2) | (EDID_COLOR_B_Y & 0x3))
|
#define EDID_COLOR_B_X10_Y10 (((EDID_COLOR_B_X & 0x3) << 2) | (EDID_COLOR_B_Y & 0x3))
|
||||||
#define EDID_COLOR_W_X10_Y10 (((EDID_COLOR_W_X & 0x3) << 2) | (EDID_COLOR_W_Y & 0x3))
|
#define EDID_COLOR_W_X10_Y10 (((EDID_COLOR_W_X & 0x3) << 2) | (EDID_COLOR_W_Y & 0x3))
|
||||||
|
|
||||||
/* Concatenated 0 and 1 bits of each color. To be put
|
/* Concatenated 0 and 1 bits of each color. To be put
|
||||||
* as first and second byte of color characteristic. */
|
* as first and second byte of color characteristic. */
|
||||||
#define EDID_COLOR_RG_XY ((EDID_COLOR_R_X10_Y10 << 4) | EDID_COLOR_G_X10_Y10)
|
#define EDID_COLOR_RG_XY ((EDID_COLOR_R_X10_Y10 << 4) | EDID_COLOR_G_X10_Y10)
|
||||||
#define EDID_COLOR_BW_XY ((EDID_COLOR_B_X10_Y10 << 4) | EDID_COLOR_W_X10_Y10)
|
#define EDID_COLOR_BW_XY ((EDID_COLOR_B_X10_Y10 << 4) | EDID_COLOR_W_X10_Y10)
|
||||||
|
|
||||||
/* Bits 9 through 2 of each color */
|
/* Bits 9 through 2 of each color */
|
||||||
#define EDID_COLOR_R_X92 (EDID_COLOR_R_X >> 2)
|
#define EDID_COLOR_R_X92 (EDID_COLOR_R_X >> 2)
|
||||||
#define EDID_COLOR_R_Y92 (EDID_COLOR_R_Y >> 2)
|
#define EDID_COLOR_R_Y92 (EDID_COLOR_R_Y >> 2)
|
||||||
#define EDID_COLOR_G_X92 (EDID_COLOR_G_X >> 2)
|
#define EDID_COLOR_G_X92 (EDID_COLOR_G_X >> 2)
|
||||||
#define EDID_COLOR_G_Y92 (EDID_COLOR_G_Y >> 2)
|
#define EDID_COLOR_G_Y92 (EDID_COLOR_G_Y >> 2)
|
||||||
#define EDID_COLOR_B_X92 (EDID_COLOR_B_X >> 2)
|
#define EDID_COLOR_B_X92 (EDID_COLOR_B_X >> 2)
|
||||||
#define EDID_COLOR_B_Y92 (EDID_COLOR_B_Y >> 2)
|
#define EDID_COLOR_B_Y92 (EDID_COLOR_B_Y >> 2)
|
||||||
#define EDID_COLOR_W_X92 (EDID_COLOR_W_X >> 2)
|
#define EDID_COLOR_W_X92 (EDID_COLOR_W_X >> 2)
|
||||||
#define EDID_COLOR_W_Y92 (EDID_COLOR_W_Y >> 2)
|
#define EDID_COLOR_W_Y92 (EDID_COLOR_W_Y >> 2)
|
||||||
|
|
||||||
#define EDID_ESTABLISHED_TIMINGS_1_800x600_60Hz 1u
|
#define EDID_ESTABLISHED_TIMINGS_1_800x600_60Hz 1u
|
||||||
#define EDID_ESTABLISHED_TIMINGS_1_800x600_56Hz (1u << 1)
|
#define EDID_ESTABLISHED_TIMINGS_1_800x600_56Hz (1u << 1)
|
||||||
#define EDID_ESTABLISHED_TIMINGS_1_640x480_75Hz (1u << 2)
|
#define EDID_ESTABLISHED_TIMINGS_1_640x480_75Hz (1u << 2)
|
||||||
#define EDID_ESTABLISHED_TIMINGS_1_640x480_72Hz (1u << 3)
|
#define EDID_ESTABLISHED_TIMINGS_1_640x480_72Hz (1u << 3)
|
||||||
#define EDID_ESTABLISHED_TIMINGS_1_640x480_67Hz (1u << 4)
|
#define EDID_ESTABLISHED_TIMINGS_1_640x480_67Hz (1u << 4)
|
||||||
#define EDID_ESTABLISHED_TIMINGS_1_640x480_60Hz (1u << 5)
|
#define EDID_ESTABLISHED_TIMINGS_1_640x480_60Hz (1u << 5)
|
||||||
#define EDID_ESTABLISHED_TIMINGS_1_720x400_88Hz (1u << 6)
|
#define EDID_ESTABLISHED_TIMINGS_1_720x400_88Hz (1u << 6)
|
||||||
#define EDID_ESTABLISHED_TIMINGS_1_720x400_70Hz (1u << 7)
|
#define EDID_ESTABLISHED_TIMINGS_1_720x400_70Hz (1u << 7)
|
||||||
|
|
||||||
#define EDID_ESTABLISHED_TIMINGS_2_1280x1024_75Hz 1u
|
#define EDID_ESTABLISHED_TIMINGS_2_1280x1024_75Hz 1u
|
||||||
#define EDID_ESTABLISHED_TIMINGS_2_1024x768_75Hz (1u << 1)
|
#define EDID_ESTABLISHED_TIMINGS_2_1024x768_75Hz (1u << 1)
|
||||||
#define EDID_ESTABLISHED_TIMINGS_2_1024x768_70Hz (1u << 2)
|
#define EDID_ESTABLISHED_TIMINGS_2_1024x768_70Hz (1u << 2)
|
||||||
#define EDID_ESTABLISHED_TIMINGS_2_1024x768_60Hz (1u << 3)
|
#define EDID_ESTABLISHED_TIMINGS_2_1024x768_60Hz (1u << 3)
|
||||||
#define EDID_ESTABLISHED_TIMINGS_2_1024x768_80HzI (1u << 4)
|
#define EDID_ESTABLISHED_TIMINGS_2_1024x768_80HzI (1u << 4)
|
||||||
#define EDID_ESTABLISHED_TIMINGS_2_832x624_75Hz (1u << 5)
|
#define EDID_ESTABLISHED_TIMINGS_2_832x624_75Hz (1u << 5)
|
||||||
#define EDID_ESTABLISHED_TIMINGS_2_800x600_75Hz (1u << 6)
|
#define EDID_ESTABLISHED_TIMINGS_2_800x600_75Hz (1u << 6)
|
||||||
#define EDID_ESTABLISHED_TIMINGS_2_800x600_72Hz (1u << 7)
|
#define EDID_ESTABLISHED_TIMINGS_2_800x600_72Hz (1u << 7)
|
||||||
|
|
||||||
#define EDID_MANUFACTURERS_TIMINGS_1152x870_75Hz (1u << 7)
|
#define EDID_MANUFACTURERS_TIMINGS_1152x870_75Hz (1u << 7)
|
||||||
|
|
||||||
#define EDID_HORIZONTAL_ACCESSIBLE_PIXELS(px) (((px) / 8 - 31) & 0xFF)
|
#define EDID_HORIZONTAL_ACCESSIBLE_PIXELS(px) (((px) / 8 - 31) & 0xFF)
|
||||||
#define EDID_ASPECT_RATIO_16_10 0u
|
#define EDID_ASPECT_RATIO_16_10 0u
|
||||||
#define EDID_ASPECT_RATIO_4_3 (1u << 6)
|
#define EDID_ASPECT_RATIO_4_3 (1u << 6)
|
||||||
#define EDID_ASPECT_RATIO_5_4 (2u << 6)
|
#define EDID_ASPECT_RATIO_5_4 (2u << 6)
|
||||||
#define EDID_ASPECT_RATIO_16_9 (3u << 6)
|
#define EDID_ASPECT_RATIO_16_9 (3u << 6)
|
||||||
#define EDID_FIELD_REFRESH_RATE(hz) (((hz) - 60) & 0x1f)
|
#define EDID_FIELD_REFRESH_RATE(hz) (((hz)-60) & 0x1f)
|
||||||
|
|
||||||
#define EDID_PIXEL_CLOCK(v) (((v) / 10000) & 0xFFFF)
|
#define EDID_PIXEL_CLOCK(v) (((v) / 10000) & 0xFFFF)
|
||||||
|
|
||||||
#define EDID_RAW_DEFAULT_PARAMS .header = EDID_HEADER_RAW, \
|
#define EDID_RAW_DEFAULT_PARAMS \
|
||||||
.edid_version = 1, \
|
.header = EDID_HEADER_RAW, .edid_version = 1, .edid_revision = 4, \
|
||||||
.edid_revision = 4, \
|
.manufacturer_id = EDID_MANUFACTURER_ID, .product_code = EDID_PRODUCT_CODE, \
|
||||||
.manufacturer_id = EDID_MANUFACTURER_ID, \
|
.serial_number = EDID_SERIAL_NUMBER, .manufacture_week = EDID_MANUFACTURE_NO_WEEK, \
|
||||||
.product_code = EDID_PRODUCT_CODE, \
|
.manufacture_year = EDID_MANUFACTURE_YEAR, \
|
||||||
.serial_number = EDID_SERIAL_NUMBER, \
|
.color_characteristics = { \
|
||||||
.manufacture_week = EDID_MANUFACTURE_NO_WEEK, \
|
EDID_COLOR_RG_XY, EDID_COLOR_BW_XY, EDID_COLOR_R_X92, EDID_COLOR_R_Y92, \
|
||||||
.manufacture_year = EDID_MANUFACTURE_YEAR, \
|
EDID_COLOR_G_X92, EDID_COLOR_G_Y92, EDID_COLOR_B_X92, EDID_COLOR_B_Y92, \
|
||||||
.color_characteristics = { \
|
EDID_COLOR_W_X92, EDID_COLOR_W_Y92, \
|
||||||
EDID_COLOR_RG_XY, \
|
}
|
||||||
EDID_COLOR_BW_XY, \
|
|
||||||
EDID_COLOR_R_X92, \
|
|
||||||
EDID_COLOR_R_Y92, \
|
|
||||||
EDID_COLOR_G_X92, \
|
|
||||||
EDID_COLOR_G_Y92, \
|
|
||||||
EDID_COLOR_B_X92, \
|
|
||||||
EDID_COLOR_B_Y92, \
|
|
||||||
EDID_COLOR_W_X92, \
|
|
||||||
EDID_COLOR_W_Y92, \
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* TESTS_LIB_EDID_H */
|
#endif /* TESTS_LIB_EDID_H */
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
|
|
||||||
static struct cbfs_boot_device cbd;
|
static struct cbfs_boot_device cbd;
|
||||||
|
|
||||||
static u8 aligned_cbfs_buffer[(sizeof(struct cbfs_test_file) + CBFS_ALIGNMENT) * 10]
|
static u8 aligned_cbfs_buffer[(sizeof(struct cbfs_test_file) + CBFS_ALIGNMENT) * 10] __aligned(
|
||||||
__aligned(CBFS_ALIGNMENT);
|
CBFS_ALIGNMENT);
|
||||||
|
|
||||||
static u8 *unaligned_cbfs_buffer = &aligned_cbfs_buffer[3];
|
static u8 *unaligned_cbfs_buffer = &aligned_cbfs_buffer[3];
|
||||||
static uintptr_t unaligned_cbfs_buffer_size = sizeof(aligned_cbfs_buffer) - 3;
|
static uintptr_t unaligned_cbfs_buffer_size = sizeof(aligned_cbfs_buffer) - 3;
|
||||||
|
@ -22,7 +22,7 @@ static u8 cbfs_mcache[TEST_MCACHE_SIZE] __aligned(CBFS_MCACHE_ALIGNMENT);
|
||||||
|
|
||||||
/* Add files to CBFS buffer. NULL in files list equals to one CBFS_ALIGNMENT of spacing. */
|
/* Add files to CBFS buffer. NULL in files list equals to one CBFS_ALIGNMENT of spacing. */
|
||||||
static int create_cbfs(const struct cbfs_test_file *files[], const size_t nfiles, u8 *buffer,
|
static int create_cbfs(const struct cbfs_test_file *files[], const size_t nfiles, u8 *buffer,
|
||||||
const size_t buffer_size)
|
const size_t buffer_size)
|
||||||
{
|
{
|
||||||
u8 *data_ptr = buffer;
|
u8 *data_ptr = buffer;
|
||||||
size_t file_size = 0;
|
size_t file_size = 0;
|
||||||
|
@ -34,7 +34,7 @@ static int create_cbfs(const struct cbfs_test_file *files[], const size_t nfiles
|
||||||
assert_true(&data_ptr[file_size] < &buffer[buffer_size]);
|
assert_true(&data_ptr[file_size] < &buffer[buffer_size]);
|
||||||
} else {
|
} else {
|
||||||
file_size = be32_to_cpu(files[i]->header.len)
|
file_size = be32_to_cpu(files[i]->header.len)
|
||||||
+ be32_to_cpu(files[i]->header.offset);
|
+ be32_to_cpu(files[i]->header.offset);
|
||||||
assert_true(&data_ptr[file_size] < &buffer[buffer_size]);
|
assert_true(&data_ptr[file_size] < &buffer[buffer_size]);
|
||||||
memcpy(data_ptr, files[i], file_size);
|
memcpy(data_ptr, files[i], file_size);
|
||||||
}
|
}
|
||||||
|
@ -386,7 +386,8 @@ static void test_cbfs_image_not_aligned(void **state)
|
||||||
size_t size_out;
|
size_t size_out;
|
||||||
struct cbfs_test_state *s = *state;
|
struct cbfs_test_state *s = *state;
|
||||||
const struct cbfs_test_file *cbfs_files[] = {
|
const struct cbfs_test_file *cbfs_files[] = {
|
||||||
&test_file_int_1, &test_file_2,
|
&test_file_int_1,
|
||||||
|
&test_file_2,
|
||||||
};
|
};
|
||||||
assert_int_equal(0, create_cbfs(cbfs_files, ARRAY_SIZE(cbfs_files), &s->cbfs_buf[5],
|
assert_int_equal(0, create_cbfs(cbfs_files, ARRAY_SIZE(cbfs_files), &s->cbfs_buf[5],
|
||||||
s->cbfs_size - 5));
|
s->cbfs_size - 5));
|
||||||
|
@ -663,8 +664,9 @@ static void test_cbfs_two_files_with_same_name(void **state)
|
||||||
size_out = 0;
|
size_out = 0;
|
||||||
expect_lookup_result(CB_SUCCESS);
|
expect_lookup_result(CB_SUCCESS);
|
||||||
mapping = cbfs_map(TEST_DATA_INT_1_FILENAME, &size_out);
|
mapping = cbfs_map(TEST_DATA_INT_1_FILENAME, &size_out);
|
||||||
assert_ptr_equal(mapping, &s->cbfs_buf[third_file_start
|
assert_ptr_equal(
|
||||||
+ be32_to_cpu(test_file_int_1.header.offset)]);
|
mapping,
|
||||||
|
&s->cbfs_buf[third_file_start + be32_to_cpu(test_file_int_1.header.offset)]);
|
||||||
assert_int_equal(size_out, be32_to_cpu(test_file_int_1.header.len));
|
assert_int_equal(size_out, be32_to_cpu(test_file_int_1.header.len));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -723,9 +725,8 @@ static void test_cbfs_attributes_offset_larger_than_offset(void **state)
|
||||||
assert_true(be32_to_cpu(test_file_2.header.attributes_offset) != 0);
|
assert_true(be32_to_cpu(test_file_2.header.attributes_offset) != 0);
|
||||||
memcpy(s->cbfs_buf, &test_file_2, sizeof(test_file_2));
|
memcpy(s->cbfs_buf, &test_file_2, sizeof(test_file_2));
|
||||||
f = (struct cbfs_test_file *)s->cbfs_buf;
|
f = (struct cbfs_test_file *)s->cbfs_buf;
|
||||||
f->header.attributes_offset = cpu_to_be32(
|
f->header.attributes_offset = cpu_to_be32(sizeof(struct cbfs_file) + FILENAME_SIZE
|
||||||
sizeof(struct cbfs_file) + FILENAME_SIZE
|
+ sizeof(struct cbfs_file_attr_compression));
|
||||||
+ sizeof(struct cbfs_file_attr_compression));
|
|
||||||
f->header.offset = cpu_to_be32(sizeof(struct cbfs_file) + FILENAME_SIZE);
|
f->header.offset = cpu_to_be32(sizeof(struct cbfs_file) + FILENAME_SIZE);
|
||||||
|
|
||||||
assert_int_equal(CB_SUCCESS, cbfs_init_boot_device(&cbd, NULL));
|
assert_int_equal(CB_SUCCESS, cbfs_init_boot_device(&cbd, NULL));
|
||||||
|
@ -943,8 +944,9 @@ static void test_cbfs_attributes_offset_uint32_max(void **state)
|
||||||
EMPTY_WRAP( \
|
EMPTY_WRAP( \
|
||||||
CBFS_LOOKUP_NAME_SETUP_PRESTATE_COMMON_TEST( \
|
CBFS_LOOKUP_NAME_SETUP_PRESTATE_COMMON_TEST( \
|
||||||
("aligned, " name), (test_fn), setup_test_cbfs_aligned, (prestate)), \
|
("aligned, " name), (test_fn), setup_test_cbfs_aligned, (prestate)), \
|
||||||
CBFS_LOOKUP_NAME_SETUP_PRESTATE_COMMON_TEST( \
|
CBFS_LOOKUP_NAME_SETUP_PRESTATE_COMMON_TEST(("unaligned, " name), (test_fn), \
|
||||||
("unaligned, " name), (test_fn), setup_test_cbfs_unaligned, (prestate)))
|
setup_test_cbfs_unaligned, \
|
||||||
|
(prestate)))
|
||||||
|
|
||||||
#define CBFS_LOOKUP_TEST(test_fn) CBFS_LOOKUP_NAME_PRESTATE_TEST(#test_fn, test_fn, NULL)
|
#define CBFS_LOOKUP_TEST(test_fn) CBFS_LOOKUP_NAME_PRESTATE_TEST(#test_fn, test_fn, NULL)
|
||||||
|
|
||||||
|
|
|
@ -47,10 +47,11 @@ void test_cbmemc_tx_byte(void **state)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
u32 cursor;
|
u32 cursor;
|
||||||
const unsigned char data[] = "Random testing string\n"
|
const unsigned char data[] =
|
||||||
"`1234567890-=~!@#$%^&*()_+\n"
|
"Random testing string\n"
|
||||||
"abcdefghijklmnopqrstuvwxyz\n"
|
"`1234567890-=~!@#$%^&*()_+\n"
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ\n";
|
"abcdefghijklmnopqrstuvwxyz\n"
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ\n";
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(data); ++i)
|
for (i = 0; i < ARRAY_SIZE(data); ++i)
|
||||||
cbmemc_tx_byte(data[i]);
|
cbmemc_tx_byte(data[i]);
|
||||||
|
@ -69,15 +70,16 @@ void test_cbmemc_tx_byte_overflow(void **state)
|
||||||
u32 cursor;
|
u32 cursor;
|
||||||
u32 flags;
|
u32 flags;
|
||||||
const uint32_t console_size = current_console->size;
|
const uint32_t console_size = current_console->size;
|
||||||
const unsigned char data[] = "Another random string\n"
|
const unsigned char data[] =
|
||||||
"abcdefghijklmnopqrstuvwxyz\n"
|
"Another random string\n"
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"
|
"abcdefghijklmnopqrstuvwxyz\n"
|
||||||
"`1234567890-=~!@#$%^&*()_+\n";
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"
|
||||||
|
"`1234567890-=~!@#$%^&*()_+\n";
|
||||||
const int data_size = ARRAY_SIZE(data) - 1;
|
const int data_size = ARRAY_SIZE(data) - 1;
|
||||||
const int data_stream_length = console_size + data_size;
|
const int data_stream_length = console_size + data_size;
|
||||||
const int overflow_bytes = data_stream_length % console_size;
|
const int overflow_bytes = data_stream_length % console_size;
|
||||||
unsigned char *check_buffer =
|
unsigned char *check_buffer =
|
||||||
(unsigned char *)malloc(sizeof(unsigned char) * console_size);
|
(unsigned char *)malloc(sizeof(unsigned char) * console_size);
|
||||||
|
|
||||||
/* Fill console buffer */
|
/* Fill console buffer */
|
||||||
for (i = 0; i < console_size; ++i)
|
for (i = 0; i < console_size; ++i)
|
||||||
|
@ -102,16 +104,13 @@ void test_cbmemc_tx_byte_overflow(void **state)
|
||||||
assert_int_equal(data_size, cursor);
|
assert_int_equal(data_size, cursor);
|
||||||
|
|
||||||
/* Check if overflow buffer was overwritten */
|
/* Check if overflow buffer was overwritten */
|
||||||
assert_memory_not_equal(current_console->body,
|
assert_memory_not_equal(current_console->body, data, overflow_bytes);
|
||||||
data,
|
|
||||||
overflow_bytes);
|
|
||||||
|
|
||||||
/* Check if rest of the buffer contents, that should not be overridden,
|
/* Check if rest of the buffer contents, that should not be overridden,
|
||||||
* is the same.
|
* is the same.
|
||||||
*/
|
*/
|
||||||
assert_memory_equal(¤t_console->body[overflow_bytes],
|
assert_memory_equal(¤t_console->body[overflow_bytes],
|
||||||
check_buffer + overflow_bytes,
|
check_buffer + overflow_bytes, console_size - overflow_bytes);
|
||||||
console_size - overflow_bytes);
|
|
||||||
|
|
||||||
free(check_buffer);
|
free(check_buffer);
|
||||||
}
|
}
|
||||||
|
@ -120,10 +119,10 @@ int main(void)
|
||||||
{
|
{
|
||||||
const struct CMUnitTest tests[] = {
|
const struct CMUnitTest tests[] = {
|
||||||
cmocka_unit_test_teardown(test_cbmemc_init, teardown_cbmemc),
|
cmocka_unit_test_teardown(test_cbmemc_init, teardown_cbmemc),
|
||||||
cmocka_unit_test_setup_teardown(test_cbmemc_tx_byte,
|
cmocka_unit_test_setup_teardown(test_cbmemc_tx_byte, setup_cbmemc,
|
||||||
setup_cbmemc, teardown_cbmemc),
|
teardown_cbmemc),
|
||||||
cmocka_unit_test_setup_teardown(test_cbmemc_tx_byte_overflow,
|
cmocka_unit_test_setup_teardown(test_cbmemc_tx_byte_overflow, setup_cbmemc,
|
||||||
setup_cbmemc, teardown_cbmemc),
|
teardown_cbmemc),
|
||||||
};
|
};
|
||||||
|
|
||||||
return cb_run_group_tests(tests, NULL, NULL);
|
return cb_run_group_tests(tests, NULL, NULL);
|
||||||
|
|
|
@ -180,14 +180,14 @@ void test_stage_cache_load_stage(void **state)
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
const struct CMUnitTest tests[] = {
|
const struct CMUnitTest tests[] = {
|
||||||
cmocka_unit_test_setup_teardown(test_stage_cache_add,
|
cmocka_unit_test_setup_teardown(test_stage_cache_add, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_stage_cache_add_raw,
|
cmocka_unit_test_setup_teardown(test_stage_cache_add_raw, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_stage_cache_get_raw,
|
cmocka_unit_test_setup_teardown(test_stage_cache_get_raw, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_stage_cache_load_stage,
|
cmocka_unit_test_setup_teardown(test_stage_cache_load_stage, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
};
|
};
|
||||||
|
|
||||||
return cb_run_group_tests(tests, NULL, NULL);
|
return cb_run_group_tests(tests, NULL, NULL);
|
||||||
|
|
|
@ -7,12 +7,9 @@
|
||||||
#include <ip_checksum.h>
|
#include <ip_checksum.h>
|
||||||
|
|
||||||
static const uint8_t test_data_simple[] = {
|
static const uint8_t test_data_simple[] = {
|
||||||
0x64, 0x3b, 0x33, 0x17, 0x34, 0x74, 0x62, 0x30,
|
0x64, 0x3b, 0x33, 0x17, 0x34, 0x74, 0x62, 0x30, 0x75, 0x73, 0xf3, 0x11, 0x30, 0x2c,
|
||||||
0x75, 0x73, 0xf3, 0x11, 0x30, 0x2c, 0x34, 0x35,
|
0x34, 0x35, 0x6d, 0x39, 0x69, 0x32, 0x23, 0x24, 0x76, 0x71, 0x77, 0x30, 0x39, 0x75,
|
||||||
0x6d, 0x39, 0x69, 0x32, 0x23, 0x24, 0x76, 0x71,
|
0x76, 0x35, 0x71, 0x32, 0x40, 0x46, 0x34, 0x34, 0xBB, 0x03, 0x66, 0x52};
|
||||||
0x77, 0x30, 0x39, 0x75, 0x76, 0x35, 0x71, 0x32,
|
|
||||||
0x40, 0x46, 0x34, 0x34, 0xBB, 0x03, 0x66, 0x52
|
|
||||||
};
|
|
||||||
static const size_t test_data_simple_sz = ARRAY_SIZE(test_data_simple);
|
static const size_t test_data_simple_sz = ARRAY_SIZE(test_data_simple);
|
||||||
static const unsigned long test_data_simple_checksum = 0x4267;
|
static const unsigned long test_data_simple_checksum = 0x4267;
|
||||||
|
|
||||||
|
@ -81,7 +78,7 @@ static void test_add_ip_checksums(void **state)
|
||||||
{
|
{
|
||||||
unsigned long res_1 = compute_ip_checksum(test_data_simple, test_data_simple_sz / 2);
|
unsigned long res_1 = compute_ip_checksum(test_data_simple, test_data_simple_sz / 2);
|
||||||
unsigned long res_2 = compute_ip_checksum(test_data_simple + test_data_simple_sz / 2,
|
unsigned long res_2 = compute_ip_checksum(test_data_simple + test_data_simple_sz / 2,
|
||||||
test_data_simple_sz / 2);
|
test_data_simple_sz / 2);
|
||||||
unsigned long res_sum = add_ip_checksums(test_data_simple_sz / 2, res_1, res_2);
|
unsigned long res_sum = add_ip_checksums(test_data_simple_sz / 2, res_1, res_2);
|
||||||
|
|
||||||
assert_int_equal(test_data_simple_checksum, res_sum);
|
assert_int_equal(test_data_simple_checksum, res_sum);
|
||||||
|
|
|
@ -43,11 +43,10 @@ static struct lb_record *lb_first_record(struct lb_header *header)
|
||||||
return rec;
|
return rec;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LB_RECORD_FOR_EACH(record_ptr, index, header) \
|
#define LB_RECORD_FOR_EACH(record_ptr, index, header) \
|
||||||
for (index = 0, record_ptr = lb_first_record(header); \
|
for (index = 0, record_ptr = lb_first_record(header); index < header->table_entries; \
|
||||||
index < header->table_entries; \
|
record_ptr = (struct lb_record *)((uintptr_t)record_ptr + record_ptr->size), \
|
||||||
record_ptr = (struct lb_record *)((uintptr_t)record_ptr \
|
index++)
|
||||||
+ record_ptr->size), index++)
|
|
||||||
|
|
||||||
static void test_lb_add_gpios(void **state)
|
static void test_lb_add_gpios(void **state)
|
||||||
{
|
{
|
||||||
|
@ -77,7 +76,7 @@ static void test_lb_add_gpios(void **state)
|
||||||
assert_int_equal(sizeof(gpios) + 2 * sizeof(gpios[0]), gpios_table->size);
|
assert_int_equal(sizeof(gpios) + 2 * sizeof(gpios[0]), gpios_table->size);
|
||||||
assert_memory_equal(&gpios_table->gpios[0], gpios, sizeof(gpios));
|
assert_memory_equal(&gpios_table->gpios[0], gpios, sizeof(gpios));
|
||||||
assert_memory_equal(&gpios_table->gpios[ARRAY_SIZE(gpios)], &gpios[1],
|
assert_memory_equal(&gpios_table->gpios[ARRAY_SIZE(gpios)], &gpios[1],
|
||||||
2 * sizeof(gpios[0]));
|
2 * sizeof(gpios[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t tables_buffer[sizeof(struct lb_header) + 10 * KiB];
|
uint8_t tables_buffer[sizeof(struct lb_header) + 10 * KiB];
|
||||||
|
@ -169,20 +168,18 @@ static void test_write_coreboot_forwarding_table(void **state)
|
||||||
uint8_t forwarding_table_buffer[sizeof(struct lb_header)
|
uint8_t forwarding_table_buffer[sizeof(struct lb_header)
|
||||||
+ 2 * sizeof(struct lb_forward)];
|
+ 2 * sizeof(struct lb_forward)];
|
||||||
struct lb_header *forward_header =
|
struct lb_header *forward_header =
|
||||||
(struct lb_header *)ALIGN_UP((uintptr_t)forwarding_table_buffer, 16);
|
(struct lb_header *)ALIGN_UP((uintptr_t)forwarding_table_buffer, 16);
|
||||||
size_t forwarding_table_size =
|
size_t forwarding_table_size = write_coreboot_forwarding_table(
|
||||||
write_coreboot_forwarding_table((uintptr_t)forwarding_table_buffer,
|
(uintptr_t)forwarding_table_buffer, (uintptr_t)header);
|
||||||
(uintptr_t)header);
|
size_t expected_forwarding_table_size =
|
||||||
size_t expected_forwarding_table_size = ALIGN_UP((uintptr_t)forwarding_table_buffer, 16)
|
ALIGN_UP((uintptr_t)forwarding_table_buffer, 16) + sizeof(struct lb_header)
|
||||||
+ sizeof(struct lb_header)
|
+ sizeof(struct lb_forward) - (uintptr_t)forwarding_table_buffer;
|
||||||
+ sizeof(struct lb_forward)
|
|
||||||
- (uintptr_t)forwarding_table_buffer;
|
|
||||||
assert_int_equal(expected_forwarding_table_size, forwarding_table_size);
|
assert_int_equal(expected_forwarding_table_size, forwarding_table_size);
|
||||||
|
|
||||||
assert_int_equal(1, forward_header->table_entries);
|
assert_int_equal(1, forward_header->table_entries);
|
||||||
assert_int_equal(sizeof(struct lb_forward), forward_header->table_bytes);
|
assert_int_equal(sizeof(struct lb_forward), forward_header->table_bytes);
|
||||||
assert_ptr_equal(header,
|
assert_ptr_equal(header,
|
||||||
((struct lb_forward *)lb_first_record(forward_header))->forward);
|
((struct lb_forward *)lb_first_record(forward_header))->forward);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mocks for write_tables() */
|
/* Mocks for write_tables() */
|
||||||
|
@ -214,8 +211,8 @@ void arch_write_tables(uintptr_t coreboot_table)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct resource mock_bootmem_ranges[] = {
|
struct resource mock_bootmem_ranges[] = {
|
||||||
{ .base = 0x1000, .size = 0x2000, .flags = LB_MEM_RAM },
|
{.base = 0x1000, .size = 0x2000, .flags = LB_MEM_RAM},
|
||||||
{ .base = 0x0000, .size = 0x4000, .flags = LB_MEM_RAM },
|
{.base = 0x0000, .size = 0x4000, .flags = LB_MEM_RAM},
|
||||||
};
|
};
|
||||||
|
|
||||||
void bootmem_write_memory_table(struct lb_memory *mem)
|
void bootmem_write_memory_table(struct lb_memory *mem)
|
||||||
|
@ -346,14 +343,15 @@ static void test_write_tables(void **state)
|
||||||
/* At least one entry should be present. */
|
/* At least one entry should be present. */
|
||||||
assert_int_not_equal(0, header->table_entries);
|
assert_int_not_equal(0, header->table_entries);
|
||||||
|
|
||||||
LB_RECORD_FOR_EACH(record, i, header) {
|
LB_RECORD_FOR_EACH(record, i, header)
|
||||||
|
{
|
||||||
switch (record->tag) {
|
switch (record->tag) {
|
||||||
case LB_TAG_MEMORY:
|
case LB_TAG_MEMORY:
|
||||||
/* Should be the same as in bootmem_write_memory_table() */
|
/* Should be the same as in bootmem_write_memory_table() */
|
||||||
assert_int_equal(sizeof(struct lb_memory)
|
assert_int_equal(sizeof(struct lb_memory)
|
||||||
+ ARRAY_SIZE(mock_bootmem_ranges)
|
+ ARRAY_SIZE(mock_bootmem_ranges)
|
||||||
* sizeof(struct lb_memory_range),
|
* sizeof(struct lb_memory_range),
|
||||||
record->size);
|
record->size);
|
||||||
|
|
||||||
const struct lb_memory *memory = (struct lb_memory *)record;
|
const struct lb_memory *memory = (struct lb_memory *)record;
|
||||||
const struct lb_memory_range *range;
|
const struct lb_memory_range *range;
|
||||||
|
@ -366,38 +364,45 @@ static void test_write_tables(void **state)
|
||||||
|
|
||||||
value = pack_lb64(res->base);
|
value = pack_lb64(res->base);
|
||||||
assert_memory_equal(&value, &range->start,
|
assert_memory_equal(&value, &range->start,
|
||||||
sizeof(struct lb_uint64));
|
sizeof(struct lb_uint64));
|
||||||
value = pack_lb64(res->size);
|
value = pack_lb64(res->size);
|
||||||
assert_memory_equal(&value, &range->size,
|
assert_memory_equal(&value, &range->size,
|
||||||
sizeof(struct lb_uint64));
|
sizeof(struct lb_uint64));
|
||||||
assert_int_equal(range->type, res->flags);
|
assert_int_equal(range->type, res->flags);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case LB_TAG_MAINBOARD:
|
case LB_TAG_MAINBOARD:
|
||||||
/* Mainboard record contains its header followed
|
/* Mainboard record contains its header followed
|
||||||
by two null-terminated strings */
|
by two null-terminated strings */
|
||||||
assert_int_equal(ALIGN_UP(sizeof(struct lb_mainboard) +
|
assert_int_equal(ALIGN_UP(sizeof(struct lb_mainboard)
|
||||||
ARRAY_SIZE(mainboard_vendor) +
|
+ ARRAY_SIZE(mainboard_vendor)
|
||||||
ARRAY_SIZE(mainboard_part_number), 8), record->size);
|
+ ARRAY_SIZE(mainboard_part_number),
|
||||||
|
8),
|
||||||
|
record->size);
|
||||||
break;
|
break;
|
||||||
case LB_TAG_VERSION:
|
case LB_TAG_VERSION:
|
||||||
assert_int_equal(ALIGN_UP(sizeof(struct lb_string)
|
assert_int_equal(ALIGN_UP(sizeof(struct lb_string)
|
||||||
+ ARRAY_SIZE(coreboot_version), 8), record->size);
|
+ ARRAY_SIZE(coreboot_version),
|
||||||
|
8),
|
||||||
|
record->size);
|
||||||
break;
|
break;
|
||||||
case LB_TAG_EXTRA_VERSION:
|
case LB_TAG_EXTRA_VERSION:
|
||||||
assert_int_equal(ALIGN_UP(sizeof(struct lb_string)
|
assert_int_equal(ALIGN_UP(sizeof(struct lb_string)
|
||||||
+ ARRAY_SIZE(coreboot_extra_version), 8),
|
+ ARRAY_SIZE(coreboot_extra_version),
|
||||||
record->size);
|
8),
|
||||||
|
record->size);
|
||||||
break;
|
break;
|
||||||
case LB_TAG_BUILD:
|
case LB_TAG_BUILD:
|
||||||
assert_int_equal(ALIGN_UP(sizeof(struct lb_string)
|
assert_int_equal(
|
||||||
+ ARRAY_SIZE(coreboot_build), 8),
|
ALIGN_UP(sizeof(struct lb_string) + ARRAY_SIZE(coreboot_build),
|
||||||
record->size);
|
8),
|
||||||
|
record->size);
|
||||||
break;
|
break;
|
||||||
case LB_TAG_COMPILE_TIME:
|
case LB_TAG_COMPILE_TIME:
|
||||||
assert_int_equal(ALIGN_UP(sizeof(struct lb_string)
|
assert_int_equal(ALIGN_UP(sizeof(struct lb_string)
|
||||||
+ ARRAY_SIZE(coreboot_compile_time), 8),
|
+ ARRAY_SIZE(coreboot_compile_time),
|
||||||
record->size);
|
8),
|
||||||
|
record->size);
|
||||||
break;
|
break;
|
||||||
case LB_TAG_SERIAL:
|
case LB_TAG_SERIAL:
|
||||||
assert_int_equal(sizeof(struct lb_serial), record->size);
|
assert_int_equal(sizeof(struct lb_serial), record->size);
|
||||||
|
@ -428,7 +433,7 @@ static void test_write_tables(void **state)
|
||||||
assert_int_equal(sizeof(struct lb_boot_media_params), record->size);
|
assert_int_equal(sizeof(struct lb_boot_media_params), record->size);
|
||||||
|
|
||||||
const struct lb_boot_media_params *bmp =
|
const struct lb_boot_media_params *bmp =
|
||||||
(struct lb_boot_media_params *)record;
|
(struct lb_boot_media_params *)record;
|
||||||
const struct cbfs_boot_device *cbd = cbfs_get_boot_device(false);
|
const struct cbfs_boot_device *cbd = cbfs_get_boot_device(false);
|
||||||
const struct region_device *boot_dev = boot_device_ro();
|
const struct region_device *boot_dev = boot_device_ro();
|
||||||
assert_int_equal(region_device_offset(&cbd->rdev), bmp->cbfs_offset);
|
assert_int_equal(region_device_offset(&cbd->rdev), bmp->cbfs_offset);
|
||||||
|
@ -441,13 +446,11 @@ static void test_write_tables(void **state)
|
||||||
assert_int_equal(sizeof(struct lb_cbmem_entry), record->size);
|
assert_int_equal(sizeof(struct lb_cbmem_entry), record->size);
|
||||||
|
|
||||||
const struct lb_cbmem_entry *cbmem_entry =
|
const struct lb_cbmem_entry *cbmem_entry =
|
||||||
(struct lb_cbmem_entry *)record;
|
(struct lb_cbmem_entry *)record;
|
||||||
const LargestIntegralType expected_tags[] = {
|
const LargestIntegralType expected_tags[] = {CBMEM_ID_CBTABLE,
|
||||||
CBMEM_ID_CBTABLE,
|
CBMEM_ID_MMC_STATUS};
|
||||||
CBMEM_ID_MMC_STATUS
|
assert_in_set(cbmem_entry->id, expected_tags,
|
||||||
};
|
ARRAY_SIZE(expected_tags));
|
||||||
assert_in_set(cbmem_entry->id,
|
|
||||||
expected_tags, ARRAY_SIZE(expected_tags));
|
|
||||||
break;
|
break;
|
||||||
case LB_TAG_TSC_INFO:
|
case LB_TAG_TSC_INFO:
|
||||||
assert_int_equal(sizeof(struct lb_tsc_info), record->size);
|
assert_int_equal(sizeof(struct lb_tsc_info), record->size);
|
||||||
|
@ -465,10 +468,10 @@ static void test_write_tables(void **state)
|
||||||
assert_int_equal(sizeof(struct lb_board_config), record->size);
|
assert_int_equal(sizeof(struct lb_board_config), record->size);
|
||||||
|
|
||||||
const struct lb_board_config *board_config =
|
const struct lb_board_config *board_config =
|
||||||
(struct lb_board_config *)record;
|
(struct lb_board_config *)record;
|
||||||
const struct lb_uint64 expected_fw_version = pack_lb64(fw_config_get());
|
const struct lb_uint64 expected_fw_version = pack_lb64(fw_config_get());
|
||||||
assert_memory_equal(&expected_fw_version,
|
assert_memory_equal(&expected_fw_version, &board_config->fw_config,
|
||||||
&board_config->fw_config, sizeof(struct lb_uint64));
|
sizeof(struct lb_uint64));
|
||||||
assert_int_equal(board_id(), board_config->board_id);
|
assert_int_equal(board_id(), board_config->board_id);
|
||||||
assert_int_equal(ram_code(), board_config->ram_code);
|
assert_int_equal(ram_code(), board_config->ram_code);
|
||||||
assert_int_equal(sku_id(), board_config->sku_id);
|
assert_int_equal(sku_id(), board_config->sku_id);
|
||||||
|
@ -488,8 +491,7 @@ int main(void)
|
||||||
cmocka_unit_test_setup(test_lb_add_console, setup_test_header),
|
cmocka_unit_test_setup(test_lb_add_console, setup_test_header),
|
||||||
cmocka_unit_test_setup(test_multiple_entries, setup_test_header),
|
cmocka_unit_test_setup(test_multiple_entries, setup_test_header),
|
||||||
cmocka_unit_test_setup(test_write_coreboot_forwarding_table, setup_test_header),
|
cmocka_unit_test_setup(test_write_coreboot_forwarding_table, setup_test_header),
|
||||||
cmocka_unit_test_setup_teardown(test_write_tables,
|
cmocka_unit_test_setup_teardown(test_write_tables, setup_write_tables_test,
|
||||||
setup_write_tables_test,
|
|
||||||
teardown_write_tables_test),
|
teardown_write_tables_test),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,38 +4,25 @@
|
||||||
#include <crc_byte.h>
|
#include <crc_byte.h>
|
||||||
|
|
||||||
static const uint8_t test_data_bytes[] = {
|
static const uint8_t test_data_bytes[] = {
|
||||||
0x2f, 0x8f, 0x2d, 0x06, 0xc2, 0x11, 0x0c, 0xaf,
|
0x2f, 0x8f, 0x2d, 0x06, 0xc2, 0x11, 0x0c, 0xaf, 0xd7, 0x4b, 0x48, 0x71, 0xce, 0x3c,
|
||||||
0xd7, 0x4b, 0x48, 0x71, 0xce, 0x3c, 0xfe, 0x29,
|
0xfe, 0x29, 0x90, 0xf6, 0x33, 0x6d, 0x79, 0x23, 0x9d, 0x84, 0x58, 0x5c, 0xcc, 0xf1,
|
||||||
0x90, 0xf6, 0x33, 0x6d, 0x79, 0x23, 0x9d, 0x84,
|
0xa1, 0xf2, 0x39, 0x22, 0xdc, 0x63, 0xe0, 0x44, 0x0a, 0x95, 0x36, 0xee, 0x53, 0xb3,
|
||||||
0x58, 0x5c, 0xcc, 0xf1, 0xa1, 0xf2, 0x39, 0x22,
|
0x61, 0x2c, 0x4a, 0xf4, 0x8b, 0x32, 0xeb, 0x94, 0x86, 0x55, 0x41, 0x27, 0xa4, 0xbd,
|
||||||
0xdc, 0x63, 0xe0, 0x44, 0x0a, 0x95, 0x36, 0xee,
|
0x0f, 0xc1, 0x4f, 0xfb, 0xb6, 0xa3, 0xc5, 0x38, 0x99, 0xfc, 0xca, 0xf8, 0x8e, 0x72,
|
||||||
0x53, 0xb3, 0x61, 0x2c, 0x4a, 0xf4, 0x8b, 0x32,
|
0xaa, 0xed, 0x6b, 0xb2, 0xd3, 0xd4, 0xd6, 0x81, 0x7d, 0x24, 0x56, 0x9f, 0x7a, 0x21,
|
||||||
0xeb, 0x94, 0x86, 0x55, 0x41, 0x27, 0xa4, 0xbd,
|
0x67, 0xac, 0x6a, 0x98, 0xf7, 0xd1, 0xad, 0x01, 0xdb, 0xc6, 0x80, 0x34, 0x8d, 0x51,
|
||||||
0x0f, 0xc1, 0x4f, 0xfb, 0xb6, 0xa3, 0xc5, 0x38,
|
0x60, 0x3e, 0xd2, 0x52, 0x0e, 0x26, 0x12, 0xb1, 0x13, 0xa2, 0x88, 0x04, 0x66, 0xb0,
|
||||||
0x99, 0xfc, 0xca, 0xf8, 0x8e, 0x72, 0xaa, 0xed,
|
0x3b, 0xc8, 0x1b, 0x7f, 0x92, 0x4e, 0xb8, 0xe9, 0x70, 0xe3, 0xfa, 0x76, 0x3a, 0xa7,
|
||||||
0x6b, 0xb2, 0xd3, 0xd4, 0xd6, 0x81, 0x7d, 0x24,
|
0x4c, 0x25, 0x91, 0x54, 0x19, 0xea, 0x50, 0x37, 0xd8, 0xb4, 0x47, 0x49, 0xbf, 0xc4,
|
||||||
0x56, 0x9f, 0x7a, 0x21, 0x67, 0xac, 0x6a, 0x98,
|
0xb7, 0xd0, 0x93, 0xda, 0x6c, 0x03, 0x9b, 0x15, 0xbb, 0xfd, 0xe7, 0xdd, 0x2e, 0x31,
|
||||||
0xf7, 0xd1, 0xad, 0x01, 0xdb, 0xc6, 0x80, 0x34,
|
0x68, 0x46, 0xa0, 0x43, 0xcd, 0x08, 0x8c, 0xff, 0x40, 0xcf, 0x1a, 0x7c, 0x69, 0x59,
|
||||||
0x8d, 0x51, 0x60, 0x3e, 0xd2, 0x52, 0x0e, 0x26,
|
0xc0, 0x5b, 0x83, 0x17, 0x10, 0x14, 0x9e, 0x1d, 0xc3, 0xa6, 0x5f, 0x4d, 0x9c, 0xa5,
|
||||||
0x12, 0xb1, 0x13, 0xa2, 0x88, 0x04, 0x66, 0xb0,
|
0x73, 0x77, 0x87, 0x96, 0x65, 0x0b, 0xec, 0xc7, 0xd9, 0x85, 0x1c, 0xae, 0x18, 0x5e,
|
||||||
0x3b, 0xc8, 0x1b, 0x7f, 0x92, 0x4e, 0xb8, 0xe9,
|
0x09, 0x78, 0x2b, 0x82, 0x1f, 0xe6, 0xc9, 0x64, 0x6f, 0x20, 0x16, 0x57, 0x9a, 0xbe,
|
||||||
0x70, 0xe3, 0xfa, 0x76, 0x3a, 0xa7, 0x4c, 0x25,
|
0xd5, 0xe2, 0x89, 0x3f, 0xdf, 0xe4, 0x7e, 0xde, 0x30, 0xa9, 0x74, 0xe5, 0xab, 0x07,
|
||||||
0x91, 0x54, 0x19, 0xea, 0x50, 0x37, 0xd8, 0xb4,
|
0x35, 0x5d, 0x2a, 0x28, 0xcb, 0xf0, 0x8a, 0xef, 0x5a, 0xe1, 0x75, 0x42, 0xf9, 0xba,
|
||||||
0x47, 0x49, 0xbf, 0xc4, 0xb7, 0xd0, 0x93, 0xda,
|
0x02, 0xbc, 0xf5, 0x45, 0x05, 0x0d, 0x3d, 0x62, 0xb9, 0x00, 0x7b, 0x1e, 0xe8, 0xb5,
|
||||||
0x6c, 0x03, 0x9b, 0x15, 0xbb, 0xfd, 0xe7, 0xdd,
|
0x97, 0x6e, 0xa8, 0xf3,
|
||||||
0x2e, 0x31, 0x68, 0x46, 0xa0, 0x43, 0xcd, 0x08,
|
|
||||||
0x8c, 0xff, 0x40, 0xcf, 0x1a, 0x7c, 0x69, 0x59,
|
|
||||||
0xc0, 0x5b, 0x83, 0x17, 0x10, 0x14, 0x9e, 0x1d,
|
|
||||||
0xc3, 0xa6, 0x5f, 0x4d, 0x9c, 0xa5, 0x73, 0x77,
|
|
||||||
0x87, 0x96, 0x65, 0x0b, 0xec, 0xc7, 0xd9, 0x85,
|
|
||||||
0x1c, 0xae, 0x18, 0x5e, 0x09, 0x78, 0x2b, 0x82,
|
|
||||||
0x1f, 0xe6, 0xc9, 0x64, 0x6f, 0x20, 0x16, 0x57,
|
|
||||||
0x9a, 0xbe, 0xd5, 0xe2, 0x89, 0x3f, 0xdf, 0xe4,
|
|
||||||
0x7e, 0xde, 0x30, 0xa9, 0x74, 0xe5, 0xab, 0x07,
|
|
||||||
0x35, 0x5d, 0x2a, 0x28, 0xcb, 0xf0, 0x8a, 0xef,
|
|
||||||
0x5a, 0xe1, 0x75, 0x42, 0xf9, 0xba, 0x02, 0xbc,
|
|
||||||
0xf5, 0x45, 0x05, 0x0d, 0x3d, 0x62, 0xb9, 0x00,
|
|
||||||
0x7b, 0x1e, 0xe8, 0xb5, 0x97, 0x6e, 0xa8, 0xf3,
|
|
||||||
};
|
};
|
||||||
static const size_t test_data_bytes_sz = ARRAY_SIZE(test_data_bytes);
|
static const size_t test_data_bytes_sz = ARRAY_SIZE(test_data_bytes);
|
||||||
static const uint8_t test_data_crc7_checksum = 0x30;
|
static const uint8_t test_data_crc7_checksum = 0x30;
|
||||||
|
@ -191,9 +178,8 @@ static void test_crc16_byte_static_data(void **state)
|
||||||
|
|
||||||
/* Calculating CRC of data with its CRC should yield zero if data
|
/* Calculating CRC of data with its CRC should yield zero if data
|
||||||
and/or checksum is correct */
|
and/or checksum is correct */
|
||||||
assert_int_equal(0,
|
assert_int_equal(0, crc16_byte(crc16_byte(crc_value, test_data_crc16_checksum >> 8),
|
||||||
crc16_byte(crc16_byte(crc_value, test_data_crc16_checksum >> 8),
|
test_data_crc16_checksum & 0xFF));
|
||||||
test_data_crc16_checksum & 0xFF));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_crc32_byte_zeros(void **state)
|
static void test_crc32_byte_zeros(void **state)
|
||||||
|
|
|
@ -22,33 +22,28 @@ static void test_smbios_bus_width_to_spd_width_parametrized(smbios_memory_type d
|
||||||
extension_8bits = SPD_ECC_8BIT_LP5_DDR5;
|
extension_8bits = SPD_ECC_8BIT_LP5_DDR5;
|
||||||
|
|
||||||
assert_int_equal(MEMORY_BUS_WIDTH_64 | extension_8bits,
|
assert_int_equal(MEMORY_BUS_WIDTH_64 | extension_8bits,
|
||||||
smbios_bus_width_to_spd_width(ddr_type, 64 + 8, 64));
|
smbios_bus_width_to_spd_width(ddr_type, 64 + 8, 64));
|
||||||
assert_int_equal(MEMORY_BUS_WIDTH_32 | extension_8bits,
|
assert_int_equal(MEMORY_BUS_WIDTH_32 | extension_8bits,
|
||||||
smbios_bus_width_to_spd_width(ddr_type, 32 + 8, 32));
|
smbios_bus_width_to_spd_width(ddr_type, 32 + 8, 32));
|
||||||
assert_int_equal(MEMORY_BUS_WIDTH_16 | extension_8bits,
|
assert_int_equal(MEMORY_BUS_WIDTH_16 | extension_8bits,
|
||||||
smbios_bus_width_to_spd_width(ddr_type, 16 + 8, 16));
|
smbios_bus_width_to_spd_width(ddr_type, 16 + 8, 16));
|
||||||
assert_int_equal(MEMORY_BUS_WIDTH_8 | extension_8bits,
|
assert_int_equal(MEMORY_BUS_WIDTH_8 | extension_8bits,
|
||||||
smbios_bus_width_to_spd_width(ddr_type, 8 + 8, 8));
|
smbios_bus_width_to_spd_width(ddr_type, 8 + 8, 8));
|
||||||
/* Incorrect data width. Fallback to 8-bit */
|
/* Incorrect data width. Fallback to 8-bit */
|
||||||
assert_int_equal(MEMORY_BUS_WIDTH_8 | extension_8bits,
|
assert_int_equal(MEMORY_BUS_WIDTH_8 | extension_8bits,
|
||||||
smbios_bus_width_to_spd_width(ddr_type, 15 + 8, 15));
|
smbios_bus_width_to_spd_width(ddr_type, 15 + 8, 15));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_smbios_bus_width_to_spd_width(void **state)
|
static void test_smbios_bus_width_to_spd_width(void **state)
|
||||||
{
|
{
|
||||||
smbios_memory_type memory_type[] = {
|
smbios_memory_type memory_type[] = {
|
||||||
MEMORY_TYPE_DDR2,
|
MEMORY_TYPE_DDR2, MEMORY_TYPE_DDR3, MEMORY_TYPE_DDR4, MEMORY_TYPE_DDR5,
|
||||||
MEMORY_TYPE_DDR3,
|
MEMORY_TYPE_LPDDR3, MEMORY_TYPE_LPDDR4, MEMORY_TYPE_LPDDR5,
|
||||||
MEMORY_TYPE_DDR4,
|
|
||||||
MEMORY_TYPE_DDR5,
|
|
||||||
MEMORY_TYPE_LPDDR3,
|
|
||||||
MEMORY_TYPE_LPDDR4,
|
|
||||||
MEMORY_TYPE_LPDDR5,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int i = 0; i < ARRAY_SIZE(memory_type); i++) {
|
for (int i = 0; i < ARRAY_SIZE(memory_type); i++) {
|
||||||
print_message("test_smbios_bus_width_to_spd_width_parametrized(%d)\n",
|
print_message("test_smbios_bus_width_to_spd_width_parametrized(%d)\n",
|
||||||
memory_type[i]);
|
memory_type[i]);
|
||||||
test_smbios_bus_width_to_spd_width_parametrized(memory_type[i]);
|
test_smbios_bus_width_to_spd_width_parametrized(memory_type[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,43 +86,34 @@ static void test_smbios_memory_size_to_mib(void **state)
|
||||||
static void test_smbios_form_factor_to_spd_mod_type_ddr(smbios_memory_type memory_type)
|
static void test_smbios_form_factor_to_spd_mod_type_ddr(smbios_memory_type memory_type)
|
||||||
{
|
{
|
||||||
const smbios_memory_form_factor undefined_factors[] = {
|
const smbios_memory_form_factor undefined_factors[] = {
|
||||||
MEMORY_FORMFACTOR_OTHER,
|
MEMORY_FORMFACTOR_OTHER, MEMORY_FORMFACTOR_UNKNOWN,
|
||||||
MEMORY_FORMFACTOR_UNKNOWN,
|
MEMORY_FORMFACTOR_SIMM, MEMORY_FORMFACTOR_SIP,
|
||||||
MEMORY_FORMFACTOR_SIMM,
|
MEMORY_FORMFACTOR_CHIP, MEMORY_FORMFACTOR_DIP,
|
||||||
MEMORY_FORMFACTOR_SIP,
|
MEMORY_FORMFACTOR_ZIP, MEMORY_FORMFACTOR_PROPRIETARY_CARD,
|
||||||
MEMORY_FORMFACTOR_CHIP,
|
MEMORY_FORMFACTOR_TSOP, MEMORY_FORMFACTOR_ROC,
|
||||||
MEMORY_FORMFACTOR_DIP,
|
MEMORY_FORMFACTOR_SRIMM, MEMORY_FORMFACTOR_FBDIMM,
|
||||||
MEMORY_FORMFACTOR_ZIP,
|
|
||||||
MEMORY_FORMFACTOR_PROPRIETARY_CARD,
|
|
||||||
MEMORY_FORMFACTOR_TSOP,
|
|
||||||
MEMORY_FORMFACTOR_ROC,
|
|
||||||
MEMORY_FORMFACTOR_SRIMM,
|
|
||||||
MEMORY_FORMFACTOR_FBDIMM,
|
|
||||||
MEMORY_FORMFACTOR_DIE,
|
MEMORY_FORMFACTOR_DIE,
|
||||||
};
|
};
|
||||||
for (int i = 0; i < ARRAY_SIZE(undefined_factors); ++i) {
|
for (int i = 0; i < ARRAY_SIZE(undefined_factors); ++i) {
|
||||||
assert_int_equal(SPD_UNDEFINED,
|
assert_int_equal(SPD_UNDEFINED, smbios_form_factor_to_spd_mod_type(
|
||||||
smbios_form_factor_to_spd_mod_type(memory_type,
|
memory_type, undefined_factors[i]));
|
||||||
undefined_factors[i]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_smbios_form_factor_to_spd_mod_type_ddrx_parametrized(
|
static void test_smbios_form_factor_to_spd_mod_type_ddrx_parametrized(
|
||||||
smbios_memory_type memory_type,
|
smbios_memory_type memory_type, const LargestIntegralType udimm_allowed[],
|
||||||
const LargestIntegralType udimm_allowed[],
|
const LargestIntegralType rdimm_allowed[], LargestIntegralType expected_module_type)
|
||||||
const LargestIntegralType rdimm_allowed[],
|
|
||||||
LargestIntegralType expected_module_type)
|
|
||||||
{
|
{
|
||||||
print_message("%s(%d)\n", __func__, memory_type);
|
print_message("%s(%d)\n", __func__, memory_type);
|
||||||
|
|
||||||
assert_in_set(smbios_form_factor_to_spd_mod_type(memory_type, MEMORY_FORMFACTOR_DIMM),
|
assert_in_set(smbios_form_factor_to_spd_mod_type(memory_type, MEMORY_FORMFACTOR_DIMM),
|
||||||
udimm_allowed, MAX_ALLOWED_MODULE_TYPE);
|
udimm_allowed, MAX_ALLOWED_MODULE_TYPE);
|
||||||
|
|
||||||
assert_in_set(smbios_form_factor_to_spd_mod_type(memory_type, MEMORY_FORMFACTOR_RIMM),
|
assert_in_set(smbios_form_factor_to_spd_mod_type(memory_type, MEMORY_FORMFACTOR_RIMM),
|
||||||
rdimm_allowed, MAX_ALLOWED_MODULE_TYPE);
|
rdimm_allowed, MAX_ALLOWED_MODULE_TYPE);
|
||||||
|
|
||||||
assert_int_equal(expected_module_type, smbios_form_factor_to_spd_mod_type(memory_type,
|
assert_int_equal(expected_module_type, smbios_form_factor_to_spd_mod_type(
|
||||||
MEMORY_FORMFACTOR_SODIMM));
|
memory_type, MEMORY_FORMFACTOR_SODIMM));
|
||||||
|
|
||||||
test_smbios_form_factor_to_spd_mod_type_ddr(memory_type);
|
test_smbios_form_factor_to_spd_mod_type_ddr(memory_type);
|
||||||
}
|
}
|
||||||
|
@ -136,8 +122,8 @@ static void test_smbios_form_factor_to_spd_mod_type_lpddrx(smbios_memory_type me
|
||||||
{
|
{
|
||||||
print_message("%s(%d)\n", __func__, memory_type);
|
print_message("%s(%d)\n", __func__, memory_type);
|
||||||
/* Form factors defined in coreboot */
|
/* Form factors defined in coreboot */
|
||||||
assert_int_equal(LPX_SPD_NONDIMM, smbios_form_factor_to_spd_mod_type(memory_type,
|
assert_int_equal(LPX_SPD_NONDIMM, smbios_form_factor_to_spd_mod_type(
|
||||||
MEMORY_FORMFACTOR_ROC));
|
memory_type, MEMORY_FORMFACTOR_ROC));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_smbios_form_factor_to_spd_mod_type(void **state)
|
static void test_smbios_form_factor_to_spd_mod_type(void **state)
|
||||||
|
@ -150,37 +136,35 @@ static void test_smbios_form_factor_to_spd_mod_type(void **state)
|
||||||
} ddrx_info[] = {
|
} ddrx_info[] = {
|
||||||
{
|
{
|
||||||
.memory_type = MEMORY_TYPE_DDR2,
|
.memory_type = MEMORY_TYPE_DDR2,
|
||||||
.udimm_allowed = { DDR2_SPD_UDIMM, DDR2_SPD_MICRO_DIMM,
|
.udimm_allowed = {DDR2_SPD_UDIMM, DDR2_SPD_MICRO_DIMM,
|
||||||
DDR2_SPD_MINI_UDIMM },
|
DDR2_SPD_MINI_UDIMM},
|
||||||
.rdimm_allowed = { DDR2_SPD_RDIMM, DDR2_SPD_MINI_RDIMM },
|
.rdimm_allowed = {DDR2_SPD_RDIMM, DDR2_SPD_MINI_RDIMM},
|
||||||
.expected_module_type = DDR2_SPD_SODIMM,
|
.expected_module_type = DDR2_SPD_SODIMM,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.memory_type = MEMORY_TYPE_DDR3,
|
.memory_type = MEMORY_TYPE_DDR3,
|
||||||
.udimm_allowed = { DDR3_SPD_UDIMM, DDR3_SPD_MICRO_DIMM,
|
.udimm_allowed = {DDR3_SPD_UDIMM, DDR3_SPD_MICRO_DIMM,
|
||||||
DDR3_SPD_MINI_UDIMM },
|
DDR3_SPD_MINI_UDIMM},
|
||||||
.rdimm_allowed = { DDR3_SPD_RDIMM, DDR3_SPD_MINI_RDIMM },
|
.rdimm_allowed = {DDR3_SPD_RDIMM, DDR3_SPD_MINI_RDIMM},
|
||||||
.expected_module_type = DDR3_SPD_SODIMM,
|
.expected_module_type = DDR3_SPD_SODIMM,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.memory_type = MEMORY_TYPE_DDR4,
|
.memory_type = MEMORY_TYPE_DDR4,
|
||||||
.udimm_allowed = { DDR4_SPD_UDIMM, DDR4_SPD_MINI_UDIMM },
|
.udimm_allowed = {DDR4_SPD_UDIMM, DDR4_SPD_MINI_UDIMM},
|
||||||
.rdimm_allowed = { DDR4_SPD_RDIMM, DDR4_SPD_MINI_RDIMM },
|
.rdimm_allowed = {DDR4_SPD_RDIMM, DDR4_SPD_MINI_RDIMM},
|
||||||
.expected_module_type = DDR4_SPD_SODIMM,
|
.expected_module_type = DDR4_SPD_SODIMM,
|
||||||
},
|
},
|
||||||
{
|
{.memory_type = MEMORY_TYPE_DDR5,
|
||||||
.memory_type = MEMORY_TYPE_DDR5,
|
.udimm_allowed = {DDR5_SPD_UDIMM, DDR5_SPD_MINI_UDIMM},
|
||||||
.udimm_allowed = { DDR5_SPD_UDIMM, DDR5_SPD_MINI_UDIMM },
|
.rdimm_allowed = {DDR5_SPD_RDIMM, DDR5_SPD_MINI_RDIMM},
|
||||||
.rdimm_allowed = { DDR5_SPD_RDIMM, DDR5_SPD_MINI_RDIMM },
|
.expected_module_type = DDR5_SPD_SODIMM},
|
||||||
.expected_module_type = DDR5_SPD_SODIMM
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Test for DDRx DIMM Modules */
|
/* Test for DDRx DIMM Modules */
|
||||||
for (int i = 0; i < ARRAY_SIZE(ddrx_info); i++)
|
for (int i = 0; i < ARRAY_SIZE(ddrx_info); i++)
|
||||||
test_smbios_form_factor_to_spd_mod_type_ddrx_parametrized(
|
test_smbios_form_factor_to_spd_mod_type_ddrx_parametrized(
|
||||||
ddrx_info[i].memory_type, ddrx_info[i].udimm_allowed,
|
ddrx_info[i].memory_type, ddrx_info[i].udimm_allowed,
|
||||||
ddrx_info[i].rdimm_allowed, ddrx_info[i].expected_module_type);
|
ddrx_info[i].rdimm_allowed, ddrx_info[i].expected_module_type);
|
||||||
|
|
||||||
smbios_memory_type lpddrx_memory_type[] = {
|
smbios_memory_type lpddrx_memory_type[] = {
|
||||||
MEMORY_TYPE_LPDDR3,
|
MEMORY_TYPE_LPDDR3,
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -31,7 +31,7 @@ static void prepare_flash_buffer(void)
|
||||||
|
|
||||||
/* Fill rest of buffer with dummy data */
|
/* Fill rest of buffer with dummy data */
|
||||||
for (int i = FMAP_SECTION_FMAP_START + FMAP_SECTION_FMAP_SIZE;
|
for (int i = FMAP_SECTION_FMAP_START + FMAP_SECTION_FMAP_SIZE;
|
||||||
i < FMAP_SECTION_FLASH_SIZE; ++i)
|
i < FMAP_SECTION_FLASH_SIZE; ++i)
|
||||||
flash_buffer[i] = 'a' + i % ('z' - 'a');
|
flash_buffer[i] = 'a' + i % ('z' - 'a');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,13 +140,13 @@ static void test_fmap_locate_area_as_rdev_rw(void **state)
|
||||||
/* Test if returned section region device is writable */
|
/* Test if returned section region device is writable */
|
||||||
assert_int_not_equal(-1, fmap_locate_area_as_rdev_rw("MISC_RW", &rdev));
|
assert_int_not_equal(-1, fmap_locate_area_as_rdev_rw("MISC_RW", &rdev));
|
||||||
assert_int_equal(ro_rw_section_size,
|
assert_int_equal(ro_rw_section_size,
|
||||||
rdev_readat(&rdev, buffer1, 0, ro_rw_section_size));
|
rdev_readat(&rdev, buffer1, 0, ro_rw_section_size));
|
||||||
assert_int_equal(ro_rw_section_size,
|
assert_int_equal(ro_rw_section_size,
|
||||||
rdev_writeat(&rdev, dummy_data, 0, ro_rw_section_size));
|
rdev_writeat(&rdev, dummy_data, 0, ro_rw_section_size));
|
||||||
/* Check if written data is visible and correct after locating area as RO */
|
/* Check if written data is visible and correct after locating area as RO */
|
||||||
assert_int_not_equal(-1, fmap_locate_area_as_rdev("MISC_RW", &rdev));
|
assert_int_not_equal(-1, fmap_locate_area_as_rdev("MISC_RW", &rdev));
|
||||||
assert_int_equal(ro_rw_section_size,
|
assert_int_equal(ro_rw_section_size,
|
||||||
rdev_readat(&rdev, buffer2, 0, ro_rw_section_size));
|
rdev_readat(&rdev, buffer2, 0, ro_rw_section_size));
|
||||||
assert_memory_not_equal(buffer1, buffer2, ro_rw_section_size);
|
assert_memory_not_equal(buffer1, buffer2, ro_rw_section_size);
|
||||||
assert_memory_equal(dummy_data, buffer2, ro_rw_section_size);
|
assert_memory_equal(dummy_data, buffer2, ro_rw_section_size);
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ static void test_fmap_overwrite_area(void **state)
|
||||||
|
|
||||||
/* Overwrite part of section. */
|
/* Overwrite part of section. */
|
||||||
assert_int_equal(section_size / 2,
|
assert_int_equal(section_size / 2,
|
||||||
fmap_overwrite_area(section_name, new_data, section_size / 2));
|
fmap_overwrite_area(section_name, new_data, section_size / 2));
|
||||||
|
|
||||||
/* Read and check if memory has changed as expected */
|
/* Read and check if memory has changed as expected */
|
||||||
assert_int_equal(section_size, fmap_read_area(section_name, buffer2, section_size));
|
assert_int_equal(section_size, fmap_read_area(section_name, buffer2, section_size));
|
||||||
|
@ -272,8 +272,8 @@ static void test_fmap_overwrite_area(void **state)
|
||||||
assert_memory_equal(buffer2 + (section_size / 2), zero_buffer, section_size / 2);
|
assert_memory_equal(buffer2 + (section_size / 2), zero_buffer, section_size / 2);
|
||||||
|
|
||||||
/* Expect error when overwriting incorrect section */
|
/* Expect error when overwriting incorrect section */
|
||||||
assert_int_equal(-1, fmap_overwrite_area("NONEXISTENT_SECTION",
|
assert_int_equal(
|
||||||
new_data, section_size / 2));
|
-1, fmap_overwrite_area("NONEXISTENT_SECTION", new_data, section_size / 2));
|
||||||
assert_int_equal(-1, fmap_overwrite_area(NULL, new_data, section_size / 2));
|
assert_int_equal(-1, fmap_overwrite_area(NULL, new_data, section_size / 2));
|
||||||
|
|
||||||
/* Function fmap_overwrite_area is not tested with NULL
|
/* Function fmap_overwrite_area is not tested with NULL
|
||||||
|
@ -288,18 +288,17 @@ static void test_fmap_overwrite_area(void **state)
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
const struct CMUnitTest tests[] = {
|
const struct CMUnitTest tests[] = {
|
||||||
cmocka_unit_test_setup_teardown(test_fmap_locate_area_as_rdev,
|
cmocka_unit_test_setup_teardown(test_fmap_locate_area_as_rdev, setup_fmap,
|
||||||
setup_fmap, teardown_fmap),
|
teardown_fmap),
|
||||||
cmocka_unit_test_setup_teardown(test_fmap_locate_area_as_rdev_rw,
|
cmocka_unit_test_setup_teardown(test_fmap_locate_area_as_rdev_rw, setup_fmap,
|
||||||
setup_fmap, teardown_fmap),
|
teardown_fmap),
|
||||||
cmocka_unit_test_setup_teardown(test_fmap_locate_area,
|
cmocka_unit_test_setup_teardown(test_fmap_locate_area, setup_fmap,
|
||||||
setup_fmap, teardown_fmap),
|
teardown_fmap),
|
||||||
cmocka_unit_test_setup_teardown(test_fmap_find_region_name,
|
cmocka_unit_test_setup_teardown(test_fmap_find_region_name, setup_fmap,
|
||||||
setup_fmap, teardown_fmap),
|
teardown_fmap),
|
||||||
cmocka_unit_test_setup_teardown(test_fmap_read_area,
|
cmocka_unit_test_setup_teardown(test_fmap_read_area, setup_fmap, teardown_fmap),
|
||||||
setup_fmap, teardown_fmap),
|
cmocka_unit_test_setup_teardown(test_fmap_overwrite_area, setup_fmap,
|
||||||
cmocka_unit_test_setup_teardown(test_fmap_overwrite_area,
|
teardown_fmap),
|
||||||
setup_fmap, teardown_fmap),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return cb_run_group_tests(tests, NULL, NULL);
|
return cb_run_group_tests(tests, NULL, NULL);
|
||||||
|
|
|
@ -12,11 +12,11 @@ struct hexstr_t {
|
||||||
size_t res;
|
size_t res;
|
||||||
} hexstr[] = {
|
} hexstr[] = {
|
||||||
{.str = "A", .res = 0},
|
{.str = "A", .res = 0},
|
||||||
{.str = "AB", .val = (int[]) {171}, .res = 1},
|
{.str = "AB", .val = (int[]){171}, .res = 1},
|
||||||
{.str = "277a", .val = (int[]) {39, 122}, .res = 2},
|
{.str = "277a", .val = (int[]){39, 122}, .res = 2},
|
||||||
{.str = "277ab", .val = (int[]) {39, 122}, .res = 2},
|
{.str = "277ab", .val = (int[]){39, 122}, .res = 2},
|
||||||
{.str = "\n\rx1234567ijkl", .val = (int[]) {18, 52, 86}, .res = 3},
|
{.str = "\n\rx1234567ijkl", .val = (int[]){18, 52, 86}, .res = 3},
|
||||||
{.str = "\nB*e/ef-", .val = (int[]) {190, 239}, .res = 2},
|
{.str = "\nB*e/ef-", .val = (int[]){190, 239}, .res = 2},
|
||||||
};
|
};
|
||||||
|
|
||||||
static void test_hexstrtobin(void **state)
|
static void test_hexstrtobin(void **state)
|
||||||
|
|
|
@ -12,8 +12,9 @@
|
||||||
|
|
||||||
/* Auxiliary functions and definitions. */
|
/* Auxiliary functions and definitions. */
|
||||||
|
|
||||||
#define LG_ROOT_SIZE align_up_pow2(sizeof(struct imd_root_pointer) +\
|
#define LG_ROOT_SIZE \
|
||||||
sizeof(struct imd_root) + 3 * sizeof(struct imd_entry))
|
align_up_pow2(sizeof(struct imd_root_pointer) + sizeof(struct imd_root) \
|
||||||
|
+ 3 * sizeof(struct imd_entry))
|
||||||
#define LG_ENTRY_ALIGN (2 * sizeof(int32_t))
|
#define LG_ENTRY_ALIGN (2 * sizeof(int32_t))
|
||||||
#define LG_ENTRY_SIZE (2 * sizeof(int32_t))
|
#define LG_ENTRY_SIZE (2 * sizeof(int32_t))
|
||||||
#define LG_ENTRY_ID 0xA001
|
#define LG_ENTRY_ID 0xA001
|
||||||
|
@ -33,7 +34,7 @@ static uint32_t align_up_pow2(uint32_t x)
|
||||||
static size_t max_entries(size_t root_size)
|
static size_t max_entries(size_t root_size)
|
||||||
{
|
{
|
||||||
return (root_size - sizeof(struct imd_root_pointer) - sizeof(struct imd_root))
|
return (root_size - sizeof(struct imd_root_pointer) - sizeof(struct imd_root))
|
||||||
/ sizeof(struct imd_entry);
|
/ sizeof(struct imd_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -47,14 +48,14 @@ static void test_imd_handle_init(void **state)
|
||||||
void *base;
|
void *base;
|
||||||
struct imd imd;
|
struct imd imd;
|
||||||
uintptr_t test_inputs[] = {
|
uintptr_t test_inputs[] = {
|
||||||
0, /* Lowest possible address */
|
0, /* Lowest possible address */
|
||||||
0xA000, /* Fits in 16 bits, should not get rounded down*/
|
0xA000, /* Fits in 16 bits, should not get rounded down*/
|
||||||
0xDEAA, /* Fits in 16 bits */
|
0xDEAA, /* Fits in 16 bits */
|
||||||
0xB0B0B000, /* Fits in 32 bits, should not get rounded down */
|
0xB0B0B000, /* Fits in 32 bits, should not get rounded down */
|
||||||
0xF0F0F0F0, /* Fits in 32 bits */
|
0xF0F0F0F0, /* Fits in 32 bits */
|
||||||
((1ULL << 32) + 4), /* Just above 32-bit limit */
|
((1ULL << 32) + 4), /* Just above 32-bit limit */
|
||||||
0x6666777788889000, /* Fits in 64 bits, should not get rounded down */
|
0x6666777788889000, /* Fits in 64 bits, should not get rounded down */
|
||||||
((1ULL << 60) - 100) /* Very large address, fitting in 64 bits */
|
((1ULL << 60) - 100) /* Very large address, fitting in 64 bits */
|
||||||
};
|
};
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(test_inputs); i++) {
|
for (i = 0; i < ARRAY_SIZE(test_inputs); i++) {
|
||||||
|
@ -122,16 +123,15 @@ static void test_imd_create_empty(void **state)
|
||||||
imd_handle_init(&imd, (void *)(LIMIT_ALIGN + (uintptr_t)base));
|
imd_handle_init(&imd, (void *)(LIMIT_ALIGN + (uintptr_t)base));
|
||||||
|
|
||||||
/* Try incorrect sizes */
|
/* Try incorrect sizes */
|
||||||
assert_int_equal(-1, imd_create_empty(&imd,
|
assert_int_equal(
|
||||||
sizeof(struct imd_root_pointer),
|
-1, imd_create_empty(&imd, sizeof(struct imd_root_pointer), LG_ENTRY_ALIGN));
|
||||||
LG_ENTRY_ALIGN));
|
|
||||||
assert_int_equal(-1, imd_create_empty(&imd, LG_ROOT_SIZE, 2 * LG_ROOT_SIZE));
|
assert_int_equal(-1, imd_create_empty(&imd, LG_ROOT_SIZE, 2 * LG_ROOT_SIZE));
|
||||||
|
|
||||||
/* Working case */
|
/* Working case */
|
||||||
assert_int_equal(0, imd_create_empty(&imd, LG_ROOT_SIZE, LG_ENTRY_ALIGN));
|
assert_int_equal(0, imd_create_empty(&imd, LG_ROOT_SIZE, LG_ENTRY_ALIGN));
|
||||||
|
|
||||||
/* Only large allocation initialized with one entry for the root region */
|
/* Only large allocation initialized with one entry for the root region */
|
||||||
r = (struct imd_root *) (imd.lg.r);
|
r = (struct imd_root *)(imd.lg.r);
|
||||||
assert_non_null(r);
|
assert_non_null(r);
|
||||||
|
|
||||||
e = &r->entries[r->num_entries - 1];
|
e = &r->entries[r->num_entries - 1];
|
||||||
|
@ -171,15 +171,13 @@ static void test_imd_create_tiered_empty(void **state)
|
||||||
|
|
||||||
/* Too small root_size for small region */
|
/* Too small root_size for small region */
|
||||||
assert_int_equal(-1, imd_create_tiered_empty(&imd, LG_ROOT_SIZE, LG_ENTRY_ALIGN,
|
assert_int_equal(-1, imd_create_tiered_empty(&imd, LG_ROOT_SIZE, LG_ENTRY_ALIGN,
|
||||||
sizeof(int32_t), 2 * sizeof(int32_t)));
|
sizeof(int32_t), 2 * sizeof(int32_t)));
|
||||||
|
|
||||||
/* Fail when large region doesn't have capacity for more than 1 entry */
|
/* Fail when large region doesn't have capacity for more than 1 entry */
|
||||||
lg_region_wrong_size = sizeof(struct imd_root_pointer) + sizeof(struct imd_root) +
|
lg_region_wrong_size = sizeof(struct imd_root_pointer) + sizeof(struct imd_root)
|
||||||
sizeof(struct imd_entry);
|
+ sizeof(struct imd_entry);
|
||||||
expect_assert_failure(
|
expect_assert_failure(imd_create_tiered_empty(
|
||||||
imd_create_tiered_empty(&imd, lg_region_wrong_size, LG_ENTRY_ALIGN,
|
&imd, lg_region_wrong_size, LG_ENTRY_ALIGN, SM_ROOT_SIZE, SM_ENTRY_ALIGN));
|
||||||
SM_ROOT_SIZE, SM_ENTRY_ALIGN)
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_int_equal(0, imd_create_tiered_empty(&imd, LG_ROOT_SIZE, LG_ENTRY_ALIGN,
|
assert_int_equal(0, imd_create_tiered_empty(&imd, LG_ROOT_SIZE, LG_ENTRY_ALIGN,
|
||||||
SM_ROOT_SIZE, SM_ENTRY_ALIGN));
|
SM_ROOT_SIZE, SM_ENTRY_ALIGN));
|
||||||
|
@ -230,11 +228,11 @@ static void test_imd_recover(void **state)
|
||||||
struct imd imd = {0};
|
struct imd imd = {0};
|
||||||
struct imd_root_pointer *rp;
|
struct imd_root_pointer *rp;
|
||||||
struct imd_root *r;
|
struct imd_root *r;
|
||||||
struct imd_entry *lg_root_entry, *sm_root_entry, *ptr;
|
struct imd_entry *lg_root_entry, *sm_root_entry, *ptr;
|
||||||
const struct imd_entry *lg_entry;
|
const struct imd_entry *lg_entry;
|
||||||
|
|
||||||
/* Fail when the limit for lg was not set. */
|
/* Fail when the limit for lg was not set. */
|
||||||
imd.lg.limit = (uintptr_t) NULL;
|
imd.lg.limit = (uintptr_t)NULL;
|
||||||
assert_int_equal(-1, imd_recover(&imd));
|
assert_int_equal(-1, imd_recover(&imd));
|
||||||
|
|
||||||
/* Set the limit for lg. */
|
/* Set the limit for lg. */
|
||||||
|
@ -327,8 +325,8 @@ static void test_imd_limit_size(void **state)
|
||||||
struct imd imd = {0};
|
struct imd imd = {0};
|
||||||
size_t root_size, max_size;
|
size_t root_size, max_size;
|
||||||
|
|
||||||
max_size = align_up_pow2(sizeof(struct imd_root_pointer)
|
max_size = align_up_pow2(sizeof(struct imd_root_pointer) + sizeof(struct imd_root)
|
||||||
+ sizeof(struct imd_root) + 3 * sizeof(struct imd_entry));
|
+ 3 * sizeof(struct imd_entry));
|
||||||
|
|
||||||
assert_int_equal(-1, imd_limit_size(&imd, max_size));
|
assert_int_equal(-1, imd_limit_size(&imd, max_size));
|
||||||
|
|
||||||
|
@ -337,8 +335,8 @@ static void test_imd_limit_size(void **state)
|
||||||
fail_msg("Cannot allocate enough memory - fail test");
|
fail_msg("Cannot allocate enough memory - fail test");
|
||||||
imd_handle_init(&imd, (void *)(LIMIT_ALIGN + (uintptr_t)base));
|
imd_handle_init(&imd, (void *)(LIMIT_ALIGN + (uintptr_t)base));
|
||||||
|
|
||||||
root_size = align_up_pow2(sizeof(struct imd_root_pointer)
|
root_size = align_up_pow2(sizeof(struct imd_root_pointer) + sizeof(struct imd_root)
|
||||||
+ sizeof(struct imd_root) + 2 * sizeof(struct imd_entry));
|
+ 2 * sizeof(struct imd_entry));
|
||||||
imd.lg.r = (void *)imd.lg.limit - root_size;
|
imd.lg.r = (void *)imd.lg.limit - root_size;
|
||||||
|
|
||||||
imd_create_empty(&imd, root_size, LG_ENTRY_ALIGN);
|
imd_create_empty(&imd, root_size, LG_ENTRY_ALIGN);
|
||||||
|
@ -362,7 +360,7 @@ static void test_imd_lockdown(void **state)
|
||||||
if (imd.lg.r == NULL)
|
if (imd.lg.r == NULL)
|
||||||
fail_msg("Cannot allocate enough memory - fail test");
|
fail_msg("Cannot allocate enough memory - fail test");
|
||||||
|
|
||||||
r_lg = (struct imd_root *) (imd.lg.r);
|
r_lg = (struct imd_root *)(imd.lg.r);
|
||||||
|
|
||||||
assert_int_equal(0, imd_lockdown(&imd));
|
assert_int_equal(0, imd_lockdown(&imd));
|
||||||
assert_true(r_lg->flags & IMD_FLAG_LOCKED);
|
assert_true(r_lg->flags & IMD_FLAG_LOCKED);
|
||||||
|
@ -370,7 +368,7 @@ static void test_imd_lockdown(void **state)
|
||||||
imd.sm.r = malloc(sizeof(struct imd_root));
|
imd.sm.r = malloc(sizeof(struct imd_root));
|
||||||
if (imd.sm.r == NULL)
|
if (imd.sm.r == NULL)
|
||||||
fail_msg("Cannot allocate enough memory - fail test");
|
fail_msg("Cannot allocate enough memory - fail test");
|
||||||
r_sm = (struct imd_root *) (imd.sm.r);
|
r_sm = (struct imd_root *)(imd.sm.r);
|
||||||
|
|
||||||
assert_int_equal(0, imd_lockdown(&imd));
|
assert_int_equal(0, imd_lockdown(&imd));
|
||||||
assert_true(r_sm->flags & IMD_FLAG_LOCKED);
|
assert_true(r_sm->flags & IMD_FLAG_LOCKED);
|
||||||
|
@ -492,7 +490,7 @@ static void test_imd_entry_add(void **state)
|
||||||
/* All five new entries should be added to small allocations */
|
/* All five new entries should be added to small allocations */
|
||||||
for (i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
assert_non_null(imd_entry_add(&imd, SM_ENTRY_ID, SM_ENTRY_SIZE));
|
assert_non_null(imd_entry_add(&imd, SM_ENTRY_ID, SM_ENTRY_SIZE));
|
||||||
assert_int_equal(i+2, sm_r->num_entries);
|
assert_int_equal(i + 2, sm_r->num_entries);
|
||||||
assert_int_equal(2, lg_r->num_entries);
|
assert_int_equal(2, lg_r->num_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,7 +577,7 @@ static void test_imd_entry_find_or_add(void **state)
|
||||||
|
|
||||||
static void test_imd_entry_size(void **state)
|
static void test_imd_entry_size(void **state)
|
||||||
{
|
{
|
||||||
struct imd_entry entry = { .size = LG_ENTRY_SIZE };
|
struct imd_entry entry = {.size = LG_ENTRY_SIZE};
|
||||||
|
|
||||||
assert_int_equal(LG_ENTRY_SIZE, imd_entry_size(&entry));
|
assert_int_equal(LG_ENTRY_SIZE, imd_entry_size(&entry));
|
||||||
|
|
||||||
|
@ -616,7 +614,7 @@ static void test_imd_entry_at(void **state)
|
||||||
|
|
||||||
static void test_imd_entry_id(void **state)
|
static void test_imd_entry_id(void **state)
|
||||||
{
|
{
|
||||||
struct imd_entry entry = { .id = LG_ENTRY_ID };
|
struct imd_entry entry = {.id = LG_ENTRY_ID};
|
||||||
|
|
||||||
assert_int_equal(LG_ENTRY_ID, imd_entry_id(&entry));
|
assert_int_equal(LG_ENTRY_ID, imd_entry_id(&entry));
|
||||||
}
|
}
|
||||||
|
@ -761,4 +759,3 @@ int main(void)
|
||||||
|
|
||||||
return cb_run_group_tests(tests, NULL, NULL);
|
return cb_run_group_tests(tests, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -441,14 +441,13 @@ static void test_cbmem_entry_start(void **state)
|
||||||
/* Check if start address of found entry is the same
|
/* Check if start address of found entry is the same
|
||||||
as the one returned by cbmem_find() function */
|
as the one returned by cbmem_find() function */
|
||||||
assert_ptr_equal(cbmem_find(CBMEM_ENTRY_ID),
|
assert_ptr_equal(cbmem_find(CBMEM_ENTRY_ID),
|
||||||
cbmem_entry_start(cbmem_entry_find(CBMEM_ENTRY_ID)));
|
cbmem_entry_start(cbmem_entry_find(CBMEM_ENTRY_ID)));
|
||||||
assert_ptr_equal(cbmem_find(id1), cbmem_entry_start(cbmem_entry_find(id1)));
|
assert_ptr_equal(cbmem_find(id1), cbmem_entry_start(cbmem_entry_find(id1)));
|
||||||
assert_ptr_equal(cbmem_find(id2), cbmem_entry_start(cbmem_entry_find(id2)));
|
assert_ptr_equal(cbmem_find(id2), cbmem_entry_start(cbmem_entry_find(id2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reimplementation for testing purposes */
|
/* Reimplementation for testing purposes */
|
||||||
void bootmem_add_range(uint64_t start, uint64_t size,
|
void bootmem_add_range(uint64_t start, uint64_t size, const enum bootmem_type tag)
|
||||||
const enum bootmem_type tag)
|
|
||||||
{
|
{
|
||||||
check_expected(start);
|
check_expected(start);
|
||||||
check_expected(size);
|
check_expected(size);
|
||||||
|
|
|
@ -12,108 +12,108 @@ struct {
|
||||||
} test_data[] = {
|
} test_data[] = {
|
||||||
/* GCC documentation says, __clzsi2() has undefined result for zero as an input value,
|
/* GCC documentation says, __clzsi2() has undefined result for zero as an input value,
|
||||||
but coreboot implementation can handle this. */
|
but coreboot implementation can handle this. */
|
||||||
{ .value = 0, .expected_output = 32 },
|
{.value = 0, .expected_output = 32},
|
||||||
|
|
||||||
{ .value = 1, .expected_output = 31 },
|
{.value = 1, .expected_output = 31},
|
||||||
{ .value = 2, .expected_output = 30 },
|
{.value = 2, .expected_output = 30},
|
||||||
{ .value = 3, .expected_output = 30 },
|
{.value = 3, .expected_output = 30},
|
||||||
{ .value = 4, .expected_output = 29 },
|
{.value = 4, .expected_output = 29},
|
||||||
{ .value = 5, .expected_output = 29 },
|
{.value = 5, .expected_output = 29},
|
||||||
{ .value = 6, .expected_output = 29 },
|
{.value = 6, .expected_output = 29},
|
||||||
{ .value = 7, .expected_output = 29 },
|
{.value = 7, .expected_output = 29},
|
||||||
|
|
||||||
{ .value = 0xF, .expected_output = 28 },
|
{.value = 0xF, .expected_output = 28},
|
||||||
{ .value = 0x10, .expected_output = 27 },
|
{.value = 0x10, .expected_output = 27},
|
||||||
{ .value = 0x25, .expected_output = 26 },
|
{.value = 0x25, .expected_output = 26},
|
||||||
{ .value = 0x5D, .expected_output = 25 },
|
{.value = 0x5D, .expected_output = 25},
|
||||||
{ .value = 0xB7, .expected_output = 24 },
|
{.value = 0xB7, .expected_output = 24},
|
||||||
|
|
||||||
{ .value = 0x133, .expected_output = 23 },
|
{.value = 0x133, .expected_output = 23},
|
||||||
{ .value = 0x3DC, .expected_output = 22 },
|
{.value = 0x3DC, .expected_output = 22},
|
||||||
{ .value = 0x6F1, .expected_output = 21 },
|
{.value = 0x6F1, .expected_output = 21},
|
||||||
{ .value = 0x897, .expected_output = 20 },
|
{.value = 0x897, .expected_output = 20},
|
||||||
|
|
||||||
{ .value = 0x1FFF, .expected_output = 19 },
|
{.value = 0x1FFF, .expected_output = 19},
|
||||||
{ .value = 0x2222, .expected_output = 18 },
|
{.value = 0x2222, .expected_output = 18},
|
||||||
{ .value = 0x7BAD, .expected_output = 17 },
|
{.value = 0x7BAD, .expected_output = 17},
|
||||||
{ .value = 0xE708, .expected_output = 16 },
|
{.value = 0xE708, .expected_output = 16},
|
||||||
|
|
||||||
{ .value = 0x1DABD, .expected_output = 15 },
|
{.value = 0x1DABD, .expected_output = 15},
|
||||||
{ .value = 0x29876, .expected_output = 14 },
|
{.value = 0x29876, .expected_output = 14},
|
||||||
{ .value = 0x56665, .expected_output = 13 },
|
{.value = 0x56665, .expected_output = 13},
|
||||||
{ .value = 0xABCDE, .expected_output = 12 },
|
{.value = 0xABCDE, .expected_output = 12},
|
||||||
|
|
||||||
{ .value = 0x18365F, .expected_output = 11 },
|
{.value = 0x18365F, .expected_output = 11},
|
||||||
{ .value = 0x3D0115, .expected_output = 10 },
|
{.value = 0x3D0115, .expected_output = 10},
|
||||||
{ .value = 0x4B07EB, .expected_output = 9 },
|
{.value = 0x4B07EB, .expected_output = 9},
|
||||||
{ .value = 0xCCC74D, .expected_output = 8 },
|
{.value = 0xCCC74D, .expected_output = 8},
|
||||||
|
|
||||||
{ .value = 0x17933ED, .expected_output = 7 },
|
{.value = 0x17933ED, .expected_output = 7},
|
||||||
{ .value = 0x2B00071, .expected_output = 6 },
|
{.value = 0x2B00071, .expected_output = 6},
|
||||||
{ .value = 0x4D4C1A5, .expected_output = 5 },
|
{.value = 0x4D4C1A5, .expected_output = 5},
|
||||||
{ .value = 0xAD01FFF, .expected_output = 4 },
|
{.value = 0xAD01FFF, .expected_output = 4},
|
||||||
|
|
||||||
{ .value = 0x1C5A8057, .expected_output = 3 },
|
{.value = 0x1C5A8057, .expected_output = 3},
|
||||||
{ .value = 0x35AB23C3, .expected_output = 2 },
|
{.value = 0x35AB23C3, .expected_output = 2},
|
||||||
{ .value = 0x7017013B, .expected_output = 1 },
|
{.value = 0x7017013B, .expected_output = 1},
|
||||||
{ .value = 0xAD01EB15, .expected_output = 0 },
|
{.value = 0xAD01EB15, .expected_output = 0},
|
||||||
|
|
||||||
{ .value = 0xFFFFFFFF, .expected_output = 0 },
|
{.value = 0xFFFFFFFF, .expected_output = 0},
|
||||||
{ .value = 0x80000000, .expected_output = 0 },
|
{.value = 0x80000000, .expected_output = 0},
|
||||||
{ .value = 0x7FFFFFFF, .expected_output = 1 },
|
{.value = 0x7FFFFFFF, .expected_output = 1},
|
||||||
{ .value = 0x30000000, .expected_output = 2 },
|
{.value = 0x30000000, .expected_output = 2},
|
||||||
{ .value = 0x10000000, .expected_output = 3 },
|
{.value = 0x10000000, .expected_output = 3},
|
||||||
{ .value = 0x0FFFFFFF, .expected_output = 4 },
|
{.value = 0x0FFFFFFF, .expected_output = 4},
|
||||||
|
|
||||||
{ .value = 0xFF000000, .expected_output = 0 },
|
{.value = 0xFF000000, .expected_output = 0},
|
||||||
{ .value = 0x00FF0000, .expected_output = 8 },
|
{.value = 0x00FF0000, .expected_output = 8},
|
||||||
{ .value = 0x0000FF00, .expected_output = 16 },
|
{.value = 0x0000FF00, .expected_output = 16},
|
||||||
{ .value = 0x000000FF, .expected_output = 24 },
|
{.value = 0x000000FF, .expected_output = 24},
|
||||||
|
|
||||||
{ .value = 0x8F000000, .expected_output = 0 },
|
{.value = 0x8F000000, .expected_output = 0},
|
||||||
{ .value = 0x008F0000, .expected_output = 8 },
|
{.value = 0x008F0000, .expected_output = 8},
|
||||||
{ .value = 0x00008F00, .expected_output = 16 },
|
{.value = 0x00008F00, .expected_output = 16},
|
||||||
{ .value = 0x0000008F, .expected_output = 24 },
|
{.value = 0x0000008F, .expected_output = 24},
|
||||||
|
|
||||||
{ .value = 0x7F000000, .expected_output = 1 },
|
{.value = 0x7F000000, .expected_output = 1},
|
||||||
{ .value = 0x007F0000, .expected_output = 9 },
|
{.value = 0x007F0000, .expected_output = 9},
|
||||||
{ .value = 0x00007F00, .expected_output = 17 },
|
{.value = 0x00007F00, .expected_output = 17},
|
||||||
{ .value = 0x0000007F, .expected_output = 25 },
|
{.value = 0x0000007F, .expected_output = 25},
|
||||||
|
|
||||||
{ .value = 0x3F000000, .expected_output = 2 },
|
{.value = 0x3F000000, .expected_output = 2},
|
||||||
{ .value = 0x003F0000, .expected_output = 10 },
|
{.value = 0x003F0000, .expected_output = 10},
|
||||||
{ .value = 0x00003F00, .expected_output = 18 },
|
{.value = 0x00003F00, .expected_output = 18},
|
||||||
{ .value = 0x0000003F, .expected_output = 26 },
|
{.value = 0x0000003F, .expected_output = 26},
|
||||||
|
|
||||||
{ .value = 0x1F000000, .expected_output = 3 },
|
{.value = 0x1F000000, .expected_output = 3},
|
||||||
{ .value = 0x001F0000, .expected_output = 11 },
|
{.value = 0x001F0000, .expected_output = 11},
|
||||||
{ .value = 0x00001F00, .expected_output = 19 },
|
{.value = 0x00001F00, .expected_output = 19},
|
||||||
{ .value = 0x0000001F, .expected_output = 27 },
|
{.value = 0x0000001F, .expected_output = 27},
|
||||||
|
|
||||||
{ .value = 0x0F000000, .expected_output = 4 },
|
{.value = 0x0F000000, .expected_output = 4},
|
||||||
{ .value = 0x000F0000, .expected_output = 12 },
|
{.value = 0x000F0000, .expected_output = 12},
|
||||||
{ .value = 0x00000F00, .expected_output = 20 },
|
{.value = 0x00000F00, .expected_output = 20},
|
||||||
{ .value = 0x0000000F, .expected_output = 28 },
|
{.value = 0x0000000F, .expected_output = 28},
|
||||||
|
|
||||||
{ .value = 0x08000000, .expected_output = 4 },
|
{.value = 0x08000000, .expected_output = 4},
|
||||||
{ .value = 0x00080000, .expected_output = 12 },
|
{.value = 0x00080000, .expected_output = 12},
|
||||||
{ .value = 0x00000800, .expected_output = 20 },
|
{.value = 0x00000800, .expected_output = 20},
|
||||||
{ .value = 0x00000008, .expected_output = 28 },
|
{.value = 0x00000008, .expected_output = 28},
|
||||||
|
|
||||||
{ .value = 0x07000000, .expected_output = 5 },
|
{.value = 0x07000000, .expected_output = 5},
|
||||||
{ .value = 0x00070000, .expected_output = 13 },
|
{.value = 0x00070000, .expected_output = 13},
|
||||||
{ .value = 0x00000700, .expected_output = 21 },
|
{.value = 0x00000700, .expected_output = 21},
|
||||||
{ .value = 0x00000007, .expected_output = 29 },
|
{.value = 0x00000007, .expected_output = 29},
|
||||||
|
|
||||||
{ .value = 0x03000000, .expected_output = 6 },
|
{.value = 0x03000000, .expected_output = 6},
|
||||||
{ .value = 0x00030000, .expected_output = 14 },
|
{.value = 0x00030000, .expected_output = 14},
|
||||||
{ .value = 0x00000300, .expected_output = 22 },
|
{.value = 0x00000300, .expected_output = 22},
|
||||||
{ .value = 0x00000003, .expected_output = 30 },
|
{.value = 0x00000003, .expected_output = 30},
|
||||||
|
|
||||||
{ .value = 0x01000000, .expected_output = 7 },
|
{.value = 0x01000000, .expected_output = 7},
|
||||||
{ .value = 0x00010000, .expected_output = 15 },
|
{.value = 0x00010000, .expected_output = 15},
|
||||||
{ .value = 0x00000100, .expected_output = 23 },
|
{.value = 0x00000100, .expected_output = 23},
|
||||||
{ .value = 0x00000001, .expected_output = 31 },
|
{.value = 0x00000001, .expected_output = 31},
|
||||||
};
|
};
|
||||||
|
|
||||||
void test_clzsi2_with_data(void **state)
|
void test_clzsi2_with_data(void **state)
|
||||||
|
|
|
@ -51,12 +51,12 @@ static int setup_ulzman_file(void **state)
|
||||||
if (!s)
|
if (!s)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
const size_t raw_filename_size = strlen(path_prefix) + strlen(fname_base)
|
const size_t raw_filename_size =
|
||||||
+ ARRAY_SIZE(raw_file_suffix);
|
strlen(path_prefix) + strlen(fname_base) + ARRAY_SIZE(raw_file_suffix);
|
||||||
s->raw_filename = test_malloc(raw_filename_size);
|
s->raw_filename = test_malloc(raw_filename_size);
|
||||||
|
|
||||||
const size_t comp_filename_size = strlen(path_prefix) + strlen(fname_base)
|
const size_t comp_filename_size =
|
||||||
+ ARRAY_SIZE(comp_file_suffix);
|
strlen(path_prefix) + strlen(fname_base) + ARRAY_SIZE(comp_file_suffix);
|
||||||
s->comp_filename = test_malloc(comp_filename_size);
|
s->comp_filename = test_malloc(comp_filename_size);
|
||||||
|
|
||||||
if (!s->raw_filename || !s->comp_filename) {
|
if (!s->raw_filename || !s->comp_filename) {
|
||||||
|
@ -67,7 +67,7 @@ static int setup_ulzman_file(void **state)
|
||||||
|
|
||||||
snprintf(s->raw_filename, raw_filename_size, path_prefix, fname_base, raw_file_suffix);
|
snprintf(s->raw_filename, raw_filename_size, path_prefix, fname_base, raw_file_suffix);
|
||||||
snprintf(s->comp_filename, comp_filename_size, path_prefix, fname_base,
|
snprintf(s->comp_filename, comp_filename_size, path_prefix, fname_base,
|
||||||
comp_file_suffix);
|
comp_file_suffix);
|
||||||
|
|
||||||
s->raw_file_sz = get_file_size(s->raw_filename);
|
s->raw_file_sz = get_file_size(s->raw_filename);
|
||||||
s->comp_file_sz = get_file_size(s->comp_filename);
|
s->comp_file_sz = get_file_size(s->comp_filename);
|
||||||
|
@ -117,10 +117,10 @@ static void test_ulzman_correct_file(void **state)
|
||||||
assert_non_null(comp_buf);
|
assert_non_null(comp_buf);
|
||||||
assert_int_equal(s->raw_file_sz, read_file(s->raw_filename, raw_buf, s->raw_file_sz));
|
assert_int_equal(s->raw_file_sz, read_file(s->raw_filename, raw_buf, s->raw_file_sz));
|
||||||
assert_int_equal(s->comp_file_sz,
|
assert_int_equal(s->comp_file_sz,
|
||||||
read_file(s->comp_filename, comp_buf, s->comp_file_sz));
|
read_file(s->comp_filename, comp_buf, s->comp_file_sz));
|
||||||
|
|
||||||
assert_int_equal(s->raw_file_sz,
|
assert_int_equal(s->raw_file_sz,
|
||||||
ulzman(comp_buf, s->comp_file_sz, decomp_buf, s->raw_file_sz));
|
ulzman(comp_buf, s->comp_file_sz, decomp_buf, s->raw_file_sz));
|
||||||
assert_memory_equal(raw_buf, decomp_buf, s->raw_file_sz);
|
assert_memory_equal(raw_buf, decomp_buf, s->raw_file_sz);
|
||||||
|
|
||||||
test_free(raw_buf);
|
test_free(raw_buf);
|
||||||
|
@ -148,13 +148,11 @@ static void test_ulzman_zero_buffer(void **state)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ULZMAN_CORRECT_FILE_TEST(_file_prefix) \
|
#define ULZMAN_CORRECT_FILE_TEST(_file_prefix) \
|
||||||
{ \
|
{ \
|
||||||
.name = "test_ulzman_correct_file(" _file_prefix ")", \
|
.name = "test_ulzman_correct_file(" _file_prefix ")", \
|
||||||
.test_func = test_ulzman_correct_file, \
|
.test_func = test_ulzman_correct_file, .setup_func = setup_ulzman_file, \
|
||||||
.setup_func = setup_ulzman_file, \
|
.teardown_func = teardown_ulzman_file, .initial_state = (_file_prefix) \
|
||||||
.teardown_func = teardown_ulzman_file, \
|
}
|
||||||
.initial_state = (_file_prefix) \
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,42 +5,28 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static const char test_data1[] =
|
static const char test_data1[] =
|
||||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
static const size_t test_data1_sz = sizeof(test_data1);
|
static const size_t test_data1_sz = sizeof(test_data1);
|
||||||
static const char test_data2[] = {
|
static const char test_data2[] = {
|
||||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
|
||||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
|
||||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29,
|
||||||
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
|
||||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
|
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
|
||||||
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
|
||||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
|
0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61,
|
||||||
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d,
|
||||||
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b,
|
||||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
|
0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
|
||||||
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
|
||||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5,
|
||||||
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3,
|
||||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1,
|
||||||
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
|
||||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed,
|
||||||
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,
|
||||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
|
0xfc, 0xfd, 0xfe, 0xff};
|
||||||
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
|
||||||
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
|
|
||||||
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
|
|
||||||
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
|
|
||||||
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
|
|
||||||
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
|
|
||||||
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
|
|
||||||
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
|
|
||||||
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
|
|
||||||
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
|
|
||||||
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
|
|
||||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
|
||||||
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
|
|
||||||
};
|
|
||||||
static const size_t test_data2_sz = sizeof(test_data2);
|
static const size_t test_data2_sz = sizeof(test_data2);
|
||||||
|
|
||||||
static void test_memchr_existing_value(void **state)
|
static void test_memchr_existing_value(void **state)
|
||||||
|
|
|
@ -116,7 +116,7 @@ static void test_memcpy_buffer_part(void **state)
|
||||||
assert_memory_equal(s->buffer_to, s->helper_buffer, offset);
|
assert_memory_equal(s->buffer_to, s->helper_buffer, offset);
|
||||||
assert_memory_equal(s->buffer_to + offset, s->buffer_from, sz);
|
assert_memory_equal(s->buffer_to + offset, s->buffer_from, sz);
|
||||||
assert_memory_equal(s->buffer_to + offset + sz, s->helper_buffer + offset + sz,
|
assert_memory_equal(s->buffer_to + offset + sz, s->helper_buffer + offset + sz,
|
||||||
MEMCPY_BUFFER_SZ - (offset + sz));
|
MEMCPY_BUFFER_SZ - (offset + sz));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_memcpy_buffer_part_unaligned(void **state)
|
static void test_memcpy_buffer_part_unaligned(void **state)
|
||||||
|
@ -138,7 +138,7 @@ static void test_memcpy_buffer_part_unaligned(void **state)
|
||||||
assert_memory_equal(s->buffer_to, s->helper_buffer, dst_offset);
|
assert_memory_equal(s->buffer_to, s->helper_buffer, dst_offset);
|
||||||
assert_memory_equal(s->buffer_to + dst_offset, s->buffer_from + src_offset, sz);
|
assert_memory_equal(s->buffer_to + dst_offset, s->buffer_from + src_offset, sz);
|
||||||
assert_memory_equal(s->buffer_to + dst_offset + sz, s->helper_buffer + dst_offset + sz,
|
assert_memory_equal(s->buffer_to + dst_offset + sz, s->helper_buffer + dst_offset + sz,
|
||||||
MEMCPY_BUFFER_SZ - (dst_offset + sz));
|
MEMCPY_BUFFER_SZ - (dst_offset + sz));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_memcpy_copy_to_itself(void **state)
|
static void test_memcpy_copy_to_itself(void **state)
|
||||||
|
@ -178,16 +178,16 @@ static void test_memcpy_copy_part_of_itself_to_itself(void **state)
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
const struct CMUnitTest tests[] = {
|
const struct CMUnitTest tests[] = {
|
||||||
cmocka_unit_test_setup_teardown(test_memcpy_full_buffer_copy,
|
cmocka_unit_test_setup_teardown(test_memcpy_full_buffer_copy, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_memcpy_zero_size,
|
cmocka_unit_test_setup_teardown(test_memcpy_zero_size, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_memcpy_buffer_part,
|
cmocka_unit_test_setup_teardown(test_memcpy_buffer_part, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_memcpy_buffer_part_unaligned,
|
cmocka_unit_test_setup_teardown(test_memcpy_buffer_part_unaligned, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_memcpy_copy_to_itself,
|
cmocka_unit_test_setup_teardown(test_memcpy_copy_to_itself, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_memcpy_copy_part_of_itself_to_itself,
|
cmocka_unit_test_setup_teardown(test_memcpy_copy_part_of_itself_to_itself,
|
||||||
setup_test, teardown_test),
|
setup_test, teardown_test),
|
||||||
};
|
};
|
||||||
|
|
|
@ -115,7 +115,7 @@ static void test_memmove_buffer_part(void **state)
|
||||||
assert_memory_equal(s->buffer_to, s->helper_buffer, offset);
|
assert_memory_equal(s->buffer_to, s->helper_buffer, offset);
|
||||||
assert_memory_equal(s->buffer_to + offset, s->buffer_from, sz);
|
assert_memory_equal(s->buffer_to + offset, s->buffer_from, sz);
|
||||||
assert_memory_equal(s->buffer_to + offset + sz, s->helper_buffer + offset + sz,
|
assert_memory_equal(s->buffer_to + offset + sz, s->helper_buffer + offset + sz,
|
||||||
MEMMOVE_BUFFER_SZ - (offset + sz));
|
MEMMOVE_BUFFER_SZ - (offset + sz));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_memmove_buffer_part_unaligned(void **state)
|
static void test_memmove_buffer_part_unaligned(void **state)
|
||||||
|
@ -137,7 +137,7 @@ static void test_memmove_buffer_part_unaligned(void **state)
|
||||||
assert_memory_equal(s->buffer_to, s->helper_buffer, dst_offset);
|
assert_memory_equal(s->buffer_to, s->helper_buffer, dst_offset);
|
||||||
assert_memory_equal(s->buffer_to + dst_offset, s->buffer_from + src_offset, sz);
|
assert_memory_equal(s->buffer_to + dst_offset, s->buffer_from + src_offset, sz);
|
||||||
assert_memory_equal(s->buffer_to + dst_offset + sz, s->helper_buffer + dst_offset + sz,
|
assert_memory_equal(s->buffer_to + dst_offset + sz, s->helper_buffer + dst_offset + sz,
|
||||||
MEMMOVE_BUFFER_SZ - (dst_offset + sz));
|
MEMMOVE_BUFFER_SZ - (dst_offset + sz));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_memmove_copy_to_itself(void **state)
|
static void test_memmove_copy_to_itself(void **state)
|
||||||
|
@ -225,26 +225,25 @@ static void test_memmove_self_lower_to_higher_unaligned(void **state)
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
const struct CMUnitTest tests[] = {
|
const struct CMUnitTest tests[] = {
|
||||||
cmocka_unit_test_setup_teardown(test_memmove_full_buffer_copy,
|
cmocka_unit_test_setup_teardown(test_memmove_full_buffer_copy, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_memmove_zero_size,
|
cmocka_unit_test_setup_teardown(test_memmove_zero_size, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_memmove_buffer_part,
|
cmocka_unit_test_setup_teardown(test_memmove_buffer_part, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_memmove_buffer_part_unaligned,
|
cmocka_unit_test_setup_teardown(test_memmove_buffer_part_unaligned, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_memmove_copy_to_itself,
|
cmocka_unit_test_setup_teardown(test_memmove_copy_to_itself, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_memmove_self_higher_to_lower,
|
cmocka_unit_test_setup_teardown(test_memmove_self_higher_to_lower, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_memmove_self_higher_to_lower_unaligned,
|
cmocka_unit_test_setup_teardown(test_memmove_self_higher_to_lower_unaligned,
|
||||||
setup_test, teardown_test),
|
setup_test, teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_memmove_self_lower_to_higher,
|
cmocka_unit_test_setup_teardown(test_memmove_self_lower_to_higher, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_memmove_self_lower_to_higher_unaligned,
|
cmocka_unit_test_setup_teardown(test_memmove_self_lower_to_higher_unaligned,
|
||||||
setup_test, teardown_test),
|
setup_test, teardown_test),
|
||||||
};
|
};
|
||||||
|
|
||||||
return cb_run_group_tests(tests, NULL, NULL);
|
return cb_run_group_tests(tests, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,36 +22,54 @@ enum mem_types {
|
||||||
|
|
||||||
/* Indices of entries matters, since it must reflect mem_types enum */
|
/* Indices of entries matters, since it must reflect mem_types enum */
|
||||||
struct resource res_mock_1[] = {
|
struct resource res_mock_1[] = {
|
||||||
[CACHEABLE_TAG] = { .base = 0xE000, .size = 0xF2000,
|
[CACHEABLE_TAG] = {.base = 0xE000,
|
||||||
.next = &res_mock_1[RESERVED_TAG], .flags = IORESOURCE_CACHEABLE | IORESOURCE_MEM },
|
.size = 0xF2000,
|
||||||
[RESERVED_TAG] = { .base = 4ULL * GiB, .size = 4ULL * KiB,
|
.next = &res_mock_1[RESERVED_TAG],
|
||||||
.next = &res_mock_1[READONLY_TAG], .flags = IORESOURCE_RESERVE | IORESOURCE_MEM },
|
.flags = IORESOURCE_CACHEABLE | IORESOURCE_MEM},
|
||||||
[READONLY_TAG] = { .base = 0xFF0000, .size = 0x10000, .next = NULL,
|
[RESERVED_TAG] = {.base = 4ULL * GiB,
|
||||||
.flags = IORESOURCE_READONLY | IORESOURCE_MEM }
|
.size = 4ULL * KiB,
|
||||||
|
.next = &res_mock_1[READONLY_TAG],
|
||||||
|
.flags = IORESOURCE_RESERVE | IORESOURCE_MEM},
|
||||||
|
[READONLY_TAG] = {.base = 0xFF0000,
|
||||||
|
.size = 0x10000,
|
||||||
|
.next = NULL,
|
||||||
|
.flags = IORESOURCE_READONLY | IORESOURCE_MEM}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Boundary 1 byte below 4GiB and 1 byte above 4GiB. */
|
/* Boundary 1 byte below 4GiB and 1 byte above 4GiB. */
|
||||||
struct resource res_mock_2[] = {
|
struct resource res_mock_2[] = {
|
||||||
[CACHEABLE_TAG] = { .base = 0x1000000, .size = 4ULL * GiB - 0x1000001ULL,
|
[CACHEABLE_TAG] = {.base = 0x1000000,
|
||||||
.next = &res_mock_2[RESERVED_TAG], .flags = IORESOURCE_CACHEABLE | IORESOURCE_MEM },
|
.size = 4ULL * GiB - 0x1000001ULL,
|
||||||
[RESERVED_TAG] = { .base = 4ULL * GiB + 1ULL, .size = 4ULL * GiB,
|
.next = &res_mock_2[RESERVED_TAG],
|
||||||
.next = &res_mock_2[READONLY_TAG], .flags = IORESOURCE_RESERVE | IORESOURCE_MEM },
|
.flags = IORESOURCE_CACHEABLE | IORESOURCE_MEM},
|
||||||
[READONLY_TAG] = { .base = 0, .size = 0x10000, .next = NULL,
|
[RESERVED_TAG] = {.base = 4ULL * GiB + 1ULL,
|
||||||
.flags = IORESOURCE_READONLY | IORESOURCE_MEM}
|
.size = 4ULL * GiB,
|
||||||
|
.next = &res_mock_2[READONLY_TAG],
|
||||||
|
.flags = IORESOURCE_RESERVE | IORESOURCE_MEM},
|
||||||
|
[READONLY_TAG] = {.base = 0,
|
||||||
|
.size = 0x10000,
|
||||||
|
.next = NULL,
|
||||||
|
.flags = IORESOURCE_READONLY | IORESOURCE_MEM}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Boundary crossing 4GiB. */
|
/* Boundary crossing 4GiB. */
|
||||||
struct resource res_mock_3[] = {
|
struct resource res_mock_3[] = {
|
||||||
[CACHEABLE_TAG] = { .base = 0xD000, .size = 0xF3000,
|
[CACHEABLE_TAG] = {.base = 0xD000,
|
||||||
.next = &res_mock_3[RESERVED_TAG], .flags = IORESOURCE_CACHEABLE | IORESOURCE_MEM },
|
.size = 0xF3000,
|
||||||
[RESERVED_TAG] = { .base = 1ULL * GiB, .size = 4ULL * GiB,
|
.next = &res_mock_3[RESERVED_TAG],
|
||||||
.next = &res_mock_3[READONLY_TAG], .flags = IORESOURCE_RESERVE | IORESOURCE_MEM },
|
.flags = IORESOURCE_CACHEABLE | IORESOURCE_MEM},
|
||||||
[READONLY_TAG] = { .base = 0xFF0000, .size = 0x10000, .next = NULL,
|
[RESERVED_TAG] = {.base = 1ULL * GiB,
|
||||||
.flags = IORESOURCE_READONLY | IORESOURCE_MEM}
|
.size = 4ULL * GiB,
|
||||||
|
.next = &res_mock_3[READONLY_TAG],
|
||||||
|
.flags = IORESOURCE_RESERVE | IORESOURCE_MEM},
|
||||||
|
[READONLY_TAG] = {.base = 0xFF0000,
|
||||||
|
.size = 0x10000,
|
||||||
|
.next = NULL,
|
||||||
|
.flags = IORESOURCE_READONLY | IORESOURCE_MEM}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct device mock_device = { .enabled = 1 };
|
struct device mock_device = {.enabled = 1};
|
||||||
|
|
||||||
/* Fake memory devices handle */
|
/* Fake memory devices handle */
|
||||||
struct device *all_devices = &mock_device;
|
struct device *all_devices = &mock_device;
|
||||||
|
@ -87,9 +105,8 @@ resource_t get_aligned_base(struct resource *res, struct range_entry *entry)
|
||||||
|
|
||||||
resource_t get_aligned_end(struct resource *res, struct range_entry *entry)
|
resource_t get_aligned_end(struct resource *res, struct range_entry *entry)
|
||||||
{
|
{
|
||||||
resource_t end = res[range_entry_tag(entry)].base +
|
resource_t end = res[range_entry_tag(entry)].base + res[range_entry_tag(entry)].size
|
||||||
res[range_entry_tag(entry)].size +
|
+ (res[range_entry_tag(entry)].base - range_entry_base(entry));
|
||||||
(res[range_entry_tag(entry)].base - range_entry_base(entry));
|
|
||||||
return ALIGN_UP(end, MEMRANGE_ALIGN);
|
return ALIGN_UP(end, MEMRANGE_ALIGN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +153,8 @@ static void test_memrange_basic(void **state)
|
||||||
|
|
||||||
/* There should be two entries, since cacheable and
|
/* There should be two entries, since cacheable and
|
||||||
reserved regions are not neighbors */
|
reserved regions are not neighbors */
|
||||||
memranges_each_entry(ptr, &test_memrange) {
|
memranges_each_entry(ptr, &test_memrange)
|
||||||
|
{
|
||||||
assert_in_range(range_entry_tag(ptr), CACHEABLE_TAG, RESERVED_TAG);
|
assert_in_range(range_entry_tag(ptr), CACHEABLE_TAG, RESERVED_TAG);
|
||||||
assert_int_equal(range_entry_base(ptr), get_aligned_base(res_mock, ptr));
|
assert_int_equal(range_entry_base(ptr), get_aligned_base(res_mock, ptr));
|
||||||
|
|
||||||
|
@ -153,8 +171,7 @@ static void test_memrange_basic(void **state)
|
||||||
|
|
||||||
/* Remove initial memrange */
|
/* Remove initial memrange */
|
||||||
memranges_teardown(&test_memrange);
|
memranges_teardown(&test_memrange);
|
||||||
memranges_each_entry(ptr, &test_memrange)
|
memranges_each_entry(ptr, &test_memrange) counter++;
|
||||||
counter++;
|
|
||||||
assert_int_equal(counter, 0);
|
assert_int_equal(counter, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +222,8 @@ static void test_memrange_clone_insert(void **state)
|
||||||
memranges_teardown(&test_memrange);
|
memranges_teardown(&test_memrange);
|
||||||
|
|
||||||
/* Verify that new one is really a clone */
|
/* Verify that new one is really a clone */
|
||||||
memranges_each_entry(ptr, &clone_memrange) {
|
memranges_each_entry(ptr, &clone_memrange)
|
||||||
|
{
|
||||||
assert_in_range(range_entry_tag(ptr), CACHEABLE_TAG, END_OF_RESOURCES - 1);
|
assert_in_range(range_entry_tag(ptr), CACHEABLE_TAG, END_OF_RESOURCES - 1);
|
||||||
assert_int_equal(range_entry_base(ptr), get_aligned_base(res_mock, ptr));
|
assert_int_equal(range_entry_base(ptr), get_aligned_base(res_mock, ptr));
|
||||||
|
|
||||||
|
@ -221,7 +239,8 @@ static void test_memrange_clone_insert(void **state)
|
||||||
res_mock[CACHEABLE_TAG].size, INSERTED_TAG);
|
res_mock[CACHEABLE_TAG].size, INSERTED_TAG);
|
||||||
|
|
||||||
/* Three ranges should be there - CACHEABLE(shrunk), INSERTED and RESERVED */
|
/* Three ranges should be there - CACHEABLE(shrunk), INSERTED and RESERVED */
|
||||||
memranges_each_entry(ptr, &clone_memrange) {
|
memranges_each_entry(ptr, &clone_memrange)
|
||||||
|
{
|
||||||
resource_t expected_end;
|
resource_t expected_end;
|
||||||
|
|
||||||
if (range_entry_tag(ptr) == CACHEABLE_TAG) {
|
if (range_entry_tag(ptr) == CACHEABLE_TAG) {
|
||||||
|
@ -234,10 +253,10 @@ static void test_memrange_clone_insert(void **state)
|
||||||
assert_int_equal(range_entry_base(ptr),
|
assert_int_equal(range_entry_base(ptr),
|
||||||
res_mock[CACHEABLE_TAG].base + new_range_begin_offset);
|
res_mock[CACHEABLE_TAG].base + new_range_begin_offset);
|
||||||
|
|
||||||
expected_end = res_mock[CACHEABLE_TAG].base + new_range_begin_offset +
|
expected_end = res_mock[CACHEABLE_TAG].base + new_range_begin_offset
|
||||||
res_mock[CACHEABLE_TAG].size;
|
+ res_mock[CACHEABLE_TAG].size;
|
||||||
assert_int_equal(range_entry_end(ptr),
|
assert_int_equal(range_entry_end(ptr),
|
||||||
ALIGN_UP(expected_end, MEMRANGE_ALIGN));
|
ALIGN_UP(expected_end, MEMRANGE_ALIGN));
|
||||||
}
|
}
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
|
@ -248,7 +267,8 @@ static void test_memrange_clone_insert(void **state)
|
||||||
* Additionally verify API for updating tags */
|
* Additionally verify API for updating tags */
|
||||||
memranges_update_tag(&clone_memrange, INSERTED_TAG, READONLY_TAG);
|
memranges_update_tag(&clone_memrange, INSERTED_TAG, READONLY_TAG);
|
||||||
|
|
||||||
memranges_each_entry(ptr, &clone_memrange) {
|
memranges_each_entry(ptr, &clone_memrange)
|
||||||
|
{
|
||||||
resource_t expected_end;
|
resource_t expected_end;
|
||||||
|
|
||||||
assert_int_not_equal(range_entry_tag(ptr), INSERTED_TAG);
|
assert_int_not_equal(range_entry_tag(ptr), INSERTED_TAG);
|
||||||
|
@ -256,10 +276,10 @@ static void test_memrange_clone_insert(void **state)
|
||||||
assert_int_equal(range_entry_base(ptr),
|
assert_int_equal(range_entry_base(ptr),
|
||||||
res_mock[CACHEABLE_TAG].base + new_range_begin_offset);
|
res_mock[CACHEABLE_TAG].base + new_range_begin_offset);
|
||||||
|
|
||||||
expected_end = res_mock[CACHEABLE_TAG].base + new_range_begin_offset +
|
expected_end = res_mock[CACHEABLE_TAG].base + new_range_begin_offset
|
||||||
res_mock[CACHEABLE_TAG].size;
|
+ res_mock[CACHEABLE_TAG].size;
|
||||||
assert_int_equal(range_entry_end(ptr),
|
assert_int_equal(range_entry_end(ptr),
|
||||||
ALIGN_UP(expected_end, MEMRANGE_ALIGN));
|
ALIGN_UP(expected_end, MEMRANGE_ALIGN));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -267,17 +287,18 @@ static void test_memrange_clone_insert(void **state)
|
||||||
memranges_insert(&clone_memrange, res_mock[RESERVED_TAG].base + 0xAD,
|
memranges_insert(&clone_memrange, res_mock[RESERVED_TAG].base + 0xAD,
|
||||||
res_mock[RESERVED_TAG].size, INSERTED_TAG);
|
res_mock[RESERVED_TAG].size, INSERTED_TAG);
|
||||||
|
|
||||||
memranges_each_entry(ptr, &clone_memrange) {
|
memranges_each_entry(ptr, &clone_memrange)
|
||||||
|
{
|
||||||
resource_t expected_end;
|
resource_t expected_end;
|
||||||
|
|
||||||
assert_int_not_equal(range_entry_tag(ptr), RESERVED_TAG);
|
assert_int_not_equal(range_entry_tag(ptr), RESERVED_TAG);
|
||||||
if (range_entry_tag(ptr) == INSERTED_TAG) {
|
if (range_entry_tag(ptr) == INSERTED_TAG) {
|
||||||
assert_int_equal(range_entry_base(ptr),
|
assert_int_equal(
|
||||||
ALIGN_DOWN(res_mock[RESERVED_TAG].base,
|
range_entry_base(ptr),
|
||||||
MEMRANGE_ALIGN));
|
ALIGN_DOWN(res_mock[RESERVED_TAG].base, MEMRANGE_ALIGN));
|
||||||
|
|
||||||
expected_end = ALIGN_DOWN(res_mock[RESERVED_TAG].base, MEMRANGE_ALIGN) +
|
expected_end = ALIGN_DOWN(res_mock[RESERVED_TAG].base, MEMRANGE_ALIGN)
|
||||||
new_range_begin_offset + res_mock[RESERVED_TAG].size;
|
+ new_range_begin_offset + res_mock[RESERVED_TAG].size;
|
||||||
expected_end = ALIGN_UP(expected_end, MEMRANGE_ALIGN);
|
expected_end = ALIGN_UP(expected_end, MEMRANGE_ALIGN);
|
||||||
|
|
||||||
assert_int_equal(range_entry_end(ptr), expected_end);
|
assert_int_equal(range_entry_end(ptr), expected_end);
|
||||||
|
@ -329,7 +350,8 @@ static void test_memrange_holes(void **state)
|
||||||
memranges_add_resources(&test_memrange, reserved, reserved, RESERVED_TAG);
|
memranges_add_resources(&test_memrange, reserved, reserved, RESERVED_TAG);
|
||||||
|
|
||||||
/* Count holes in ranges */
|
/* Count holes in ranges */
|
||||||
memranges_each_entry(ptr, &test_memrange) {
|
memranges_each_entry(ptr, &test_memrange)
|
||||||
|
{
|
||||||
if (!last_range_end) {
|
if (!last_range_end) {
|
||||||
last_range_end = range_entry_end(ptr);
|
last_range_end = range_entry_end(ptr);
|
||||||
continue;
|
continue;
|
||||||
|
@ -349,12 +371,13 @@ static void test_memrange_holes(void **state)
|
||||||
(but with different tags) */
|
(but with different tags) */
|
||||||
memranges_fill_holes_up_to(&test_memrange, holes_fill_end, HOLE_TAG);
|
memranges_fill_holes_up_to(&test_memrange, holes_fill_end, HOLE_TAG);
|
||||||
|
|
||||||
memranges_each_entry(ptr, &test_memrange) {
|
memranges_each_entry(ptr, &test_memrange)
|
||||||
|
{
|
||||||
if (range_entry_tag(ptr) == HOLE_TAG) {
|
if (range_entry_tag(ptr) == HOLE_TAG) {
|
||||||
assert_int_equal(range_entry_base(ptr),
|
assert_int_equal(range_entry_base(ptr),
|
||||||
ALIGN_UP(res_mock[CACHEABLE_TAG].base +
|
ALIGN_UP(res_mock[CACHEABLE_TAG].base
|
||||||
res_mock[CACHEABLE_TAG].size,
|
+ res_mock[CACHEABLE_TAG].size,
|
||||||
MEMRANGE_ALIGN));
|
MEMRANGE_ALIGN));
|
||||||
assert_int_equal(range_entry_end(ptr), holes_fill_end);
|
assert_int_equal(range_entry_end(ptr), holes_fill_end);
|
||||||
/* Store pointer to HOLE_TAG region for future use */
|
/* Store pointer to HOLE_TAG region for future use */
|
||||||
hole_ptr = ptr;
|
hole_ptr = ptr;
|
||||||
|
@ -372,15 +395,16 @@ static void test_memrange_holes(void **state)
|
||||||
|
|
||||||
/* Create hole crossing the border of two range entries */
|
/* Create hole crossing the border of two range entries */
|
||||||
const resource_t new_cacheable_end = ALIGN_DOWN(
|
const resource_t new_cacheable_end = ALIGN_DOWN(
|
||||||
res_mock[CACHEABLE_TAG].base + res_mock[CACHEABLE_TAG].size - 4 * KiB,
|
res_mock[CACHEABLE_TAG].base + res_mock[CACHEABLE_TAG].size - 4 * KiB,
|
||||||
MEMRANGE_ALIGN);
|
MEMRANGE_ALIGN);
|
||||||
const resource_t new_hole_begin = ALIGN_UP(range_entry_base(hole_ptr) + 4 * KiB,
|
const resource_t new_hole_begin =
|
||||||
MEMRANGE_ALIGN);
|
ALIGN_UP(range_entry_base(hole_ptr) + 4 * KiB, MEMRANGE_ALIGN);
|
||||||
const resource_t ranges_diff = new_hole_begin - new_cacheable_end;
|
const resource_t ranges_diff = new_hole_begin - new_cacheable_end;
|
||||||
|
|
||||||
memranges_create_hole(&test_memrange, new_cacheable_end, ranges_diff);
|
memranges_create_hole(&test_memrange, new_cacheable_end, ranges_diff);
|
||||||
|
|
||||||
memranges_each_entry(ptr, &test_memrange) {
|
memranges_each_entry(ptr, &test_memrange)
|
||||||
|
{
|
||||||
switch (range_entry_tag(ptr)) {
|
switch (range_entry_tag(ptr)) {
|
||||||
case CACHEABLE_TAG:
|
case CACHEABLE_TAG:
|
||||||
assert_int_equal(range_entry_base(ptr), res_mock[CACHEABLE_TAG].base);
|
assert_int_equal(range_entry_base(ptr), res_mock[CACHEABLE_TAG].base);
|
||||||
|
@ -388,8 +412,9 @@ static void test_memrange_holes(void **state)
|
||||||
break;
|
break;
|
||||||
case RESERVED_TAG:
|
case RESERVED_TAG:
|
||||||
assert_int_equal(range_entry_base(ptr), res_mock[RESERVED_TAG].base);
|
assert_int_equal(range_entry_base(ptr), res_mock[RESERVED_TAG].base);
|
||||||
assert_int_equal(range_entry_end(ptr), res_mock[RESERVED_TAG].base +
|
assert_int_equal(range_entry_end(ptr),
|
||||||
res_mock[RESERVED_TAG].size);
|
res_mock[RESERVED_TAG].base
|
||||||
|
+ res_mock[RESERVED_TAG].size);
|
||||||
break;
|
break;
|
||||||
case HOLE_TAG:
|
case HOLE_TAG:
|
||||||
assert_int_equal(range_entry_base(ptr), new_hole_begin);
|
assert_int_equal(range_entry_base(ptr), new_hole_begin);
|
||||||
|
@ -448,18 +473,19 @@ static void test_memrange_steal(void **state)
|
||||||
memranges_add_resources(&test_memrange, reserved, reserved, RESERVED_TAG);
|
memranges_add_resources(&test_memrange, reserved, reserved, RESERVED_TAG);
|
||||||
memranges_add_resources(&test_memrange, readonly, readonly, READONLY_TAG);
|
memranges_add_resources(&test_memrange, readonly, readonly, READONLY_TAG);
|
||||||
|
|
||||||
status = memranges_steal(&test_memrange, res_mock[RESERVED_TAG].base +
|
status = memranges_steal(&test_memrange,
|
||||||
res_mock[RESERVED_TAG].size,
|
res_mock[RESERVED_TAG].base + res_mock[RESERVED_TAG].size,
|
||||||
stolen_range_size, 12, READONLY_TAG, &stolen);
|
stolen_range_size, 12, READONLY_TAG, &stolen);
|
||||||
assert_true(status);
|
assert_true(status);
|
||||||
assert_in_range(stolen, res_mock[READONLY_TAG].base, res_mock[READONLY_TAG].base +
|
assert_in_range(stolen, res_mock[READONLY_TAG].base,
|
||||||
res_mock[READONLY_TAG].size);
|
res_mock[READONLY_TAG].base + res_mock[READONLY_TAG].size);
|
||||||
|
|
||||||
memranges_each_entry(ptr, &test_memrange) {
|
memranges_each_entry(ptr, &test_memrange)
|
||||||
|
{
|
||||||
if (range_entry_tag(ptr) == READONLY_TAG) {
|
if (range_entry_tag(ptr) == READONLY_TAG) {
|
||||||
assert_int_equal(range_entry_base(ptr),
|
assert_int_equal(range_entry_base(ptr),
|
||||||
ALIGN_DOWN(res_mock[READONLY_TAG].base, MEMRANGE_ALIGN)
|
ALIGN_DOWN(res_mock[READONLY_TAG].base, MEMRANGE_ALIGN)
|
||||||
+ stolen_range_size);
|
+ stolen_range_size);
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
@ -468,16 +494,17 @@ static void test_memrange_steal(void **state)
|
||||||
|
|
||||||
/* Check if inserting range in previously stolen area will merge it. */
|
/* Check if inserting range in previously stolen area will merge it. */
|
||||||
memranges_insert(&test_memrange, res_mock[READONLY_TAG].base + 0xCC, stolen_range_size,
|
memranges_insert(&test_memrange, res_mock[READONLY_TAG].base + 0xCC, stolen_range_size,
|
||||||
READONLY_TAG);
|
READONLY_TAG);
|
||||||
memranges_each_entry(ptr, &test_memrange) {
|
memranges_each_entry(ptr, &test_memrange)
|
||||||
|
{
|
||||||
if (range_entry_tag(ptr) == READONLY_TAG) {
|
if (range_entry_tag(ptr) == READONLY_TAG) {
|
||||||
assert_int_equal(range_entry_base(ptr),
|
assert_int_equal(
|
||||||
ALIGN_DOWN(res_mock[READONLY_TAG].base,
|
range_entry_base(ptr),
|
||||||
MEMRANGE_ALIGN));
|
ALIGN_DOWN(res_mock[READONLY_TAG].base, MEMRANGE_ALIGN));
|
||||||
assert_int_equal(range_entry_end(ptr),
|
assert_int_equal(
|
||||||
ALIGN_UP(range_entry_base(ptr) +
|
range_entry_end(ptr),
|
||||||
res_mock[READONLY_TAG].size,
|
ALIGN_UP(range_entry_base(ptr) + res_mock[READONLY_TAG].size,
|
||||||
MEMRANGE_ALIGN));
|
MEMRANGE_ALIGN));
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
@ -489,12 +516,13 @@ static void test_memrange_steal(void **state)
|
||||||
|
|
||||||
/* Utility function checking number of entries and alignment of their base and end pointers */
|
/* Utility function checking number of entries and alignment of their base and end pointers */
|
||||||
static void check_range_entries_count_and_alignment(struct memranges *ranges,
|
static void check_range_entries_count_and_alignment(struct memranges *ranges,
|
||||||
size_t ranges_count, resource_t alignment)
|
size_t ranges_count, resource_t alignment)
|
||||||
{
|
{
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
struct range_entry *ptr;
|
struct range_entry *ptr;
|
||||||
|
|
||||||
memranges_each_entry(ptr, ranges) {
|
memranges_each_entry(ptr, ranges)
|
||||||
|
{
|
||||||
assert_true(IS_ALIGNED(range_entry_base(ptr), alignment));
|
assert_true(IS_ALIGNED(range_entry_base(ptr), alignment));
|
||||||
assert_true(IS_ALIGNED(range_entry_end(ptr), alignment));
|
assert_true(IS_ALIGNED(range_entry_end(ptr), alignment));
|
||||||
|
|
||||||
|
@ -511,7 +539,7 @@ static void test_memrange_init_and_teardown(void **state)
|
||||||
const unsigned long reserved = IORESOURCE_RESERVE;
|
const unsigned long reserved = IORESOURCE_RESERVE;
|
||||||
const unsigned long readonly = IORESOURCE_READONLY;
|
const unsigned long readonly = IORESOURCE_READONLY;
|
||||||
struct memranges test_memrange;
|
struct memranges test_memrange;
|
||||||
struct range_entry range_entries[4] = { 0 };
|
struct range_entry range_entries[4] = {0};
|
||||||
|
|
||||||
/* Test memranges_init() correctness */
|
/* Test memranges_init() correctness */
|
||||||
memranges_init(&test_memrange, cacheable, cacheable, CACHEABLE_TAG);
|
memranges_init(&test_memrange, cacheable, cacheable, CACHEABLE_TAG);
|
||||||
|
@ -527,8 +555,7 @@ static void test_memrange_init_and_teardown(void **state)
|
||||||
|
|
||||||
|
|
||||||
/* Test memranges_init_with_alignment() correctness with alignment of 1KiB (2^10) */
|
/* Test memranges_init_with_alignment() correctness with alignment of 1KiB (2^10) */
|
||||||
memranges_init_with_alignment(&test_memrange, cacheable, cacheable,
|
memranges_init_with_alignment(&test_memrange, cacheable, cacheable, CACHEABLE_TAG, 10);
|
||||||
CACHEABLE_TAG, 10);
|
|
||||||
memranges_add_resources(&test_memrange, reserved, reserved, RESERVED_TAG);
|
memranges_add_resources(&test_memrange, reserved, reserved, RESERVED_TAG);
|
||||||
memranges_add_resources(&test_memrange, readonly, readonly, READONLY_TAG);
|
memranges_add_resources(&test_memrange, readonly, readonly, READONLY_TAG);
|
||||||
|
|
||||||
|
@ -554,7 +581,7 @@ static void test_memrange_init_and_teardown(void **state)
|
||||||
|
|
||||||
/* Test memranges_init_with_alignment() correctness with alignment of 8KiB (2^13) */
|
/* Test memranges_init_with_alignment() correctness with alignment of 8KiB (2^13) */
|
||||||
memranges_init_empty_with_alignment(&test_memrange, &range_entries[0],
|
memranges_init_empty_with_alignment(&test_memrange, &range_entries[0],
|
||||||
ARRAY_SIZE(range_entries), 13);
|
ARRAY_SIZE(range_entries), 13);
|
||||||
assert_true(memranges_is_empty(&test_memrange));
|
assert_true(memranges_is_empty(&test_memrange));
|
||||||
|
|
||||||
memranges_add_resources(&test_memrange, cacheable, cacheable, CACHEABLE_TAG);
|
memranges_add_resources(&test_memrange, cacheable, cacheable, CACHEABLE_TAG);
|
||||||
|
@ -595,10 +622,11 @@ static void test_memrange_add_resources_filter(void **state)
|
||||||
/* Check if filter accepts range correctly */
|
/* Check if filter accepts range correctly */
|
||||||
memranges_init(&test_memrange, reserved, reserved, RESERVED_TAG);
|
memranges_init(&test_memrange, reserved, reserved, RESERVED_TAG);
|
||||||
memranges_add_resources_filter(&test_memrange, cacheable, cacheable, CACHEABLE_TAG,
|
memranges_add_resources_filter(&test_memrange, cacheable, cacheable, CACHEABLE_TAG,
|
||||||
memrange_filter_mem_only);
|
memrange_filter_mem_only);
|
||||||
|
|
||||||
/* Check if filter accepted desired range. */
|
/* Check if filter accepted desired range. */
|
||||||
memranges_each_entry(ptr, &test_memrange) {
|
memranges_each_entry(ptr, &test_memrange)
|
||||||
|
{
|
||||||
assert_in_set(range_entry_tag(ptr), accepted_tags, ARRAY_SIZE(accepted_tags));
|
assert_in_set(range_entry_tag(ptr), accepted_tags, ARRAY_SIZE(accepted_tags));
|
||||||
assert_true(IS_ALIGNED(range_entry_base(ptr), MEMRANGE_ALIGN));
|
assert_true(IS_ALIGNED(range_entry_base(ptr), MEMRANGE_ALIGN));
|
||||||
assert_true(IS_ALIGNED(range_entry_end(ptr), MEMRANGE_ALIGN));
|
assert_true(IS_ALIGNED(range_entry_end(ptr), MEMRANGE_ALIGN));
|
||||||
|
@ -611,7 +639,7 @@ static void test_memrange_add_resources_filter(void **state)
|
||||||
/* Check if filter rejects range correctly */
|
/* Check if filter rejects range correctly */
|
||||||
memranges_init(&test_memrange, reserved, reserved, RESERVED_TAG);
|
memranges_init(&test_memrange, reserved, reserved, RESERVED_TAG);
|
||||||
memranges_add_resources_filter(&test_memrange, cacheable, cacheable, CACHEABLE_TAG,
|
memranges_add_resources_filter(&test_memrange, cacheable, cacheable, CACHEABLE_TAG,
|
||||||
memrange_filter_non_mem);
|
memrange_filter_non_mem);
|
||||||
|
|
||||||
check_range_entries_count_and_alignment(&test_memrange, 1, MEMRANGE_ALIGN);
|
check_range_entries_count_and_alignment(&test_memrange, 1, MEMRANGE_ALIGN);
|
||||||
|
|
||||||
|
@ -629,10 +657,10 @@ int main(void)
|
||||||
cmocka_unit_test(test_memrange_add_resources_filter),
|
cmocka_unit_test(test_memrange_add_resources_filter),
|
||||||
};
|
};
|
||||||
|
|
||||||
return cmocka_run_group_tests_name(__TEST_NAME__"(Boundary on 4GiB)",
|
return cmocka_run_group_tests_name(__TEST_NAME__ "(Boundary on 4GiB)", tests,
|
||||||
tests, setup_test_1, NULL) +
|
setup_test_1, NULL)
|
||||||
cmocka_run_group_tests_name(__TEST_NAME__"(Boundaries 1 byte from 4GiB)",
|
+ cmocka_run_group_tests_name(__TEST_NAME__ "(Boundaries 1 byte from 4GiB)",
|
||||||
tests, setup_test_2, NULL) +
|
tests, setup_test_2, NULL)
|
||||||
cmocka_run_group_tests_name(__TEST_NAME__"(Range over 4GiB boundary)",
|
+ cmocka_run_group_tests_name(__TEST_NAME__ "(Range over 4GiB boundary)", tests,
|
||||||
tests, setup_test_3, NULL);
|
setup_test_3, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,14 +106,14 @@ static void test_memset_one_byte(void **state)
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
const struct CMUnitTest tests[] = {
|
const struct CMUnitTest tests[] = {
|
||||||
cmocka_unit_test_setup_teardown(test_memset_full_range,
|
cmocka_unit_test_setup_teardown(test_memset_full_range, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_memset_subrange,
|
cmocka_unit_test_setup_teardown(test_memset_subrange, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_memset_zero_size,
|
cmocka_unit_test_setup_teardown(test_memset_zero_size, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
cmocka_unit_test_setup_teardown(test_memset_one_byte,
|
cmocka_unit_test_setup_teardown(test_memset_one_byte, setup_test,
|
||||||
setup_test, teardown_test),
|
teardown_test),
|
||||||
};
|
};
|
||||||
|
|
||||||
return cb_run_group_tests(tests, NULL, NULL);
|
return cb_run_group_tests(tests, NULL, NULL);
|
||||||
|
|
|
@ -243,12 +243,12 @@ static void test_region_file_update_data_arr(void **state)
|
||||||
for (int i = 0; i < dummy_data_size; ++i)
|
for (int i = 0; i < dummy_data_size; ++i)
|
||||||
dummy_data[i] = 'A' + i % ('Z' - 'A');
|
dummy_data[i] = 'A' + i % ('Z' - 'A');
|
||||||
|
|
||||||
update_entries[0] = (struct update_region_file_entry)
|
update_entries[0] = (struct update_region_file_entry){
|
||||||
{ .size = data1_size, .data = &dummy_data[data1_offset] };
|
.size = data1_size, .data = &dummy_data[data1_offset]};
|
||||||
update_entries[1] = (struct update_region_file_entry)
|
update_entries[1] = (struct update_region_file_entry){
|
||||||
{ .size = data2_size, .data = &dummy_data[data2_offset] };
|
.size = data2_size, .data = &dummy_data[data2_offset]};
|
||||||
update_entries[2] = (struct update_region_file_entry)
|
update_entries[2] = (struct update_region_file_entry){
|
||||||
{ .size = data3_size, .data = &dummy_data[data3_offset] };
|
.size = data3_size, .data = &dummy_data[data3_offset]};
|
||||||
|
|
||||||
ret = region_file_init(®f, rdev);
|
ret = region_file_init(®f, rdev);
|
||||||
assert_int_equal(0, ret);
|
assert_int_equal(0, ret);
|
||||||
|
@ -274,10 +274,9 @@ static void test_region_file_update_data_arr(void **state)
|
||||||
ret = rdev_readat(&read_rdev, output_buffer, 0, data1_size + data2_size + data3_size);
|
ret = rdev_readat(&read_rdev, output_buffer, 0, data1_size + data2_size + data3_size);
|
||||||
assert_int_equal(data1_size + data2_size + data3_size, ret);
|
assert_int_equal(data1_size + data2_size + data3_size, ret);
|
||||||
assert_memory_equal(&dummy_data[data1_offset], output_buffer, data1_size);
|
assert_memory_equal(&dummy_data[data1_offset], output_buffer, data1_size);
|
||||||
assert_memory_equal(&dummy_data[data2_offset],
|
assert_memory_equal(&dummy_data[data2_offset], &output_buffer[data1_size], data2_size);
|
||||||
&output_buffer[data1_size], data2_size);
|
assert_memory_equal(&dummy_data[data3_offset], &output_buffer[data1_size + data2_size],
|
||||||
assert_memory_equal(&dummy_data[data3_offset],
|
data3_size);
|
||||||
&output_buffer[data1_size + data2_size], data3_size);
|
|
||||||
|
|
||||||
/* Check if data is correctly shrunk down to smaller size and different content */
|
/* Check if data is correctly shrunk down to smaller size and different content */
|
||||||
ret = region_file_update_data_arr(®f, &update_entries[1], 2);
|
ret = region_file_update_data_arr(®f, &update_entries[1], 2);
|
||||||
|
@ -294,35 +293,35 @@ int main(void)
|
||||||
{
|
{
|
||||||
const struct CMUnitTest tests[] = {
|
const struct CMUnitTest tests[] = {
|
||||||
cmocka_unit_test_setup_teardown(test_region_file_init_empty,
|
cmocka_unit_test_setup_teardown(test_region_file_init_empty,
|
||||||
setup_teardown_region_file_test,
|
setup_teardown_region_file_test,
|
||||||
setup_teardown_region_file_test),
|
setup_teardown_region_file_test),
|
||||||
cmocka_unit_test_setup_teardown(test_region_file_init_invalid_metadata,
|
cmocka_unit_test_setup_teardown(test_region_file_init_invalid_metadata,
|
||||||
setup_teardown_region_file_test,
|
setup_teardown_region_file_test,
|
||||||
setup_teardown_region_file_test),
|
setup_teardown_region_file_test),
|
||||||
cmocka_unit_test_setup_teardown(test_region_file_init_valid_no_data,
|
cmocka_unit_test_setup_teardown(test_region_file_init_valid_no_data,
|
||||||
setup_teardown_region_file_test,
|
setup_teardown_region_file_test,
|
||||||
setup_teardown_region_file_test),
|
setup_teardown_region_file_test),
|
||||||
cmocka_unit_test_setup_teardown(test_region_file_init_invalid_data_offset,
|
cmocka_unit_test_setup_teardown(test_region_file_init_invalid_data_offset,
|
||||||
setup_teardown_region_file_test,
|
setup_teardown_region_file_test,
|
||||||
setup_teardown_region_file_test),
|
setup_teardown_region_file_test),
|
||||||
cmocka_unit_test_setup_teardown(test_region_file_init_correct_data_offset,
|
cmocka_unit_test_setup_teardown(test_region_file_init_correct_data_offset,
|
||||||
setup_teardown_region_file_test,
|
setup_teardown_region_file_test,
|
||||||
setup_teardown_region_file_test),
|
setup_teardown_region_file_test),
|
||||||
cmocka_unit_test_setup_teardown(test_region_file_init_real_data,
|
cmocka_unit_test_setup_teardown(test_region_file_init_real_data,
|
||||||
setup_teardown_region_file_test,
|
setup_teardown_region_file_test,
|
||||||
setup_teardown_region_file_test),
|
setup_teardown_region_file_test),
|
||||||
cmocka_unit_test_setup_teardown(test_region_file_init_invalid_region_device,
|
cmocka_unit_test_setup_teardown(test_region_file_init_invalid_region_device,
|
||||||
setup_teardown_region_file_test,
|
setup_teardown_region_file_test,
|
||||||
setup_teardown_region_file_test),
|
setup_teardown_region_file_test),
|
||||||
cmocka_unit_test_setup_teardown(test_region_file_data,
|
cmocka_unit_test_setup_teardown(test_region_file_data,
|
||||||
setup_teardown_region_file_test,
|
setup_teardown_region_file_test,
|
||||||
setup_teardown_region_file_test),
|
setup_teardown_region_file_test),
|
||||||
cmocka_unit_test_setup_teardown(test_region_file_update_data,
|
cmocka_unit_test_setup_teardown(test_region_file_update_data,
|
||||||
setup_teardown_region_file_test,
|
setup_teardown_region_file_test,
|
||||||
setup_teardown_region_file_test),
|
setup_teardown_region_file_test),
|
||||||
cmocka_unit_test_setup_teardown(test_region_file_update_data_arr,
|
cmocka_unit_test_setup_teardown(test_region_file_update_data_arr,
|
||||||
setup_teardown_region_file_test,
|
setup_teardown_region_file_test,
|
||||||
setup_teardown_region_file_test),
|
setup_teardown_region_file_test),
|
||||||
};
|
};
|
||||||
|
|
||||||
return cb_run_group_tests(tests, setup_region_file_test_group,
|
return cb_run_group_tests(tests, setup_region_file_test_group,
|
||||||
|
|
|
@ -163,37 +163,37 @@ static void test_rtc_mktime_with_rtc_to_tm(void **state)
|
||||||
|
|
||||||
/* Conversion from rtc_time to timestamp and back to rtc_time */
|
/* Conversion from rtc_time to timestamp and back to rtc_time */
|
||||||
tm_in = (struct rtc_time){
|
tm_in = (struct rtc_time){
|
||||||
.year = 1970, .mon = 1, .mday = 1, .hour = 0, .min = 0, .sec = 0, .wday = 4
|
.year = 1970, .mon = 1, .mday = 1, .hour = 0, .min = 0, .sec = 0, .wday = 4,
|
||||||
};
|
};
|
||||||
assert_int_equal(0, rtc_to_tm(rtc_mktime(&tm_in), &tm_out));
|
assert_int_equal(0, rtc_to_tm(rtc_mktime(&tm_in), &tm_out));
|
||||||
assert_rtc_time_equal(&tm_in, &tm_out);
|
assert_rtc_time_equal(&tm_in, &tm_out);
|
||||||
|
|
||||||
tm_in = (struct rtc_time){
|
tm_in = (struct rtc_time){
|
||||||
.year = 2000, .mon = 2, .mday = 29, .hour = 13, .min = 4, .sec = 15, .wday = 2
|
.year = 2000, .mon = 2, .mday = 29, .hour = 13, .min = 4, .sec = 15, .wday = 2,
|
||||||
};
|
};
|
||||||
assert_int_equal(0, rtc_to_tm(rtc_mktime(&tm_in), &tm_out));
|
assert_int_equal(0, rtc_to_tm(rtc_mktime(&tm_in), &tm_out));
|
||||||
assert_rtc_time_equal(&tm_in, &tm_out);
|
assert_rtc_time_equal(&tm_in, &tm_out);
|
||||||
|
|
||||||
tm_in = (struct rtc_time){
|
tm_in = (struct rtc_time){
|
||||||
.year = 2000, .mon = 3, .mday = 1, .hour = 13, .min = 8, .sec = 37, .wday = 3
|
.year = 2000, .mon = 3, .mday = 1, .hour = 13, .min = 8, .sec = 37, .wday = 3,
|
||||||
};
|
};
|
||||||
assert_int_equal(0, rtc_to_tm(rtc_mktime(&tm_in), &tm_out));
|
assert_int_equal(0, rtc_to_tm(rtc_mktime(&tm_in), &tm_out));
|
||||||
assert_rtc_time_equal(&tm_in, &tm_out);
|
assert_rtc_time_equal(&tm_in, &tm_out);
|
||||||
|
|
||||||
tm_in = (struct rtc_time){
|
tm_in = (struct rtc_time){
|
||||||
.year = 2017, .mon = 12, .mday = 7, .hour = 8, .min = 18, .sec = 9, .wday = 4
|
.year = 2017, .mon = 12, .mday = 7, .hour = 8, .min = 18, .sec = 9, .wday = 4,
|
||||||
};
|
};
|
||||||
assert_int_equal(0, rtc_to_tm(rtc_mktime(&tm_in), &tm_out));
|
assert_int_equal(0, rtc_to_tm(rtc_mktime(&tm_in), &tm_out));
|
||||||
assert_rtc_time_equal(&tm_in, &tm_out);
|
assert_rtc_time_equal(&tm_in, &tm_out);
|
||||||
|
|
||||||
tm_in = (struct rtc_time){
|
tm_in = (struct rtc_time){
|
||||||
.year = 2020, .mon = 2, .mday = 29, .hour = 18, .min = 50, .sec = 0, .wday = 6
|
.year = 2020, .mon = 2, .mday = 29, .hour = 18, .min = 50, .sec = 0, .wday = 6,
|
||||||
};
|
};
|
||||||
assert_int_equal(0, rtc_to_tm(rtc_mktime(&tm_in), &tm_out));
|
assert_int_equal(0, rtc_to_tm(rtc_mktime(&tm_in), &tm_out));
|
||||||
assert_rtc_time_equal(&tm_in, &tm_out);
|
assert_rtc_time_equal(&tm_in, &tm_out);
|
||||||
|
|
||||||
tm_in = (struct rtc_time){
|
tm_in = (struct rtc_time){
|
||||||
.year = 2020, .mon = 3, .mday = 1, .hour = 1, .min = 20, .sec = 23, .wday = 0
|
.year = 2020, .mon = 3, .mday = 1, .hour = 1, .min = 20, .sec = 23, .wday = 0,
|
||||||
};
|
};
|
||||||
assert_int_equal(0, rtc_to_tm(rtc_mktime(&tm_in), &tm_out));
|
assert_int_equal(0, rtc_to_tm(rtc_mktime(&tm_in), &tm_out));
|
||||||
assert_rtc_time_equal(&tm_in, &tm_out);
|
assert_rtc_time_equal(&tm_in, &tm_out);
|
||||||
|
@ -246,53 +246,53 @@ static void test_leap_day_secday(void **state)
|
||||||
memset(&tm_out, 0, sizeof(tm_out));
|
memset(&tm_out, 0, sizeof(tm_out));
|
||||||
|
|
||||||
/* Non-leap year */
|
/* Non-leap year */
|
||||||
tm_in = (struct rtc_time) {
|
tm_in = (struct rtc_time){
|
||||||
.year = 1999, .mon = 2, .mday = 28, .hour = 5, .min = 37, .sec = 15, .wday = 0
|
.year = 1999, .mon = 2, .mday = 28, .hour = 5, .min = 37, .sec = 15, .wday = 0,
|
||||||
};
|
};
|
||||||
tim = rtc_mktime(&tm_in) + secday;
|
tim = rtc_mktime(&tm_in) + secday;
|
||||||
tm_expected = (struct rtc_time) {
|
tm_expected = (struct rtc_time){
|
||||||
.year = 1999, .mon = 3, .mday = 1, .hour = 5, .min = 37, .sec = 15, .wday = 1
|
.year = 1999, .mon = 3, .mday = 1, .hour = 5, .min = 37, .sec = 15, .wday = 1,
|
||||||
};
|
};
|
||||||
assert_int_equal(0, rtc_to_tm(tim, &tm_out));
|
assert_int_equal(0, rtc_to_tm(tim, &tm_out));
|
||||||
assert_rtc_time_equal(&tm_out, &tm_expected);
|
assert_rtc_time_equal(&tm_out, &tm_expected);
|
||||||
|
|
||||||
/* Leap-year February 28 to February 29 */
|
/* Leap-year February 28 to February 29 */
|
||||||
tm_in = (struct rtc_time) {
|
tm_in = (struct rtc_time){
|
||||||
.year = 2000, .mon = 2, .mday = 28, .hour = 0, .min = 33, .sec = 11, .wday = 1,
|
.year = 2000, .mon = 2, .mday = 28, .hour = 0, .min = 33, .sec = 11, .wday = 1,
|
||||||
};
|
};
|
||||||
tim = rtc_mktime(&tm_in) + secday;
|
tim = rtc_mktime(&tm_in) + secday;
|
||||||
tm_expected = (struct rtc_time) {
|
tm_expected = (struct rtc_time){
|
||||||
.year = 2000, .mon = 2, .mday = 29, .hour = 0, .min = 33, .sec = 11, .wday = 2,
|
.year = 2000, .mon = 2, .mday = 29, .hour = 0, .min = 33, .sec = 11, .wday = 2,
|
||||||
};
|
};
|
||||||
assert_int_equal(0, rtc_to_tm(tim, &tm_out));
|
assert_int_equal(0, rtc_to_tm(tim, &tm_out));
|
||||||
assert_rtc_time_equal(&tm_out, &tm_expected);
|
assert_rtc_time_equal(&tm_out, &tm_expected);
|
||||||
|
|
||||||
tm_in = (struct rtc_time) {
|
tm_in = (struct rtc_time){
|
||||||
.year = 2004, .mon = 2, .mday = 28, .hour = 9, .min = 13, .sec = 45, .wday = 6,
|
.year = 2004, .mon = 2, .mday = 28, .hour = 9, .min = 13, .sec = 45, .wday = 6,
|
||||||
};
|
};
|
||||||
tim = rtc_mktime(&tm_in) + secday;
|
tim = rtc_mktime(&tm_in) + secday;
|
||||||
tm_expected = (struct rtc_time) {
|
tm_expected = (struct rtc_time){
|
||||||
.year = 2004, .mon = 2, .mday = 29, .hour = 9, .min = 13, .sec = 45, .wday = 0,
|
.year = 2004, .mon = 2, .mday = 29, .hour = 9, .min = 13, .sec = 45, .wday = 0,
|
||||||
};
|
};
|
||||||
assert_int_equal(0, rtc_to_tm(tim, &tm_out));
|
assert_int_equal(0, rtc_to_tm(tim, &tm_out));
|
||||||
assert_rtc_time_equal(&tm_out, &tm_expected);
|
assert_rtc_time_equal(&tm_out, &tm_expected);
|
||||||
|
|
||||||
/* Leap-year February 29 to March 1 */
|
/* Leap-year February 29 to March 1 */
|
||||||
tm_in = (struct rtc_time) {
|
tm_in = (struct rtc_time){
|
||||||
.year = 2000, .mon = 2, .mday = 29, .hour = 22, .min = 50, .sec = 25, .wday = 2,
|
.year = 2000, .mon = 2, .mday = 29, .hour = 22, .min = 50, .sec = 25, .wday = 2,
|
||||||
};
|
};
|
||||||
tim = rtc_mktime(&tm_in) + secday;
|
tim = rtc_mktime(&tm_in) + secday;
|
||||||
tm_expected = (struct rtc_time) {
|
tm_expected = (struct rtc_time){
|
||||||
.year = 2000, .mon = 3, .mday = 1, .hour = 22, .min = 50, .sec = 25, .wday = 3,
|
.year = 2000, .mon = 3, .mday = 1, .hour = 22, .min = 50, .sec = 25, .wday = 3,
|
||||||
};
|
};
|
||||||
assert_int_equal(0, rtc_to_tm(tim, &tm_out));
|
assert_int_equal(0, rtc_to_tm(tim, &tm_out));
|
||||||
assert_rtc_time_equal(&tm_out, &tm_expected);
|
assert_rtc_time_equal(&tm_out, &tm_expected);
|
||||||
|
|
||||||
tm_in = (struct rtc_time) {
|
tm_in = (struct rtc_time){
|
||||||
.year = 2004, .mon = 2, .mday = 29, .hour = 17, .min = 56, .sec = 27, .wday = 0,
|
.year = 2004, .mon = 2, .mday = 29, .hour = 17, .min = 56, .sec = 27, .wday = 0,
|
||||||
};
|
};
|
||||||
tim = rtc_mktime(&tm_in) + secday;
|
tim = rtc_mktime(&tm_in) + secday;
|
||||||
tm_expected = (struct rtc_time) {
|
tm_expected = (struct rtc_time){
|
||||||
.year = 2004, .mon = 3, .mday = 1, .hour = 17, .min = 56, .sec = 27, .wday = 1,
|
.year = 2004, .mon = 3, .mday = 1, .hour = 17, .min = 56, .sec = 27, .wday = 1,
|
||||||
};
|
};
|
||||||
assert_int_equal(0, rtc_to_tm(tim, &tm_out));
|
assert_int_equal(0, rtc_to_tm(tim, &tm_out));
|
||||||
|
|
|
@ -62,12 +62,10 @@ static void test_load_spd_cache(void **state)
|
||||||
|
|
||||||
static void calc_spd_cache_crc(uint8_t *spd_cache)
|
static void calc_spd_cache_crc(uint8_t *spd_cache)
|
||||||
{
|
{
|
||||||
*(uint16_t *)(spd_cache + SC_CRC_OFFSET) =
|
*(uint16_t *)(spd_cache + SC_CRC_OFFSET) = CRC(spd_cache, SC_SPD_TOTAL_LEN, crc16_byte);
|
||||||
CRC(spd_cache, SC_SPD_TOTAL_LEN, crc16_byte);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((unused))
|
__attribute__((unused)) static void fill_spd_cache_ddr3(uint8_t *spd_cache, size_t spd_cache_sz)
|
||||||
static void fill_spd_cache_ddr3(uint8_t *spd_cache, size_t spd_cache_sz)
|
|
||||||
{
|
{
|
||||||
assert_true(spd_cache_sz >= (spd_data_ddr3_1_sz + sizeof(uint16_t)));
|
assert_true(spd_cache_sz >= (spd_data_ddr3_1_sz + sizeof(uint16_t)));
|
||||||
|
|
||||||
|
@ -76,16 +74,15 @@ static void fill_spd_cache_ddr3(uint8_t *spd_cache, size_t spd_cache_sz)
|
||||||
calc_spd_cache_crc(spd_cache);
|
calc_spd_cache_crc(spd_cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((unused))
|
__attribute__((unused)) static void fill_spd_cache_ddr4(uint8_t *spd_cache, size_t spd_cache_sz)
|
||||||
static void fill_spd_cache_ddr4(uint8_t *spd_cache, size_t spd_cache_sz)
|
|
||||||
{
|
{
|
||||||
assert_true(spd_cache_sz >=
|
assert_true(spd_cache_sz
|
||||||
(spd_data_ddr4_1_sz + spd_data_ddr4_2_sz + sizeof(uint16_t)));
|
>= (spd_data_ddr4_1_sz + spd_data_ddr4_2_sz + sizeof(uint16_t)));
|
||||||
|
|
||||||
memcpy(spd_cache, spd_data_ddr4_1, spd_data_ddr4_1_sz);
|
memcpy(spd_cache, spd_data_ddr4_1, spd_data_ddr4_1_sz);
|
||||||
memcpy(spd_cache + spd_data_ddr4_1_sz, spd_data_ddr4_2, spd_data_ddr4_2_sz);
|
memcpy(spd_cache + spd_data_ddr4_1_sz, spd_data_ddr4_2, spd_data_ddr4_2_sz);
|
||||||
memset(spd_cache + spd_data_ddr4_1_sz + spd_data_ddr4_2_sz, 0,
|
memset(spd_cache + spd_data_ddr4_1_sz + spd_data_ddr4_2_sz, 0,
|
||||||
spd_cache_sz - (spd_data_ddr4_1_sz + spd_data_ddr4_2_sz));
|
spd_cache_sz - (spd_data_ddr4_1_sz + spd_data_ddr4_2_sz));
|
||||||
calc_spd_cache_crc(spd_cache);
|
calc_spd_cache_crc(spd_cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +124,7 @@ static void test_spd_cache_is_valid(void **state)
|
||||||
|
|
||||||
|
|
||||||
/* Used for setting `sn` parameter value */
|
/* Used for setting `sn` parameter value */
|
||||||
static u32 get_spd_sn_ret_sn[SC_SPD_NUMS] = { 0 };
|
static u32 get_spd_sn_ret_sn[SC_SPD_NUMS] = {0};
|
||||||
static size_t get_spd_sn_ret_sn_idx = 0;
|
static size_t get_spd_sn_ret_sn_idx = 0;
|
||||||
/* Implementation for testing purposes. */
|
/* Implementation for testing purposes. */
|
||||||
enum cb_err get_spd_sn(u8 addr, u32 *sn)
|
enum cb_err get_spd_sn(u8 addr, u32 *sn)
|
||||||
|
@ -145,12 +142,11 @@ static void get_sn_from_spd_cache(uint8_t *spd_cache, u32 arr[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check_if_dimm_changed() has is used only with DDR4, so there tests are not used for DDR3 */
|
/* check_if_dimm_changed() has is used only with DDR4, so there tests are not used for DDR3 */
|
||||||
__attribute__((unused))
|
__attribute__((unused)) static void test_check_if_dimm_changed_not_changed(void **state)
|
||||||
static void test_check_if_dimm_changed_not_changed(void **state)
|
|
||||||
{
|
{
|
||||||
uint8_t *spd_cache;
|
uint8_t *spd_cache;
|
||||||
size_t spd_cache_sz;
|
size_t spd_cache_sz;
|
||||||
struct spd_block blk = { .addr_map = {0}, .spd_array = {0}, .len = 0 };
|
struct spd_block blk = {.addr_map = {0}, .spd_array = {0}, .len = 0};
|
||||||
|
|
||||||
assert_int_equal(CB_SUCCESS, load_spd_cache(&spd_cache, &spd_cache_sz));
|
assert_int_equal(CB_SUCCESS, load_spd_cache(&spd_cache, &spd_cache_sz));
|
||||||
fill_spd_cache_ddr4(spd_cache, spd_cache_sz);
|
fill_spd_cache_ddr4(spd_cache, spd_cache_sz);
|
||||||
|
@ -162,12 +158,11 @@ static void test_check_if_dimm_changed_not_changed(void **state)
|
||||||
assert_false(check_if_dimm_changed(spd_cache, &blk));
|
assert_false(check_if_dimm_changed(spd_cache, &blk));
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((unused))
|
__attribute__((unused)) static void test_check_if_dimm_changed_sn_error(void **state)
|
||||||
static void test_check_if_dimm_changed_sn_error(void **state)
|
|
||||||
{
|
{
|
||||||
uint8_t *spd_cache;
|
uint8_t *spd_cache;
|
||||||
size_t spd_cache_sz;
|
size_t spd_cache_sz;
|
||||||
struct spd_block blk = { .addr_map = {0}, .spd_array = {0}, .len = 0 };
|
struct spd_block blk = {.addr_map = {0}, .spd_array = {0}, .len = 0};
|
||||||
|
|
||||||
assert_int_equal(CB_SUCCESS, load_spd_cache(&spd_cache, &spd_cache_sz));
|
assert_int_equal(CB_SUCCESS, load_spd_cache(&spd_cache, &spd_cache_sz));
|
||||||
fill_spd_cache_ddr4(spd_cache, spd_cache_sz);
|
fill_spd_cache_ddr4(spd_cache, spd_cache_sz);
|
||||||
|
@ -178,12 +173,11 @@ static void test_check_if_dimm_changed_sn_error(void **state)
|
||||||
assert_true(check_if_dimm_changed(spd_cache, &blk));
|
assert_true(check_if_dimm_changed(spd_cache, &blk));
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((unused))
|
__attribute__((unused)) static void test_check_if_dimm_changed_sodimm_lost(void **state)
|
||||||
static void test_check_if_dimm_changed_sodimm_lost(void **state)
|
|
||||||
{
|
{
|
||||||
uint8_t *spd_cache;
|
uint8_t *spd_cache;
|
||||||
size_t spd_cache_sz;
|
size_t spd_cache_sz;
|
||||||
struct spd_block blk = { .addr_map = {0}, .spd_array = {0}, .len = 0 };
|
struct spd_block blk = {.addr_map = {0}, .spd_array = {0}, .len = 0};
|
||||||
|
|
||||||
assert_int_equal(CB_SUCCESS, load_spd_cache(&spd_cache, &spd_cache_sz));
|
assert_int_equal(CB_SUCCESS, load_spd_cache(&spd_cache, &spd_cache_sz));
|
||||||
fill_spd_cache_ddr4(spd_cache, spd_cache_sz);
|
fill_spd_cache_ddr4(spd_cache, spd_cache_sz);
|
||||||
|
@ -196,31 +190,29 @@ static void test_check_if_dimm_changed_sodimm_lost(void **state)
|
||||||
assert_true(check_if_dimm_changed(spd_cache, &blk));
|
assert_true(check_if_dimm_changed(spd_cache, &blk));
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((unused))
|
__attribute__((unused)) static void test_check_if_dimm_changed_new_sodimm(void **state)
|
||||||
static void test_check_if_dimm_changed_new_sodimm(void **state)
|
|
||||||
{
|
{
|
||||||
uint8_t *spd_cache;
|
uint8_t *spd_cache;
|
||||||
size_t spd_cache_sz;
|
size_t spd_cache_sz;
|
||||||
struct spd_block blk = { .addr_map = {0}, .spd_array = {0}, .len = 0 };
|
struct spd_block blk = {.addr_map = {0}, .spd_array = {0}, .len = 0};
|
||||||
|
|
||||||
assert_int_equal(CB_SUCCESS, load_spd_cache(&spd_cache, &spd_cache_sz));
|
assert_int_equal(CB_SUCCESS, load_spd_cache(&spd_cache, &spd_cache_sz));
|
||||||
fill_spd_cache_ddr4(spd_cache, spd_cache_sz);
|
fill_spd_cache_ddr4(spd_cache, spd_cache_sz);
|
||||||
assert_int_equal(CB_SUCCESS, spd_fill_from_cache(spd_cache, &blk));
|
assert_int_equal(CB_SUCCESS, spd_fill_from_cache(spd_cache, &blk));
|
||||||
get_sn_from_spd_cache(spd_cache, get_spd_sn_ret_sn);
|
get_sn_from_spd_cache(spd_cache, get_spd_sn_ret_sn);
|
||||||
memcpy(spd_cache + spd_data_ddr4_1_sz + spd_data_ddr4_2_sz,
|
memcpy(spd_cache + spd_data_ddr4_1_sz + spd_data_ddr4_2_sz, spd_data_ddr4_2,
|
||||||
spd_data_ddr4_2, spd_data_ddr4_2_sz);
|
spd_data_ddr4_2_sz);
|
||||||
|
|
||||||
get_spd_sn_ret_sn_idx = 0;
|
get_spd_sn_ret_sn_idx = 0;
|
||||||
will_return_always(get_spd_sn, CB_SUCCESS);
|
will_return_always(get_spd_sn, CB_SUCCESS);
|
||||||
assert_true(check_if_dimm_changed(spd_cache, &blk));
|
assert_true(check_if_dimm_changed(spd_cache, &blk));
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((unused))
|
__attribute__((unused)) static void test_check_if_dimm_changed_sn_changed(void **state)
|
||||||
static void test_check_if_dimm_changed_sn_changed(void **state)
|
|
||||||
{
|
{
|
||||||
uint8_t *spd_cache;
|
uint8_t *spd_cache;
|
||||||
size_t spd_cache_sz;
|
size_t spd_cache_sz;
|
||||||
struct spd_block blk = { .addr_map = {0}, .spd_array = {0}, .len = 0 };
|
struct spd_block blk = {.addr_map = {0}, .spd_array = {0}, .len = 0};
|
||||||
|
|
||||||
assert_int_equal(CB_SUCCESS, load_spd_cache(&spd_cache, &spd_cache_sz));
|
assert_int_equal(CB_SUCCESS, load_spd_cache(&spd_cache, &spd_cache_sz));
|
||||||
fill_spd_cache_ddr4(spd_cache, spd_cache_sz);
|
fill_spd_cache_ddr4(spd_cache, spd_cache_sz);
|
||||||
|
@ -241,15 +233,15 @@ int main(void)
|
||||||
cmocka_unit_test_setup(test_spd_cache_is_valid, setup_spd_cache_test),
|
cmocka_unit_test_setup(test_spd_cache_is_valid, setup_spd_cache_test),
|
||||||
#if __TEST_SPD_CACHE_DDR == 4
|
#if __TEST_SPD_CACHE_DDR == 4
|
||||||
cmocka_unit_test_setup(test_check_if_dimm_changed_not_changed,
|
cmocka_unit_test_setup(test_check_if_dimm_changed_not_changed,
|
||||||
setup_spd_cache_test),
|
setup_spd_cache_test),
|
||||||
cmocka_unit_test_setup(test_check_if_dimm_changed_sn_error,
|
cmocka_unit_test_setup(test_check_if_dimm_changed_sn_error,
|
||||||
setup_spd_cache_test),
|
setup_spd_cache_test),
|
||||||
cmocka_unit_test_setup(test_check_if_dimm_changed_sodimm_lost,
|
cmocka_unit_test_setup(test_check_if_dimm_changed_sodimm_lost,
|
||||||
setup_spd_cache_test),
|
setup_spd_cache_test),
|
||||||
cmocka_unit_test_setup(test_check_if_dimm_changed_new_sodimm,
|
cmocka_unit_test_setup(test_check_if_dimm_changed_new_sodimm,
|
||||||
setup_spd_cache_test),
|
setup_spd_cache_test),
|
||||||
cmocka_unit_test_setup(test_check_if_dimm_changed_sn_changed,
|
cmocka_unit_test_setup(test_check_if_dimm_changed_sn_changed,
|
||||||
setup_spd_cache_test),
|
setup_spd_cache_test),
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
|
|
||||||
|
|
||||||
#if CONFIG_STACK_SIZE == 0
|
#if CONFIG_STACK_SIZE == 0
|
||||||
# define STACK_SIZE 0x1000
|
#define STACK_SIZE 0x1000
|
||||||
#else
|
#else
|
||||||
# define STACK_SIZE CONFIG_STACK_SIZE
|
#define STACK_SIZE CONFIG_STACK_SIZE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Value used for stack initialization. Change if implementation changes. */
|
/* Value used for stack initialization. Change if implementation changes. */
|
||||||
|
|
|
@ -32,7 +32,7 @@ void test_timestamp_add(void **state)
|
||||||
entry = &glob_ts_table->entries[0];
|
entry = &glob_ts_table->entries[0];
|
||||||
assert_int_equal(1, entry->entry_id);
|
assert_int_equal(1, entry->entry_id);
|
||||||
assert_int_equal(base_multipler - timestamp_base, /* Added timestamp reduced by base */
|
assert_int_equal(base_multipler - timestamp_base, /* Added timestamp reduced by base */
|
||||||
entry->entry_stamp);
|
entry->entry_stamp);
|
||||||
|
|
||||||
/* Add few timestamps to check if all of them will be added properly */
|
/* Add few timestamps to check if all of them will be added properly */
|
||||||
for (i = 1; i < 10; ++i)
|
for (i = 1; i < 10; ++i)
|
||||||
|
@ -43,8 +43,7 @@ void test_timestamp_add(void **state)
|
||||||
for (i = 0; i < 10; ++i) {
|
for (i = 0; i < 10; ++i) {
|
||||||
entry = &glob_ts_table->entries[i];
|
entry = &glob_ts_table->entries[i];
|
||||||
assert_int_equal(i + 1, entry->entry_id);
|
assert_int_equal(i + 1, entry->entry_id);
|
||||||
assert_int_equal(base_multipler * (i + 1) - timestamp_base,
|
assert_int_equal(base_multipler * (i + 1) - timestamp_base, entry->entry_stamp);
|
||||||
entry->entry_stamp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +69,7 @@ void test_timestamp_add_now(void **state)
|
||||||
|
|
||||||
assert_int_equal(1, entry->entry_id);
|
assert_int_equal(1, entry->entry_id);
|
||||||
assert_int_equal(base_multipler - timestamp_base, /* Added timestamp reduced by base */
|
assert_int_equal(base_multipler - timestamp_base, /* Added timestamp reduced by base */
|
||||||
entry->entry_stamp);
|
entry->entry_stamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_timestamp_rescale_table(void **state)
|
void test_timestamp_rescale_table(void **state)
|
||||||
|
|
|
@ -4,14 +4,14 @@
|
||||||
|
|
||||||
TEST_REGION(cbfs_cache, TEST_CBFS_CACHE_SIZE);
|
TEST_REGION(cbfs_cache, TEST_CBFS_CACHE_SIZE);
|
||||||
|
|
||||||
const u8 test_data_1[TEST_DATA_1_SIZE] = { TEST_DATA_1 };
|
const u8 test_data_1[TEST_DATA_1_SIZE] = {TEST_DATA_1};
|
||||||
const u8 test_data_2[TEST_DATA_2_SIZE] = { TEST_DATA_2 };
|
const u8 test_data_2[TEST_DATA_2_SIZE] = {TEST_DATA_2};
|
||||||
const u8 test_data_int_1[TEST_DATA_INT_1_SIZE] = { LE64(TEST_DATA_INT_1) };
|
const u8 test_data_int_1[TEST_DATA_INT_1_SIZE] = {LE64(TEST_DATA_INT_1)};
|
||||||
const u8 test_data_int_2[TEST_DATA_INT_2_SIZE] = { LE64(TEST_DATA_INT_2) };
|
const u8 test_data_int_2[TEST_DATA_INT_2_SIZE] = {LE64(TEST_DATA_INT_2)};
|
||||||
const u8 test_data_int_3[TEST_DATA_INT_3_SIZE] = { LE64(TEST_DATA_INT_3) };
|
const u8 test_data_int_3[TEST_DATA_INT_3_SIZE] = {LE64(TEST_DATA_INT_3)};
|
||||||
|
|
||||||
const u8 good_hash[VB2_SHA256_DIGEST_SIZE] = { TEST_SHA256 };
|
const u8 good_hash[VB2_SHA256_DIGEST_SIZE] = {TEST_SHA256};
|
||||||
const u8 bad_hash[VB2_SHA256_DIGEST_SIZE] = { INVALID_SHA256 };
|
const u8 bad_hash[VB2_SHA256_DIGEST_SIZE] = {INVALID_SHA256};
|
||||||
|
|
||||||
const struct cbfs_test_file file_no_hash = {
|
const struct cbfs_test_file file_no_hash = {
|
||||||
.header = HEADER_INITIALIZER(CBFS_TYPE_RAW, 0, TEST_DATA_1_SIZE),
|
.header = HEADER_INITIALIZER(CBFS_TYPE_RAW, 0, TEST_DATA_1_SIZE),
|
||||||
|
|
Loading…
Reference in New Issue