BUG=none TEST=Build and verify on Screebo TEST=make unit-tests ``` $ make tests/commonlib/bsd/string-test [==========] tests_commonlib_bsd_string-test(tests): Running 1 test(s). [ RUN ] test_skip_atoi [ OK ] test_skip_atoi [==========] tests_commonlib_bsd_string-test(tests): 1 test(s) run. [ PASSED ] 1 test(s). ``` Change-Id: Ifaaa80d0c696a625592ce301f9e3eefb2b4dcd98 Signed-off-by: Maximilian Brune <maximilian.brune@9elements.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/82910 Reviewed-by: Jakub Czapiga <czapiga@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Subrata Banik <subratabanik@google.com>
		
			
				
	
	
		
			39 lines
		
	
	
		
			730 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			730 B
		
	
	
	
		
			C
		
	
	
	
	
	
| /* SPDX-License-Identifier: GPL-2.0-only */
 | |
| 
 | |
| #include <commonlib/bsd/string.h>
 | |
| #include <tests/test.h>
 | |
| 
 | |
| /* Used to test skip_atoi */
 | |
| struct str_with_u_val_t {
 | |
| 	char *str;
 | |
| 	uint32_t value;
 | |
| 	uint32_t offset;
 | |
| } str_with_u_val[] = {
 | |
| 	{"42aa", 42, 2},
 | |
| 	{"a", 0, 0},
 | |
| 	{"0", 0, 1},
 | |
| 	{"4a2", 4, 1},
 | |
| };
 | |
| 
 | |
| static void test_skip_atoi(void **state)
 | |
| {
 | |
| 	int i;
 | |
| 	char *ptr, *copy;
 | |
| 
 | |
| 	for (i = 0; i < ARRAY_SIZE(str_with_u_val); i++) {
 | |
| 		ptr = str_with_u_val[i].str;
 | |
| 		copy = ptr;
 | |
| 		assert_true(str_with_u_val[i].value == skip_atoi(&ptr));
 | |
| 		assert_int_equal(str_with_u_val[i].offset, ptr - copy);
 | |
| 	}
 | |
| }
 | |
| 
 | |
| int main(void)
 | |
| {
 | |
| 	const struct CMUnitTest tests[] = {
 | |
| 		cmocka_unit_test(test_skip_atoi),
 | |
| 	};
 | |
| 
 | |
| 	return cb_run_group_tests(tests, NULL, NULL);
 | |
| }
 |