From patchwork Fri Jun 21 11:50:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13707433 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 8DCCB13D615 for ; Fri, 21 Jun 2024 11:57:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971067; cv=none; b=kcr3u72w8JW70TucZ97/G6ShjhW0VdHf5r+Im2YKM/ovbGdXpaOF/p1acW7kJA1U+7q3FbCT2DvdQFFGaeTgQ19DJ8YKzh4DLnEBf0uPk6A/e3YAqKJsrJvQcLjbvaPYvu3GeCTrqfmX+3I1T1r0aV0Q1dYAsu2zq5oXeG2l/6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971067; c=relaxed/simple; bh=OoTJemVyRW8TYKBFpN6Ub/xGbZfeKzeqkPJkF1PsYCM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P+IcmRwx2Q43cAwTRTOKIerdF+9n66iJnSaI9qBKOYz06TGGAZuPdB48/Vzz7VZ4q4+EQy3fkXK/WVvToSNnl5M5DE1kQuwcvcBIE/0gkXuJWYjMBu4lp2IJm+MhICMGb2eUV4gDtREH1aV74ix9uE6A4sNKclL2fuvuomYrUIA= 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=lRlPDGUd; arc=none smtp.client-ip=209.85.214.174 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="lRlPDGUd" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1f9f9a3866fso1827715ad.0 for ; Fri, 21 Jun 2024 04:57:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718971064; x=1719575864; 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=kkNsc81pvogY8LbTicFd/ENZaZm51YQcpZbMFUuPyPE=; b=lRlPDGUdH8XANB7NyjMj0ldXLINf4rtudXZjSpjOnD0UUFKa4u2j1iSRsON7HHVAkN Kk7GzK8ih9i4pmPi3zNAtHw6t6jZ0T7epbY7sa57LbEggSrF2FyIWQyEz3eeqVnR42d7 BzPktEUcDpmEuXGYHsghxMwAzR944tzpQHcNz/0Z3O/LQ0Cqq4w3pPPxVOmKnAqDOoR6 AZNNUdYbtLu75/Ue0dclkbQrTMLbef/fIHq+GH+C4IKRoFceeRV0r76pIncYE4v1sMTY n8UCTm+WOG3jb/Dbk6r5SMSutfhTqibAesIMUaOWmI5BNcLZRtA7xtaqBWflekZI9uwh vsig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718971064; x=1719575864; 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=kkNsc81pvogY8LbTicFd/ENZaZm51YQcpZbMFUuPyPE=; b=kRqCViiK9ji2cuCGDRQkasE7sVQluKkfR27D4oC01BVdnPfhN5noH7Dto147aJ4t2p 7vfypMon0SLDmh5cE7RXeRb/M3634pvSigNRnaiUSAK7Nh+2Wyb2bJIWqgzDSV/V3Ruq W9qEi8W/qNqh6CHNO+r9zB33i90XaYyGrWgOBLyyT+IVOoKCO43jUC3wWKfxbgInRfb/ SVc4ZTgyr6XunCbFL3kpjwqIfVVdAo8+hlFsvWvsT24jG+ebxllIn6Wwe8eil0skYPxu JMfO3/eGy6raPdiTYmB5ItyRYR5kpPWwQfWYzQzB9g9eo83LwfLID1Cj+ferVCJ2cR0x /waw== X-Gm-Message-State: AOJu0YzLgKGm9VXrvayPDamaHrMSJMG+bn7MOhjaixri7Y/51TK/A6zb 6P8EnaRA4B7LtQDptvKd67hPnAFmogrU89egzLt94jL94J7t1jBV4pm+XA== X-Google-Smtp-Source: AGHT+IGI0854vK911Vp33pBNJJ7EPMLXQk6V6VmsMUZMpXhhw5q+9gMtFTYJuPQ7kPseJGaD7fJjAA== X-Received: by 2002:a17:902:ce88:b0:1f6:1a86:37ba with SMTP id d9443c01a7336-1f9a8d35971mr123143815ad.2.1718971063876; Fri, 21 Jun 2024 04:57:43 -0700 (PDT) Received: from Ubuntu.. ([106.206.204.195]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f9eb3c5ee9sm12407195ad.180.2024.06.21.04.57.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 04:57:43 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 01/11] t: move reftable/record_test.c to the unit testing framework Date: Fri, 21 Jun 2024 17:20:56 +0530 Message-ID: <20240621115708.3626-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621115708.3626-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240621115708.3626-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 reftable/record_test.c exercises the functions defined in reftable/record.{c, h}. Migrate reftable/record_test.c to the unit testing framework. Migration involves refactoring the tests to use the unit testing framework instead of reftable's test framework. While at it, change the type of index variable 'i' to 'size_t' from 'int'. This is because 'i' is used in comparison against 'ARRAY_SIZE(x)' which is of type 'size_t'. Also, use set_hash() which is defined locally in the test file instead of set_test_hash() which is defined by reftable/test_framework.{c, h}. This is fine to do as both these functions are similarly implemented, and reftable/test_framework.{c, h} is not #included in the ported test. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- Makefile | 2 +- t/helper/test-reftable.c | 1 - .../unit-tests/t-reftable-record.c | 106 ++++++++---------- 3 files changed, 50 insertions(+), 59 deletions(-) rename reftable/record_test.c => t/unit-tests/t-reftable-record.c (77%) diff --git a/Makefile b/Makefile index f25b2e80a1..def3700b4d 100644 --- a/Makefile +++ b/Makefile @@ -1338,6 +1338,7 @@ UNIT_TEST_PROGRAMS += t-hash UNIT_TEST_PROGRAMS += t-mem-pool UNIT_TEST_PROGRAMS += t-prio-queue UNIT_TEST_PROGRAMS += t-reftable-basics +UNIT_TEST_PROGRAMS += t-reftable-record UNIT_TEST_PROGRAMS += t-strbuf UNIT_TEST_PROGRAMS += t-strcmp-offset UNIT_TEST_PROGRAMS += t-strvec @@ -2678,7 +2679,6 @@ 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 REFTABLE_TEST_OBJS += reftable/test_framework.o diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index 9160bc5da6..aa6538a8da 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -5,7 +5,6 @@ int cmd__reftable(int argc, const char **argv) { /* test from simple to complex. */ - record_test_main(argc, argv); block_test_main(argc, argv); tree_test_main(argc, argv); pq_test_main(argc, argv); diff --git a/reftable/record_test.c b/t/unit-tests/t-reftable-record.c similarity index 77% rename from reftable/record_test.c rename to t/unit-tests/t-reftable-record.c index 58290bdba3..1b357e6c7f 100644 --- a/reftable/record_test.c +++ b/t/unit-tests/t-reftable-record.c @@ -6,13 +6,9 @@ https://developers.google.com/open-source/licenses/bsd */ -#include "record.h" - -#include "system.h" -#include "basics.h" -#include "constants.h" -#include "test_framework.h" -#include "reftable-tests.h" +#include "test-lib.h" +#include "reftable/constants.h" +#include "reftable/record.h" static void test_copy(struct reftable_record *rec) { @@ -24,9 +20,9 @@ static void test_copy(struct reftable_record *rec) reftable_record_copy_from(©, rec, GIT_SHA1_RAWSZ); /* do it twice to catch memory leaks */ reftable_record_copy_from(©, rec, GIT_SHA1_RAWSZ); - EXPECT(reftable_record_equal(rec, ©, GIT_SHA1_RAWSZ)); + check(reftable_record_equal(rec, ©, GIT_SHA1_RAWSZ)); - puts("testing print coverage:\n"); + test_msg("testing print coverage:"); reftable_record_print(©, GIT_SHA1_RAWSZ); reftable_record_release(©); @@ -43,8 +39,8 @@ static void test_varint_roundtrip(void) 4096, ((uint64_t)1 << 63), ((uint64_t)1 << 63) + ((uint64_t)1 << 63) - 1 }; - int i = 0; - for (i = 0; i < ARRAY_SIZE(inputs); i++) { + + for (size_t i = 0; i < ARRAY_SIZE(inputs); i++) { uint8_t dest[10]; struct string_view out = { @@ -55,29 +51,26 @@ static void test_varint_roundtrip(void) int n = put_var_int(&out, in); uint64_t got = 0; - EXPECT(n > 0); + check_int(n, >, 0); out.len = n; n = get_var_int(&got, &out); - EXPECT(n > 0); + check_int(n, >, 0); - EXPECT(got == in); + check_int(got, ==, in); } } static void set_hash(uint8_t *h, int j) { - int i = 0; - for (i = 0; i < hash_size(GIT_SHA1_FORMAT_ID); i++) { + for (int i = 0; i < hash_size(GIT_SHA1_FORMAT_ID); i++) h[i] = (j >> i) & 0xff; - } } static void test_reftable_ref_record_roundtrip(void) { struct strbuf scratch = STRBUF_INIT; - int i = 0; - for (i = REFTABLE_REF_DELETION; i < REFTABLE_NR_REF_VALUETYPES; i++) { + for (int i = REFTABLE_REF_DELETION; i < REFTABLE_NR_REF_VALUETYPES; i++) { struct reftable_record in = { .type = BLOCK_TYPE_REF, }; @@ -109,17 +102,17 @@ static void test_reftable_ref_record_roundtrip(void) test_copy(&in); - EXPECT(reftable_record_val_type(&in) == i); + check_int(reftable_record_val_type(&in), ==, i); reftable_record_key(&in, &key); n = reftable_record_encode(&in, dest, GIT_SHA1_RAWSZ); - EXPECT(n > 0); + check_int(n, >, 0); /* decode into a non-zero reftable_record to test for leaks. */ m = reftable_record_decode(&out, key, i, dest, GIT_SHA1_RAWSZ, &scratch); - EXPECT(n == m); + check_int(n, ==, m); - EXPECT(reftable_ref_record_equal(&in.u.ref, &out.u.ref, + check(reftable_ref_record_equal(&in.u.ref, &out.u.ref, GIT_SHA1_RAWSZ)); reftable_record_release(&in); @@ -143,16 +136,15 @@ static void test_reftable_log_record_equal(void) } }; - EXPECT(!reftable_log_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ)); + check(!reftable_log_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ)); in[1].update_index = in[0].update_index; - EXPECT(reftable_log_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ)); + check(reftable_log_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ)); reftable_log_record_release(&in[0]); reftable_log_record_release(&in[1]); } static void test_reftable_log_record_roundtrip(void) { - int i; struct reftable_log_record in[] = { { .refname = xstrdup("refs/heads/master"), @@ -180,12 +172,12 @@ static void test_reftable_log_record_roundtrip(void) } }; struct strbuf scratch = STRBUF_INIT; + set_hash(in[0].value.update.new_hash, 1); + set_hash(in[0].value.update.old_hash, 2); + set_hash(in[2].value.update.new_hash, 3); + set_hash(in[2].value.update.old_hash, 4); - set_test_hash(in[0].value.update.new_hash, 1); - set_test_hash(in[0].value.update.old_hash, 2); - set_test_hash(in[2].value.update.new_hash, 3); - set_test_hash(in[2].value.update.old_hash, 4); - for (i = 0; i < ARRAY_SIZE(in); i++) { + for (size_t i = 0; i < ARRAY_SIZE(in); i++) { struct reftable_record rec = { .type = BLOCK_TYPE_LOG }; struct strbuf key = STRBUF_INIT; uint8_t buffer[1024] = { 0 }; @@ -217,13 +209,13 @@ static void test_reftable_log_record_roundtrip(void) reftable_record_key(&rec, &key); n = reftable_record_encode(&rec, dest, GIT_SHA1_RAWSZ); - EXPECT(n >= 0); + check_int(n, >=, 0); valtype = reftable_record_val_type(&rec); m = reftable_record_decode(&out, key, valtype, dest, GIT_SHA1_RAWSZ, &scratch); - EXPECT(n == m); + check_int(n, ==, m); - EXPECT(reftable_log_record_equal(&in[i], &out.u.log, + check(reftable_log_record_equal(&in[i], &out.u.log, GIT_SHA1_RAWSZ)); reftable_log_record_release(&in[i]); strbuf_release(&key); @@ -252,14 +244,14 @@ static void test_key_roundtrip(void) strbuf_addstr(&key, "refs/tags/bla"); extra = 6; n = reftable_encode_key(&restart, dest, last_key, key, extra); - EXPECT(!restart); - EXPECT(n > 0); + check(!restart); + check_int(n, >, 0); strbuf_addstr(&roundtrip, "refs/heads/master"); m = reftable_decode_key(&roundtrip, &rt_extra, dest); - EXPECT(n == m); - EXPECT(0 == strbuf_cmp(&key, &roundtrip)); - EXPECT(rt_extra == extra); + check_int(n, ==, m); + check(!strbuf_cmp(&key, &roundtrip)); + check_int(rt_extra, ==, extra); strbuf_release(&last_key); strbuf_release(&key); @@ -289,9 +281,8 @@ static void test_reftable_obj_record_roundtrip(void) }, }; struct strbuf scratch = STRBUF_INIT; - int i = 0; - for (i = 0; i < ARRAY_SIZE(recs); i++) { + for (size_t i = 0; i < ARRAY_SIZE(recs); i++) { uint8_t buffer[1024] = { 0 }; struct string_view dest = { .buf = buffer, @@ -311,13 +302,13 @@ static void test_reftable_obj_record_roundtrip(void) test_copy(&in); reftable_record_key(&in, &key); n = reftable_record_encode(&in, dest, GIT_SHA1_RAWSZ); - EXPECT(n > 0); + check_int(n, >, 0); extra = reftable_record_val_type(&in); m = reftable_record_decode(&out, key, extra, dest, GIT_SHA1_RAWSZ, &scratch); - EXPECT(n == m); + check_int(n, ==, m); - EXPECT(reftable_record_equal(&in, &out, GIT_SHA1_RAWSZ)); + check(reftable_record_equal(&in, &out, GIT_SHA1_RAWSZ)); strbuf_release(&key); reftable_record_release(&out); } @@ -352,16 +343,16 @@ static void test_reftable_index_record_roundtrip(void) reftable_record_key(&in, &key); test_copy(&in); - EXPECT(0 == strbuf_cmp(&key, &in.u.idx.last_key)); + check(!strbuf_cmp(&key, &in.u.idx.last_key)); n = reftable_record_encode(&in, dest, GIT_SHA1_RAWSZ); - EXPECT(n > 0); + check_int(n, >, 0); extra = reftable_record_val_type(&in); m = reftable_record_decode(&out, key, extra, dest, GIT_SHA1_RAWSZ, &scratch); - EXPECT(m == n); + check_int(m, ==, n); - EXPECT(reftable_record_equal(&in, &out, GIT_SHA1_RAWSZ)); + check(reftable_record_equal(&in, &out, GIT_SHA1_RAWSZ)); reftable_record_release(&out); strbuf_release(&key); @@ -369,14 +360,15 @@ static void test_reftable_index_record_roundtrip(void) strbuf_release(&in.u.idx.last_key); } -int record_test_main(int argc, const char *argv[]) +int cmd_main(int argc, const char *argv[]) { - RUN_TEST(test_reftable_log_record_equal); - RUN_TEST(test_reftable_log_record_roundtrip); - RUN_TEST(test_reftable_ref_record_roundtrip); - RUN_TEST(test_varint_roundtrip); - RUN_TEST(test_key_roundtrip); - RUN_TEST(test_reftable_obj_record_roundtrip); - RUN_TEST(test_reftable_index_record_roundtrip); - return 0; + TEST(test_reftable_log_record_equal(), "reftable_log_record_equal works"); + TEST(test_reftable_log_record_roundtrip(), "record operations work on log record"); + TEST(test_reftable_ref_record_roundtrip(), "record operations work on ref record"); + TEST(test_varint_roundtrip(), "put_var_int and get_var_int work"); + TEST(test_key_roundtrip(), "reftable_encode_key and reftable_decode_key work"); + TEST(test_reftable_obj_record_roundtrip(), "record operations work on obj record"); + TEST(test_reftable_index_record_roundtrip(), "record operations work on index record"); + + return test_done(); } From patchwork Fri Jun 21 11:50:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13707434 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 87EB5174ECA for ; Fri, 21 Jun 2024 11:57:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971069; cv=none; b=ULlxqVVzeRoM4H+e6au7tGPbbi5OCVpcRlo70tjgtq1abKZ/e6I8ZKyZXw8YdzEitZGGePYZapTVqd35SL7/PuEieDpc0TLPArbr3Ld1UR9cWDI+yC0aSDUyrvKRvUGc6m9XK67X6m+Ra2ShJaRoGV0cEv9SXuUTYI1XKWm56gs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971069; c=relaxed/simple; bh=9c9jQ0KFEYeHYQ36bjp542+Yn4z95zobLhSO6s7RcMk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gncSPAcE23FUNxfSmV2ktGkwRKjGw2/hkWcuf7fxmUdO3GiCS4biQq5gcbczKg0Zz+p2KuL/suzxtSwf1YapI1W8V2/SwSO/HOz36VgyBvAOmX+m3apFTn2v6NJNhdpEyCy1BVyGF99+pkoHfvu3FSsROZsI112sLPKu0bzxtCU= 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=T3EnsMk/; arc=none smtp.client-ip=209.85.214.178 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="T3EnsMk/" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1f9aeb96b93so14681105ad.3 for ; Fri, 21 Jun 2024 04:57:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718971067; x=1719575867; 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=ojuWJXrxweF+iwiFe0whhzIAzLxRXjoT7fSsoiqm8A8=; b=T3EnsMk/y/cXhbi6Oisu+a2tS5rGxuJh/WfY4+rODPs3Nim4Lc1IMguzFiCvZrOQK1 7oKEiyPwKtRuNkZLVWiwDqcJqkJ1lCkRyLKY+eyX4r13Rmt6+QpuE7tFIay8ryyAa49v nII18H/DW0dBrPS2lTXPNSx92ak9JQL6eRq7Qq/+ZKPYPqqSeH/J0aJqYaoIqu/fZzn3 MPYrdAQFPvmIfN6wLnXmydSQHLXqe5NqFmLVMDxS9FjBBOjM6mlrWX7lSQNanEBBQV1M gdEbmfktiD6RKUID8F/Et5VG4D8MlN6qB+h2Bt3TH0ZsdfHOivELAZw+PgDEx5ogEUhb rIwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718971067; x=1719575867; 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=ojuWJXrxweF+iwiFe0whhzIAzLxRXjoT7fSsoiqm8A8=; b=ETRwa6Rk7tF+iX/ZV7DnRxhTSf13SkCVvQXCn2MgSdV5NQkPEcu6FLPdOF/3lhXeH5 TaC5uN74EZUbD52qMaWYxJi3kkhD1Rp4r3sBDbm2X27JZbkdk+zVRtuZB9rfZPI2AL8E 9gbMUQng7xgRue6NpSPWztU7NB+p2XV85X05znLeI2Rc8y0O9SsR0NpXYBJGXdDaJB6p WCoXwqpvpE5v/785QtnUnZW5s3P99wYZqSN3Cc6BBHIsxdTD0HS4TSVgTTcevSx1fclq QlVgcjfjzfw6+A+KWs8gPJjiq0i4Zb53j4dTNRlDiswcwJCjS5BPyXaL9YdwJ6dYJHNa sZpg== X-Gm-Message-State: AOJu0YyLgBfORjan6hZtD80obwSC1My0ca/Z/QL3ihQGTkuwIDCbFhbj AK332u62g56HLbBYcGfOxPuREhP6iFNLkYBDcOHuwTTIj/i4dBBo8sGc2w== X-Google-Smtp-Source: AGHT+IExOLrpKnJWrqBG2mXzharR31dfxXHSDhIz0NkE02ZVMJqTkbtIzy50+ANS8wdcrq/fjIr9Zw== X-Received: by 2002:a17:903:2341:b0:1f9:df62:6a9a with SMTP id d9443c01a7336-1f9df626c31mr33264065ad.20.1718971066942; Fri, 21 Jun 2024 04:57:46 -0700 (PDT) Received: from Ubuntu.. ([106.206.204.195]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f9eb3c5ee9sm12407195ad.180.2024.06.21.04.57.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 04:57:46 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 02/11] t-reftable-record: add reftable_record_cmp() tests for log records Date: Fri, 21 Jun 2024 17:20:57 +0530 Message-ID: <20240621115708.3626-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621115708.3626-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240621115708.3626-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In the current testing setup for log records, only reftable_log_record_equal() among log record's comparison functions is tested. Modify the existing tests to exercise reftable_log_record_cmp_void() (using the wrapper function reftable_record_cmp()) alongside reftable_log_record_equal(). Note that to achieve this, we'll need to replace instances of reftable_log_record_equal() with the wrapper function reftable_record_equal(). Rename the now modified test to reflect its nature of exercising all comparison operations, not just equality. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-record.c | 40 +++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index 1b357e6c7f..0cf223e51b 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -123,24 +123,38 @@ static void test_reftable_ref_record_roundtrip(void) strbuf_release(&scratch); } -static void test_reftable_log_record_equal(void) +static void test_reftable_log_record_comparison(void) { - struct reftable_log_record in[2] = { + struct reftable_record in[3] = { { - .refname = xstrdup("refs/heads/master"), - .update_index = 42, + .type = BLOCK_TYPE_LOG, + .u.log.refname = xstrdup("refs/heads/master"), + .u.log.update_index = 42, }, { - .refname = xstrdup("refs/heads/master"), - .update_index = 22, - } + .type = BLOCK_TYPE_LOG, + .u.log.refname = xstrdup("refs/heads/master"), + .u.log.update_index = 22, + }, + { + .type = BLOCK_TYPE_LOG, + .u.log.refname = xstrdup("refs/heads/main"), + .u.log.update_index = 22, + }, }; - check(!reftable_log_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ)); - in[1].update_index = in[0].update_index; - check(reftable_log_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ)); - reftable_log_record_release(&in[0]); - reftable_log_record_release(&in[1]); + check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ)); + check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ)); + check_int(reftable_record_cmp(&in[1], &in[2]), >, 0); + /* comparison should be reversed for equal keys */ + check_int(reftable_record_cmp(&in[0], &in[1]), <, 0); + + in[1].u.log.update_index = in[0].u.log.update_index; + check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ)); + check(!reftable_record_cmp(&in[0], &in[1])); + + for (size_t i = 0; i < ARRAY_SIZE(in); i++) + reftable_record_release(&in[i]); } static void test_reftable_log_record_roundtrip(void) @@ -362,7 +376,7 @@ static void test_reftable_index_record_roundtrip(void) int cmd_main(int argc, const char *argv[]) { - TEST(test_reftable_log_record_equal(), "reftable_log_record_equal works"); + TEST(test_reftable_log_record_comparison(), "comparison operations work on log record"); TEST(test_reftable_log_record_roundtrip(), "record operations work on log record"); TEST(test_reftable_ref_record_roundtrip(), "record operations work on ref record"); TEST(test_varint_roundtrip(), "put_var_int and get_var_int work"); From patchwork Fri Jun 21 11:50:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13707435 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 536DA175552 for ; Fri, 21 Jun 2024 11:57:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971072; cv=none; b=ZHMTzbhRPnTOk1bYrli/9FIT0KpaOJic/rpSgATcC1UvobbI28Zas2RGGD/wMbVUuN+12znM6+V3+UnrdgdTAsZQKyy8Uf044a7cIZXGsKlprqKr/8WEyq6NltizCBHdbojKqPxAdF0h28nxxVi20neIdBgm4AxBWiGINA1Y7jE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971072; c=relaxed/simple; bh=WcGJUDtVloXLVEimVxi+h81ea7dMs2LptXCXDaFIr/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g26cvMdZHZtVIVo0EkMbtZL5FGz3iWfj6YXAARnqomzyoBowJLKc+U2pHfa1A+t2ntNZlwjPuoUbFMngUz5m8Z+vCzV7oAFK1/1YF0/XQiQdlthMK0PeVx3QMvL0I9wFJ6srrxgCypZC9jbKOWsLVolRxQ4398XlzU0DDU9Ch3I= 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=f2GNMn04; arc=none smtp.client-ip=209.85.210.174 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="f2GNMn04" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-7061365d2f3so1507953b3a.3 for ; Fri, 21 Jun 2024 04:57:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718971070; x=1719575870; 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=iufUZiGIAT1BA18rMIbcTdxJaeP/q47DamJEmXGPIiA=; b=f2GNMn045ffnkw2v9dXr4Sil13mbMdjQA9KVjJ3jwb5JyoTPGkgaqoUujsbA9+lCUT gL2xC0CRLuLCCKIo9bdl8UNsewKTu2Ym6ENLD9FX8xvQ/LsmmrJylpM1pMofsdt1xeUd teeTI+5LE/i5tSzBd7IgCznwl9E77lpeDN0xNiSqajcBuby5CyxDCCfmOoLumUyvO+x9 a2E66Jnbq6DUtshsgTWgARMVMQ2T5BUju60rWujmoBEanM041+lAHJT3FkXRw4K/wKax Y/A4VIjeoFsAqXcyp0BsXKH71lQUk3BUW2Tn59eafzgdTyeoTnQ5m7jsOqk8nW/enNyu DsAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718971070; x=1719575870; 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=iufUZiGIAT1BA18rMIbcTdxJaeP/q47DamJEmXGPIiA=; b=L4tghD+eG/vC+58kNb/aTpyDM02R4kplW6C1kv+GRHymDklPJgNnSFmWEPZ3wXQf7S aADyaIb0BkJ/VS9KTGbUeODeWu6PwVeuEMJLCICA6s15VZpe3YnxUoAC1ILIwIPyfiYd 4OvQkb2j86RjxBqcgV9eXiDIS9jdNdZVTVqw17eWtrYn/Q3A3uEPonGS9wDmkDlAhE8I widojAAwpKWjs9bvkUGUoEpOwtk9kZzLnyBWMxrmZy2XfAnAlpVT6qKU3V7ZnV/Bx5uD gbYbdoMOWR10Nc0MCUglrQCn2kMEl21Zr8qq33jqmNpBC0I9/7kMfZ+n4G6KQYuR8Z0t 3jCg== X-Gm-Message-State: AOJu0Yz8rtpwoGz35ssXdJSwP151MgQvFok7WtBf3T/CBRk1lULBTIHI SJMmwttY+18hGr25fJ3pLoIyV0/FPQP+Rkc80XljD4SyRbShhQyz8Enuiw== X-Google-Smtp-Source: AGHT+IFlv01Wv7B6pfJepT7lqbI584j/YhtDh9dmIbZiJq9aZDP7XIqgAAUSU8tByJIxuHmb/S3Ytw== X-Received: by 2002:a05:6a20:bc82:b0:1b7:4527:e291 with SMTP id adf61e73a8af0-1bcbb3f3793mr8151974637.17.1718971070071; Fri, 21 Jun 2024 04:57:50 -0700 (PDT) Received: from Ubuntu.. ([106.206.204.195]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f9eb3c5ee9sm12407195ad.180.2024.06.21.04.57.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 04:57:49 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 03/11] t-reftable-record: add comparison tests for ref records Date: Fri, 21 Jun 2024 17:20:58 +0530 Message-ID: <20240621115708.3626-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621115708.3626-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240621115708.3626-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In the current testing setup for ref records, the comparison functions for ref records, reftable_ref_record_cmp_void() and reftable_ref_record_equal() are left untested. Add tests for the same by using the wrapper functions reftable_record_cmp() and reftable_record_equal() for reftable_ref_record_cmp_void() and reftable_ref_record_equal() respectively. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-record.c | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index 0cf223e51b..c74fdbecf8 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -66,6 +66,41 @@ static void set_hash(uint8_t *h, int j) h[i] = (j >> i) & 0xff; } +static void test_reftable_ref_record_comparison(void) +{ + struct reftable_record in[3] = { + { + .type = BLOCK_TYPE_REF, + .u.ref.refname = xstrdup("refs/heads/master"), + .u.ref.value_type = REFTABLE_REF_VAL1, + }, + { + .type = BLOCK_TYPE_REF, + .u.ref.refname = xstrdup("refs/heads/master"), + .u.ref.value_type = REFTABLE_REF_DELETION, + }, + { + .type = BLOCK_TYPE_REF, + .u.ref.refname = xstrdup("HEAD"), + .u.ref.value_type = REFTABLE_REF_SYMREF, + .u.ref.value.symref = xstrdup("refs/heads/master"), + }, + }; + + check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ)); + check(!reftable_record_cmp(&in[0], &in[1])); + + check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ)); + check_int(reftable_record_cmp(&in[1], &in[2]), >, 0); + + in[1].u.ref.value_type = in[0].u.ref.value_type; + check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ)); + check(!reftable_record_cmp(&in[0], &in[1])); + + for (size_t i = 0; i < ARRAY_SIZE(in); i++) + reftable_record_release(&in[i]); +} + static void test_reftable_ref_record_roundtrip(void) { struct strbuf scratch = STRBUF_INIT; @@ -376,6 +411,7 @@ static void test_reftable_index_record_roundtrip(void) int cmd_main(int argc, const char *argv[]) { + TEST(test_reftable_ref_record_comparison(), "comparison operations work on ref record"); TEST(test_reftable_log_record_comparison(), "comparison operations work on log record"); TEST(test_reftable_log_record_roundtrip(), "record operations work on log record"); TEST(test_reftable_ref_record_roundtrip(), "record operations work on ref record"); From patchwork Fri Jun 21 11:50:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13707436 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 AD617176236 for ; Fri, 21 Jun 2024 11:57:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971076; cv=none; b=nUJEGnwDFhD0sivEzpDqf6qGy74LgiYXUt1EA40AxgOEOPbYMhoAFLYM1ZxSqG/wbMuimHqDRDDYsCPtTH9TmfdsEnRsP60eMtC/TEri/xKWDJS3SJtVOlbNbdSqbpJI05A79aSfy5He7LHpbWFvEZhOZrPJSQCvsV5xyDDaiYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971076; c=relaxed/simple; bh=C+rt4kgPBITUeCtMbdeCdOEB9OGFuMd6xgbnL0s+xik=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i9OyrR9poYXrpZT3te8Uo0WLEVC77cdzfTZT7qnGdpoImKBUdHKDjKEikaLnOWqzFZ/EzQ8k+OcNrTrfAq7Sy1aDl+AlmX6BkLa57tTdnPyNbKwJsm+6Q02UjHKkdmYL6L4OIyD1x+2b1XSpXlUdxJaacNw8EjsW56uWXuuijpo= 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=IbiH9XBf; arc=none smtp.client-ip=209.85.214.180 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="IbiH9XBf" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1f9aeb96b93so14681575ad.3 for ; Fri, 21 Jun 2024 04:57:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718971073; x=1719575873; 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=XIx8GS86bk8SfKIL2syVgphvVAr1B/g2nHCWHuiaV5U=; b=IbiH9XBfvzwlpwIvKUc1vmyjP7prVcHGlMd4jQcDiawZNg2woiHqspx2xQUTpI2125 4clq2ZHyDkxW7EiU93jhvYJ1TKj5E3BmB1MBw5IIKZWvaDqnb0CEOvUuuHiyZ8/60m8x ZvPeOqi46uc2MEsoAR53018HyL8Tg2zGpSeKeCtAprAiYIbqj3lRiZwcO3/43912JkV9 y03HUFYLGc5RpkBNUse4Z0djLM5p59ej94tMwaqICyTtqIEre74QgJKU1j0GyJQEDL+Y K4chw/9ureb6lmAYEkXFYRmCpqHsLCMgMqcL5pDrJf7207Rs0kk4S0U6AzT5mfW+mI+1 Sf7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718971073; x=1719575873; 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=XIx8GS86bk8SfKIL2syVgphvVAr1B/g2nHCWHuiaV5U=; b=n248qcX20tnKPPA5YYnsgopnFbCWWSgwNu2W3Dumj/qyfECMvjAKfhy3Vd1W1QuVER /V0kmFB9wXGSiVq725+s0QiX5xI7rL6pU+8hG2/TWYn3F+M0FgKtismMCS0V3tSk5WEs wapCjwtrHrlL4qwqTQhnM/CbzEtC6cTD1hsqQ6PUIsOplDOgIGRr7HiPWs4aJZrNz8im owmJ6tjIqvp2iVEnhsdAaONB6T6IquySCNdICBnXCHz99jIfUdyUFZtGR9eYmq5F/C9D mU2O0fYvKpYyZ5y47WzqdvKEMpSD0F2q3ihas/CLznwKZBMDFj9mo4nYwTa71yGloZNV deIw== X-Gm-Message-State: AOJu0Yyy5GVTeMY9Hn5hTkylDsevBpd+OVABmMLsWj1riBLwKZcpErFj 4udyhYJ6D29qIXm5VVt0Gkb6nJirUVSawg0qG6qsnwSdwPDl9tn45HdeTg== X-Google-Smtp-Source: AGHT+IFENjEVZZTHYF+ZuHO7elkKDUgxmkny8hqCo7M9bGfuXA4Ml5aRrk15L/VPK8jy8E/4pV6IQA== X-Received: by 2002:a17:903:190:b0:1f9:ad09:e677 with SMTP id d9443c01a7336-1f9ad09e7aamr91394345ad.60.1718971073144; Fri, 21 Jun 2024 04:57:53 -0700 (PDT) Received: from Ubuntu.. ([106.206.204.195]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f9eb3c5ee9sm12407195ad.180.2024.06.21.04.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 04:57:52 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 04/11] t-reftable-record: add comparison tests for index records Date: Fri, 21 Jun 2024 17:20:59 +0530 Message-ID: <20240621115708.3626-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621115708.3626-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240621115708.3626-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In the current testing setup for index records, the comparison functions for index records, reftable_index_record_cmp() and reftable_index_record_equal() are left untested. Add tests for the same by using the wrapper functions reftable_record_cmp() and reftable_record_equal() for reftable_index_record_cmp() and reftable_index_record_equal() respectively. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-record.c | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index c74fdbecf8..9644f1de71 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -365,6 +365,43 @@ static void test_reftable_obj_record_roundtrip(void) strbuf_release(&scratch); } +static void test_reftable_index_record_comparison(void) +{ + struct reftable_record in[3] = { + { + .type = BLOCK_TYPE_INDEX, + .u.idx.offset = 22, + .u.idx.last_key = STRBUF_INIT, + }, + { + .type = BLOCK_TYPE_INDEX, + .u.idx.offset = 32, + .u.idx.last_key = STRBUF_INIT, + }, + { + .type = BLOCK_TYPE_INDEX, + .u.idx.offset = 32, + .u.idx.last_key = STRBUF_INIT, + }, + }; + strbuf_addstr(&in[0].u.idx.last_key, "refs/heads/master"); + strbuf_addstr(&in[1].u.idx.last_key, "refs/heads/master"); + strbuf_addstr(&in[2].u.idx.last_key, "refs/heads/branch"); + + check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ)); + check(!reftable_record_cmp(&in[0], &in[1])); + + check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ)); + check_int(reftable_record_cmp(&in[1], &in[2]), >, 0); + + in[1].u.idx.offset = in[0].u.idx.offset; + check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ)); + check(!reftable_record_cmp(&in[0], &in[1])); + + for (size_t i = 0; i < ARRAY_SIZE(in); i++) + reftable_record_release(&in[i]); +} + static void test_reftable_index_record_roundtrip(void) { struct reftable_record in = { @@ -413,6 +450,7 @@ int cmd_main(int argc, const char *argv[]) { TEST(test_reftable_ref_record_comparison(), "comparison operations work on ref record"); TEST(test_reftable_log_record_comparison(), "comparison operations work on log record"); + TEST(test_reftable_index_record_comparison(), "comparison operations work on index record"); TEST(test_reftable_log_record_roundtrip(), "record operations work on log record"); TEST(test_reftable_ref_record_roundtrip(), "record operations work on ref record"); TEST(test_varint_roundtrip(), "put_var_int and get_var_int work"); From patchwork Fri Jun 21 11:51:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13707437 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 CE186172BC7 for ; Fri, 21 Jun 2024 11:57:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971079; cv=none; b=MhKdCezJWQgPTapxuKj7avvc+oNZQGn2HeYcPYAfKHHr0+msNAguKfiRJO+G9SYc8R8zQ8VbjL+v0vGD41mjPjclxxOy+jNcsn3V/5eiMeSQzBKzTNCj+3jvkgepjJPl587WkKweaNr6FOJd1XBbv6GIf/w+GTIR1ZIK904zV1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971079; c=relaxed/simple; bh=649sxEkfbyEgKdBSmEH4E2AYxN2zPI5KRDKA1QfzRhw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CwJgMfZE4DQ6QsGHs1dZGLIOY0EtD9yL4hSuetajfqF8/5ixQemPozP+d2p//1NlUGP57h97vbOGyu3wM6gggfzm4hodHU0YS9ossR5tOwjLhLpeDPEftYqm+sk7A95908V7W044gp9flgndQN/mf5VwZJgYLdqLm09bo0ZvzXs= 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=Wtnx/XGP; arc=none smtp.client-ip=209.85.214.170 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="Wtnx/XGP" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1f8395a530dso15175715ad.0 for ; Fri, 21 Jun 2024 04:57:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718971076; x=1719575876; 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=mvYjIX0ZHgx6Fah/TwVqpIKAcMFiTLbs4NjX2pklekk=; b=Wtnx/XGPSulXXry9OQQjQEvV8wTt69Om7r74wFWesd2rtiLuX0L36F5+NbdTueHomy 8Qeqr6R8SDZEFfM4Y83CvBr3JkMIxNm20K0nkuehQrcTKE14lzFFJ7KEdWXzDK6ewMam ffpvn9USK0wQoGsb1XPyaW2weK34F7jFvMRKwMww6rWEYO3o4UYsVCCBw3tUK0Ua8gCm tM8xVhnXioKH5CEJNG1SzuZ2q3c7c3unZck9Puie/FOgGS63S5vpmg69vtFyEHGQupp5 w9ghevXd+jxfFDmG0PgEWnCsM6ITTTulRyhMn4DdvvTZIBaS8Vt20g8GjRHI8hxe0KW2 uqng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718971076; x=1719575876; 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=mvYjIX0ZHgx6Fah/TwVqpIKAcMFiTLbs4NjX2pklekk=; b=vDQFzwEgBCiwJFCR23MYqhyzt6BTNPXgXq0UIu3HX6OyzxANNIXAIbQCImCjukzOgY 8bz2ESDCjaSy8gfHf9YTqlxThbzMaa5wB67GFlgKhIq+3RGTG3iTGA7/wWfLl86XaKDa qkHwbDYP2vh7NG8eWio9Ilg9iu4SL1H6ghDIaJYDvEbsglZjwvDjQ9DfRH8Qhz1h/AMd xKE39WSyFGWaThTIJwRM6GHW/vDuQ5vynE8RqzumBokTqDlCuUJT9hSC2fKmmsHCHQqd EvXlvhMMkcm5c2dlWEacpSMbVlTBpfWUXvfpdNQxYZXCdjfbYNUnEmarLoZpTobLSA5K P5Vw== X-Gm-Message-State: AOJu0YyMjyY0e8SgOzrfuSNJ5re2pT4GRl9MUcrp6S6IoquHM2EA9nAS kWCsEyH7cZVTyqyQHDBZfWJ4sjDaKGksE+lLrfzIZ47d40RehhsMO/Q5xA== X-Google-Smtp-Source: AGHT+IHQUEr7vfSrrniMEmv76YukFD1EYgnYT4D9bbet/D7Qn1YFxOB54PqhIkWqU307hfeAQoG3Vg== X-Received: by 2002:a17:903:1211:b0:1f7:3314:524a with SMTP id d9443c01a7336-1f9aa3bc7e8mr99341765ad.6.1718971076257; Fri, 21 Jun 2024 04:57:56 -0700 (PDT) Received: from Ubuntu.. ([106.206.204.195]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f9eb3c5ee9sm12407195ad.180.2024.06.21.04.57.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 04:57:55 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 05/11] t-reftable-record: add comparison tests for obj records Date: Fri, 21 Jun 2024 17:21:00 +0530 Message-ID: <20240621115708.3626-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621115708.3626-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240621115708.3626-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In the current testing setup for obj records, the comparison functions for obj records, reftable_obj_record_cmp_void() and reftable_obj_record_equal_void() are left untested. Add tests for the same by using the wrapper functions reftable_record_cmp() and reftable_record_equal() for reftable_index_record_cmp_void() and reftable_index_record_equal_void() respectively. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-record.c | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index 9644f1de71..1f9c830631 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -307,6 +307,44 @@ static void test_key_roundtrip(void) strbuf_release(&roundtrip); } +static void test_reftable_obj_record_comparison(void) +{ + + uint8_t id_bytes[] = { 0, 1, 2, 3, 4, 5, 6 }; + uint64_t offsets[] = { 0, 16, 32, 48, 64, 80, 96, 112}; + struct reftable_record in[3] = { + { + .type = BLOCK_TYPE_OBJ, + .u.obj.hash_prefix = id_bytes, + .u.obj.hash_prefix_len = 7, + .u.obj.offsets = offsets, + .u.obj.offset_len = 8, + }, + { + .type = BLOCK_TYPE_OBJ, + .u.obj.hash_prefix = id_bytes, + .u.obj.hash_prefix_len = 7, + .u.obj.offsets = offsets, + .u.obj.offset_len = 5, + }, + { + .type = BLOCK_TYPE_OBJ, + .u.obj.hash_prefix = id_bytes, + .u.obj.hash_prefix_len = 5, + }, + }; + + check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ)); + check(!reftable_record_cmp(&in[0], &in[1])); + + check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ)); + check_int(reftable_record_cmp(&in[1], &in[2]), >, 0); + + in[1].u.obj.offset_len = in[0].u.obj.offset_len; + check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ)); + check(!reftable_record_cmp(&in[0], &in[1])); +} + static void test_reftable_obj_record_roundtrip(void) { uint8_t testHash1[GIT_SHA1_RAWSZ] = { 1, 2, 3, 4, 0 }; @@ -451,6 +489,7 @@ int cmd_main(int argc, const char *argv[]) TEST(test_reftable_ref_record_comparison(), "comparison operations work on ref record"); TEST(test_reftable_log_record_comparison(), "comparison operations work on log record"); TEST(test_reftable_index_record_comparison(), "comparison operations work on index record"); + TEST(test_reftable_obj_record_comparison(), "comparison operations work on obj record"); TEST(test_reftable_log_record_roundtrip(), "record operations work on log record"); TEST(test_reftable_ref_record_roundtrip(), "record operations work on ref record"); TEST(test_varint_roundtrip(), "put_var_int and get_var_int work"); From patchwork Fri Jun 21 11:51:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13707438 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 DF4F1172BC7 for ; Fri, 21 Jun 2024 11:58:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971082; cv=none; b=JsFZbpFxIGGMI5xsRomCQ3lAgT5aOXLcdJ/O9vqu+kTCPXbNavlqZWhcp7Xoc2LT84A+eJ1MKMzTImD6iP8+Nfo6ho+LqvavDBOyHb0o1zikcup7L3MZS5lBFe31VfvQqa6tvF0CRqdcFNsr1I7TVhtOkQSBHg9g8WQfxFoAwKU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971082; c=relaxed/simple; bh=0KGmpyY77eQcUQF5ZB3LaGt6atjQSoxI7Grq13CmUQM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WCpGiTVQpkkz7KT2ybk+N3o/cgG7Os2sdRt5/MynpQrHokDtS1ZH2C0jnKVaqxAvNG5A7RHvncu2DInZ/Ix6OuRdk9D10xqhkgER9j1dYr9VagIDuGheqFBocOJ0Mq5G3lRufyO/CUFYD3BK6O801jgjN2yL4LXFx+GRuTk9d2o= 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=QyeZEhy2; arc=none smtp.client-ip=209.85.214.181 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="QyeZEhy2" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1f480624d10so15583305ad.1 for ; Fri, 21 Jun 2024 04:58:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718971079; x=1719575879; 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=HRF+wbaRaaKwoot8inbQdv64fAvqiwZLW0ytW9NdOC4=; b=QyeZEhy2gnVGcFbg+kfqHbo7LEhTZmWB2JrD3h3xu9E1zTQ1L6IAQFcSweFeFnRobU BNJt+T9s4jYw9gIa1DdBszFYzZpNejAyXTYVwyHo0GyDj/9Ni4lf7UQc/6ObNN/mZLY9 qR4rowKYJ4ktvhCg0dmUEGorX0zvBFz9Ohta2i+pgd2TEoUA9RqfJFD5SLN+462l54jK 8BeW72dhn8mH4KRG2/8INZakE2A1lj4VpiavNPX6IHg8ayH7yg48PeIhaxS4OYXbcUBO aY/Nc30UPJsrVkReKehwJIDbh3NFJj7Qs+N3jqKJR6V6TS2M7jrPYfviMx9d+ILdP8l1 AZMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718971079; x=1719575879; 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=HRF+wbaRaaKwoot8inbQdv64fAvqiwZLW0ytW9NdOC4=; b=MlGdK4Qg+mmeY4eoS1wIea+0YekR2kTyF6GHLQGKV3yJyAWyx37Q80ssnXSynr19m5 ov6nflSGFFIWHC+MDUL5NZl8AgE2YmurfKiqWleDDphw1laOCi9F8TaDyZ1f7OcaXxdv Lld5eaTJdQ8zOh8A4tmp5wNkT8YXHOOexwX63UBPYlINOSLEDz7bLR1ue13mnESzIFEX 9zIG58o04XkJ3xViercyl+BtwR9wd2IW2GxcWuzzcUtB4i5VBi9TTzB8ggcp4X8Meb6i LjxFZQ4LSA8UqL1l8oKynUF6Q8h4klWUYbJhR1rM7wZF7h80RXEP4oRaojUJ3XgvN42u cbnw== X-Gm-Message-State: AOJu0Yyywo7dtczV8MhVD6Q1yQ4r+KdaRoTF+jiZvw0YbrazdwW6Uup2 MujYyK3oXESsAZIUwpLf616aHO8GOpK1TOC9jbzlOQo42w67/hvLZ/JdtA== X-Google-Smtp-Source: AGHT+IGRO06Is5xQDRH7gfNSjeXJk0MGQB/PTyKtbgWRALCaSNhcyQ+DksWrUhFV51x4MiOqjmYDCQ== X-Received: by 2002:a17:902:b7c1:b0:1f6:efd9:bec4 with SMTP id d9443c01a7336-1f9aa3cedd2mr67794595ad.19.1718971079295; Fri, 21 Jun 2024 04:57:59 -0700 (PDT) Received: from Ubuntu.. ([106.206.204.195]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f9eb3c5ee9sm12407195ad.180.2024.06.21.04.57.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 04:57:58 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 06/11] t-reftable-record: add ref tests for reftable_record_is_deletion() Date: Fri, 21 Jun 2024 17:21:01 +0530 Message-ID: <20240621115708.3626-7-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621115708.3626-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240621115708.3626-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 reftable_record_is_deletion() is a function defined in reftable/record.{c, h} that determines whether a record is of type deletion or not. In the current testing setup, this function is left untested for all the four record types (ref, log, obj, index). Add tests for this function in the case of ref records. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-record.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index 1f9c830631..cbc2ce93b2 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -108,6 +108,7 @@ static void test_reftable_ref_record_roundtrip(void) for (int i = REFTABLE_REF_DELETION; i < REFTABLE_NR_REF_VALUETYPES; i++) { struct reftable_record in = { .type = BLOCK_TYPE_REF, + .u.ref.value_type = i, }; struct reftable_record out = { .type = BLOCK_TYPE_REF }; struct strbuf key = STRBUF_INIT; @@ -121,15 +122,19 @@ static void test_reftable_ref_record_roundtrip(void) in.u.ref.value_type = i; switch (i) { case REFTABLE_REF_DELETION: + check(reftable_record_is_deletion(&in)); break; case REFTABLE_REF_VAL1: + check(!reftable_record_is_deletion(&in)); set_hash(in.u.ref.value.val1, 1); break; case REFTABLE_REF_VAL2: + check(!reftable_record_is_deletion(&in)); set_hash(in.u.ref.value.val2.value, 1); set_hash(in.u.ref.value.val2.target_value, 2); break; case REFTABLE_REF_SYMREF: + check(!reftable_record_is_deletion(&in)); in.u.ref.value.symref = xstrdup("target"); break; } From patchwork Fri Jun 21 11:51:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13707439 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 DCB76172BC7 for ; Fri, 21 Jun 2024 11:58:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971085; cv=none; b=GYVBGfdXcgdfB4/TZHq9aDL/2436JRf4+sjieorvCc+c0TJ8NglktzyvoB5aAUDGBiH7lxHVySv3n+TjrtdcA/i4bOGyN8p0UYbft4oTb2hAnOigz6mAH1hO9/xfJkDDHcQPhWHuqON95Qv/z4n6Z9KLYIGt7P/jS7F90VOMF8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971085; c=relaxed/simple; bh=NRJZPoMrg9FpbLJeDirocCZmg3nnkmqfTIQubgTedVA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X+3nSYaW2POSZKeNpa75XGGRIIokUwhFwkJXPcQxB7PHNB/hjq0fAYcAbW81GVemf+8jPCW/rGpC1DUfo1rVMHElFagmE9UQXaLj+mF/gy+P26PwCfjc+tBzMVQOfWB1xRE5RnHH19mzxm8nINvEBycSdSiwAYEhc8qo/WhgXNE= 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=croj4D13; arc=none smtp.client-ip=209.85.214.182 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="croj4D13" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1f862f7c7edso15777735ad.3 for ; Fri, 21 Jun 2024 04:58:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718971082; x=1719575882; 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=0K52JLzcWFaK5zDwjskdDWV4KeyY+dwCntcyvt9vJgk=; b=croj4D13o2vZ4dY2Z9PR8x362qaCCrLsJa9Mtl9cTnAUd29ERcy9zzQbAPzWq20jQX qJbUedYDf971I9PI+QfDz500n0xGANrPjmVL7MN2Xvr/gvhanbz0L3+VmW/30r1MUSYZ Qi8zkwoog/8e1tKUeMmLOK7oaqSMMFBzPVU2s6jyl/Pq3HV7e/na9XidGOV9leFme4MJ 8KN6LsL7dtDX9gn7L1EA9/0HV63idGS/qrqvTdc//3V5eL2dxOEPRBKhmbPUDMMRECNM O4N12nKOpFZe3kzXn1hi39sBPDT/O20cMmEhY50t3X9Pw2keivSFC+wv0AY0PU5hmWho jeLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718971082; x=1719575882; 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=0K52JLzcWFaK5zDwjskdDWV4KeyY+dwCntcyvt9vJgk=; b=C4SULSOFIWgxW+CtMsIds04wyO+jghKHY57Xy/NcCc5r5Sxw7eSPU62esxNVSsdcQy U9HzNP6mDydjr7lxB0bRWeAT7gsjANJN75E1bBGn6TT+zqV8ANGRLvPYFE339r6aEzyv Z7OrXJJJygsXTl/EItWHfUyhzN7B3dAybzipwntUZVnyCVCKLX7w89dQa47hG8cBP51G WKMycmMAn93ceVti286DAjbNgM1a/u8PdCNEPtXOsBCrD3iAg+kPBhAT2YEh+IifEipD dQ9+0TzS8sxtII52EjmlP7gxKXF6DroBYDdpKHrwmw1AMMxTM9C4HWjWmuO0oRgX5MR3 YPjg== X-Gm-Message-State: AOJu0YxX/skP6RqVWrj7B6eBtN5LDTkWirO+yI910POfSSgYO9ryZVhf np6yPhnJh1ArEbfx1826SAU9rj84CqMLeAxPAOeEXqkbwkBl+Qmjj9CBkw== X-Google-Smtp-Source: AGHT+IFQ0nLFRhLRy6UuK9DzRrEv7QKlHhCWvz+MLHWijUmliNb/7U7wVHrux9XGoNhZEHjIrr6srw== X-Received: by 2002:a17:902:e812:b0:1f6:7f20:d988 with SMTP id d9443c01a7336-1f9aa44fd68mr95541235ad.42.1718971082348; Fri, 21 Jun 2024 04:58:02 -0700 (PDT) Received: from Ubuntu.. ([106.206.204.195]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f9eb3c5ee9sm12407195ad.180.2024.06.21.04.57.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 04:58:01 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 07/11] t-reftable-record: add log tests for reftable_record_is_deletion() Date: Fri, 21 Jun 2024 17:21:02 +0530 Message-ID: <20240621115708.3626-8-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621115708.3626-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240621115708.3626-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 reftable_record_is_deletion() is a function defined in reftable/record.{c, h} that determines whether a record is of type deletion or not. In the current testing setup, this function is left untested for all the four record types (ref, log, obj, index). Add tests for this function in the case of log records. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-record.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index cbc2ce93b2..b2e1a892c0 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -231,6 +231,10 @@ static void test_reftable_log_record_roundtrip(void) set_hash(in[2].value.update.new_hash, 3); set_hash(in[2].value.update.old_hash, 4); + check(!reftable_log_record_is_deletion(&in[0])); + check(reftable_log_record_is_deletion(&in[1])); + check(!reftable_log_record_is_deletion(&in[2])); + for (size_t i = 0; i < ARRAY_SIZE(in); i++) { struct reftable_record rec = { .type = BLOCK_TYPE_LOG }; struct strbuf key = STRBUF_INIT; From patchwork Fri Jun 21 11:51: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: 13707440 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 A377D172BC7 for ; Fri, 21 Jun 2024 11:58:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971088; cv=none; b=Dj6u16Anu8favtzsY9Y2ABth/zPvZjozC6ShEbOCw8b6anYakvif5kR82OLO6N/B1UdvkibyybkMKApxX4it2Wsiq4D1np9D/KivZk697A1kc5L0a0LwgPwhbhmfX2asvNc5rdpptdSYBBcIScSBanE0kIfnzVLQnVFLpAmuD0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971088; c=relaxed/simple; bh=zVfrphsMh6HB8ICsJkGVrifwl1JaA+OPf/cVtHT0N0c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kBfiiVVAK5hRBFaZnDVGlAxk6Lh7Ru9buDc9uwukXTY2yzVXgpDt77RIpEf0EuNNdVZ/c6yQVzu7bwvmsSUaQQFWP0/uC4vcZZuZ50CeRiVMC1nwWMdjag/FcL0CtFLwP8fUhrVhHSUt9B/KrIuCceGQQJyv+GmOBBUCMp0AvLo= 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=aQNnr+Po; arc=none smtp.client-ip=209.85.214.169 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="aQNnr+Po" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1f6da06ba24so14245505ad.2 for ; Fri, 21 Jun 2024 04:58:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718971085; x=1719575885; 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=fPwUNDCbHOeI0ietUFo87O+sWRD05rlCSy3ODHoOK+s=; b=aQNnr+PomOjpZaHJ1sPcjo/Bs4a3At4o7qybW2eQTWUaeM4D7Sx4tr4s1vrCp/G1Pr mPV5CqsQEN/8ZarEPG4MS0WCll3vi+PNZG4llAx3iH/u4F7gUYjVeWfFDzot3LfKdQWt BI9ewgzPHKVU6E1eA82dXr/SjG8qlRnWvi/lM9jw/lBPsFPuerO//8xL3trzpp77C3Hl tPvW3zUcwNtKQwgpUbzXHdtLTr7IdU+tWZZe8zX2Qku1Ut65TNp6tWmgbl+SONrawr1l aQgHVNdilKc/A18s5opfUWXo7JCAtRxJ78qEzVFLLaeEkMh0bXPX5V1Eh3pkFQunCi78 bZ9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718971085; x=1719575885; 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=fPwUNDCbHOeI0ietUFo87O+sWRD05rlCSy3ODHoOK+s=; b=tElncZ+XrcX/fpLj+ZR7j/5XfQVQNrghm2Od05iYvxsf3CmfwKadnHpqCqtxXzJBqn 7Tr9Yd2wZ8Of1omJmZ9tDN6DB0eEkIYuo0rULlzMvDbuDo4sNAtrR86CAQv3VFCuC3o6 snV3Ku9Y4JlrZg289oXVqEJmYavolxx+4WgWs/AbT/FvuMQiEwjwNPHWDTGS9W+XYWO5 4EBJbigjzvpPP4z0+3y3TmvquipNlwydt5snF8BjLPSSxohSi7frQuRtN9ZcqBSNgHgN N++9xnMIg20bKh/F9Kqp+4KLVSQ3dJJMoQbHhX4VoOYmxrwU8GMALrDZbAQBd42FLANh aWnQ== X-Gm-Message-State: AOJu0YyJEQ7VJzDXLxWiTckIxfpKabyLZzt3JXl/wZoszcDMpcCMuyQU CRLGCcZXBO2zauQwuOb/5Z/ozwVv6wpMycICnIwjgdp4yG8X7nN6miDf6A== X-Google-Smtp-Source: AGHT+IFv2b88fN5+9Sx4z7RgW2JA2OHMRUU4SncBCO/yi7KVr6c4D6dx+LWHvDe8NlECMgZztieWtQ== X-Received: by 2002:a17:902:6e01:b0:1f6:a1c:e5b5 with SMTP id d9443c01a7336-1f9aa3db4c1mr64419675ad.24.1718971085339; Fri, 21 Jun 2024 04:58:05 -0700 (PDT) Received: from Ubuntu.. ([106.206.204.195]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f9eb3c5ee9sm12407195ad.180.2024.06.21.04.58.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 04:58:04 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 08/11] t-reftable-record: add obj tests for reftable_record_is_deletion() Date: Fri, 21 Jun 2024 17:21:03 +0530 Message-ID: <20240621115708.3626-9-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621115708.3626-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240621115708.3626-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 reftable_record_is_deletion() is a function defined in reftable/record.{c, h} that determines whether a record is of type deletion or not. In the current testing setup, this function is left untested for all the four record types (ref, log, obj, index). Add tests for this function in the case of obj records. Note that since obj records cannot be of type deletion, this function must always return '0' when called on an obj record. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-record.c | 1 + 1 file changed, 1 insertion(+) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index b2e1a892c0..766431ca67 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -395,6 +395,7 @@ static void test_reftable_obj_record_roundtrip(void) int n, m; uint8_t extra; + check(!reftable_record_is_deletion(&in)); test_copy(&in); reftable_record_key(&in, &key); n = reftable_record_encode(&in, dest, GIT_SHA1_RAWSZ); From patchwork Fri Jun 21 11:51:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13707441 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.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 B7EC917555C for ; Fri, 21 Jun 2024 11:58:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971091; cv=none; b=c94ccT0k63iSACzvpLAcXyfnEEiNX9Vr4SAmZQoQgeac8ooD75frWYbBKQX5suwqNyQZjPlhLcno7p/gjiIO/1LpNnHuL186rYTaaTXsCxOAYt9LEAbr2dwKdZ1D568B/TAxKlyEtaIgaFMq4XNntpa5r6UtJgZo8QK1+QMlso4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971091; c=relaxed/simple; bh=Sq5GZ5n4gXFhI+9ReIFRaAxeeXg0NM+fqxYeo+aH5iY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jVzo/k0s8V6jz2VUAd8Y77HOw7jeBeIMjdTE0RpP+PQQYCU3yHkn9rZ/HQbGurYgyHpXeBpgm+kO8FRlcpRnhd6QyiG+p5ipHpxDqZfL3ZPr4QTvMUo1LkB4RBm3QBMafp6pQxMvMFJL2F/38+AYOW2TgnU9MFEJ8H5t/pvH2vQ= 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=ZQV6K7LS; arc=none smtp.client-ip=209.85.214.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="ZQV6K7LS" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1f6da06ba24so14245815ad.2 for ; Fri, 21 Jun 2024 04:58:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718971088; x=1719575888; 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=k+3y7mPz92NANjorhbC4DDbfAxJxgWbgD2KSLpNT8sw=; b=ZQV6K7LSQDRjWC0HxDhzMh4DzFItst6rB6smSsxSI2EpLktZ781T+5wmm8Phjsnj27 VPrdIrLK4oOFqpXZqkn4uZfGoUZReY0RZfM4raPXSrZ1aGx4OytgYyThQfbvZ6pBWvij 7SaZs8qK4akslyBkwHs3MQocNExk1Pu4mPl5WhMJHYtywn1P4PRxNi7UxmCq8iCYr5l0 CbdhhFJil4TSfjVCvHskh3KM2fprFpixeDxnqrm9KlBolCo1xx2dtGmemtAJ0fJXQHLE oqBCl6P8rQ1NgTyaJyPlZokqsTalHhq48t43fskqqvPEwpihV4BmVKhfu3kcRCu56RK9 rEfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718971088; x=1719575888; 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=k+3y7mPz92NANjorhbC4DDbfAxJxgWbgD2KSLpNT8sw=; b=SFY95DQ+YjuKFfr9u+MnRocjJb4u/L1qNBfBvHRvuL/IKyPj83wN1SX4MGxCOX81+W eSVUWB9r3Ot1tqbnldZbKZZCK8zPL8SXOH59Md1IFiTFQDBP6As3V5p260NTtchW5wem CGbpp9pwCxbwJPodYtHtl32V994j1TpImc61Zeso/ydOVT+3M87QIZLVhDV5qtl1UEfG qrm2PM7Uy6L/BiTnAub2baefCmrL0TQHMUXSUpj0NFkA82XHYL2CpR7S1EbbibGlWXYi 0LMPAjXw31Xj2LWmMIIc7jpOgcVSTtxThCS8z1n7ZUHtLk1T2CI8YTEOAo0o1xl9bCJy 2IEA== X-Gm-Message-State: AOJu0YwP3GOMaWmdFJ5JGcVSw7dCjT5Wp1NXOOQWrh0T5hohn92hgeFF kyDlIIDGkx2gBMMocviT1/nKlfEEtzKKih6qqDGO61+kHYQnG2RSLeEHGw== X-Google-Smtp-Source: AGHT+IHdq+E76ynceahuWlGY6K1Pz1Zn4T6J4G0onE0f0mtxH8u6AvOb1/R2ze+yjx3gi58Y7ZpNAg== X-Received: by 2002:a17:903:1248:b0:1f7:2561:cd98 with SMTP id d9443c01a7336-1f9aa47167amr85984845ad.60.1718971088306; Fri, 21 Jun 2024 04:58:08 -0700 (PDT) Received: from Ubuntu.. ([106.206.204.195]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f9eb3c5ee9sm12407195ad.180.2024.06.21.04.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 04:58:07 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 09/11] t-reftable-record: add index tests for reftable_record_is_deletion() Date: Fri, 21 Jun 2024 17:21:04 +0530 Message-ID: <20240621115708.3626-10-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621115708.3626-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240621115708.3626-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 reftable_record_is_deletion() is a function defined in reftable/record.{c, h} that determines whether a record is of type deletion or not. In the current testing setup, this function is left untested for all the four record types (ref, log, obj, index). Add tests for this function in the case of index records. Note that since index records cannot be of type deletion, this function must always return '0' when called on an index record. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-record.c | 1 + 1 file changed, 1 insertion(+) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index 766431ca67..99ebfafe0b 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -477,6 +477,7 @@ static void test_reftable_index_record_roundtrip(void) reftable_record_key(&in, &key); test_copy(&in); + check(!reftable_record_is_deletion(&in)); check(!strbuf_cmp(&key, &in.u.idx.last_key)); n = reftable_record_encode(&in, dest, GIT_SHA1_RAWSZ); check_int(n, >, 0); From patchwork Fri Jun 21 11:51:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13707442 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 507B7172BC7 for ; Fri, 21 Jun 2024 11:58:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971094; cv=none; b=hK2a0jgYP1f6E+WdFR4fkZlWCjbQ11+Dd88F1XESIc6IQJXx3yXy60f/ZJxraA6Lu8nEc2RX270Yy2hXgsa5hjuDNnUR/7yT0d4Vre8IfkiPIQsgxxEJrYEbXZInmXleLCvFftekHSZtUmOXkFa75iyfM8j4FQcE2DjIHgbOAKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971094; c=relaxed/simple; bh=Ndcdob8r2Jh31THxqrvZ/dBBj/oUcVHXieE00bMNQp4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X6cZWEn4URDjFBhrJH2WtY/pZuRybesdl46OXQC16T+dXcOnczYAbHVBZcLvbEaw1JW2EbQIg+NmHNeCKb2m7XmZcaNb8IOLyO+6CjsWYSjVppubcVoQjxg8NsR1DOTez4ffxWnOmltCofwpf8FDqJ2qNmV62c7Dr/KXqJNnHTQ= 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=UmmiOg/J; arc=none smtp.client-ip=209.85.210.177 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="UmmiOg/J" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-70436ac8882so1566098b3a.2 for ; Fri, 21 Jun 2024 04:58:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718971092; x=1719575892; 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=G2ZmXn/Tj+1LbTcgE/6nRbu6BlL4xXg9bIFlee029iQ=; b=UmmiOg/J3OAfByEnt0P5Qgn5lDM6CjxNolrx/mGSjWrVMMsigu6MJuMucwH30DvmZo uRdOxleQnYrycTFXbmODiBQK7pjIP/QZxUVLIv4kuX14BbJJwpkqEA96FRqefzFt3V/K TyP72T2x2olhfM/Hod8oBIOj52mfL0mp+ycqp9aXDUADp7LIgoPHsNMOwH6oSoHO43JH fRFy8uVi+eTa3TNH7ISHd+SaR2ZK4LhlWvfke2zHscfQz68doKpA1IbiGVQt7x4YkpwY inPMlJHYvLsul+OxNZS15Kwyv+n80IOg9M98MECEPhJj52sa4KgC1x6j3TFVu37Im10M D04w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718971092; x=1719575892; 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=G2ZmXn/Tj+1LbTcgE/6nRbu6BlL4xXg9bIFlee029iQ=; b=oIKS0ddNI30aemzbFSneHKUP6NV8pF/oXzFxH/Qq0Dixjs11DUwdmKHHJmiJQN8anX l+rUQGdamoZigb8xQECkG7/wSk2PrgkrDs/RXekUxYbbdb4imolOM3mA8xiPJjbq+hm5 QHFbYty7z8lwboNvzQZo15efk+LdSRyNSRxStTzkqEEq4w62XHr2kWEyBwecbIe46/BH zs4M16ulhmxbwN3CLchDlmamMIZGy65/IrGsA5E+PheLYi00tsFZ1mPMYxbZz350/TCK 6xCkwls7mDwboFWxR9R1SD2l6UwdA7x7KDqqxXCGmWLn1WMkA5mtOItyC73x1Ks46d25 W5yg== X-Gm-Message-State: AOJu0YwTuHHCDQiZx90BBh9RcwkicHfCCxgsPj6jQ7z0/VCXrSiYV2zX vBZOSVfgxQfZalSWYtQN4jsJYeGHN+HZl+AHbWeYOt7TGuPAgXeuFOdABg== X-Google-Smtp-Source: AGHT+IH7cihgg6f3Z5zXuFSfghCF/kRJ0PX90wTOxwBGSjCOzdW8QRNaMJGU0brV4y7dVMe0xUEMyA== X-Received: by 2002:a05:6a20:c507:b0:1b7:b55:c87a with SMTP id adf61e73a8af0-1bcbb6037bemr8000743637.53.1718971092286; Fri, 21 Jun 2024 04:58:12 -0700 (PDT) Received: from Ubuntu.. ([106.206.204.195]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f9eb3c5ee9sm12407195ad.180.2024.06.21.04.58.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 04:58:11 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 10/11] t-reftable-record: add tests for reftable_ref_record_compare_name() Date: Fri, 21 Jun 2024 17:21:05 +0530 Message-ID: <20240621115708.3626-11-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621115708.3626-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240621115708.3626-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 reftable_ref_record_compare_name() is a function defined by reftable/record.{c, h} and is used to compare the refname of two ref records when sorting multiple ref records using 'qsort'. In the current testing setup, this function is left unexercised. Add a testing function for the same. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-record.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index 99ebfafe0b..b949617c88 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -101,6 +101,23 @@ static void test_reftable_ref_record_comparison(void) reftable_record_release(&in[i]); } +static void test_reftable_ref_record_compare_name(void) +{ + struct reftable_ref_record recs[14] = { 0 }; + size_t N = ARRAY_SIZE(recs), i; + + for (i = 0; i < N; i++) + recs[i].refname = xstrfmt("%02"PRIuMAX, (uintmax_t)i); + + QSORT(recs, N, reftable_ref_record_compare_name); + + for (i = 1; i < N; i++) + check(reftable_ref_record_compare_name(&recs[i - 1], &recs[i]) < 0); + + for (i = 0; i < N; i++) + reftable_ref_record_release(&recs[i]); +} + static void test_reftable_ref_record_roundtrip(void) { struct strbuf scratch = STRBUF_INIT; @@ -501,6 +518,7 @@ int cmd_main(int argc, const char *argv[]) TEST(test_reftable_log_record_comparison(), "comparison operations work on log record"); TEST(test_reftable_index_record_comparison(), "comparison operations work on index record"); TEST(test_reftable_obj_record_comparison(), "comparison operations work on obj record"); + TEST(test_reftable_ref_record_compare_name(), "reftable_ref_record_compare_name works"); TEST(test_reftable_log_record_roundtrip(), "record operations work on log record"); TEST(test_reftable_ref_record_roundtrip(), "record operations work on ref record"); TEST(test_varint_roundtrip(), "put_var_int and get_var_int work"); From patchwork Fri Jun 21 11:51:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13707443 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 553A3172BC7 for ; Fri, 21 Jun 2024 11:58:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971097; cv=none; b=WCkLN5tjkTtdAYJunxRu4C5Tu0KED/Pbnb54OkOsNgMKD3nFLppOBKHk1z7cZhX292pXUnxIwpUn3hZ/wqRJg1pwJtnrxCXTDBQZKzmjjgAt2cEVU1gkN3XsU0P/KAmMtqdCZ/RhIUzMXP/tl042QWoLP/Zt0BnTiV7kpyDg4HE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718971097; c=relaxed/simple; bh=5HuxIaQtqJmWfQDU4ik/hynvUZHvVbK4jJ7+Ev5MtTo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C8LQyknqwg5R2/XlzskWpjpvl+lZpbiYbVdaFiQJzjDoLsR8g6bx4iajIJ43qSJpaq3Fk/E1HdwlCV5Pe9QOtIc3H5tDjoMbV3bkF/PL+YD48qsUFdsg86NNl87AC8liZnG9joaErL01pZK/MfQcPAfd+YzxHgsd9YO1XTpV5aM= 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=cRJuUR6D; arc=none smtp.client-ip=209.85.210.181 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="cRJuUR6D" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-701b0b0be38so1703762b3a.0 for ; Fri, 21 Jun 2024 04:58:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718971095; x=1719575895; 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=OunLGBMB2r/G8aJZ9CXDWZYdLx8suSo4CLsmg1lc9II=; b=cRJuUR6DXOIfJC3Itki/DzxWGhxOcuFNWqd9hYExOA1LEU8AqrOu8+d47GEWHA70OJ F372R0A/nlaobqsePlA332rCou44eQMZTyVPpFb/AIM2cwkMgkiUNkt9vls9f8AUjRNT rilas4VfSeDoTWC2lk1eknHjJ2w4Jl++UbWKofhkLZVWazPENV8OtLnhuc8t19b1c5Xk u0i3vupHd1S8UcbR9JKTD2b+1oqWjLv71u8IvcwKNalVKRGKf7lOTMdYMYJHXlh/okI0 4AnEZhs52ibOsIfk5S46HLM+x5a1OQFyd78OqmGpsgpexfbJAYbWIC2zK1J7YRuQ4er0 xg9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718971095; x=1719575895; 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=OunLGBMB2r/G8aJZ9CXDWZYdLx8suSo4CLsmg1lc9II=; b=i6mJttrzhhhLrD1rFdsen5pP6XELtkuGu5R5zFvdQ5cy7eAkGl9xMoVHlTwrvj27Qq vF5fmUAGmzgxIdOPrMWFMUbySDZL8APD5X4OpzsG2D4RD8H29af2zcBY+sgWk8HNxsZi b0dQ5HMeDEusZepHFvOjRc32bSydaBdkNvivfZACYGmRKXK2QoXXEw914lezh2ZtfB48 c3lCZuU/5grUiUqbVIdr1pSFcnDdhw4ETCmNTsOi13OoWOz78yEyQhiO8hBBW5+EY8m3 n/l2mnBBLhO4Mdd2YtqILWwE+vuk1q32SIEqaABznGtBxW1fSwbPfzJKZJkaXEA0Sueo gdpA== X-Gm-Message-State: AOJu0YxRt6jJPOxszq8Efe6jfAOf29NoQd9CsLA8nNi3fJEPqYGhe6bX M4B8AswPK41XC6gpoPbFO9HUNN+4KhE0vGP0O7oBgxHrpsh31MCjdAkX8Q== X-Google-Smtp-Source: AGHT+IEMAKamZkUPVU+XD7Fs7FOIyCFai/Ksgd5cyYCwuIlzcTV8N2c7cuRG3/jRF6omO6FrA5fQgw== X-Received: by 2002:a05:6a20:47dd:b0:1b6:f34c:95b3 with SMTP id adf61e73a8af0-1bcbb60fca3mr7260862637.59.1718971095268; Fri, 21 Jun 2024 04:58:15 -0700 (PDT) Received: from Ubuntu.. ([106.206.204.195]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f9eb3c5ee9sm12407195ad.180.2024.06.21.04.58.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 04:58:14 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 11/11] t-reftable-record: add tests for reftable_log_record_compare_key() Date: Fri, 21 Jun 2024 17:21:06 +0530 Message-ID: <20240621115708.3626-12-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621115708.3626-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240621115708.3626-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 reftable_log_record_compare_key() is a function defined by reftable/record.{c, h} and is used to compare the keys of two log records when sorting multiple log records using 'qsort'. In the current testing setup, this function is left unexercised. Add a testing function for the same. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-record.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index b949617c88..d480cc438a 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -214,6 +214,30 @@ static void test_reftable_log_record_comparison(void) reftable_record_release(&in[i]); } +static void test_reftable_log_record_compare_key(void) +{ + struct reftable_log_record logs[14] = { 0 }; + size_t N = ARRAY_SIZE(logs), i; + + for (i = 0; i < N; i++) { + if (i < N / 2) { + logs[i].refname = xstrfmt("%02"PRIuMAX, (uintmax_t)i); + logs[i].update_index = i; + } else { + logs[i].refname = xstrdup("refs/heads/master"); + logs[i].update_index = i; + } + } + + QSORT(logs, N, reftable_log_record_compare_key); + + for (i = 1; i < N; i++) + check(reftable_log_record_compare_key(&logs[i - 1], &logs[i]) < 0); + + for (i = 0; i < N; i++) + reftable_log_record_release(&logs[i]); +} + static void test_reftable_log_record_roundtrip(void) { struct reftable_log_record in[] = { @@ -519,6 +543,7 @@ int cmd_main(int argc, const char *argv[]) TEST(test_reftable_index_record_comparison(), "comparison operations work on index record"); TEST(test_reftable_obj_record_comparison(), "comparison operations work on obj record"); TEST(test_reftable_ref_record_compare_name(), "reftable_ref_record_compare_name works"); + TEST(test_reftable_log_record_compare_key(), "reftable_log_record_compare_key works"); TEST(test_reftable_log_record_roundtrip(), "record operations work on log record"); TEST(test_reftable_ref_record_roundtrip(), "record operations work on ref record"); TEST(test_varint_roundtrip(), "put_var_int and get_var_int work");