7c6081e02b
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>
73 lines
2 KiB
C
73 lines
2 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
/* Include memcmp() source code and alter its name to compare results with libc memcmp() */
|
|
#define memcmp cb_memcmp
|
|
|
|
#include "../lib/memcmp.c"
|
|
|
|
#undef cb_memcmp
|
|
|
|
#include <tests/test.h>
|
|
#include <string.h>
|
|
|
|
const char test_data1[] = "TEST_DATA @4321 !@#$%^&*\\/";
|
|
const size_t test_data1_sz = sizeof(test_data1);
|
|
|
|
const char test_data2[] = "TEST_DATA @8765 !@#$%^&*\\/";
|
|
const char test_data2_sz = sizeof(test_data2);
|
|
|
|
static void test_data_correctness(void **state)
|
|
{
|
|
assert_int_equal(sizeof(test_data1), test_data1_sz);
|
|
assert_int_equal(sizeof(test_data2), test_data2_sz);
|
|
assert_int_equal(test_data1_sz, test_data2_sz);
|
|
}
|
|
|
|
static void test_memcmp_equal(void **state)
|
|
{
|
|
const int res_cb = cb_memcmp(test_data1, test_data1, test_data1_sz);
|
|
const int res_std = memcmp(test_data1, test_data1, test_data1_sz);
|
|
|
|
assert_int_equal(0, res_cb);
|
|
assert_int_equal(res_cb, res_std);
|
|
}
|
|
|
|
static void test_memcmp_first_not_matching_lower(void **state)
|
|
{
|
|
const int res_cb = cb_memcmp(test_data1, test_data2, test_data1_sz);
|
|
const int res_std = memcmp(test_data1, test_data2, test_data1_sz);
|
|
|
|
assert_true(res_cb < 0);
|
|
assert_int_equal(res_cb, res_std);
|
|
}
|
|
|
|
static void test_memcmp_first_not_matching_higher(void **state)
|
|
{
|
|
const int res_cb = cb_memcmp(test_data2, test_data1, test_data1_sz);
|
|
const int res_std = memcmp(test_data2, test_data1, test_data1_sz);
|
|
|
|
assert_true(res_cb > 0);
|
|
assert_int_equal(res_cb, res_std);
|
|
}
|
|
|
|
static void test_memcmp_zero_size(void **state)
|
|
{
|
|
const int res_cb = cb_memcmp(test_data1, test_data2, 0);
|
|
const int res_std = memcmp(test_data1, test_data2, 0);
|
|
|
|
assert_int_equal(0, res_cb);
|
|
assert_int_equal(res_cb, res_std);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
const struct CMUnitTest tests[] = {
|
|
cmocka_unit_test(test_data_correctness),
|
|
cmocka_unit_test(test_memcmp_equal),
|
|
cmocka_unit_test(test_memcmp_first_not_matching_lower),
|
|
cmocka_unit_test(test_memcmp_first_not_matching_higher),
|
|
cmocka_unit_test(test_memcmp_zero_size),
|
|
};
|
|
|
|
return cb_run_group_tests(tests, NULL, NULL);
|
|
}
|