From 30ff6afe596eddafacf22b1a5b2d1a3d6254ea15 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 15:14:44 +0200 Subject: Adding upstream version 2.36.1. Signed-off-by: Daniel Baumann --- tests/helpers/Makemodule.am | 33 +++++++ tests/helpers/test_byteswap.c | 114 +++++++++++++++++++++++ tests/helpers/test_mbsencode.c | 52 +++++++++++ tests/helpers/test_md5.c | 29 ++++++ tests/helpers/test_pathnames.c | 86 +++++++++++++++++ tests/helpers/test_sha1.c | 29 ++++++ tests/helpers/test_sigreceive.c | 181 ++++++++++++++++++++++++++++++++++++ tests/helpers/test_strerror.c | 44 +++++++++ tests/helpers/test_sysinfo.c | 129 +++++++++++++++++++++++++ tests/helpers/test_tiocsti.c | 32 +++++++ tests/helpers/test_uuid_namespace.c | 37 ++++++++ 11 files changed, 766 insertions(+) create mode 100644 tests/helpers/Makemodule.am create mode 100644 tests/helpers/test_byteswap.c create mode 100644 tests/helpers/test_mbsencode.c create mode 100644 tests/helpers/test_md5.c create mode 100644 tests/helpers/test_pathnames.c create mode 100644 tests/helpers/test_sha1.c create mode 100644 tests/helpers/test_sigreceive.c create mode 100644 tests/helpers/test_strerror.c create mode 100644 tests/helpers/test_sysinfo.c create mode 100644 tests/helpers/test_tiocsti.c create mode 100644 tests/helpers/test_uuid_namespace.c (limited to 'tests/helpers') diff --git a/tests/helpers/Makemodule.am b/tests/helpers/Makemodule.am new file mode 100644 index 0000000..a34cd8d --- /dev/null +++ b/tests/helpers/Makemodule.am @@ -0,0 +1,33 @@ +check_PROGRAMS += test_mbsencode +test_mbsencode_SOURCES = tests/helpers/test_mbsencode.c +test_mbsencode_LDADD = $(LDADD) libcommon.la + +check_PROGRAMS += test_byteswap +test_byteswap_SOURCES = tests/helpers/test_byteswap.c + +check_PROGRAMS += test_md5 +test_md5_SOURCES = tests/helpers/test_md5.c lib/md5.c + +check_PROGRAMS += test_sha1 +test_sha1_SOURCES = tests/helpers/test_sha1.c lib/sha1.c + +check_PROGRAMS += test_pathnames +test_pathnames_SOURCES = tests/helpers/test_pathnames.c + +check_PROGRAMS += test_strerror +test_strerror_SOURCES = tests/helpers/test_strerror.c + +check_PROGRAMS += test_sysinfo +test_sysinfo_SOURCES = tests/helpers/test_sysinfo.c + +check_PROGRAMS += test_sigreceive +test_sigreceive_SOURCES = tests/helpers/test_sigreceive.c +test_sigreceive_LDADD = $(LDADD) libcommon.la + +check_PROGRAMS += test_tiocsti +test_tiocsti_SOURCES = tests/helpers/test_tiocsti.c + +check_PROGRAMS += test_uuid_namespace +test_uuid_namespace_SOURCES = tests/helpers/test_uuid_namespace.c \ + libuuid/src/predefined.c libuuid/src/unpack.c libuuid/src/unparse.c + diff --git a/tests/helpers/test_byteswap.c b/tests/helpers/test_byteswap.c new file mode 100644 index 0000000..1b98f76 --- /dev/null +++ b/tests/helpers/test_byteswap.c @@ -0,0 +1,114 @@ +/* + * This testing program makes sure the byteswap functions work + * + * Copyright (C) 2000 by Theodore Ts'o. + * Copyright (C) 2008 Karel Zak + * + * This file may be redistributed under the terms of the GNU Public + * License. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "bitops.h" + +static uint16_t ary16[] = { + 0x0001, 0x0100, + 0x1234, 0x3412, + 0xff00, 0x00ff, + 0x4000, 0x0040, + 0xfeff, 0xfffe, + 0x0000, 0x0000 + }; + +static uint32_t ary32[] = { + 0x00000001, 0x01000000, + 0x80000000, 0x00000080, + 0x12345678, 0x78563412, + 0xffff0000, 0x0000ffff, + 0x00ff0000, 0x0000ff00, + 0xff000000, 0x000000ff, + 0x00000000, 0x00000000 + }; + +static uint64_t ary64[] = { + 0x0000000000000001, 0x0100000000000000, + 0x8000000000000000, 0x0000000000000080, + 0x1234567812345678, 0x7856341278563412, + 0xffffffff00000000, 0x00000000ffffffff, + 0x00ff000000000000, 0x000000000000ff00, + 0xff00000000000000, 0x00000000000000ff, + 0x0000000000000000, 0x0000000000000000 + }; + +int main(void) +{ + int i; + int errors = 0; + + printf("Testing swab16\n"); + i=0; + do { + printf("swab16(0x%04"PRIx16") = 0x%04"PRIx16"\n", + ary16[i], swab16(ary16[i])); + if (swab16(ary16[i]) != ary16[i+1]) { + printf("Error!!! %04"PRIx16" != %04"PRIx16"\n", + swab16(ary16[i]), ary16[i+1]); + errors++; + } + if (swab16(ary16[i+1]) != ary16[i]) { + printf("Error!!! %04"PRIx16" != %04"PRIx16"\n", + swab16(ary16[i+1]), ary16[i]); + errors++; + } + i += 2; + } while (ary16[i] != 0); + + printf("Testing swab32\n"); + i = 0; + do { + printf("swab32(0x%08"PRIx32") = 0x%08"PRIx32"\n", + ary32[i], swab32(ary32[i])); + if (swab32(ary32[i]) != ary32[i+1]) { + printf("Error!!! %04"PRIx32" != %04"PRIx32"\n", + swab32(ary32[i]), ary32[i+1]); + errors++; + } + if (swab32(ary32[i+1]) != ary32[i]) { + printf("Error!!! %04"PRIx32" != %04"PRIx32"\n", + swab32(ary32[i+1]), ary32[i]); + errors++; + } + i += 2; + } while (ary32[i] != 0); + + printf("Testing swab64\n"); + i = 0; + do { + printf("swab64(0x%016"PRIx64") = 0x%016"PRIx64"\n", + ary64[i], swab64(ary64[i])); + if (swab64(ary64[i]) != ary64[i+1]) { + printf("Error!!! %016"PRIx64" != %016"PRIx64"\n", + swab64(ary64[i]), ary64[i+1]); + errors++; + } + if (swab64(ary64[i+1]) != ary64[i]) { + printf("Error!!! %016"PRIx64" != %016"PRIx64"\n", + swab64(ary64[i+1]), ary64[i]); + errors++; + } + i += 2; + } while (ary64[i] != 0); + + if (!errors) + printf("No errors found in the byteswap implementation\n"); + + return errors; +} diff --git a/tests/helpers/test_mbsencode.c b/tests/helpers/test_mbsencode.c new file mode 100644 index 0000000..a8f9383 --- /dev/null +++ b/tests/helpers/test_mbsencode.c @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2018 Vaclav Dolezal + * + * This file is part of util-linux. + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include + +#include "mbsalign.h" + +int main(int argc, char **argv) +{ + int i = 1; + char *(*encode_fn)(const char *, size_t *) = mbs_safe_encode; + + setlocale(LC_ALL, ""); + + if (i < argc) { + if (!strcmp(argv[i], "--safe")) { + i++; + encode_fn = mbs_safe_encode; + } else if (!strcmp(argv[i], "--invalid")) { + i++; + encode_fn = mbs_invalid_encode; + } else if (!strcmp(argv[i], "--")) { + i++; + } + } + + for (; i < argc; i++) { + size_t width; + char *res; + res = encode_fn(argv[i], &width); + printf("%zi %s\n", width, res); + free(res); + } + + return 0; +} diff --git a/tests/helpers/test_md5.c b/tests/helpers/test_md5.c new file mode 100644 index 0000000..6f8dec4 --- /dev/null +++ b/tests/helpers/test_md5.c @@ -0,0 +1,29 @@ + +#include +#include + +#include "md5.h" + +int main(void) +{ + int i, ret; + struct UL_MD5Context ctx; + unsigned char digest[UL_MD5LENGTH]; + unsigned char buf[BUFSIZ]; + + ul_MD5Init( &ctx ); + + while(!feof(stdin) && !ferror(stdin)) { + ret = fread(buf, 1, sizeof(buf), stdin); + if (ret) + ul_MD5Update( &ctx, buf, ret ); + } + + fclose(stdin); + ul_MD5Final( digest, &ctx ); + + for (i = 0; i < UL_MD5LENGTH; i++) + printf( "%02x", digest[i] ); + printf("\n"); + return 0; +} diff --git a/tests/helpers/test_pathnames.c b/tests/helpers/test_pathnames.c new file mode 100644 index 0000000..2368641 --- /dev/null +++ b/tests/helpers/test_pathnames.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2007 Karel Zak + * + * This file is part of util-linux. + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include + +#include "pathnames.h" + +struct hlpPath +{ + const char *name; + const char *path; +}; + +#define DEF_HLPPATH(_p) { #_p, _p } + +static struct hlpPath paths[] = +{ + DEF_HLPPATH(_PATH_DEFPATH), + DEF_HLPPATH(_PATH_DEFPATH_ROOT), + DEF_HLPPATH(_PATH_DEV_LOOP), + DEF_HLPPATH(_PATH_HUSHLOGIN), + DEF_HLPPATH(_PATH_MAILDIR), + DEF_HLPPATH(_PATH_MOTDFILE), + DEF_HLPPATH(_PATH_NOLOGIN), + DEF_HLPPATH(_PATH_LOGIN), + DEF_HLPPATH(_PATH_PASSWD), + DEF_HLPPATH(_PATH_GSHADOW), + DEF_HLPPATH(_PATH_GROUP), + DEF_HLPPATH(_PATH_SHADOW_PASSWD), + DEF_HLPPATH(_PATH_WORDS), + DEF_HLPPATH(_PATH_WORDS_ALT), + DEF_HLPPATH(_PATH_FILESYSTEMS), + DEF_HLPPATH(_PATH_PROC_SWAPS), + DEF_HLPPATH(_PATH_PROC_FILESYSTEMS), + DEF_HLPPATH(_PATH_MOUNTED), + DEF_HLPPATH(_PATH_MNTTAB), + DEF_HLPPATH(_PATH_DEV_BYLABEL), + DEF_HLPPATH(_PATH_DEV_BYUUID), + { NULL, NULL } +}; + +int +main(int argc, char **argv) +{ + struct hlpPath *p; + + if (argc == 1) { + for (p = paths; p->name; p++) + printf("%20s %s\n", p->name, p->path); + exit(EXIT_SUCCESS); + } else { + if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0) { + printf("%s