From c08b6a7037e4dd21f08a2fc8d40db51c7b4e051b Mon Sep 17 00:00:00 2001 From: Jakub Czapiga Date: Mon, 10 Jan 2022 13:36:47 +0000 Subject: 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/60970 Tested-by: build bot (Jenkins) Reviewed-by: Paul Fagerburg --- tests/acpi/acpigen-test.c | 20 +- tests/commonlib/region-test.c | 26 +- tests/console/routing-test.c | 5 +- tests/device/ddr4-test.c | 4 +- tests/device/i2c-test.c | 90 ++-- tests/include/tests/lib/edid.h | 247 +++++---- tests/lib/cbfs-lookup-test.c | 26 +- tests/lib/cbmem_console-test.c | 35 +- tests/lib/cbmem_stage_cache-test.c | 16 +- tests/lib/compute_ip_checksum-test.c | 11 +- tests/lib/coreboot_table-test.c | 96 ++-- tests/lib/crc_byte-test.c | 56 +- tests/lib/dimm_info_util-test.c | 94 ++-- tests/lib/edid-test.c | 959 ++++++++++++++++++----------------- tests/lib/fmap-test.c | 37 +- tests/lib/hexstrtobin-test.c | 10 +- tests/lib/imd-test.c | 65 ++- tests/lib/imd_cbmem-test.c | 5 +- tests/lib/libgcc-test.c | 204 ++++---- tests/lib/lzma-test.c | 26 +- tests/lib/memchr-test.c | 54 +- tests/lib/memcpy-test.c | 24 +- tests/lib/memmove-test.c | 33 +- tests/lib/memrange-test.c | 194 ++++--- tests/lib/memset-test.c | 16 +- tests/lib/region_file-test.c | 59 ++- tests/lib/rtc-test.c | 36 +- tests/lib/spd_cache-test.c | 56 +- tests/lib/stack-test.c | 4 +- tests/lib/timestamp-test.c | 7 +- tests/mock/cbfs_file_mock.c | 14 +- 31 files changed, 1263 insertions(+), 1266 deletions(-) diff --git a/tests/acpi/acpigen-test.c b/tests/acpi/acpigen-test.c index 6bd1d02689f9..156b54409551 100644 --- a/tests/acpi/acpigen-test.c +++ b/tests/acpi/acpigen-test.c @@ -13,7 +13,7 @@ static u32 decode_package_length(const char *ptr) { const u8 *aml = (u8 *)ptr; 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 package_length = 0; @@ -106,7 +106,7 @@ static void test_acpigen_nested_ifs(void **state) for (int i = 0; i < nesting_level; ++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) @@ -203,14 +203,14 @@ static void test_acpigen_scope_with_contents(void **state) int main(void) { const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_acpigen_single_if, - setup_acpigen, teardown_acpigen), - cmocka_unit_test_setup_teardown(test_acpigen_nested_ifs, - setup_acpigen, teardown_acpigen), - cmocka_unit_test_setup_teardown(test_acpigen_write_package, - setup_acpigen, teardown_acpigen), - cmocka_unit_test_setup_teardown(test_acpigen_scope_with_contents, - setup_acpigen, teardown_acpigen), + cmocka_unit_test_setup_teardown(test_acpigen_single_if, setup_acpigen, + teardown_acpigen), + cmocka_unit_test_setup_teardown(test_acpigen_nested_ifs, setup_acpigen, + teardown_acpigen), + cmocka_unit_test_setup_teardown(test_acpigen_write_package, setup_acpigen, + teardown_acpigen), + cmocka_unit_test_setup_teardown(test_acpigen_scope_with_contents, setup_acpigen, + teardown_acpigen), }; return cb_run_group_tests(tests, NULL, NULL); diff --git a/tests/commonlib/region-test.c b/tests/commonlib/region-test.c index 59f272a7d95d..32804825a6ed 100644 --- a/tests/commonlib/region-test.c +++ b/tests/commonlib/region-test.c @@ -14,30 +14,30 @@ static void test_region(void **state) assert_true(VAL(5) + 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_sz(&outer), VAL(4)); 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)); - 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)); - 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)); - 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)); - 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)); - struct region below = { .offset = 0, .size = VAL(1) }; + struct region below = {.offset = 0, .size = VAL(1)}; 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)); } @@ -58,8 +58,8 @@ static int mock_unmap(const struct region_device *rdev, void *mapping) return mock(); } -static ssize_t mock_readat(const struct region_device *rdev, void *buffer, - size_t offset, size_t size) +static ssize_t mock_readat(const struct region_device *rdev, void *buffer, size_t offset, + size_t size) { check_expected_ptr(rdev); check_expected_ptr(buffer); @@ -73,8 +73,8 @@ static ssize_t mock_readat(const struct region_device *rdev, void *buffer, return ret; } -static ssize_t mock_writeat(const struct region_device *rdev, const void *buffer, - size_t offset, size_t size) +static ssize_t mock_writeat(const struct region_device *rdev, const void *buffer, size_t offset, + size_t size) { check_expected_ptr(rdev); check_expected_ptr(buffer); @@ -365,7 +365,7 @@ static void test_mem_rdev(void **state) /* Test read/write/erase of larger chunk. */ size_t offs = 0x47; - size_t chunk = 0x72; + size_t chunk = 0x72; memset(backing, 0, size); memset(scratch, 0, size); memset(scratch + offs, 0x39, chunk); diff --git a/tests/console/routing-test.c b/tests/console/routing-test.c index 153ca77c198c..3cba51f7c45a 100644 --- a/tests/console/routing-test.c +++ b/tests/console/routing-test.c @@ -42,7 +42,7 @@ static void test_console_log_level(void **state) for (int i = 0; i < ARRAY_SIZE(combinations); i++) { console_loglevel = combinations[i].log_lvl; 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) { const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_console_log_level, - setup_console_log_level, + cmocka_unit_test_setup_teardown(test_console_log_level, setup_console_log_level, teardown_console_log_level), }; diff --git a/tests/device/ddr4-test.c b/tests/device/ddr4-test.c index 3ee1e79f1dba..d5d7ee7d36ef 100644 --- a/tests/device/ddr4-test.c +++ b/tests/device/ddr4-test.c @@ -33,9 +33,7 @@ static void ddr4_speed_mhz_to_mts_test(void **state) int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(ddr4_speed_mhz_to_mts_test) - }; + const struct CMUnitTest tests[] = {cmocka_unit_test(ddr4_speed_mhz_to_mts_test)}; return cb_run_group_tests(tests, NULL, NULL); } diff --git a/tests/device/i2c-test.c b/tests/device/i2c-test.c index 010b8688f995..4b96d940f9d8 100644 --- a/tests/device/i2c-test.c +++ b/tests/device/i2c-test.c @@ -18,20 +18,27 @@ typedef struct { } i2c_ex_devs_t; i2c_ex_devs_t i2c_ex_devs[] = { - {.bus = 0, .slave = 0xA, .regs = { - {.reg = 0x0, .data = 0xB}, - {.reg = 0x1, .data = 0x6}, - {.reg = 0x2, .data = 0xF}, - } }, - {.bus = 0, .slave = 0x3, .regs = { - {.reg = 0x0, .data = 0xDE}, - {.reg = 0x1, .data = 0xAD}, - {.reg = 0x2, .data = 0xBE}, - } }, + { + .bus = 0, + .slave = 0xA, + .regs = { + {.reg = 0x0, .data = 0xB}, + {.reg = 0x1, .data = 0x6}, + {.reg = 0x2, .data = 0xF}, + } + }, + { + .bus = 0, + .slave = 0x3, + .regs = { + {.reg = 0x0, .data = 0xDE}, + {.reg = 0x1, .data = 0xAD}, + {.reg = 0x2, .data = 0xBE}, + } + }, }; -int platform_i2c_transfer(unsigned int bus, struct i2c_msg *segments, - int count) +int platform_i2c_transfer(unsigned int bus, struct i2c_msg *segments, int count) { int i; int reg; @@ -73,22 +80,19 @@ int platform_i2c_transfer(unsigned int bus, struct i2c_msg *segments, static void mock_expect_params_platform_i2c_transfer(void) { - unsigned long int expected_flags[] = {0, I2C_M_RD, I2C_M_TEN, - I2C_M_RECV_LEN, I2C_M_NOSTART}; + unsigned long int expected_flags[] = {0, I2C_M_RD, I2C_M_TEN, I2C_M_RECV_LEN, + I2C_M_NOSTART}; /* Flags should always be only within supported range */ - expect_in_set_count(platform_i2c_transfer, segments->flags, - expected_flags, -1); + expect_in_set_count(platform_i2c_transfer, segments->flags, expected_flags, -1); - expect_not_value_count(platform_i2c_transfer, segments->buf, - NULL, -1); + expect_not_value_count(platform_i2c_transfer, segments->buf, NULL, -1); - expect_in_range_count(platform_i2c_transfer, count, 1, INT_MAX, - -1); + expect_in_range_count(platform_i2c_transfer, count, 1, INT_MAX, -1); } -#define MASK 0x3 -#define SHIFT 0x1 +#define MASK 0x3 +#define SHIFT 0x1 static void i2c_read_field_test(void **state) { @@ -101,21 +105,17 @@ static void i2c_read_field_test(void **state) with expected value. */ for (i = 0; i < ARRAY_SIZE(i2c_ex_devs); i++) for (j = 0; j < ARRAY_SIZE(i2c_ex_devs[0].regs); j++) { - i2c_read_field(i2c_ex_devs[i].bus, - i2c_ex_devs[i].slave, - i2c_ex_devs[i].regs[j].reg, - &buf, MASK, SHIFT); - assert_int_equal((i2c_ex_devs[i].regs[j].data & - (MASK << SHIFT)) >> SHIFT, buf); + i2c_read_field(i2c_ex_devs[i].bus, i2c_ex_devs[i].slave, + i2c_ex_devs[i].regs[j].reg, &buf, MASK, SHIFT); + assert_int_equal( + (i2c_ex_devs[i].regs[j].data & (MASK << SHIFT)) >> SHIFT, buf); }; /* Read whole registers */ for (i = 0; i < ARRAY_SIZE(i2c_ex_devs); i++) for (j = 0; j < ARRAY_SIZE(i2c_ex_devs[0].regs); j++) { - i2c_read_field(i2c_ex_devs[i].bus, - i2c_ex_devs[i].slave, - i2c_ex_devs[i].regs[j].reg, - &buf, 0xFF, 0); + i2c_read_field(i2c_ex_devs[i].bus, i2c_ex_devs[i].slave, + i2c_ex_devs[i].regs[j].reg, &buf, 0xFF, 0); assert_int_equal(i2c_ex_devs[i].regs[j].data, buf); }; } @@ -133,36 +133,28 @@ static void i2c_write_field_test(void **state) for (j = 0; j < ARRAY_SIZE(i2c_ex_devs[0].regs); j++) { buf = 0x0; tmp = i2c_ex_devs[i].regs[j].data; - i2c_write_field(i2c_ex_devs[i].bus, - i2c_ex_devs[i].slave, - i2c_ex_devs[i].regs[j].reg, - buf, MASK, SHIFT); + i2c_write_field(i2c_ex_devs[i].bus, i2c_ex_devs[i].slave, + i2c_ex_devs[i].regs[j].reg, buf, MASK, SHIFT); assert_int_equal(i2c_ex_devs[i].regs[j].data, - (tmp & ~(MASK << SHIFT)) | (buf << SHIFT)); + (tmp & ~(MASK << SHIFT)) | (buf << SHIFT)); }; /* Set all bits in all registers, this time verify using i2c_read_field() accessor. */ for (i = 0; i < ARRAY_SIZE(i2c_ex_devs); i++) for (j = 0; j < ARRAY_SIZE(i2c_ex_devs[0].regs); j++) { - i2c_write_field(i2c_ex_devs[i].bus, - i2c_ex_devs[i].slave, - i2c_ex_devs[i].regs[j].reg, - 0xFF, 0xFF, 0); - i2c_read_field(i2c_ex_devs[i].bus, - i2c_ex_devs[i].slave, - i2c_ex_devs[i].regs[j].reg, - &buf, 0xFF, 0); + i2c_write_field(i2c_ex_devs[i].bus, i2c_ex_devs[i].slave, + i2c_ex_devs[i].regs[j].reg, 0xFF, 0xFF, 0); + i2c_read_field(i2c_ex_devs[i].bus, i2c_ex_devs[i].slave, + i2c_ex_devs[i].regs[j].reg, &buf, 0xFF, 0); assert_int_equal(buf, 0xFF); }; } int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(i2c_read_field_test), - cmocka_unit_test(i2c_write_field_test) - }; + const struct CMUnitTest tests[] = {cmocka_unit_test(i2c_read_field_test), + cmocka_unit_test(i2c_write_field_test)}; return cb_run_group_tests(tests, NULL, NULL); } diff --git a/tests/include/tests/lib/edid.h b/tests/include/tests/lib/edid.h index 25d5c8a159dd..7d59ed4bc196 100644 --- a/tests/include/tests/lib/edid.h +++ b/tests/include/tests/lib/edid.h @@ -24,7 +24,7 @@ struct edid_raw { /* Basic display parameters */ uint8_t video_input_type; uint8_t horizontal_size; /* [cm] */ - uint8_t vertical_size; /* [cm] */ + uint8_t vertical_size; /* [cm] */ uint8_t display_gamma; uint8_t supported_features; @@ -46,157 +46,152 @@ struct edid_raw { uint8_t checksum; } __packed; -_Static_assert(sizeof(struct edid_raw) == 128, - "assert failed: edid_raw size mismatch"); - -#define EDID_HEADER_RAW { 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_NAME "UNK" -#define EDID_PRODUCT_CODE 0x1234 -#define EDID_SERIAL_NUMBER 0x56789ABC -#define EDID_MANUFACTURE_WEEK 23u -#define EDID_MANUFACTURE_NO_WEEK 0u -#define EDID_MANUFACTURE_YEAR (2015u - 1990u) +_Static_assert(sizeof(struct edid_raw) == 128, "assert failed: edid_raw size mismatch"); + +#define EDID_HEADER_RAW \ + { \ + 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_NAME "UNK" +#define EDID_PRODUCT_CODE 0x1234 +#define EDID_SERIAL_NUMBER 0x56789ABC +#define EDID_MANUFACTURE_WEEK 23u +#define EDID_MANUFACTURE_NO_WEEK 0u +#define EDID_MANUFACTURE_YEAR (2015u - 1990u) /* Video Input Definition for Analog Video Signal Interface */ -#define EDID_ANALOG_VSI (0u << 7) -#define EDID_SIGNAL_LEVEL_0 0u -#define EDID_SIGNAL_LEVEL_1 (1u << 5) -#define EDID_SIGNAL_LEVEL_2 (2u << 5) -#define EDID_SIGNAL_LEVEL_3 (3u << 5) +#define EDID_ANALOG_VSI (0u << 7) +#define EDID_SIGNAL_LEVEL_0 0u +#define EDID_SIGNAL_LEVEL_1 (1u << 5) +#define EDID_SIGNAL_LEVEL_2 (2u << 5) +#define EDID_SIGNAL_LEVEL_3 (3u << 5) #define EDID_VIDEO_SETUP_BLANK_EQ_BLACK 0u #define EDID_VIDEO_SETUP_BLANK_TO_BLACK (1u << 4) -#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_ON_GREEN(v) ((v != 0 ? 0x1 : 0x0) << 1) -#define EDID_SERRATION_VSYNC(v) (v != 0 ? 0x1 : 0x0) +#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_ON_GREEN(v) ((v != 0 ? 0x1 : 0x0) << 1) +#define EDID_SERRATION_VSYNC(v) (v != 0 ? 0x1 : 0x0) /* Video Input Definition for Digital Video Signal Interface */ -#define EDID_DIGITAL_VSI (1u << 7) -#define EDID_COLOR_BIT_DEPTH_UNDEFINED 0u -#define EDID_COLOR_BIT_DEPTH_6B (1u << 4) -#define EDID_COLOR_BIT_DEPTH_8B (2u << 4) -#define EDID_COLOR_BIT_DEPTH_10B (3u << 4) -#define EDID_COLOR_BIT_DEPTH_12B (4u << 4) -#define EDID_COLOR_BIT_DEPTH_14B (5u << 4) -#define EDID_COLOR_BIT_DEPTH_16B (6u << 4) -#define EDID_INTERFACE_UNDEFINED 0u -#define EDID_INTERFACE_DVI 1u -#define EDID_INTERFACE_HDMI_A 2u -#define EDID_INTERFACE_HDMI_B 3u -#define EDID_INTERFACE_MDDI 4u -#define EDID_INTERFACE_DP 5u +#define EDID_DIGITAL_VSI (1u << 7) +#define EDID_COLOR_BIT_DEPTH_UNDEFINED 0u +#define EDID_COLOR_BIT_DEPTH_6B (1u << 4) +#define EDID_COLOR_BIT_DEPTH_8B (2u << 4) +#define EDID_COLOR_BIT_DEPTH_10B (3u << 4) +#define EDID_COLOR_BIT_DEPTH_12B (4u << 4) +#define EDID_COLOR_BIT_DEPTH_14B (5u << 4) +#define EDID_COLOR_BIT_DEPTH_16B (6u << 4) +#define EDID_INTERFACE_UNDEFINED 0u +#define EDID_INTERFACE_DVI 1u +#define EDID_INTERFACE_HDMI_A 2u +#define EDID_INTERFACE_HDMI_B 3u +#define EDID_INTERFACE_MDDI 4u +#define EDID_INTERFACE_DP 5u /* BEGIN Supported features */ -#define EDID_STANDBY_MODE(v) ((v != 0 ? 0x1 : 0x0) << 7) -#define EDID_SUSPEND_MODE(v) ((v != 0 ? 0x1 : 0x0) << 6) -#define EDID_ACTIVE_OFF(v) ((v != 0 ? 0x1 : 0x0) << 5) +#define EDID_STANDBY_MODE(v) ((v != 0 ? 0x1 : 0x0) << 7) +#define EDID_SUSPEND_MODE(v) ((v != 0 ? 0x1 : 0x0) << 6) +#define EDID_ACTIVE_OFF(v) ((v != 0 ? 0x1 : 0x0) << 5) /* For analog interface */ -#define EDID_COLOR_TYPE_MONO 0u -#define EDID_COLOR_TYPE_RGB (1u << 3) -#define EDID_COLOR_TYPE_NON_RGB (2u << 3) -#define EDID_COLOR_TYPE_UNDEFINED (3u << 3) +#define EDID_COLOR_TYPE_MONO 0u +#define EDID_COLOR_TYPE_RGB (1u << 3) +#define EDID_COLOR_TYPE_NON_RGB (2u << 3) +#define EDID_COLOR_TYPE_UNDEFINED (3u << 3) /* For digital interface */ -#define EDID_COLOR_FORMAT_RGB444 0u -#define EDID_COLOR_FORMAT_RGB444_YCRCB444 (1u << 3) -#define EDID_COLOR_FORMAT_RGB444_YCRCB422 (2u << 3) -#define EDID_COLOR_FORMAT_RGB444_YCRCB422_YCRCB422 (3u << 3) - -#define EDID_SRGB_SUPPORTED(v) (((v) == 0 ? 0u : 1u) << 2) -#define EDID_PREFERRED_TIMING_EXTENDED_INFO (1u << 1) -#define EDID_PREFERRED_TIMING_NO_EXTENDED_INFO 0u -#define EDID_DISPLAY_FREQUENCY_CONTINUOUS 1u -#define EDID_DISPLAY_FREQUENCY_NON_CONTINUOUS 0u +#define EDID_COLOR_FORMAT_RGB444 0u +#define EDID_COLOR_FORMAT_RGB444_YCRCB444 (1u << 3) +#define EDID_COLOR_FORMAT_RGB444_YCRCB422 (2u << 3) +#define EDID_COLOR_FORMAT_RGB444_YCRCB422_YCRCB422 (3u << 3) + +#define EDID_SRGB_SUPPORTED(v) (((v) == 0 ? 0u : 1u) << 2) +#define EDID_PREFERRED_TIMING_EXTENDED_INFO (1u << 1) +#define EDID_PREFERRED_TIMING_NO_EXTENDED_INFO 0u +#define EDID_DISPLAY_FREQUENCY_CONTINUOUS 1u +#define EDID_DISPLAY_FREQUENCY_NON_CONTINUOUS 0u /* END Supported features */ /* Red X 0.640 */ -#define EDID_COLOR_R_X 0x25 +#define EDID_COLOR_R_X 0x25 /* Red Y 0.330 */ -#define EDID_COLOR_R_Y 0x152 +#define EDID_COLOR_R_Y 0x152 /* Green X 0.300 */ -#define EDID_COLOR_G_X 0x13a +#define EDID_COLOR_G_X 0x13a /* Green Y 0.600 */ -#define EDID_COLOR_G_Y 0x267 +#define EDID_COLOR_G_Y 0x267 /* Blue X 0.150 */ -#define EDID_COLOR_B_X 0x9a +#define EDID_COLOR_B_X 0x9a /* Blue Y 0.060 */ -#define EDID_COLOR_B_Y 0x3e +#define EDID_COLOR_B_Y 0x3e /* White X 0.3125 */ -#define EDID_COLOR_W_X 0xa +#define EDID_COLOR_W_X 0xa /* White Y 0.3291 */ -#define EDID_COLOR_W_Y 0x22a +#define EDID_COLOR_W_Y 0x22a /* 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_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_W_X10_Y10 (((EDID_COLOR_W_X & 0x3) << 2) | (EDID_COLOR_W_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_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)) /* Concatenated 0 and 1 bits of each color. To be put * 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_BW_XY ((EDID_COLOR_B_X10_Y10 << 4) | EDID_COLOR_W_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) /* Bits 9 through 2 of each color */ -#define EDID_COLOR_R_X92 (EDID_COLOR_R_X >> 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_Y92 (EDID_COLOR_G_Y >> 2) -#define EDID_COLOR_B_X92 (EDID_COLOR_B_X >> 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_Y92 (EDID_COLOR_W_Y >> 2) - -#define EDID_ESTABLISHED_TIMINGS_1_800x600_60Hz 1u -#define EDID_ESTABLISHED_TIMINGS_1_800x600_56Hz (1u << 1) -#define EDID_ESTABLISHED_TIMINGS_1_640x480_75Hz (1u << 2) -#define EDID_ESTABLISHED_TIMINGS_1_640x480_72Hz (1u << 3) -#define EDID_ESTABLISHED_TIMINGS_1_640x480_67Hz (1u << 4) -#define EDID_ESTABLISHED_TIMINGS_1_640x480_60Hz (1u << 5) -#define EDID_ESTABLISHED_TIMINGS_1_720x400_88Hz (1u << 6) -#define EDID_ESTABLISHED_TIMINGS_1_720x400_70Hz (1u << 7) - -#define EDID_ESTABLISHED_TIMINGS_2_1280x1024_75Hz 1u -#define EDID_ESTABLISHED_TIMINGS_2_1024x768_75Hz (1u << 1) -#define EDID_ESTABLISHED_TIMINGS_2_1024x768_70Hz (1u << 2) -#define EDID_ESTABLISHED_TIMINGS_2_1024x768_60Hz (1u << 3) -#define EDID_ESTABLISHED_TIMINGS_2_1024x768_80HzI (1u << 4) -#define EDID_ESTABLISHED_TIMINGS_2_832x624_75Hz (1u << 5) -#define EDID_ESTABLISHED_TIMINGS_2_800x600_75Hz (1u << 6) -#define EDID_ESTABLISHED_TIMINGS_2_800x600_72Hz (1u << 7) - -#define EDID_MANUFACTURERS_TIMINGS_1152x870_75Hz (1u << 7) - -#define EDID_HORIZONTAL_ACCESSIBLE_PIXELS(px) (((px) / 8 - 31) & 0xFF) -#define EDID_ASPECT_RATIO_16_10 0u -#define EDID_ASPECT_RATIO_4_3 (1u << 6) -#define EDID_ASPECT_RATIO_5_4 (2u << 6) -#define EDID_ASPECT_RATIO_16_9 (3u << 6) -#define EDID_FIELD_REFRESH_RATE(hz) (((hz) - 60) & 0x1f) - -#define EDID_PIXEL_CLOCK(v) (((v) / 10000) & 0xFFFF) - -#define EDID_RAW_DEFAULT_PARAMS .header = EDID_HEADER_RAW, \ - .edid_version = 1, \ - .edid_revision = 4, \ - .manufacturer_id = EDID_MANUFACTURER_ID, \ - .product_code = EDID_PRODUCT_CODE, \ - .serial_number = EDID_SERIAL_NUMBER, \ - .manufacture_week = EDID_MANUFACTURE_NO_WEEK, \ - .manufacture_year = EDID_MANUFACTURE_YEAR, \ - .color_characteristics = { \ - 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, \ - } +#define EDID_COLOR_R_X92 (EDID_COLOR_R_X >> 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_Y92 (EDID_COLOR_G_Y >> 2) +#define EDID_COLOR_B_X92 (EDID_COLOR_B_X >> 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_Y92 (EDID_COLOR_W_Y >> 2) + +#define EDID_ESTABLISHED_TIMINGS_1_800x600_60Hz 1u +#define EDID_ESTABLISHED_TIMINGS_1_800x600_56Hz (1u << 1) +#define EDID_ESTABLISHED_TIMINGS_1_640x480_75Hz (1u << 2) +#define EDID_ESTABLISHED_TIMINGS_1_640x480_72Hz (1u << 3) +#define EDID_ESTABLISHED_TIMINGS_1_640x480_67Hz (1u << 4) +#define EDID_ESTABLISHED_TIMINGS_1_640x480_60Hz (1u << 5) +#define EDID_ESTABLISHED_TIMINGS_1_720x400_88Hz (1u << 6) +#define EDID_ESTABLISHED_TIMINGS_1_720x400_70Hz (1u << 7) + +#define EDID_ESTABLISHED_TIMINGS_2_1280x1024_75Hz 1u +#define EDID_ESTABLISHED_TIMINGS_2_1024x768_75Hz (1u << 1) +#define EDID_ESTABLISHED_TIMINGS_2_1024x768_70Hz (1u << 2) +#define EDID_ESTABLISHED_TIMINGS_2_1024x768_60Hz (1u << 3) +#define EDID_ESTABLISHED_TIMINGS_2_1024x768_80HzI (1u << 4) +#define EDID_ESTABLISHED_TIMINGS_2_832x624_75Hz (1u << 5) +#define EDID_ESTABLISHED_TIMINGS_2_800x600_75Hz (1u << 6) +#define EDID_ESTABLISHED_TIMINGS_2_800x600_72Hz (1u << 7) + +#define EDID_MANUFACTURERS_TIMINGS_1152x870_75Hz (1u << 7) + +#define EDID_HORIZONTAL_ACCESSIBLE_PIXELS(px) (((px) / 8 - 31) & 0xFF) +#define EDID_ASPECT_RATIO_16_10 0u +#define EDID_ASPECT_RATIO_4_3 (1u << 6) +#define EDID_ASPECT_RATIO_5_4 (2u << 6) +#define EDID_ASPECT_RATIO_16_9 (3u << 6) +#define EDID_FIELD_REFRESH_RATE(hz) (((hz)-60) & 0x1f) + +#define EDID_PIXEL_CLOCK(v) (((v) / 10000) & 0xFFFF) + +#define EDID_RAW_DEFAULT_PARAMS \ + .header = EDID_HEADER_RAW, .edid_version = 1, .edid_revision = 4, \ + .manufacturer_id = EDID_MANUFACTURER_ID, .product_code = EDID_PRODUCT_CODE, \ + .serial_number = EDID_SERIAL_NUMBER, .manufacture_week = EDID_MANUFACTURE_NO_WEEK, \ + .manufacture_year = EDID_MANUFACTURE_YEAR, \ + .color_characteristics = { \ + 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 */ diff --git a/tests/lib/cbfs-lookup-test.c b/tests/lib/cbfs-lookup-test.c index 78481d782e2b..63a8298cf7de 100644 --- a/tests/lib/cbfs-lookup-test.c +++ b/tests/lib/cbfs-lookup-test.c @@ -12,8 +12,8 @@ static struct cbfs_boot_device cbd; -static u8 aligned_cbfs_buffer[(sizeof(struct cbfs_test_file) + CBFS_ALIGNMENT) * 10] - __aligned(CBFS_ALIGNMENT); +static u8 aligned_cbfs_buffer[(sizeof(struct cbfs_test_file) + CBFS_ALIGNMENT) * 10] __aligned( + CBFS_ALIGNMENT); static u8 *unaligned_cbfs_buffer = &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. */ 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; 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]); } else { 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]); memcpy(data_ptr, files[i], file_size); } @@ -386,7 +386,8 @@ static void test_cbfs_image_not_aligned(void **state) size_t size_out; struct cbfs_test_state *s = *state; 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], s->cbfs_size - 5)); @@ -663,8 +664,9 @@ static void test_cbfs_two_files_with_same_name(void **state) size_out = 0; expect_lookup_result(CB_SUCCESS); mapping = cbfs_map(TEST_DATA_INT_1_FILENAME, &size_out); - assert_ptr_equal(mapping, &s->cbfs_buf[third_file_start - + be32_to_cpu(test_file_int_1.header.offset)]); + assert_ptr_equal( + 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)); } @@ -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); memcpy(s->cbfs_buf, &test_file_2, sizeof(test_file_2)); f = (struct cbfs_test_file *)s->cbfs_buf; - f->header.attributes_offset = cpu_to_be32( - sizeof(struct cbfs_file) + FILENAME_SIZE - + sizeof(struct cbfs_file_attr_compression)); + f->header.attributes_offset = cpu_to_be32(sizeof(struct cbfs_file) + FILENAME_SIZE + + sizeof(struct cbfs_file_attr_compression)); f->header.offset = cpu_to_be32(sizeof(struct cbfs_file) + FILENAME_SIZE); 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( \ CBFS_LOOKUP_NAME_SETUP_PRESTATE_COMMON_TEST( \ ("aligned, " name), (test_fn), setup_test_cbfs_aligned, (prestate)), \ - CBFS_LOOKUP_NAME_SETUP_PRESTATE_COMMON_TEST( \ - ("unaligned, " name), (test_fn), setup_test_cbfs_unaligned, (prestate))) + CBFS_LOOKUP_NAME_SETUP_PRESTATE_COMMON_TEST(("unaligned, " name), (test_fn), \ + setup_test_cbfs_unaligned, \ + (prestate))) #define CBFS_LOOKUP_TEST(test_fn) CBFS_LOOKUP_NAME_PRESTATE_TEST(#test_fn, test_fn, NULL) diff --git a/tests/lib/cbmem_console-test.c b/tests/lib/cbmem_console-test.c index fca84a7bd4e4..a5ca3b09331a 100644 --- a/tests/lib/cbmem_console-test.c +++ b/tests/lib/cbmem_console-test.c @@ -47,10 +47,11 @@ void test_cbmemc_tx_byte(void **state) { int i; u32 cursor; - const unsigned char data[] = "Random testing string\n" - "`1234567890-=~!@#$%^&*()_+\n" - "abcdefghijklmnopqrstuvwxyz\n" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; + const unsigned char data[] = + "Random testing string\n" + "`1234567890-=~!@#$%^&*()_+\n" + "abcdefghijklmnopqrstuvwxyz\n" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; for (i = 0; i < ARRAY_SIZE(data); ++i) cbmemc_tx_byte(data[i]); @@ -69,15 +70,16 @@ void test_cbmemc_tx_byte_overflow(void **state) u32 cursor; u32 flags; const uint32_t console_size = current_console->size; - const unsigned char data[] = "Another random string\n" - "abcdefghijklmnopqrstuvwxyz\n" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" - "`1234567890-=~!@#$%^&*()_+\n"; + const unsigned char data[] = + "Another random string\n" + "abcdefghijklmnopqrstuvwxyz\n" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" + "`1234567890-=~!@#$%^&*()_+\n"; const int data_size = ARRAY_SIZE(data) - 1; const int data_stream_length = console_size + data_size; const int overflow_bytes = data_stream_length % console_size; unsigned char *check_buffer = - (unsigned char *)malloc(sizeof(unsigned char) * console_size); + (unsigned char *)malloc(sizeof(unsigned char) * console_size); /* Fill console buffer */ 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); /* Check if overflow buffer was overwritten */ - assert_memory_not_equal(current_console->body, - data, - overflow_bytes); + assert_memory_not_equal(current_console->body, data, overflow_bytes); /* Check if rest of the buffer contents, that should not be overridden, * is the same. */ assert_memory_equal(¤t_console->body[overflow_bytes], - check_buffer + overflow_bytes, - console_size - overflow_bytes); + check_buffer + overflow_bytes, console_size - overflow_bytes); free(check_buffer); } @@ -120,10 +119,10 @@ int main(void) { const struct CMUnitTest tests[] = { cmocka_unit_test_teardown(test_cbmemc_init, teardown_cbmemc), - cmocka_unit_test_setup_teardown(test_cbmemc_tx_byte, - setup_cbmemc, teardown_cbmemc), - cmocka_unit_test_setup_teardown(test_cbmemc_tx_byte_overflow, - setup_cbmemc, teardown_cbmemc), + cmocka_unit_test_setup_teardown(test_cbmemc_tx_byte, setup_cbmemc, + teardown_cbmemc), + cmocka_unit_test_setup_teardown(test_cbmemc_tx_byte_overflow, setup_cbmemc, + teardown_cbmemc), }; return cb_run_group_tests(tests, NULL, NULL); diff --git a/tests/lib/cbmem_stage_cache-test.c b/tests/lib/cbmem_stage_cache-test.c index 070f4318cafa..7256a270c121 100644 --- a/tests/lib/cbmem_stage_cache-test.c +++ b/tests/lib/cbmem_stage_cache-test.c @@ -180,14 +180,14 @@ void test_stage_cache_load_stage(void **state) int main(void) { const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_stage_cache_add, - setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_stage_cache_add_raw, - setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_stage_cache_get_raw, - setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_stage_cache_load_stage, - setup_test, teardown_test), + cmocka_unit_test_setup_teardown(test_stage_cache_add, setup_test, + teardown_test), + cmocka_unit_test_setup_teardown(test_stage_cache_add_raw, setup_test, + teardown_test), + cmocka_unit_test_setup_teardown(test_stage_cache_get_raw, setup_test, + teardown_test), + cmocka_unit_test_setup_teardown(test_stage_cache_load_stage, setup_test, + teardown_test), }; return cb_run_group_tests(tests, NULL, NULL); diff --git a/tests/lib/compute_ip_checksum-test.c b/tests/lib/compute_ip_checksum-test.c index 18e7ff0f841b..d465bfc4d0f6 100644 --- a/tests/lib/compute_ip_checksum-test.c +++ b/tests/lib/compute_ip_checksum-test.c @@ -7,12 +7,9 @@ #include static const uint8_t test_data_simple[] = { - 0x64, 0x3b, 0x33, 0x17, 0x34, 0x74, 0x62, 0x30, - 0x75, 0x73, 0xf3, 0x11, 0x30, 0x2c, 0x34, 0x35, - 0x6d, 0x39, 0x69, 0x32, 0x23, 0x24, 0x76, 0x71, - 0x77, 0x30, 0x39, 0x75, 0x76, 0x35, 0x71, 0x32, - 0x40, 0x46, 0x34, 0x34, 0xBB, 0x03, 0x66, 0x52 -}; + 0x64, 0x3b, 0x33, 0x17, 0x34, 0x74, 0x62, 0x30, 0x75, 0x73, 0xf3, 0x11, 0x30, 0x2c, + 0x34, 0x35, 0x6d, 0x39, 0x69, 0x32, 0x23, 0x24, 0x76, 0x71, 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 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_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); assert_int_equal(test_data_simple_checksum, res_sum); diff --git a/tests/lib/coreboot_table-test.c b/tests/lib/coreboot_table-test.c index 7668941243d1..f9d963de2ded 100644 --- a/tests/lib/coreboot_table-test.c +++ b/tests/lib/coreboot_table-test.c @@ -43,11 +43,10 @@ static struct lb_record *lb_first_record(struct lb_header *header) return rec; } -#define LB_RECORD_FOR_EACH(record_ptr, index, header) \ - for (index = 0, record_ptr = lb_first_record(header); \ - index < header->table_entries; \ - record_ptr = (struct lb_record *)((uintptr_t)record_ptr \ - + record_ptr->size), index++) +#define LB_RECORD_FOR_EACH(record_ptr, index, header) \ + for (index = 0, record_ptr = lb_first_record(header); index < header->table_entries; \ + record_ptr = (struct lb_record *)((uintptr_t)record_ptr + record_ptr->size), \ + index++) 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_memory_equal(&gpios_table->gpios[0], gpios, sizeof(gpios)); 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]; @@ -169,20 +168,18 @@ static void test_write_coreboot_forwarding_table(void **state) uint8_t forwarding_table_buffer[sizeof(struct lb_header) + 2 * sizeof(struct lb_forward)]; struct lb_header *forward_header = - (struct lb_header *)ALIGN_UP((uintptr_t)forwarding_table_buffer, 16); - size_t forwarding_table_size = - write_coreboot_forwarding_table((uintptr_t)forwarding_table_buffer, - (uintptr_t)header); - size_t expected_forwarding_table_size = ALIGN_UP((uintptr_t)forwarding_table_buffer, 16) - + sizeof(struct lb_header) - + sizeof(struct lb_forward) - - (uintptr_t)forwarding_table_buffer; + (struct lb_header *)ALIGN_UP((uintptr_t)forwarding_table_buffer, 16); + size_t forwarding_table_size = write_coreboot_forwarding_table( + (uintptr_t)forwarding_table_buffer, (uintptr_t)header); + size_t expected_forwarding_table_size = + ALIGN_UP((uintptr_t)forwarding_table_buffer, 16) + sizeof(struct lb_header) + + sizeof(struct lb_forward) - (uintptr_t)forwarding_table_buffer; assert_int_equal(expected_forwarding_table_size, forwarding_table_size); assert_int_equal(1, forward_header->table_entries); assert_int_equal(sizeof(struct lb_forward), forward_header->table_bytes); 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() */ @@ -214,8 +211,8 @@ void arch_write_tables(uintptr_t coreboot_table) } struct resource mock_bootmem_ranges[] = { - { .base = 0x1000, .size = 0x2000, .flags = LB_MEM_RAM }, - { .base = 0x0000, .size = 0x4000, .flags = LB_MEM_RAM }, + {.base = 0x1000, .size = 0x2000, .flags = LB_MEM_RAM}, + {.base = 0x0000, .size = 0x4000, .flags = LB_MEM_RAM}, }; 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. */ 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) { case LB_TAG_MEMORY: /* Should be the same as in bootmem_write_memory_table() */ assert_int_equal(sizeof(struct lb_memory) - + ARRAY_SIZE(mock_bootmem_ranges) - * sizeof(struct lb_memory_range), - record->size); + + ARRAY_SIZE(mock_bootmem_ranges) + * sizeof(struct lb_memory_range), + record->size); const struct lb_memory *memory = (struct lb_memory *)record; const struct lb_memory_range *range; @@ -366,38 +364,45 @@ static void test_write_tables(void **state) value = pack_lb64(res->base); assert_memory_equal(&value, &range->start, - sizeof(struct lb_uint64)); + sizeof(struct lb_uint64)); value = pack_lb64(res->size); assert_memory_equal(&value, &range->size, - sizeof(struct lb_uint64)); + sizeof(struct lb_uint64)); assert_int_equal(range->type, res->flags); } break; case LB_TAG_MAINBOARD: /* Mainboard record contains its header followed by two null-terminated strings */ - assert_int_equal(ALIGN_UP(sizeof(struct lb_mainboard) + - ARRAY_SIZE(mainboard_vendor) + - ARRAY_SIZE(mainboard_part_number), 8), record->size); + assert_int_equal(ALIGN_UP(sizeof(struct lb_mainboard) + + ARRAY_SIZE(mainboard_vendor) + + ARRAY_SIZE(mainboard_part_number), + 8), + record->size); break; case LB_TAG_VERSION: assert_int_equal(ALIGN_UP(sizeof(struct lb_string) - + ARRAY_SIZE(coreboot_version), 8), record->size); + + ARRAY_SIZE(coreboot_version), + 8), + record->size); break; case LB_TAG_EXTRA_VERSION: assert_int_equal(ALIGN_UP(sizeof(struct lb_string) - + ARRAY_SIZE(coreboot_extra_version), 8), - record->size); + + ARRAY_SIZE(coreboot_extra_version), + 8), + record->size); break; case LB_TAG_BUILD: - assert_int_equal(ALIGN_UP(sizeof(struct lb_string) - + ARRAY_SIZE(coreboot_build), 8), - record->size); + assert_int_equal( + ALIGN_UP(sizeof(struct lb_string) + ARRAY_SIZE(coreboot_build), + 8), + record->size); break; case LB_TAG_COMPILE_TIME: assert_int_equal(ALIGN_UP(sizeof(struct lb_string) - + ARRAY_SIZE(coreboot_compile_time), 8), - record->size); + + ARRAY_SIZE(coreboot_compile_time), + 8), + record->size); break; case LB_TAG_SERIAL: 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); 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 region_device *boot_dev = boot_device_ro(); 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); const struct lb_cbmem_entry *cbmem_entry = - (struct lb_cbmem_entry *)record; - const LargestIntegralType expected_tags[] = { - CBMEM_ID_CBTABLE, - CBMEM_ID_MMC_STATUS - }; - assert_in_set(cbmem_entry->id, - expected_tags, ARRAY_SIZE(expected_tags)); + (struct lb_cbmem_entry *)record; + const LargestIntegralType expected_tags[] = {CBMEM_ID_CBTABLE, + CBMEM_ID_MMC_STATUS}; + assert_in_set(cbmem_entry->id, expected_tags, + ARRAY_SIZE(expected_tags)); break; case LB_TAG_TSC_INFO: 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); 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()); - assert_memory_equal(&expected_fw_version, - &board_config->fw_config, sizeof(struct lb_uint64)); + assert_memory_equal(&expected_fw_version, &board_config->fw_config, + sizeof(struct lb_uint64)); assert_int_equal(board_id(), board_config->board_id); assert_int_equal(ram_code(), board_config->ram_code); 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_multiple_entries, setup_test_header), cmocka_unit_test_setup(test_write_coreboot_forwarding_table, setup_test_header), - cmocka_unit_test_setup_teardown(test_write_tables, - setup_write_tables_test, + cmocka_unit_test_setup_teardown(test_write_tables, setup_write_tables_test, teardown_write_tables_test), }; diff --git a/tests/lib/crc_byte-test.c b/tests/lib/crc_byte-test.c index 86249420c8ee..16850f033fa9 100644 --- a/tests/lib/crc_byte-test.c +++ b/tests/lib/crc_byte-test.c @@ -4,38 +4,25 @@ #include static const uint8_t test_data_bytes[] = { - 0x2f, 0x8f, 0x2d, 0x06, 0xc2, 0x11, 0x0c, 0xaf, - 0xd7, 0x4b, 0x48, 0x71, 0xce, 0x3c, 0xfe, 0x29, - 0x90, 0xf6, 0x33, 0x6d, 0x79, 0x23, 0x9d, 0x84, - 0x58, 0x5c, 0xcc, 0xf1, 0xa1, 0xf2, 0x39, 0x22, - 0xdc, 0x63, 0xe0, 0x44, 0x0a, 0x95, 0x36, 0xee, - 0x53, 0xb3, 0x61, 0x2c, 0x4a, 0xf4, 0x8b, 0x32, - 0xeb, 0x94, 0x86, 0x55, 0x41, 0x27, 0xa4, 0xbd, - 0x0f, 0xc1, 0x4f, 0xfb, 0xb6, 0xa3, 0xc5, 0x38, - 0x99, 0xfc, 0xca, 0xf8, 0x8e, 0x72, 0xaa, 0xed, - 0x6b, 0xb2, 0xd3, 0xd4, 0xd6, 0x81, 0x7d, 0x24, - 0x56, 0x9f, 0x7a, 0x21, 0x67, 0xac, 0x6a, 0x98, - 0xf7, 0xd1, 0xad, 0x01, 0xdb, 0xc6, 0x80, 0x34, - 0x8d, 0x51, 0x60, 0x3e, 0xd2, 0x52, 0x0e, 0x26, - 0x12, 0xb1, 0x13, 0xa2, 0x88, 0x04, 0x66, 0xb0, - 0x3b, 0xc8, 0x1b, 0x7f, 0x92, 0x4e, 0xb8, 0xe9, - 0x70, 0xe3, 0xfa, 0x76, 0x3a, 0xa7, 0x4c, 0x25, - 0x91, 0x54, 0x19, 0xea, 0x50, 0x37, 0xd8, 0xb4, - 0x47, 0x49, 0xbf, 0xc4, 0xb7, 0xd0, 0x93, 0xda, - 0x6c, 0x03, 0x9b, 0x15, 0xbb, 0xfd, 0xe7, 0xdd, - 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, + 0x2f, 0x8f, 0x2d, 0x06, 0xc2, 0x11, 0x0c, 0xaf, 0xd7, 0x4b, 0x48, 0x71, 0xce, 0x3c, + 0xfe, 0x29, 0x90, 0xf6, 0x33, 0x6d, 0x79, 0x23, 0x9d, 0x84, 0x58, 0x5c, 0xcc, 0xf1, + 0xa1, 0xf2, 0x39, 0x22, 0xdc, 0x63, 0xe0, 0x44, 0x0a, 0x95, 0x36, 0xee, 0x53, 0xb3, + 0x61, 0x2c, 0x4a, 0xf4, 0x8b, 0x32, 0xeb, 0x94, 0x86, 0x55, 0x41, 0x27, 0xa4, 0xbd, + 0x0f, 0xc1, 0x4f, 0xfb, 0xb6, 0xa3, 0xc5, 0x38, 0x99, 0xfc, 0xca, 0xf8, 0x8e, 0x72, + 0xaa, 0xed, 0x6b, 0xb2, 0xd3, 0xd4, 0xd6, 0x81, 0x7d, 0x24, 0x56, 0x9f, 0x7a, 0x21, + 0x67, 0xac, 0x6a, 0x98, 0xf7, 0xd1, 0xad, 0x01, 0xdb, 0xc6, 0x80, 0x34, 0x8d, 0x51, + 0x60, 0x3e, 0xd2, 0x52, 0x0e, 0x26, 0x12, 0xb1, 0x13, 0xa2, 0x88, 0x04, 0x66, 0xb0, + 0x3b, 0xc8, 0x1b, 0x7f, 0x92, 0x4e, 0xb8, 0xe9, 0x70, 0xe3, 0xfa, 0x76, 0x3a, 0xa7, + 0x4c, 0x25, 0x91, 0x54, 0x19, 0xea, 0x50, 0x37, 0xd8, 0xb4, 0x47, 0x49, 0xbf, 0xc4, + 0xb7, 0xd0, 0x93, 0xda, 0x6c, 0x03, 0x9b, 0x15, 0xbb, 0xfd, 0xe7, 0xdd, 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 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 and/or checksum is correct */ - assert_int_equal(0, - crc16_byte(crc16_byte(crc_value, test_data_crc16_checksum >> 8), - test_data_crc16_checksum & 0xFF)); + assert_int_equal(0, crc16_byte(crc16_byte(crc_value, test_data_crc16_checksum >> 8), + test_data_crc16_checksum & 0xFF)); } static void test_crc32_byte_zeros(void **state) diff --git a/tests/lib/dimm_info_util-test.c b/tests/lib/dimm_info_util-test.c index cfe7176006fb..cecbacbb8593 100644 --- a/tests/lib/dimm_info_util-test.c +++ b/tests/lib/dimm_info_util-test.c @@ -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; 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, - 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, - 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, - 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 */ 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) { smbios_memory_type memory_type[] = { - MEMORY_TYPE_DDR2, - MEMORY_TYPE_DDR3, - MEMORY_TYPE_DDR4, - MEMORY_TYPE_DDR5, - MEMORY_TYPE_LPDDR3, - MEMORY_TYPE_LPDDR4, - MEMORY_TYPE_LPDDR5, + MEMORY_TYPE_DDR2, MEMORY_TYPE_DDR3, 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++) { 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]); } } @@ -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) { const smbios_memory_form_factor undefined_factors[] = { - MEMORY_FORMFACTOR_OTHER, - MEMORY_FORMFACTOR_UNKNOWN, - MEMORY_FORMFACTOR_SIMM, - MEMORY_FORMFACTOR_SIP, - MEMORY_FORMFACTOR_CHIP, - MEMORY_FORMFACTOR_DIP, - MEMORY_FORMFACTOR_ZIP, - MEMORY_FORMFACTOR_PROPRIETARY_CARD, - MEMORY_FORMFACTOR_TSOP, - MEMORY_FORMFACTOR_ROC, - MEMORY_FORMFACTOR_SRIMM, - MEMORY_FORMFACTOR_FBDIMM, + MEMORY_FORMFACTOR_OTHER, MEMORY_FORMFACTOR_UNKNOWN, + MEMORY_FORMFACTOR_SIMM, MEMORY_FORMFACTOR_SIP, + MEMORY_FORMFACTOR_CHIP, MEMORY_FORMFACTOR_DIP, + MEMORY_FORMFACTOR_ZIP, MEMORY_FORMFACTOR_PROPRIETARY_CARD, + MEMORY_FORMFACTOR_TSOP, MEMORY_FORMFACTOR_ROC, + MEMORY_FORMFACTOR_SRIMM, MEMORY_FORMFACTOR_FBDIMM, MEMORY_FORMFACTOR_DIE, }; for (int i = 0; i < ARRAY_SIZE(undefined_factors); ++i) { - assert_int_equal(SPD_UNDEFINED, - smbios_form_factor_to_spd_mod_type(memory_type, - undefined_factors[i])); + assert_int_equal(SPD_UNDEFINED, smbios_form_factor_to_spd_mod_type( + memory_type, undefined_factors[i])); } } static void test_smbios_form_factor_to_spd_mod_type_ddrx_parametrized( - smbios_memory_type memory_type, - const LargestIntegralType udimm_allowed[], - const LargestIntegralType rdimm_allowed[], - LargestIntegralType expected_module_type) + smbios_memory_type memory_type, const LargestIntegralType udimm_allowed[], + const LargestIntegralType rdimm_allowed[], LargestIntegralType expected_module_type) { print_message("%s(%d)\n", __func__, memory_type); 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), - 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, - MEMORY_FORMFACTOR_SODIMM)); + assert_int_equal(expected_module_type, smbios_form_factor_to_spd_mod_type( + memory_type, MEMORY_FORMFACTOR_SODIMM)); 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); /* Form factors defined in coreboot */ - assert_int_equal(LPX_SPD_NONDIMM, smbios_form_factor_to_spd_mod_type(memory_type, - MEMORY_FORMFACTOR_ROC)); + assert_int_equal(LPX_SPD_NONDIMM, smbios_form_factor_to_spd_mod_type( + memory_type, MEMORY_FORMFACTOR_ROC)); } 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[] = { { .memory_type = MEMORY_TYPE_DDR2, - .udimm_allowed = { DDR2_SPD_UDIMM, DDR2_SPD_MICRO_DIMM, - DDR2_SPD_MINI_UDIMM }, - .rdimm_allowed = { DDR2_SPD_RDIMM, DDR2_SPD_MINI_RDIMM }, + .udimm_allowed = {DDR2_SPD_UDIMM, DDR2_SPD_MICRO_DIMM, + DDR2_SPD_MINI_UDIMM}, + .rdimm_allowed = {DDR2_SPD_RDIMM, DDR2_SPD_MINI_RDIMM}, .expected_module_type = DDR2_SPD_SODIMM, }, { .memory_type = MEMORY_TYPE_DDR3, - .udimm_allowed = { DDR3_SPD_UDIMM, DDR3_SPD_MICRO_DIMM, - DDR3_SPD_MINI_UDIMM }, - .rdimm_allowed = { DDR3_SPD_RDIMM, DDR3_SPD_MINI_RDIMM }, - .expected_module_type = DDR3_SPD_SODIMM, + .udimm_allowed = {DDR3_SPD_UDIMM, DDR3_SPD_MICRO_DIMM, + DDR3_SPD_MINI_UDIMM}, + .rdimm_allowed = {DDR3_SPD_RDIMM, DDR3_SPD_MINI_RDIMM}, + .expected_module_type = DDR3_SPD_SODIMM, }, { .memory_type = MEMORY_TYPE_DDR4, - .udimm_allowed = { DDR4_SPD_UDIMM, DDR4_SPD_MINI_UDIMM }, - .rdimm_allowed = { DDR4_SPD_RDIMM, DDR4_SPD_MINI_RDIMM }, + .udimm_allowed = {DDR4_SPD_UDIMM, DDR4_SPD_MINI_UDIMM}, + .rdimm_allowed = {DDR4_SPD_RDIMM, DDR4_SPD_MINI_RDIMM}, .expected_module_type = DDR4_SPD_SODIMM, }, - { - .memory_type = MEMORY_TYPE_DDR5, - .udimm_allowed = { DDR5_SPD_UDIMM, DDR5_SPD_MINI_UDIMM }, - .rdimm_allowed = { DDR5_SPD_RDIMM, DDR5_SPD_MINI_RDIMM }, - .expected_module_type = DDR5_SPD_SODIMM - }, + {.memory_type = MEMORY_TYPE_DDR5, + .udimm_allowed = {DDR5_SPD_UDIMM, DDR5_SPD_MINI_UDIMM}, + .rdimm_allowed = {DDR5_SPD_RDIMM, DDR5_SPD_MINI_RDIMM}, + .expected_module_type = DDR5_SPD_SODIMM}, }; /* Test for DDRx DIMM Modules */ for (int i = 0; i < ARRAY_SIZE(ddrx_info); i++) test_smbios_form_factor_to_spd_mod_type_ddrx_parametrized( - ddrx_info[i].memory_type, ddrx_info[i].udimm_allowed, - ddrx_info[i].rdimm_allowed, ddrx_info[i].expected_module_type); + ddrx_info[i].memory_type, ddrx_info[i].udimm_allowed, + ddrx_info[i].rdimm_allowed, ddrx_info[i].expected_module_type); smbios_memory_type lpddrx_memory_type[] = { MEMORY_TYPE_LPDDR3, diff --git a/tests/lib/edid-test.c b/tests/lib/edid-test.c index a93e88a2923c..5a22e6bd9503 100644 --- a/tests/lib/edid-test.c +++ b/tests/lib/edid-test.c @@ -34,22 +34,20 @@ static void test_decode_edid_no_edid(void **state) static void test_decode_edid_invalid_header(void **state) { - struct edid_raw raw = { - .header = EDID_HEADER_INVALID_RAW - }; + struct edid_raw raw = {.header = EDID_HEADER_INVALID_RAW}; raw.checksum = get_raw_edid_checksum((const unsigned char *)&raw); assert_int_equal(EDID_ABSENT, decode_edid((unsigned char *)&raw, sizeof(raw), NULL)); } /* Frame is modified example of an LCD Desktop IT display - * from VESA E-EDID Standard Release A2. - */ + from VESA E-EDID Standard Release A2. */ static int setup_decode_edid_basic_frame(void **state) { struct edid_raw raw = { EDID_RAW_DEFAULT_PARAMS, - .video_input_type = EDID_ANALOG_VSI + .video_input_type = + EDID_ANALOG_VSI | EDID_SIGNAL_LEVEL_0 | EDID_VIDEO_SETUP_BLANK_EQ_BLACK | EDID_SEPARATE_SYNC_H_AND_V(1) @@ -57,9 +55,10 @@ static int setup_decode_edid_basic_frame(void **state) | EDID_COMPOSITE_SYNC_ON_GREEN(1) | EDID_SERRATION_VSYNC(1), .horizontal_size = 43, /* [cm] */ - .vertical_size = 32, /* [cm] */ - .display_gamma = 120, /* 220% */ - .supported_features = EDID_STANDBY_MODE(0) + .vertical_size = 32, /* [cm] */ + .display_gamma = 120, /* 220% */ + .supported_features = + EDID_STANDBY_MODE(0) | EDID_SUSPEND_MODE(0) | EDID_ACTIVE_OFF(1) | EDID_COLOR_FORMAT_RGB444 @@ -68,21 +67,21 @@ static int setup_decode_edid_basic_frame(void **state) | EDID_DISPLAY_FREQUENCY_CONTINUOUS, .established_supported_timings = { [0] = EDID_ESTABLISHED_TIMINGS_1_720x400_70Hz - | EDID_ESTABLISHED_TIMINGS_1_720x400_88Hz - | EDID_ESTABLISHED_TIMINGS_1_640x480_60Hz - | EDID_ESTABLISHED_TIMINGS_1_640x480_67Hz - | EDID_ESTABLISHED_TIMINGS_1_640x480_72Hz - | EDID_ESTABLISHED_TIMINGS_1_640x480_75Hz - | EDID_ESTABLISHED_TIMINGS_1_800x600_56Hz - | EDID_ESTABLISHED_TIMINGS_1_800x600_60Hz, + | EDID_ESTABLISHED_TIMINGS_1_720x400_88Hz + | EDID_ESTABLISHED_TIMINGS_1_640x480_60Hz + | EDID_ESTABLISHED_TIMINGS_1_640x480_67Hz + | EDID_ESTABLISHED_TIMINGS_1_640x480_72Hz + | EDID_ESTABLISHED_TIMINGS_1_640x480_75Hz + | EDID_ESTABLISHED_TIMINGS_1_800x600_56Hz + | EDID_ESTABLISHED_TIMINGS_1_800x600_60Hz, [1] = EDID_ESTABLISHED_TIMINGS_2_800x600_72Hz - | EDID_ESTABLISHED_TIMINGS_2_800x600_75Hz - | EDID_ESTABLISHED_TIMINGS_2_832x624_75Hz - | EDID_ESTABLISHED_TIMINGS_2_1024x768_80HzI - | EDID_ESTABLISHED_TIMINGS_2_1024x768_60Hz - | EDID_ESTABLISHED_TIMINGS_2_1024x768_70Hz - | EDID_ESTABLISHED_TIMINGS_2_1024x768_75Hz - | EDID_ESTABLISHED_TIMINGS_2_1280x1024_75Hz, + | EDID_ESTABLISHED_TIMINGS_2_800x600_75Hz + | EDID_ESTABLISHED_TIMINGS_2_832x624_75Hz + | EDID_ESTABLISHED_TIMINGS_2_1024x768_80HzI + | EDID_ESTABLISHED_TIMINGS_2_1024x768_60Hz + | EDID_ESTABLISHED_TIMINGS_2_1024x768_70Hz + | EDID_ESTABLISHED_TIMINGS_2_1024x768_75Hz + | EDID_ESTABLISHED_TIMINGS_2_1280x1024_75Hz, }, .manufacturers_reserved_timing = EDID_MANUFACTURERS_TIMINGS_1152x870_75Hz, .standard_timings_supported = { @@ -114,64 +113,69 @@ static int setup_decode_edid_basic_frame(void **state) [0] = EDID_PIXEL_CLOCK(162000000u) & 0xFF, [1] = (EDID_PIXEL_CLOCK(162000000u) >> 8) & 0xFF, - /* - * Horizontal Addressable Video is 1600px - * Horizontal Blanking is 560px - */ - [2] = 0x40, [3] = 0x30, [4] = 0x62, + /* Horizontal Addressable Video is 1600px, + Horizontal Blanking is 560px. */ + [2] = 0x40, + [3] = 0x30, + [4] = 0x62, - /* - * Vertical Addressable Video is 1200 lines - * Vertical Blanking is 50 lines - */ - [5] = 0xB0, [6] = 0x32, [7] = 0x40, + /* Vertical Addressable Video is 1200 lines, + Vertical Blanking is 50 lines. */ + [5] = 0xB0, + [6] = 0x32, + [7] = 0x40, - [8] = 64u, /* Horizontal Front Porch in pixels */ - [9] = 192u, /* Horizontal Pulse Sync Width in pixels */ - [10] = 0x13, /* Vertical Front Porch is 1 line */ - [11] = 0x00, /* Vertical Sync Pulse Width is 3 lines */ + [8] = 64u, /* Horizontal Front Porch in pixels. */ + [9] = 192u, /* Horizontal Pulse Sync Width in pixels. */ + [10] = 0x13, /* Vertical Front Porch is 1 line. */ + [11] = 0x00, /* Vertical Sync Pulse Width is 3 lines. */ - /* - * Horizontal Addressable Image Size is 427mm - * Vertical Addressable Image Size is 320mm - */ - [12] = 0xAB, [13] = 0x40, [14] = 0x11, + /* Horizontal Addressable Image Size is 427mm, + Vertical Addressable Image Size is 320mm. */ + [12] = 0xAB, + [13] = 0x40, + [14] = 0x11, - [15] = 0x00, /* Horizontal border size is 0px*/ - [16] = 0x00, /* Vertical Border Size is 0px */ + [15] = 0x00, /* Horizontal Border Size is 0px. */ + [16] = 0x00, /* Vertical Border Size is 0px. */ - /* - * Timing is Non-Interlaced Video, - * Stereo Video is not supported, - * Digital separate syncs are requires. - * */ + /* Timing is Non-Interlaced Video, + Stereo Video is not supported, + Digital separate syncs are requires. */ [17] = 0x1E, }, .descriptor_block_2 = { /* Display Range Limits Block Tag */ - [0] = 0, [1] = 0, [2] = 0, [3] = 0xFD, + [0] = 0, + [1] = 0, + [2] = 0, + [3] = 0xFD, - [4] = 0, /* Horizontal and Vertical Rate Offsets are zero */ - [5] = 50u, /* Minimum Vertical Freq is 50Hz */ - [6] = 90u, /* Maximum Vertical Freq is 90Hz */ + [4] = 0, /* Horizontal and Vertical Rate Offsets are zero. */ + [5] = 50u, /* Minimum Vertical Freq is 50Hz. */ + [6] = 90u, /* Maximum Vertical Freq is 90Hz. */ - [7] = 30u, /* Minimum Horizontal Freq is 30kHz */ - [8] = 110u, /* Maximum Horizontal Freq is 110kHz */ - [9] = 23u, /* Maximum Pixel Clock Freq i 230MHz */ - [10] = 0x4, /* Begin CVT Support Info */ + [7] = 30u, /* Minimum Horizontal Freq is 30kHz. */ + [8] = 110u, /* Maximum Horizontal Freq is 110kHz. */ + [9] = 23u, /* Maximum Pixel Clock Freq is 230MHz. */ + [10] = 0x4, /* Begin CVT Support Info */ [11] = 0x11, /* Compatible with CVT Version 1.1 */ - [12] = 0, /* Maimum Pixel Clock Freq remains at 230MHz */ - [13] = 200, /* Maximum Active Pixels per Pile is 1600 */ - [14] = 0x90, /* Supported aspect ratios: 4:3, 5:4 */ + [12] = 0, /* Maximum Pixel Clock Freq remains at 230MHz. */ + [13] = 200, /* Maximum Active Pixels per Line is 1600. */ + [14] = 0x90, /* Supported aspect ratios: 4:3, 5:4. */ - /* Preferred Aspect Ratio is 4:3, Standard CVT Blanking is supported */ + /* Preferred Aspect Ratio is 4:3, Standard CVT Blanking is supported. */ [15] = 0, - [16] = 0x50, /* H. & V. Stretch are supported and Shrinks are not */ - [17] = 60u, /* Preferred Refresh Rate is 60Hz */ + [16] = 0x50, /* H. & V. Stretch are supported and Shrinks are not. */ + [17] = 60u, /* Preferred Refresh Rate is 60Hz. */ }, .descriptor_block_3 = { /* Established Timings III Block Tag */ - [0] = 0, [1] = 0, [2] = 0, [3] = 0xF7, [4] = 0, + [0] = 0, + [1] = 0, + [2] = 0, + [3] = 0xF7, + [4] = 0, [5] = 10u, /* VESA DMT Standard Version #10 */ /* @@ -181,7 +185,7 @@ static int setup_decode_edid_basic_frame(void **state) * 640x480@85Hz, * 800x600@85Hz, * 1024x768@85Hz, - * 1152x864@75Hz + * 1152x864@75Hz are supported. */ [6] = 0x7F, @@ -189,7 +193,7 @@ static int setup_decode_edid_basic_frame(void **state) * 1280x960@60Hz, * 1280x960@85Hz, * 1280x1024@60Hz, - * 1280x1024@85Hz + * 1280x1024@85Hz are supported. */ [7] = 0x0F, @@ -213,14 +217,18 @@ static int setup_decode_edid_basic_frame(void **state) */ [10] = 0xC0, - /* 1920 timings not supported */ + /* 1920 timings not supported. */ [11] = 0x0, [12 ... 17] = 0, }, .descriptor_block_4 = { /* Display Product Name Block Tag */ - [0] = 0, [1] = 0, [2] = 0, [3] = 0xFC, [4] = 0, + [0] = 0, + [1] = 0, + [2] = 0, + [3] = 0xFC, + [4] = 0, /* Product name */ [5] = 'A', @@ -244,10 +252,8 @@ static int setup_decode_edid_basic_frame(void **state) *state = malloc(sizeof(struct test_state)); - struct test_state ts = { - .data_size = sizeof(struct edid_raw), - .data = malloc(sizeof(struct edid_raw)) - }; + struct test_state ts = {.data_size = sizeof(struct edid_raw), + .data = malloc(sizeof(struct edid_raw))}; memcpy(ts.data, &raw, sizeof(raw)); memcpy(*state, &ts, sizeof(ts)); @@ -255,18 +261,16 @@ static int setup_decode_edid_basic_frame(void **state) return 0; } -/* Test decoding of EDID frame without extensions. - */ +/* Test decoding of EDID frame without extensions. */ static void test_decode_edid_basic_frame(void **state) { struct edid out; struct test_state *ts = *state; /* In real-life situations frames often are not 100% conformant, - * but are at least correct when it comes to key data fields. - */ + but are at least correct when it comes to key data fields. */ assert_int_equal(EDID_CONFORMANT, - decode_edid((unsigned char *)ts->data, ts->data_size, &out)); + decode_edid((unsigned char *)ts->data, ts->data_size, &out)); assert_int_equal(32, out.framebuffer_bits_per_pixel); assert_int_equal(0, out.panel_bits_per_color); @@ -305,19 +309,20 @@ static void test_decode_edid_basic_frame(void **state) } /* Frame is modified example of base EDID frame with CEA861 extension - * for DTV Display from VESA E-EDID Standard Release A2. - */ + for DTV Display from VESA E-EDID Standard Release A2. */ static int setup_decode_edid_dtv_frame_with_extension(void **state) { struct edid_raw raw = { EDID_RAW_DEFAULT_PARAMS, - .video_input_type = EDID_DIGITAL_VSI + .video_input_type = + EDID_DIGITAL_VSI | EDID_INTERFACE_HDMI_A | EDID_COLOR_BIT_DEPTH_8B, - .horizontal_size = 16, /* Aspect ratio 16:9 in landscape */ - .vertical_size = 0, /* Landscape flag */ - .display_gamma = 120, /* 220% */ - .supported_features = EDID_STANDBY_MODE(0) + .horizontal_size = 16, /* Aspect ratio 16:9 in landscape. */ + .vertical_size = 0, /* Landscape flag */ + .display_gamma = 120, /* 220% */ + .supported_features = + EDID_STANDBY_MODE(0) | EDID_SUSPEND_MODE(0) | EDID_ACTIVE_OFF(0) | EDID_COLOR_FORMAT_RGB444_YCRCB422_YCRCB422 @@ -330,109 +335,121 @@ static int setup_decode_edid_dtv_frame_with_extension(void **state) [1] = 0, }, .manufacturers_reserved_timing = 0, - .standard_timings_supported = { [0 ... 15] = 0, }, + .standard_timings_supported = { + [0 ... 15] = 0, + }, .descriptor_block_1 = { [0] = EDID_PIXEL_CLOCK(148500000u) & 0xFF, [1] = (EDID_PIXEL_CLOCK(148500000u) >> 8) & 0xFF, - /* Horizontal Addressable Video is 1920px - * Horizontal Blanking is 280px - */ - [2] = 0x80, [3] = 0x18, [4] = 0x71, + /* Horizontal Addressable Video is 1920px, + Horizontal Blanking is 280px. */ + [2] = 0x80, + [3] = 0x18, + [4] = 0x71, - /* Vertical Addressable Video is 1080 lines - * Vertical Blanking is 45 lines - */ - [5] = 0x38, [6] = 0x2D, [7] = 0x40, + /* Vertical Addressable Video is 1080 lines, + Vertical Blanking is 45 lines. */ + [5] = 0x38, + [6] = 0x2D, + [7] = 0x40, - [8] = 88u, /* Horizontal Front Porch in pixels */ - [9] = 44u, /* Horizontal Pulse Sync Width in pixels */ - [10] = 4u, /* Vertical Front Porch is 4 lines */ - [11] = 5u, /* Vertical Sync Pulse Width is 5 lines */ + [8] = 88u, /* Horizontal Front Porch in pixels. */ + [9] = 44u, /* Horizontal Pulse Sync Width in pixels. */ + [10] = 4u, /* Vertical Front Porch is 4 lines. */ + [11] = 5u, /* Vertical Sync Pulse Width is 5 lines. */ - /* Horizontal Addressable Image Size is 1039mm - * Vertical Addressable Image Size is 584mm - */ - [12] = 0x0F, [13] = 0x48, [14] = 0x42, + /* Horizontal Addressable Image Size is 1039mm, + Vertical Addressable Image Size is 584mm. */ + [12] = 0x0F, + [13] = 0x48, + [14] = 0x42, - [15] = 0x00, /* Horizontal border size is 0px*/ - [16] = 0x00, /* Vertical Border Size is 0px */ + [15] = 0x00, /* Horizontal Border Size is 0px. */ + [16] = 0x00, /* Vertical Border Size is 0px. */ /* Timing is Non-Interlaced Video, - * Stereo Video is not supported, - * Digital separate and syncs are requires. - */ + Stereo Video is not supported, + Digital separate and syncs are requires. */ [17] = 0x1E, }, .descriptor_block_2 = { [0] = EDID_PIXEL_CLOCK(74250000u) & 0xFF, [1] = (EDID_PIXEL_CLOCK(74250000u) >> 8) & 0xFF, - /* Horizontal Addressable Video is 1920px - * Horizontal Blanking is 280px - */ - [2] = 0x80, [3] = 0x18, [4] = 0x71, + /* Horizontal Addressable Video is 1920px, + Horizontal Blanking is 280px. */ + [2] = 0x80, + [3] = 0x18, + [4] = 0x71, - /* Vertical Addressable Video is 540 lines - * Vertical Blanking is 22 lines - */ - [5] = 0x1C, [6] = 0x16, [7] = 0x20, + /* Vertical Addressable Video is 540 lines, + Vertical Blanking is 22 lines. */ + [5] = 0x1C, + [6] = 0x16, + [7] = 0x20, - [8] = 88u, /* Horizontal Front Porch in pixels */ - [9] = 44u, /* Horizontal Pulse Sync Width in pixels */ - [10] = 0x25, /* Vertical Front Porch is 2 lines */ - [11] = 0x00, /* Vertical Sync Pulse Width is 5 lines */ + [8] = 88u, /* Horizontal Front Porch in pixels. */ + [9] = 44u, /* Horizontal Pulse Sync Width in pixels. */ + [10] = 0x25, /* Vertical Front Porch is 2 lines. */ + [11] = 0x00, /* Vertical Sync Pulse Width is 5 lines. */ - /* Horizontal Addressable Image Size is 1039mm - * Vertical Addressable Image Size is 584mm - */ - [12] = 0x0F, [13] = 0x48, [14] = 0x42, + /* Horizontal Addressable Image Size is 1039mm, + Vertical Addressable Image Size is 584mm. */ + [12] = 0x0F, + [13] = 0x48, + [14] = 0x42, - [15] = 0x00, /* Horizontal border size is 0px*/ - [16] = 0x00, /* Vertical Border Size is 0px */ + [15] = 0x00, /* Horizontal Border Size is 0px. */ + [16] = 0x00, /* Vertical Border Size is 0px. */ /* Timing is Interlaced Video, - * Stereo Video is not supported, - * Digital separate and syncs are requires. - */ + Stereo Video is not supported, + Digital separate and syncs are requires. */ [17] = 0x9E, }, .descriptor_block_3 = { [0] = EDID_PIXEL_CLOCK(74250000u) & 0xFF, [1] = (EDID_PIXEL_CLOCK(74250000u) >> 8) & 0xFF, - /* Horizontal Addressable Video is 1280px - * Horizontal Blanking is 370px - */ - [2] = 0x00, [3] = 0x72, [4] = 0x51, + /* Horizontal Addressable Video is 1280px, + Horizontal Blanking is 370px. */ + [2] = 0x00, + [3] = 0x72, + [4] = 0x51, - /* Vertical Addressable Video is 720 lines - * Vertical Blanking is 30 lines - */ - [5] = 0xD0, [6] = 0x1E, [7] = 0x20, + /* Vertical Addressable Video is 720 lines, + Vertical Blanking is 30 lines. */ + [5] = 0xD0, + [6] = 0x1E, + [7] = 0x20, - [8] = 110u, /* Horizontal Front Porch in pixels */ - [9] = 40u, /* Horizontal Pulse Sync Width in pixels */ - [10] = 0x55u, /* Vertical Front Porch is 5 lines */ - [11] = 0x00, /* Vertical Sync Pulse Width is 5 lines */ + [8] = 110u, /* Horizontal Front Porch in pixels. */ + [9] = 40u, /* Horizontal Pulse Sync Width in pixels. */ + [10] = 0x55u, /* Vertical Front Porch is 5 lines. */ + [11] = 0x00, /* Vertical Sync Pulse Width is 5 lines. */ - /* Horizontal Addressable Image Size is 1039mm - * Vertical Addressable Image Size is 584mm - */ - [12] = 0x0F, [13] = 0x48, [14] = 0x42, + /* Horizontal Addressable Image Size is 1039mm, + Vertical Addressable Image Size is 584mm. */ + [12] = 0x0F, + [13] = 0x48, + [14] = 0x42, - [15] = 0x00, /* Horizontal border size is 0px*/ - [16] = 0x00, /* Vertical Border Size is 0px */ + [15] = 0x00, /* Horizontal Border Size is 0px. */ + [16] = 0x00, /* Vertical Border Size is 0px. */ /* Timing is Non-Interlaced Video, - * Stereo Video is not supported, - * Digital separate syncs are requires. - */ + Stereo Video is not supported, + Digital separate syncs are requires. */ [17] = 0x1E, }, .descriptor_block_4 = { /* Display Product Name Block Tag */ - [0] = 0, [1] = 0, [2] = 0, [3] = 0xFC, [4] = 0, + [0] = 0, + [1] = 0, + [2] = 0, + [3] = 0xFC, + [4] = 0, /* Product name */ [5] = 'A', @@ -458,26 +475,24 @@ static int setup_decode_edid_dtv_frame_with_extension(void **state) [0] = 0x02, /* CEA 861 Extension Block Tag Code */ [1] = 0x03, /* CEA 861 Block Version */ - [2] = 0x18, /* Detail Timing Descriptors start 0x18 bytes from here */ + [2] = 0x18, /* Detail Timing Descriptors start 0x18 bytes from here. */ - /* Underscan is not supported - * Basic Audio is supported - * YCbCr 4:4:4 & YCbCr 4:2:2 are supported - * Number of native formats: 2 - */ + /* Underscan is not supported, + Basic Audio is supported, + YCbCr 4:4:4 & YCbCr 4:2:2 are supported, + Number of native formats: 2. */ [3] = 0x72, - /* Video Data Block Tag Code is 2 - * Number of Short Video Descriptor Bytes i 7 - */ + /* Video Data Block Tag Code is 2, + Number of Short Video Descriptor Bytes is 7. */ [4] = 0x47, /* 1920x1080p 59.94/60 Hz 16 : 9 AR (CEA Format #16) - * is a supported Native Format. */ + is a supported Native Format. */ [5] = 0x90, /* 1920x1080i 59.94/60 Hz 16 : 9 AR (CEA Format #5) - * is a supported Native Format. */ + is a supported Native Format. */ [6] = 0x85, /* 1280x720p 59.94/60 Hz 16 : 9 AR (CEA Format #4) is a supported format. */ @@ -495,14 +510,12 @@ static int setup_decode_edid_dtv_frame_with_extension(void **state) /* 720x480i 59.94/60 Hz 4 : 3 AR (CEA Format #6) is a supported format. */ [11] = 0x06, - /* Audio Data Block Tag Code is 1. - * Number of Short Audio Descriptor Bytes is 3. - */ + /* Audio Data Block Tag Code is 1, + Number of Short Audio Descriptor Bytes is 3. */ [12] = 0x23, - /* Audio Format Tag Code is 1 --- LPCM is supported. - * Maximum number of audio channels is 2 - */ + /* Audio Format Tag Code is 1 --- LPCM is supported, + Maximum number of audio channels is 2. */ [13] = 0x09, /* Supported Sampling Frequencies include: 48kHz; 44.1kHz & 32kHz. */ @@ -511,59 +524,63 @@ static int setup_decode_edid_dtv_frame_with_extension(void **state) /* Supported Sampling Bit Rates include: 24 bit; 20 bit & 16 bit. */ [15] = 0x07, - /* Speaker Allocation Block Tag Code is 4. - * Number of Speaker Allocation - * Descriptor Bytes is 3. - */ + /* Speaker Allocation Block Tag Code is 4, + Number of Speaker Allocation Descriptor Bytes is 3. */ [16] = 0x83, - /* Speaker Allocation is Front-Left & Front-Right */ + /* Speaker Allocation is Front-Left & Front-Right. */ [17] = 0x01, /* Reserved */ [18 ... 19] = 0, - /* Vendor Specific Data Block Tag Code is 3. - * Number of Vendor Specific Data Bytes is 5. - */ + /* Vendor Specific Data Block Tag Code is 3, + Number of Vendor Specific Data Bytes is 5. */ [20] = 0x65, - /* 24bit IEEE registration Identifier is 0x000C03 */ - [21] = 0x03, [22] = 0x0C, [23] = 0x00, + /* 24bit IEEE registration Identifier is 0x000C03. */ + [21] = 0x03, + [22] = 0x0C, + [23] = 0x00, - /* Vendor Specific Data is 0x10000 */ - [24] = 0x01, [25] = 0x00, + /* Vendor Specific Data is 0x10000. */ + [24] = 0x01, + [25] = 0x00, /* Descriptor Block 5 [18 Bytes] */ [26] = EDID_PIXEL_CLOCK(27027000u) & 0xFF, [27] = (EDID_PIXEL_CLOCK(27027000u) >> 8) & 0xFF, - /* Horizontal Addressable Video is 720px. - * Horizontal Blanking is 138 px. - */ - [28] = 0xD0, [29] = 0x8A, [30] = 0x20, + /* Horizontal Addressable Video is 720px, + Horizontal Blanking is 138 px. */ + [28] = 0xD0, + [29] = 0x8A, + [30] = 0x20, - /* Vertical Addressable Video is 480 lines. - * Vertical Blanking is 45 lines. - */ - [31] = 0xE0, [32] = 0x2D, [33] = 0x10, + /* Vertical Addressable Video is 480 lines, + Vertical Blanking is 45 lines. */ + [31] = 0xE0, + [32] = 0x2D, + [33] = 0x10, - [34] = 16u, /* Horizontal Front Porch in pixels */ - [35] = 62u, /* Horizontal Sync Pulse Width in pixels */ - [36] = 0x96, /* Vertical Front Porch is 9 lines */ - [37] = 0x00, /* Vertical Sync Pulse Width is 6 lines */ + [34] = 16u, /* Horizontal Front Porch in pixels. */ + [35] = 62u, /* Horizontal Sync Pulse Width in pixels. */ + [36] = 0x96, /* Vertical Front Porch is 9 lines. */ + [37] = 0x00, /* Vertical Sync Pulse Width is 6 lines. */ /* Displayed Image Aspect Ratio is 16:9 */ - [38] = 16u, [39] = 9u, [40] = 0u, + [38] = 16u, + [39] = 9u, + [40] = 0u, /* Horizontal and Vertical Border Size is 0 px */ - [41] = 0u, [42] = 0u, + [41] = 0u, + [42] = 0u, - /* Timing is Interlaced Video - * Stereo Video is not supported - * Digital Separate Syncs are required - */ + /* Timing is Interlaced Video, + Stereo Video is not supported, + Digital Separate Syncs are required. */ [43] = 0x18, /* Descriptor Block 6 [18 Bytes] */ @@ -571,31 +588,35 @@ static int setup_decode_edid_dtv_frame_with_extension(void **state) [44] = EDID_PIXEL_CLOCK(27027000u) & 0xFF, [45] = (EDID_PIXEL_CLOCK(27027000u) >> 8) & 0xFF, - /* Horizontal Addressable Video is 720px. - * Horizontal Blanking is 138 px. - */ - [46] = 0xD0, [47] = 0x8A, [48] = 0x20, - - /* Vertical Addressable Video is 480 lines. - * Vertical Blanking is 45 lines. - */ - [49] = 0xE0, [50] = 0x2D, [51] = 0x10, - - [52] = 16u, /* Horizontal Front Porch in pixels */ - [53] = 62u, /* Horizontal Sync Pulse Width in pixels */ - [54] = 0x96, /* Vertical Front Porch is 9 lines */ - [55] = 0x00, /* Vertical Sync Pulse Width is 6 lines */ - - /* Displayed Image Aspect Ratio is 4:3 */ - [56] = 4u, [57] = 3u, [58] = 0u, - - /* Horizontal and Vertical Border Size is 0 px */ - [59] = 0u, [60] = 0u, - - /* Timing is Interlaced Video - * Stereo Video is not supported - * Digital Separate Syncs are required - */ + /* Horizontal Addressable Video is 720px, + Horizontal Blanking is 138 px. */ + [46] = 0xD0, + [47] = 0x8A, + [48] = 0x20, + + /* Vertical Addressable Video is 480 lines, + Vertical Blanking is 45 lines. */ + [49] = 0xE0, + [50] = 0x2D, + [51] = 0x10, + + [52] = 16u, /* Horizontal Front Porch in pixels. */ + [53] = 62u, /* Horizontal Sync Pulse Width in pixels. */ + [54] = 0x96, /* Vertical Front Porch is 9 lines. */ + [55] = 0x00, /* Vertical Sync Pulse Width is 6 lines. */ + + /* Displayed Image Aspect Ratio is 4:3. */ + [56] = 4u, + [57] = 3u, + [58] = 0u, + + /* Horizontal and Vertical Border Size is 0px. */ + [59] = 0u, + [60] = 0u, + + /* Timing is Interlaced Video, + Stereo Video is not supported, + Digital Separate Syncs are required. */ [61] = 0x18, /* Descriptor Block 7 [18 Bytes] */ @@ -603,31 +624,35 @@ static int setup_decode_edid_dtv_frame_with_extension(void **state) [62] = EDID_PIXEL_CLOCK(27027000u) & 0xFF, [63] = (EDID_PIXEL_CLOCK(27027000u) >> 8) & 0xFF, - /* Horizontal Addressable Video is 1440px. - * Horizontal Blanking is 276 px. - */ - [64] = 0xA0, [65] = 0x14, [66] = 0x51, + /* Horizontal Addressable Video is 1440px, + Horizontal Blanking is 276 px. */ + [64] = 0xA0, + [65] = 0x14, + [66] = 0x51, - /* Vertical Addressable Video is 240 lines. - * Vertical Blanking is 23 lines. - */ - [67] = 0xF0, [68] = 0x16, [69] = 0x00, + /* Vertical Addressable Video is 240 lines, + Vertical Blanking is 23 lines. */ + [67] = 0xF0, + [68] = 0x16, + [69] = 0x00, - [70] = 38u, /* Horizontal Front Porch in pixels */ - [71] = 124u, /* Horizontal Sync Pulse Width in pixels */ - [72] = 0x43, /* Vertical Front Porch is 9 lines */ - [73] = 0x00, /* Vertical Sync Pulse Width is 6 lines */ + [70] = 38u, /* Horizontal Front Porch in pixels. */ + [71] = 124u, /* Horizontal Sync Pulse Width in pixels. */ + [72] = 0x43, /* Vertical Front Porch is 9 lines. */ + [73] = 0x00, /* Vertical Sync Pulse Width is 6 lines. */ /* Displayed Image Aspect Ratio is 16:9 */ - [74] = 16u, [75] = 9u, [76] = 0u, + [74] = 16u, + [75] = 9u, + [76] = 0u, - /* Horizontal and Vertical Border Size is 0 px */ - [77] = 0u, [78] = 0u, + /* Horizontal and Vertical Border Size is 0px. */ + [77] = 0u, + [78] = 0u, - /* Timing is Interlaced Video - * Stereo Video is not supported - * Digital Separate Syncs are required - */ + /* Timing is Interlaced Video, + Stereo Video is not supported, + Digital Separate Syncs are required. */ [79] = 0x98, /* Descriptor Block 8 [18 Bytes] */ @@ -635,44 +660,45 @@ static int setup_decode_edid_dtv_frame_with_extension(void **state) [80] = EDID_PIXEL_CLOCK(27027000u) & 0xFF, [81] = (EDID_PIXEL_CLOCK(27027000u) >> 8) & 0xFF, - /* Horizontal Addressable Video is 1440px. - * Horizontal Blanking is 276 px. - */ - [82] = 0xA0, [83] = 0x14, [84] = 0x51, - - /* Vertical Addressable Video is 240 lines. - * Vertical Blanking is 23 lines. - */ - [85] = 0xF0, [86] = 0x16, [87] = 0x00, - - [88] = 38u, /* Horizontal Front Porch in pixels */ - [89] = 124u, /* Horizontal Sync Pulse Width in pixels */ - [90] = 0x43, /* Vertical Front Porch is 9 lines */ - [91] = 0x00, /* Vertical Sync Pulse Width is 6 lines */ - - /* Displayed Image Aspect Ratio is 4:3 */ - [92] = 4u, [93] = 3u, [94] = 0u, - - /* Horizontal and Vertical Border Size is 0 px */ - [95] = 0u, [96] = 0u, - - /* Timing is Interlaced Video - * Stereo Video is not supported - * Digital Separate Syncs are required - */ + /* Horizontal Addressable Video is 1440px, + Horizontal Blanking is 276 px. */ + [82] = 0xA0, + [83] = 0x14, + [84] = 0x51, + + /* Vertical Addressable Video is 240 lines, + Vertical Blanking is 23 lines. */ + [85] = 0xF0, + [86] = 0x16, + [87] = 0x00, + + [88] = 38u, /* Horizontal Front Porch in pixels. */ + [89] = 124u, /* Horizontal Sync Pulse Width in pixels. */ + [90] = 0x43, /* Vertical Front Porch is 9 lines. */ + [91] = 0x00, /* Vertical Sync Pulse Width is 6 lines. */ + + /* Displayed Image Aspect Ratio is 4:3. */ + [92] = 4u, + [93] = 3u, + [94] = 0u, + + /* Horizontal and Vertical Border Size is 0px. */ + [95] = 0u, + [96] = 0u, + + /* Timing is Interlaced Video, + Stereo Video is not supported, + Digital Separate Syncs are required. */ [97] = 0x98, - [99 ... 126] = 0 - }; + [99 ... 126] = 0}; ext[127] = get_raw_edid_checksum(ext); *state = malloc(sizeof(struct test_state)); - struct test_state ts = { - .data_size = sizeof(raw) + sizeof(ext), - .data = malloc(sizeof(raw) + sizeof(ext)) - }; + struct test_state ts = {.data_size = sizeof(raw) + sizeof(ext), + .data = malloc(sizeof(raw) + sizeof(ext))}; memcpy(ts.data, &raw, sizeof(raw)); memcpy(ts.data + sizeof(raw), &ext[0], sizeof(ext)); @@ -682,18 +708,16 @@ static int setup_decode_edid_dtv_frame_with_extension(void **state) return 0; } -/* Test decoding of EDID frame with one extension. - */ +/* Test decoding of EDID frame with one extension. */ static void test_decode_edid_dtv_frame_with_extension(void **state) { struct edid out; struct test_state *ts = *state; /* In real-life situations frames often are not 100% conformant, - * but are at least correct when it comes to key data fields. - */ + but are at least correct when it comes to key data fields. */ assert_int_equal(EDID_CONFORMANT, - decode_edid((unsigned char *)ts->data, ts->data_size, &out)); + decode_edid((unsigned char *)ts->data, ts->data_size, &out)); assert_int_equal(32, out.framebuffer_bits_per_pixel); assert_int_equal(8, out.panel_bits_per_color); @@ -733,20 +757,21 @@ static void test_decode_edid_dtv_frame_with_extension(void **state) /* Test decoding of EDID frame with one extension. Tested frame is modified - * example of base EDID frame with CEA861 extension for IT/DTV Display from - * VESA E-EDID Standard Release A2. - */ + example of base EDID frame with CEA861 extension for IT/DTV Display from + VESA E-EDID Standard Release A2. */ static int setup_decode_edid_it_dtv_frame_with_extension(void **state) { struct edid_raw raw = { EDID_RAW_DEFAULT_PARAMS, - .video_input_type = EDID_DIGITAL_VSI + .video_input_type = + EDID_DIGITAL_VSI | EDID_INTERFACE_HDMI_A | EDID_COLOR_BIT_DEPTH_8B, .horizontal_size = 121, /* Aspect ratio 16:9 in landscape */ - .vertical_size = 68, /* Landscape flag */ - .display_gamma = 120, /* 220% */ - .supported_features = EDID_STANDBY_MODE(0) + .vertical_size = 68, /* Landscape flag */ + .display_gamma = 120, /* 220% */ + .supported_features = + EDID_STANDBY_MODE(0) | EDID_SUSPEND_MODE(0) | EDID_ACTIVE_OFF(0) | EDID_COLOR_FORMAT_RGB444_YCRCB422_YCRCB422 @@ -755,20 +780,20 @@ static int setup_decode_edid_it_dtv_frame_with_extension(void **state) | EDID_DISPLAY_FREQUENCY_NON_CONTINUOUS, .established_supported_timings = { [0] = EDID_ESTABLISHED_TIMINGS_1_800x600_60Hz - | EDID_ESTABLISHED_TIMINGS_1_800x600_56Hz - | EDID_ESTABLISHED_TIMINGS_1_640x480_75Hz - | EDID_ESTABLISHED_TIMINGS_1_640x480_72Hz - | EDID_ESTABLISHED_TIMINGS_1_640x480_67Hz - | EDID_ESTABLISHED_TIMINGS_1_640x480_60Hz - | EDID_ESTABLISHED_TIMINGS_1_720x400_88Hz - | EDID_ESTABLISHED_TIMINGS_1_720x400_70Hz, + | EDID_ESTABLISHED_TIMINGS_1_800x600_56Hz + | EDID_ESTABLISHED_TIMINGS_1_640x480_75Hz + | EDID_ESTABLISHED_TIMINGS_1_640x480_72Hz + | EDID_ESTABLISHED_TIMINGS_1_640x480_67Hz + | EDID_ESTABLISHED_TIMINGS_1_640x480_60Hz + | EDID_ESTABLISHED_TIMINGS_1_720x400_88Hz + | EDID_ESTABLISHED_TIMINGS_1_720x400_70Hz, [1] = EDID_ESTABLISHED_TIMINGS_2_1280x1024_75Hz - | EDID_ESTABLISHED_TIMINGS_2_1024x768_75Hz - | EDID_ESTABLISHED_TIMINGS_2_1024x768_70Hz - | EDID_ESTABLISHED_TIMINGS_2_1024x768_60Hz - | EDID_ESTABLISHED_TIMINGS_2_832x624_75Hz - | EDID_ESTABLISHED_TIMINGS_2_800x600_75Hz - | EDID_ESTABLISHED_TIMINGS_2_800x600_72Hz, + | EDID_ESTABLISHED_TIMINGS_2_1024x768_75Hz + | EDID_ESTABLISHED_TIMINGS_2_1024x768_70Hz + | EDID_ESTABLISHED_TIMINGS_2_1024x768_60Hz + | EDID_ESTABLISHED_TIMINGS_2_832x624_75Hz + | EDID_ESTABLISHED_TIMINGS_2_800x600_75Hz + | EDID_ESTABLISHED_TIMINGS_2_800x600_72Hz, }, .manufacturers_reserved_timing = EDID_MANUFACTURERS_TIMINGS_1152x870_75Hz, .standard_timings_supported = { @@ -800,78 +825,83 @@ static int setup_decode_edid_it_dtv_frame_with_extension(void **state) [0] = EDID_PIXEL_CLOCK(85500000u) & 0xFF, [1] = (EDID_PIXEL_CLOCK(85500000u) >> 8) & 0xFF, - /* Horizontal Addressable Video is 1360px - * Horizontal Blanking is 432px - */ - [2] = 0x50, [3] = 0xB0, [4] = 0x51, + /* Horizontal Addressable Video is 1360px, + Horizontal Blanking is 432px. */ + [2] = 0x50, + [3] = 0xB0, + [4] = 0x51, - /* Vertical Addressable Video is 768 lines - * Vertical Blanking is 27 lines - */ - [5] = 0x00, [6] = 0x1B, [7] = 0x30, + /* Vertical Addressable Video is 768 lines, + Vertical Blanking is 27 lines. */ + [5] = 0x00, + [6] = 0x1B, + [7] = 0x30, - [8] = 64u, /* Horizontal Front Porch in pixels */ - [9] = 112u, /* Horizontal Pulse Sync Width in pixels */ - [10] = 0x36, /* Vertical Front Porch is 3 lines */ - [11] = 0u, /* Vertical Sync Pulse Width is 6 lines */ + [8] = 64u, /* Horizontal Front Porch in pixels. */ + [9] = 112u, /* Horizontal Pulse Sync Width in pixels. */ + [10] = 0x36, /* Vertical Front Porch is 3 lines. */ + [11] = 0u, /* Vertical Sync Pulse Width is 6 lines. */ - /* Horizontal Addressable Image Size is 1214mm - * Vertical Addressable Image Size is 683mm - */ - [12] = 0xBE, [13] = 0xAB, [14] = 0x42, + /* Horizontal Addressable Image Size is 1214mm, + Vertical Addressable Image Size is 683mm. */ + [12] = 0xBE, + [13] = 0xAB, + [14] = 0x42, - [15] = 0x00, /* Horizontal border size is 0px*/ - [16] = 0x00, /* Vertical Border Size is 0px */ + [15] = 0x00, /* Horizontal border size is 0px. */ + [16] = 0x00, /* Vertical Border Size is 0px. */ /* Timing is Non-Interlaced Video, - * Stereo Video is not supported, - * Digital separate and syncs are requires. - */ + Stereo Video is not supported, + Digital separate and syncs are requires. */ [17] = 0x1E, }, .descriptor_block_2 = { [0] = EDID_PIXEL_CLOCK(74250000u) & 0xFF, [1] = (EDID_PIXEL_CLOCK(74250000u) >> 8) & 0xFF, - /* Horizontal Addressable Video is 1280px - * Horizontal Blanking is 370px - */ - [2] = 0x00, [3] = 0x72, [4] = 0x51, + /* Horizontal Addressable Video is 1280px, + Horizontal Blanking is 370px. */ + [2] = 0x00, + [3] = 0x72, + [4] = 0x51, - /* Vertical Addressable Video is 720 lines - * Vertical Blanking is 30 lines - */ - [5] = 0xD0, [6] = 0x1E, [7] = 0x20, + /* Vertical Addressable Video is 720 lines, + Vertical Blanking is 30 lines. */ + [5] = 0xD0, + [6] = 0x1E, + [7] = 0x20, - [8] = 110u, /* Horizontal Front Porch in pixels */ - [9] = 40u, /* Horizontal Pulse Sync Width in pixels */ - [10] = 0x55, /* Vertical Front Porch is 5 lines */ - [11] = 0x00, /* Vertical Sync Pulse Width is 5 lines */ + [8] = 110u, /* Horizontal Front Porch in pixels. */ + [9] = 40u, /* Horizontal Pulse Sync Width in pixels. */ + [10] = 0x55, /* Vertical Front Porch is 5 lines. */ + [11] = 0x00, /* Vertical Sync Pulse Width is 5 lines. */ - /* Horizontal Addressable Image Size is 1214mm - * Vertical Addressable Image Size is 683mm - */ - [12] = 0xBE, [13] = 0xAB, [14] = 0x42, + /* Horizontal Addressable Image Size is 1214mm, + Vertical Addressable Image Size is 683mm. */ + [12] = 0xBE, + [13] = 0xAB, + [14] = 0x42, - [15] = 0x00, /* Horizontal border size is 0px*/ - [16] = 0x00, /* Vertical Border Size is 0px */ + [15] = 0x00, /* Horizontal border size is 0px. */ + [16] = 0x00, /* Vertical Border Size is 0px. */ /* Timing is Non-Interlaced Video, - * Stereo Video is not supported, - * Digital separate and syncs are requires. - */ + Stereo Video is not supported, + Digital separate and syncs are required. */ [17] = 0x1E, }, .descriptor_block_3 = { /* Established timings III Block Tag */ - [0 ... 2] = 0u, [3] = 0xF7, [4] = 0u, + [0 ... 2] = 0u, + [3] = 0xF7, + [4] = 0u, - /* - * VESA DMT Standard Version #10 - */ + /* VESA DMT Standard Version #10 */ [5] = 10u, - /* 640x350@85Hz, + /* + * 640x350@85Hz, * 640x400@85Hz, * 720x400@85Hz, * 640x480@85Hz, @@ -881,26 +911,30 @@ static int setup_decode_edid_it_dtv_frame_with_extension(void **state) */ [6] = 0x7F, - /* 1280x960@60Hz, + /* + * 1280x960@60Hz, * 1280x960@85Hz, * 1280x1024@60Hz, * 1280x1024@85Hz */ [7] = 0x0F, - /* 1400x1050@60Hz (Normal Blanking), + /* + * 1400x1050@60Hz (Normal Blanking), * 1400x1050@75Hz are supported. */ [8] = 0x03, - /* 1400x1050@85Hz, + /* + * 1400x1050@85Hz, * 1600x1200@60Hz, * 1600x1200@65Hz, * 1600x1200@70Hz are supported. */ [9] = 0x87, - /* 1600x1200@75Hz, + /* + * 1600x1200@75Hz, * 1600x1200@85Hz are supported. */ [10] = 0xC0, @@ -913,7 +947,11 @@ static int setup_decode_edid_it_dtv_frame_with_extension(void **state) }, .descriptor_block_4 = { /* Display Product Name Block Tag */ - [0] = 0, [1] = 0, [2] = 0, [3] = 0xFC, [4] = 0, + [0] = 0, + [1] = 0, + [2] = 0, + [3] = 0xFC, + [4] = 0, /* Product name */ [5] = 'A', @@ -940,16 +978,14 @@ static int setup_decode_edid_it_dtv_frame_with_extension(void **state) [1] = 0x03, /* CEA 861 Block Version */ [2] = 0x17, /* Detail Timing Descriptors start 0x17 bytesfrom here */ - /* Underscan is supported - * Basic Audio is supported - * YCbCr 4:4:4 & YCbCr 4:2:2 are supported - * Number of native formats: 0 - */ + /* Underscan is supported, + Basic Audio is supported, + YCbCr 4:4:4 & YCbCr 4:2:2 are supported, + Number of native formats: 0. */ [3] = 0xF0, - /* Video Data Block Tag Code is 2 - * Number of Short Video Descriptor Bytes i 6 - */ + /* Video Data Block Tag Code is 2. + Number of Short Video Descriptor Bytes is 6. */ [4] = 0x46, /* 1920x1080i 59.94/60 Hz 16 : 9 AR (CEA Format #5) is a supported format. */ @@ -970,14 +1006,12 @@ static int setup_decode_edid_it_dtv_frame_with_extension(void **state) /* 720x480i 59.94/60 Hz 4 : 3 AR (CEA Format #6) is a supported format. */ [10] = 0x06, - /* Audio Data Block Tag Code is 1. - * Number of Short Audio Descriptor Bytes is 3. - */ + /* Audio Data Block Tag Code is 1, + Number of Short Audio Descriptor Bytes is 3. */ [11] = 0x23, - /* Audio Format Tag Code is 1 --- LPCM is supported. - * Maximum number of audio channels is 2 - */ + /* Audio Format Tag Code is 1 --- LPCM is supported, + Maximum number of audio channels is 2. */ [12] = 0x09, /* Supported Sampling Frequencies include: 48kHz; 44.1kHz & 32kHz. */ @@ -986,10 +1020,8 @@ static int setup_decode_edid_it_dtv_frame_with_extension(void **state) /* Supported Sampling Bit Rates include: 24 bit; 20 bit & 16 bit. */ [14] = 0x07, - /* Speaker Allocation Block Tag Code is 4. - * Number of Speaker Allocation - * Descriptor Bytes is 3. - */ + /* Speaker Allocation Block Tag Code is 4, + Number of Speaker Allocation Descriptor Bytes is 3. */ [15] = 0x83, /* Speaker Allocation is Front-Left & Front-Right */ @@ -998,47 +1030,53 @@ static int setup_decode_edid_it_dtv_frame_with_extension(void **state) /* Reserved */ [17 ... 18] = 0, - /* Vendor Specific Data Block Tag Code is 3. - * Number of Vendor Specific Data Bytes is 5. - */ + /* Vendor Specific Data Block Tag Code is 3, + Number of Vendor Specific Data Bytes is 5. */ [19] = 0x65, - /* 24bit IEEE registration Identifier is 0x000C03 */ - [20] = 0x03, [21] = 0x0C, [22] = 0x00, + /* 24bit IEEE registration Identifier is 0x000C03. */ + [20] = 0x03, + [21] = 0x0C, + [22] = 0x00, - /* Vendor Specific Data is 0x10000 */ - [23] = 0x01, [24] = 0x00, + /* Vendor Specific Data is 0x10000. */ + [23] = 0x01, + [24] = 0x00, /* Descriptor Block 5 [18 Bytes] */ [25] = EDID_PIXEL_CLOCK(74250000u) & 0xFF, [26] = (EDID_PIXEL_CLOCK(74250000u) >> 8) & 0xFF, - /* Horizontal Addressable Video is 1920px. - * Horizontal Blanking is 280px. - */ - [27] = 0x80, [28] = 0x18, [29] = 0x71, + /* Horizontal Addressable Video is 1920px, + Horizontal Blanking is 280px. */ + [27] = 0x80, + [28] = 0x18, + [29] = 0x71, - /* Vertical Addressable Video is 540 lines. - * Vertical Blanking is 22 lines. - */ - [30] = 0x1C, [31] = 0x16, [32] = 0x20, + /* Vertical Addressable Video is 540 lines, + Vertical Blanking is 22 lines. */ + [30] = 0x1C, + [31] = 0x16, + [32] = 0x20, - [33] = 88u, /* Horizontal Front Porch in pixels */ - [34] = 44u, /* Horizontal Sync Pulse Width in pixels */ - [35] = 0x25, /* Vertical Front Porch is 2 lines */ - [36] = 0x00, /* Vertical Sync Pulse Width is 5 lines */ + [33] = 88u, /* Horizontal Front Porch in pixels. */ + [34] = 44u, /* Horizontal Sync Pulse Width in pixels. */ + [35] = 0x25, /* Vertical Front Porch is 2 lines. */ + [36] = 0x00, /* Vertical Sync Pulse Width is 5 lines. */ /* Image size: 1039mm x 584mm */ - [37] = 0x0F, [38] = 0x48, [39] = 0x42, + [37] = 0x0F, + [38] = 0x48, + [39] = 0x42, - /* Horizontal and Vertical Border Size is 0 px */ - [40] = 0u, [41] = 0u, + /* Horizontal and Vertical Border Size is 0px. */ + [40] = 0u, + [41] = 0u, - /* Timing is Interlaced Video - * Stereo Video is not supported - * Digital Separate Syncs are required - */ + /* Timing is Interlaced Video, + Stereo Video is not supported, + Digital Separate Syncs are required. */ [42] = 0x9E, /* Descriptor Block 6 [18 Bytes] */ @@ -1046,31 +1084,35 @@ static int setup_decode_edid_it_dtv_frame_with_extension(void **state) [43] = EDID_PIXEL_CLOCK(74250000u) & 0xFF, [44] = (EDID_PIXEL_CLOCK(74250000u) >> 8) & 0xFF, - /* Horizontal Addressable Video is 1280px. - * Horizontal Blanking is 370 px. - */ - [45] = 0x00, [46] = 0x72, [47] = 0x51, + /* Horizontal Addressable Video is 1280px, + Horizontal Blanking is 370 px. */ + [45] = 0x00, + [46] = 0x72, + [47] = 0x51, - /* Vertical Addressable Video is 720 lines. - * Vertical Blanking is 30 lines. - */ - [48] = 0xD0, [49] = 0x1E, [50] = 0x20, + /* Vertical Addressable Video is 720 lines, + Vertical Blanking is 30 lines. */ + [48] = 0xD0, + [49] = 0x1E, + [50] = 0x20, - [51] = 110u, /* Horizontal Front Porch in pixels */ - [52] = 40u, /* Horizontal Sync Pulse Width in pixels */ - [53] = 0x55, /* Vertical Front Porch is 5 lines */ - [54] = 0x00, /* Vertical Sync Pulse Width is 5 lines */ + [51] = 110u, /* Horizontal Front Porch in pixels. */ + [52] = 40u, /* Horizontal Sync Pulse Width in pixels. */ + [53] = 0x55, /* Vertical Front Porch is 5 lines. */ + [54] = 0x00, /* Vertical Sync Pulse Width is 5 lines. */ /* Image size: 1039mm x 584mm */ - [55] = 0x0F, [56] = 0x48, [57] = 0x42, + [55] = 0x0F, + [56] = 0x48, + [57] = 0x42, - /* Horizontal and Vertical Border Size is 0 px */ - [58] = 0u, [59] = 0u, + /* Horizontal and Vertical Border Size is 0px. */ + [58] = 0u, + [59] = 0u, - /* Timing is Non-Interlaced Video - * Stereo Video is not supported - * Digital Separate Syncs are required - */ + /* Timing is Non-Interlaced Video, + Stereo Video is not supported, + Digital Separate Syncs are required. */ [60] = 0x1E, /* Descriptor Block 7 [18 Bytes] */ @@ -1078,31 +1120,35 @@ static int setup_decode_edid_it_dtv_frame_with_extension(void **state) [61] = EDID_PIXEL_CLOCK(27000000u) & 0xFF, [62] = (EDID_PIXEL_CLOCK(27000000u) >> 8) & 0xFF, - /* Horizontal Addressable Video is 1440px. - * Horizontal Blanking is 276 px. - */ - [63] = 0xA0, [64] = 0x14, [65] = 0x51, + /* Horizontal Addressable Video is 1440px, + Horizontal Blanking is 276 px. */ + [63] = 0xA0, + [64] = 0x14, + [65] = 0x51, - /* Vertical Addressable Video is 240 lines. - * Vertical Blanking is 23 lines. - */ - [66] = 0xF0, [67] = 0x16, [68] = 0x00, + /* Vertical Addressable Video is 240 lines, + Vertical Blanking is 23 lines. */ + [66] = 0xF0, + [67] = 0x16, + [68] = 0x00, - [69] = 38u, /* Horizontal Front Porch in pixels */ - [70] = 124u, /* Horizontal Sync Pulse Width in pixels */ - [71] = 0x43, /* Vertical Front Porch is 4 lines */ - [72] = 0x00, /* Vertical Sync Pulse Width is 3 lines */ + [69] = 38u, /* Horizontal Front Porch in pixels. */ + [70] = 124u, /* Horizontal Sync Pulse Width in pixels. */ + [71] = 0x43, /* Vertical Front Porch is 4 lines. */ + [72] = 0x00, /* Vertical Sync Pulse Width is 3 lines. */ /* Image size: 1039mm x 584mm */ - [73] = 0x0F, [74] = 0x48, [75] = 0x42, + [73] = 0x0F, + [74] = 0x48, + [75] = 0x42, - /* Horizontal and Vertical Border Size is 0 px */ - [76] = 0u, [77] = 0u, + /* Horizontal and Vertical Border Size is 0px. */ + [76] = 0u, + [77] = 0u, - /* Timing is Interlaced Video - * Stereo Video is not supported - * Digital Separate Syncs are required - */ + /* Timing is Interlaced Video, + Stereo Video is not supported, + Digital Separate Syncs are required. */ [78] = 0x18, /* Descriptor Block 8 [18 Bytes] */ @@ -1110,31 +1156,35 @@ static int setup_decode_edid_it_dtv_frame_with_extension(void **state) [79] = EDID_PIXEL_CLOCK(27027000u) & 0xFF, [80] = (EDID_PIXEL_CLOCK(27027000u) >> 8) & 0xFF, - /* Horizontal Addressable Video is 1440px. - * Horizontal Blanking is 276 px. - */ - [81] = 0xA0, [82] = 0x14, [83] = 0x51, + /* Horizontal Addressable Video is 1440px, + Horizontal Blanking is 276 px. */ + [81] = 0xA0, + [82] = 0x14, + [83] = 0x51, - /* Vertical Addressable Video is 240 lines. - * Vertical Blanking is 23 lines. - */ - [84] = 0xF0, [85] = 0x16, [86] = 0x00, + /* Vertical Addressable Video is 240 lines, + Vertical Blanking is 23 lines. */ + [84] = 0xF0, + [85] = 0x16, + [86] = 0x00, - [87] = 38u, /* Horizontal Front Porch in pixels */ - [88] = 124u, /* Horizontal Sync Pulse Width in pixels */ - [89] = 0x43, /* Vertical Front Porch is 4 lines */ - [90] = 0x00, /* Vertical Sync Pulse Width is 3 lines */ + [87] = 38u, /* Horizontal Front Porch in pixels. */ + [88] = 124u, /* Horizontal Sync Pulse Width in pixels. */ + [89] = 0x43, /* Vertical Front Porch is 4 lines. */ + [90] = 0x00, /* Vertical Sync Pulse Width is 3 lines. */ /* Image size: 1039mm x 584mm */ - [91] = 0x0F, [92] = 0x48, [93] = 0x42, + [91] = 0x0F, + [92] = 0x48, + [93] = 0x42, - /* Horizontal and Vertical Border Size is 0 px */ - [94] = 0u, [95] = 0u, + /* Horizontal and Vertical Border Size is 0px. */ + [94] = 0u, + [95] = 0u, - /* Timing is Interlaced Video - * Stereo Video is not supported - * Digital Separate Syncs are required - */ + /* Timing is Interlaced Video, + Stereo Video is not supported, + Digital Separate Syncs are required. */ [96] = 0x98, [97 ... 126] = 0, @@ -1144,10 +1194,8 @@ static int setup_decode_edid_it_dtv_frame_with_extension(void **state) *state = malloc(sizeof(struct test_state)); - struct test_state ts = { - .data_size = sizeof(raw) + sizeof(ext), - .data = malloc(sizeof(raw) + sizeof(ext)) - }; + struct test_state ts = {.data_size = sizeof(raw) + sizeof(ext), + .data = malloc(sizeof(raw) + sizeof(ext))}; memcpy(ts.data, &raw, sizeof(raw)); memcpy(ts.data + sizeof(raw), &ext[0], sizeof(ext)); @@ -1163,10 +1211,9 @@ static void test_decode_edid_it_dtv_frame_with_extension(void **state) struct test_state *ts = *state; /* In real-life situations frames often are not 100% conformant, - * but are at least correct when it comes to key data fields. - */ + but are at least correct when it comes to key data fields. */ assert_int_equal(EDID_CONFORMANT, - decode_edid((unsigned char *)ts->data, ts->data_size, &out)); + decode_edid((unsigned char *)ts->data, ts->data_size, &out)); assert_int_equal(32, out.framebuffer_bits_per_pixel); assert_int_equal(8, out.panel_bits_per_color); diff --git a/tests/lib/fmap-test.c b/tests/lib/fmap-test.c index 044c3121a96f..1cc8246b4be3 100644 --- a/tests/lib/fmap-test.c +++ b/tests/lib/fmap-test.c @@ -31,7 +31,7 @@ static void prepare_flash_buffer(void) /* Fill rest of buffer with dummy data */ 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'); } @@ -140,13 +140,13 @@ static void test_fmap_locate_area_as_rdev_rw(void **state) /* Test if returned section region device is writable */ assert_int_not_equal(-1, fmap_locate_area_as_rdev_rw("MISC_RW", &rdev)); 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, - 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 */ assert_int_not_equal(-1, fmap_locate_area_as_rdev("MISC_RW", &rdev)); 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_equal(dummy_data, buffer2, ro_rw_section_size); @@ -261,7 +261,7 @@ static void test_fmap_overwrite_area(void **state) /* Overwrite part of section. */ 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 */ 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); /* Expect error when overwriting incorrect section */ - assert_int_equal(-1, fmap_overwrite_area("NONEXISTENT_SECTION", - new_data, section_size / 2)); + assert_int_equal( + -1, fmap_overwrite_area("NONEXISTENT_SECTION", 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 @@ -288,18 +288,17 @@ static void test_fmap_overwrite_area(void **state) int main(void) { const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_fmap_locate_area_as_rdev, - setup_fmap, teardown_fmap), - cmocka_unit_test_setup_teardown(test_fmap_locate_area_as_rdev_rw, - setup_fmap, teardown_fmap), - cmocka_unit_test_setup_teardown(test_fmap_locate_area, - setup_fmap, teardown_fmap), - cmocka_unit_test_setup_teardown(test_fmap_find_region_name, - setup_fmap, teardown_fmap), - cmocka_unit_test_setup_teardown(test_fmap_read_area, - setup_fmap, teardown_fmap), - cmocka_unit_test_setup_teardown(test_fmap_overwrite_area, - setup_fmap, teardown_fmap), + cmocka_unit_test_setup_teardown(test_fmap_locate_area_as_rdev, setup_fmap, + teardown_fmap), + cmocka_unit_test_setup_teardown(test_fmap_locate_area_as_rdev_rw, setup_fmap, + teardown_fmap), + cmocka_unit_test_setup_teardown(test_fmap_locate_area, setup_fmap, + teardown_fmap), + cmocka_unit_test_setup_teardown(test_fmap_find_region_name, setup_fmap, + teardown_fmap), + cmocka_unit_test_setup_teardown(test_fmap_read_area, setup_fmap, teardown_fmap), + cmocka_unit_test_setup_teardown(test_fmap_overwrite_area, setup_fmap, + teardown_fmap), }; return cb_run_group_tests(tests, NULL, NULL); diff --git a/tests/lib/hexstrtobin-test.c b/tests/lib/hexstrtobin-test.c index f096b9b9e7d7..aaad0d6b3136 100644 --- a/tests/lib/hexstrtobin-test.c +++ b/tests/lib/hexstrtobin-test.c @@ -12,11 +12,11 @@ struct hexstr_t { size_t res; } hexstr[] = { {.str = "A", .res = 0}, - {.str = "AB", .val = (int[]) {171}, .res = 1}, - {.str = "277a", .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 = "\nB*e/ef-", .val = (int[]) {190, 239}, .res = 2}, + {.str = "AB", .val = (int[]){171}, .res = 1}, + {.str = "277a", .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 = "\nB*e/ef-", .val = (int[]){190, 239}, .res = 2}, }; static void test_hexstrtobin(void **state) diff --git a/tests/lib/imd-test.c b/tests/lib/imd-test.c index 6da1ac926c6f..28a4456b27b7 100644 --- a/tests/lib/imd-test.c +++ b/tests/lib/imd-test.c @@ -12,8 +12,9 @@ /* Auxiliary functions and definitions. */ -#define LG_ROOT_SIZE align_up_pow2(sizeof(struct imd_root_pointer) +\ - sizeof(struct imd_root) + 3 * sizeof(struct imd_entry)) +#define LG_ROOT_SIZE \ + 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_SIZE (2 * sizeof(int32_t)) #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) { 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; struct imd imd; uintptr_t test_inputs[] = { - 0, /* Lowest possible address */ - 0xA000, /* Fits in 16 bits, should not get rounded down*/ - 0xDEAA, /* Fits in 16 bits */ - 0xB0B0B000, /* Fits in 32 bits, should not get rounded down */ - 0xF0F0F0F0, /* Fits in 32 bits */ - ((1ULL << 32) + 4), /* Just above 32-bit limit */ - 0x6666777788889000, /* Fits in 64 bits, should not get rounded down */ - ((1ULL << 60) - 100) /* Very large address, fitting in 64 bits */ + 0, /* Lowest possible address */ + 0xA000, /* Fits in 16 bits, should not get rounded down*/ + 0xDEAA, /* Fits in 16 bits */ + 0xB0B0B000, /* Fits in 32 bits, should not get rounded down */ + 0xF0F0F0F0, /* Fits in 32 bits */ + ((1ULL << 32) + 4), /* Just above 32-bit limit */ + 0x6666777788889000, /* Fits in 64 bits, should not get rounded down */ + ((1ULL << 60) - 100) /* Very large address, fitting in 64 bits */ }; 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)); /* Try incorrect sizes */ - assert_int_equal(-1, imd_create_empty(&imd, - sizeof(struct imd_root_pointer), - LG_ENTRY_ALIGN)); + assert_int_equal( + -1, imd_create_empty(&imd, sizeof(struct imd_root_pointer), LG_ENTRY_ALIGN)); assert_int_equal(-1, imd_create_empty(&imd, LG_ROOT_SIZE, 2 * LG_ROOT_SIZE)); /* Working case */ 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 */ - r = (struct imd_root *) (imd.lg.r); + r = (struct imd_root *)(imd.lg.r); assert_non_null(r); 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 */ 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 */ - lg_region_wrong_size = sizeof(struct imd_root_pointer) + sizeof(struct imd_root) + - sizeof(struct imd_entry); - expect_assert_failure( - imd_create_tiered_empty(&imd, lg_region_wrong_size, LG_ENTRY_ALIGN, - SM_ROOT_SIZE, SM_ENTRY_ALIGN) - ); + lg_region_wrong_size = sizeof(struct imd_root_pointer) + sizeof(struct imd_root) + + sizeof(struct imd_entry); + expect_assert_failure(imd_create_tiered_empty( + &imd, lg_region_wrong_size, LG_ENTRY_ALIGN, SM_ROOT_SIZE, SM_ENTRY_ALIGN)); assert_int_equal(0, imd_create_tiered_empty(&imd, LG_ROOT_SIZE, LG_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_root_pointer *rp; 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; /* 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)); /* Set the limit for lg. */ @@ -327,8 +325,8 @@ static void test_imd_limit_size(void **state) struct imd imd = {0}; size_t root_size, max_size; - max_size = align_up_pow2(sizeof(struct imd_root_pointer) - + sizeof(struct imd_root) + 3 * sizeof(struct imd_entry)); + max_size = align_up_pow2(sizeof(struct imd_root_pointer) + sizeof(struct imd_root) + + 3 * sizeof(struct imd_entry)); 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"); imd_handle_init(&imd, (void *)(LIMIT_ALIGN + (uintptr_t)base)); - root_size = align_up_pow2(sizeof(struct imd_root_pointer) - + sizeof(struct imd_root) + 2 * sizeof(struct imd_entry)); + root_size = align_up_pow2(sizeof(struct imd_root_pointer) + sizeof(struct imd_root) + + 2 * sizeof(struct imd_entry)); imd.lg.r = (void *)imd.lg.limit - root_size; 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) 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_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)); if (imd.sm.r == NULL) 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_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 */ for (i = 0; i < 5; i++) { 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); } @@ -579,7 +577,7 @@ static void test_imd_entry_find_or_add(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)); @@ -616,7 +614,7 @@ static void test_imd_entry_at(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)); } @@ -761,4 +759,3 @@ int main(void) return cb_run_group_tests(tests, NULL, NULL); } - diff --git a/tests/lib/imd_cbmem-test.c b/tests/lib/imd_cbmem-test.c index 1a1756c9d38c..fe25285b6829 100644 --- a/tests/lib/imd_cbmem-test.c +++ b/tests/lib/imd_cbmem-test.c @@ -441,14 +441,13 @@ static void test_cbmem_entry_start(void **state) /* Check if start address of found entry is the same as the one returned by cbmem_find() function */ 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(id2), cbmem_entry_start(cbmem_entry_find(id2))); } /* Reimplementation for testing purposes */ -void bootmem_add_range(uint64_t start, uint64_t size, - const enum bootmem_type tag) +void bootmem_add_range(uint64_t start, uint64_t size, const enum bootmem_type tag) { check_expected(start); check_expected(size); diff --git a/tests/lib/libgcc-test.c b/tests/lib/libgcc-test.c index d089f646b9ce..1a567e91c00e 100644 --- a/tests/lib/libgcc-test.c +++ b/tests/lib/libgcc-test.c @@ -12,108 +12,108 @@ struct { } test_data[] = { /* GCC documentation says, __clzsi2() has undefined result for zero as an input value, but coreboot implementation can handle this. */ - { .value = 0, .expected_output = 32 }, - - { .value = 1, .expected_output = 31 }, - { .value = 2, .expected_output = 30 }, - { .value = 3, .expected_output = 30 }, - { .value = 4, .expected_output = 29 }, - { .value = 5, .expected_output = 29 }, - { .value = 6, .expected_output = 29 }, - { .value = 7, .expected_output = 29 }, - - { .value = 0xF, .expected_output = 28 }, - { .value = 0x10, .expected_output = 27 }, - { .value = 0x25, .expected_output = 26 }, - { .value = 0x5D, .expected_output = 25 }, - { .value = 0xB7, .expected_output = 24 }, - - { .value = 0x133, .expected_output = 23 }, - { .value = 0x3DC, .expected_output = 22 }, - { .value = 0x6F1, .expected_output = 21 }, - { .value = 0x897, .expected_output = 20 }, - - { .value = 0x1FFF, .expected_output = 19 }, - { .value = 0x2222, .expected_output = 18 }, - { .value = 0x7BAD, .expected_output = 17 }, - { .value = 0xE708, .expected_output = 16 }, - - { .value = 0x1DABD, .expected_output = 15 }, - { .value = 0x29876, .expected_output = 14 }, - { .value = 0x56665, .expected_output = 13 }, - { .value = 0xABCDE, .expected_output = 12 }, - - { .value = 0x18365F, .expected_output = 11 }, - { .value = 0x3D0115, .expected_output = 10 }, - { .value = 0x4B07EB, .expected_output = 9 }, - { .value = 0xCCC74D, .expected_output = 8 }, - - { .value = 0x17933ED, .expected_output = 7 }, - { .value = 0x2B00071, .expected_output = 6 }, - { .value = 0x4D4C1A5, .expected_output = 5 }, - { .value = 0xAD01FFF, .expected_output = 4 }, - - { .value = 0x1C5A8057, .expected_output = 3 }, - { .value = 0x35AB23C3, .expected_output = 2 }, - { .value = 0x7017013B, .expected_output = 1 }, - { .value = 0xAD01EB15, .expected_output = 0 }, - - { .value = 0xFFFFFFFF, .expected_output = 0 }, - { .value = 0x80000000, .expected_output = 0 }, - { .value = 0x7FFFFFFF, .expected_output = 1 }, - { .value = 0x30000000, .expected_output = 2 }, - { .value = 0x10000000, .expected_output = 3 }, - { .value = 0x0FFFFFFF, .expected_output = 4 }, - - { .value = 0xFF000000, .expected_output = 0 }, - { .value = 0x00FF0000, .expected_output = 8 }, - { .value = 0x0000FF00, .expected_output = 16 }, - { .value = 0x000000FF, .expected_output = 24 }, - - { .value = 0x8F000000, .expected_output = 0 }, - { .value = 0x008F0000, .expected_output = 8 }, - { .value = 0x00008F00, .expected_output = 16 }, - { .value = 0x0000008F, .expected_output = 24 }, - - { .value = 0x7F000000, .expected_output = 1 }, - { .value = 0x007F0000, .expected_output = 9 }, - { .value = 0x00007F00, .expected_output = 17 }, - { .value = 0x0000007F, .expected_output = 25 }, - - { .value = 0x3F000000, .expected_output = 2 }, - { .value = 0x003F0000, .expected_output = 10 }, - { .value = 0x00003F00, .expected_output = 18 }, - { .value = 0x0000003F, .expected_output = 26 }, - - { .value = 0x1F000000, .expected_output = 3 }, - { .value = 0x001F0000, .expected_output = 11 }, - { .value = 0x00001F00, .expected_output = 19 }, - { .value = 0x0000001F, .expected_output = 27 }, - - { .value = 0x0F000000, .expected_output = 4 }, - { .value = 0x000F0000, .expected_output = 12 }, - { .value = 0x00000F00, .expected_output = 20 }, - { .value = 0x0000000F, .expected_output = 28 }, - - { .value = 0x08000000, .expected_output = 4 }, - { .value = 0x00080000, .expected_output = 12 }, - { .value = 0x00000800, .expected_output = 20 }, - { .value = 0x00000008, .expected_output = 28 }, - - { .value = 0x07000000, .expected_output = 5 }, - { .value = 0x00070000, .expected_output = 13 }, - { .value = 0x00000700, .expected_output = 21 }, - { .value = 0x00000007, .expected_output = 29 }, - - { .value = 0x03000000, .expected_output = 6 }, - { .value = 0x00030000, .expected_output = 14 }, - { .value = 0x00000300, .expected_output = 22 }, - { .value = 0x00000003, .expected_output = 30 }, - - { .value = 0x01000000, .expected_output = 7 }, - { .value = 0x00010000, .expected_output = 15 }, - { .value = 0x00000100, .expected_output = 23 }, - { .value = 0x00000001, .expected_output = 31 }, + {.value = 0, .expected_output = 32}, + + {.value = 1, .expected_output = 31}, + {.value = 2, .expected_output = 30}, + {.value = 3, .expected_output = 30}, + {.value = 4, .expected_output = 29}, + {.value = 5, .expected_output = 29}, + {.value = 6, .expected_output = 29}, + {.value = 7, .expected_output = 29}, + + {.value = 0xF, .expected_output = 28}, + {.value = 0x10, .expected_output = 27}, + {.value = 0x25, .expected_output = 26}, + {.value = 0x5D, .expected_output = 25}, + {.value = 0xB7, .expected_output = 24}, + + {.value = 0x133, .expected_output = 23}, + {.value = 0x3DC, .expected_output = 22}, + {.value = 0x6F1, .expected_output = 21}, + {.value = 0x897, .expected_output = 20}, + + {.value = 0x1FFF, .expected_output = 19}, + {.value = 0x2222, .expected_output = 18}, + {.value = 0x7BAD, .expected_output = 17}, + {.value = 0xE708, .expected_output = 16}, + + {.value = 0x1DABD, .expected_output = 15}, + {.value = 0x29876, .expected_output = 14}, + {.value = 0x56665, .expected_output = 13}, + {.value = 0xABCDE, .expected_output = 12}, + + {.value = 0x18365F, .expected_output = 11}, + {.value = 0x3D0115, .expected_output = 10}, + {.value = 0x4B07EB, .expected_output = 9}, + {.value = 0xCCC74D, .expected_output = 8}, + + {.value = 0x17933ED, .expected_output = 7}, + {.value = 0x2B00071, .expected_output = 6}, + {.value = 0x4D4C1A5, .expected_output = 5}, + {.value = 0xAD01FFF, .expected_output = 4}, + + {.value = 0x1C5A8057, .expected_output = 3}, + {.value = 0x35AB23C3, .expected_output = 2}, + {.value = 0x7017013B, .expected_output = 1}, + {.value = 0xAD01EB15, .expected_output = 0}, + + {.value = 0xFFFFFFFF, .expected_output = 0}, + {.value = 0x80000000, .expected_output = 0}, + {.value = 0x7FFFFFFF, .expected_output = 1}, + {.value = 0x30000000, .expected_output = 2}, + {.value = 0x10000000, .expected_output = 3}, + {.value = 0x0FFFFFFF, .expected_output = 4}, + + {.value = 0xFF000000, .expected_output = 0}, + {.value = 0x00FF0000, .expected_output = 8}, + {.value = 0x0000FF00, .expected_output = 16}, + {.value = 0x000000FF, .expected_output = 24}, + + {.value = 0x8F000000, .expected_output = 0}, + {.value = 0x008F0000, .expected_output = 8}, + {.value = 0x00008F00, .expected_output = 16}, + {.value = 0x0000008F, .expected_output = 24}, + + {.value = 0x7F000000, .expected_output = 1}, + {.value = 0x007F0000, .expected_output = 9}, + {.value = 0x00007F00, .expected_output = 17}, + {.value = 0x0000007F, .expected_output = 25}, + + {.value = 0x3F000000, .expected_output = 2}, + {.value = 0x003F0000, .expected_output = 10}, + {.value = 0x00003F00, .expected_output = 18}, + {.value = 0x0000003F, .expected_output = 26}, + + {.value = 0x1F000000, .expected_output = 3}, + {.value = 0x001F0000, .expected_output = 11}, + {.value = 0x00001F00, .expected_output = 19}, + {.value = 0x0000001F, .expected_output = 27}, + + {.value = 0x0F000000, .expected_output = 4}, + {.value = 0x000F0000, .expected_output = 12}, + {.value = 0x00000F00, .expected_output = 20}, + {.value = 0x0000000F, .expected_output = 28}, + + {.value = 0x08000000, .expected_output = 4}, + {.value = 0x00080000, .expected_output = 12}, + {.value = 0x00000800, .expected_output = 20}, + {.value = 0x00000008, .expected_output = 28}, + + {.value = 0x07000000, .expected_output = 5}, + {.value = 0x00070000, .expected_output = 13}, + {.value = 0x00000700, .expected_output = 21}, + {.value = 0x00000007, .expected_output = 29}, + + {.value = 0x03000000, .expected_output = 6}, + {.value = 0x00030000, .expected_output = 14}, + {.value = 0x00000300, .expected_output = 22}, + {.value = 0x00000003, .expected_output = 30}, + + {.value = 0x01000000, .expected_output = 7}, + {.value = 0x00010000, .expected_output = 15}, + {.value = 0x00000100, .expected_output = 23}, + {.value = 0x00000001, .expected_output = 31}, }; void test_clzsi2_with_data(void **state) diff --git a/tests/lib/lzma-test.c b/tests/lib/lzma-test.c index 8ae9ceda1829..b68d38e122a8 100644 --- a/tests/lib/lzma-test.c +++ b/tests/lib/lzma-test.c @@ -51,12 +51,12 @@ static int setup_ulzman_file(void **state) if (!s) return 1; - const size_t raw_filename_size = strlen(path_prefix) + strlen(fname_base) - + ARRAY_SIZE(raw_file_suffix); + const size_t raw_filename_size = + strlen(path_prefix) + strlen(fname_base) + ARRAY_SIZE(raw_file_suffix); s->raw_filename = test_malloc(raw_filename_size); - const size_t comp_filename_size = strlen(path_prefix) + strlen(fname_base) - + ARRAY_SIZE(comp_file_suffix); + const size_t comp_filename_size = + strlen(path_prefix) + strlen(fname_base) + ARRAY_SIZE(comp_file_suffix); s->comp_filename = test_malloc(comp_filename_size); 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->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->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_int_equal(s->raw_file_sz, read_file(s->raw_filename, raw_buf, s->raw_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, - 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); test_free(raw_buf); @@ -148,13 +148,11 @@ static void test_ulzman_zero_buffer(void **state) } #define ULZMAN_CORRECT_FILE_TEST(_file_prefix) \ -{ \ - .name = "test_ulzman_correct_file(" _file_prefix ")", \ - .test_func = test_ulzman_correct_file, \ - .setup_func = setup_ulzman_file, \ - .teardown_func = teardown_ulzman_file, \ - .initial_state = (_file_prefix) \ -} + { \ + .name = "test_ulzman_correct_file(" _file_prefix ")", \ + .test_func = test_ulzman_correct_file, .setup_func = setup_ulzman_file, \ + .teardown_func = teardown_ulzman_file, .initial_state = (_file_prefix) \ + } int main(void) { diff --git a/tests/lib/memchr-test.c b/tests/lib/memchr-test.c index eadabc7c9d04..2575ce8b6502 100644 --- a/tests/lib/memchr-test.c +++ b/tests/lib/memchr-test.c @@ -5,42 +5,28 @@ #include static const char test_data1[] = - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; static const size_t test_data1_sz = sizeof(test_data1); static const char test_data2[] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, - 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, - 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, - 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 - }; + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, + 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, + 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, + 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, + 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, + 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, + 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, + 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, + 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 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 void test_memchr_existing_value(void **state) diff --git a/tests/lib/memcpy-test.c b/tests/lib/memcpy-test.c index f4f6e185a668..98303a49aa90 100644 --- a/tests/lib/memcpy-test.c +++ b/tests/lib/memcpy-test.c @@ -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 + offset, s->buffer_from, 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) @@ -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 + dst_offset, s->buffer_from + src_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) @@ -178,16 +178,16 @@ static void test_memcpy_copy_part_of_itself_to_itself(void **state) int main(void) { const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_memcpy_full_buffer_copy, - setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_memcpy_zero_size, - setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_memcpy_buffer_part, - setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_memcpy_buffer_part_unaligned, - setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_memcpy_copy_to_itself, - setup_test, teardown_test), + cmocka_unit_test_setup_teardown(test_memcpy_full_buffer_copy, setup_test, + teardown_test), + cmocka_unit_test_setup_teardown(test_memcpy_zero_size, setup_test, + teardown_test), + cmocka_unit_test_setup_teardown(test_memcpy_buffer_part, setup_test, + teardown_test), + cmocka_unit_test_setup_teardown(test_memcpy_buffer_part_unaligned, setup_test, + teardown_test), + cmocka_unit_test_setup_teardown(test_memcpy_copy_to_itself, setup_test, + teardown_test), cmocka_unit_test_setup_teardown(test_memcpy_copy_part_of_itself_to_itself, setup_test, teardown_test), }; diff --git a/tests/lib/memmove-test.c b/tests/lib/memmove-test.c index 87cace9c6ad9..3854dd65acab 100644 --- a/tests/lib/memmove-test.c +++ b/tests/lib/memmove-test.c @@ -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 + offset, s->buffer_from, 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) @@ -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 + dst_offset, s->buffer_from + src_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) @@ -225,26 +225,25 @@ static void test_memmove_self_lower_to_higher_unaligned(void **state) int main(void) { const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_memmove_full_buffer_copy, - setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_memmove_zero_size, - setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_memmove_buffer_part, - setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_memmove_buffer_part_unaligned, - setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_memmove_copy_to_itself, - setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_memmove_self_higher_to_lower, - setup_test, teardown_test), + cmocka_unit_test_setup_teardown(test_memmove_full_buffer_copy, setup_test, + teardown_test), + cmocka_unit_test_setup_teardown(test_memmove_zero_size, setup_test, + teardown_test), + cmocka_unit_test_setup_teardown(test_memmove_buffer_part, setup_test, + teardown_test), + cmocka_unit_test_setup_teardown(test_memmove_buffer_part_unaligned, setup_test, + teardown_test), + cmocka_unit_test_setup_teardown(test_memmove_copy_to_itself, setup_test, + teardown_test), + cmocka_unit_test_setup_teardown(test_memmove_self_higher_to_lower, setup_test, + teardown_test), cmocka_unit_test_setup_teardown(test_memmove_self_higher_to_lower_unaligned, setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_memmove_self_lower_to_higher, - setup_test, teardown_test), + cmocka_unit_test_setup_teardown(test_memmove_self_lower_to_higher, setup_test, + teardown_test), cmocka_unit_test_setup_teardown(test_memmove_self_lower_to_higher_unaligned, setup_test, teardown_test), }; return cb_run_group_tests(tests, NULL, NULL); } - diff --git a/tests/lib/memrange-test.c b/tests/lib/memrange-test.c index 1bdd62e028ff..25eb1aaaa44f 100644 --- a/tests/lib/memrange-test.c +++ b/tests/lib/memrange-test.c @@ -22,36 +22,54 @@ enum mem_types { /* Indices of entries matters, since it must reflect mem_types enum */ struct resource res_mock_1[] = { - [CACHEABLE_TAG] = { .base = 0xE000, .size = 0xF2000, - .next = &res_mock_1[RESERVED_TAG], .flags = IORESOURCE_CACHEABLE | IORESOURCE_MEM }, - [RESERVED_TAG] = { .base = 4ULL * GiB, .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 } + [CACHEABLE_TAG] = {.base = 0xE000, + .size = 0xF2000, + .next = &res_mock_1[RESERVED_TAG], + .flags = IORESOURCE_CACHEABLE | IORESOURCE_MEM}, + [RESERVED_TAG] = {.base = 4ULL * GiB, + .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. */ struct resource res_mock_2[] = { - [CACHEABLE_TAG] = { .base = 0x1000000, .size = 4ULL * GiB - 0x1000001ULL, - .next = &res_mock_2[RESERVED_TAG], .flags = IORESOURCE_CACHEABLE | IORESOURCE_MEM }, - [RESERVED_TAG] = { .base = 4ULL * GiB + 1ULL, .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} + [CACHEABLE_TAG] = {.base = 0x1000000, + .size = 4ULL * GiB - 0x1000001ULL, + .next = &res_mock_2[RESERVED_TAG], + .flags = IORESOURCE_CACHEABLE | IORESOURCE_MEM}, + [RESERVED_TAG] = {.base = 4ULL * GiB + 1ULL, + .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. */ struct resource res_mock_3[] = { - [CACHEABLE_TAG] = { .base = 0xD000, .size = 0xF3000, - .next = &res_mock_3[RESERVED_TAG], .flags = IORESOURCE_CACHEABLE | IORESOURCE_MEM }, - [RESERVED_TAG] = { .base = 1ULL * GiB, .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} + [CACHEABLE_TAG] = {.base = 0xD000, + .size = 0xF3000, + .next = &res_mock_3[RESERVED_TAG], + .flags = IORESOURCE_CACHEABLE | IORESOURCE_MEM}, + [RESERVED_TAG] = {.base = 1ULL * GiB, + .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 */ 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 end = res[range_entry_tag(entry)].base + - res[range_entry_tag(entry)].size + - (res[range_entry_tag(entry)].base - range_entry_base(entry)); + resource_t end = res[range_entry_tag(entry)].base + res[range_entry_tag(entry)].size + + (res[range_entry_tag(entry)].base - range_entry_base(entry)); 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 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_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 */ memranges_teardown(&test_memrange); - memranges_each_entry(ptr, &test_memrange) - counter++; + memranges_each_entry(ptr, &test_memrange) counter++; assert_int_equal(counter, 0); } @@ -205,7 +222,8 @@ static void test_memrange_clone_insert(void **state) memranges_teardown(&test_memrange); /* 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_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); /* 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; 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), 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; + expected_end = res_mock[CACHEABLE_TAG].base + new_range_begin_offset + + res_mock[CACHEABLE_TAG].size; assert_int_equal(range_entry_end(ptr), - ALIGN_UP(expected_end, MEMRANGE_ALIGN)); + ALIGN_UP(expected_end, MEMRANGE_ALIGN)); } counter++; } @@ -248,7 +267,8 @@ static void test_memrange_clone_insert(void **state) * Additionally verify API for updating tags */ 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; 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), 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; + expected_end = res_mock[CACHEABLE_TAG].base + new_range_begin_offset + + res_mock[CACHEABLE_TAG].size; 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, res_mock[RESERVED_TAG].size, INSERTED_TAG); - memranges_each_entry(ptr, &clone_memrange) { + memranges_each_entry(ptr, &clone_memrange) + { resource_t expected_end; assert_int_not_equal(range_entry_tag(ptr), RESERVED_TAG); if (range_entry_tag(ptr) == INSERTED_TAG) { - assert_int_equal(range_entry_base(ptr), - ALIGN_DOWN(res_mock[RESERVED_TAG].base, - MEMRANGE_ALIGN)); + assert_int_equal( + range_entry_base(ptr), + 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; + expected_end = ALIGN_DOWN(res_mock[RESERVED_TAG].base, MEMRANGE_ALIGN) + + new_range_begin_offset + res_mock[RESERVED_TAG].size; expected_end = ALIGN_UP(expected_end, MEMRANGE_ALIGN); 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); /* Count holes in ranges */ - memranges_each_entry(ptr, &test_memrange) { + memranges_each_entry(ptr, &test_memrange) + { if (!last_range_end) { last_range_end = range_entry_end(ptr); continue; @@ -349,12 +371,13 @@ static void test_memrange_holes(void **state) (but with different tags) */ 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) { assert_int_equal(range_entry_base(ptr), - ALIGN_UP(res_mock[CACHEABLE_TAG].base + - res_mock[CACHEABLE_TAG].size, - MEMRANGE_ALIGN)); + ALIGN_UP(res_mock[CACHEABLE_TAG].base + + res_mock[CACHEABLE_TAG].size, + MEMRANGE_ALIGN)); assert_int_equal(range_entry_end(ptr), holes_fill_end); /* Store pointer to HOLE_TAG region for future use */ hole_ptr = ptr; @@ -372,15 +395,16 @@ static void test_memrange_holes(void **state) /* Create hole crossing the border of two range entries */ const resource_t new_cacheable_end = ALIGN_DOWN( - res_mock[CACHEABLE_TAG].base + res_mock[CACHEABLE_TAG].size - 4 * KiB, - MEMRANGE_ALIGN); - const resource_t new_hole_begin = ALIGN_UP(range_entry_base(hole_ptr) + 4 * KiB, - MEMRANGE_ALIGN); + res_mock[CACHEABLE_TAG].base + res_mock[CACHEABLE_TAG].size - 4 * KiB, + MEMRANGE_ALIGN); + const resource_t new_hole_begin = + ALIGN_UP(range_entry_base(hole_ptr) + 4 * KiB, MEMRANGE_ALIGN); const resource_t ranges_diff = new_hole_begin - new_cacheable_end; 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)) { case CACHEABLE_TAG: assert_int_equal(range_entry_base(ptr), res_mock[CACHEABLE_TAG].base); @@ -388,8 +412,9 @@ static void test_memrange_holes(void **state) break; case RESERVED_TAG: assert_int_equal(range_entry_base(ptr), res_mock[RESERVED_TAG].base); - assert_int_equal(range_entry_end(ptr), res_mock[RESERVED_TAG].base + - res_mock[RESERVED_TAG].size); + assert_int_equal(range_entry_end(ptr), + res_mock[RESERVED_TAG].base + + res_mock[RESERVED_TAG].size); break; case HOLE_TAG: 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, readonly, readonly, READONLY_TAG); - status = memranges_steal(&test_memrange, res_mock[RESERVED_TAG].base + - res_mock[RESERVED_TAG].size, + status = memranges_steal(&test_memrange, + res_mock[RESERVED_TAG].base + res_mock[RESERVED_TAG].size, stolen_range_size, 12, READONLY_TAG, &stolen); assert_true(status); - assert_in_range(stolen, res_mock[READONLY_TAG].base, res_mock[READONLY_TAG].base + - res_mock[READONLY_TAG].size); + assert_in_range(stolen, res_mock[READONLY_TAG].base, + 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) { assert_int_equal(range_entry_base(ptr), - ALIGN_DOWN(res_mock[READONLY_TAG].base, MEMRANGE_ALIGN) - + stolen_range_size); + ALIGN_DOWN(res_mock[READONLY_TAG].base, MEMRANGE_ALIGN) + + stolen_range_size); } count++; } @@ -468,16 +494,17 @@ static void test_memrange_steal(void **state) /* Check if inserting range in previously stolen area will merge it. */ memranges_insert(&test_memrange, res_mock[READONLY_TAG].base + 0xCC, stolen_range_size, - READONLY_TAG); - memranges_each_entry(ptr, &test_memrange) { + READONLY_TAG); + memranges_each_entry(ptr, &test_memrange) + { if (range_entry_tag(ptr) == READONLY_TAG) { - assert_int_equal(range_entry_base(ptr), - ALIGN_DOWN(res_mock[READONLY_TAG].base, - MEMRANGE_ALIGN)); - assert_int_equal(range_entry_end(ptr), - ALIGN_UP(range_entry_base(ptr) + - res_mock[READONLY_TAG].size, - MEMRANGE_ALIGN)); + assert_int_equal( + range_entry_base(ptr), + ALIGN_DOWN(res_mock[READONLY_TAG].base, MEMRANGE_ALIGN)); + assert_int_equal( + range_entry_end(ptr), + ALIGN_UP(range_entry_base(ptr) + res_mock[READONLY_TAG].size, + MEMRANGE_ALIGN)); } 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 */ 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; 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_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 readonly = IORESOURCE_READONLY; struct memranges test_memrange; - struct range_entry range_entries[4] = { 0 }; + struct range_entry range_entries[4] = {0}; /* Test memranges_init() correctness */ 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) */ - memranges_init_with_alignment(&test_memrange, cacheable, cacheable, - CACHEABLE_TAG, 10); + memranges_init_with_alignment(&test_memrange, cacheable, cacheable, CACHEABLE_TAG, 10); memranges_add_resources(&test_memrange, reserved, reserved, RESERVED_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) */ 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)); 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 */ memranges_init(&test_memrange, reserved, reserved, RESERVED_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. */ - 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_true(IS_ALIGNED(range_entry_base(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 */ memranges_init(&test_memrange, reserved, reserved, RESERVED_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); @@ -629,10 +657,10 @@ int main(void) cmocka_unit_test(test_memrange_add_resources_filter), }; - return cmocka_run_group_tests_name(__TEST_NAME__"(Boundary on 4GiB)", - tests, setup_test_1, NULL) + - cmocka_run_group_tests_name(__TEST_NAME__"(Boundaries 1 byte from 4GiB)", - tests, setup_test_2, NULL) + - cmocka_run_group_tests_name(__TEST_NAME__"(Range over 4GiB boundary)", - tests, setup_test_3, NULL); + return cmocka_run_group_tests_name(__TEST_NAME__ "(Boundary on 4GiB)", tests, + setup_test_1, NULL) + + cmocka_run_group_tests_name(__TEST_NAME__ "(Boundaries 1 byte from 4GiB)", + tests, setup_test_2, NULL) + + cmocka_run_group_tests_name(__TEST_NAME__ "(Range over 4GiB boundary)", tests, + setup_test_3, NULL); } diff --git a/tests/lib/memset-test.c b/tests/lib/memset-test.c index bdc3cb310418..b0be91f4772b 100644 --- a/tests/lib/memset-test.c +++ b/tests/lib/memset-test.c @@ -106,14 +106,14 @@ static void test_memset_one_byte(void **state) int main(void) { const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(test_memset_full_range, - setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_memset_subrange, - setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_memset_zero_size, - setup_test, teardown_test), - cmocka_unit_test_setup_teardown(test_memset_one_byte, - setup_test, teardown_test), + cmocka_unit_test_setup_teardown(test_memset_full_range, setup_test, + teardown_test), + cmocka_unit_test_setup_teardown(test_memset_subrange, setup_test, + teardown_test), + cmocka_unit_test_setup_teardown(test_memset_zero_size, setup_test, + teardown_test), + cmocka_unit_test_setup_teardown(test_memset_one_byte, setup_test, + teardown_test), }; return cb_run_group_tests(tests, NULL, NULL); diff --git a/tests/lib/region_file-test.c b/tests/lib/region_file-test.c index 98c4eb650b0f..56bb8e4f019c 100644 --- a/tests/lib/region_file-test.c +++ b/tests/lib/region_file-test.c @@ -243,12 +243,12 @@ static void test_region_file_update_data_arr(void **state) for (int i = 0; i < dummy_data_size; ++i) dummy_data[i] = 'A' + i % ('Z' - 'A'); - update_entries[0] = (struct update_region_file_entry) - { .size = data1_size, .data = &dummy_data[data1_offset] }; - update_entries[1] = (struct update_region_file_entry) - { .size = data2_size, .data = &dummy_data[data2_offset] }; - update_entries[2] = (struct update_region_file_entry) - { .size = data3_size, .data = &dummy_data[data3_offset] }; + update_entries[0] = (struct update_region_file_entry){ + .size = data1_size, .data = &dummy_data[data1_offset]}; + update_entries[1] = (struct update_region_file_entry){ + .size = data2_size, .data = &dummy_data[data2_offset]}; + update_entries[2] = (struct update_region_file_entry){ + .size = data3_size, .data = &dummy_data[data3_offset]}; ret = region_file_init(®f, rdev); 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); 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[data2_offset], - &output_buffer[data1_size], data2_size); - assert_memory_equal(&dummy_data[data3_offset], - &output_buffer[data1_size + data2_size], data3_size); + assert_memory_equal(&dummy_data[data2_offset], &output_buffer[data1_size], data2_size); + assert_memory_equal(&dummy_data[data3_offset], &output_buffer[data1_size + data2_size], + data3_size); /* Check if data is correctly shrunk down to smaller size and different content */ ret = region_file_update_data_arr(®f, &update_entries[1], 2); @@ -294,35 +293,35 @@ int main(void) { const struct CMUnitTest tests[] = { 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, - 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, - 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, - 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, - 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, - 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, - 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, - 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, - 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, - 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, diff --git a/tests/lib/rtc-test.c b/tests/lib/rtc-test.c index e9415714a524..c3c7403a4bb4 100644 --- a/tests/lib/rtc-test.c +++ b/tests/lib/rtc-test.c @@ -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 */ 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_rtc_time_equal(&tm_in, &tm_out); 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_rtc_time_equal(&tm_in, &tm_out); 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_rtc_time_equal(&tm_in, &tm_out); 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_rtc_time_equal(&tm_in, &tm_out); 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_rtc_time_equal(&tm_in, &tm_out); 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_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)); /* Non-leap year */ - tm_in = (struct rtc_time) { - .year = 1999, .mon = 2, .mday = 28, .hour = 5, .min = 37, .sec = 15, .wday = 0 + tm_in = (struct rtc_time){ + .year = 1999, .mon = 2, .mday = 28, .hour = 5, .min = 37, .sec = 15, .wday = 0, }; tim = rtc_mktime(&tm_in) + secday; - tm_expected = (struct rtc_time) { - .year = 1999, .mon = 3, .mday = 1, .hour = 5, .min = 37, .sec = 15, .wday = 1 + tm_expected = (struct rtc_time){ + .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_rtc_time_equal(&tm_out, &tm_expected); /* 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, }; 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, }; assert_int_equal(0, rtc_to_tm(tim, &tm_out)); 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, }; 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, }; assert_int_equal(0, rtc_to_tm(tim, &tm_out)); assert_rtc_time_equal(&tm_out, &tm_expected); /* 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, }; 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, }; assert_int_equal(0, rtc_to_tm(tim, &tm_out)); 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, }; 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, }; assert_int_equal(0, rtc_to_tm(tim, &tm_out)); diff --git a/tests/lib/spd_cache-test.c b/tests/lib/spd_cache-test.c index 4f75690979a0..e1c1777bc694 100644 --- a/tests/lib/spd_cache-test.c +++ b/tests/lib/spd_cache-test.c @@ -62,12 +62,10 @@ static void test_load_spd_cache(void **state) static void calc_spd_cache_crc(uint8_t *spd_cache) { - *(uint16_t *)(spd_cache + SC_CRC_OFFSET) = - CRC(spd_cache, SC_SPD_TOTAL_LEN, crc16_byte); + *(uint16_t *)(spd_cache + SC_CRC_OFFSET) = CRC(spd_cache, SC_SPD_TOTAL_LEN, crc16_byte); } -__attribute__((unused)) -static void fill_spd_cache_ddr3(uint8_t *spd_cache, size_t spd_cache_sz) +__attribute__((unused)) 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))); @@ -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); } -__attribute__((unused)) -static void fill_spd_cache_ddr4(uint8_t *spd_cache, size_t spd_cache_sz) +__attribute__((unused)) static void fill_spd_cache_ddr4(uint8_t *spd_cache, size_t spd_cache_sz) { - assert_true(spd_cache_sz >= - (spd_data_ddr4_1_sz + spd_data_ddr4_2_sz + sizeof(uint16_t))); + assert_true(spd_cache_sz + >= (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_sz, spd_data_ddr4_2, spd_data_ddr4_2_sz); 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); } @@ -127,7 +124,7 @@ static void test_spd_cache_is_valid(void **state) /* 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; /* Implementation for testing purposes. */ 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 */ -__attribute__((unused)) -static void test_check_if_dimm_changed_not_changed(void **state) +__attribute__((unused)) static void test_check_if_dimm_changed_not_changed(void **state) { uint8_t *spd_cache; 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)); 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)); } -__attribute__((unused)) -static void test_check_if_dimm_changed_sn_error(void **state) +__attribute__((unused)) static void test_check_if_dimm_changed_sn_error(void **state) { uint8_t *spd_cache; 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)); 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)); } -__attribute__((unused)) -static void test_check_if_dimm_changed_sodimm_lost(void **state) +__attribute__((unused)) static void test_check_if_dimm_changed_sodimm_lost(void **state) { uint8_t *spd_cache; 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)); 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)); } -__attribute__((unused)) -static void test_check_if_dimm_changed_new_sodimm(void **state) +__attribute__((unused)) static void test_check_if_dimm_changed_new_sodimm(void **state) { uint8_t *spd_cache; 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)); fill_spd_cache_ddr4(spd_cache, spd_cache_sz); assert_int_equal(CB_SUCCESS, spd_fill_from_cache(spd_cache, &blk)); 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, - spd_data_ddr4_2, 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_sz); get_spd_sn_ret_sn_idx = 0; will_return_always(get_spd_sn, CB_SUCCESS); assert_true(check_if_dimm_changed(spd_cache, &blk)); } -__attribute__((unused)) -static void test_check_if_dimm_changed_sn_changed(void **state) +__attribute__((unused)) static void test_check_if_dimm_changed_sn_changed(void **state) { uint8_t *spd_cache; 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)); 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), #if __TEST_SPD_CACHE_DDR == 4 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, - setup_spd_cache_test), + setup_spd_cache_test), 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, - setup_spd_cache_test), + setup_spd_cache_test), cmocka_unit_test_setup(test_check_if_dimm_changed_sn_changed, - setup_spd_cache_test), + setup_spd_cache_test), #endif }; diff --git a/tests/lib/stack-test.c b/tests/lib/stack-test.c index 1f671f39cb47..583fe4954f2a 100644 --- a/tests/lib/stack-test.c +++ b/tests/lib/stack-test.c @@ -6,9 +6,9 @@ #if CONFIG_STACK_SIZE == 0 -# define STACK_SIZE 0x1000 +#define STACK_SIZE 0x1000 #else -# define STACK_SIZE CONFIG_STACK_SIZE +#define STACK_SIZE CONFIG_STACK_SIZE #endif /* Value used for stack initialization. Change if implementation changes. */ diff --git a/tests/lib/timestamp-test.c b/tests/lib/timestamp-test.c index ad33ed08c00e..06a5a001424d 100644 --- a/tests/lib/timestamp-test.c +++ b/tests/lib/timestamp-test.c @@ -32,7 +32,7 @@ void test_timestamp_add(void **state) entry = &glob_ts_table->entries[0]; assert_int_equal(1, entry->entry_id); 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 */ for (i = 1; i < 10; ++i) @@ -43,8 +43,7 @@ void test_timestamp_add(void **state) for (i = 0; i < 10; ++i) { entry = &glob_ts_table->entries[i]; assert_int_equal(i + 1, entry->entry_id); - assert_int_equal(base_multipler * (i + 1) - timestamp_base, - entry->entry_stamp); + assert_int_equal(base_multipler * (i + 1) - timestamp_base, entry->entry_stamp); } } @@ -70,7 +69,7 @@ void test_timestamp_add_now(void **state) assert_int_equal(1, entry->entry_id); 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) diff --git a/tests/mock/cbfs_file_mock.c b/tests/mock/cbfs_file_mock.c index 2be89b06b339..09e23e2a7d86 100644 --- a/tests/mock/cbfs_file_mock.c +++ b/tests/mock/cbfs_file_mock.c @@ -4,14 +4,14 @@ TEST_REGION(cbfs_cache, TEST_CBFS_CACHE_SIZE); -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_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_3[TEST_DATA_INT_3_SIZE] = { LE64(TEST_DATA_INT_3) }; +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_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_3[TEST_DATA_INT_3_SIZE] = {LE64(TEST_DATA_INT_3)}; -const u8 good_hash[VB2_SHA256_DIGEST_SIZE] = { TEST_SHA256 }; -const u8 bad_hash[VB2_SHA256_DIGEST_SIZE] = { INVALID_SHA256 }; +const u8 good_hash[VB2_SHA256_DIGEST_SIZE] = {TEST_SHA256}; +const u8 bad_hash[VB2_SHA256_DIGEST_SIZE] = {INVALID_SHA256}; const struct cbfs_test_file file_no_hash = { .header = HEADER_INITIALIZER(CBFS_TYPE_RAW, 0, TEST_DATA_1_SIZE), -- cgit v1.2.3