tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[PATCH 3/7] Add tests for missing libc catalog entries



---
 distrib/sets/lists/debug/mi    |  1 +
 distrib/sets/lists/tests/mi    |  5 ++
 etc/mtree/NetBSD.dist.tests    |  2 +
 tests/lib/libc/Makefile        |  4 +-
 tests/lib/libc/nls/Makefile    |  9 ++++
 tests/lib/libc/nls/t_catalog.c | 97 ++++++++++++++++++++++++++++++++++
 6 files changed, 116 insertions(+), 2 deletions(-)
 create mode 100644 tests/lib/libc/nls/Makefile
 create mode 100644 tests/lib/libc/nls/t_catalog.c

diff --git a/distrib/sets/lists/debug/mi b/distrib/sets/lists/debug/mi
index 9de65ff60eb8..5f8307e680d5 100644
--- a/distrib/sets/lists/debug/mi
+++ b/distrib/sets/lists/debug/mi
@@ -2027,6 +2027,7 @@
 ./usr/libdata/debug/usr/tests/lib/libc/net/t_ether_aton.debug		tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/net/t_getprotoent.debug		tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/net/t_if_nametoindex.debug	tests-lib-debug		debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/lib/libc/nls/t_catalog.debug		tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/regex/h_regex.debug		tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/regex/h_regex_att.debug		tests-obsolete		obsolete,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/regex/t_exhaust.debug		tests-lib-debug		debug,atf,compattestfile
diff --git a/distrib/sets/lists/tests/mi b/distrib/sets/lists/tests/mi
index 0df21c0d7cf1..4d2d631f7a71 100644
--- a/distrib/sets/lists/tests/mi
+++ b/distrib/sets/lists/tests/mi
@@ -107,6 +107,7 @@
 ./usr/libdata/debug/usr/tests/lib/libc/misc				tests-lib-debug		compattestfile,atf
 ./usr/libdata/debug/usr/tests/lib/libc/net				tests-lib-debug		compattestfile,atf
 ./usr/libdata/debug/usr/tests/lib/libc/net/getaddrinfo			tests-lib-debug		compattestfile,atf
+./usr/libdata/debug/usr/tests/lib/libc/nls				tests-lib-debug		compattestfile,atf
 ./usr/libdata/debug/usr/tests/lib/libc/regex				tests-lib-debug		compattestfile,atf
 ./usr/libdata/debug/usr/tests/lib/libc/rpc				tests-lib-debug		compattestfile,atf
 ./usr/libdata/debug/usr/tests/lib/libc/setjmp				tests-lib-debug		compattestfile,atf
@@ -2965,6 +2966,10 @@
 ./usr/tests/lib/libc/net/t_nsdispatch		tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libc/net/t_protoent		tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libc/net/t_servent		tests-lib-tests		compattestfile,atf
+./usr/tests/lib/libc/nls			tests-lib-tests	compattestfile,atf
+./usr/tests/lib/libc/nls/Atffile		tests-lib-tests		compattestfile,atf
+./usr/tests/lib/libc/nls/Kyuafile		tests-lib-tests		compattestfile,atf,kyua
+./usr/tests/lib/libc/nls/t_catalog		tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libc/regex			tests-lib-tests	compattestfile,atf
 ./usr/tests/lib/libc/regex/Atffile		tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libc/regex/Kyuafile		tests-lib-tests		compattestfile,atf,kyua
diff --git a/etc/mtree/NetBSD.dist.tests b/etc/mtree/NetBSD.dist.tests
index bf46f3d370ca..d14eddaae30f 100644
--- a/etc/mtree/NetBSD.dist.tests
+++ b/etc/mtree/NetBSD.dist.tests
@@ -88,6 +88,7 @@
 ./usr/libdata/debug/usr/tests/lib/libc/misc
 ./usr/libdata/debug/usr/tests/lib/libc/net
 ./usr/libdata/debug/usr/tests/lib/libc/net/getaddrinfo
+./usr/libdata/debug/usr/tests/lib/libc/nls
 ./usr/libdata/debug/usr/tests/lib/libc/regex
 ./usr/libdata/debug/usr/tests/lib/libc/rpc
 ./usr/libdata/debug/usr/tests/lib/libc/setjmp
@@ -278,6 +279,7 @@
 ./usr/tests/lib/libc/net
 ./usr/tests/lib/libc/net/getaddrinfo
 ./usr/tests/lib/libc/net/getaddrinfo/data
+./usr/tests/lib/libc/nls
 ./usr/tests/lib/libc/regex
 ./usr/tests/lib/libc/regex/data
 ./usr/tests/lib/libc/rpc
diff --git a/tests/lib/libc/Makefile b/tests/lib/libc/Makefile
index ab4f43b4a4e8..9a9e2b3a61dc 100644
--- a/tests/lib/libc/Makefile
+++ b/tests/lib/libc/Makefile
@@ -6,8 +6,8 @@
 SUBDIR+=	tls_dso .WAIT sync
 
 TESTS_SUBDIRS+=	atomic
-TESTS_SUBDIRS+=	c063 db gen hash inet locale misc net regex rpc setjmp stdlib
-TESTS_SUBDIRS+=	stdio string sys termios time tls ttyio
+TESTS_SUBDIRS+=	c063 db gen hash inet locale misc net nls regex rpc setjmp
+TESTS_SUBDIRS+=	stdlib stdio string sys termios time tls ttyio
 
 .if ${HAVE_SSP} == "yes"
 TESTS_SUBDIRS+=	ssp
diff --git a/tests/lib/libc/nls/Makefile b/tests/lib/libc/nls/Makefile
new file mode 100644
index 000000000000..698952abd2e0
--- /dev/null
+++ b/tests/lib/libc/nls/Makefile
@@ -0,0 +1,9 @@
+# $NetBSD$
+
+.include <bsd.own.mk>
+
+TESTSDIR=	${TESTSBASE}/lib/libc/nls
+
+TESTS_C+=	t_catalog
+
+.include <bsd.test.mk>
diff --git a/tests/lib/libc/nls/t_catalog.c b/tests/lib/libc/nls/t_catalog.c
new file mode 100644
index 000000000000..5e4a1dc151ba
--- /dev/null
+++ b/tests/lib/libc/nls/t_catalog.c
@@ -0,0 +1,97 @@
+/* $NetBSD$ */
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD$");
+
+#include <atf-c.h>
+#include <errno.h>
+#include <stdio.h>	/* Needed for sys_nerr on FreeBSD */
+#include <limits.h>
+#include <locale.h>
+#include <nl_types.h>
+#include <signal.h>
+#include <string.h>
+
+ATF_TC(catalog_errno);
+ATF_TC_HEAD(catalog_errno, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test whether C catalog covers all "
+	    "errno values");
+}
+
+ATF_TC_BODY(catalog_errno, tc)
+{
+	int i;
+	nl_catd catd = catopen("libc", NL_CAT_LOCALE);
+	ATF_REQUIRE(catd);
+
+	for (i = 1; i < sys_nerr; i++) {
+		const char *strerr = sys_errlist[i];
+		const char *caterr = catgets(catd, 1, i, "");
+		ATF_CHECK_MSG(!strcmp(strerr, caterr),
+		    "Catalog message mismatch for errno=%d (sys_errlist: '%s', "
+		    "catalog: '%s')\n", i, strerr, caterr);
+	}
+
+	catclose(catd);
+}
+
+ATF_TC(catalog_signal);
+ATF_TC_HEAD(catalog_signal, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test whether C catalog covers all "
+	    "signal values");
+}
+
+ATF_TC_BODY(catalog_signal, tc)
+{
+	int i;
+	nl_catd catd = catopen("libc", NL_CAT_LOCALE);
+	ATF_REQUIRE(catd);
+
+	for (i = 1; i < SIGRTMIN-1; i++) {
+		const char *strerr = sys_siglist[i];
+		const char *caterr = catgets(catd, 2, i, "");
+		ATF_CHECK_MSG(!strcmp(strerr, caterr),
+		    "Catalog message mismatch for signal=%d (sys_siglist: '%s', "
+		    "catalog: '%s')\n", i, strerr, caterr);
+	}
+
+	catclose(catd);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+	(void)setlocale(LC_ALL, "C");
+
+	ATF_TP_ADD_TC(tp, catalog_errno);
+	ATF_TP_ADD_TC(tp, catalog_signal);
+
+	return atf_no_error();
+}
+
-- 
2.25.1



Home | Main Index | Thread Index | Old Index