From patchwork Wed Jun 12 05:38: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: 13694445 Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.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 D462D1EB45 for ; Wed, 12 Jun 2024 05:51:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718171467; cv=none; b=qz5MNOwKSP6ujQfTME3iKo502qLDmzl3T6XdNwTkj28CcvsUYyK7V+6/wauF+EWg/aKhXcLebifkjr7g3llLgrcQU652wUqgxTWTybK2lk4zKSbaDgIvhAblThZVhoXKkuMWZ57Kz0Jil/gkB1ym8TR8g1UlbA743gFO3cC+eZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718171467; c=relaxed/simple; bh=Vg8lr4/Bm+hHi8Pl4iOuphqxbznv+5JAh8YSrO08Rjc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MpNixcluxQ1TyLatBNj+5zee+cNkwqoPIX7RG57hv+eK+sglEjQ4+nKXemUJV5WLpPAop4BZiAKLqz7Ny7D6I8mJxxVUlku8E1e7m85sW5zNcqHlIrgFS0SBsTfQKZZotPfmqCOCDi+5A258vJrRkjUPkJ1d8EQOHcFyLNk3N3I= 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=PF39fdaQ; arc=none smtp.client-ip=209.85.128.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="PF39fdaQ" Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-62a2a6a5ccfso23562837b3.3 for ; Tue, 11 Jun 2024 22:51:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718171464; x=1718776264; 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=P4X3e3Z7MOsPGcx9grwDTf7tmbLprv2+NFWd/pBK21s=; b=PF39fdaQXsnXqXeR7MEam8L+8ZjO3fUmt3OHxDOgQ1FPAtXIogxQTODfLj8NjXm5f5 SLbueYkZo4m1GK4wV0+1m9nCvySuiM8kFRo/Yku4+CbxnGFWxGlI9PLuBclHDS62OdcX j2SZVrVNaiduP5ECRL6ienac208GwSXSaDHVppezUgI8tkrEQeVr8wEHsneQmdC2ByYK 8fVYDthE/djM49DkKurVk2chFg4BDmTcYEBxeuxsyLMqBDp3rjoHg3rJvsw7VzuHs5Wy lUm9uDQvHAQx+Iw7BSl2MV8yOvE+OQhXRjOTKlPyi6ajS76750JS61g0gzOV5+V6BnP/ Z0jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718171464; x=1718776264; 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=P4X3e3Z7MOsPGcx9grwDTf7tmbLprv2+NFWd/pBK21s=; b=cSDoVr4yc8fUGWh41JjDbdmg3E9FnI+IeIiAyYjP/DKsNxHmogLY7N0dqrdHy+y6Wc X8ky62yRvuJ+aZQfyWCzTjXfNmzY7yp4kneIdqhIdguLbH1HPT/LH23zlULXKESNi5oV F2Twk//22nl2tdCCcbqqH7bD8KZpqa60WX2xap6sLewxypU9O/yJlomHiEHYbEF9m+Au 8t9UBTEMfeT1wjjrhbbCCUq2pwv9kLeOKXFxp1odilDh7kTidppnqZIZIUmScp0GBzq7 l/+4AHWulti9bMsZKsn5BZwj44NFsLZF8F6X5oLczHXaKFp+h4QkNRFCs1ciq5TvUZJ6 arkA== X-Gm-Message-State: AOJu0YwqyRAtZZbOWUmcweU7vsR9M0epxKThpUN3kPL+BoS5wmOWrWKV VSQRKhMoFIq1ByR+hMd2a2zEodDpI8cVfM8GvboKnpcODMHc/JbWNH8GkpG+ X-Google-Smtp-Source: AGHT+IEcvLjVhKB2mL/BCfWnHDpk7mE9R93XxB0qoo/jCTN0xnMZYsO0R5ZZlkfW7yfhNWTaiojqCw== X-Received: by 2002:a81:6fd5:0:b0:615:8c1:d7ec with SMTP id 00721157ae682-62fba375d32mr8510137b3.33.1718171464471; Tue, 11 Jun 2024 22:51:04 -0700 (PDT) Received: from Ubuntu.. ([106.206.194.53]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-6f78b8336a7sm1934114a12.73.2024.06.11.22.51.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:51:04 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v2 1/5] reftable: remove unnecessary curly braces in reftable/tree.c Date: Wed, 12 Jun 2024 11:08:10 +0530 Message-ID: <20240612055031.3607-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240612055031.3607-1-chandrapratap3519@gmail.com> References: <20240610131017.8321-1-chandrapratap3519@gmail.com> <20240612055031.3607-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 According to Documentation/CodingGuidelines, single-line control-flow statements must omit curly braces (except for some special cases). Make reftable/tree.c adhere to this guideline. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- reftable/tree.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/reftable/tree.c b/reftable/tree.c index 528f33ae38..5ffb2e0d69 100644 --- a/reftable/tree.c +++ b/reftable/tree.c @@ -39,25 +39,20 @@ struct tree_node *tree_search(void *key, struct tree_node **rootp, void infix_walk(struct tree_node *t, void (*action)(void *arg, void *key), void *arg) { - if (t->left) { + if (t->left) infix_walk(t->left, action, arg); - } action(arg, t->key); - if (t->right) { + if (t->right) infix_walk(t->right, action, arg); - } } void tree_free(struct tree_node *t) { - if (!t) { + if (!t) return; - } - if (t->left) { + if (t->left) tree_free(t->left); - } - if (t->right) { + if (t->right) tree_free(t->right); - } reftable_free(t); } From patchwork Wed Jun 12 05:38:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13694446 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 7562338DF2 for ; Wed, 12 Jun 2024 05:51:08 +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=1718171469; cv=none; b=YbxttsOWuo96shIxWsYAFk93/XpTdI6Gg+L8d5AoBPM7WJWbFQsEAs1gkDuouTHvWbKGrsgHX7BN0nV+wRZyeci4/ZTHGg91fdcaB0zznQPT0Usw6/D1sjJJD9puFAO8pEAybM1OIcI1R3Sz3JNDIWadrsiXc4uJBMOjGP6NKQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718171469; c=relaxed/simple; bh=Pq6fvH6see6NZIBIFeB7IaN4Jg8NcBtFIkuTYeLePQc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=slUHHdh5/wWkiVYITC2YzAGciqWxgig43mh4siiiRPcSi6rs+zDbSe2UGXN99o75l+dTmd4i2y6Fs5E1wW+oVvyZfwViqD9v3zBe+h0/0rNWQgKzX+V3pnNRWu2V5uTqObOf2s6q7P63eAnM9VFmrYRifpdwrykBXb2o0jlagOk= 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=RPQeOvtt; 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="RPQeOvtt" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-705959a2dfbso473366b3a.1 for ; Tue, 11 Jun 2024 22:51:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718171467; x=1718776267; 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=cDFXxri1fS73+VNmjcNGWp15A/C0f4gErIv+95CXRHo=; b=RPQeOvttSLcktcBj5E+/BP+wFvqo3WKaV3ajw8nlooqacgubFG1XsbXvZ87A67IupH LbE2KUCjaFV+eXwsBaiQwuDtshoB7CkEkbgk5oEyv4o3IJ4RpQM+b7lgZz0N4zueOjlI lYbjmFHTZdVJWDjCht3LbEUbwPT2vq2TXPAiDYOiREUdm/U1Yygxnj9u5EzL0LkKVz52 gHseirPxjFdHSmgFnzR64yiXKUIC2VdKPZhVSdSzxOx6p2Nqnwd7e3t2APPNZRDmuHMi lhAUnATGUQ/mF0wXi8HQmFEPs/rzNjqcbSlwEsLjmxaq3MiRs500srdJVNc4RoKyz+xn w3RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718171467; x=1718776267; 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=cDFXxri1fS73+VNmjcNGWp15A/C0f4gErIv+95CXRHo=; b=qtVTTjiut7g3aRV3RYCby50jek+sFNWl9BdkYXbNBTeriK+4pu7Ih10kLaESd4OF8F KlQ7uQOWKo5d84GVOUBY1HXwyP06+CEe9HjzyzzztqrACJlKoYkUM5a66n4SBdDNDgRW ZHRZNrcAjVELNykXH9h0bUp2VkpCQ7alAChxd/nDknZaWFXphhTNTZQWpBMfF7BApuO6 6GZdR8WOsok/yM/30MyvjAgtM/sO2EUx9yVrfwvxJDJlmzbysnJnJU4YdaZZLIKxoLtS VA5QiEokE8o+4SjCD3mnRghplQXNfSbWeLx+SObLAeeNv0uNM+nkZk/h62NAV/4aAJoV lsXg== X-Gm-Message-State: AOJu0YzUzTnb9DkzVDTbO4ZQ3mhtl74wD0Ov2XU4fx/T0pP7Lm7mNwAt zRhEOkUVFiYfZog3tmSr/qR0kANXnTup+MBJeZw/vcHNy5LNEoJW3a7VauGq X-Google-Smtp-Source: AGHT+IEbap6G9oPBpA6v1fvLVKrEO3bNJ5eB4JI67E95Rhw60CMpxBhh+ymIcwiMj10Xn/f3yVC9Wg== X-Received: by 2002:a05:6a20:9190:b0:1b0:3910:3796 with SMTP id adf61e73a8af0-1b86d5acb9emr5769024637.31.1718171467449; Tue, 11 Jun 2024 22:51:07 -0700 (PDT) Received: from Ubuntu.. ([106.206.194.53]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-6f78b8336a7sm1934114a12.73.2024.06.11.22.51.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:51:06 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v2 2/5] t: move reftable/tree_test.c to the unit testing framework Date: Wed, 12 Jun 2024 11:08:11 +0530 Message-ID: <20240612055031.3607-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240612055031.3607-1-chandrapratap3519@gmail.com> References: <20240610131017.8321-1-chandrapratap3519@gmail.com> <20240612055031.3607-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 reftable/tree_test.c exercises the functions defined in reftable/tree.{c, h}. Migrate reftable/tree_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-tree.c | 32 ++++++++----------- 3 files changed, 15 insertions(+), 20 deletions(-) rename reftable/tree_test.c => t/unit-tests/t-reftable-tree.c (59%) diff --git a/Makefile b/Makefile index 2f5f16847a..d736b2f8bd 100644 --- a/Makefile +++ b/Makefile @@ -1336,6 +1336,7 @@ THIRD_PARTY_SOURCES += sha1dc/% UNIT_TEST_PROGRAMS += t-ctype UNIT_TEST_PROGRAMS += t-mem-pool UNIT_TEST_PROGRAMS += t-prio-queue +UNIT_TEST_PROGRAMS += t-reftable-tree UNIT_TEST_PROGRAMS += t-strbuf UNIT_TEST_PROGRAMS += t-strcmp-offset UNIT_TEST_PROGRAMS += t-strvec @@ -2681,7 +2682,6 @@ 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 -REFTABLE_TEST_OBJS += reftable/tree_test.o TEST_OBJS := $(patsubst %$X,%.o,$(TEST_PROGRAMS)) $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS)) diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index bae731669c..9475db2f76 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -8,7 +8,6 @@ int cmd__reftable(int argc, const char **argv) basics_test_main(argc, argv); record_test_main(argc, argv); block_test_main(argc, argv); - tree_test_main(argc, argv); pq_test_main(argc, argv); readwrite_test_main(argc, argv); merged_test_main(argc, argv); diff --git a/reftable/tree_test.c b/t/unit-tests/t-reftable-tree.c similarity index 59% rename from reftable/tree_test.c rename to t/unit-tests/t-reftable-tree.c index 6961a657ad..208e7b7874 100644 --- a/reftable/tree_test.c +++ b/t/unit-tests/t-reftable-tree.c @@ -6,11 +6,8 @@ license that can be found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd */ -#include "system.h" -#include "tree.h" - -#include "test_framework.h" -#include "reftable-tests.h" +#include "test-lib.h" +#include "reftable/tree.h" static int test_compare(const void *a, const void *b) { @@ -24,37 +21,36 @@ struct curry { static void check_increasing(void *arg, void *key) { struct curry *c = arg; - if (c->last) { - EXPECT(test_compare(c->last, key) < 0); - } + if (c->last) + check_int(test_compare(c->last, key), <, 0); c->last = key; } static void test_tree(void) { struct tree_node *root = NULL; + void *values[11] = { 0 }; + struct tree_node *nodes[11] = { 0 }; + size_t i = 1; + struct curry c = { 0 }; - void *values[11] = { NULL }; - struct tree_node *nodes[11] = { NULL }; - int i = 1; - struct curry c = { NULL }; do { nodes[i] = tree_search(values + i, &root, &test_compare, 1); i = (i * 7) % 11; } while (i != 1); for (i = 1; i < ARRAY_SIZE(nodes); i++) { - EXPECT(values + i == nodes[i]->key); - EXPECT(nodes[i] == - tree_search(values + i, &root, &test_compare, 0)); + check_pointer_eq(values + i, nodes[i]->key); + check_pointer_eq(nodes[i], tree_search(values + i, &root, &test_compare, 0)); } infix_walk(root, check_increasing, &c); tree_free(root); } -int tree_test_main(int argc, const char *argv[]) +int cmd_main(int argc, const char *argv[]) { - RUN_TEST(test_tree); - return 0; + TEST(test_tree(), "tree_search and infix_walk work"); + + return test_done(); } From patchwork Wed Jun 12 05:38:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13694447 Received: from mail-oo1-f54.google.com (mail-oo1-f54.google.com [209.85.161.54]) (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 466603716D for ; Wed, 12 Jun 2024 05:51:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718171473; cv=none; b=hUXOnWoIrGvhj3qaUgXBE7cIuR9Ll3Z1jDwCZKkPWr3Q/JpQGq/qBuUPA2DvI9JFpAMazbNU+OgMiPkZonHAWBEUgXCfw6UvhNuiCks12ioZoddjN7wd6mx3MqfXVTk0Ad5mkXth/CSOmbDiTKAr0qbRA3J2R8DCe6P29MxL6N0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718171473; c=relaxed/simple; bh=Q7pMSyQP80ggGaKhyXA8swmOExRd8oyrTSo+6kokmpI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A6xssVkXIJJiSiM/shVQb5X0dqKWZsH06VW9TtSRPrjtGAwaUabKMFYBrCNArW+IepmTkt6BH6AOAPnJRHvg8g9hTx8tLHo6fjBkNeMsFRkTXKW19jzOmUlF7TdIFUWGjLyByDg0gsJiOZLlBePmu0kdbN+nghDCB2hpsezdSio= 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=BVJAh1di; arc=none smtp.client-ip=209.85.161.54 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="BVJAh1di" Received: by mail-oo1-f54.google.com with SMTP id 006d021491bc7-5b9a5be6668so865076eaf.1 for ; Tue, 11 Jun 2024 22:51:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718171471; x=1718776271; 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=8r9XrWy8GhQ830TW4yLffFrj4/ysvD19t0QFptNnVMM=; b=BVJAh1diEbTUCKeS8O7yvZiXV59625Y73BpBswoimmvQMnrgiQ0X6w0BOn4r3fWpKr H4SGVofQY98/oib964Bm4P78sEOrmVhbQUL5PUiU47SKAYcklqEQ8s5FWr9qAF59GFwD F391O2ApS+efIQCw5BtkVGtfvjxkOaY/OdJE1yhD2lw497rkWuwnpyBcqCqpi8ZTUWHX NLx6XorkMIuW3t2SY5jLdRTq1konF+ZK9Rm5sIvr3o+pZX5/NnR+5YNBKS7aUD6LBPvH bnV2L7cS72ZdQ1J0NEo4vWUMV5ZJmWDkiMdlFL5c/o5y0xWTrGUqt2B0IuoBdQ0Dqx+H mpvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718171471; x=1718776271; 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=8r9XrWy8GhQ830TW4yLffFrj4/ysvD19t0QFptNnVMM=; b=bGi/GCSId3zHuGqGA6wv4xU2b2R9QAmmVjZNS8t4j2C/F+vb9xg15NSz/6RhqDBEmm UzxzOzhemlcZ66q8wEA5VYGkmWIxD+l+Wmpd8iLa2jKJ5JuJ5yijMzBRHS+eNQpd6oN6 K3e0xGB0aDWFjXwYilM5+nDFOBx6zu5WnH8fecByx7t6KyhOiVjUpFn5mh2+Chk5vpvT wBcKRk3t9fnWIU4meqRLaeC5SXZVyNB+Cp7fgC+WAXxH5jviyKp7D2ABqa6LHYjmFi5k RSu8TtxrW2bscPTsSnEP4d3o0kHECEqROzNwPXi1kSnfKGRIege0X3SivI+2kPo5qC1f zllQ== X-Gm-Message-State: AOJu0Yz8EegI90TJjjzkTP2Jrs39MQTscPVn5EQNvLCDG5vi/97wfT3B Su30TosRkWD4/x5mO8Agq+vuR+EBZTRX7iRuMZCOBjl3EwugpDpjbEU4rZH6 X-Google-Smtp-Source: AGHT+IF0hfnUy5y1Q22lYFpxmMYb9Ene7vUj6RQIOJ25L/yhA1R16oNNO/7o5PjAqgHjp0RaRjCJkw== X-Received: by 2002:a05:6358:7e96:b0:19f:19dd:9029 with SMTP id e5c5f4694b2df-19f69d31b53mr121261555d.9.1718171470664; Tue, 11 Jun 2024 22:51:10 -0700 (PDT) Received: from Ubuntu.. ([106.206.194.53]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-6f78b8336a7sm1934114a12.73.2024.06.11.22.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:51:10 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v2 3/5] t-reftable-tree: split test_tree() into two sub-test functions Date: Wed, 12 Jun 2024 11:08:12 +0530 Message-ID: <20240612055031.3607-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240612055031.3607-1-chandrapratap3519@gmail.com> References: <20240610131017.8321-1-chandrapratap3519@gmail.com> <20240612055031.3607-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, tests for both tree_search() and infix_walk() defined by reftable/tree.{c, h} are performed by a single test function, test_tree(). Split tree_test() into test_tree_search() and test_infix_walk() responsible for independently testing tree_search() and infix_walk() respectively. This improves the overall readability of the test file as well as simplifies debugging. Note that the last parameter in the tree_search() functiom is 'int insert' which when set, inserts the key if it is not found in the tree. Otherwise, the function returns NULL for such cases. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-tree.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/t/unit-tests/t-reftable-tree.c b/t/unit-tests/t-reftable-tree.c index 208e7b7874..cb721b377a 100644 --- a/t/unit-tests/t-reftable-tree.c +++ b/t/unit-tests/t-reftable-tree.c @@ -26,13 +26,12 @@ static void check_increasing(void *arg, void *key) c->last = key; } -static void test_tree(void) +static void test_tree_search(void) { struct tree_node *root = NULL; void *values[11] = { 0 }; struct tree_node *nodes[11] = { 0 }; size_t i = 1; - struct curry c = { 0 }; do { nodes[i] = tree_search(values + i, &root, &test_compare, 1); @@ -44,13 +43,29 @@ static void test_tree(void) check_pointer_eq(nodes[i], tree_search(values + i, &root, &test_compare, 0)); } - infix_walk(root, check_increasing, &c); + tree_free(root); +} + +static void test_infix_walk(void) +{ + struct tree_node *root = NULL; + void *values[11] = { 0 }; + struct curry c = { 0 }; + size_t i = 1; + + do { + tree_search(values + i, &root, &test_compare, 1); + i = (i * 7) % 11; + } while (i != 1); + + infix_walk(root, &check_increasing, &c); tree_free(root); } int cmd_main(int argc, const char *argv[]) { - TEST(test_tree(), "tree_search and infix_walk work"); + TEST(test_tree_search(), "tree_search works"); + TEST(test_infix_walk(), "infix_walk works"); return test_done(); } From patchwork Wed Jun 12 05:38:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13694448 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.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 ABC6C3716D for ; Wed, 12 Jun 2024 05:51:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718171477; cv=none; b=pppK5D9tSIuwNX5bTqGBCTggeTEVdbW7tKMgVUCJr23okedxoBlNtyS30Xybv//CZN5amH3Nu+KEHqvFf5rH7ceXQ9Q4CFh5pKKn1iLj4S0QMeu1DuPtDYvhMwfh2HSfVU1jL652mp7/Oxb5Z5ne8QfPdKnuvah0KoQmwS/KRFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718171477; c=relaxed/simple; bh=OCBQ9tjRvoQr7HXZ8VMV3IU6S6ATeB1pR3zF0tokTtA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XLo7qIqxkFfjPOJNCOLBlRCXE2+lRoY3tPOOdhLyD2hrzqR/QW9raIGlvPjhWBvvJKVAzed/iwhBinhK8qIcghT09iyTeAAO1Lf88eTa5GhWE4P26PLYSmuh2Ywp/oTNxhX+zzDPq/qLry7QJBuytLWz6c0mHVrqTRqQ5N1/aDc= 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=LHm5QnVb; arc=none smtp.client-ip=209.85.210.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="LHm5QnVb" Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-6f855b2499cso3440817a34.1 for ; Tue, 11 Jun 2024 22:51:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718171474; x=1718776274; 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=0KZcKIhlNgpm2MiNyCc2/Weo4ZRujP+9T59sCvV/69w=; b=LHm5QnVb2A12qWRgIhTHT8GJcGHoba4lk/thxZ9dM01N8txUZFwzifwLs6QCf0CyOZ ufR/h7LVxsmacEKEVh/5Vk2kuz5BaJVAsC9cxLC+t2a8+Cu6g35sOmfIbulHq7PRZqwT A8CHWADYU5S6ipSmeJ6InIw8xTrzCnBapUtpFEkTK94CwaJ8zTjwKgKhWkhoQVO0Yu8V MREA7My1Ho2yohTKUM4OhT8zUo0+IIEZbskpJg1E9Rew1JTwBoU500dQ/i7ecidYJOAg /QjBBPVqIIwKpjCJgYS29+xObh7PLGu7UybUwKzh93aOY8gaaYuAm0fztrut4GpZAIta oDWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718171474; x=1718776274; 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=0KZcKIhlNgpm2MiNyCc2/Weo4ZRujP+9T59sCvV/69w=; b=WSEuv+IgBj6zypULz7t5Tc2sxVCocP82pCmEoL9SdzlSZtd3CRZBAGfDFvGtOdGDp1 jNJMbbx0JgmCkC3a2p/g6h4nHA+dqSn/iXq94/LdtFXcm/2dB8QOtOLCSMShKfebE6LJ JdVdXU64fuJcwJfUGz7NKFlM1tj1dB26meXcqRspzVrWV6VzHtC8Z/ykNLRsWL8vEefa DXmTuPpzNGFf91LzMnlNS0fehnx0bOgfeA029DQ//dDCnNn4i+JRRZ58mQj4TGDrsQX8 YlpMPKplUjnwQVlSqE8tun1ife5f9fHFy0WBaHWdIQwVMUsebQ+cKAQs6jwIivPUn6nW 0OPg== X-Gm-Message-State: AOJu0YxzuV+UX+5jEieAiBQtxht5gsUKf6YnVq1pZmzweeI8wkAx1ffJ xgyS56OVE2G/moXgf+CJvSw8s6j/1uk3gBHQ/NOuCjx/Ih+StboI6Dy8ZshD X-Google-Smtp-Source: AGHT+IFoaevWxuFtexgeNDISneT50UOnRQ3iDoG3I8/Eb3QDT/UBmnDYHGhhwqbeuHG6WJkV6+DApQ== X-Received: by 2002:a05:6830:16d6:b0:6f9:8000:53e5 with SMTP id 46e09a7af769-6fa1c222cbfmr957233a34.23.1718171473872; Tue, 11 Jun 2024 22:51:13 -0700 (PDT) Received: from Ubuntu.. ([106.206.194.53]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-6f78b8336a7sm1934114a12.73.2024.06.11.22.51.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:51:13 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v2 4/5] t-reftable-tree: add test for non-existent key Date: Wed, 12 Jun 2024 11:08:13 +0530 Message-ID: <20240612055031.3607-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240612055031.3607-1-chandrapratap3519@gmail.com> References: <20240610131017.8321-1-chandrapratap3519@gmail.com> <20240612055031.3607-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 tree_search(), the case for non-existent key is not exercised. Improve this by adding a test-case for the same. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-tree.c | 1 + 1 file changed, 1 insertion(+) diff --git a/t/unit-tests/t-reftable-tree.c b/t/unit-tests/t-reftable-tree.c index cb721b377a..f1adab4458 100644 --- a/t/unit-tests/t-reftable-tree.c +++ b/t/unit-tests/t-reftable-tree.c @@ -43,6 +43,7 @@ static void test_tree_search(void) check_pointer_eq(nodes[i], tree_search(values + i, &root, &test_compare, 0)); } + check(!tree_search(values, &root, &test_compare, 0)); tree_free(root); } From patchwork Wed Jun 12 05:38:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13694449 Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08E363B78D for ; Wed, 12 Jun 2024 05:51:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718171479; cv=none; b=Yv+L1rcVC30PohiXG9jMFyT9OLD7RJVdRDBpvTq17zKAaDG/piGn429P9Dwq+uWY//yfGan8V+mlx7i4nl9HKalNGS4jGfK3jP3Lc8aEarILfg3NzjBWjjl9obluvzO4e+8Umu4HNuNN4untI1PLd3QgxKYpLQhsxTJpuja+bAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718171479; c=relaxed/simple; bh=YpoQo59ec7J0Yx+hXT/p9Vu/+Lghtv3YJbf7z7qoeSs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nUKlfq733mizaNKLP03HhI2uGYyYRktxd21CBoOnl0+nDV2/wLE7aKdxcDd6qxTsZBex++lhuKkLGrXHB8g15ahzAwMysoG9mDtkB/Pb1da0mGE9wc4mbJwgkxXCFvlWVU0UokvNSYDohbAIoXvNmcfAkBL7ydDNPxGysI4T7HU= 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=UNUe+U/B; arc=none smtp.client-ip=209.85.210.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UNUe+U/B" Received: by mail-ot1-f41.google.com with SMTP id 46e09a7af769-6f9c1902459so1649672a34.0 for ; Tue, 11 Jun 2024 22:51:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718171477; x=1718776277; 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=U+xlbCO+p4/KUvao3SeC3kNZobdUc6+q4rCdR8ptb/A=; b=UNUe+U/BQnAloDXYNzbZUtVKDtpohRSRA+lQhqymakIKqscbgsgD9gM/vTVxbCblSS 6G4T19qhP47cTt7FIpli4I5y+L3MrW/qMWGU0UlAcgUf6Vrw0CzQBSB2a0eBYdOBMehM UO+aHtIw+PtuoGWq68UyTmbOoiGqFiRYvWOsTeGWFzYIg/8zpdFV41RzeLwcwNjmWJvU ni8CS4T41eNrF9N1HIlOtIt43XoFLnTFVILMedxBrRD4ko30Ltv1w+/pKg1tenW7FHwF SkQbmyASfPEAhDBe8PjEAklnGSOspkxFFY6eHcY1cj9OzB/xgNwxeRY7pUD5AswIu8GD Utag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718171477; x=1718776277; 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=U+xlbCO+p4/KUvao3SeC3kNZobdUc6+q4rCdR8ptb/A=; b=fudc/ewvgznlkbFVK2E1hamgkAYLFDMORqlRhxAXC4yotvLMdqB7eVvzlfuB5h1hQQ OPQJxSJxTeuXGVBTZTDqWayJH85G0gs3Ho0SSZ9jsfvJmSejURwZfPMCwooOR+fdJ41m S0Xe/5+vLP60x/UtK2GTLc2VWM7heabQs1XNRcmW2eNZ6MUyC0C6GvHBKMHlFW6qFzYR tCFnDJAage5yvvNTTj+5SWmeJaeEdB96DIBWDKGV6eQd+b9YQqNnCkWbyHNWuo3uBh2g YqX1enGAzovUBCDOHfQrZvGP4Ha9xpWICclAgIZgZ3EekItbaFyPaRuOamzd4bPLRo4o 1O9Q== X-Gm-Message-State: AOJu0Yzjo/QX0YpOAOw9TaveGY4NPBmnV+FWzLUzCYD5srO8JSe4ONPa 7WnOxOLS+X/BAbuBym5hwOXlUwE+sxVUyO92tszEkVh+BFVvsioVG2YjQBNA X-Google-Smtp-Source: AGHT+IHUkQC7tw+e3NNNi6RL/QfTQvdnynEHx7A4kDeZFOIwl60h9iKV9Eq6gvF8Y7/bQsPWhERXDg== X-Received: by 2002:a9d:7592:0:b0:6f9:94f4:c670 with SMTP id 46e09a7af769-6fa1c23813dmr839335a34.28.1718171476846; Tue, 11 Jun 2024 22:51:16 -0700 (PDT) Received: from Ubuntu.. ([106.206.194.53]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-6f78b8336a7sm1934114a12.73.2024.06.11.22.51.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:51:16 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v2 5/5] t-reftable-tree: improve the test for infix_walk() Date: Wed, 12 Jun 2024 11:08:14 +0530 Message-ID: <20240612055031.3607-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240612055031.3607-1-chandrapratap3519@gmail.com> References: <20240610131017.8321-1-chandrapratap3519@gmail.com> <20240612055031.3607-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 infix_walk(), the following properties of an infix traversal of a tree remain untested: - every node of the tree must be visited - every node must be visited exactly only and only the property 'traversal in increasing order' is tested. Modify test_infix_walk() to check for all the properties above. This can be achieved by storing the nodes' keys linearly, in a nullified buffer, as we visit them and then checking the input keys against this buffer in increasing order. By checking that the element just after the last input key is 'NULL' in the output buffer, we ensure that every node is traversed exactly once. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-tree.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/t/unit-tests/t-reftable-tree.c b/t/unit-tests/t-reftable-tree.c index f1adab4458..917a64a7d1 100644 --- a/t/unit-tests/t-reftable-tree.c +++ b/t/unit-tests/t-reftable-tree.c @@ -15,15 +15,14 @@ static int test_compare(const void *a, const void *b) } struct curry { - void *last; + void **arr; + size_t i; }; -static void check_increasing(void *arg, void *key) +static void store(void *arg, void *key) { struct curry *c = arg; - if (c->last) - check_int(test_compare(c->last, key), <, 0); - c->last = key; + c->arr[c->i++] = key; } static void test_tree_search(void) @@ -51,6 +50,7 @@ static void test_infix_walk(void) { struct tree_node *root = NULL; void *values[11] = { 0 }; + void *out[20] = { 0 }; struct curry c = { 0 }; size_t i = 1; @@ -59,7 +59,11 @@ static void test_infix_walk(void) i = (i * 7) % 11; } while (i != 1); - infix_walk(root, &check_increasing, &c); + c.arr = (void **) &out; + infix_walk(root, &store, &c); + for (i = 1; i < ARRAY_SIZE(values); i++) + check_pointer_eq(values + i, out[i - 1]); + check(!out[i]); tree_free(root); }