From patchwork Wed Apr 29 16:17:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos O'Donell X-Patchwork-Id: 1279501 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=ZrHVrr+i; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49C3Zp4f5dz9sPF for ; Thu, 30 Apr 2020 02:17:54 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 60DDA395B0AE; Wed, 29 Apr 2020 16:17:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 60DDA395B0AE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1588177072; bh=NrZjIH7KryXAhDpE1gTIyq/Z6cwpMzg3OjbJVPy3u2I=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ZrHVrr+iSx67v+/gGzWUXlngCfO5a3UJpa0RuG4WOUEe0UCTbpBPfG8UXFYARYqaw b1fTeLR1JmmDQh8+lEOgMMwZH25ObG1boMv4IhKoxvMOCxpmxj7ULXndUEn4Gmrolg rbuS4cLZLSEdBK4eIQYfE3W+XCYqpt2ag/svy9Yk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id C1567395A027 for ; Wed, 29 Apr 2020 16:17:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C1567395A027 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-93-r_xIaY7KPB6kJYN3i7rIgQ-1; Wed, 29 Apr 2020 12:17:41 -0400 X-MC-Unique: r_xIaY7KPB6kJYN3i7rIgQ-1 Received: by mail-qk1-f197.google.com with SMTP id 198so3218044qkf.2 for ; Wed, 29 Apr 2020 09:17:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=NrZjIH7KryXAhDpE1gTIyq/Z6cwpMzg3OjbJVPy3u2I=; b=UF8+pIr27ooMfInmx8yJp+6sicGr72wmgHrn2spvptUxUzPqdWDWPmK85DEJNHmg0b 2ZOmWN2ibWa1QBmi9CiWvmezb/25+BmLioLA0JGi6KrbwkK5Ia9z4vXFYqty3ufS8DjE KLg6rrrX5Yn6VlzOZGA+zvfAhu38Q7gvgo5kqeVpKPwHlVUsZvGnX/vL/9juMmS9UIzJ 6y31a0K/1Ebd6cxgG4IVICG01gOHUvEZfQAPc+yTgoI4xWOWnA2PZ+MnwKLQr+5QnoYl Yf4Z0jL1fKdYMT1PCTWTWonXiHHr54lLTzOVl1yaCXDW4L5M7BG0yObXmtylZLXnH9RQ efSQ== X-Gm-Message-State: AGi0PuYSePvS4/9yLWp9ubwVMas3rSEFiFDXKGOQ1k3oNpG+iCuphT0s 3aoSPepLdgYK21UypANcNJ9T5r2ZOe+1u1GcET4TuZf3Xlw6v9FNMj2q0IdPfjVq1H8RADJsi1p MKlSeZw8vh+91MvUnkuXB X-Received: by 2002:aed:2765:: with SMTP id n92mr34539835qtd.73.1588177060256; Wed, 29 Apr 2020 09:17:40 -0700 (PDT) X-Google-Smtp-Source: APiQypKUElmjtL4SZrpzQ9zfl4zQL11heMTnAaKEgKPXoBr3MmsTTeEVPZeRzo8oBpMf2YTO+inOwA== X-Received: by 2002:aed:2765:: with SMTP id n92mr34539794qtd.73.1588177059736; Wed, 29 Apr 2020 09:17:39 -0700 (PDT) Received: from [192.168.1.4] (198-84-170-103.cpe.teksavvy.com. [198.84.170.103]) by smtp.gmail.com with ESMTPSA id a27sm17023693qtb.26.2020.04.29.09.17.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Apr 2020 09:17:39 -0700 (PDT) Subject: [PATCHv2] localedef: Add tests-container test for --no-hard-links. To: DJ Delorie References: Organization: Red Hat Message-ID: <582d4330-ec19-5d2f-53e0-8a9d64d78ddc@redhat.com> Date: Wed, 29 Apr 2020 12:17:37 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-21.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Carlos O'Donell via Libc-alpha From: Carlos O'Donell Reply-To: Carlos O'Donell Cc: libc-alpha@sourceware.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" On 4/28/20 2:28 PM, DJ Delorie wrote: > > "Carlos O'Donell" writes: >> OK for master? > > Minor comments about comments but functionally OK. > > Reviewed-by: DJ Delorie > >> +tests-container = \ >> + tst-localedef-hardlinks > > New test, ok. > >> +/* Test --no-hard-links option to localedef. >> + Copyright (C) 2018 Free Software Foundation, Inc. > > 2018 ? Fixed. > >> + . */ > > https Fixed. > >> +/* 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. Fixed. Yes, we expect localedef to remove the files and replace them. ~~~ -/* Each test compiles a locale to output, and has an expected link count for - LC_CTYPE. */ +/* Each test compiles a locale to output, and has an expected link count + for LC_CTYPE. This test expects that localedef removes the existing + files before installing new copies of the files, and we do not + cleanup between localedef runs. We can't cleanup between each pair + of runs since localedef must see the existing locale in order to + determine that space could be saved by using a hardlink. */ ~~~ >> +struct test_data >> +{ >> + /* Arguments to localedef for this step. */ >> + const char * argv[16]; > > Overkill ;-) Right, we're at 6 args, so I gave some room. We really need some dynamic APIs for writing test closures. I don't want ad-hoc methods for creating closures. > >> + /* 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. > Fixed. >> +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 > > 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? Correct. Fixed. >> 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. > v2 - Fix date. - Fix https - Add extra comment about file overwrite expecatations. - Add comment about argv[0] getting filled in (it's dynamic and depends on bindir). - Add comment to postclean.req. OK for master? 8< --- 8< --- 8< From 67854155584856bab4849b01ecf51aab67048bbb Mon Sep 17 00:00:00 2001 From: Carlos O'Donell Date: Tue, 25 Feb 2020 10:15:30 -0500 Subject: [PATCH] localedef: Add tests-container test for --no-hard-links. The new tst-localedef-hardlinks verifies that when compiling two locales (with default output directory) one with --no-hard-links and one without the option, results in the expected behaviour. When --no-hard-links is used the link counts on LC_CTYPE is 1, indicating that even thoug the two locale are identical (though different named source files and output direcotry) the localedef did not carry out the hard link optimization. Then when --no-hard-links is omitted the localedef hard link optimization is correctly carried out and for 2 compiled locales the link count for LC_CTYPE is 2. Reviewed-by: DJ Delorie --- localedata/Makefile | 2 + localedata/tst-localedef-hardlinks.c | 135 ++++++++++++++++++ .../postclean.req | 2 + .../tst-localedef-hardlinks.root/test1_locale | 3 + .../tst-localedef-hardlinks.root/test2_locale | 3 + .../tst-localedef-hardlinks.script | 9 ++ 6 files changed, 154 insertions(+) create mode 100644 localedata/tst-localedef-hardlinks.c create mode 100644 localedata/tst-localedef-hardlinks.root/postclean.req create mode 100644 localedata/tst-localedef-hardlinks.root/test1_locale create mode 100644 localedata/tst-localedef-hardlinks.root/test2_locale create mode 100644 localedata/tst-localedef-hardlinks.root/tst-localedef-hardlinks.script diff --git a/localedata/Makefile b/localedata/Makefile index e89bacc1aa..ccfcb0049f 100644 --- a/localedata/Makefile +++ b/localedata/Makefile @@ -167,6 +167,8 @@ tests-special += $(objpfx)mtrace-tst-leaks.out endif endif endif +tests-container = \ + tst-localedef-hardlinks # Files to install. ifeq ($(INSTALL_UNCOMPRESSED),yes) diff --git a/localedata/tst-localedef-hardlinks.c b/localedata/tst-localedef-hardlinks.c new file mode 100644 index 0000000000..e8fda167be --- /dev/null +++ b/localedata/tst-localedef-hardlinks.c @@ -0,0 +1,135 @@ +/* Test --no-hard-links option to localedef. + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* The test is designed to run in a container and execute localedef + once without --no-hard-links, verify that there are 2 hard links to + LC_CTYPE, and then run again *with* --no-hard-links and verify there + are no hard links and link counts remain at 1. The expectation here + is that LC_CTYPE is identical for both locales because they are same + empty locale but with a different name. We use tests-container in + this test because the hard link optimziation is only carried out for + the default locale installation directory, and to write to that we + need write access to that directory, enabled by 'su' via + tests-container framework. */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +/* Each test compiles a locale to output, and has an expected link count + for LC_CTYPE. This test expects that localedef removes the existing + files before installing new copies of the files, and we do not + cleanup between localedef runs. We can't cleanup between each pair + of runs since localedef must see the existing locale in order to + determine that space could be saved by using a hardlink. */ +struct test_data +{ + /* Arguments to localedef for this step. */ + const char * argv[16]; + /* Expected output file generated by running localedef. */ + const char *output; + /* Expected st_nlink count for the output. */ + int st_nlink; +}; + +/* 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); +} + +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"); +} + +#define TEST1DIR "test1_locale.dir" +#define TEST2DIR "test2_locale.dir" + +/* The whole test has 4 steps described below. Note the argv[0] NULL + will be filled in at runtime by run_localedef. */ +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 }, +}; + +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; +} + +#include diff --git a/localedata/tst-localedef-hardlinks.root/postclean.req b/localedata/tst-localedef-hardlinks.root/postclean.req new file mode 100644 index 0000000000..48f3c4bd4e --- /dev/null +++ b/localedata/tst-localedef-hardlinks.root/postclean.req @@ -0,0 +1,2 @@ +# We do not want test locales to remain installed for future tests so +# we request that the testroot be cleaned after the test is complete. 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. 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. 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..dd88663530 --- /dev/null +++ b/localedata/tst-localedef-hardlinks.root/tst-localedef-hardlinks.script @@ -0,0 +1,9 @@ +# 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. + +# The container install ensures we have the compiled locale dirctory +# present for localedef to write to by default.