From 9ca8e9a633501c3ec3c95d2576b795eee8d9b1cc Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Sun, 14 Feb 2021 14:50:44 -0500 Subject: make 'make test' able to run unit test harnesses This adds a couple of make targets to do unit tests that are linked to libc: test-FOO : builds and runs test-FOO for any test-FOO.c test : builds and runs all test-FOO tests Note that building and running this test does not quite work yet /on this branch/. In order to do that, we need some cleanups and reorganizing that I don't want to push just yet, which can be found on https://github.com/rhboot/shim/tree/test-reorg Signed-off-by: Peter Jones --- test.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 test.c (limited to 'test.c') diff --git a/test.c b/test.c new file mode 100644 index 00000000..b21e2191 --- /dev/null +++ b/test.c @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: BSD-2-Clause-Patent +/* + * test.c - stuff we need for test harnesses + * Copyright Peter Jones + */ + +#ifndef SHIM_UNIT_TEST +#define SHIM_UNIT_TEST +#endif +#include "shim.h" + +UINT8 in_protocol = 0; +int debug = DEFAULT_DEBUG_PRINT_STATE; + +EFI_STATUS LogError_(const char *file, int line, const char *func, const CHAR16 *fmt, ...) +{ + assert(0); + return EFI_SUCCESS; +} + +INTN +StrCmp(CONST CHAR16 *s1, CONST CHAR16 *s2) { + assert(s1 != NULL); + assert(s2 != NULL); + + int i; + for (i = 0; s1[i] && s2[i]; i++) { + if (s1[i] != s2[i]) + return s2[i] - s1[i]; + } + return 0; +} + +INTN +StrnCmp(CONST CHAR16 *s1, CONST CHAR16 *s2, UINTN len) { + assert(s1 != NULL); + assert(s2 != NULL); + + UINTN i; + for (i = 0; i < len && s1[i] && s2[i]; i++) { + if (s1[i] != s2[i]) + return s2[i] - s1[i]; + + } + return 0; +} + +EFI_STATUS +get_variable_attr(const CHAR16 * const var, UINT8 **data, UINTN *len, + EFI_GUID owner, UINT32 *attributes) +{ + return EFI_UNSUPPORTED; +} + +EFI_STATUS +get_variable(const CHAR16 * const var, UINT8 **data, UINTN *len, EFI_GUID owner) +{ + return get_variable_attr(var, data, len, owner, NULL); +} + +EFI_GUID SHIM_LOCK_GUID = {0x605dab50, 0xe046, 0x4300, {0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23 } }; + +// vim:fenc=utf-8:tw=75:noet -- cgit v1.2.3