From patchwork Fri Jun 14 09:48:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13698446 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B5251922FE for ; Fri, 14 Jun 2024 09:52:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718358732; cv=none; b=celAPCOMs4MdLz94Ll/Tsjf4ZB6IcJw2seMV/za/ed4vmZqQ7QBpy04xaZ++7hStsyhDPpyQM6RJ9YhnCuNULxIVezJDRJo4uY5IYJ0sKZcZD/pzFdjjIBLmzasmsKOmncnxtIYJtrThLDYSpLhLkBxykC1+NRjw7Fh5mgu6Qpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718358732; c=relaxed/simple; bh=lDezlVhbx4xsaZZRDTavwaiORNa5S6p3fLN6vjDPF2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C7imb48yBMEUBleHWV5WsT9kIZuYgtejFN5MnyOjH6mN/RgEIMvzW92Oq9fLI0ETvkNP+EnYZ1ZkY62K+dcDLOMJ4kevOcPpqwjFuOuqSn8IgL0mxOHKCePt/z1D6wEaPrf/JzwuhNK61foul2uhagexfjC+JTDsRd1IHNxaijk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=STIR10JE; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="STIR10JE" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-704189f1225so1867366b3a.0 for ; Fri, 14 Jun 2024 02:52:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718358730; x=1718963530; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QJRxUKvgzPgiuPQGG7wF/Iiv7ARwpsrNISAnWEDh/wg=; b=STIR10JEH04HFcU24rBHzE3OvAJMKxtS7RXZ2t/kuzs8Dsk5EG4gnkgysyGvwCbCZC r5+V/fhs5rmf9UzjQQearHbL5EJna9UDnAewmz7bw/h+hROmHlaRrEAKsu80TenOhGHO C8su7Dgkk3yN1spxoMs6gCbVRp9slXoe3xS910fiDOfpUdZdL6pb7aFE9h5YhRosucnY QsJUlncRmSVfyKKHvA1a5ivTCXpGlg7rb5vbt5Jh+BdxFQkvA25Wt0/utLvbZCvV6UXs mhMBdO/PKrghmUjw5U+ku9qpY6jbUkA8sWsNoEr/CiQub7ylcoQVW6YWu8eqqk1R0+TS GNHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718358730; x=1718963530; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QJRxUKvgzPgiuPQGG7wF/Iiv7ARwpsrNISAnWEDh/wg=; b=VxgDKnuNIQ8skIxFdQeY8obnsWxmhAMFwXSdDK4y0IkqaNVAh6/tgaG1nCvJCCsBqU 4hB0bUUae+vqzTN1xhzVSlo0jE+454GorYb/o0D65vPKtdQ9LQSx5jwljfv725MZSp1R 9m+kYwkIG4BwA2f7I5zUlS3vWyGQ5T+yk4LCKM4KSprvshp0KLQG1eLMEg7CIq9Q5/gi bs+1YlMmnVTWceApxdeOiaTgRRNi1nS6A/dJYe5r8SW15eiYCcYVw/N/uM7tF767DTpE QKtdy2ShCw+87zyrMN2Q/SpFAQapaoriebT6waWcBVHyNW8aJt3rjNLH8PH5N6zQL6rn mgpQ== X-Gm-Message-State: AOJu0Yyvu43mYxVjk+LfOLM/PdfHZI3lOjLcG86rnj6ZGoceLSLa7I89 kGjeTxnyB8ilEKyxoN6lkYX2Jf8pN1/MjQjBHv8mtu0CtJE2GdEYSpX4hoqWNtE= X-Google-Smtp-Source: AGHT+IHEY8EOu4m7ti4L6DOr1JuvxhnOjnr6fEXd6Tm89MRXy+nglm8JQz39psLuKptqpttozsQ/IA== X-Received: by 2002:a05:6a20:430d:b0:1b7:82b4:a380 with SMTP id adf61e73a8af0-1bae7e93639mr3002271637.29.1718358729845; Fri, 14 Jun 2024 02:52:09 -0700 (PDT) Received: from Ubuntu.. ([117.96.146.43]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f868b83afesm9230005ad.156.2024.06.14.02.52.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 02:52:09 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 3/7] t: move reftable/pq_test.c to the unit testing framework Date: Fri, 14 Jun 2024 15:18:03 +0530 Message-ID: <20240614095136.12052-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240614095136.12052-1-chandrapratap3519@gmail.com> References: <20240611083157.9876-1-chandrapratap3519@gmail.com> <20240614095136.12052-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 reftable/pq_test.c exercises a priority queue defined by reftable/pq.{c, h}. Migrate reftable/pq_test.c to the unit testing framework. Migration involves refactoring the tests to use the unit testing framework instead of reftable's test framework. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- Makefile | 2 +- t/helper/test-reftable.c | 1 - .../pq_test.c => t/unit-tests/t-reftable-pq.c | 37 ++++++++----------- 3 files changed, 16 insertions(+), 24 deletions(-) rename reftable/pq_test.c => t/unit-tests/t-reftable-pq.c (62%) diff --git a/Makefile b/Makefile index 59d98ba688..1cabe4cc69 100644 --- a/Makefile +++ b/Makefile @@ -1336,6 +1336,7 @@ THIRD_PARTY_SOURCES += sha1dc/% UNIT_TEST_PROGRAMS += t-ctype UNIT_TEST_PROGRAMS += t-mem-pool UNIT_TEST_PROGRAMS += t-prio-queue +UNIT_TEST_PROGRAMS += t-reftable-pq UNIT_TEST_PROGRAMS += t-strbuf UNIT_TEST_PROGRAMS += t-strcmp-offset UNIT_TEST_PROGRAMS += t-trailer @@ -2675,7 +2676,6 @@ REFTABLE_TEST_OBJS += reftable/basics_test.o REFTABLE_TEST_OBJS += reftable/block_test.o REFTABLE_TEST_OBJS += reftable/dump.o REFTABLE_TEST_OBJS += reftable/merged_test.o -REFTABLE_TEST_OBJS += reftable/pq_test.o REFTABLE_TEST_OBJS += reftable/record_test.o REFTABLE_TEST_OBJS += reftable/readwrite_test.o REFTABLE_TEST_OBJS += reftable/stack_test.o diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index bae731669c..86a2b0f91a 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -9,7 +9,6 @@ int cmd__reftable(int argc, const char **argv) record_test_main(argc, argv); block_test_main(argc, argv); tree_test_main(argc, argv); - pq_test_main(argc, argv); readwrite_test_main(argc, argv); merged_test_main(argc, argv); stack_test_main(argc, argv); diff --git a/reftable/pq_test.c b/t/unit-tests/t-reftable-pq.c similarity index 62% rename from reftable/pq_test.c rename to t/unit-tests/t-reftable-pq.c index b7d3c80cc7..a47a9473f3 100644 --- a/reftable/pq_test.c +++ b/t/unit-tests/t-reftable-pq.c @@ -6,35 +6,28 @@ license that can be found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd */ -#include "system.h" - -#include "basics.h" -#include "constants.h" -#include "pq.h" -#include "record.h" -#include "reftable-tests.h" -#include "test_framework.h" +#include "test-lib.h" +#include "reftable/constants.h" +#include "reftable/pq.h" void merged_iter_pqueue_check(struct merged_iter_pqueue pq) { - int i; - for (i = 1; i < pq.len; i++) { - int parent = (i - 1) / 2; - - EXPECT(pq_less(&pq.heap[parent], &pq.heap[i])); + for (size_t i = 1; i < pq.len; i++) { + size_t parent = (i - 1) / 2; + check(pq_less(&pq.heap[parent], &pq.heap[i])); } } static void test_pq(void) { - struct merged_iter_pqueue pq = { NULL }; + struct merged_iter_pqueue pq = { 0 }; struct reftable_record recs[54]; - int N = ARRAY_SIZE(recs) - 1, i; + size_t N = ARRAY_SIZE(recs) - 1, i; char *last = NULL; for (i = 0; i < N; i++) { struct strbuf refname = STRBUF_INIT; - strbuf_addf(&refname, "%02d", i); + strbuf_addf(&refname, "%02"PRIuMAX, (uintmax_t)i); reftable_record_init(&recs[i], BLOCK_TYPE_REF); recs[i].u.ref.refname = strbuf_detach(&refname, NULL); @@ -48,7 +41,6 @@ static void test_pq(void) merged_iter_pqueue_add(&pq, &e); merged_iter_pqueue_check(pq); - i = (i * 7) % N; } while (i != 1); @@ -56,9 +48,9 @@ static void test_pq(void) struct pq_entry e = merged_iter_pqueue_remove(&pq); merged_iter_pqueue_check(pq); - EXPECT(reftable_record_type(e.rec) == BLOCK_TYPE_REF); + check(reftable_record_type(e.rec) == BLOCK_TYPE_REF); if (last) - EXPECT(strcmp(last, e.rec->u.ref.refname) < 0); + check_int(strcmp(last, e.rec->u.ref.refname), <, 0); last = e.rec->u.ref.refname; } @@ -67,8 +59,9 @@ static void test_pq(void) merged_iter_pqueue_release(&pq); } -int pq_test_main(int argc, const char *argv[]) +int cmd_main(int argc, const char *argv[]) { - RUN_TEST(test_pq); - return 0; + TEST(test_pq(), "pq works"); + + return test_done(); }