From patchwork Tue Jul 2 07:22:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13719069 Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (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 C3A44372 for ; Tue, 2 Jul 2024 07:49:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906587; cv=none; b=tdxoN18byINM9NbLI2iDsl97L05SQLGgjDxUSTxMxLw5nQ8+I+Q/pdw55aqnTQOjo3bKx7xnug4I98LykCZ/Rwi1Ob+Ri9ppDkfRIN97p/LMarja8gReDp7wITL92CcOAIZYnqTpgvF8BZeDYyjkj0NQYmqIKFUHlr+dVMUTvY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906587; c=relaxed/simple; bh=VXCWbeiCCoefQu0q2nmRqyFjKs1quAyIAr5aLF3k41s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EBUDpO7EsZzBcvls+ehaffd3jPtw2KBkLssRmQ1+RoQSt6JQMiaTZbhBlekj5gZ2R5+cS8sOMw6lSSi6BxT2CKgzWyT4i/GRKcmNnMSP2kc2kxQCrJGqJJCVw2s1KKb6gJ4ukqHgZpnO9XIokjXLUHxyNM8lt5/UCw054bBwuMk= 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=ZKkjsR4F; arc=none smtp.client-ip=209.85.210.48 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="ZKkjsR4F" Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-701eea2095eso2282542a34.2 for ; Tue, 02 Jul 2024 00:49:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719906584; x=1720511384; 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=STMmRfRGoeqyn5QIqse7yydo3Sk24pkDDI1BQ45TBx8=; b=ZKkjsR4F8kC8823LrXp3YzxhyixuDwRlv1+rapxNvFblNcsvx0mEZiCvjZkIZjLEa0 CDzTBZQNVZuo2YhuRas3NXItBd1fYNa20Hf4fYpYT1MSNfP6K7aPqE43tHHv8R4rC9vW qBKU+M5Zcz6gP/I5GdaoJVclFZw4b97N34V+DZYtJxP3pP7EZYdDgOSa4jUHxUT/AvVq qswwYE5XMBnEwOqPV+DqevFaYBBrEj8IdoZFQN9+dEq3xJfAWGwwXgtS6TSvlI69rBRE kQtWn8XiPRM67S9gzVW7PWZhBofwAacAOELN2pfSYZJvN6P8/vjbkqnuIZTrhIYW4u9x 4vOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719906584; x=1720511384; 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=STMmRfRGoeqyn5QIqse7yydo3Sk24pkDDI1BQ45TBx8=; b=CjkQZ4ZlbJS5lfgtd6C42lRCsrxHlfisRSEggXWzDjmB/TKNGv3Eut3iWiSpaaVMD+ a4UJK0RVidAghZvUcSZ2Vm8ID2G8GzObuQ+q3+Hu+9TQcRL9J2yO7Ttn+vA5wsCim9R/ 8XvRMykIwJsSqJuKpS8IKAszRpC35JerbMTNQB8TtitUR/3hqC2G+Xb8y1tf+1K4Xv3i f8zpJEJ7GPCf4n/8KnG3lXlWVSoMQuQ+BpI4tIrvZ1Lmlu5HY3G0BZtRFwCTmZz6mFyg JHNgu4iY4xG/8UxfY6DCYh90JLmouRpb7+lPcd7QhEMVAa7eK7oDR0HxA2Lo+XwM4/Cl Tz9w== X-Gm-Message-State: AOJu0YxZojuSpXWe4gi6Q2G6AhZbusc+PGz0US34VxyS/DIZp1r3+yg5 Tdi2x5+tr+Vsp2HaQnR939d/UqZSkx93AE1KvGkM05K32BxROiEdyzBzv/VuMX4= X-Google-Smtp-Source: AGHT+IG1GFm56a2fBK2EcVbcTY58jPphEQ1YuOhzIDXNeTfCrlFqCDfKKbyf0F/S5pCmIJ/D3Zj9AQ== X-Received: by 2002:a05:6830:90:b0:702:65e:12ec with SMTP id 46e09a7af769-702075f4b98mr9125181a34.9.1719906584005; Tue, 02 Jul 2024 00:49:44 -0700 (PDT) Received: from Ubuntu.. ([106.206.197.80]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-708044ac424sm7772626b3a.161.2024.07.02.00.49.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 00:49:43 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 01/11] t: move reftable/record_test.c to the unit testing framework Date: Tue, 2 Jul 2024 12:52:14 +0530 Message-ID: <20240702074906.5587-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240702074906.5587-1-chandrapratap3519@gmail.com> References: <20240628063625.4092-1-chandrapratap3519@gmail.com> <20240702074906.5587-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, and renaming the tests to fit unit-tests' naming scheme. 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. Get rid of reftable_record_print() from the tests as well, because it clutters the test framework's output and we have no way of verifying the output. 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 | 131 ++++++++---------- 3 files changed, 61 insertions(+), 73 deletions(-) rename reftable/record_test.c => t/unit-tests/t-reftable-record.c (72%) 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 72% rename from reftable/record_test.c rename to t/unit-tests/t-reftable-record.c index 58290bdba3..e799464c36 100644 --- a/reftable/record_test.c +++ b/t/unit-tests/t-reftable-record.c @@ -6,15 +6,11 @@ https://developers.google.com/open-source/licenses/bsd */ -#include "record.h" +#include "test-lib.h" +#include "reftable/constants.h" +#include "reftable/record.h" -#include "system.h" -#include "basics.h" -#include "constants.h" -#include "test_framework.h" -#include "reftable-tests.h" - -static void test_copy(struct reftable_record *rec) +static void t_copy(struct reftable_record *rec) { struct reftable_record copy; uint8_t typ; @@ -24,15 +20,12 @@ 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)); - - puts("testing print coverage:\n"); - reftable_record_print(©, GIT_SHA1_RAWSZ); + check(reftable_record_equal(rec, ©, GIT_SHA1_RAWSZ)); reftable_record_release(©); } -static void test_varint_roundtrip(void) +static void t_varint_roundtrip(void) { uint64_t inputs[] = { 0, 1, @@ -43,8 +36,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 +48,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) +static void t_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, }; @@ -107,19 +97,19 @@ static void test_reftable_ref_record_roundtrip(void) } in.u.ref.refname = xstrdup("refs/heads/master"); - test_copy(&in); + t_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); @@ -130,7 +120,7 @@ static void test_reftable_ref_record_roundtrip(void) strbuf_release(&scratch); } -static void test_reftable_log_record_equal(void) +static void t_reftable_log_record_equal(void) { struct reftable_log_record in[2] = { { @@ -143,16 +133,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) +static void t_reftable_log_record_roundtrip(void) { - int i; struct reftable_log_record in[] = { { .refname = xstrdup("refs/heads/master"), @@ -180,12 +169,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 }; @@ -212,18 +201,18 @@ static void test_reftable_log_record_roundtrip(void) rec.u.log = in[i]; - test_copy(&rec); + t_copy(&rec); 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); @@ -233,7 +222,7 @@ static void test_reftable_log_record_roundtrip(void) strbuf_release(&scratch); } -static void test_key_roundtrip(void) +static void t_key_roundtrip(void) { uint8_t buffer[1024] = { 0 }; struct string_view dest = { @@ -252,21 +241,21 @@ 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); strbuf_release(&roundtrip); } -static void test_reftable_obj_record_roundtrip(void) +static void t_reftable_obj_record_roundtrip(void) { uint8_t testHash1[GIT_SHA1_RAWSZ] = { 1, 2, 3, 4, 0 }; uint64_t till9[] = { 1, 2, 3, 4, 500, 600, 700, 800, 9000 }; @@ -289,9 +278,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, @@ -308,16 +296,16 @@ static void test_reftable_obj_record_roundtrip(void) int n, m; uint8_t extra; - test_copy(&in); + t_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); } @@ -325,7 +313,7 @@ static void test_reftable_obj_record_roundtrip(void) strbuf_release(&scratch); } -static void test_reftable_index_record_roundtrip(void) +static void t_reftable_index_record_roundtrip(void) { struct reftable_record in = { .type = BLOCK_TYPE_INDEX, @@ -350,18 +338,18 @@ static void test_reftable_index_record_roundtrip(void) strbuf_addstr(&in.u.idx.last_key, "refs/heads/master"); reftable_record_key(&in, &key); - test_copy(&in); + t_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 +357,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(t_reftable_log_record_equal(), "reftable_log_record_equal works"); + TEST(t_reftable_log_record_roundtrip(), "record operations work on log record"); + TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record"); + TEST(t_varint_roundtrip(), "put_var_int and get_var_int work"); + TEST(t_key_roundtrip(), "reftable_encode_key and reftable_decode_key work"); + TEST(t_reftable_obj_record_roundtrip(), "record operations work on obj record"); + TEST(t_reftable_index_record_roundtrip(), "record operations work on index record"); + + return test_done(); } From patchwork Tue Jul 2 07:22:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13719070 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.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 9FF3214D2BF for ; Tue, 2 Jul 2024 07:49:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906591; cv=none; b=d0Id2tHabhszljzj3Mlpe/iicjlGaAxhbDDuL+3Ye7WG/WBdTf6AEQbib16IrJPX1tUzELg19Klf/5vBjE8GvWBP18LuA3xRw2dit8weP1xK5qcCZnA9degDZYsWSpCeulSDBeumwZJW3zyyCRQMSEYEqav+nob21/W0r2B1V+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906591; c=relaxed/simple; bh=vo5Co2h+DLd2xY9andqvyIo/UE0tdrjeSh9dsLiK3/k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SHCNMwooY7E1doW23S8eVFN6U4BnkQ4p04n4m9zkPYi1NQAC2UTu2LUNo/IbKHuswVVerAe41ML/kz8OaR4/cuZdjXXuS35v6/aQabxQkiGFtsw97BZIVGyi67QsL6guFJik64fTXzjmzVmzlVFnpF6YN1c+EpnQt7Y8tdUVWLU= 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=fSh/1/Cq; arc=none smtp.client-ip=209.85.210.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="fSh/1/Cq" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-70670fb3860so2380508b3a.1 for ; Tue, 02 Jul 2024 00:49:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719906588; x=1720511388; 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=wRSX5JZuaV1ReK+PxniiN8ERDcaaohcGmBRdbjkQOnk=; b=fSh/1/Cq3XlEtVTtBGbAC5VyAOa6ihPtNinpz1CKaqjcc+uiQ1fyINlDndWKrmTl55 YmngSdtqNuPZd+FTnmhwhchbeTjlPvBUR6TxfLIvnhMWA9i9e/ImnOkXj5Xw1GVeqEL6 BeHMT9JXxEWnEBGjJWah3vCTVuQOmIKumBopOLndtidz2Pn/Cr0DfX5n1Xs2G+HeJxhq jt1wNU/n/FmMtwZ/KaxEJWSPyBX7t0F+ploQXmfOIoS7trQuq9tqhR6765TcYPM4uXyE Lv/IWTQVWTLUMyJJSkVhkYosjE5ExaKW2IpFNaSMEnweOaAmO9lvvDE9r2JYtcD5PkRq 79Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719906588; x=1720511388; 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=wRSX5JZuaV1ReK+PxniiN8ERDcaaohcGmBRdbjkQOnk=; b=fH8HxvSBk781IC0nnYSxbSPIs4K45aU/wdhGUPdGHl7BXslCqonZVO1f8ktK7GsTLv 9f+SK8BYC01PLIsOiCnkv7zwBQgY8FDLoVtadSkckgAIUbp51rRWIRdX8/xoh0As1sba 47qKDUkqzHoTV7FiPSBbKDwcCP7mDej3w+pE653QpFp2mFG5YDn4pIW+l5YBEKKY4v8Q wzmnJtfVh4CxgT21lgJaNKNwPlwZ1FLaXAKtQdiKSpuncfOu035LKdDKVpe/W9LXQTcp n3TPsr1kKIBFGmf6/RJl5vHCEhcNxQkivFu3vIxyeCbTH15HhTER2LMmN51CBDng4hv5 ZyjA== X-Gm-Message-State: AOJu0Yyz0ooOoe9K7eCEImpMJRke2rkJk2AZM6K227/2xmQlr1yYsgGB DG+0xEPSdK7PL8MI3QYjjWTlSN9OV1FlkmfualATkGt/UtNoLJaSiLNIPz3s5O0= X-Google-Smtp-Source: AGHT+IFI44vJ0dlyMiF62gHB0+VPwFSUvPI2s94YxQTt/yK5ZjOQgfe7hYxI76e6X3eziZBijxYxZA== X-Received: by 2002:a05:6a00:ccf:b0:704:1c78:4f8a with SMTP id d2e1a72fcca58-70aaadd0f42mr7452284b3a.21.1719906587908; Tue, 02 Jul 2024 00:49:47 -0700 (PDT) Received: from Ubuntu.. ([106.206.197.80]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-708044ac424sm7772626b3a.161.2024.07.02.00.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 00:49:47 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 02/11] t-reftable-record: add reftable_record_cmp() tests for log records Date: Tue, 2 Jul 2024 12:52:15 +0530 Message-ID: <20240702074906.5587-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240702074906.5587-1-chandrapratap3519@gmail.com> References: <20240628063625.4092-1-chandrapratap3519@gmail.com> <20240702074906.5587-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 | 38 +++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index e799464c36..dd64e71f3b 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -120,24 +120,36 @@ static void t_reftable_ref_record_roundtrip(void) strbuf_release(&scratch); } -static void t_reftable_log_record_equal(void) +static void t_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 = (char *) "refs/heads/master", + .u.log.update_index = 42, }, { - .refname = xstrdup("refs/heads/master"), - .update_index = 22, - } + .type = BLOCK_TYPE_LOG, + .u.log.refname = (char *) "refs/heads/master", + .u.log.update_index = 22, + }, + { + .type = BLOCK_TYPE_LOG, + .u.log.refname = (char *) "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, because + * comparison is now performed on the basis of update indices */ + 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])); } static void t_reftable_log_record_roundtrip(void) @@ -359,7 +371,7 @@ static void t_reftable_index_record_roundtrip(void) int cmd_main(int argc, const char *argv[]) { - TEST(t_reftable_log_record_equal(), "reftable_log_record_equal works"); + TEST(t_reftable_log_record_comparison(), "comparison operations work on log record"); TEST(t_reftable_log_record_roundtrip(), "record operations work on log record"); TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record"); TEST(t_varint_roundtrip(), "put_var_int and get_var_int work"); From patchwork Tue Jul 2 07:22:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13719071 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (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 B688814D2BF for ; Tue, 2 Jul 2024 07:49:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906594; cv=none; b=PqmCihtO23kSBGStkDSuJmrlDYH53/E14oxFiO1mliDN4hz966zXkqhcvjNJDIjKyu1hl7XZuLqy+QJBZSppNDETx1YeBSXkRfz19yCmtsOdKWa28KNw/ytemHcUUjVPKcuSfaYfrei393w78uBsS5MKCIooEe+rmqu1eRO+nP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906594; c=relaxed/simple; bh=vfmBT15Yfik046KDeYJhNepLC8rrhPq93JJ278eFMlk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UK5aaUCZvQ73m748SUxRDBuRJ5q43VI9hf9rmeyDr6Fve4K3jqYKPFBLW37JFLIh6/BBTQG7O64vdKOXbBOAyZFTlc7FUDPipDurq0sjvUE2Relbbv/7aRLDPkBEPhxZMs+II/L1gpBZrQvWGS8kuUX2NfJsUSlrOTZWCGAETdk= 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=I6VIJW2W; arc=none smtp.client-ip=209.85.167.176 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="I6VIJW2W" Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3d55db7863bso2546883b6e.1 for ; Tue, 02 Jul 2024 00:49:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719906591; x=1720511391; 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=fuLTt4KEArDVqocACKGXB3ECVOLU/82LKdhDhScyN2w=; b=I6VIJW2W5r43Ex4qOxN9LzVp3+LWfCLNZXWN9np4EWa0wUMc+Fl+QXmqWvaO9qnV1N lvtdLCd+okCXj2hvXcwoc61wOhNhn55J9/DRZX3j0SJOyj2Z3LX3qywYSkvlxdFv5rpr dA0/nAHbH6R7ZGmgA5jQS4FxvyjgBZiwtL5oUlJ8V59+CO9II7U3kYq4XWWg6S4I55Do JPWnz26D0TAxHReVxI8fJxGvW8zaVpcMfH35JSMUcPJohSCGijvNTn+yrlH3xMmyqhry gXliqmXSayK9Vypg3Gdj8vdmmbCcOB3caehDqyBzxTX8h6Knj8/UcQ1mgBRiAETsGfj1 mwMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719906591; x=1720511391; 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=fuLTt4KEArDVqocACKGXB3ECVOLU/82LKdhDhScyN2w=; b=PxC0dtbAN56jRQqJ90PtuTq61vc20uLAEsJIeEedOH/zh1HgZd2pyWcUWgm5h3O0jF H4wRJvmYxK1ZygWrawynhhQ9dLFZcj2eHJd7euzhWZYVqXBk4Owc1FV7ByP4TFYUPE2x BW5HCOQnq9IlxVE2EDnsHpKQBwy9RKgiqe4TCrp9v93kB9GJMJRrRtFRtKZe3XgW3JDl arwboGOfD8GR8HhdGxsbGB0/8IRslQX/QEhevbCNRyS5qq15JU7D9PX3RJXtUh5lEsXv hlQTEnyBSnnoiG9o+Vua7RnjssjWQq3IAHzXBWKXKyzszgYumES6t3fgpZTHlZJ0OoFp 3o6Q== X-Gm-Message-State: AOJu0YxeNP1YPq1D5TKDOwvzN94pSVUe89N4LMc1OkCMVE7CQMNZDO1Z Iunu9Cm0ANMpoAYkMQMYWpK7yrd4HmKjKDGgURd4ZdtQDjEc5Mmtt3txIczSHzU= X-Google-Smtp-Source: AGHT+IFfP9FfAT0jZE2OI9kGWI2618QFTI0lbgtInW5wWr1u/Vp1OOm3SuPC10lRbovro+oiIlbdFQ== X-Received: by 2002:a05:6870:71cc:b0:254:a3c7:b917 with SMTP id 586e51a60fabf-25db3433859mr7674489fac.34.1719906591445; Tue, 02 Jul 2024 00:49:51 -0700 (PDT) Received: from Ubuntu.. ([106.206.197.80]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-708044ac424sm7772626b3a.161.2024.07.02.00.49.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 00:49:51 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 03/11] t-reftable-record: add comparison tests for ref records Date: Tue, 2 Jul 2024 12:52:16 +0530 Message-ID: <20240702074906.5587-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240702074906.5587-1-chandrapratap3519@gmail.com> References: <20240628063625.4092-1-chandrapratap3519@gmail.com> <20240702074906.5587-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 | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index dd64e71f3b..99534acd17 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -63,6 +63,38 @@ static void set_hash(uint8_t *h, int j) h[i] = (j >> i) & 0xff; } +static void t_reftable_ref_record_comparison(void) +{ + struct reftable_record in[3] = { + { + .type = BLOCK_TYPE_REF, + .u.ref.refname = (char *) "refs/heads/master", + .u.ref.value_type = REFTABLE_REF_VAL1, + }, + { + .type = BLOCK_TYPE_REF, + .u.ref.refname = (char *) "refs/heads/master", + .u.ref.value_type = REFTABLE_REF_DELETION, + }, + { + .type = BLOCK_TYPE_REF, + .u.ref.refname = (char *) "HEAD", + .u.ref.value_type = REFTABLE_REF_SYMREF, + .u.ref.value.symref = (char *) "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])); +} + static void t_reftable_ref_record_roundtrip(void) { struct strbuf scratch = STRBUF_INIT; @@ -371,6 +403,7 @@ static void t_reftable_index_record_roundtrip(void) int cmd_main(int argc, const char *argv[]) { + TEST(t_reftable_ref_record_comparison(), "comparison operations work on ref record"); TEST(t_reftable_log_record_comparison(), "comparison operations work on log record"); TEST(t_reftable_log_record_roundtrip(), "record operations work on log record"); TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record"); From patchwork Tue Jul 2 07:22:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13719072 Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.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 C3E047829C for ; Tue, 2 Jul 2024 07:49:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906598; cv=none; b=FJIW7h4EelXchMjny46q2gqC6OZ9/LEKil336FXYWmTdMXRpALsEUsaIh2eatE+ZP1wtCxETDCvoyUjvMNB97ex8USUbXJyzfC+6xjwrE7Vo5TTzmz3e5ng//tXpcfsP/PHcdV18EOTurWsJLOf+Jd9hbngld/6iVUgD46FNR3U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906598; c=relaxed/simple; bh=F5bLrlEWWUDXQsHpj3313xyBzLdZk6CM1Y8+etrKs2A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BmWGVVG+DXgVeijQ7LXkydbBatBXpBA2/xJ5glmuPEd9kcV5R1J3+/pKVeV5SIDWF7aQnIAD0C/KqCFDl2teyofxlbuiXNeiLf7amaYX77l7YD+K9PhyGYWqeyvH/sKAQlO+D5Lz7TBGlXCAwREgGt6rF+TD1Yk7uWsWX878sCA= 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=Yuq7EQxA; arc=none smtp.client-ip=209.85.167.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="Yuq7EQxA" Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-3d846f4360cso449001b6e.0 for ; Tue, 02 Jul 2024 00:49:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719906595; x=1720511395; 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=ZtKV7FnKyM99LU76K4C/3KT2JrZsiw6RCQIs6XSjxSI=; b=Yuq7EQxASmY1+SmolmAfWZUVJZfvLvM6yYr1HpLYb22ug3oKunTHAPnwyEFYeplEkn eaQVbmgTRXwN42P67+Tne2UWOy1/GjzDrq8wf2vcVbnq6PhLgo6/uxMWIgJWJFSFKOr2 /gbtocH/K7N9AKCkwgY9QN4svNO8nbhVVSr0z6+xwlCCYzrDp6cqXXJyH2AYo+5GRGXG NlyoXJPhafUUkq1waTzq2LPdHvlqM7lm33/r2ZRIsSjbLm3Lqt+2KDRszHQbYAnKCImM MVbowcshNCZ+CbhOVC5EL7BEI6Ohrx8cwzAWE7BsBhQjVD3SZE4MRHfnUrsmEtYys+Eg ztWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719906595; x=1720511395; 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=ZtKV7FnKyM99LU76K4C/3KT2JrZsiw6RCQIs6XSjxSI=; b=ccC8UjKvGVQl27AVey/eNmQJcaq4fhAnBYdZF7QQgiWiaBmovNtjCGRnh4x8qLoVde Webqx8V4WVF2AKX/ptQLiM8nIlSnlHPpSHcMkj3yrMPVCZeB4omPe9YYPKR/4kSs9mAg m6vek7GsqAOV+5KNz8Vr3DxKtA/ZbH2EOqwq/z6dSa/WIzdISFe9YG/Ka3+3FqN1G9YL fk6aTvTfTddutC+BBucNncTQEMg3rClBekiPyW0ijsTq4VTsRvUHbxaGcjM5YV/MWUtD +ve8wqKONFk+goGMVzlbZ8OSE9huZLbrVJPVA9N4F308aBUXvj//pGwhbesi3yAV2Klc xWQw== X-Gm-Message-State: AOJu0Yz/AX91BCFlgKI8p4H7UxB5i6J8unuABtrfU7LwusIbR1u2BleP 4mxgoRX4Hdu1c2onmP4L/MsUSTiJ2HqZ5zHFi+HVd1en7eqfisV2mlA45rBFfsg= X-Google-Smtp-Source: AGHT+IFHUpdr4ahk6870BkMlwwRf1m2M2vyF2gljE0otp3/JUUT0uT6+qK0hIZAqgZF3pbHolbgzmw== X-Received: by 2002:a05:6808:1823:b0:3d5:6410:7dd8 with SMTP id 5614622812f47-3d6b2b23729mr10862652b6e.12.1719906595055; Tue, 02 Jul 2024 00:49:55 -0700 (PDT) Received: from Ubuntu.. ([106.206.197.80]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-708044ac424sm7772626b3a.161.2024.07.02.00.49.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 00:49:54 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 04/11] t-reftable-record: add comparison tests for index records Date: Tue, 2 Jul 2024 12:52:17 +0530 Message-ID: <20240702074906.5587-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240702074906.5587-1-chandrapratap3519@gmail.com> References: <20240628063625.4092-1-chandrapratap3519@gmail.com> <20240702074906.5587-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 99534acd17..e8db337eb8 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -357,6 +357,43 @@ static void t_reftable_obj_record_roundtrip(void) strbuf_release(&scratch); } +static void t_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 t_reftable_index_record_roundtrip(void) { struct reftable_record in = { @@ -405,6 +442,7 @@ int cmd_main(int argc, const char *argv[]) { TEST(t_reftable_ref_record_comparison(), "comparison operations work on ref record"); TEST(t_reftable_log_record_comparison(), "comparison operations work on log record"); + TEST(t_reftable_index_record_comparison(), "comparison operations work on index record"); TEST(t_reftable_log_record_roundtrip(), "record operations work on log record"); TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record"); TEST(t_varint_roundtrip(), "put_var_int and get_var_int work"); From patchwork Tue Jul 2 07:22:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13719073 Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.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 2A7017829C for ; Tue, 2 Jul 2024 07:50:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906601; cv=none; b=s+oaVddcKi6O8W7HgT3dpdSOcUsrtTbu+v3REy7UfTbWap0d6+/AMGjwENq0hUrVph5yX45nHP21CdycN1jKAEtzCpsDwRlNo7mXepGV14QInfjXB+EN77VZKAXhvNxC9Jck1v4OXHG5WK3jHmq+LibkeEsYUeLitHiSxBluVas= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906601; c=relaxed/simple; bh=xSUnpyVRsn+apiNVMctanSVmerZ9z45ivFvBGsHhupU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NYF8xVL11gjETVfCGZBB/jk9kROiSYmPhzxQrBiBq7vneW3CGndnmp5tS4ufYCs8bM1lxm1crODAtLiY6m+JJLhUquc/B4l0VxecRM/eeEXFTUGYkjlvTa1lBgEIKQuT3B2E+z7vwRbWd4L6T8fMBagxfwPWKD79sSu0jTNLFtU= 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=LNHT9JgE; arc=none smtp.client-ip=209.85.167.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="LNHT9JgE" Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-3d55cfebcc5so1693103b6e.2 for ; Tue, 02 Jul 2024 00:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719906598; x=1720511398; 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=t6pyvVkkEdKASWRr9WbGaKCIkhXsJJSZG4HhAp3FrrQ=; b=LNHT9JgEhqGTNWo3ytAuRhzAg52t4JXuHb7rHfHXOZqEvx7POi608aJ/WS4uFKzwCE e59LqqV0OTwHrkLsHaA1E222dPN+L/X04vEGYBJGgs17/G2hsBCHZHJF+xy0pYM06x6y 1m9w6/HKEARi/SlCsKMGl4e5qB4GAVqKRzLAJ0kEn7AAyYdcfPjsLw4H52xUYY9SWe9f UxnespdJYxX49nm7GnYjpJ1NoVG7ho0hcVbtDfcxiBOJCfbnCT5Ad1j0ldalfKhGCrrX rdKvODbhlbL3EQjyrjOEGHNcDwru7O7gtg0roZ81aImy8r74n3RXUviXAt7cUfrkHziD PnMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719906598; x=1720511398; 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=t6pyvVkkEdKASWRr9WbGaKCIkhXsJJSZG4HhAp3FrrQ=; b=PpVG7sJfL1sOiVnkZQCK2nTDwVAoYkKHX8c0mU2/2c9KerUlI/3wvkjP1+LUJ/cy0z EQQTRMVnipLqrQrVsEMZ4x6ftKODTRFnxq6DHo0L6gVrzAXg5VhgwJbEv6WuRu+WHh6k pqLVMrhG08FTfdQ5+7W5ZNviymHFp4VflPIwyK1ozg7m7e+xEBfui39NV0x/3yeOYVju bi6IddSc/PcgPbMHrdz6ytgodFTDbYm3qci8htP0T8g5B8/EBTaaPU5pz2B4dMR4GELD fJxf6MWL/L78RhAs5/GwQV3oJcm3fx8NuqpphUhXVN2J8Pzx3RR3qIoXdEzj7FDx0Gor W0tw== X-Gm-Message-State: AOJu0YzELZHuWS84zi5poQCHeJVrPYvipaUXgNHGnuCxUnjeNgmy22TB 8XMxraDsvgaPKJ0TTbu6aypEkRBLDnWcdUc3qVv5Ef7dJ/H8ZXUltelNGMv/0rA= X-Google-Smtp-Source: AGHT+IFNGN2DVh7Vw/gC1mU7Umhdv1cImasPXw1YlbSAwwbq0rtDrHasjo/xOu88f2et37onP9iaYg== X-Received: by 2002:a05:6808:308d:b0:3d6:2d2e:76a3 with SMTP id 5614622812f47-3d6b4de23f3mr7831064b6e.38.1719906598582; Tue, 02 Jul 2024 00:49:58 -0700 (PDT) Received: from Ubuntu.. ([106.206.197.80]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-708044ac424sm7772626b3a.161.2024.07.02.00.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 00:49:58 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 05/11] t-reftable-record: add comparison tests for obj records Date: Tue, 2 Jul 2024 12:52:18 +0530 Message-ID: <20240702074906.5587-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240702074906.5587-1-chandrapratap3519@gmail.com> References: <20240628063625.4092-1-chandrapratap3519@gmail.com> <20240702074906.5587-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 e8db337eb8..46614de948 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -299,6 +299,44 @@ static void t_key_roundtrip(void) strbuf_release(&roundtrip); } +static void t_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 t_reftable_obj_record_roundtrip(void) { uint8_t testHash1[GIT_SHA1_RAWSZ] = { 1, 2, 3, 4, 0 }; @@ -443,6 +481,7 @@ int cmd_main(int argc, const char *argv[]) TEST(t_reftable_ref_record_comparison(), "comparison operations work on ref record"); TEST(t_reftable_log_record_comparison(), "comparison operations work on log record"); TEST(t_reftable_index_record_comparison(), "comparison operations work on index record"); + TEST(t_reftable_obj_record_comparison(), "comparison operations work on obj record"); TEST(t_reftable_log_record_roundtrip(), "record operations work on log record"); TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record"); TEST(t_varint_roundtrip(), "put_var_int and get_var_int work"); From patchwork Tue Jul 2 07:22:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13719074 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 015AB14E2FB for ; Tue, 2 Jul 2024 07:50:02 +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=1719906604; cv=none; b=dIg6OGmXy6pBv/FRPeJJS2Ji0onh3lQfYVNP3L4UsBlWCVSoQv+GJpfER6lZc+Ok/Onb4Fl9hLcUZbkoRY2PgSY53vSlw1r8IDsY+nxRF/+30AIDK5G4DcAD5G7wDbJNqbAWYT5bv03HXtvK+rkLs4jaqWUNZP+4xf+bgmBxltw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906604; c=relaxed/simple; bh=OtBimNkwnIk94ZSTta/HkYIxLDWplRd3hHrM9/EwHKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nHP6xRyYST6spgPz51z2L//5elW+qbpibWK35D4ZCv34jCkZT3b3CkchBtHHhnie0tDvuS6Qpmas5BzA0NCpxmXkTsQJWTbdKA2MwlGaogCENcieCTMnwO7KDggYHrnPflsRi8D1fTyPjz2dKwqeD5DAkC+MMgOs8Tb0gPL2r7E= 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=U2leaizH; 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="U2leaizH" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-706a4a04891so2445818b3a.3 for ; Tue, 02 Jul 2024 00:50:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719906602; x=1720511402; 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=r6AA2o4X8R22DXw/IanXSu1lHOYpmnIlURb7wXpGIFU=; b=U2leaizHNZWlgDZSpdDN4lvmqewnyM3+dHuoIDbAyPHVQRYZR1fSurqFQ8/Zi6GWV3 jlYUIABfq21ksewmiW9QR30AjfnxQAPd+xacV7FT/e44vHGHAAwWz52l+1/Xl5qrTMpG i05bRd5Ybfvo+tpVsCTuAgrbL21v84DmZTEe8zWT47B9bFhoQCrxyC0s15gSt08xUPmL NM/LFwdtaSPzgqISnOs+cBXfLwTN9MQv5NV8Ion66qMlzUe4NdX0qjz3pWe34L1LL7yx ++ylHjfVQOhQwGwtCB9E1KyNgWc5mN4oRVk+oXhkrCtfh8ann3pF0Y7YB+N6RjUn18t2 hj3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719906602; x=1720511402; 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=r6AA2o4X8R22DXw/IanXSu1lHOYpmnIlURb7wXpGIFU=; b=pz6FwLFto8AuA1P77nYQjQLMguYeAFd7f6ilI2F+Ka3omkoTPcAm3FG00fh4U2wPQI C79fmniSUxb0lMgK8H4z4Ltl2qx2tb5amEH22Wooqee4oyLmtqr7oe7hY/7RKG/A2F8s v0kdULf8iwEIBk8gGdSWaECOeT4nUzFtCU3k0VwEaAPWSL6pegTrxLxg/5TjkIzI+Dxk Be0H7O1QeG//43TqM55Bb2h9nisRf1xIhSZZUVxxoFp5EjOIh/hxtoEvWn0m4jNUbcsr bmGLKXln3+RxMB17wp1JIg8rOEtxksnX4LhWknCOxbvBKw9a05VyClU21Kq9fxswksUM J8yA== X-Gm-Message-State: AOJu0YzMb2cqXWGKhAm+94vdy/WSCoamUaKyBcx5VUFKO5nGViGdr6AW 0vPf3cqHmUyg3dkjYohWt8fZHTXqPDhnralKMaFIiEzloda1wqy4yXr/PX4Dvbc= X-Google-Smtp-Source: AGHT+IF2d5Oi1FeX+BhivJlTrx3wFzdMcvip7xWrAtrXa4cl4Ly8j+A5GoDlfNuBpQKHRh9BtvoWkQ== X-Received: by 2002:a05:6a00:4b10:b0:706:7943:b9cc with SMTP id d2e1a72fcca58-70aaad4c445mr6238473b3a.12.1719906601925; Tue, 02 Jul 2024 00:50:01 -0700 (PDT) Received: from Ubuntu.. ([106.206.197.80]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-708044ac424sm7772626b3a.161.2024.07.02.00.49.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 00:50:01 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 06/11] t-reftable-record: add ref tests for reftable_record_is_deletion() Date: Tue, 2 Jul 2024 12:52:19 +0530 Message-ID: <20240702074906.5587-7-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240702074906.5587-1-chandrapratap3519@gmail.com> References: <20240628063625.4092-1-chandrapratap3519@gmail.com> <20240702074906.5587-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 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index 46614de948..170c804825 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -102,6 +102,7 @@ static void t_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; @@ -132,6 +133,7 @@ static void t_reftable_ref_record_roundtrip(void) t_copy(&in); check_int(reftable_record_val_type(&in), ==, i); + check_int(reftable_record_is_deletion(&in), ==, i == REFTABLE_REF_DELETION); reftable_record_key(&in, &key); n = reftable_record_encode(&in, dest, GIT_SHA1_RAWSZ); From patchwork Tue Jul 2 07:22:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13719075 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (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 2FBB314A4ED for ; Tue, 2 Jul 2024 07:50:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906608; cv=none; b=Hblyb1hCks6oXgNJr1G4nAoiZDS84QiInC4P4OmMuBpRtoJotpvZ7rEa85BdFMbX3InavMQqy+ST6gFBpauJFPr6WSG+Z3pn4FwWdiGW/ms16hc4Q3/OyUltLw3aVn+bkTAhxjNehu0RoUV0KeDP4BVFIEHXxGk+sTnf5Y+ozfQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906608; c=relaxed/simple; bh=iv+3fFdtLIdU+4u6UlJ5P3cnS7lOA4o9C5D2O6OyAHk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CHAI3mCi+bxdblBn6ve0UhiVNTft0l9XQz8e7PHMrB+D0c0tPM5TBxtPBSN7Zmt5QC+n7vKwtKyzMb72Vz5zbMRtamDTwRMtCBODeTtuqn9UGA1MCmMz9X/5bMiwuceu6vNykrWc4xnu7t5lCtT1p3t2klLlZPYinnwb7NpHGZs= 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=M14zifMC; arc=none smtp.client-ip=209.85.167.176 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="M14zifMC" Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3d5666a4860so2277960b6e.2 for ; Tue, 02 Jul 2024 00:50:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719906605; x=1720511405; 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=F72auR7oyKgzk8C5heFV/L/7fLzB79XOdeFqoq/Kf0g=; b=M14zifMCcE8+4p9DM8TXXNKQCI3Gr3lwyU4fLkwWB0ii+t6FaNau0SFI87MQfqZ8T3 wMttfthN9GXMDGxig1Ih9/KbrqH1P3mje8rEWMj0bVVWifrcUo6KpHeAXjCHJLK6zLRU zBvQMLgwmDAQ3TDaCmO+zVLV2yNKIBwA9C+83SbeGNsQoMIIgHoF/HOlee3W8qth8ZVq zE+77hJvC1b7XOLHi8JvaQdYUc/fGYZl1s3Jsx8aWr0GxDUDK3Me23ZW0x53p8W6CgK7 tlbsKs32PZQWhWZ0gcq3W3UvUJbcylzTTbMN0Ffo9n2m7h/pUgTVwNt4RDf6NI963dVf tdqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719906605; x=1720511405; 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=F72auR7oyKgzk8C5heFV/L/7fLzB79XOdeFqoq/Kf0g=; b=fm3EXIh9dRaE5wU0PQLhYxPN47Mz9snHWhAELZxYSlWR+TIyrUmpbcMDZ/KmHSD8Gq vzgVtsHmM3nsBtk6O+kJy2ooDfeQF2+zXuHP5yzeSF0r147/Wc0PyLnm8pBMEEgh2cTm rQkYAAmUo+a1sLibARTPHLz7GjUGOKKiS/uhil+nYhHUiXrnVjXIpB4lO1HG4+3Z5BTf /d9RG6fdQn5LsBAuF019UMYCXwswdqF+V9SLQG++O7tOiVT2gfuZKrB8knu6tWUACAqh u3OPaEjYiaYr8jet4aL4eqC29mVcQZuL6BTnz9po4iyk3hhgopSET+NddrmkNH6/T3nC 223g== X-Gm-Message-State: AOJu0YxkY65ZHcys5e6rX0e3h0Tb+Y4QFteVb2xxCk0cVE4KczN0lzHA DwEsQrTWcsNNN1HOOz23BgPhLAcO/9h2cTRK6B58pH1z5sx+W0I7uJhXVyIvay4= X-Google-Smtp-Source: AGHT+IFlE65zoQGihcxPLX6rtiEgKMCQXjonLhKPKrCGaK6mlWfURyR1nGoVrPlWvhpmgyR4LLuuuA== X-Received: by 2002:a05:6808:308f:b0:3d2:24d3:80f3 with SMTP id 5614622812f47-3d6b4de2410mr10626182b6e.43.1719906605477; Tue, 02 Jul 2024 00:50:05 -0700 (PDT) Received: from Ubuntu.. ([106.206.197.80]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-708044ac424sm7772626b3a.161.2024.07.02.00.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 00:50:05 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 07/11] t-reftable-record: add log tests for reftable_record_is_deletion() Date: Tue, 2 Jul 2024 12:52:20 +0530 Message-ID: <20240702074906.5587-8-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240702074906.5587-1-chandrapratap3519@gmail.com> References: <20240628063625.4092-1-chandrapratap3519@gmail.com> <20240702074906.5587-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 three of the four record types (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 170c804825..6ece76e416 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -220,6 +220,10 @@ static void t_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 Tue Jul 2 07:22:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13719076 Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.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 204DB14B941 for ; Tue, 2 Jul 2024 07:50:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906612; cv=none; b=IugOlhYS2LoL/XB1z1hMOaF0y3i3PtEvtIpmLyUX91zhB+BU9SBz4u/f4Ra6ZPXnsRlFg+Ld3O+g3Mb9rgZ0bFWyLFTRtk1lB4gfUWZWxjL3ve0qOObC/3AYmX+Hx7f3e/A55FMGOEdfvk3F0gNzFPjZasFo9nFcS6nVOf4Kdn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906612; c=relaxed/simple; bh=lbxxZWov7krDvfRPREguqlu+nMVALJZ1VvdGFEKSvag=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M8LCRTt3vFhzuBipFiF5FGsv4GfNwVEyQ/0TNZyRx3Z64A2FdrEhf2xhcGNI0tCD7kLouG088LFs6trvHmu/3ol4geI5IEhKaCSjp0vNMk6wm1UxejjdWP6DNpEsf+oIQjmeSSTuQk0aZs12EEvkhJUIRetQngw3SEkQROhUpJ8= 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=bCueunpB; arc=none smtp.client-ip=209.85.167.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="bCueunpB" Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-3d55e2e032dso2338288b6e.3 for ; Tue, 02 Jul 2024 00:50:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719906609; x=1720511409; 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=8SjjoWcrN9Uaxxpmx4FAHcpdNLcALiOKRRA5v3KYKuc=; b=bCueunpBC3LH60VfepbGLT0tCbC8wB8niWTwyNscICLVdaEHrIn/dwut2wgpnUWadV QsR5psYG24GzaXQI33xWf/eueLu/evEb1CxccEJAKZJPy4oQo4wSeq9tdTpZj3Puqupo u4mCi9xsXkQZk5KFm66FqWrZ70PyqnF6MWW4wSRqqROQS41RSLnpALCBLpoUcSbgOPYT dFqZOAps+EEoZuApnp/K7qMSaUtr94MnDFnID3fhCg5k+WIb9HUGTCuDaE00THasNvks YvYqqomNaeJkv71tTz15gksxfYowBzWvY1G8+jHUgJU3/yxNfLVanS2UqQEZ3DAqY6gC hOgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719906609; x=1720511409; 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=8SjjoWcrN9Uaxxpmx4FAHcpdNLcALiOKRRA5v3KYKuc=; b=oVfwA98ug54QJYdtj/v4YPGg6g7dN7+m5K4WGtUMxkk1sLKzXNtkSjP85kjkAiz4xY 379Ip1dtaZzlshIEw5aGS6DDRRLmH2BGHXT0WV710vVVwzGH62uxAeRMtBrS9Rvwqrbd eunnj0WFbiBPy7xx3jKxQjP6lHn/SA4TSyGAL65pC0lGX2s1x/+26iT+tbgQKS5/Awmm 6CJ0+Rkyg8l163rrleIEH0YHIG6/8O3ARKBVaXqlpfMqM66yF4FJHVf2Vg2p2+TotB9M eR2Y8KccSWx3JO0RKnIwyhrw+SoC6ZDeIE32HCj3mQbpbZutlP2mg2hwXrJDnOVn1H2n p/eA== X-Gm-Message-State: AOJu0YzaAxUhwzLFuohfm/oaFHfwtlKdVVVLBPfdFL2WLUBJE3FYoSzO mb5RUR3YCOfJDQT/0Xp3aYRO6lsT7w0pDRFmm4poQhkN94vhZJTBQFSIEN7Kqzk= X-Google-Smtp-Source: AGHT+IHvG3JrcHwEdt/leAnmsECLZhsOGTXm/5CNWQQSXWi4cdwGc71iDTgc8QNopJrsauVbyLmkbQ== X-Received: by 2002:a05:6808:1408:b0:3d5:5fbe:b31a with SMTP id 5614622812f47-3d6b55925e4mr11968397b6e.51.1719906608922; Tue, 02 Jul 2024 00:50:08 -0700 (PDT) Received: from Ubuntu.. ([106.206.197.80]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-708044ac424sm7772626b3a.161.2024.07.02.00.50.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 00:50:08 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 08/11] t-reftable-record: add obj tests for reftable_record_is_deletion() Date: Tue, 2 Jul 2024 12:52:21 +0530 Message-ID: <20240702074906.5587-9-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240702074906.5587-1-chandrapratap3519@gmail.com> References: <20240628063625.4092-1-chandrapratap3519@gmail.com> <20240702074906.5587-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 two of the four record types (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 6ece76e416..1b52085f46 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -384,6 +384,7 @@ static void t_reftable_obj_record_roundtrip(void) int n, m; uint8_t extra; + check(!reftable_record_is_deletion(&in)); t_copy(&in); reftable_record_key(&in, &key); n = reftable_record_encode(&in, dest, GIT_SHA1_RAWSZ); From patchwork Tue Jul 2 07:22:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13719077 Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) (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 EF13E14B941 for ; Tue, 2 Jul 2024 07:50:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906615; cv=none; b=pcaq46T0NGIEi08ib4uKu9/YpMPsbOpz2bhkOhfO3HUKG2g3pVy4W6FXpZYoE9IxU1Gq8Dp7OcmscmNVub3PJVZ15iSG3ep9mpdVR0kgvMfgUEE2/saIJba63aeDf4j/8ojJUpteqKYWFhE9jhANpB6oD+G3ugGak/Pu8gbCSrY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906615; c=relaxed/simple; bh=ly9/7822hCju/OC4ebJHxM7m+tFhB3TL6VtHqpDc4aY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cRKFEX+kvQJ6tfQidR1yuan9qgIeJG1L5hEu4u0vhJU7KppNVB4MUX8JkoRhGWzTzENkspiZKpBnEma26IY9IRIDpPVv9igqIGgRaS5v1OUrGd75HSRhSu6a8EkOauH686riCe+VXvBSzj+KcrCJnyRgdzIk9M04Ig4DVJdAt88= 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=gWuhmXtL; arc=none smtp.client-ip=209.85.210.41 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="gWuhmXtL" Received: by mail-ot1-f41.google.com with SMTP id 46e09a7af769-701fef57ac1so2078570a34.0 for ; Tue, 02 Jul 2024 00:50:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719906612; x=1720511412; 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=4kjzoArxTuZugz+BbAB8T+oPDdYz5PbFujHOY1soELs=; b=gWuhmXtLq2ro6kkwbRNqume2QjwMDrViL3v1N8hLD0aEQY40/5/XzY0uXPqtmPJW4N KIO+FRsxSksnADQXgV9b4+mLiKWLUZzb0gtcsEcVaBiXBdlXVb5DLmg1C9cYdaCB1emz yKivD6pmHRQ9sfSRzhWicOvoUzrLqmKOM2FgoJUYOuWXGH55FixxkA3beXIjZ07Cy08h 0EKTCf0RodfixSJ4dJEuJ0bIPEGqetOxaQafRffe9E0IuW0urQfsmw0Pt01lRka6j5Mz b3sHzpmqLjfuPmes6kRHGINiOy+U4hOaJ6AfYu4WMlEQKmXivVe4OoexrqT9Z6bgaJWt ecdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719906612; x=1720511412; 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=4kjzoArxTuZugz+BbAB8T+oPDdYz5PbFujHOY1soELs=; b=TxQV5OaS5RjDtCFFPechA/0GzI8d1WPTyxbD3NsyP0Ty2aUkVyiTcqMtTJrhsYafqQ GLU0oaoEji9ssLc89XoZ5wmN3x0As/Pxjd6JQVHzxe5oW42wcSspwGHcboe1RdcDAAX2 M6HVSun/3eatzFFI15ibqcWfUjOsgQ2JCYe/KP7w/NCoE39Vd09gMFCVdo+OpHuoZUwj BbOhgMMbLY20SUb9RARHJoi0oQZuL97Ou2m23wZtsXnQs3x+pUyJGBFoqk82VGx/NVZ7 cAxK6iqwQGbrIk3CUiGVxpkP+FsQ5mKnja6H1OZ/pn/l2tdmMz1g+D+lm8KQiFRU3riy SQ3w== X-Gm-Message-State: AOJu0YwFDSUvUGUbswIvNBhhaoeKa3xT5J4U7KPzBdWFpKjwcI5gjP4a q0F57DsAhVmFaOYxS+M9VVLN1bEH3967+eZGdhUvDiaS7iwDyw310KAe5fkHtGU= X-Google-Smtp-Source: AGHT+IFURR3LHtdPsu8fmr+Xfa1UmBUxUZsjRa08WhWwjjVZIN3NYAt6s4Hs5/wSkoPOzMrRAMizuw== X-Received: by 2002:a9d:6f81:0:b0:701:c041:7cfe with SMTP id 46e09a7af769-7020775ebf4mr9769031a34.35.1719906612301; Tue, 02 Jul 2024 00:50:12 -0700 (PDT) Received: from Ubuntu.. ([106.206.197.80]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-708044ac424sm7772626b3a.161.2024.07.02.00.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 00:50:11 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 09/11] t-reftable-record: add index tests for reftable_record_is_deletion() Date: Tue, 2 Jul 2024 12:52:22 +0530 Message-ID: <20240702074906.5587-10-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240702074906.5587-1-chandrapratap3519@gmail.com> References: <20240628063625.4092-1-chandrapratap3519@gmail.com> <20240702074906.5587-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 index records. 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 1b52085f46..43b5d40899 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -466,6 +466,7 @@ static void t_reftable_index_record_roundtrip(void) reftable_record_key(&in, &key); t_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 Tue Jul 2 07:22:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13719078 Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) (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 2168D14D42C for ; Tue, 2 Jul 2024 07:50:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906618; cv=none; b=B7jWkKoWMSy6hfKNf0b8WQMWnBH4pl6fivutqMQgOuN5IgFBPKAcwELKOEck3YWxzykoFTVB6gjll4duEyDFmsPo67fLEHZs4wwbiDRPAOQDd20CXZuM5FXuGL0bNCbpSLxD/mQsYygVBgO0wRfMtb45diJ6vh/5c3CM3uzISs0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906618; c=relaxed/simple; bh=kpm8IEjm7/FpsXEgHos1G/0PiCCq+iAmNFz30yyxqig=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EVjMxrRxIslQvY7k+o32Gey2EmjLc2ulUH6YAtVV4Bv/VHXk+da5dX1uyhHufcPVDWW6SR0y8m7/K/2XbQzEGV4ZbndY0ZDAjJTHokWIugoPNNr5UiVnfbqZEJQ/7av1csTAXG055EyyhV8/nQSqxW14GAsG2MBn30Lbu7EFBtw= 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=d/54zsWR; arc=none smtp.client-ip=209.85.210.51 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="d/54zsWR" Received: by mail-ot1-f51.google.com with SMTP id 46e09a7af769-6f8d0a1e500so3557597a34.3 for ; Tue, 02 Jul 2024 00:50:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719906616; x=1720511416; 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=JDSXlzAo1+yDEpsERu682IX3LxAq0JyvYBIm8EjFNuM=; b=d/54zsWRAE+XBpejGBF5cqR911BeNBvBPrHSBq6F6t7ZsVWlRqm7dTNkcKxm61890Q QcOSmCal1JcDa5Wlvh5Lw8am1svSTTAZhi/FTCKyBsbjXquJ591MFpQOUFzE93xbF4sE ikPOOUOLvghlQaChYXMNd2WaUhUucQY2CnSxTcsCDD6RnhxpLaiWSi7hdyCtmwUcrxPb 5hX60ZKrvtTPsviTKpKd2yWn6uwH57lbptUgZGEAooo/hhq3/p9nmWzbQt2M65E7BZTb R3J5lGXh3WcSkEmtt2702VjNjYTa2RQv64CJb3suPqabCZJxlerGh/mLQXFk7kbWm/8C GKsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719906616; x=1720511416; 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=JDSXlzAo1+yDEpsERu682IX3LxAq0JyvYBIm8EjFNuM=; b=oAecyCBsjgRh598BU+6VWSi4vslGb4tItamq6BPsd1Pt5MdAcEXIwSndGmOqyC9EgM WfGpd+oO0HNVAuArBRU05+rkzbvpxJ0cICe2skIGb3VywXzIA8/J5kSUprv5Rh+zvPhp uFVkzpATUn/Dpsa22z2cMtzTXGoseaHNZydTTwwpgL7aMpSWXbYVrTVwC6bFNSTLbgeI TPhbAEYK1AaAuuWL8+rW8VkHpPs1aSqT02wd4dOJ19ao9/ty46XQzXnDOvsHHILZDfHW ar5loshXhV5LOEMII7JW6wJz/5Z+tr7XBXbbhsxgcUMYw90q2QTwCvb44lcA4eV80GG4 viRQ== X-Gm-Message-State: AOJu0YxLmcJZMtMEbgOYt8HBZBVc0G/xinG4WduDE8iUZk3PPifo4hEN 3iNj5suPv+S/Gbvz/nWW8yuyrvnhrpbyKlJikSpRPFzgO5MQhL8dEitCRuNgsgg= X-Google-Smtp-Source: AGHT+IFU9ttNcHc651WJOGhXm9ExIFs61eEE9GthyPtmnhFFPqa3iVPepxpnopzdYFxhKCFKdLSiaA== X-Received: by 2002:a05:6830:1e27:b0:702:1e88:6092 with SMTP id 46e09a7af769-7021e886112mr2753861a34.20.1719906615818; Tue, 02 Jul 2024 00:50:15 -0700 (PDT) Received: from Ubuntu.. ([106.206.197.80]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-708044ac424sm7772626b3a.161.2024.07.02.00.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 00:50:15 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 10/11] t-reftable-record: add tests for reftable_ref_record_compare_name() Date: Tue, 2 Jul 2024 12:52:23 +0530 Message-ID: <20240702074906.5587-11-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240702074906.5587-1-chandrapratap3519@gmail.com> References: <20240628063625.4092-1-chandrapratap3519@gmail.com> <20240702074906.5587-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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index 43b5d40899..c0668cd8b4 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -95,6 +95,25 @@ static void t_reftable_ref_record_comparison(void) check(!reftable_record_cmp(&in[0], &in[1])); } +static void t_reftable_ref_record_compare_name(void) +{ + struct reftable_ref_record recs[3] = { + { + .refname = (char *) "refs/heads/a" + }, + { + .refname = (char *) "refs/heads/b" + }, + { + .refname = (char *) "refs/heads/a" + }, + }; + + check_int(reftable_ref_record_compare_name(&recs[0], &recs[1]), <, 0); + check_int(reftable_ref_record_compare_name(&recs[1], &recs[0]), >, 0); + check_int(reftable_ref_record_compare_name(&recs[0], &recs[2]), ==, 0); +} + static void t_reftable_ref_record_roundtrip(void) { struct strbuf scratch = STRBUF_INIT; @@ -490,6 +509,7 @@ int cmd_main(int argc, const char *argv[]) TEST(t_reftable_log_record_comparison(), "comparison operations work on log record"); TEST(t_reftable_index_record_comparison(), "comparison operations work on index record"); TEST(t_reftable_obj_record_comparison(), "comparison operations work on obj record"); + TEST(t_reftable_ref_record_compare_name(), "reftable_ref_record_compare_name works"); TEST(t_reftable_log_record_roundtrip(), "record operations work on log record"); TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record"); TEST(t_varint_roundtrip(), "put_var_int and get_var_int work"); From patchwork Tue Jul 2 07:22:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13719079 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 73A6C14D42C for ; Tue, 2 Jul 2024 07:50:20 +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=1719906621; cv=none; b=RN6gWoQYj822vRBFnwuOSVEFAL6fuG0/3R/D1HlwK0P2arCVJOBaRg2q30PjOHk+VcvoZI0a5U+fDYFi6ijPIfYDNf/f9bSnmn/4PU2YkJzPD3C7A/RdUZD1+gne6Jq3deNxb+9eX96vzsXfpQLG1AOBAyBe9aQdGIaqxQrhohs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719906621; c=relaxed/simple; bh=Oz7FLGLPnsDV+1o1uOShkAwc+m5xj3WMKalwkxe/NpI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c1zetxVBqN464OOuUo9DcL8g/E7JaLqi6SuT1YgH2rSMDeHNzBzz6YUYU/7TzIQfYs8AjBc8U+zdeOaGkiylhHf2h6ELx9wJVVWUz7tP+cbvKx4VJ2xtdanh2weOMwKPCA8Zt2jqnBJHatRUR1gDu27ppKj8IIdmGOtaHeSQ/Cg= 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=JxHNl1oF; 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="JxHNl1oF" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-701b0b0be38so3129962b3a.0 for ; Tue, 02 Jul 2024 00:50:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719906619; x=1720511419; 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=WkmOFTD/g7Ed01jSdr/oGiWRDpD+kvQlw386TLsQwVk=; b=JxHNl1oF5u2NiPjhZTFvEENEWwRf1111BHdn3Luj9wk7Tdx/EwZc3DTBva1Z6fxgjC wDhuOpOV2Zl07vOvdfg8TuOTRsbECowxuoe3xHL+pWv0l8uUWqfO1h8jlgp76PIcNPMp cnoioGTIy+Z894u/GVg4i444MBNG5XTfGQgge7qpmVMyyDj8lx2/S/xFZMXQOoB4Bd8B eZrc8TV15jnK7Ptt4lCH+ro2sasgzzTZ7cczPNVsBpXkCleMfl3SV7bTUoMB0LHOlwA7 rzmqygkk8rOtv0QP4HIMZASwnG3FJpWU0zt+O9eokNGVypFRuLh0Im2itLL02EgDrHRD sQkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719906619; x=1720511419; 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=WkmOFTD/g7Ed01jSdr/oGiWRDpD+kvQlw386TLsQwVk=; b=ZkX4qbAnV8V1H1KZluJ9rmXmCv1W+QNY+R/fFPdL9FBKKvJ67j6snoNoVQI00EKkNl MJz66/t0J6eJ++1L/2OjQAGxi4kPtTof6bJFEQiinXaDxEKQC/fr/iq2GUO0tui/uOA4 IOaKVsUJXM/fjnigBhfPE1LbceHIyoHT68FewLro/e0emy70ALPZX3T5vDcS5hTWIP52 mO65PpRdsK0mkfdnDXijY7YtjxCK/6GRkBWJ6mGBtpAJyauQ0NxlFqxv6XESL93m3Wog sZaHvzQmtrukFnuJzK9y5TJ/X09StZEuhviqyGmmP54Ki4kmjzYsCZL8z19ZyXvqOloX QhEw== X-Gm-Message-State: AOJu0Yw/lDdMHA6BolfbMG41ekqdnq+BZGpK9x2IktoNepfetxYA3NF6 cPs9s16wuuoVsnDY/SWEmIhHiaqgALFc7+aH2qDllahJbFh5a5HgobO/hu1r454= X-Google-Smtp-Source: AGHT+IFqCl0aC9xVexbe2vb66XyUF72dS0B7IS03ehkoRO9Fcpt6c47wHiWWKF6PFxBpVn/4vlpCHg== X-Received: by 2002:a05:6a00:240d:b0:706:251d:d98 with SMTP id d2e1a72fcca58-70aaad2c0femr9018118b3a.4.1719906619440; Tue, 02 Jul 2024 00:50:19 -0700 (PDT) Received: from Ubuntu.. ([106.206.197.80]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-708044ac424sm7772626b3a.161.2024.07.02.00.50.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 00:50:19 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik.188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v4 11/11] t-reftable-record: add tests for reftable_log_record_compare_key() Date: Tue, 2 Jul 2024 12:52:24 +0530 Message-ID: <20240702074906.5587-12-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240702074906.5587-1-chandrapratap3519@gmail.com> References: <20240628063625.4092-1-chandrapratap3519@gmail.com> <20240702074906.5587-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 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index c0668cd8b4..cb649ee419 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -205,6 +205,35 @@ static void t_reftable_log_record_comparison(void) check(!reftable_record_cmp(&in[0], &in[1])); } +static void t_reftable_log_record_compare_key(void) +{ + struct reftable_log_record logs[3] = { + { + .refname = (char *) "refs/heads/a", + .update_index = 1, + }, + { + .refname = (char *) "refs/heads/b", + .update_index = 2, + }, + { + .refname = (char *) "refs/heads/a", + .update_index = 3, + }, + }; + + check_int(reftable_log_record_compare_key(&logs[0], &logs[1]), <, 0); + check_int(reftable_log_record_compare_key(&logs[1], &logs[0]), >, 0); + + logs[1].update_index = logs[0].update_index; + check_int(reftable_log_record_compare_key(&logs[0], &logs[1]), <, 0); + + check_int(reftable_log_record_compare_key(&logs[0], &logs[2]), >, 0); + check_int(reftable_log_record_compare_key(&logs[2], &logs[0]), <, 0); + logs[2].update_index = logs[0].update_index; + check_int(reftable_log_record_compare_key(&logs[0], &logs[2]), ==, 0); +} + static void t_reftable_log_record_roundtrip(void) { struct reftable_log_record in[] = { @@ -510,6 +539,7 @@ int cmd_main(int argc, const char *argv[]) TEST(t_reftable_index_record_comparison(), "comparison operations work on index record"); TEST(t_reftable_obj_record_comparison(), "comparison operations work on obj record"); TEST(t_reftable_ref_record_compare_name(), "reftable_ref_record_compare_name works"); + TEST(t_reftable_log_record_compare_key(), "reftable_log_record_compare_key works"); TEST(t_reftable_log_record_roundtrip(), "record operations work on log record"); TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record"); TEST(t_varint_roundtrip(), "put_var_int and get_var_int work");