From 01590227f2281c106008ad923bb4cdc5d4249fd5 Mon Sep 17 00:00:00 2001 From: Eric Lai Date: Fri, 15 Apr 2022 11:20:38 +0800 Subject: test/lib: Add non-existent DIMMs test case in spd_cache-test Add non-existent DIMMs test case in spd_cache-test. BUG=b:213964936 TEST=make unit-tests PASSED Signed-off-by: Eric Lai Change-Id: I3c8aa92ee0cfd5908399f4bbd305f8f306571d40 Reviewed-on: https://review.coreboot.org/c/coreboot/+/63643 Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel Reviewed-by: Tim Wawrzynczak Reviewed-by: Jakub Czapiga --- tests/lib/spd_cache-test.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests') diff --git a/tests/lib/spd_cache-test.c b/tests/lib/spd_cache-test.c index 48f06e3883..b949d1b297 100644 --- a/tests/lib/spd_cache-test.c +++ b/tests/lib/spd_cache-test.c @@ -230,6 +230,25 @@ __attribute__((unused)) static void test_check_if_dimm_changed_sn_changed(void * assert_true(check_if_dimm_changed(spd_cache, &blk)); } +__attribute__((unused)) static void test_check_if_dimm_changed_with_nonexistent(void **state) +{ + uint8_t *spd_cache; + size_t spd_cache_sz; + struct spd_block blk = {.addr_map = {0x50, 0, 0, 0}, + .spd_array = {0}, .len = 0}; + + assert_int_equal(CB_SUCCESS, load_spd_cache(&spd_cache, &spd_cache_sz)); + memcpy(spd_cache, spd_data_ddr4_1, spd_data_ddr4_1_sz); + memset(spd_cache + spd_data_ddr4_1_sz, 0xff, spd_cache_sz - spd_data_ddr4_1_sz); + calc_spd_cache_crc(spd_cache); + assert_int_equal(CB_SUCCESS, spd_fill_from_cache(spd_cache, &blk)); + + get_sn_from_spd_cache(spd_cache, get_spd_sn_ret_sn); + get_spd_sn_ret_sn_idx = 0; + will_return_always(get_spd_sn, CB_SUCCESS); + assert_false(check_if_dimm_changed(spd_cache, &blk)); +} + int main(void) { const struct CMUnitTest tests[] = { @@ -247,6 +266,8 @@ int main(void) setup_spd_cache_test), cmocka_unit_test_setup(test_check_if_dimm_changed_sn_changed, setup_spd_cache_test), + cmocka_unit_test_setup(test_check_if_dimm_changed_with_nonexistent, + setup_spd_cache_test), #endif }; -- cgit v1.2.3