coreboot-kgpe-d16/tests/lib/string-test.c
Patrick Georgi 6b5bc77c9b treewide: Remove "this file is part of" lines
Stefan thinks they don't add value.

Command used:
sed -i -e '/file is part of /d' $(git grep "file is part of " |egrep ":( */\*.*\*/\$|#|;#|-- | *\* )" | cut -d: -f1 |grep -v crossgcc |grep -v gcov | grep -v /elf.h |grep -v nvramtool)

The exceptions are for:
 - crossgcc (patch file)
 - gcov (imported from gcc)
 - elf.h (imported from GNU's libc)
 - nvramtool (more complicated header)

The removed lines are:
-       fmt.Fprintln(f, "/* This file is part of the coreboot project. */")
-# This file is part of a set of unofficial pre-commit hooks available
-/* This file is part of coreboot */
-# This file is part of msrtool.
-/* This file is part of msrtool. */
- * This file is part of ncurses, designed to be appended after curses.h.in
-/* This file is part of pgtblgen. */
- * This file is part of the coreboot project.
- /* This file is part of the coreboot project. */
-#  This file is part of the coreboot project.
-# This file is part of the coreboot project.
-## This file is part of the coreboot project.
--- This file is part of the coreboot project.
-/* This file is part of the coreboot project */
-/* This file is part of the coreboot project. */
-;## This file is part of the coreboot project.
-# This file is part of the coreboot project. It originated in the
- * This file is part of the coreinfo project.
-## This file is part of the coreinfo project.
- * This file is part of the depthcharge project.
-/* This file is part of the depthcharge project. */
-/* This file is part of the ectool project. */
- * This file is part of the GNU C Library.
- * This file is part of the libpayload project.
-## This file is part of the libpayload project.
-/* This file is part of the Linux kernel. */
-## This file is part of the superiotool project.
-/* This file is part of the superiotool project */
-/* This file is part of uio_usbdebug */

Change-Id: I82d872b3b337388c93d5f5bf704e9ee9e53ab3a9
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/41194
Reviewed-by: HAOUAS Elyes <ehaouas@noos.fr>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2020-05-11 17:11:40 +00:00

55 lines
1.3 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <string.h>
/*
* Important note: In every particular test, don't use any string-related
* functions other than function under test. We are linking against
* src/lib/string.c not the standard library. This is important for proper test
* isolation. One can use __builtin_xxx for many of the most simple str*()
* functions, when non-coreboot one is required.
*/
struct strings_t {
char *str;
size_t size;
} strings[] = {
{"coreboot", 8},
{"is\0very", 2}, /* strlen should be 2 because of the embedded \0 */
{"nice\n", 5}
};
static void test_strlen_strings(void **state)
{
int i;
for (i = 0; i < ARRAY_SIZE(strings); i++)
assert_int_equal(strings[i].size, strlen(strings[i].str));
}
static void test_strdup(void **state)
{
char str[] = "Hello coreboot\n";
char *duplicate;
duplicate = strdup(str);
/* There is a more suitable Cmocka's function 'assert_string_equal()', but it
is using strcmp() internally. */
assert_int_equal(0, memcmp(str, duplicate, __builtin_strlen(str)));
}
int main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_strlen_strings),
cmocka_unit_test(test_strdup),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}