tests: Fix tests code and comments style

This patch applies clang-format settings to most of tests files. Some
files were fixed "by-hand" to exclude some lines, which whould be less
readable after automatic style fixing.
Moreover, some comments (mostly in tests/lib/edid-test.c) were adjusted
to match coreboot coding style guidelines.

Change-Id: I69f25a7b6d8265800c731754e2fbb2255f482134
Signed-off-by: Jakub Czapiga <jacz@semihalf.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/60970
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
This commit is contained in:
Jakub Czapiga
2022-01-10 13:36:47 +00:00
committed by Felix Held
parent 63ec2ac97a
commit c08b6a7037
31 changed files with 1225 additions and 1228 deletions

View File

@@ -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)

View File

@@ -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(&current_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);

View File

@@ -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);

View File

@@ -7,12 +7,9 @@
#include <ip_checksum.h>
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);

View File

@@ -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),
};

View File

@@ -4,38 +4,25 @@
#include <crc_byte.h>
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)

View File

@@ -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,

File diff suppressed because it is too large Load Diff

View File

@@ -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);

View File

@@ -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)

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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)

View File

@@ -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)
{

View File

@@ -5,42 +5,28 @@
#include <string.h>
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)

View File

@@ -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),
};

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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(&regf, 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(&regf, &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,

View File

@@ -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));

View File

@@ -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
};

View File

@@ -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. */

View File

@@ -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)