From patchwork Fri Jun 28 06:19:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13715526 Received: from mail-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) (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 161FF6F2F3 for ; Fri, 28 Jun 2024 06:37:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556632; cv=none; b=VuhGSXfwAxmd5OelelawyBjnEkcdqJKyh+46Kyl9/gPxYYUclcllIxH69zZ7sxd5fRvK+sGbPohjwHLEwb7WN3WfNHOONTj0zHz97myM9Gjl5dyvconJrikLn8mul1XpEZ9/GEbPiZgIevvK/FnG35gMEYqld6b5+phgzNaVZDE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556632; c=relaxed/simple; bh=rM10OPjnjPmmEnkDmTs2flSLjlbb4PWlOMbAXE5cdTo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QzTkqRps8ECMTcAY/j+X2IToFvaFzuXrFP8VH0zOQGYPsFS0SSoVxD004Zg2NkyAB4uuYJtGS4u6GZzmMttQu+2VZY9pM9ebzhg9NVHyYZEg9BAKlBwJlyWBtY/MSBEIN0U7qnvGxKVR78QGnz1SP/7+lb/1w9fGFoByu3N+N7c= 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=aWd79IHp; arc=none smtp.client-ip=209.85.166.43 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="aWd79IHp" Received: by mail-io1-f43.google.com with SMTP id ca18e2360f4ac-7f624e70870so25139f.3 for ; Thu, 27 Jun 2024 23:37:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719556629; x=1720161429; 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=mhwFF2AyHrTE3R8oWcTDImuVlgx5DS6vICN5X78OEis=; b=aWd79IHpKHiQj8SxYgVNeF7Iby3X2pMz8o9IzJR/WCDOqKHggom4w44Zqj+O/6oC/g JrG8hU8MK0dIaenvVzKQxTlemSNtPFYE4dcaPPQVaNe/7pby6fxns6ns7efHG3HM2QaM /MXe9VQ/JJnPlLy9uHbxItahTiMNpe4XTRvgg53CgrP9+8yDouVjaE6uSylvaaQx5pjl oFNzILG9cbrWTQOjwQCODMTlLF9+DDeIqVTOpHZ+hXq744+7f0IZ6cXot03vug1fywzy mV3HAUsOlXuRIjvK96afYCYp3GjpFzSedZhbpFgzS0uj3O0ZprlswxkL/+/NDTzwnSwG 9Lww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719556629; x=1720161429; 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=mhwFF2AyHrTE3R8oWcTDImuVlgx5DS6vICN5X78OEis=; b=Tgyv1YhI8d55U5OlgaH7MksJkcFuXMPZV0tmFDH8n/Cb9W+Qg0wC66rqklrcCKzYq7 oCaVBnG32pB0XrVxmfvShnh19H/gy9qkbDbik8A9fDlAl0eNkFB4gAAc7OAJq/Sm8dPU 5RW8yRmxhzf2qWqs5cNoJk7rbMgL4ommofH4I+mJZ2xK8PV8EpfHSo6iGyn3u1ChtoAM bWwM5XIwoDz7ROGSTFd3aL3AmCsUB1C0X3+a2zGGVCcXiZqAdFaTi20HQjaU6Tl4RgL4 V8dYHfyJ0QGHghp5iUgJ2+N32Yzr6Gy4/f1+slNRXM8jtCZ7PkO2tLhrqLDNsUQuIJ2q FA0A== X-Gm-Message-State: AOJu0YwkVgItwZNKxiUoyEhrhPbZN9GkmNTdfowz47jAUtIW2iIqlh8I 5ZwVdiSyVYR7SSOTo52NRIdtdWnFUQ0RKYgBvJJLYlktC4z6Fdt34e6RnsKAPKw= X-Google-Smtp-Source: AGHT+IFMaGO+a6jAX9ZijJ4U+GlCMd71vAvrL5lrBVEuq2SXjuQ3mI5ExaQwHnhYz0bLSi6Ki7HqXg== X-Received: by 2002:a05:6602:6d87:b0:7e1:8bc1:57d3 with SMTP id ca18e2360f4ac-7f3a7588598mr1874636339f.19.1719556629162; Thu, 27 Jun 2024 23:37:09 -0700 (PDT) Received: from Ubuntu.. ([117.99.235.160]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70804a93ce7sm786003b3a.207.2024.06.27.23.37.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 23:37:08 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 01/11] t: move reftable/record_test.c to the unit testing framework Date: Fri, 28 Jun 2024 11:49:31 +0530 Message-ID: <20240628063625.4092-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240628063625.4092-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240628063625.4092-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 reftable/record_test.c exercises the functions defined in reftable/record.{c, h}. Migrate reftable/record_test.c to the unit testing framework. Migration involves refactoring the tests to use the unit testing framework instead of reftable's test framework. While at it, change the type of index variable 'i' to 'size_t' from 'int'. This is because 'i' is used in comparison against 'ARRAY_SIZE(x)' which is of type 'size_t'. Also, use set_hash() which is defined locally in the test file instead of set_test_hash() which is defined by reftable/test_framework.{c, h}. This is fine to do as both these functions are similarly implemented, and reftable/test_framework.{c, h} is not #included in the ported test. 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 | 107 ++++++++---------- 3 files changed, 49 insertions(+), 61 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..9305919e1e 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,10 +20,7 @@ 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(©); } @@ -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) { 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 +99,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 +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) { - 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 }; @@ -217,13 +206,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 +241,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 +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, @@ -311,13 +299,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 +340,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 +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(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 28 06:19:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13715528 Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.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 D9D807E0FB for ; Fri, 28 Jun 2024 06:37:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556639; cv=none; b=peYndwsHI2HPhavsiXdOXT8jxV//FyJ2kJTY64ooRg90AsWOx0w3U5I5IlNVGZAzonZ5OEUnp50uvi1JldIDDjS/LH/mcSmYqv9EJHtXe+E+cC6ytf89iBAXVBQM79UIjTcuvE4HgTOJoh+CVq8XxZxLE8uKW+qGYFd1wjZHbTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556639; c=relaxed/simple; bh=pJ3RRy2LV9Y1begKljn4MTG/q2YxPyWnq2jeuw4PwqI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bVkgeGB7sGZz43CHdG2lKfRShZECFKieP+97b/bcI/PH4fojR8nz4SKHD9ZSm3g+kU9qzC+79HnTXlSjNSm+XULCAUzWxXlSUOz0qbRPD/LbWaj/1zqllO78cFbFX+w1zWzg+v4C/dcskdQoZIF6YMcpdyiHuk96LUYmqSD0OIE= 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=f8zplVBY; arc=none smtp.client-ip=209.85.167.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="f8zplVBY" Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3d562b35fb6so158076b6e.3 for ; Thu, 27 Jun 2024 23:37:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719556632; x=1720161432; 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=nTKNtf0Hzo0wYVprslC7gTj07VA7lPre3x2EJnw78H8=; b=f8zplVBYQsy7B5bbY0X2kABvAOQ59CxXxxOemWMqhOH3zePHrXLLs5rPQ/CLZpKCkC zEq6cNv/5IigDeOLKimxDXmilZ24oJGABi/EW0GikupI2Ms1SX5+BlwCw1NuX84SmTi9 sX1MI82VWZx5ZF6+gjZjjohD2uVf6uc6+Ae2tPfUMjXcOG272n3UQL+v5v/QSYYtquP1 34wpdbwr5eopL0rUnACBv4zx7mxwAHqrsRqhtQaVuoH/7vAbqbLzkVXhwcbkXOewTR/Q 7wMEnLuwfhvyLvW+gVMm13deZtgc9lSh+0q6XGZJEWn+ss/eH24aXikUY/PcPSRBwAVB Mx0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719556632; x=1720161432; 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=nTKNtf0Hzo0wYVprslC7gTj07VA7lPre3x2EJnw78H8=; b=rP8vA11kcimn6vIf/6x16pdBG7EL6/4JUHLRbVmymULetgzkEdcEOlaTCPgLS3Le+y dCaX1r46x0rD8wjxDpJgTxjbPksUn8yqYB7fJjTvMpfDV33ndSAN8okbVprv2D1/LW20 KoVJiI9M6KRP4pjODwHMi6xWfEcl26v5UhrYsnJ67CmquU22hCzpm7fQnNmrv7rMIIPz bbxlGKjRk9aKkbuX7bdtIdheAv1irkfzNmVeTBrjEs3XM4Fxh1GyraHdLEJpycPO0bdm CPJUbaoplLpXo1+OiJ40D5b8bPgm2XbGebNjTsyOBnszK5Jr/xkW0S89jt2xEEHn/OiE owZw== X-Gm-Message-State: AOJu0Yz2b8yRdtDgWmqFRmEr+RwiB4DLdPjymBSFQjFWNKLeQkNQvucS /BDdYjHtMLl9NSiQm0+qE93xIRONXOkixC/pRiqvjD2094NOleOyfiT3De2uW+U= X-Google-Smtp-Source: AGHT+IGPYufva2CrsSpB+2vS5NUXjIfdPRrDF3mWOCmgUJcOVUEv/SEDOTm6/IxeNeNQna4pClZMrQ== X-Received: by 2002:a05:6808:1388:b0:3d2:2b43:1808 with SMTP id 5614622812f47-3d541d45316mr19677517b6e.55.1719556632037; Thu, 27 Jun 2024 23:37:12 -0700 (PDT) Received: from Ubuntu.. ([117.99.235.160]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70804a93ce7sm786003b3a.207.2024.06.27.23.37.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 23:37:11 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 02/11] t-reftable-record: add reftable_record_cmp() tests for log records Date: Fri, 28 Jun 2024 11:49:32 +0530 Message-ID: <20240628063625.4092-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240628063625.4092-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240628063625.4092-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 9305919e1e..82988d9231 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -120,24 +120,36 @@ 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 = (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 test_reftable_log_record_roundtrip(void) @@ -359,7 +371,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 28 06:19:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13715527 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81EA46F2F3 for ; Fri, 28 Jun 2024 06:37:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556637; cv=none; b=t8ASP8zdkOUwlIrCFeBtaw6Cfq4oaZWlsb7N8y+IgGnhFU1n8p6zvhiPqdA+4IH7o1XMz7To+WhwnqxjAmxRskkmJmGnArRwml8Dipi+/dshP+ADXi/EC+XlIGOXCs5kcby4qmu/S+ZhxTSyGnRfWEgldjIkPnstMbDOMBMi/Ao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556637; c=relaxed/simple; bh=2RGKYoOflRPlpaPlN8au/OOJe0S1P/Ugn4N1GrcdGbM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YgsbJZk84vVwoh4rn7ffM4bjoU1YigTVYAgbmhBQy0DQeTSHAAdJ+pA8MLSZOoplNHY0nSShBxA/fczL6XWCKDWBYku5vQhKJgIcTUHtFuDcA670DeRV7G/1deOu6tfkZ+p4i9Aask1fDQx1sYGY5+A853DwX5/t4XbX/7vYra4= 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=JevGgab5; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JevGgab5" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-706aab1b7ffso243638b3a.1 for ; Thu, 27 Jun 2024 23:37:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719556635; x=1720161435; 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=8zf9IA6MXUcABFH2EsqnWuHVk065kriLFK3PKrLW8/Y=; b=JevGgab5Cf1DE/vu5OCEWidUk7Yajxyq4OwmctltyE3Kw4aeFwdILg5/uu/jRcq+Ka eS9/K8mLZvnQQg67M98FJyZJagH2CWSBNhs4Webi1b9RNoA9ayrxK5TT4NeACgQoIFUF VSQJ+hyV4NGkCCUYKokw6GT6ztlAWagulSEix7phMDaWpSHqx3VbblpM3B4qDO36LspO ziayh8vBPN/wdasaGXlo+IgWsLxP+dcQFYr6GL34dORI/M6FQQ3UfipNJIP+o+JiDHuB FuXA1oMH1mR+u/MzKVLQfD14qmFVAsCwEumKEGlxnLcS/R+H4nRqPUndrQQFzmhTqnLK GKDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719556635; x=1720161435; 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=8zf9IA6MXUcABFH2EsqnWuHVk065kriLFK3PKrLW8/Y=; b=PdPoeX/wmz5WBPK7XrDnMqs16zlHlFzjiTeaBBDyjJrlnVm0wCgPrBt3A8wLmCzomK syYokGctKTHeuWbQvfNKuAZNvSmfgGXf8vLWbRjufsdobk37xY0atBSUiQl7yRBa9PhY hEvrwV20chsrxXXbBnxmi1SH35gED9uSHnoAjS7/KRvqnoi2h3a45pAEKRFwbsazXKPP FAVVLJ6kYtX/aDPL94K9jrdDgs/+NFeYIXhIYEqpogamyosdKTDr1ixXDE6NzxQ8ycE8 o9V4MTP9JV/C/bf4qs5PiHbZncgHGxk3fM380b8DLHXnsyI5OsCd2qpOAaVBlC9i55je w0qw== X-Gm-Message-State: AOJu0Yzb/bmUmi+jg+Msmxm49s7x4KHrmFYGQAIHZO478JM6UTNizUTT X9wVdHbitlc2jU+eUdzuN3cJxBL8sAadrxo1ZyvG7i6jnKken6hprtuyokP6ouw= X-Google-Smtp-Source: AGHT+IFUT1MI2vTf7Nnjd+70DyuGw/F7sBJqirP0wFhg4sa2hqbTEs/RfqrWbQy6hWDdgLEcGHUbFg== X-Received: by 2002:aa7:9edc:0:b0:706:29e6:2ed2 with SMTP id d2e1a72fcca58-7067459359dmr15769260b3a.5.1719556634927; Thu, 27 Jun 2024 23:37:14 -0700 (PDT) Received: from Ubuntu.. ([117.99.235.160]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70804a93ce7sm786003b3a.207.2024.06.27.23.37.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 23:37:14 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 03/11] t-reftable-record: add comparison tests for ref records Date: Fri, 28 Jun 2024 11:49:33 +0530 Message-ID: <20240628063625.4092-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240628063625.4092-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240628063625.4092-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 82988d9231..aaa49e76af 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 test_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 test_reftable_ref_record_roundtrip(void) { struct strbuf scratch = STRBUF_INIT; @@ -371,6 +403,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 28 06:19:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13715529 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D3957EEE4 for ; Fri, 28 Jun 2024 06:37:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556640; cv=none; b=a/gBM0GC2QvFrEyQ5oMeoxouwrK16Q8kgeW6CsiOxJF+7HcbGH/e12Dqhk+JWf5485/2ecEbEG646uAkgVTSMV+V5y11+lQD6/xHANG3QhDvbdN8HtVNRMktuR+0pyzNvxsBp57UQcoIFJml3Ad0i4CPMqWLaOH3jsrTn9Vgi2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556640; c=relaxed/simple; bh=tJRnzruNQbL9u6f52Inm/dlFtFVFl1JHwLfWG5fXhOY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IS10oJ8a2qvL4vc2olXBQyjMB80Qg7k66qjpIx8IwNpEfwJP8aCRUoh6MaB474PGztFb5fwUPYVLxEbKfWtE0osqrJdD6NK872KR2cvKbVxMIJ6kaQFCto1HNMA3vj5Vx41EFOMC+qJ1xfsaKNydoNcWflZuZhk/QaoWnKPhHmw= 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=WXuDvmrp; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WXuDvmrp" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-70675977d0eso238873b3a.0 for ; Thu, 27 Jun 2024 23:37:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719556638; x=1720161438; 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=RGsl7AtgnA+dBBrXfzwaiRwNb/aaQ6maeeZJKQxk3dg=; b=WXuDvmrpW+UF0zN8B/erYIohTDQtvcqBzsvOi8p9rFEvsveia6KNTYRc2Cx+Kd4bXW bsaV8jfLTVddyrg1w8v1QXjMiFIP7mkqscezK7XkPNpB6nQWYwEVyqsmxLSjVpsIaeo2 duRAUj2m0/t9ow64r9y6rLeftKScfqenE9yFlHnaNQAffeU4Tfu6NTG0C0pMBQxJJ2UH t7MDiacNjzLnOPh4ckowa6kmuUtKP9hfBn13b5tbwGPOR9jW07LgHEt4wjEy9AaUG8lR qa4lWz0or22Pz6+VH4be03D6brDOWCRzr4oSD/r+2O6B/0dDpAu6Y8/0yswJKYsjTTrW vRPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719556638; x=1720161438; 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=RGsl7AtgnA+dBBrXfzwaiRwNb/aaQ6maeeZJKQxk3dg=; b=VYol/H5sp2bosgbPNXgg0wTm3L1cyyDYhFd+bV85GxncsbOa1pXL3ZjphMo8z05PD8 q2jNkalLvK9bb+9eLe1qS0cKsi/PkrQK4TBtoABAjhdWnPAczfE0GFp0f8XZiJBFVkGn EqVgQM5I0Lean6z/omhFiST0nRdkrJIARcNjZHQ5jV1D5TIRihZOx9zaeHq3mDAHtmu/ 1fwYS5gA2Kww2WHhLWUa6WKoqIRKD966M1RfsbdNpx+bS4eBVqRq+0qtLo6P27ZjX5wH LHmXfugqclFAjTrFjHSzzXAtFBadHgFc+XK1CND+nA/Xh9AZSLY8X8TKIPfU3GlLqWWN LIYA== X-Gm-Message-State: AOJu0Yz8s4NeBg/0meBwwf2fy3+APve1sD2VWni5UHmhQdrDQkasIhMr tfRK7Eg0DMdPYZEqWIih23X2mEHfEhuAR2Wgaq0gjahjC+El1ldzknwU3/hozj0= X-Google-Smtp-Source: AGHT+IF06TF7zvw4SxNBlWg26XmC7a5NvyQUypAKFXGlDhZ+KY3ets0jnQXfRJLxC5UnNmWt4YMlLQ== X-Received: by 2002:a05:6a00:80d5:b0:706:3329:5533 with SMTP id d2e1a72fcca58-7067469450amr13930810b3a.24.1719556637871; Thu, 27 Jun 2024 23:37:17 -0700 (PDT) Received: from Ubuntu.. ([117.99.235.160]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70804a93ce7sm786003b3a.207.2024.06.27.23.37.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 23:37:17 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 04/11] t-reftable-record: add comparison tests for index records Date: Fri, 28 Jun 2024 11:49:34 +0530 Message-ID: <20240628063625.4092-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240628063625.4092-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240628063625.4092-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 aaa49e76af..e242a3923c 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -357,6 +357,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 = { @@ -405,6 +442,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 28 06:19:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13715530 Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.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 B05AD6F30E for ; Fri, 28 Jun 2024 06:37:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556644; cv=none; b=AzZ4Mb4mB3G+DCPLsLmKC68NrhYDqDFC76Vo/0yiyu7UZ0VbvYBzAXgL7oJQTATM5rqe+wTGKfhVNfiHOAlCEgLa9iANbJrpG6fLdUG8dnviVdhJbsSwige08Ei5tPwkm+bn5xK/OGDbRJgFxZEdZo/fYL5ffp1kKgLsrsjHYkk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556644; c=relaxed/simple; bh=C6FME0k7ynPldudu0jkCQRgGAEjpyrUAR9OvFTILbRU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pdo0xbvLXp32llz7i0JR9AhP5x1dH2sf+ChBUMyo/ACbXybLBRFAkcq0CRYAGTd2St0fKz27X1CZ554tkmP/gx2RsME7vg+hmIfW7CniXd3GIaCwl7pn/Bkz/9VmBL8gQAbqLuXlDFNESoDMx0oQEcvM7b6U6zGwy0WfK+8l3a8= 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=Ab4Js9bJ; arc=none smtp.client-ip=209.85.167.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="Ab4Js9bJ" Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-3d55ed47cc6so161155b6e.2 for ; Thu, 27 Jun 2024 23:37:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719556641; x=1720161441; 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=rDijk4fdcZL1Vh6O5OQRHk5Kw7/talJd4QVeXB0hW2I=; b=Ab4Js9bJnj/dNeUdFi4HjIOAzb4VDO30XZDDhud5R3x++ZLl6zBwWVDL9Q03vnNAbT cE2of7vTeGliHl+jXv0QCa+Olsdjgt+CkRKRhwfJHhu0gn99eMThAkPOnTEVJXF25G4K Yq4980UN8zf7NDFkU6lG/N4GkzMk/vun7CqA5AH6SNturdBf2KTjmzucxEUFDI0yzp1c dAqSti/L7dG1mkCVJnAwJ7r5xs99pH+YuwGtU010Wdcs9tvZYhGEmqN1MTxTXG7QOyE+ IiFQbjd4rHu5jkXHGCJCOTwTD+4VV8WqT3T76UzwguExak4phZ9LErDRYF6Jwf0yCRYo Yy5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719556641; x=1720161441; 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=rDijk4fdcZL1Vh6O5OQRHk5Kw7/talJd4QVeXB0hW2I=; b=DkckSTb1pvBK7hs/LlCLnwzWamvVq8TNC6JWFU0swtg1XfmiNY43yzUZhc4Jr0/LFx Qpyz86oSncRJkzp0t86C3dkg14I1XLudeBql7fk4Dph8pF/UxH/O++g+l8TgYMauQpVU WkmaTPrIa6qn2NKwytOMSmYE08qEuV7fKXYDh1GRDfNkDeqPxvaHjq2/3p6rkzA6CfSF cswyFPuYFth6LNbIocDmFLpm9gjdo0GIcGZNEzubz4z4m4AwltzBjyOeDo/9qAWOokwu sYDjfkV4x579HQcFiqKVcDyda5WBzlph3aMAacm5J4DnP4H8RYhPFa4i6MA73wdAliWk sAdw== X-Gm-Message-State: AOJu0YxAPIUvZuGOeXuzVQOZaGfE5tYYG/LbFpbU1lnMrur0ioVCQyir O3waR4B/a+B+3JkRkHwB5ga/8V+A8OgxxRg/fyfF74QE39OXjcbZ6RxUi3GRp/4= X-Google-Smtp-Source: AGHT+IGZtHGAtoKLwKpIFggqyv1Bdv4gKKFH7k9QLFTg7NOfgCYP5aaBpe6Jc0xrQq9X1oWX4BalLw== X-Received: by 2002:a05:6808:2018:b0:3d6:2d45:a791 with SMTP id 5614622812f47-3d62d45dd73mr3400845b6e.32.1719556640829; Thu, 27 Jun 2024 23:37:20 -0700 (PDT) Received: from Ubuntu.. ([117.99.235.160]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70804a93ce7sm786003b3a.207.2024.06.27.23.37.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 23:37:20 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 05/11] t-reftable-record: add comparison tests for obj records Date: Fri, 28 Jun 2024 11:49:35 +0530 Message-ID: <20240628063625.4092-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240628063625.4092-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240628063625.4092-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 e242a3923c..bdd54ad265 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -299,6 +299,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 }; @@ -443,6 +481,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 28 06:19:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13715531 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 311A37F7CA for ; Fri, 28 Jun 2024 06:37:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556646; cv=none; b=XI3pStyYvWe0T4nemnIYx0cAgRgRyPYij4oMuktUBsTsC7Tyuv0NjULZ3A18UIfFvFYOMFHV8ij7mrQYYAMvv7RSuGS+FB/ZaqEh1juRtOdOgfr6Yzy62NZERpxTj9LXHnGFQec6tG7+7YlhKqR8/nij4MD8B59bR8d4xy8ixCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556646; c=relaxed/simple; bh=J6fRcqA9KNuIkIUbPTwYxCsvDGvdQNDbL1BjmF+9fKc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bpTCqVqCiwqscpbrxCYSNxHDYSGcStYaNT0BtuJ6ITKSk7o9+B0ObeS9DyDJnS3KiTtgatNouhz26qj+zWLC/4H4/2RGdZMvXcCCFLgDRu0zMOpVfiAS0jUCZyJ8JtOJL1S1rckA+f3r9HcRzZQdQBu/ZWR3lJd/mMnC34sEnog= 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=IIEaUqi0; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IIEaUqi0" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-706524adf91so230479b3a.2 for ; Thu, 27 Jun 2024 23:37:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719556644; x=1720161444; 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=mR1gYwxf1gvJkrmxV64urSShT49X2F6oNEtOnMdN/bs=; b=IIEaUqi0TTdzlwjqLsI4MAZw/yMY60WqLokmo4sawOSS12UKDR0vaJzcDNXpFlrsTv azXNwZt5P6LqNxpBjPylUtKPnVD2rIgTXB6S980fG9Tmxa+1+/V7ZcAf5ir4+VxVWFHW lnN6gYhE0oftUILGg/2obbeVufYEUtBtawfZx6CcMZ20cOF7Aao+Fjzzd1gf88GBANaY 4o4WcYP9O3/ASw3NB0j95JJKAhYFFnF7IJRezp92FUpT305WAuNgTvC6uBPbogpjrNN+ KKwuzbm6cyNzJ+IP6FiLjr6+EIBNGwwryZzusrnYKQ5ugPXUQYMWCjej6ECV229yEmlt Hddw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719556644; x=1720161444; 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=mR1gYwxf1gvJkrmxV64urSShT49X2F6oNEtOnMdN/bs=; b=JqZsdbUrvdnXVCXMwW5GbhblC01qqYyYfI2wnLq9CwHAzIS/iPmsuMlICW0ZOGxKmU ZxXQK768ebX2CAv9rWHzq3Obiom9WX83RLoYxz4psCnnsbYhgXh6XX2O9KM/K+ibfPEx iPbTXubiKHvLjEfvqN5gspJGEtiFmuWk/4ErdeYh9bZwBQY4QbZR4awenEnLbnEiAUZY R6jGAcdyrpSDn3nr+3sQVN3ZHJCbOW6Jiz8COpsIpdT9EeAB20HFeF7GRjsMUUWTgd3P EDCl7mXCXrCryHEBaPKnx8dkcxyb2MZo+RdYa2fFJCCOHZel7M7djg2wlHWo0Allbre0 +8Aw== X-Gm-Message-State: AOJu0Yx0gTKTs+3jzD4w+S14ztuPXfDsZSdgfFj6Z8OfI48ULo0IoJU/ N93YSTBkr67RKuOQy7jGCpu7LSsD8pr8xReKYSNOsfXRltZj0br+c+jEAQ5HJMg= X-Google-Smtp-Source: AGHT+IG4eeMNHQfdtLl/8AZuMcIUnIQOFBgUHhA72CkZPDAk3A1ap3P7ECAHSjJEtgRo+rY2UKBXOA== X-Received: by 2002:a05:6a00:6816:b0:704:2d99:9ee0 with SMTP id d2e1a72fcca58-70671084e1bmr15516903b3a.33.1719556643778; Thu, 27 Jun 2024 23:37:23 -0700 (PDT) Received: from Ubuntu.. ([117.99.235.160]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70804a93ce7sm786003b3a.207.2024.06.27.23.37.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 23:37:23 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 06/11] t-reftable-record: add ref tests for reftable_record_is_deletion() Date: Fri, 28 Jun 2024 11:49:36 +0530 Message-ID: <20240628063625.4092-7-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240628063625.4092-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240628063625.4092-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 bdd54ad265..99dad75fb1 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -102,6 +102,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; @@ -132,6 +133,7 @@ static void test_reftable_ref_record_roundtrip(void) test_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 Fri Jun 28 06:19:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13715532 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 49D3D7F7CA for ; Fri, 28 Jun 2024 06:37:28 +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=1719556649; cv=none; b=PMAT6k5agGV8yrc8Gf0NEUt0SdrCHUH/vLv2oE3vlZ+z6zRjJhb1uOJCuUo4HO/DW68kkTS3qJfPnNuVbFskbd2cv92VCKmLXHyDPzVjroSLzTb5RRjCsTd7/hsdk8EtNzwQD8nL073RDtPLotaSywZkgdAgoiGEVrv/TaSjE4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556649; c=relaxed/simple; bh=BP06EDRvZG7FzNWlKj+6KEwAKe9JagKTD+thyQkpEEM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ilCC+lGXbOP8i9/qDNnEbRE3QRJzVib1hwVMMTN+8J3J/uiCFkrI1ajkyeGOwtdVdibH/lVyYkDP7ntuW0VMIPEuQp7x3UbtaE0Ft8OdkEpT1y/Ld4Cf5MX3gqgtBmnV0KtewUoOAn/AbeG/wyyM/h8/Mbnv7tuM2UnV/WgJkOI= 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=IJ/yroMf; 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="IJ/yroMf" Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3c9cc681e4fso159537b6e.0 for ; Thu, 27 Jun 2024 23:37:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719556647; x=1720161447; 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=8ck0l/MCxUwUFr2m1o8QgrlNLROreBXDTUAJK5Vyax0=; b=IJ/yroMfdfYT2qVMl63eGRvdvffCNjiHVxQUysMm38hhD5oauTB7KnjtjZCGfZ76QK FyCs1d9RDb23q1JvgzpVw//alOVb11XdixzGA/Ux+8u1uCp6RI1xlZ/7nWeYWSn5vhML elprLHjYmxdPYN5ACwaB8e7/+NxD4XdPYgCSXXF5n8PLtV8GvbT7FjNq7QnVFzOT1c1k E7k7xjeVCj6ZVndGg5Zj90nJORuQlL61sTa3GaP/LvcyYn36NQxDjVDJ31QFaX2RPaGP YyRqr/az3uOjEUeK9khR8RpTcxABKNEVGEui35OQtNBVmx0KasHhayCZfBCfK5xHlNHk blgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719556647; x=1720161447; 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=8ck0l/MCxUwUFr2m1o8QgrlNLROreBXDTUAJK5Vyax0=; b=sLWy07/I03K+F6WosTE/TrJHTfbA3i/SvhHuglcPw3ApLd1s2fOmsfC1L97fInZ/Xq 3vpCITNJxC/1dyDw956XaOcgS4hPR8VeFhpon5DQ2udm/wqG8OmJYSKsCpxGaBcIOw2m vHWJfRIjXqzMCC2PKz3voPCTCrdmWaMZ7NtRLU9waDDSGUGs8eC5QOCjVFVRywI5gO3j DtOiPzqE6eqT0GAdj73qDD++M2bR/SGOP8HSIldLd+b6H+IdpchYawOO/4JgcQxQDspv /npHm+P990cU/vrVkjsUVZW4BXpjSsU1OfxCX/SXHZFJPegoArF3eiKQHQDRzdJQyFhO pcng== X-Gm-Message-State: AOJu0YyJxiVO3OVheV9YJEMYeCxNpYDVLzN7g5OUeOFmJ85nYfU7Y8aH AUS5vDWPoO1lohx6oGd+6YMA5FVetwDqhA2SGwcKZyeAKE2LTdgYd/bRnXCTh5k= X-Google-Smtp-Source: AGHT+IGgW3o0sAXSEtaleCJE/d4RnwXTZLJZuESzo7K8qPz96N4hPHVaRFcJp6QZ52CHyhFsOJxv6Q== X-Received: by 2002:a05:6808:2226:b0:3d5:65d5:edd9 with SMTP id 5614622812f47-3d565d5f1ddmr6294057b6e.16.1719556646741; Thu, 27 Jun 2024 23:37:26 -0700 (PDT) Received: from Ubuntu.. ([117.99.235.160]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70804a93ce7sm786003b3a.207.2024.06.27.23.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 23:37:26 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 07/11] t-reftable-record: add log tests for reftable_record_is_deletion() Date: Fri, 28 Jun 2024 11:49:37 +0530 Message-ID: <20240628063625.4092-8-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240628063625.4092-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240628063625.4092-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 99dad75fb1..8983d54bb3 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -220,6 +220,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 28 06:19:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13715533 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.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 21BF17FBC1 for ; Fri, 28 Jun 2024 06:37:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556652; cv=none; b=FEFkS97rUpGY54i1wD5YrYt+KdmDOwQHxNzCyzK1/7z1FLe11UHg7sgzdPLhuAiBhtw0uPXPRVPpqh9HPX5Uw2CR8GGWxSQH7bNQhiVJP28C7FZzFigowK9y11MLxD5tjjwWXGSMo7r3bt9f/6dcNeSDckgEcvMdT1WNAH/qcmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556652; c=relaxed/simple; bh=OiNQkyy0wmBiN4odcZ/SHAVkGfyF5vW1xrvjmW//pUk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=onpvkbFsAcqABE70XZuHhDQ/Oh/Oulo52ci5z8CxV2BC/0GyYY4q3obKjqbBL5+Jsw+33YvNnRNmO8Skm7uMjZyewpYWxRFwNwsCffokXc3j6i7lvR89k+tZvXbN7wSUA8L+aD7NDVDPB9J+4HaK6VyFdbYuxFAOStbsLewqXUI= 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=N2oMBdfd; arc=none smtp.client-ip=209.85.210.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="N2oMBdfd" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-70699b6afddso226042b3a.1 for ; Thu, 27 Jun 2024 23:37:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719556650; x=1720161450; 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=ntGe1fp4qI/haA+jyjU2pwEYgOjKnHwAHyi65t3Eo1U=; b=N2oMBdfdzcSMhy8TIwMM2GOE8hMaqXs82kP0MpKQWnKVGeFoPEIG6ykX0Xj81B7Y0e ATj/IQRZLScY/UPOxsijixfAa9jMKHzMnNjAR1+6XfNKpMLYMNaB5IMEvel6NXtlGR7J m5xipwfkoqg7LRYMP3jn1w5Syqqm+8rq0g7TqAOQSnLmLcCe+bEouA2KMPqUUIcy4S23 Jfc/d9qfr31Cxv6HOOoXKGFrhdEMxw+GOE9FafbmLHBwQWRVo4H10nZRpXyNDBpXxYy3 +RYaAq4rmYUgLgTHgQOT5lb4kzlb6qdL8VYFBfGIuoGMb2uTeYs82r2Xdaq9KYKm9klC sOCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719556650; x=1720161450; 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=ntGe1fp4qI/haA+jyjU2pwEYgOjKnHwAHyi65t3Eo1U=; b=Bx2ylS3z2HrYNQyN2pwg7suGWM2KK8r26wkOuwEqpbvmSd7ULHWVzpMaDDciKxpfec dUSQZzI8wJsrU3kknm/9ipiDpRV0nRmmJxiLSieFQzX/aDPhv896AENZESAH5I5OCkhg 2RkvM7P3KNDuKFn+RDvFT1a3OrAUUaXYKOO2ngVewivzLXUREkwspR6D+OYvIYV4gWpI GSAt65XMWeC4fxdpXlJhXTjumWoTeBdCzs8jgVcQpiUYZbwSK9alQCaXEldTZFRbKOyS l3PAxdWDxyt6Krz2Vllm+1ZhhU1yYCug/EA3iZLk44i+j0qlAS9d58cO4x+36RjyVTkF vrDA== X-Gm-Message-State: AOJu0Ywo6TeiDaePLhpe5XS1QgVVdwZQ5XwoYXlKc/WPLRdtjpHT3dxK h6+2HdT8mQ7CuoZ2nWgGbTKVSLfkpTullZydUnCzhg5gmnwEwc/NNXVVlVL9H6I= X-Google-Smtp-Source: AGHT+IHjVh4QEoMU60DZlXpwVH0S8J7q4hJ3s9HiJC7Vi4Prt5uZLokYYTF/Ih5+AtjIJtYZqdnHdQ== X-Received: by 2002:a05:6a00:69b7:b0:702:38ff:4a59 with SMTP id d2e1a72fcca58-70670e79d03mr16299352b3a.6.1719556649846; Thu, 27 Jun 2024 23:37:29 -0700 (PDT) Received: from Ubuntu.. ([117.99.235.160]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70804a93ce7sm786003b3a.207.2024.06.27.23.37.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 23:37:29 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 08/11] t-reftable-record: add obj tests for reftable_record_is_deletion() Date: Fri, 28 Jun 2024 11:49:38 +0530 Message-ID: <20240628063625.4092-9-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240628063625.4092-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240628063625.4092-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 8983d54bb3..f2422a7af0 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -384,6 +384,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 28 06:19:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13715534 Received: from mail-oi1-f170.google.com (mail-oi1-f170.google.com [209.85.167.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1003C7FBC1 for ; Fri, 28 Jun 2024 06:37:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556655; cv=none; b=rBeuJda7gDKyh0/UXb0r0KLcQfCGgzGPptfTF0ZnovV+K90e18WOImoh9AbX0jhfm6Pe7tNvji12fM/nlqq2t/rzHGJuZCdu07py6UJJUHWaDNq6wQ/vEgQ61og/tHsudGidAMZbOx7SPvSqBl4NKwrZOC2K6OxZuCpAV7cxizM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556655; c=relaxed/simple; bh=whBOa+e0rTItv+W18a+Kfok3zqsNWeqCc9aVf04Kjks=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UxsO9R7m48nsg8sEVrYX5a44hQK9+R0B5QnHvb0CrP7RyXWptSic/sFl0qh9kiTxjdsQYxzOQiop/2ftQljE5kMG9KQsJE21PSWYO+U8Q4FE8wfkHrFHNPwRB/5mNkJzdUFFJesB7UOJ85toF0qv+BLD2Uvny7n+4KDkRQfctCs= 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=ArAfEb4Q; arc=none smtp.client-ip=209.85.167.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ArAfEb4Q" Received: by mail-oi1-f170.google.com with SMTP id 5614622812f47-3d561e564d0so154532b6e.1 for ; Thu, 27 Jun 2024 23:37:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719556653; x=1720161453; 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=aJGDfO5+rCQHcXLZ2juVKKM4NHiM6JoO/Tsycmu++N4=; b=ArAfEb4Q1L1sGu8jTY5eNYYK9PGgRkyp85/ncud7n75TEFWlvzCJYbmGbtexM0owgd bq0kEM6zVSP08k5BiM2fO9pVFLiIRUIkos99A4TlgBH7Iq2ecjQxYFJ0WUultPjk69TA +cJcaoevgiglag3lMFWTwuO0I1YKhjNGbbajZKDYS6kw/7WrJAqbLBOZRJoDoKZrVHA1 JYqJQdm9nwWz6l+HwFjlE/+1O6MuT+KfzFi6k/CIUEx+qG4btHYZpLQ9b2ECDxWvE8ns yn+Cr4haq9gIKJCEtmZ8zpFjggusJzn3MbSAv8pJkANHqC99AAQrk41J7UoaalsND1CF uLVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719556653; x=1720161453; 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=aJGDfO5+rCQHcXLZ2juVKKM4NHiM6JoO/Tsycmu++N4=; b=pmEE9cu08sBxW23MhjdQFnHO9jXCCKfqx2C4wmEfkbK5KqLUNIMPdDh4SoXE8ksoe/ 2rFb6JjhnZDdreNrP8IcIh42iCXshY/pd2PjzBQn1lCVmcjCgfNNb301nJa3NJ9nTRG5 nsnQVa4/HlCUIvmtMj0j28ixskB9fFw/Z1vLJDyopAUoUthv9nANTHBKauNp1YLWaXAt /i1Ld+qh/IDcUiJ+e5aHcpfBCo3JwrkMFLqy3+NFyk+ZkGTFTH0ISR+1si6w9b5IqoBs NAw2AhmHjnr7c7n7D+2GvbawypU+UyesitQ1uRCjKWLECgDOul+dLdizfK/8OL6nJ4G2 b3tA== X-Gm-Message-State: AOJu0YwxLiwNRL8++8g9jarQsJovVmjLMqMnLdYPL9k+YeAeuxHsa9gk RPtv5frgxdj1ZhAmIzsefJvLGW7vJIXAepEzhy8Wc/ZOaqgqLq7/z1BYiS8QeDY= X-Google-Smtp-Source: AGHT+IEG/zluRNv4E4YkV1V3rduGz9ARHz1fzqKA/mNTbnsWvzGHg2QlUD3p5H1NBBwf8viIkJwCUQ== X-Received: by 2002:a05:6808:1492:b0:3d2:1f71:1901 with SMTP id 5614622812f47-3d541c915a5mr18169030b6e.29.1719556652728; Thu, 27 Jun 2024 23:37:32 -0700 (PDT) Received: from Ubuntu.. ([117.99.235.160]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70804a93ce7sm786003b3a.207.2024.06.27.23.37.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 23:37:32 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 09/11] t-reftable-record: add index tests for reftable_record_is_deletion() Date: Fri, 28 Jun 2024 11:49:39 +0530 Message-ID: <20240628063625.4092-10-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240628063625.4092-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240628063625.4092-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 f2422a7af0..55b8d03494 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -466,6 +466,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 28 06:19:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13715535 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 73D2F80BEC for ; Fri, 28 Jun 2024 06:37:37 +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=1719556659; cv=none; b=LpeQk7g+0SOofM0u7lxN6rYMzRYalrQb7bp7EzKPlUrowqgYTZ/z0UALU1fyQTNaLkVLJJPi/+NvnCMcIN9ez5ATLS0eKTQSqLUK+sHLJKtBYVtl01/TpzMgJGrWe6rX8uZxoczDd2SVX5//k538SG9Md99ltZ2EVeUW9AR/6GA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556659; c=relaxed/simple; bh=QrPwgborrqctCqeQPOf8HiFfX/Scxe86B2fyjkKGJ9w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SNIdBU4rFGmeLyxz4aDCz1aeYRDO9uOUDbwTUhqAmpwzxS+8g8MQtrRAyWeYfE/eV9aCtzbg+BQrjNgVJ81DELvR9HWdlreMc0MPqhzbUMq14Qs4F0vC8f+RFOBT58BlShRm95dubPm6VmmtL6aC8J46sw+Eina1iC7z4pxiEuA= 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=axwHM1tZ; 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="axwHM1tZ" Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3d562882f4cso179259b6e.3 for ; Thu, 27 Jun 2024 23:37:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719556656; x=1720161456; 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=Xv592SfPjxw8jhBL83Ylm0VRCACmKjSSuf/KOFQ4CKA=; b=axwHM1tZ1Gptsoesy5ACltkHS3Djr77EyAaSY3lWN9qfWUVBSV1ztvjBufOFLtZp10 NqSWqnByIo+Lu5LAiP0nNFnvzo/Yw2pGnXqC/i1F23L3yH2QHPvO+3GLyXL9n4bi4P70 0kWhEG+ggbZxoAkszNNAS8G+cLSrluaakh3SHfTeVOTpTM55IyZZV8bd2kAoBajeGSnw WrOlYE+ZKN6EiELC+R4svaHhuQ3u2A4dzPOeOrIn4sRn2K5fP+4PSqhQhilu2UB4dyHE gPd4DdVySLEfBdknjzQW+glyKPaqGjp74jZee7l0930+WzahM9qc08aP/RivcVEyuTc0 EJ2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719556656; x=1720161456; 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=Xv592SfPjxw8jhBL83Ylm0VRCACmKjSSuf/KOFQ4CKA=; b=gYfs05PlpOK+4yceipkg2Beo4e5/pr45fDrfyobQX7XaIY3oBrjUZ/D8vD7PmhZbSz DpR5cEcTDW+El395M0g2ZZNd5W4GltA1dShbbiKhalVoCivuizqHZKEKkyqsRem4+QUl t/MvGjYOKRuEHefQ1uWa8LFPSi+QLdMtUXKisx0rQo8JC9oW2wjM5mAxjcMAqaonjLFW cZxxuO8LQuShPKlsIgH85W97rVP5H3I4NQpeLpwexoZBnwn6W9JWbPvL8/fYsdrNnzwh 9VT+sfH0F6OLgtKkCHMFC+qNaHeX7TtIE1AB6w3XDBNcroNQsU80aneHgKJcEvEOjZSg i7og== X-Gm-Message-State: AOJu0YztvW4bASG+fTWp5KkB3NCyC20auh1fBhBGA2qaOiRs4Dfzt3tD VDMGV7PuKjm4yIK7EHGDhYt+WZrKhaYpD2boP8iG3sslbFyLc7mLtQZW91Jfa/E= X-Google-Smtp-Source: AGHT+IEwGO0HuUeUB4YiF23VMgzNMQlWhIroSVnzx2EAOVkHHSIDyRJxj3boEa5q8q21uglfKJONbg== X-Received: by 2002:a05:6808:1704:b0:3d2:26d1:5fd4 with SMTP id 5614622812f47-3d54594db07mr20205769b6e.8.1719556655677; Thu, 27 Jun 2024 23:37:35 -0700 (PDT) Received: from Ubuntu.. ([117.99.235.160]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70804a93ce7sm786003b3a.207.2024.06.27.23.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 23:37:35 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 10/11] t-reftable-record: add tests for reftable_ref_record_compare_name() Date: Fri, 28 Jun 2024 11:49:40 +0530 Message-ID: <20240628063625.4092-11-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240628063625.4092-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240628063625.4092-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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index 55b8d03494..f45f2fdef2 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -95,6 +95,28 @@ 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; + + for (i = 0; i < N; i++) + recs[i].refname = xstrfmt("%02"PRIuMAX, (uintmax_t)i); + + QSORT(recs, N, reftable_ref_record_compare_name); + + for (i = 1; i < N; i++) { + check_int(strcmp(recs[i - 1].refname, recs[i].refname), <, 0); + check_int(reftable_ref_record_compare_name(&recs[i], &recs[i]), ==, 0); + } + + for (i = 0; i < N - 1; i++) + check_int(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; @@ -490,6 +512,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 28 06:19:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13715536 Received: from mail-oa1-f50.google.com (mail-oa1-f50.google.com [209.85.160.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 5612380C0C for ; Fri, 28 Jun 2024 06:37:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556661; cv=none; b=orDCMeTZMeXt2+asfp69xSiNsUB+fuS1U7jAQ8s48H9iZVRiE57k0/1R4zu8n1llF/RnHOgqSrKWoy8CBCzTcd/UR/CwLUDnw0D4mVb3AZaCwSVil4ekdiRO3pjzAaID6fmwRCDWKV6eg+BoElT7GmfbVzaBIqVvZXkNEO/nSmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719556661; c=relaxed/simple; bh=T+1tfK67SzEbhuCd9Z0woKSeZywierHZz0RNb4XgviU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MSfjJKu7EURvQSmYdQr9t8UDjJJNfk3KtdF+hR1LSu3rS0nhEcCUyIpVChF/q9GBUhvHG6bC6QbI/dRaxrravvGeGkZ+r9lzJ/yFnAoJfK7znou8VIHZycE1xVB67XvYged+Vl1xvuxn8PcMbpHPbgnIrLB3j8kfV4MUpHlErQs= 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=e4ydsD7G; arc=none smtp.client-ip=209.85.160.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="e4ydsD7G" Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-2598ae41389so134370fac.3 for ; Thu, 27 Jun 2024 23:37:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719556659; x=1720161459; 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=ZHPJSar1HmgdZVZs1GFo6+wyK1RzKRckDCfAbp/EbXE=; b=e4ydsD7GcBl3N2Dg9i1D78HtUvX745lmQTTYR+SbManNhuoxcnClIP9WNkExhFONsy YMvgXoNFH7lRB9nf4r4EjanghQzQ5VwZLkIZTtb2Q+Edf86zsiDFLI8KPPaFYI92WUrE IBCRQVBcdBpeuPrve0/nuCCdK6HZ2Gwt59NTKLab0mYwNeB/0+YkFxLLTuSaxT9QNFzl Vd4hQifOkL5a/mExvXymZnshnbAF4BqBVUPe+sCzMga40JQE1xMmqMvM7dPZrjOtUs2V Gh5EEBGZw7Wyt3czILbR2I18NhFU74sksiLsDfoDLVC8qYmdmgtQF1J5mO2zY+Dl7pKd YDqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719556659; x=1720161459; 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=ZHPJSar1HmgdZVZs1GFo6+wyK1RzKRckDCfAbp/EbXE=; b=I9BJRCiDdzrCas6u5c782E73H1rZ3TBO8xiBCbNiiELs5uBUTBmOuMI8KSy5IsmZP/ iwdMQJmFI2Pc4Jns8A7gX2V0DoXSbBTE8tL7vM/njkhh1Iw1ho8D4hqQKoLWztMRfIL0 pwFSqcS0SmKyUC3TjO8gDwZauC9H246PnMZokKXrqlBdjnOXzZV0XfFQhLULFWjAYsIu uHCZu5X3PFsynSp2O1C0wX/+3nY+difNu1FNv6q9XzqN1FBnOoH0Y2RUPHV0fNP//JEm iJHIWdptPFTU7FMF0b4J+NHYmCgtIw7tKkfAk0EQEzfVmZ7fbmo6OqdwmjKqIL6M8EYG 3SoA== X-Gm-Message-State: AOJu0YzvlhLPdC4FVCFhThfmbZFj4ww6d9MGIVNyHG4oeTgoPBtmJZCS 2ovXcJfbLkGgCpNKfD7MKI74Et1ewXupf+j2yQoTgPpMJBnfcMziZ4DKHUSXs/g= X-Google-Smtp-Source: AGHT+IH9WJKfNBNMUfPQn6D93Rb+mbseAJ1B4Db4QpTbxLXVf+4KetIegO+zaK/EPOB2mx7aBuhk7g== X-Received: by 2002:a05:6870:c68d:b0:254:aada:cc8b with SMTP id 586e51a60fabf-25d06ce3ab7mr15586734fac.31.1719556658675; Thu, 27 Jun 2024 23:37:38 -0700 (PDT) Received: from Ubuntu.. ([117.99.235.160]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70804a93ce7sm786003b3a.207.2024.06.27.23.37.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 23:37:38 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: karthik188@gmail.com, Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 11/11] t-reftable-record: add tests for reftable_log_record_compare_key() Date: Fri, 28 Jun 2024 11:49:41 +0530 Message-ID: <20240628063625.4092-12-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240628063625.4092-1-chandrapratap3519@gmail.com> References: <20240621060018.12795-1-chandrapratap3519@gmail.com> <20240628063625.4092-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 | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index f45f2fdef2..cac8f632f9 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -208,6 +208,37 @@ 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; + + for (i = 0; i < N; i++) { + if (i < N / 2) { + logs[i].refname = xstrfmt("%02"PRIuMAX, (uintmax_t)i); + logs[i].update_index = i; + } else { + logs[i].refname = xstrdup("refs/heads/master"); + logs[i].update_index = i; + } + } + + QSORT(logs, N, reftable_log_record_compare_key); + + for (i = 1; i < N / 2; i++) + check_int(strcmp(logs[i - 1].refname, logs[i].refname), <, 0); + for (i = N / 2 + 1; i < N; i++) + check_int(logs[i - 1].update_index, >, logs[i].update_index); + + for (i = 0; i < N - 1; i++) { + check_int(reftable_log_record_compare_key(&logs[i], &logs[i]), ==, 0); + check_int(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[] = { @@ -513,6 +544,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");