tech-toolchain archive

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

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



Looks good, but please remember to update distribution sets and register
new directory in src/etc/mtree/.

On 03.03.2020 15:03, Michał Górny wrote:
> ---
>  tests/lib/libc/Makefile        |  4 +-
>  tests/lib/libc/nls/Makefile    |  9 ++++
>  tests/lib/libc/nls/t_catalog.c | 97 ++++++++++++++++++++++++++++++++++
>  3 files changed, 108 insertions(+), 2 deletions(-)
>  create mode 100644 tests/lib/libc/nls/Makefile
>  create mode 100644 tests/lib/libc/nls/t_catalog.c
> 
> 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();
> +}
> +
> 


Attachment: signature.asc
Description: OpenPGP digital signature



Home | Main Index | Thread Index | Old Index