From patchwork Mon Jun 10 13:01:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13691989 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13BDE823DC for ; Mon, 10 Jun 2024 13:11:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718025079; cv=none; b=Ha8lUoLKHsrM7zIt0NA0N1JC5KQP+S0AZl+LOcJtrrl1Kv88oTEOkrNAUn1iQRaV+58YxT3QgPqfB2aVI6XyF0s2C+PmgKfVi1ul5u7aLNz9nzYD798V6pU8BdnkeAv37Z/jw1JyP4Ogl064WOWrchGhbe0NVba6rknlncYwfHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718025079; c=relaxed/simple; bh=Vg8lr4/Bm+hHi8Pl4iOuphqxbznv+5JAh8YSrO08Rjc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QnF6CxhbVb+PrZSJOhUPPHd6MIr4DByPUPkQhR68JFU2O8auPVrXskA+kd3V9jn9eWU55Vh3pVtHPmd/+yenulMIabnhrCeq1iwYmGP7wMpJGr3ud+5pcaadWD5WE2RPb863QO8i+n6SPkOKAkxTbCP7rqx/Izs+evhKAcogbzc= 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=JTT5zCTZ; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JTT5zCTZ" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-70423e8e6c9so1513424b3a.0 for ; Mon, 10 Jun 2024 06:11:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718025076; x=1718629876; 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=JTT5zCTZ3lsXhnoDPxkpc4q0n/JKy4KWtYFzpwWhqKGqjxmtMSKeeIDl46DM66QX/o na1W4/JMxScdkmFPOgj9KbOCW+cYoG/AkExCcoenNNdW2Hziu+krTx3T3832MhHFvIJP uyrsP2LYCD60R6QBuWkEBFt8J2snVu9fViKwa0i00RrS2q0Y94q6IUO5gDdWTR5M1XYW x1XscimSFl0zQjk1/SAfZCBIuIomgnLpx01Urqo+Qjs3FDHZElbcqlgupgsIpbzpo8zl XhAAN+TDRfos4bFEjqroVVwuGNE/vSiP7mjehKWF9IkWhe5lgMjKGa82uuOFnCWgqEFO TxwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718025076; x=1718629876; 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=wGaYsEYuGvMe4Cv0BfRV0G0W/A4KXO2EX6vP3nvUwBgQIkAN4tSZhjNik9Nh9v6FbO tNNUQNmqBaH0Q2WoO+Eb9AtPfxLxxlqMYQJg5gTue9MJ3eNvyFB+D5wVNfmai1JecP7o /P2jVuggwbhoRlb0EnNllsE1hNIvlTwtGB7kaoZI5JuKbKL2FnQX6MqlCAXcRCUNKbcy u4bEBiQ5p9+mv/MF3LEI89HwyZQONc8Nvj1uyrb8vgUy3Dya8eKiTTdR52qpPjbC05F0 XpmLD2eL+/3w3EYhGVA/3JgzyOPTt32XYjEZw8lTYi8syBVbKHun9WP15Kv6wrcLVGbV gkeQ== X-Gm-Message-State: AOJu0Yw9xSUaEmHNOtlZCJWvSJNog9C+jA9C1/eNiABBl5VaTDsjy6Vw bdxshfJp8eO6m2wCja+11SeIptUf6PVG9KgDdw3QiCparLEiWAs99Z9qPdsz X-Google-Smtp-Source: AGHT+IF2tZpEoy9FZfHL3Kd4up3yr8lIPrBtVg5gRe3QELZYyV2d5rveHJUKZYyxctaS2qgLW7c75A== X-Received: by 2002:a05:6a00:1404:b0:704:6ea0:2bac with SMTP id d2e1a72fcca58-7046ea05af3mr3996003b3a.8.1718025075868; Mon, 10 Jun 2024 06:11:15 -0700 (PDT) Received: from Ubuntu.. ([106.206.194.184]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70599bcac14sm1378516b3a.1.2024.06.10.06.11.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 06:11:15 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 1/4] reftable: remove unnecessary curly braces in reftable/tree.c Date: Mon, 10 Jun 2024 18:31:28 +0530 Message-ID: <20240610131017.8321-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240610131017.8321-1-chandrapratap3519@gmail.com> References: <20240610131017.8321-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 Mon Jun 10 13:01:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13691990 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7ACC82499 for ; Mon, 10 Jun 2024 13:11:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718025081; cv=none; b=dlwJm8eoQMqvvY+IeJ+9gBFy16RDV624abkAY2PJQM0uy8aDLPwV3ZGTK8exKSX66tsC2scIKiJ3iR9kWXau1r78V+GkYJPd11eg9v/C5gfzYcTB5J+Y1ZlxpS7HmKphp2afGsL5iFqKyd+y/9EsfMQP1PDfxDj08nGmcxS06mU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718025081; c=relaxed/simple; bh=Pq6fvH6see6NZIBIFeB7IaN4Jg8NcBtFIkuTYeLePQc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EgrBTO2OyACL6PraDvsFjXdy9ttwbKWctu8CLr/keP9JhIYNnZ3z9yrIsyiCabgDnC1boCmIw/gHc6S9fNnQyY+UrKRvzz3rojmAgWt1R3NazNaD+2gtf+IxcOUIeuToNyp9NnYXHXL8AVrCZW4K6c1UjqWjU5POaZkQn913bxw= 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=HE8zZ6hr; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HE8zZ6hr" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-7042cb2abc8so1090691b3a.0 for ; Mon, 10 Jun 2024 06:11:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718025079; x=1718629879; 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=HE8zZ6hrZMtwxOBXCPm6Ub83gfOaK0RfrcOPeNnigfLqMltNGCWsBW6TAz3K+tResM xZAKF8IT7GKhVlKAqOWIWVk7SOuo5ujCQVyH3Oa7WqiwWkzyN1a+CHHs4Jqjr9KxcnRf o57rwp9KWiGmM1uutFDX6qS3wPxIUEmavBbJFphCCuxr4aUDMigpvZ2oGEDPoL0obvA4 jEDoZDTCurGlb083dqD5z/UUTzBEpdJdRU0f+9Nu0ZOKJ565GUk0HgmE/DSq6FdF2edZ sq9t3BQ9xI0BcbZZEbEhzoVx3bmg+5mWIzfsz5DC1BU7aYAyRaiiPPXnCY4e38pVyt3N QUvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718025079; x=1718629879; 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=pW6e3OVeHZqBmL87edxyevUqbfw5nJwLv0mTcIrplvyVaDmhEtwVw3vp3H5RnLntma MUy4y3payqyC70wKqYc+pKo5Kg89BoSZ27g6HA61vUhxkOz3ajppkOYbaJgKYjDHHdiX 0G7P4NnxHRsOug1ePW5+gR9qPk2qZXhoYxl3dy9Rf8fWWzyIQQr84swP6EX7ATBBB5RT 8y5QrAVGsQGs56Mnfazlz+oPGqTB/Y6w8IdRQ+5V8ibbMb8XtoaUN+eO1tP+6Zv6r/nO mTBKLMHZzg+xf1SfjKRAWv7lqVHT3P7k0wTzwD7nj9wayrhImrzCVG971dtzH6AUt7fI EA+Q== X-Gm-Message-State: AOJu0YwEwHYuVmuo5LSGNBhXhFw6r0P1tPDrDfoqlsXp3+9xKAv2z2mR YrIRLU9++fG8+wgZu3JSLIFweq9mPZqW6MERJumo8vMRIBHdFSnFIV3aejIW X-Google-Smtp-Source: AGHT+IFkBiZ1l6yM41AsCLKheWUixem0AsQQXq67CAgwV83RtW/Dqx8YoFsVUmd39rNMiOyASDS8tA== X-Received: by 2002:a05:6a00:8c8:b0:704:32dc:c4e4 with SMTP id d2e1a72fcca58-70432dcdefdmr4018736b3a.1.1718025078600; Mon, 10 Jun 2024 06:11:18 -0700 (PDT) Received: from Ubuntu.. ([106.206.194.184]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70599bcac14sm1378516b3a.1.2024.06.10.06.11.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 06:11:18 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 2/4] t: move reftable/tree_test.c to the unit testing framework Date: Mon, 10 Jun 2024 18:31:29 +0530 Message-ID: <20240610131017.8321-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240610131017.8321-1-chandrapratap3519@gmail.com> References: <20240610131017.8321-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 Mon Jun 10 13:01:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13691991 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 95B368286D for ; Mon, 10 Jun 2024 13:11:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718025083; cv=none; b=eQu/vy7WRi0o1E9Td9rcsUZwEyZMAbzxZjdbP9QIHD2X0736vviSTHgDAbr7vPxXCikYaKLn70yvMi/WfStoLymTF2Ofch6caDhRIW/3JMaip38gZyt+fJUXMlo07T8WoZyL1wh5qgQWLKI/cMH63Nr5SjferhrRYYCOJt7nnZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718025083; c=relaxed/simple; bh=xhZm38eTIVGbBmJjbcFwdU9ZnTINB83vGBzNZm8N60M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QINtJ4eDi7EENW1ieM85jFjacL4737lvDy2pni5BZgJWCzgG65mygpSp3qNacEbnNk26C7+2HUfD5JY8aSZvmZQKCjqSiYmEV8j9PFNirE7NwZfv3wncYfJcKiOXYRKwgVcEbItFFTMrZXe5Ze9YkfJfOwgUx7rpzWxKdFEo5oE= 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=W+XO1pxU; arc=none smtp.client-ip=209.85.210.171 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="W+XO1pxU" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-7041ed475acso1783432b3a.2 for ; Mon, 10 Jun 2024 06:11:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718025081; x=1718629881; 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=l83l6wi8W6kYRfLZQ1wsLN3/MI123r7fe3T4ILFe3vQ=; b=W+XO1pxUZBAl7T5kfS+93eR+Zwe8Sekwc85bZ3aVHMErMEU3Sow50/f1Sz1aWbbuSg gQK06YIrplh32Vc2ttBEm6Ac4lCi9ASjzrX8BdufbFawPRdCzljkGOPc7fBwWZX+mPG/ gzCuFXpWntsn4jBnqJUptB5S4WqHzBoo7tZFS0HamzAAzb8+BqTayIUxdeV4jpzvqdlF 8MjuHZmlqPcpU68PdDxY4UYC19Wax9U1+DOQBUwMp+C2Daa278ar84Ziz+F6vEHNKUeu KFgnpsSF7qycUf2NiCd76XYlQNDW1anaoLT1orByDCpROUZ40OG+3YYhRD9NmwFc2TZk /ytg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718025081; x=1718629881; 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=l83l6wi8W6kYRfLZQ1wsLN3/MI123r7fe3T4ILFe3vQ=; b=umY0Etge2l2i2j/288bAydf1rDkCT2GmN6eIkzuRf1/hs4hjHdgfbUEWrNi5UVmM9v CVjX6pgDxJK08WAVLl2vRk5TZd1C5YWxjcNJhW/Unt4BJ9gu9UsADYBuOJbwYp/w4k2e FnZ85ihjqSRIpEuatmkvTundhAM75yzJ/omPUz/wpPmda86Xe9XdhYot1bjcjtiTmGeM CNl85Rih6FQjd3aqvyWDVbYyF6QAQsqu4nNe1B4U5uDlmmB6MOTgsggDKc10cfIzNNfp sQSThnGEdirfrwnh6FmWYv9ZHmseHYeJYwKWcelp82hfjqPxOWGxOlPbpbTAcyYLVsCa OdXA== X-Gm-Message-State: AOJu0YxgN3V6Q0xA5aHi3Xa0PjodRhgWvPZNbKIaDEnHLskfUvZrcEvO hOEYeQl1c64W5ACANfs9aZBWNkRerQ6tQn0ZJtkX3ut+x4Fa7IkOiiZpl91d X-Google-Smtp-Source: AGHT+IGJHo0wR8s2p05zMh4YBIT4tVEFwsnsDcR/WXumoTFKm3/x8AGP+RGuMseAxMl7Egj1h8ychw== X-Received: by 2002:a05:6a00:218d:b0:705:9b04:70f with SMTP id d2e1a72fcca58-7059b04094bmr2023016b3a.30.1718025081381; Mon, 10 Jun 2024 06:11:21 -0700 (PDT) Received: from Ubuntu.. ([106.206.194.184]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70599bcac14sm1378516b3a.1.2024.06.10.06.11.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 06:11:20 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 3/4] t-reftable-tree: split test_tree() into two sub-test functions Date: Mon, 10 Jun 2024 18:31:30 +0530 Message-ID: <20240610131017.8321-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240610131017.8321-1-chandrapratap3519@gmail.com> References: <20240610131017.8321-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. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-tree.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/t/unit-tests/t-reftable-tree.c b/t/unit-tests/t-reftable-tree.c index 208e7b7874..78d5caafbe 100644 --- a/t/unit-tests/t-reftable-tree.c +++ b/t/unit-tests/t-reftable-tree.c @@ -26,7 +26,7 @@ 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 }; @@ -44,13 +44,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[13] = { 0 }; + struct curry c = { 0 }; + size_t i = 1; + + do { + tree_search(values + i, &root, &test_compare, 1); + i = (i * 5) % 13; + } 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 Mon Jun 10 13:01: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: 13691992 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 4646E82889 for ; Mon, 10 Jun 2024 13:11:25 +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=1718025086; cv=none; b=RZYYmKoJfpaMbnUTauSzqA007RLACe8fCxnc7gME/+uToRMQYshBWn82kKPQuxh3KRcJGs+h8FM/aldyJQ92DaRZokPKJKCrftR1M0ayo3CDV/k6LDBaOZkM10VpFqqtMa3Jc8VQxyHB7aU3JlqS/e3jpd6ogmXj20OUyTf4yd0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718025086; c=relaxed/simple; bh=11N7wvHkwccmHznyMGTlw97HGAQrJ/FhUgJDsx/czXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kh42fk90Gzl7i84TQonarEocB6BXtRfBQlh8RZQxeflll46cu3ZxoEDfOvGyvKX3c3hMoANrFuRthZenRiQkSnY4QrGt8/RB2zsde6f5XHQjHjPE0mmm6vsVwO/YFTihvx39eo5WHNUnRoLKnb3222KDX6AEk69VpppyEyjiZIo= 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=UoObRptJ; 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="UoObRptJ" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-70417a6c328so2140444b3a.1 for ; Mon, 10 Jun 2024 06:11:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718025084; x=1718629884; 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=LyCQWXZ5d4CiLY0kGIokt9eQRJcvdockpuVnB3UR3Lk=; b=UoObRptJTfX/HlE+Y/Q45VH7gpSD9V+HUi/jar0cUeLhRNDFKZ161dojvpPo2igdwp tVnlAX85FGMT5HoJxbk33cLNIALHq6xFjgLGazoG70byJRa6h8tP0MDYezMOUE3lO6S/ 3m1HVDjSVy6+ZUtAXkaSoDkqCso21JZ7K67357fHrPSwrSjBdn6uJaWxMa7uXKH8Di0+ KXCMpv4AoNAxqbx09udmbrJpLQlBoL8htCGlkA4DzNRkBfOjKQnbtuQy8oKUGDl5dVPv LK/bEFU5IxAQMrIOyGDzMTI1QhHzn1k4/k50LjcFmaJSuJH81lTTuZCgMCFGI3apvYY6 X3Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718025084; x=1718629884; 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=LyCQWXZ5d4CiLY0kGIokt9eQRJcvdockpuVnB3UR3Lk=; b=Mdn+priAiAEP2Wn65Elp+wpv4hJtXMUK2Ee+o5jcUXmFiJhTlATK20WoqDTlK8IDUl je9YUX0RgHyFQ+RgYHHAFL4dOZJTue//uBryhmK0WDWfpeYW7bIPWIKzF4w68bqTZQzI 6jw7QH6dlM3uiPhsYv0YXfTJRaZ0jHFshCnLr4pciNI50+6Y4dP0G6gct8k1wtkQJcq6 rmgQGukK+pqDFHrek9J5iIMD7fgdCa7W+j4vRJ0EG7DC2KY4AtFll1t3TAIaKHILQqcs 4xRy+FUkfOg+he7II7K67S7porofi/sHWwzUMF4J9OTN2uDuAI5JjpNMq56Yfvtmu6R/ tiVg== X-Gm-Message-State: AOJu0Ywp+gwielKSt3+NxIHH6l45IK6bIb0eJpPgi0A39LY6i2yA/441 QggwXc88TxLd46AhpiqpdjOVw6/Ot0Grq+7vkj0KdneDj/sXFsYCscpTEfv4 X-Google-Smtp-Source: AGHT+IEE6DqPyhRueYdIrhw4E0ibB0Qb8eGCOQBGBUhSHop+AhCbj3yqs4vFRzTGrFghjypsSlEdAA== X-Received: by 2002:a05:6a21:2716:b0:1af:cc75:3f79 with SMTP id adf61e73a8af0-1b2f9de087amr8718322637.55.1718025084219; Mon, 10 Jun 2024 06:11:24 -0700 (PDT) Received: from Ubuntu.. ([106.206.194.184]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-70599bcac14sm1378516b3a.1.2024.06.10.06.11.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 06:11:23 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH 4/4] t-reftable-tree: add test for non-existent key Date: Mon, 10 Jun 2024 18:31:31 +0530 Message-ID: <20240610131017.8321-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240610131017.8321-1-chandrapratap3519@gmail.com> References: <20240610131017.8321-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 78d5caafbe..b2fca0cb5e 100644 --- a/t/unit-tests/t-reftable-tree.c +++ b/t/unit-tests/t-reftable-tree.c @@ -44,6 +44,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); }