mirror of
				https://review.coreboot.org/flashrom.git
				synced 2025-11-04 07:00:39 +01:00 
			
		
		
		
	libflashrom: Add new layout_compare() function with test
Add a new layout_compare() function which will be used in a subsequent
patch to test equality between two layouts. Add a test function for
layout_compare(). Fix a small bug in compare_region_with_dump() which
was introduced in commit 74a1a54892 ("libflashrom: Fix comparison of
layout romentry regions"), which was discovered with the new test.
Change-Id: Ib37556bb83d4e1c26545a90b49128f1f78ffe2c6
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/89629
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
			
			
This commit is contained in:
		
				
					committed by
					
						
						Anastasia Klimchuk
					
				
			
			
				
	
			
			
			
						parent
						
							8e0bfee62f
						
					
				
				
					commit
					b0b975d0ea
				
			@@ -163,3 +163,60 @@ void probe_v2_error_code_propagation(void **state)
 | 
			
		||||
#else
 | 
			
		||||
	SKIP_TEST(probe_v2_error_code_propagation)
 | 
			
		||||
#endif /* CONFIG_DUMMY */
 | 
			
		||||
 | 
			
		||||
void flashrom_layout_compare_test_success(void **state)
 | 
			
		||||
{
 | 
			
		||||
	(void)state; /* unused */
 | 
			
		||||
	struct flashrom_layout *layout1 = NULL;
 | 
			
		||||
	struct flashrom_layout *layout2 = NULL;
 | 
			
		||||
	struct flashrom_layout *layout3 = NULL;
 | 
			
		||||
 | 
			
		||||
	/* Create three layouts */
 | 
			
		||||
	assert_int_equal(0, flashrom_layout_new(&layout1));
 | 
			
		||||
	assert_int_equal(0, flashrom_layout_new(&layout2));
 | 
			
		||||
	assert_int_equal(0, flashrom_layout_new(&layout3));
 | 
			
		||||
 | 
			
		||||
	/* Test 1: NULL pointer handling */
 | 
			
		||||
	assert_int_not_equal(0, flashrom_layout_compare(NULL, layout1));
 | 
			
		||||
	assert_int_not_equal(0, flashrom_layout_compare(layout1, NULL));
 | 
			
		||||
	assert_int_not_equal(0, flashrom_layout_compare(NULL, NULL));
 | 
			
		||||
 | 
			
		||||
	/* Test 2: Empty layouts should match */
 | 
			
		||||
	assert_int_equal(0, flashrom_layout_compare(layout1, layout2));
 | 
			
		||||
 | 
			
		||||
	/* Test 3: Add same regions to layout1 and layout2 */
 | 
			
		||||
	assert_int_equal(0, flashrom_layout_add_region(layout1, 0x00000000, 0x000fffff, "REGION1"));
 | 
			
		||||
	assert_int_equal(0, flashrom_layout_add_region(layout1, 0x00100000, 0x001fffff, "REGION2"));
 | 
			
		||||
 | 
			
		||||
	assert_int_equal(0, flashrom_layout_add_region(layout2, 0x00000000, 0x000fffff, "REGION1"));
 | 
			
		||||
	assert_int_equal(0, flashrom_layout_add_region(layout2, 0x00100000, 0x001fffff, "REGION2"));
 | 
			
		||||
 | 
			
		||||
	/* Identical layouts should match */
 | 
			
		||||
	assert_int_equal(0, flashrom_layout_compare(layout1, layout2));
 | 
			
		||||
 | 
			
		||||
	/* Test 4: Add different region to layout3 */
 | 
			
		||||
	assert_int_equal(0, flashrom_layout_add_region(layout3, 0x00000000, 0x000fffff, "REGION1"));
 | 
			
		||||
	assert_int_equal(0, flashrom_layout_add_region(layout3, 0x00100000, 0x002fffff, "REGION2")); /* different end */
 | 
			
		||||
 | 
			
		||||
	/* Different layouts should not match */
 | 
			
		||||
	assert_int_not_equal(0, flashrom_layout_compare(layout1, layout3));
 | 
			
		||||
 | 
			
		||||
	/* Test 5: Different number of regions */
 | 
			
		||||
	flashrom_layout_release(layout3);
 | 
			
		||||
	assert_int_equal(0, flashrom_layout_new(&layout3));
 | 
			
		||||
	assert_int_equal(0, flashrom_layout_add_region(layout3, 0x00000000, 0x000fffff, "REGION1"));
 | 
			
		||||
	/* layout3 has only 1 region, layout1 has 2 */
 | 
			
		||||
	assert_int_not_equal(0, flashrom_layout_compare(layout1, layout3));
 | 
			
		||||
 | 
			
		||||
	/* Test 6: Same regions but different names */
 | 
			
		||||
	flashrom_layout_release(layout3);
 | 
			
		||||
	assert_int_equal(0, flashrom_layout_new(&layout3));
 | 
			
		||||
	assert_int_equal(0, flashrom_layout_add_region(layout3, 0x00000000, 0x000fffff, "DIFFERENT_NAME"));
 | 
			
		||||
	assert_int_equal(0, flashrom_layout_add_region(layout3, 0x00100000, 0x001fffff, "REGION2"));
 | 
			
		||||
	assert_int_not_equal(0, flashrom_layout_compare(layout1, layout3));
 | 
			
		||||
 | 
			
		||||
	/* Cleanup */
 | 
			
		||||
	flashrom_layout_release(layout1);
 | 
			
		||||
	flashrom_layout_release(layout2);
 | 
			
		||||
	flashrom_layout_release(layout3);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -476,6 +476,7 @@ int main(int argc, char *argv[])
 | 
			
		||||
		cmocka_unit_test(flashrom_set_log_level_test_success),
 | 
			
		||||
		cmocka_unit_test(flashrom_supported_programmers_test_success),
 | 
			
		||||
		cmocka_unit_test(probe_v2_error_code_propagation),
 | 
			
		||||
		cmocka_unit_test(flashrom_layout_compare_test_success),
 | 
			
		||||
	};
 | 
			
		||||
	ret |= cmocka_run_group_tests_name("libflashrom.c tests", libflashrom_tests, NULL, NULL);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -29,6 +29,7 @@ void flashrom_set_log_callback_v2_test_success(void **state);
 | 
			
		||||
void flashrom_set_log_level_test_success(void **state);
 | 
			
		||||
void flashrom_supported_programmers_test_success(void **state);
 | 
			
		||||
void probe_v2_error_code_propagation(void **state);
 | 
			
		||||
void flashrom_layout_compare_test_success(void **state);
 | 
			
		||||
 | 
			
		||||
/* spi25.c */
 | 
			
		||||
void spi_write_enable_test_success(void **state);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user