From patchwork Fri Mar 20 20:41:25 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 132106 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 0EE354BBCD92 for ; Fri, 20 Mar 2026 20:43:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0EE354BBCD92 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DqVXsu9k X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 9BDD64C31818 for ; Fri, 20 Mar 2026 20:41:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9BDD64C31818 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9BDD64C31818 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1774039291; cv=none; b=eAleiEt6CWdongwhSmubnkvqXIA05ug8rJiMbXNa/obpWK4O+vCb5lfhnsgwYGxvoDTZCv+bZXl9nId0fQbbx1Bc++hvKSwBqz5PISMAYb4J3TNGozK4vbqVMgZJ3yDPnueHfgcjwSFM3FFxkcKImKybtKB+GpnIqeHIVCv+oxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1774039291; c=relaxed/simple; bh=CxUjfzOMpx3al8G+0S2auzijEdoMV457SR3Whaf9OpI=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=AV2y/dpIajNziwtMzIYGZH5wXG2IlM9mZCUZ5xoaKlzNgF4uMv//d49OWgfj41Chn1oNDbNpA1/BGaFGDzyDY+p/sTuWMpJmVnEDu4SR1ynaJAe6Z9VArO/T7CI0DF9BBIFSDLCkgCluaJhOLhFjM9WIhkhBNr8i7CGf+jFMKYk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9BDD64C31818 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774039291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=OGil5NiEFoyurnpDtmwQJhbimHHsXajUhzYjNgc6BtI=; b=DqVXsu9k0dhjrdo+xiQzDBRDzazyr40FPO2zMmAK9Hjv2UmvYP09hCz/tb74spoofJGeBn Ai+jiXXNS1G8daR2VUJwLgR7FS8mudvTatsdp37djlDetPW8Ous92L0yO078T+Wy764BJj hyHdbQDRXX5kP6dwKqGf7js801sH898= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-41-CmDYux_4NYSZj9uZQg9EdQ-1; Fri, 20 Mar 2026 16:41:30 -0400 X-MC-Unique: CmDYux_4NYSZj9uZQg9EdQ-1 X-Mimecast-MFC-AGG-ID: CmDYux_4NYSZj9uZQg9EdQ_1774039288 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 52607195609D for ; Fri, 20 Mar 2026 20:41:28 +0000 (UTC) Received: from fweimer-oldenburg.csb.redhat.com (unknown [10.45.224.63]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9CD8B180075B for ; Fri, 20 Mar 2026 20:41:27 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v2 03/23] nscd: Enhance tst-nscd-basic with query counters In-Reply-To: Message-ID: <10c9ef7c1c250ca75ce3193cd4de9cf7eb997d82.1774037705.git.fweimer@redhat.com> References: X-From-Line: 10c9ef7c1c250ca75ce3193cd4de9cf7eb997d82 Mon Sep 17 00:00:00 2001 Date: Fri, 20 Mar 2026 21:41:25 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: xQOHfnvkAiySqFDTGq24Aa-d1PqFevOCwJBccS2IyX4_1774039288 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org This helps to test that the cache is actually used. Reviewed-by: Carlos O'Donell --- nscd/tst-nscd-basic.c | 58 ++++++++++++++++++++++++++++++++++++++++++ support/nscd_test.h | 4 +++ support/support_nscd.c | 33 ++++++++++++++++++++++++ 3 files changed, 95 insertions(+) diff --git a/nscd/tst-nscd-basic.c b/nscd/tst-nscd-basic.c index 2ce1fece60..3dfde92c36 100644 --- a/nscd/tst-nscd-basic.c +++ b/nscd/tst-nscd-basic.c @@ -31,6 +31,8 @@ #include #include +#include + /* Large GECOS string for the large-gecos user. */ static char *large_gecos; @@ -452,17 +454,73 @@ do_test (void) /* First run the tests without nscd running, to check that the test expectations are correct. Use a separate process to avoid caching nscd availability. */ + puts ("info: testing without nscd"); support_isolate_in_subprocess (all_tests, NULL); support_nscd_copy_configuration (); support_nscd_start (); + /* Initially the query counters are all zero. */ + { + struct statdata stat; + support_nscd_get_statistics (&stat); + for (int i = 0; i < lastdb; ++i) + { + TEST_COMPARE (stat.dbs[i].nentries, 0); + TEST_COMPARE (stat.dbs[i].poshit, 0); + TEST_COMPARE (stat.dbs[i].neghit, 0); + TEST_COMPARE (stat.dbs[i].posmiss, 0); + TEST_COMPARE (stat.dbs[i].negmiss, 0); + } + } + + puts ("info: first pass with nscd"); all_tests (NULL); + /* After running the tests, we have cache entries in all databases. + The counters have been empirically determined. They mostly check + that nscd is actually used. */ + struct statdata stat_first_pass; + support_nscd_get_statistics (&stat_first_pass); + TEST_COMPARE (stat_first_pass.dbs[pwddb].nentries, 10); + TEST_COMPARE (stat_first_pass.dbs[pwddb].posmiss, 4); + TEST_COMPARE (stat_first_pass.dbs[pwddb].negmiss, 2); + TEST_COMPARE (stat_first_pass.dbs[grpdb].nentries, 10); + TEST_COMPARE (stat_first_pass.dbs[grpdb].posmiss, 5); + TEST_COMPARE (stat_first_pass.dbs[grpdb].negmiss, 2); + TEST_COMPARE (stat_first_pass.dbs[hstdb].nentries, 5); + TEST_COMPARE (stat_first_pass.dbs[hstdb].posmiss, 5); + TEST_COMPARE (stat_first_pass.dbs[hstdb].negmiss, 0); + TEST_COMPARE (stat_first_pass.dbs[netgrdb].nentries, 25); + TEST_COMPARE (stat_first_pass.dbs[netgrdb].posmiss, 25); + TEST_COMPARE (stat_first_pass.dbs[netgrdb].negmiss, 0); + TEST_COMPARE (stat_first_pass.dbs[servdb].nentries, 5); + TEST_COMPARE (stat_first_pass.dbs[servdb].posmiss, 3); + TEST_COMPARE (stat_first_pass.dbs[servdb].negmiss, 2); + /* Retry from cache. */ + puts ("info: second pass with nscd, with caching"); all_tests (NULL); + /* Retries should have used the cache and not increment the query + counters. This means that the shared mapping is used, not the + socket query interface or the in-process nss_files service + module. */ + { + struct statdata stat; + support_nscd_get_statistics (&stat); + for (int i = 0; i < lastdb; ++i) + { + TEST_COMPARE (stat.dbs[i].nentries, stat_first_pass.dbs[i].nentries); + TEST_COMPARE (stat.dbs[i].poshit, stat_first_pass.dbs[i].poshit); + TEST_COMPARE (stat.dbs[i].neghit, stat_first_pass.dbs[i].neghit); + TEST_COMPARE (stat.dbs[i].posmiss, stat_first_pass.dbs[i].posmiss); + TEST_COMPARE (stat.dbs[i].negmiss, stat_first_pass.dbs[i].negmiss); + } + } + + puts ("info: pass with interleaved invalidation"); invalidate = support_nscd_invalidate; all_tests (NULL); diff --git a/support/nscd_test.h b/support/nscd_test.h index 60208098f4..95d9c1cd38 100644 --- a/support/nscd_test.h +++ b/support/nscd_test.h @@ -36,4 +36,8 @@ void support_nscd_stop (void); services). */ void support_nscd_invalidate (const char *database); +/* Fill in *STATS with data from the running nscd daemon. */ +struct statdata; +void support_nscd_get_statistics (struct statdata *stat); + #endif /* SUPPORT_NSCD_TEST_H */ diff --git a/support/support_nscd.c b/support/support_nscd.c index 2d7d503ad6..96d1e6b874 100644 --- a/support/support_nscd.c +++ b/support/support_nscd.c @@ -18,20 +18,25 @@ #include +#include #include #include #include #include +#include #include #include #include #include #include +#include +#include #include #include #include #include +#include static pid_t nscd_pid; @@ -113,3 +118,31 @@ support_nscd_invalidate (const char *database) TEST_COMPARE (system (cmd), 0); free (cmd); } + +void +support_nscd_get_statistics (struct statdata *stat) +{ + struct sockaddr_un sun; + sun.sun_family = AF_UNIX; + strcpy (sun.sun_path, _PATH_NSCDSOCKET); + + int sock = socket (PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); + if (sock < 0 || connect (sock, (struct sockaddr *) &sun, sizeof (sun)) < 0) + FAIL_EXIT1 ("failed to open nscd socket: %m"); + + request_header req; + req.version = NSCD_VERSION; + req.type = GETSTAT; + req.key_len = 0; + + if (TEMP_FAILURE_RETRY (send (sock, &req, sizeof (req), MSG_NOSIGNAL)) + != sizeof (req)) + FAIL_EXIT1 ("failed to send request to nscd: %m"); + + ssize_t ret = TEMP_FAILURE_RETRY (recv (sock, stat, sizeof (*stat), 0)); + + errno = EMSGSIZE; + if (ret != sizeof (*stat) || stat->version != STATDATA_VERSION_FULL) + FAIL_EXIT1 ("failed to receive statistics from nscd: %m"); + close (sock); +}