[U-Boot] [PATCH 2/2] test: provide test for errno_str()

Heinrich Schuchardt xypron.glpk at gmx.de
Sun Oct 6 12:33:39 UTC 2019


Provide a unit test for errno_str(). Test that known and unknown error
numbers are handled correctly.

Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---
 test/lib/Makefile         |  1 +
 test/lib/test_errno_str.c | 50 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)
 create mode 100644 test/lib/test_errno_str.c

diff --git a/test/lib/Makefile b/test/lib/Makefile
index 308c61708e..b13aaca7ce 100644
--- a/test/lib/Makefile
+++ b/test/lib/Makefile
@@ -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
index 0000000000..77072d04f9
--- /dev/null
+++ b/test/lib/test_errno_str.c
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2019 Heinrich Schuchardt <xypron.glpk at 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>
+
+static const char errno_str_ok[] = "Success";
+static const char errno_str_enomem[] = "Out of memory";
+static const char errno_str_unknown[] = "Unknown error";
+
+/**
+ * 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(errno_str_ok, msg);
+
+	msg = errno_str(0);
+	ut_asserteq_str(errno_str_ok, msg);
+
+	msg = errno_str(-ENOMEM);
+	ut_asserteq_str(errno_str_enomem, msg);
+
+	msg = errno_str(-99999);
+	ut_asserteq_str(errno_str_unknown, msg);
+
+	return 0;
+}
+
+LIB_TEST(lib_errno_str, 0);
--
2.23.0



More information about the U-Boot mailing list