When running multiple tests, e.g. by using unit-tests target, it is hard to differentiate, which output comes from which file and/or configuration. This patch makes the output easier to analyze and understand by using new wrapper macro cb_run_group_tests(). This macro uses __TEST_NAME__ value (containing test path and Makefile test name) as a group name when calling cmocka group runner. Example: Test path: tests/lib/ Makefile test name: cbmem_stage_cache-test Test group array name: tests Result: tests/lib/cbmem_stage_cache-test(tests) Signed-off-by: Jakub Czapiga <jacz@semihalf.com> Change-Id: I4fd936d00d77cbe2637b857ba03b4a208428ea0d Reviewed-on: https://review.coreboot.org/c/coreboot/+/57144 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
		
			
				
	
	
		
			96 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			96 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /* SPDX-License-Identifier: GPL-2.0-only */
 | |
| 
 | |
| #include <tests/test.h>
 | |
| #include <uuid.h>
 | |
| 
 | |
| /* This test checks if parse_uuid() correctly parses UUID strings with correct format.
 | |
|    lib/uuid does not check UUID version nor variant.
 | |
|    If that changes tests should be updated as appropriate. */
 | |
| static void test_parse_uuid_correct(void **state)
 | |
| {
 | |
| 	/* lib/uuid does not check UUID version nor variant.
 | |
| 	   If that changes tests should be updated as appropriate. */
 | |
| 	uint8_t uuid_buf[UUID_LEN] = { 0 };
 | |
| 	const char *uuid_correct = "00112233-4455-6677-8899-aabbccddeeff";
 | |
| 	const uint8_t uuid_correct_bin[UUID_LEN] = {
 | |
| 		0x33, 0x22, 0x11, 0x00, 0x55, 0x44, 0x77, 0x66,
 | |
| 		0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
 | |
| 	};
 | |
| 	const char *uuid_zereos = "00000000-0000-0000-0000-000000000000";
 | |
| 	const uint8_t uuid_zeros_bin[UUID_LEN] = { 0 };
 | |
| 	const char *uuid_ff = "ffffffff-ffff-ffff-ffff-ffffffffffff";
 | |
| 	const uint8_t uuid_ff_bin[UUID_LEN] = {
 | |
| 		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
 | |
| 		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
 | |
| 	};
 | |
| 
 | |
| 	assert_int_equal(0, parse_uuid(uuid_buf, uuid_correct));
 | |
| 	assert_memory_equal(uuid_correct_bin, uuid_buf, UUID_LEN);
 | |
| 
 | |
| 	assert_int_equal(0, parse_uuid(uuid_buf, uuid_zereos));
 | |
| 	assert_memory_equal(uuid_zeros_bin, uuid_buf, UUID_LEN);
 | |
| 
 | |
| 	assert_int_equal(0, parse_uuid(uuid_buf, uuid_ff));
 | |
| 	assert_memory_equal(uuid_ff_bin, uuid_buf, UUID_LEN);
 | |
| }
 | |
| 
 | |
| /* This test validates parse_uuid() feeding it with incorrectly-formatted UUID strings.
 | |
|    No version/variant tests are performed due to lack of handling these properties
 | |
|    by lib/uuid. If that changes tests should be updated as appropriate.*/
 | |
| static void test_parse_uuid_incorrect(void **state)
 | |
| {
 | |
| 	uint8_t uuid_buf[UUID_LEN] = { 0 };
 | |
| 	/* First separator at incorrect index */
 | |
| 	const char *uuid_incorrect_1 = "ab372d0-34cc1-1337-688b-2211337777ee";
 | |
| 	/* Incorrect characters */
 | |
| 	const char *uuid_incorrect_2 = "abbce711-5@51-7777-ffff-ahchbh999911";
 | |
| 	/* Too long uuid string */
 | |
| 	const char *uuid_incorrect_3 = "a7a38502-7465-9cbd-98ea-73003906dad5dd";
 | |
| 	/* Too short uuid string */
 | |
| 	const char *uuid_incorrect_4 = "72abd839-7109-64bd-cfef-a8266";
 | |
| 
 | |
| 	assert_int_equal(-1, parse_uuid(uuid_buf, uuid_incorrect_1));
 | |
| 	assert_int_equal(-1, parse_uuid(uuid_buf, uuid_incorrect_2));
 | |
| 	assert_int_equal(-1, parse_uuid(uuid_buf, uuid_incorrect_3));
 | |
| 	assert_int_equal(-1, parse_uuid(uuid_buf, uuid_incorrect_4));
 | |
| }
 | |
| 
 | |
| static void test_guid(void **state)
 | |
| {
 | |
| 	guid_t guid = GUID_INIT(0x1F4D66BB, 0xDEAD, 0xBEEF,
 | |
| 				0x08, 0xAB, 0x21, 0x37, 0xBB, 0x07, 0xDD, 0x4C);
 | |
| 	guid_t guid_copy;
 | |
| 	const guid_t guid_bin = { {
 | |
| 			0xBB, 0x66, 0x4D, 0x1F,
 | |
| 			0xAD, 0xDE,
 | |
| 			0xEF, 0xBE,
 | |
| 			0x08, 0xAB, 0x21, 0x37, 0xBB, 0x07, 0xDD, 0x4C
 | |
| 	} };
 | |
| 
 | |
| 	/* GUID produced using GUID_INIT() macro should be identical to guid_bin
 | |
| 	   Check it by comparing memory directly and using provided comparison function */
 | |
| 	assert_memory_equal(guid.b, guid_bin.b, UUID_LEN);
 | |
| 	assert_int_equal(0, guidcmp(&guid, &guid_bin));
 | |
| 
 | |
| 	/* Copy GUID and compare it with original */
 | |
| 	guidcpy(&guid_copy, &guid);
 | |
| 	assert_memory_equal(guid.b, guid_copy.b, UUID_LEN);
 | |
| 	assert_int_equal(0, guidcmp(&guid, &guid_copy));
 | |
| 
 | |
| 	/* Binary negate bits of one of GUIDs bytes.
 | |
| 	   Expect comparison to fail as GUIDs should differ */
 | |
| 	guid_copy.b[7] = ~guid_copy.b[7];
 | |
| 	assert_int_not_equal(0, guidcmp(&guid, &guid_copy));
 | |
| }
 | |
| 
 | |
| int main(void)
 | |
| {
 | |
| 	const struct CMUnitTest tests[] = {
 | |
| 		cmocka_unit_test(test_parse_uuid_correct),
 | |
| 		cmocka_unit_test(test_parse_uuid_incorrect),
 | |
| 		cmocka_unit_test(test_guid),
 | |
| 	};
 | |
| 
 | |
| 	return cb_run_group_tests(tests, NULL, NULL);
 | |
| }
 |