test: provide test for errno_str()
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Tue, 15 Oct 2019 19:46:04 +0000 (21:46 +0200)
committerTom Rini <trini@konsulko.com>
Thu, 31 Oct 2019 11:22:53 +0000 (07:22 -0400)
Provide a unit test for errno_str(). Test that known and unknown error
numbers are handled correctly.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
test/lib/Makefile
test/lib/test_errno_str.c [new file with mode: 0644]

index 308c61708ee3d38abf9d25241d6f0ba9a8337205..b13aaca7ce541fe8bbf33b1eec3a81c575acfa82 100644 (file)
@@ -6,3 +6,4 @@ obj-y += cmd_ut_lib.o
 obj-y += hexdump.o
 obj-y += lmb.o
 obj-y += string.o
+obj-$(CONFIG_ERRNO_STR) += test_errno_str.o
diff --git a/test/lib/test_errno_str.c b/test/lib/test_errno_str.c
new file mode 100644 (file)
index 0000000..8a9f1fd
--- /dev/null
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2019 Heinrich Schuchardt <xypron.glpk@gmx.de>
+ *
+ * Unit tests for memory functions
+ *
+ * The architecture dependent implementations run through different lines of
+ * code depending on the alignment and length of memory regions copied or set.
+ * This has to be considered in testing.
+ */
+
+#include <common.h>
+#include <command.h>
+#include <errno.h>
+#include <test/lib.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+/**
+ * lib_errno_str() - unit test for errno_str()
+ *
+ * Test errno_str() with varied alignment and length of the copied buffer.
+ *
+ * @uts:       unit test state
+ * Return:     0 = success, 1 = failure
+ */
+static int lib_errno_str(struct unit_test_state *uts)
+{
+       const char *msg;
+
+       msg = errno_str(1);
+       ut_asserteq_str("Success", msg);
+
+       msg = errno_str(0);
+       ut_asserteq_str("Success", msg);
+
+       msg = errno_str(-ENOMEM);
+       ut_asserteq_str("Out of memory", msg);
+
+       msg = errno_str(-99999);
+       ut_asserteq_str("Unknown error", msg);
+
+       return 0;
+}
+
+LIB_TEST(lib_errno_str, 0);