soc/amd/sabrina,vc/amd/fsp/sabrina: Add UART support for Sabrina
[coreboot.git] / tests / lib / memcmp-test.c
blob59ca86c0cb3b37667f45b5f366ef11667d2c37b4
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 /* Include memcmp() source code and alter its name to compare results with libc memcmp() */
4 #define memcmp cb_memcmp
6 #include "../lib/memcmp.c"
8 #undef cb_memcmp
10 #include <tests/test.h>
11 #include <string.h>
13 const char test_data1[] = "TEST_DATA @4321 !@#$%^&*\\/";
14 const size_t test_data1_sz = sizeof(test_data1);
16 const char test_data2[] = "TEST_DATA @8765 !@#$%^&*\\/";
17 const char test_data2_sz = sizeof(test_data2);
19 static void test_data_correctness(void **state)
21 assert_int_equal(sizeof(test_data1), test_data1_sz);
22 assert_int_equal(sizeof(test_data2), test_data2_sz);
23 assert_int_equal(test_data1_sz, test_data2_sz);
26 static void test_memcmp_equal(void **state)
28 const int res_cb = cb_memcmp(test_data1, test_data1, test_data1_sz);
29 const int res_std = memcmp(test_data1, test_data1, test_data1_sz);
31 assert_int_equal(0, res_cb);
32 assert_int_equal(res_cb, res_std);
35 static void test_memcmp_first_not_matching_lower(void **state)
37 const int res_cb = cb_memcmp(test_data1, test_data2, test_data1_sz);
38 const int res_std = memcmp(test_data1, test_data2, test_data1_sz);
40 assert_true(res_cb < 0);
41 assert_int_equal(res_cb, res_std);
44 static void test_memcmp_first_not_matching_higher(void **state)
46 const int res_cb = cb_memcmp(test_data2, test_data1, test_data1_sz);
47 const int res_std = memcmp(test_data2, test_data1, test_data1_sz);
49 assert_true(res_cb > 0);
50 assert_int_equal(res_cb, res_std);
53 static void test_memcmp_zero_size(void **state)
55 const int res_cb = cb_memcmp(test_data1, test_data2, 0);
56 const int res_std = memcmp(test_data1, test_data2, 0);
58 assert_int_equal(0, res_cb);
59 assert_int_equal(res_cb, res_std);
62 int main(void)
64 const struct CMUnitTest tests[] = {
65 cmocka_unit_test(test_data_correctness),
66 cmocka_unit_test(test_memcmp_equal),
67 cmocka_unit_test(test_memcmp_first_not_matching_lower),
68 cmocka_unit_test(test_memcmp_first_not_matching_higher),
69 cmocka_unit_test(test_memcmp_zero_size),
72 return cb_run_group_tests(tests, NULL, NULL);