summaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
authorPeter Jones <pjones@redhat.com>2021-02-14 14:50:44 -0500
committerPeter Jones <pjones@redhat.com>2021-02-25 10:15:14 -0500
commit9ca8e9a633501c3ec3c95d2576b795eee8d9b1cc (patch)
tree00bb38ceba093b70cb1f54a85dac69c4e3de7532 /test.c
parent73322ba087d10d06b0656816bf4b7ba80b02c751 (diff)
downloadefi-boot-shim-9ca8e9a633501c3ec3c95d2576b795eee8d9b1cc.tar.gz
efi-boot-shim-9ca8e9a633501c3ec3c95d2576b795eee8d9b1cc.zip
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 <pjones@redhat.com>
Diffstat (limited to 'test.c')
-rw-r--r--test.c63
1 files changed, 63 insertions, 0 deletions
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 <pjones@redhat.com>
+ */
+
+#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