From patchwork Fri Jun 21 05:47: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: 13706874 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.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 45AD017BB9 for ; Fri, 21 Jun 2024 06:01:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949703; cv=none; b=RiYyhrO3iFtqY7v/fs56FW077slRI96tQ6Du/vEXh8JsOCdHptLCTNoaB9So2utWAVkgxgmXHhfVa7WBhQtEVolC6K+3VYtEIUNzusXyx3VW7mvKvE+7MR1fBS3NpTuEPzf4GwXsslAORoUa5fokXuo8yKBOyhaWv+YabSTwlI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949703; c=relaxed/simple; bh=dqj8VZaZmHmKhruRA4tFr/aj/shI4Ongvo4vU1lysss=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NNd+LOD7DmlZC5tZQvFNAImYmrXr03do47oYww2rORcQRbEEKjXKEl3TId9KQJdNJMXHkqtJsfBzh0hrhRb0nJjwp6t5DzNwnipjttQUBR0KudXkpy2FEEtT8euRjCwVwglkTa75+SGnw/yNwCOWItw1lVUHqQXQbbFSL8PR7Ak= 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=Or1KldLy; arc=none smtp.client-ip=209.85.215.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="Or1KldLy" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-681ad26f4a5so1056062a12.2 for ; Thu, 20 Jun 2024 23:01:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718949700; x=1719554500; 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=8bsM2p910gYOxgeOTA5PF/EWjQhIZmud6354ohZ0vII=; b=Or1KldLymB0PvuLk9X9HvNtyPGxa143GU7eerjoBRHGrewQXAJE6MqpeTrAJus5zyH CBYN+a8TaZ4AdGWFRWh/qKCzvlqQsN+EC3bHRN1KcJLucq/NjwjRIrbNPrQFujQOfIpJ lRACOVuZGsDfTb4mNKqLhRCRfosMyRTQ1FuNKjBlnaBk4KvXgxPv7czqmBuaHPMKf43q O3phf2kEX9VeOop04qLKmSIj/dothD6lm6dCvDAJqp6b4t/Q2910AYdbjGjlqGAZJVW/ q5Lrvp8EMWsIdAcF9BsfCbLZVArBMXxwgzlce3abp4ZZqLlzrcAdqCZvenWd5WAenOWk X4oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718949700; x=1719554500; 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=8bsM2p910gYOxgeOTA5PF/EWjQhIZmud6354ohZ0vII=; b=XNkJVMBcZ5U5vqXAvqA0mj/wKtgn5zKzQTDOgcRW3UdwuFnXVjxLg9mTx0YicsgXSe PzPtrg8RsvPZ85/7sXeU8vAnykBnBykTR4iur2ZEo/UNB/ETtiE8KF+UCcrJsiZxi+qi 0SS5zP7IZpzhI5fnxtj+VmTMuq1sYvzHCNR1b9idGYLlMa0K703xNje/MbWrvObczEhM nCZjme/W9a05tHPg6zGqeejBH9vHBPwP8iMQhxhCSOvcKKZ8nkDEUG4gxL3rhl7MyzIJ wPl0BezDW22CeNQ5N+nTx+mcKW51LiWTLt4BuvD+/EISlf/PskS0cBWEVodQNO8ahHd6 wukA== X-Gm-Message-State: AOJu0YyKu30R89nSVh3Rj7WhfcR9M2W4weePjMgNfoKQOKINMtv2uiAi x4ElCbZSxSnoNTiQWs1Ph8LsbD30aXf/RBnG+hbbdDj811hjgXr3jf0KEg== X-Google-Smtp-Source: AGHT+IFddPMmOnGgZf4wzybqAurH9yTOYXOkMJ4I3OGz3BoTGnqaPoAHfKbTorZnBMFEsSqNZL/CFg== X-Received: by 2002:a17:90b:1485:b0:2c2:e45b:ecd with SMTP id 98e67ed59e1d1-2c7b5b569bbmr7351394a91.12.1718949699539; Thu, 20 Jun 2024 23:01:39 -0700 (PDT) Received: from Ubuntu.. ([106.206.192.103]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2c81fe88e0fsm498661a91.3.2024.06.20.23.01.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 23:01:39 -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 11:17:00 +0530 Message-ID: <20240621060018.12795-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621060018.12795-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-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. 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 05:47: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: 13706875 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.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 DE34314535A for ; Fri, 21 Jun 2024 06:01:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949705; cv=none; b=Fre9I2AzUYHvpqTJAO7SABFeDZKfDa1TrTQX8B1x/nx6TBAbF50owcR5jCysxKsrDBGtGHXrS7JJ4kxWazYvkEfFJ4/TuOQtrqV3hO904ggFyLk3tdVJLkLABLhWdkNQrIYjgNPFtB9lqq10qeg7F2phkZL3XkEstls4RNLJHQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949705; c=relaxed/simple; bh=5if+8SD6LhrJhmKRnvQ+3TZt2O4YWU98B16DY9y1mBE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OJXJufDIulK6pRgKNjRD24jln0NuDV1EcbW4+7Va69i/7q5dXOBo27agy3sucHY+7vpCUVE9hlYvHaheNkxGLfqvqKreHL/WD25JWsZ9ErTqdHqq3gevtP8wHri8QiKWtG56RDVhIVWf642V4zQs8/kjhJz+Udhigr8KMYB0N8Q= 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=CBLy9ODu; arc=none smtp.client-ip=209.85.215.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="CBLy9ODu" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-6bce380eb9bso1075364a12.0 for ; Thu, 20 Jun 2024 23:01:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718949703; x=1719554503; 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=ZfAHEKpGa3XV8xLDle5D7onb3U5kCj2qSA9C2RPk7+o=; b=CBLy9ODuXWc1O94n1EVIPY8eloHJKUlV4efKLjqNTa+1AnxzggkXJrqC16h4S/zQcC iigOqpefTStDkPZU/Y7cg9d01OyMjkHCkme1YzP44/M2p0xMWI5M1wyB9orHEPcV7RZb pFkFg8e4He1NX0iatBYPKNa24P0/D8M7t8KyOBWLAr4c+eNgAOVYaX7iHTjk5U/UeX0K FjOB3ux5IsZXHQK3E3PyETY7ckjQ1y5M/LjbckJi3E7GkEkq3VGIOr83qmk0gkh3FbTL uAfGC2yCzEI/JnJOMPk0qrC3zGtVpXR4eaxvkBzzXGiGc6ywfP5R/jg/oJP2IiBRI2eC C0cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718949703; x=1719554503; 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=ZfAHEKpGa3XV8xLDle5D7onb3U5kCj2qSA9C2RPk7+o=; b=fTaLku7Q56AV1sW655N2w24jC53UeRK/UWCcZmGZr7PTnwTDzi2I9KFBZF1p7pcMEB 5urio2gH35b1dKFcLMsZi04ygfzKUlicV5zlQQ17gRS/FcIUVRYEKvPs8x9rxQ0d8072 4LwazcnmOJ3Bg7FYeNG/Tnfl41JmhOJlP03952OczCggmtkcysy/gg37a4EkZl7N/bG/ fDlofmTR7Yx2HIWOja24fbVGmIENXSLxIyzZhxL0i563ntMSJwnpJoaOeyX72LNmUOmj VS6VrqrqOBJ6MMA7p18z6KoENSoW1FuLXo1iucUF/7Sa6tj2ZVoF2utgHb1f5hrLXleS Iy0w== X-Gm-Message-State: AOJu0YyW2aDZHs7Qt4ON77YjZc1Wr7W1QQ4kaPGEkfoQf835Q6q/hBTy FVhR9cmLgtZ1HzHeofHc8RcTDu0+nlR+UBgU1omgf9vIkyzfs+sBdsylZg== X-Google-Smtp-Source: AGHT+IH4x49PG04hudWM+egolIQZmRVqF1WR1n9DM0ZZHOwamRHdLw1qcREQsi++WrZqBdqHEJROwQ== X-Received: by 2002:a17:90a:e2d5:b0:2c3:296a:caad with SMTP id 98e67ed59e1d1-2c7b4e4c7b7mr8601865a91.0.1718949702760; Thu, 20 Jun 2024 23:01:42 -0700 (PDT) Received: from Ubuntu.. ([106.206.192.103]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2c81fe88e0fsm498661a91.3.2024.06.20.23.01.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 23:01:42 -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 11:17:01 +0530 Message-ID: <20240621060018.12795-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621060018.12795-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-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() as well. This can be achieved by using the wrapper functions reftable_record_cmp() and reftable_record_equal() instead of reftable_log_record_cmp_void() and reftable_log_record_equal() respectively. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-record.c | 37 +++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index 1b357e6c7f..4913a82441 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -123,24 +123,35 @@ 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 = "refs/heads/master", + .u.log.update_index = 42, }, { - .refname = xstrdup("refs/heads/master"), - .update_index = 22, - } + .type = BLOCK_TYPE_LOG, + .u.log.refname = "refs/heads/master", + .u.log.update_index = 22, + }, + { + .type = BLOCK_TYPE_LOG, + .u.log.refname = "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])); } static void test_reftable_log_record_roundtrip(void) @@ -362,7 +373,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 05:47: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: 13706876 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (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 D7CF413D53A for ; Fri, 21 Jun 2024 06:01:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949709; cv=none; b=RmqNN3xiBFaG/HbTeyaOPOzOu+hK8HprUDJ1aSfKB8E8ic+ls8VmLTDZX6M61zWQFsqgotpB3owo62jSVHn6MmePl6zXA6IGRT9DXEbQPIUTzx9uxU+/FX4fh409FtxuitQSO7H57Io2ZLvXAc4H+eOJwz4h/89Ma+BKVeQqF/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949709; c=relaxed/simple; bh=uoJsoHG++tARpr7+ZrrF8iXyGEAqHJXxMRep/lp7SWg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mITsnsuw4bhLZxbcrQIjpd2D2iAl84Rufdix2rj6YHLZ3qDpLkYD+rvxh3NYK4IX2JMhprSyZKUkfmi1/flcTOHcS1oyuAnzdVuCL+/Ilmipjt4jG9ID3PEnpTZMFxefxF3lT3QWXJrY7b+2QeoL/Ad1YiZPN53eJe0hUNKGzek= 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=ORlc/ZO7; arc=none smtp.client-ip=209.85.215.175 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="ORlc/ZO7" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-6c4926bf9baso1363966a12.2 for ; Thu, 20 Jun 2024 23:01:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718949706; x=1719554506; 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=MxXlvChIkI3a8xen9u27ZJG7F3HH800XXoiAUx+/lG8=; b=ORlc/ZO7sVfDYuDqHixwDacA64faohwJGcBHTt4+Cn3AnzKTlW148ay4Pr+nZYB5BC 2F7RaMz3LB7oqYb0lfoeSgmaWxfXd5LxScEWfArBEEoavjMgGEKpaz7gArotBfN+tZsc TTsaSQp49bY02ukR8n4TxV0O1YdSD3UDGvMVWJbsux1Kvw45aXf9jNl7G4U/mAObih7z tyv7E5GX5LrxoL9j6lANBbsHRAX0J4m3vaWDeROSMhieiwCeni5n/S09+y5ALVN+hMTI GLxt8/3X3LwXOCxi+XBGVM+BHC3UTNWUE18f4e+JQ5Q/+Mb/PuVi5pXpUQbBQtjqudsO OHcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718949706; x=1719554506; 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=MxXlvChIkI3a8xen9u27ZJG7F3HH800XXoiAUx+/lG8=; b=r7bdjyrsLLfNiocaoJUvZ6HijFpd9sYieyuxql6lqO2KHYZnCql3ncNw68nchdj8F1 dr8CgPtkf/XbtYvklLh/WAf6/vZI6WpdKYAbwXeajKziLrOpxGzn1k8fwNi9wMK6GSu/ 2Fu5/IiMI2qh7MDNgX5pSmn3Ls7i1sKhc5/x5MxsnXZO5UHi2U1UUsG99Fs108vSRIw5 WKbNj3TDKLzlMLmZoodPUBpW0kSzFbBnZvcTTe9Mh7v3vX2xl6r+sXCaQasWa/iYgH1P sqs+x/qF1IvtNRpKOHIKzdyivJ4J8ZyIuwbAwT/d4PRU6iIciFAupmhlVo2FU1+MBbZi O9Cg== X-Gm-Message-State: AOJu0YxJJMsSKnskJVM4KLVJh2xyD679alGcapIg7bzwIqmFf9QNc1eJ jB3dN/qzbwZmH4KdBTsdnItXRHMg6nM5eAeApoDMMiE6JIOm/0vfm0atyw== X-Google-Smtp-Source: AGHT+IH281CwNsxfgoD7m2Pc7fKD5HBAchBU0/bBs7thbe/gvIIFEoVboO+Disrfll6XSwxS7Be0gQ== X-Received: by 2002:a17:90a:e001:b0:2c7:9b9a:7619 with SMTP id 98e67ed59e1d1-2c7b5da88b7mr7180898a91.32.1718949706158; Thu, 20 Jun 2024 23:01:46 -0700 (PDT) Received: from Ubuntu.. ([106.206.192.103]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2c81fe88e0fsm498661a91.3.2024.06.20.23.01.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 23:01:45 -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 11:17:02 +0530 Message-ID: <20240621060018.12795-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621060018.12795-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-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 4913a82441..d25d11c7e1 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -66,6 +66,38 @@ 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 = "refs/heads/master", + .u.ref.value_type = REFTABLE_REF_VAL1, + }, + { + .type = BLOCK_TYPE_REF, + .u.ref.refname = "refs/heads/master", + .u.ref.value_type = REFTABLE_REF_DELETION, + }, + { + .type = BLOCK_TYPE_REF, + .u.ref.refname = "HEAD", + .u.ref.value_type = REFTABLE_REF_SYMREF, + .u.ref.value.symref = "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 test_reftable_ref_record_roundtrip(void) { struct strbuf scratch = STRBUF_INIT; @@ -373,6 +405,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 05:47: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: 13706877 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 2CE2E12D1F1 for ; Fri, 21 Jun 2024 06:01:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949714; cv=none; b=ABkJ3zjwm10FeF/G4H7+1asVyFwqLYt+D5u4EzK3Da/SLEd9MOLNsp6GXhaKNFVRiK1Uw3XrtaguVrTYZXUrJJbf/zQ/+5FTGqbrfmnIcFxIbRMd74aD0gHzoYOfaviGnjPvF/AGW+KfyOwOXII20TuFGp3uCB3uJoTOa0dwxhg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949714; c=relaxed/simple; bh=ze9UNMvk1PdVPQ1skTFc1t38TQNJY5R9jCuIqkZCahA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rzc2+QG4I5WAl5IlXsiJuSo0Iczb9nkdMpG+D4svogqGSsG8xyUbneN9GuLCusBF3VMS/KqEcwwEUePIIZgnrm+dmcwiWD8nuaVfPNbCluOev7ssgB1iRkJtISkrW4lWPrhn1dPiEpIMK/fLOQHOyPPxeJjmzIEHt8DfF+Y2+1A= 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=BCOjmpso; arc=none smtp.client-ip=209.85.216.42 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="BCOjmpso" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-2c80657e4a3so738895a91.0 for ; Thu, 20 Jun 2024 23:01:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718949710; x=1719554510; 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=ah6uiyzYH4PMxVjnjQ06uamLIux3nuA+ksFWHV+28Nk=; b=BCOjmpsovhdE2pEyzknemfnR4j8uOHVO/Xa8zaqdWQFjPjW6iyek5KZKLp8euMHGYw KWmBU1EtvmU1pl/0W3rOpgDY1VrlF5B2DyFPWM6EOy0apUrepfGkDC1z7K3yLz3XEhI8 dHrGa6pJhHhJQjl59rGg6uiDD3VgIfsBG2iS8sv+4xXtf/lmaDJl/mH0M63zS0VUO6Z+ 6oPWM3ZbHhD+SZ0GmFdbjkqUi1Jd0IYbTN63uV9z2D3KMkeUwxvwA+OfPnqu6jNZj2CB AuaHMOcw/GXNsdgqxxA5rZgKn5lA8gY2FoGgXj5seXvOtYSjrg6dJNyg1f0xnqdU+UnN 7P+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718949710; x=1719554510; 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=ah6uiyzYH4PMxVjnjQ06uamLIux3nuA+ksFWHV+28Nk=; b=VPujJA6xmOOlj12QD3hR2WGe72/v1jg3Lxcbki/HCc2XdSqgPGIFWO51xAeGatXj66 k8PH+eiPlgxHMXxHpgnOHssKQ4b8anMR8N4mJRAxKSxZAuP3nACCm9FQpFkClToASRQw TEUKHHTvC/+DhrMwM5WJ4hrE0iHMpmIGKnOc5089vGiEJYa4GTeK7cwUcviHLlwaEct5 H1knPS5y9BwuioTIRqcq0L120YjAizKLMGCL/IXPGYKtw8CK5wBbUQWwHR9Dg/yuvu31 4MKExujwaS1EBYmn1qGbg5DcA9i2bDsNjMKSudqxgH09MmjhCspcD7vpESiXimyMgNqz zjLw== X-Gm-Message-State: AOJu0YxLxazjP5B3zGGK2ZLiYNq66bDNFEC9RXbwctzaSbbNnAWUUSUI uM8L3QMxv8od9/F79FQU3kjhwbwBDq18ChR7fv5Lfg7/tNKEx8VTGV0nrg== X-Google-Smtp-Source: AGHT+IFEXRhW7cmdbNbmSaR7DLNEEtORMYjDNQ7ETd6YlCOzaOohAyXiZTFwMHHfGCdg5fboHBumHw== X-Received: by 2002:a17:90a:df0c:b0:2c2:f6e9:54fe with SMTP id 98e67ed59e1d1-2c7b5ca5289mr6820536a91.27.1718949709469; Thu, 20 Jun 2024 23:01:49 -0700 (PDT) Received: from Ubuntu.. ([106.206.192.103]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2c81fe88e0fsm498661a91.3.2024.06.20.23.01.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 23:01:49 -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 11:17:03 +0530 Message-ID: <20240621060018.12795-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621060018.12795-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-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 d25d11c7e1..1d102fb547 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -359,6 +359,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 = { @@ -407,6 +444,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 05:47: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: 13706878 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (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 E4BAF15C9 for ; Fri, 21 Jun 2024 06:01:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949715; cv=none; b=BDxQhKCxYyy5o+C1DqPIQroknYazE/vg4HzD+ddhfH4vkOCJU26oWs6jV3FtL4CYdZ+D49UISQB+9jE+R+ywlxkhhbMCW2MOeZSQAz6ChCC5LVHNpQZT0cY6hLmz74AV7cZuZM7PZN2OQEqt7mhQ0JWTAuEfpGiW/njCDtDjNtw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949715; c=relaxed/simple; bh=lDBFpozFSoflHALRUYkIyY8JoyPKrje4hLDbm07eJ/c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bLS89tDK37q7EylgtauA8buqrY+KRe4yk9aheP8VJI3T9v9Y/c96QhGzQ/wnJVFeXOyViJR3H6lKBLPTMygZWJkerYyTx/kF5wA57C1C1avXw6a98B5E1wWVWBkkctDs5RC2S2UnsKlJ9AuKsFXMuHjBVGSEFGNKS6Mfvb9u72s= 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=BWpQVH7j; arc=none smtp.client-ip=209.85.216.45 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="BWpQVH7j" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-2c80637d8adso805938a91.0 for ; Thu, 20 Jun 2024 23:01:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718949713; x=1719554513; 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=MIUD9NEsMqxCVKPLnRrHXXphhasmSpcrLUzRvyuptOk=; b=BWpQVH7jOBHNrSpLC76rdIdcXHqU9lIjgvkywMqOUX7rR+/KvRPxdHL2MGIsLl585n 5/nDbaNdO2H7RZnoS37liZcyc9kt16Xi8r+vMSmh5M3QmzzOjHqKBPCCusrKhdczR6gc xq6fx/HXvoFZFLEC7aYUhgm0GAmOg0C6ypc5xUIYG6Sz9XKcFn2KdxzWbGtmgD2C13C2 RveirrCRPlKK4OjC6wGtXd0uI5VCISzz8pPrECSCRJR7Pb2gFankt+6BraDJzLjy32bL PE25NIaHJegTGup9vFVEZvwTtV3o1s+LpEcJU99vRznpDtUDGtsxRfMCxLYjXniyUIuB rtxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718949713; x=1719554513; 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=MIUD9NEsMqxCVKPLnRrHXXphhasmSpcrLUzRvyuptOk=; b=XjcmxsPRQUlfQXVDQaSoPHNUDafHBRPkB1U9fPF6ttYZuQLIOYX8xx0JmGxocZQHpt UFczXW7OsMmabnU1W8TC3pj69+uQZnIqSEyOew6zGj7luOJG81Xv1KdrxTbvIeSfi5Di xd8savccko50fkZ1jt6DfetxD0I+1AqtNQm1A1/yH+SPfc5mTjQ6e9obwez7nuKmZkRY E4WT+5eQffBJYFHIU0wYKLJVG8GoJpQcdlotRFGMZyJsSYQRh4gf+u1lzXNzHkv/rkPc wVM7mQ/6+C3ZIeZoImOX/8M0ms+tEKzMFc7IRPTdMx1NYsl0gBIz90/BER064UyAiGMD hINA== X-Gm-Message-State: AOJu0YyUNPhvjt8GredkkDpNiAzQQv3c0fyek6jqzch8Cn4yN61IjP95 xdcweHWAVkGzgOpl5miBk5IUjMrjS+EYnuKg3BgRtkWxDRwvRVuZINpKtg== X-Google-Smtp-Source: AGHT+IEME+2Mh83hF71hJm7aRsOqcwdYihmmw86V2CKpDbx+EtFR6apYTPWl+xFfEBQk9ZYU4jl8hw== X-Received: by 2002:a17:90a:740c:b0:2c8:7fa:a29c with SMTP id 98e67ed59e1d1-2c807faa682mr2659790a91.1.1718949712791; Thu, 20 Jun 2024 23:01:52 -0700 (PDT) Received: from Ubuntu.. ([106.206.192.103]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2c81fe88e0fsm498661a91.3.2024.06.20.23.01.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 23:01:52 -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 11:17:04 +0530 Message-ID: <20240621060018.12795-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621060018.12795-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-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 1d102fb547..d7490db5e5 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -301,6 +301,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 }; @@ -445,6 +483,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 05:47: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: 13706879 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (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 24C5A15C9 for ; Fri, 21 Jun 2024 06:01:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949718; cv=none; b=c+fCDiFRx+l0msqZlJaMgopS5Fv3sb4U24OUQkn3434rDdjSxhccswv1M33Y0LDFcBTT3/Pnp+o+BSeG/onO5a43+6pTq92H2EQmi+q3nDvCHjT0p7bz+wlRACWDYn3zf+0ixBkxKNfOh/rFMq3DUsWtiVIVvs2JDc0aPUCDzr4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949718; c=relaxed/simple; bh=rb8XTwB1xLbFMwXVZQ1sw0EvrJkBNZRZzRXS2ELsoWI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P0DsYzlElBKTx1h6mPPDyW1qxBm3h9by8Mu/NXuquDdeMjU79co/bwg8mfvGKQ+tquba4AIGzPXGYz1VFuYaee7Czs96hNR2mRrLOKToi3j4NzTx/lwD0LZztxh2SL7aIUqEisVeU0hmxRFvV9iswoDpu9FDPE7V/mayG9BcVIY= 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=kEYG7UFP; arc=none smtp.client-ip=209.85.216.50 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="kEYG7UFP" Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2c7ecfc9e22so1106587a91.0 for ; Thu, 20 Jun 2024 23:01:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718949716; x=1719554516; 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=E3hMQjdCkDKBsQOBEV/f92WR7TRzdNbkwpcecxStxlk=; b=kEYG7UFPoQnuH+nPtT7ge7tfDOjAjU12PlZ/bBUwruaf17zKe60aSzp8fDNC9AnZZy C6URpjxw1DnOKCwQ1ChpYkDuNEZNUUJhXeMnOFoP+QDeCjTS9RPrpAP7JUAh3+JtjLO0 mJBsBzWUWoc+DAA+Q9BW2k5VG8EKSzbA6QUYJptba0oAM44avr8h5QajLiUAa1Ulpr8M 09AIAddzI9qD40CD1vqB4AWOcYwAVHJbWPgwV6XNX1HasdrMClZ/6bHuEvtV6iEb40Fa 2XLIATnnlAq3RgPckE9p+EPeCSqQiq2LiBM8iSU1D1TIiBgyH+iBU0tULnhyR0KFD/nR bC8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718949716; x=1719554516; 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=E3hMQjdCkDKBsQOBEV/f92WR7TRzdNbkwpcecxStxlk=; b=Ajzc+Eyl/tnvyF/2OVtUI4Ym0m/qFF3+mxcAqpGJ8xGTJz+HJIwsNMBr07v+B2ti7s YTg1GjDKLcvPv0osANFy1cVhZRjg1yRWCGiS2SFD+eZEgcBiVmfxaZSYOcYEAfsEsFtd zXOHvdxdAEU5hl1OhjjpbgAbH8wQx0rvl/WpJKYihMXCjqtHEKfE0HpXZq4ad4OsLsi6 xnHCiEzF43WlMWbQy9UocwEQnVUzhh9NLjrnDxcneTVkkuJfBVS7A7ndHzdX8zVMnhys j2CJKIg2YH591jUcDM+hb32up2PLFRMDM/7PzLCDxqWquzCNyDEpQfwd45jalmcJGcDd 8qUg== X-Gm-Message-State: AOJu0YxYddu+c/XLrtVpW7ZzFaryIG9UI3SaD19e1UAGNJApxYuxo/4P lbmswJBsVRXRI7DQzr875mJUuK7LPPEndT/FQXe6XxrlofAuYKL6heitWg== X-Google-Smtp-Source: AGHT+IEmBz4VMCO7G8c7ESfb0MCrOWdGpwH7/yWUJqf9pHVdavrRq5ForJXVyFTXtmMnN+OL35Hwyg== X-Received: by 2002:a17:90a:c243:b0:2c7:700e:e2bf with SMTP id 98e67ed59e1d1-2c7b5cbdb3amr7808551a91.20.1718949716058; Thu, 20 Jun 2024 23:01:56 -0700 (PDT) Received: from Ubuntu.. ([106.206.192.103]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2c81fe88e0fsm498661a91.3.2024.06.20.23.01.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 23:01:55 -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 reftable_record_is_deletion() test for ref records Date: Fri, 21 Jun 2024 11:17:05 +0530 Message-ID: <20240621060018.12795-7-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621060018.12795-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-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_is_deletion() is a function defined in reftable/record.{c, h} that determines whether a ref record is of type deletion or not. In the current testing setup for ref records, this function is left untested. Add tests for the same by using the wrapper function reftable_record_is_deletion(). 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 d7490db5e5..fe12fd2201 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -105,6 +105,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; @@ -118,15 +119,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 05:47: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: 13706880 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.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 326F115C9 for ; Fri, 21 Jun 2024 06:02:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949722; cv=none; b=ISOJ1jK1Li17akRGaO1mnR9qexV87hgCUw480NsJoICkeRXcPOfHOGhv8jgqU9PZhOYAMyeFPY40Q+IMdi/3NjvunFnXcbkS7B96jcMhyT1hoiNv3OagQQeh5DBE1oVHxQh929S2ZqsIooQBdv0XPvNcHLBAupDZ2WSiIwJrO8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949722; c=relaxed/simple; bh=FRRFj+biU0FDOK+auhVxu+qM+L6LLHanlMuLypicIzc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lvErt2LdhTEoXkFkozKHh/kl1MVSDYY0nyUfW1dVbAQSqOhTA/5lNG0pqPXuaWfahQfujUvsaYL/IGBAfGBY3vqhcSmg2d0Ai0wivuXWwV0+907ZBnCzapsUMJezbUxMFEzdDhqBKSX54pqoZsmXjVa8uL96nl9zS7j6xq42C98= 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=djBxKZOr; arc=none smtp.client-ip=209.85.216.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="djBxKZOr" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2c19e6dc3dcso1383124a91.3 for ; Thu, 20 Jun 2024 23:02:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718949720; x=1719554520; 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=/AxcpOZ1IWgBzmtpyTfGuJbUrRf2xTtgEm5r8QrHWPc=; b=djBxKZOrvV0NOLyum6+W5NMPbkymoTUNaNcyPOceKKdF93oMTGGVd1QTGEDdUEbY49 9ew3eXN48wxDWoFFhqZ0JMgByYUJoN7xbfYe8X7d6EAiA+ajV3jUcbMUN1Z2ZMKWcs6x hJUpVj3ihqYimV4dQ0um7Cys/sGOzTF9DWzOPj3iZ14wTkHJXPFotv6Qi1UCWTY8Ge3d +deho9DIYIh2SqdAPNBbK3kur+JuLnbAUV12hTj7Leh/kiURGgU1b2Pv2Fa07x9PgxC9 Tpq7oi7THIVnTrZ47CkRgD27pRojVlBLGLxjqSN5zuz+c17q4M0Ivjf2gsUQ3qvRfWzh 1IWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718949720; x=1719554520; 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=/AxcpOZ1IWgBzmtpyTfGuJbUrRf2xTtgEm5r8QrHWPc=; b=Ih1TFAjqxrRI7zhS2BChKOA5mmXRYihSuStWUvvK2NyifhUD1f9id6eYaHYh6YKtVI btvEzOsLkU0Buddx7Fh4OhoCvk07Ro+2ekgHGmHXFpcnx0psRwJSxGnFdYt4+G8qihfD Cxx+jVmQ/GvqEOrRJwq8vPfPf5kPiQIu6kT8n2eO+iotM5Flx3ZJgl+tzCwcLW+ZvXsX ZlbSO1e6diGeQ9mYw9yhX9RU/uUOB2hhKBNsbSN7102ETb9j9UpiK91blBz6Dq4eY4kC PwFXcLQHKQ40XtdCcspM+ssK27DaTe2Py+ZkmEhBYA8h+WtSEZRhXf79NFzodqekGDjY h/UQ== X-Gm-Message-State: AOJu0YwcRDZiDYpU98JgXBjKY8O3NJSUvrrShz0TFp0jLXhMtDd13XvJ jJfkcOUCRZevgxUjDj9g4RNFByvRWT+x4loD7cSc82GKcQorlbO7EoOsUw== X-Google-Smtp-Source: AGHT+IFnwSA5y1AqclWyYbvN7+UWbcAyjUPON7W8UYp0a6CBkjsVhx+S3xlC3DfXA4/NHx5TdBUYDw== X-Received: by 2002:a17:90a:f2c2:b0:2c7:cc35:2819 with SMTP id 98e67ed59e1d1-2c7cc354740mr5368517a91.3.1718949719874; Thu, 20 Jun 2024 23:01:59 -0700 (PDT) Received: from Ubuntu.. ([106.206.192.103]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2c81fe88e0fsm498661a91.3.2024.06.20.23.01.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 23:01:58 -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 reftable_record_is_deletion() test for log records Date: Fri, 21 Jun 2024 11:17:06 +0530 Message-ID: <20240621060018.12795-8-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621060018.12795-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-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_is_deletion() is a function defined in reftable/record.{c, h} which determines whether a log record is of type deletion or not. In the current testing setup for log records, this function is left untested. Add tests for the same. 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 fe12fd2201..70c1db6756 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -225,6 +225,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 05:47:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13706881 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 8E5D215C9 for ; Fri, 21 Jun 2024 06:02:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949725; cv=none; b=aZMjbqiSZuSi7ErBcaKp0/7VD3fVNtAHRUmOFgSOd7mf1VhbDi2j3RnJ8uozIh6jX14BCOsPZNglS92Kx6LCfRTqL5/AhjeJxSusu5gaCvigns8VL7OJ5474BtI93FLfKkUbF2wW7Yf9BdWFDvDMsvI1Ny7gL8Q7uHT6KxAFmV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949725; c=relaxed/simple; bh=ZKfkTs3VrsBroN2uapjdESCeNg3Zq69k0Jjf4AuWqRk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HEkKkkrstakTFuAqpRKQwPCedcsKMLUc4uNGC2+ZhtqLtynXD7YGOKQ2dRdnK6ubtZ7rJ3so0mcqm62k0ZIc+menMcoOcb2UpPoRx/7PIt8knhBP4SGPKvFc7YSOMsTun59wR09JJiKIEGte7bgpADUioRfl1nalxb95C890jQA= 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=ia9oEQsQ; arc=none smtp.client-ip=209.85.216.52 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="ia9oEQsQ" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-2c7b3c513f9so1422953a91.3 for ; Thu, 20 Jun 2024 23:02:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718949723; x=1719554523; 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=9DkFDrU8YzLgG/uSXBvcpdbNRcxxJdAmTSnFAAAqjnU=; b=ia9oEQsQlP3HJ+Pvk12CgxqUewKN/R4OdgZLUezC7qHoKgDofbXgOw0oU8NIc5CzXY G3PqKkHAdS0ymVFn6BatcRNuqOLQ9Ibq3D+NyZdc60UB0iXRRL/e7/yznRENu2+cjVIe nD5h1+fx9JGPd6dgxo6zVRCllYJH6HiJIlqIJjnAYe8iZmiFrsu+N0nBRfZA8yhSqX9/ OVPrbQZngEpJJqrlCdMXn7esBMVAq7fEY9+ajgcYvBdEItO+8WS3tSGY9jUbY8VsKtOA dcQ2Bg28LDGeBCXj4S4z/tb5d/rzxjH1RhYVLHAAoegppa9odpw4AS0YnwuK1WQqhQx7 dNvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718949723; x=1719554523; 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=9DkFDrU8YzLgG/uSXBvcpdbNRcxxJdAmTSnFAAAqjnU=; b=PU296uxCYVVs/c4ijZGE6PnWpn4NV7osMyM24TAoP4Uaqpi+/FdqTPW2Va5oBRv6Fy EoAtUBBq0KK1QiWjq7ZpxgoWRCpNyXlPurrUvYIceYisHwsBtQo58Ks+ixFiJveYEeI+ xvhxs0SURxN0i9UG2UBvABwqXCu1BrK64mthZZMHDzCIohzk48M/X4VR+5tHG7PtAP0S FWWR+Jek0xMIckEqdV89tE1xbUHAjYPSGDXYxlrtwQmlPWHrOZHdVrXiflxeid9uimrr 07M+0EwsaxRQxnwYCNSsagngSGYh5bfgoU2KhkL01kNwm5dTw14o/DQ386/m3nQshq8o 3C/Q== X-Gm-Message-State: AOJu0Yy5wyobEInE3RM4RO5kfIrj7fIGvCzAAa+A//hiTXO+p2F3h2Re /WcdR9fwbHiZSdKVpf8+iD4K0Eh1A0Dx4FLLNK97Cw8+mQH1TBZ/0frZZg== X-Google-Smtp-Source: AGHT+IHHMPSihLucVh99Zww450k+qH2xRG8KeKzBc4t+jhjlYcIKAcuMEYviHZQEqeE4J6VgbEklkg== X-Received: by 2002:a17:90a:ce90:b0:2c2:db48:aae2 with SMTP id 98e67ed59e1d1-2c7b5dc9c13mr7416832a91.40.1718949723149; Thu, 20 Jun 2024 23:02:03 -0700 (PDT) Received: from Ubuntu.. ([106.206.192.103]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2c81fe88e0fsm498661a91.3.2024.06.20.23.02.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 23:02:02 -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 reftable_record_is_deletion() test for obj records Date: Fri, 21 Jun 2024 11:17:07 +0530 Message-ID: <20240621060018.12795-9-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621060018.12795-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-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} which determines whether a record is of type deletion or not. Since obj records can never be of type deletion, this function must always return 0 when called on an obj record. In the current testing setup for obj records, this functionality is left untested. Add a test for the same. 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 70c1db6756..204a673260 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -389,6 +389,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 05:47:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13706882 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.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 87E6115C9 for ; Fri, 21 Jun 2024 06:02:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949728; cv=none; b=cmvFEKuw4GxKTq/FQSR68RGW6e5mAVbUYWGYzt79Cwr2GYtAgiePljE2dZSZhGZ611gHRGxEmVi2j3rZPRHhiZGr7B/lGtm4LtufrLtXaoTP0zloENxkyYvpHiSSEkS8JF7Ezjl06rRd61DZQUXOn4bqSRSVSx1ocggpdm2ynkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949728; c=relaxed/simple; bh=FlVAF9wt6M2pcZ9JcK7QQIvYNS9bJva230ndr0eUrm0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fAf10BzHH3KzTuo0xUnRvNmizEsK+cVqZWfpPkKg0eH1kgR8OY6C5L17AbG129tdebpFU+po5uD79F3/4UxK2rrYS5GNoGgUyBvqSJN05Nrydy+L0ylrKpy8deb5o46QpNqaJneaP4SiMifketvPjzJ4CiSt6MEfdWE5PXOd/fE= 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=P4nmrFnR; arc=none smtp.client-ip=209.85.215.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="P4nmrFnR" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-7178ba1c24bso48200a12.3 for ; Thu, 20 Jun 2024 23:02:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718949726; x=1719554526; 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=yuHVr3Ex8G49YCTFbAxnZfbis7iTgVCdTmCA1jys/DI=; b=P4nmrFnRuriGFIjWWzUMo8HwEj3PvAdeaiGU1RoquvTGjEinFbGqrP8tuYcj3uveXZ GhSFy2a4xhsnKa+SvLNaJKY605q3XBDy8tz5GxeR6FBrF6/+Q7FpmOxWnwMljzLsvZoh pk+O0SXbNqPZnCNII7sfE5+sPccr2zK1NslSyZ8Fif6SUxCwlQashgo/3ZJ7ll+RZiAL 9T4i0bguVa00szvpCdu5oN01iZVMZ7A3a8/dN0y/lfqRISHDqZFGZb3Adqfz3/+B8sMo SNQzqYnAL2Ywf9QkA+Ns0UqObpmwWFxFuqBYQhYNHWWE7vB8AUV9wsRFUlNB+WHkd3l1 D/uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718949726; x=1719554526; 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=yuHVr3Ex8G49YCTFbAxnZfbis7iTgVCdTmCA1jys/DI=; b=ilbzoPRDWl9AvOttTyQRqTCadj+XTNaMkm/F9xBsxBBMoQqRr7/SZIJ1YX0KHbjDJx 8nFnqqg9OdDzE6EBr15FAPWTK1W8QwGWye2Gf3wQATkUrP2YjpeQ32D+DAC81rawBah5 j0Y19reHvS9BG5Dmo4s99fTMq0BDAotEjhaaxfybwC4nJWOYyV+yaWjilPlOOtp9iMzs 7KQj4BiW4g25jL5MuL7r/HoP7jru/JqxQepMHiQonA0ehwbgN5R5enncT8r0VKdthQOS O29JC7aXBPxytBOIO52Leo003z9AYRv2mybR0mlPiF1grRnKPVMfX2EE7YBkvSBGQmUz sOxg== X-Gm-Message-State: AOJu0YwnhiRkrrcX9ZRHHHK4pzqiOSssAFjgbGt6SdGwrLRuU3en+zAO DrxlQMk9ZQpqbNqnkxxW4fFqeYuVp6zaDqf5tAQMGtckXy/QWPckodQiOQ== X-Google-Smtp-Source: AGHT+IEKodGXO2T9mLhZQOtjEKMqGfzsP5WYarVVUJyw0CJV7rbgD3DU1OJEl6A4aqbflwDAx0/BwQ== X-Received: by 2002:a17:90a:bd8e:b0:2c8:3f5:37d2 with SMTP id 98e67ed59e1d1-2c803f53898mr3209514a91.20.1718949726464; Thu, 20 Jun 2024 23:02:06 -0700 (PDT) Received: from Ubuntu.. ([106.206.192.103]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2c81fe88e0fsm498661a91.3.2024.06.20.23.02.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 23:02:06 -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 reftable_record_is_deletion() test for index records Date: Fri, 21 Jun 2024 11:17:08 +0530 Message-ID: <20240621060018.12795-10-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621060018.12795-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-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} which determines whether a record is of type deletion or not. Since index records can never be of type deletion, this function must always return 0 when called on an index record. In the current testing setup for index records, this functionality is left untested. Add a test for the same. 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 204a673260..bb2986eef6 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -471,6 +471,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 05:47:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13706883 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 5D29C15665D for ; Fri, 21 Jun 2024 06:02:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949732; cv=none; b=fKZsnVaKLtC/zQFWuYt32qnRJQ6LwmaKAWt2l7UIfkIq4cbyzErJGtaT9QgSie8pUqyIpOwArBfHVEEyfDbAFQ9mblXHgfLriASyEpeGfxEmmJsyEGxklt0PcNVioxMAeGJS9Vx4Nup4Sce+yuO7TJLK0u5B65Ox2HtEmZr4W10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949732; c=relaxed/simple; bh=kGozN0PNCDQg0ql/dELVVZXPn57dOtEhDCIExh/EY7s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mz+LJt2TJ4Mw4AjNA0EASb0W7u6lO1zG8hbvksKG1v3J3v2Ymh9W6pmwFHu4jGSaNvvUqDLpVwelaji6FFHbWMrLgMRZxmuAGZaHuOg4ImlP+2b6klJKsAYpvR/ZM2hqnn1s0k3pTBZzyYT7zRSUXeY09yN9iBD5ojxpz2T/UMo= 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=STbp8/Ki; arc=none smtp.client-ip=209.85.210.173 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="STbp8/Ki" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-70436048c25so1662270b3a.0 for ; Thu, 20 Jun 2024 23:02:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718949730; x=1719554530; 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=CCWxDG58DmCFHAUZ7wdMTUrJXjFUu4UDqHA3yP7rjJY=; b=STbp8/KiwnTpQgQlPSon9bHtHncguIE2xBeokqltguzrE7Zmd9iBDdPjkxgKFP7zoa fqr5eYAwQm6uZLicorA02WwO1KBscVRVIG35JSTcIauKWBXvbS17SS/VmJwk++71W+Id ViLaqPKPMp1bv+qJ6JhE3H0lCl68ruua8E/yOpp16lsJOgqRMYdIJySPDVH0fU7iHjCM rr1vIUP82KbaWwzbvD6bdPpCSCAVUIlwLeoeBOuNMI0lRfj8GNC+xzDrodDcgA3t/1/G VEh9XuqfnL7vkCKsy1zL9AVOth+S+WNuIzoTaeAE2AlZNlHPy8X7VlKBtBCYVDn+pk4Z MCIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718949730; x=1719554530; 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=CCWxDG58DmCFHAUZ7wdMTUrJXjFUu4UDqHA3yP7rjJY=; b=NKGIEg1EYfXSqZOxgwzyQkyQZXa05OBouWBhyUEswQpI9V2HSZ3fgSVULTLqQJ4XRL 303rQf78AkgIlIyg1AI4TkhcCOiLquLSZyByxLofT3NkYIVLroALqpcFswlPdby4GeMD 83cPuj+WgjVWZDTUo1ub8JY9kCy75G/AA48b7JJWMGq1FLZ/wY7WBQRxXTljuXeUgYs1 qcUMV/K82H0u7eY/LUk77LmM1S2LqO/OAG5qd4XPYsatMNkJFlAkJWm2j43EDh6xiH6B bDQjtO0O7OThX8yw8SU5xY6PtXe5+dEq4udzlHKIoXhUeSQrxcoMWwO9uANYUCGq1fLc PL8w== X-Gm-Message-State: AOJu0YzNbqQr3hY7vuZOointWIc/UIuIVyNmH66UgEXodCKvDod01dYx z4aQKNoBvvF8GMpFA0wyadysubwzpHJCD523qMu0of8CEsaoM9M0wC8yZg== X-Google-Smtp-Source: AGHT+IGmxt6VlGQaZNuKH5XdnUy55KyiXJp3b1FIiwy+OSkLpPI5bG9vWuehdibYrj4WlPqTAdCikw== X-Received: by 2002:a05:6a20:12d4:b0:1b4:c499:788d with SMTP id adf61e73a8af0-1bcbb422be8mr8777745637.15.1718949729803; Thu, 20 Jun 2024 23:02:09 -0700 (PDT) Received: from Ubuntu.. ([106.206.192.103]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2c81fe88e0fsm498661a91.3.2024.06.20.23.02.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 23:02:09 -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 11:17:09 +0530 Message-ID: <20240621060018.12795-11-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621060018.12795-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-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 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index bb2986eef6..e04aac8d7d 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -98,6 +98,26 @@ static void test_reftable_ref_record_comparison(void) check(!reftable_record_cmp(&in[0], &in[1])); } +static void test_reftable_ref_record_compare_name(void) +{ + struct reftable_ref_record recs[14] = { 0 }; + size_t N = ARRAY_SIZE(recs), i; + char refname[100]; + + for (i = 0; i < N; i++) { + xsnprintf(refname, sizeof(refname), "%02"PRIuMAX, (uintmax_t)i); + recs[i].refname = xstrdup(refname); + } + + 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; @@ -495,6 +515,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 05:47:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13706884 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.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 A98C116938C for ; Fri, 21 Jun 2024 06:02:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949736; cv=none; b=LdFLB2NmbsSDNbCg2pZl4DfRG4baUr78ftO2HOxiPDouyGD6w3wg9+Rsx62IKIgJaPCUyjvxKk/o0Q2dNDFPnLoxsNy7PRNgbwjWwmKQ95Tmh0dVE8XHYvoOcMeamxz4pQAsvwgw1WVL2XjPI6iEyV8QWmYtNmFUdyiXgjk+L58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718949736; c=relaxed/simple; bh=fZGm9Vq39DWbz4PFlFJIeOvlYJ8fwLz+L0/EY8iEM/M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HOrNjeq1laTOpjFT+KbxsNYw0zjxEapZzN2MHCf/7EL+TCh2Lr4orRQvhV2lkivTB9C8LRGUJoh6X0tbf5ttzA9cGDbochn29mnXsDW7T1QuOwc+WP452pc8q2yi/7quTevOJ4T57vlz0HCd+CmJB1PoKuMTG7p+Jkxm6UIaKKk= 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=mCzYWFLl; arc=none smtp.client-ip=209.85.215.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="mCzYWFLl" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-7152e097461so773964a12.1 for ; Thu, 20 Jun 2024 23:02:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718949733; x=1719554533; 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=yNj73H7WYin+GIFCl/UxITc6e+Ekj70DYfq7txp4Bng=; b=mCzYWFLluNJ3pQANZZqSkBOtonX/EBty3duCjdnrN0Dlj/AgqBlqYRGYXJbk1NgNC7 VfCNuxCdjLKKVRQT3dM8TvJWoRvBjzCH7nI4avN6VhD3vKt9BVX2p287ako6nniL6bA3 xtMF+fk6uCPhx+HW4oaLRoa8RjgbgZicZTqdhc4094XMrLt8/Ffe6YUCgaCyQwkjs9bJ MOIOw+/oM5M4kpPP50WSgNn9uh45tPEPjbqWMnPXuRqb96cKivT43d3WmWeZMSOJIADC yTDPMnHCTF59cCUY9L1ZfoeH2V12n/Q5aVTGz4Ft9kCn6krKiZ6gQg7VURYQM/4gWgPX +vYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718949733; x=1719554533; 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=yNj73H7WYin+GIFCl/UxITc6e+Ekj70DYfq7txp4Bng=; b=qKlN26MDAr95JfvhcwI88Igex55tfRYe+Qv0EnpNNhFumcRwYKcr+CmBbVtBIvcPfk 7AshJqraVUGmi3tbj7K6wHfSIZqSIlswFlqr4gbUW0xSY2fIV0Tiqs+BXQ773pm8cX0o 6SDFAR0q6xODSR5KAhTzB1bCpix0wgtVp8YMxWg9Bs1BBupHCxa1DemXI0Jm0AlMPPQb efl2jBSGeSF6qSkzbT0QAri4AV40nkdgfVsipxDE1zhE9Jg6SlgP9z3lfNWip9raYGTb luI07Am/A8Sr7CgHVU+ApamlzOBFH8bZgWd0vx0K8PxZhWqiRb9Bc6ToY3Ljm9VUaMhV 2P5w== X-Gm-Message-State: AOJu0Yx55jM2Z1860AauREeJltolKAIc9U3yF/9S3C010lK1xdyrvaBA o9oQu0isAhG4b4ensxDMoXlHNklaz5NhwLNkbNEVM5KjDhe71mIoCBgwWQ== X-Google-Smtp-Source: AGHT+IFDb+PCXIa5ShC+9ARO69CwEOe0tRs6/Q24F6dC4nJKwHl8nvxfyrgBMZT6fw2lfoRnc8RomQ== X-Received: by 2002:a17:90a:69a4:b0:2c7:45a:d237 with SMTP id 98e67ed59e1d1-2c7b3b0eab9mr10567132a91.12.1718949733071; Thu, 20 Jun 2024 23:02:13 -0700 (PDT) Received: from Ubuntu.. ([106.206.192.103]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2c81fe88e0fsm498661a91.3.2024.06.20.23.02.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 23:02:12 -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 11:17:10 +0530 Message-ID: <20240621060018.12795-12-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240621060018.12795-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-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 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index e04aac8d7d..2765701214 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -211,6 +211,32 @@ static void test_reftable_log_record_comparison(void) check(!reftable_record_cmp(&in[0], &in[1])); } +static void test_reftable_log_record_compare_key(void) +{ + struct reftable_log_record logs[14] = { 0 }; + size_t N = ARRAY_SIZE(logs), i; + char refname[100]; + + for (i = 0; i < N; i++) { + if (i < N / 2) { + xsnprintf(refname, sizeof(refname), "%02"PRIuMAX, (uintmax_t)i); + logs[i].refname = xstrdup(refname); + 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[] = { @@ -516,6 +542,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");