[PATCH] localedef: Add tests-container test for --no-hard-links.
DJ Delorie
dj@redhat.com
Tue Apr 28 18:28:08 GMT 2020
"Carlos O'Donell" <carlos@redhat.com> writes:
> OK for master?
Minor comments about comments but functionally OK.
Reviewed-by: DJ Delorie <dj@redhat.com>
> +tests-container = \
> + tst-localedef-hardlinks
New test, ok.
> +/* Test --no-hard-links option to localedef.
> + Copyright (C) 2018 Free Software Foundation, Inc.
2018 ?
> + <http://www.gnu.org/licenses/>. */
https
> +/* Each test compiles a locale to output, and has an expected link count for
> + LC_CTYPE. */
I don't see any cleanup between each step, do we rely on localedef to
remove and replace any output files each time? And/or is that what
we're testing? Either way, I suspect such expectations should be
documented in the comment so that future test readers can share these
expectations.
> +struct test_data
> +{
> + /* Arguments to localedef for this step. */
> + const char * argv[16];
Overkill ;-)
> + /* Expected output file generated by running localedef. */
> + const char *output;
Ok.
> + /* Expected st_nlink count for the output. */
> + int st_nlink;
Ok.
> +/* Check for link count. */
> +void
> +check_link (struct test_data step)
> +{
> + struct stat64 locale;
> + char *output;
> +
> + output = xasprintf ("%s/%s", support_complocaledir_prefix, step.output);
> + xstat (output, &locale);
> + free (output);
> + TEST_COMPARE (locale.st_nlink, step.st_nlink);
> +}
Ok.
> +static void
> +run_localedef (void *step)
> +{
> + const char *prog = xasprintf ("%s/localedef", support_bindir_prefix);
> + struct test_data *one = (struct test_data *) step;
> +
> + one->argv[0] = prog;
> + execv (prog, (char * const *) one->argv);
> + FAIL_EXIT1 ("execv: %m");
> +}
Ok.
> +#define TEST1DIR "test1_locale.dir"
> +#define TEST2DIR "test2_locale.dir"
> +
> +/* The whole test has 4 steps described below. */
> +static struct test_data step[4] = {
> + { .argv = { NULL, "--no-archive", "-i", "/test1_locale", TEST1DIR, NULL },
> + .output = TEST1DIR "/LC_CTYPE",
> + .st_nlink = 1 },
> + { .argv = { NULL, "--no-archive", "-i", "/test2_locale", TEST2DIR, NULL },
> + .output = TEST2DIR "/LC_CTYPE",
> + .st_nlink = 2 },
> + { .argv = { NULL, "--no-archive", "--no-hard-links", "-i", "/test1_locale",
> + TEST1DIR, NULL },
> + .output = TEST1DIR "/LC_CTYPE",
> + .st_nlink = 1 },
> + { .argv = { NULL, "--no-archive", "--no-hard-links", "-i", "/test2_locale",
> + TEST1DIR, NULL },
> + .output = TEST2DIR "/LC_CTYPE",
> + .st_nlink = 1 },
> +};
Ok. Might want to add that the "NULL" will be filled in at runtime.
> +static int
> +do_test (void)
> +{
> + struct support_capture_subprocess result;
> +
> + printf ("INFO: $complocaledir is %s\n", support_complocaledir_prefix);
> + /* Compile the first locale. */
> + result = support_capture_subprocess (run_localedef, (void *) &step[0]);
> + support_capture_subprocess_check (&result, "execv", 1, sc_allow_stderr);
> + check_link (step[0]);
> +
> + /* This time around we should have link counts of 2 for the second
> + linked locale since categories are identical. */
> + result = support_capture_subprocess (run_localedef, (void *) &step[1]);
> + support_capture_subprocess_check (&result, "execv", 1, sc_allow_stderr);
> + check_link (step[1]);
> +
> + /* Again with --no-hard-links (link count is always one). */
> + result = support_capture_subprocess (run_localedef, (void *) &step[2]);
> + support_capture_subprocess_check (&result, "execv", 1, sc_allow_stderr);
> + check_link (step[2]);
> +
> + /* Again with --no-hard-links, and the link count must remain 1. */
> + result = support_capture_subprocess (run_localedef, (void *) &step[3]);
> + support_capture_subprocess_check (&result, "execv", 1, sc_allow_stderr);
> + check_link (step[3]);
> +
> + /* Tested without and with --no-hard-links and link counts were
> + consistent. */
> + return EXIT_SUCCESS;
> +}
Ok.
> +#include <support/test-driver.c>
Ok.
> diff --git a/localedata/tst-localedef-hardlinks.root/postclean.req b/localedata/tst-localedef-hardlinks.root/postclean.req
> new file mode 100644
> index 0000000000..e69de29bb2
I wonder if we should include a comment in this file (contents are
otherwise ignored) saying why it's justified. In this case, I assume
that having test locales hang around might influence future tests if
they're loaded and matched by default?
> diff --git a/localedata/tst-localedef-hardlinks.root/test1_locale b/localedata/tst-localedef-hardlinks.root/test1_locale
> new file mode 100644
> index 0000000000..79f4c3aec4
> --- /dev/null
> +++ b/localedata/tst-localedef-hardlinks.root/test1_locale
> @@ -0,0 +1,3 @@
> +comment_char %
> +escape_char /
> +% Empty test locale. Must be identical to the other test locale.
Ok.
> diff --git a/localedata/tst-localedef-hardlinks.root/test2_locale b/localedata/tst-localedef-hardlinks.root/test2_locale
> new file mode 100644
> index 0000000000..79f4c3aec4
> --- /dev/null
> +++ b/localedata/tst-localedef-hardlinks.root/test2_locale
> @@ -0,0 +1,3 @@
> +comment_char %
> +escape_char /
> +% Empty test locale. Must be identical to the other test locale.
Ok.
> diff --git a/localedata/tst-localedef-hardlinks.root/tst-localedef-hardlinks.script b/localedata/tst-localedef-hardlinks.root/tst-localedef-hardlinks.script
> new file mode 100644
> index 0000000000..7c737aceb0
> --- /dev/null
> +++ b/localedata/tst-localedef-hardlinks.root/tst-localedef-hardlinks.script
> @@ -0,0 +1,10 @@
> +# Need root to write to $complocaledir when running localedef.
> +su
> +
> +# The container install ensures we have uncompressed charmaps so we don't
> +# need gzip, and we don't need to copy in the uncompressed charmap from
> +# the source tree.
> +
> +# We need to create all the parent directories to install the locales
> +# into.
> +mkdirp 0755 $complocaledir/
Ok.
More information about the Libc-alpha
mailing list