From patchwork Wed Jun 12 12:52:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13694931 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 A997217837E for ; Wed, 12 Jun 2024 13:02:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718197370; cv=none; b=N3UTrATqBkA4UzlMCW2VK3LIUwTDSQeRkIrKjB41Rm4kaMCsLG+3P0b2VGdE6ntQYUwtRZIMiTb9LBI7GeJgoFKDgGiAJN6LcN1MpJF3wSKboRJBAyr5yJSnddufKoLho5UKW8enWNEWjHN+QZ1H3f9jMukMJdw6aij8ptgeY6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718197370; c=relaxed/simple; bh=Vg8lr4/Bm+hHi8Pl4iOuphqxbznv+5JAh8YSrO08Rjc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ydr+yyCdl77+el01NL3HiL7Wc76mv7U0oaWQY7Tq/Qt7RAVcwAyLCsxb5h+hQz+pVLYgubynqDPF8JK5h30zp3JekX0v7XSbeq/AVZRGfld0rr7zSrqYawMayNADp6W0PVcyitwrJOy76dOfMVjQemNEO9xRdCMFzI7Wm5a8Kc0= 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=I/a9+BBn; arc=none smtp.client-ip=209.85.214.178 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="I/a9+BBn" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1f4a0050b9aso56969555ad.2 for ; Wed, 12 Jun 2024 06:02:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718197368; x=1718802168; 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=I/a9+BBnGrwkJRVUq5bRw8Pc9+kivRji/Ikvi+WeYXGpouvzqhK22gh0KUiqYhxchr 2KL/zghU75ik2nwxh2GxPnaHk0XTsM8A8iFp7ltQ93rJal2OMln3l/ca+41lOxATJxDw RJh2sROFnIA48ZXuwVViJbx4FVaANibG7DFCt9DdRdlRuOwnvckrB5MVOT2h0nKYXsEN a2t/OJT9liqx8VWF+SYgF0hHQviZJYx1EP+zhfILe30WNpJ2RH3tRMJs6S7HV8XcJtcw aFqdwngGqCi1Gt9kfbdsDSfeAR4NPdvS45/W88Fvsx91985HYBsmx42Cn9Y3KmAyHDls rAIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197368; x=1718802168; 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=iWleGhkt7HfJd3HRRNamXf3aZhXRPhyXxxAfuG5OY0gNDHx8uKf6uYqjWJrdo1TMSO R7e55CPF1dSX1RZ+UwdyOFa8R6QxB7Y/r+I/puRoo5VQlNpc5ZiUowy1qrL5VFBcxiBK 9oJVbmghTFkpAdXk9Wiic64H251xXvbu5QIdV0OHlz46B8k9KanVNvXtApOTbs42r8to vU2LGLSiHSzLOGHGdWU6h0z4h/tgsZJFPPXZe2tKCBxwCbaJ260XiYaNpoI+/eiJYC+t dWC7eHEFnlK1rYGKY6IoLYiztWLnNeMP/czTGX+LXSULGN6t5teRKuVnVMiwFawJ8hCW g97g== X-Gm-Message-State: AOJu0YwbNCy+7Yuza05XO7J+dChmbw52d3slmEVI6SKIx6A33JBFQGab 40g5/gXSurXAlgHJStAQ4D4OFpRw+P0y3e2J9Rb1z/Tx0fbi/tAkKROHgKhuGio= X-Google-Smtp-Source: AGHT+IHMMMjy2Us7AABHT8J+ZqNJqojT0Q0iE3d81UkFR1CudUiwfI3o53nid+2TzVgnjPGTaHKjsA== X-Received: by 2002:a17:902:e842:b0:1f7:1e7a:e16f with SMTP id d9443c01a7336-1f83b6ece0amr20597455ad.52.1718197367487; Wed, 12 Jun 2024 06:02:47 -0700 (PDT) Received: from Ubuntu.. ([106.206.196.39]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f6bd7fd25fsm123942325ad.280.2024.06.12.06.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:02:47 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 1/5] reftable: remove unnecessary curly braces in reftable/tree.c Date: Wed, 12 Jun 2024 18:22:59 +0530 Message-ID: <20240612130217.8877-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240612130217.8877-1-chandrapratap3519@gmail.com> References: <20240612055031.3607-1-chandrapratap3519@gmail.com> <20240612130217.8877-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 12:53:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13694932 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 A29FE17837E for ; Wed, 12 Jun 2024 13:02:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718197373; cv=none; b=pdjKBJBsgiJ0vXZbB1FRJ354k744tAbfJAgI54uoIuLSvO0OmiPPs+VtNSKj4MZYlqM4TaHgCOf5hzJmGJR9SwOIfSQypQhWhYYs/R3xxN2tLAwrZHn+AB+IeThqY75gYeQtTbXSjWDhX12WRXA+92titHrO4XymgWbgZT8DM9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718197373; c=relaxed/simple; bh=Pq6fvH6see6NZIBIFeB7IaN4Jg8NcBtFIkuTYeLePQc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rP2ZVrmwf/GOoght7iwgBHOu5OUZWPoWhD0Hqm5gN0i686gf7NanGHUEiasVU86rgWjtlNmm6qa4MrpDPU/SPHp809NA+FeAXSpoNR2qFK9SndwqlReO1NlbtPqBTMY/4r5Y1c1QX4tyERTW4FFn7UQQYHWjGdGGec6H6U+uO88= 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=J1qbUZ+q; arc=none smtp.client-ip=209.85.214.172 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="J1qbUZ+q" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1f717608231so23393525ad.2 for ; Wed, 12 Jun 2024 06:02:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718197370; x=1718802170; 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=J1qbUZ+q7Aa+dLa04RxeZ5hbiru31F33q29+lIbAX2/9s1I+I/zYd3P4CBMV9GPzKS lQxuRje27lKE/B8IW22ZrsHzO1QrGQqaV16yRiBkGfGADHqMPpYS6bQt4XrLaQMQp0oL dGIIg3Pxct3UMonZfG65tUwJk3b97CU4v7uDtMqokK+r1gSBM4suIGcdCUi/9drEDzFd IObJnf/YOX+DD39mlQD+V5n1S5N8G/nw9a0Qvd8vJ2QGcT303MNBwVR511DlJax8wWj2 QAFwQmdwwNiDqunZ4cZ2Za4XrmbW8Zy2uKHsR4rpj5DHvd1+uvZrDH4pniLEOWwAjGsI Py6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197370; x=1718802170; 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=AlezdwAo5mGN9ehYFgSu5Tk+UN4xNf3tkEgHzCoDB6Hi+WFQimKMAVBV84QsLhdJfN pdJ1IDbbP9l2WLO6GZ/vHywQtJ1+9bvgjJjYT01H+k+4CDg8vg7w+O0gnNTPJF3/2c1W I37apW0780VmcYhRwUs8wIAMv/Emm30Fi6iG2doSxZ4Fio7dqej/Zyq0g44Tbv7UHRc3 dKfOV20AWKS2+pWyQqp/ugQzbbWoeQRuGwi8ElaDlNyYcSSiltY8fPBZvqswtRx0ZR/x jOp0fgTULfuNlhkkqti97eSl7i2omrKZkwzuFqEiBPKMuC22EvIx5weOc+DLljrmOcXG OxXA== X-Gm-Message-State: AOJu0YwOWWJYyIBRahTYAquRUljgKZzyh8GpYdL+U6gy59VJu+Q6k7a8 cEROwSMjwJPl1DoaxsrF86F/dINkPicYCJNFMg6n3NCA37vp4eolw6pCoTKdDp4= X-Google-Smtp-Source: AGHT+IHIvOaY8t0+IZ5vf3pSEE2Wi8GmclRn6a1RHbavMEw0Qf01BkrlMwYRx3WnYT4JQRMTRotQdg== X-Received: by 2002:a17:902:ed15:b0:1f8:393e:8b88 with SMTP id d9443c01a7336-1f83b74fb9fmr19456625ad.67.1718197370326; Wed, 12 Jun 2024 06:02:50 -0700 (PDT) Received: from Ubuntu.. ([106.206.196.39]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f6bd7fd25fsm123942325ad.280.2024.06.12.06.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:02:49 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 2/5] t: move reftable/tree_test.c to the unit testing framework Date: Wed, 12 Jun 2024 18:23:00 +0530 Message-ID: <20240612130217.8877-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240612130217.8877-1-chandrapratap3519@gmail.com> References: <20240612055031.3607-1-chandrapratap3519@gmail.com> <20240612130217.8877-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 12:53:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13694933 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 6428017A938 for ; Wed, 12 Jun 2024 13:02:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718197375; cv=none; b=thNi4YWM5atIYLHWYpUMllOYcaWknpGmG1IxLmJgvzPeSf57ODCHnUNZJZ4wJj7Gq6CZOXNlbEaVU3CamYFiG2PJ5Vfgm8f5jeQ/IWDf5EL+cSfgWaJqKXt8vg34hLgKJlUmjovA1ERHQ7M8b/QDGtoBsZCXCQjdDabgFLG/R/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718197375; c=relaxed/simple; bh=Q7pMSyQP80ggGaKhyXA8swmOExRd8oyrTSo+6kokmpI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eijjrGOaLI9Pop0UxKtsVT7au57UoR5NYYOk1bvZZZ6Y/3iNj9rYDzZ4Ke+kwXL1sjsYyatThl7u3C/k0tZb3hyo6N6StJj+5mVAMSOudH8kXA3K02T36VSMeT2qa3uWkvV8CdM0QOibrvM9OJgXQ49NoDRvIUEAWJLUmLbuFpw= 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=A3Jgfy7L; arc=none smtp.client-ip=209.85.214.181 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="A3Jgfy7L" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1f6fd08e0f2so30037095ad.3 for ; Wed, 12 Jun 2024 06:02:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718197373; x=1718802173; 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=A3Jgfy7LQKH4Jgx6dB+t1iadpZX2PoYhvqp6kzHd+8oCwfUUn/5mFOrcULXH8SfV5b E0MWOnEYQAE8bv2ANZLnL+wGg4+6lxj6RxZydHnP7BXmXqZ9Q4Ne6AGQKuNEGQjMzjgy 3sUlQpvui6+bVNIsnDLiZcAzEfktsJtIGV6lQUInsTGymTz3NgAM8qi3lEt9Tt49igNE JIvg1WGQ81ujzKkv4E9kw+UM2SEvjHiwgHgBcjqln5YyTDIBYTRmLJORdP1pxg+k9Rek 6dXMMWRcg5olHUJ8KSKO5jvib6G+qDpPKXIkQSvCpCDkqXDPONIMbqoT+yKloWV5RHx+ Alww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197373; x=1718802173; 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=DtH4K1BLuZ8Ugi2/EJFBCaiaQIzQwLOx10sdgGYU8G8at2GuY3jgEARGfaCnyJvLzs 6ZkAvwirQJMunwM+NxkCkUYqQFt0ealytFv0OCrBgrmkreVzil2KkVYefuaR39O0NpVC vcChDSrm2uhH/RQz683pncpsOCCCtfWJ8i4xwMSxCLHbX5GyzlM2G9Re8zaSuvJz2sag 8kOiLovx+9sHcQNcAGBuUokPWgkWw45GbEbCnpqUZPD6zqJbXE5zVOpV+LpSHRsQgsJH 1qv7Py0ArJO1HnyW+32rNAov+rx8RmAOSWfp7VUwIfQhpXrQXKWneFZIwObMP7eqmRGg jGeg== X-Gm-Message-State: AOJu0Yy4U4K0MiMZVYSQSH13eEsE/+f95tul3SqgvfjCgl3QQBd1RW4m eeWJH3OGFI02Zcs+uAiJOn2+89zbtD33SVE3EdZPSrfTaoP8GNe+JCww3LWoBmw= X-Google-Smtp-Source: AGHT+IE215AAzYWca3Pn0CWLNhix2AZ5VNmS6KT0ng0/QZEkEuVZtG4D+nPCbWwTsCNeRojtGxeLuw== X-Received: by 2002:a17:902:e844:b0:1f6:f9aa:e186 with SMTP id d9443c01a7336-1f83b716bafmr19777615ad.57.1718197373189; Wed, 12 Jun 2024 06:02:53 -0700 (PDT) Received: from Ubuntu.. ([106.206.196.39]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f6bd7fd25fsm123942325ad.280.2024.06.12.06.02.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:02:52 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 3/5] t-reftable-tree: split test_tree() into two sub-test functions Date: Wed, 12 Jun 2024 18:23:01 +0530 Message-ID: <20240612130217.8877-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240612130217.8877-1-chandrapratap3519@gmail.com> References: <20240612055031.3607-1-chandrapratap3519@gmail.com> <20240612130217.8877-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 12:53:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13694934 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.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 161EC17B4F9 for ; Wed, 12 Jun 2024 13:02:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718197378; cv=none; b=LYI6lazNPPVrZ3nI5de4AxlV228paEvK5u/LQH7IOWwVCmh7cQBu39H/HEKf+VmA23aeks48yZUaHQTWeN9dPNBqvK3G1bJpUL+cnLvHyG3/JUqMNy2f4kAXAwdpxt7bVXA7mtFJaaJ9kDZVbT+YODnfp69FjWr1i2EKA9c8mvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718197378; c=relaxed/simple; bh=OCBQ9tjRvoQr7HXZ8VMV3IU6S6ATeB1pR3zF0tokTtA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PwSKyHxvL8dHmQD1zrtJ4QIb5wB54tLZrJcJTgn0LJpkfoKVozjiFkrldWZsohZb+1/2w+QqvbiYRcL5eUI9yoFxVeEYjdAkVzIfv/wcX1Wl5mhB+BeiO9aVAdhpDi1/pLbqYDxUnRJaNzNHXPPxusF3S3PkqBUJBPYX9CqjVuE= 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=CTSPTRwu; arc=none smtp.client-ip=209.85.214.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="CTSPTRwu" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1f44b45d6abso54219635ad.0 for ; Wed, 12 Jun 2024 06:02:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718197376; x=1718802176; 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=CTSPTRwuSTgSN/eb4K7ydBuj5RII2G2rApDdsI1FbELTtRnfWTkpGN2pW+9PsJC5Ek xYPgnVuBNOAHQIXAGT66HpfkObhWNBPFwwzawL/zzngfB5d1tnbWzmLaGjFlRqj5VsIn xGfYPrBlKvp4tDOmV4sF0El37ZBeBSn+WPpkCEZUSJAHzega2O/BHc5ISDPiXn1O4XMY 0WE1pAKyBhqG6qH0KSi4Ff/hwWSjUbJ7VYbsBP2EKw/PzpkKq2Hf+Z8hlbdjTxnMZdKm xnkVX223sNLHGzbNFCvhrMxVRD36F6xQOukxpHaeTXnVPxiSk2UL1zKjJd3KHJHmtY6S rAVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197376; x=1718802176; 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=A8KY/0e7npPtMevKTzJh0Ni/7MeX3Xg9id1+x/5C5VgfH5z4v2pc+QewMjejVIXSHI i3is4B3DZXQhNejrt0kEmblpayguwn8AxRq6lvCpcBHM1X2VN86Url6/ttLzIIYzmU2x VdQPMWE7tNxxXG3pNoOBwLRLd1JZbjwZQ7s/y1pddFcRC8CcgqGVgRwR4cQsv/acpMHK AbL3glsJP1JdfEftsPFI8+3x2Q+oygzPxZn15jGmcKcAr6rTlvYIIH6sokbU2gThyqRC HQYcxER35o44fnQvGz0VR/vEOE8GSxDnSK9ABG59Tr2z2DtGglGFw+huVXZYrR42T2rT nmTQ== X-Gm-Message-State: AOJu0Ywb3NqpApoj7ePi0HoHoS6Qc6f+BWlH7zHPyG/G9ZlF24MoZ8E4 aG65muL2KbqS+/3m2KzQK0AIc4l9zrL3BG19TUE0Tqqq2QmTZxjx23iqYtGLoPY= X-Google-Smtp-Source: AGHT+IFxeLLVu1L4512kpWhlZ8VIyi2BntfPllOUi1eB+OrZ4Lj3g75fI0ulYCgGQvY1VfcqYnvB8A== X-Received: by 2002:a17:902:eb82:b0:1f6:f04e:56d0 with SMTP id d9443c01a7336-1f83b7a3267mr16290085ad.48.1718197375993; Wed, 12 Jun 2024 06:02:55 -0700 (PDT) Received: from Ubuntu.. ([106.206.196.39]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f6bd7fd25fsm123942325ad.280.2024.06.12.06.02.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:02:55 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 4/5] t-reftable-tree: add test for non-existent key Date: Wed, 12 Jun 2024 18:23:02 +0530 Message-ID: <20240612130217.8877-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240612130217.8877-1-chandrapratap3519@gmail.com> References: <20240612055031.3607-1-chandrapratap3519@gmail.com> <20240612130217.8877-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 12:53:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13694935 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.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 F33B117B4F9 for ; Wed, 12 Jun 2024 13:02:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718197381; cv=none; b=kapouqszo1lBcmGDi8M+Rh4mnLnhrzebkAM4RVPxcVrA3rfOuzhYxdy7jMIImrthOqJ9ZSwu6/8RkfuUwdrAKDG36GVem0ZUPuNPePfFmxmKI47h5gTWFF79RZz3roOJnjRcYT7ga41snMZKYR7nWYg7+Ttepob5VSbMQcN4TMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718197381; c=relaxed/simple; bh=yX2T3elDEVRqBCMX8TyAPaCGbctUnnI/YTPaZ895czs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fMeRPZnOPmJS3Mm1BqDrO4RF+t1j03Vp3e98CppuzLq+5uTAbVPY7wA84rEibiDWxTXhIQ7xhIa6JoG2y0ZBQ0k24k+0gHDNGBMfOO68DEG4WAZs1QlIxeb1yZAgCC+cb19Io/KokGmHfXvM+QsFp8B4BhmRdkhuB5hVNJ+l8Gs= 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=OgYNxiMo; arc=none smtp.client-ip=209.85.214.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="OgYNxiMo" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1f7028196f2so28225305ad.2 for ; Wed, 12 Jun 2024 06:02:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718197379; x=1718802179; 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=yu1WY0FKnfrUCF7ffjbGaaeh3Ox0MGFf9/paH5Qp8yY=; b=OgYNxiMonleQbjMFj0PP1PZbKvPZ6WFxXwv7O3z6FDV0l7PuVf3o5hIvWN9a8xEx4M 6mNhB8vrJb6Sbeu7U2VMS/kx/lqwCplFRq6bKK4UMPxMHzN+FX8iax9oHecP6CiDLdgo PK2M2Q+ucqxKkv+dTrEVHGUgrdmQla81Tb5GtjPvAtV0uPpbpaiOzI+ogtrmZU8XxOrY xRoDDsrs4XXoSG7NOYq7M21dXrvUxr6uwG8m87B/wWRHc+dAYTHTTIgkjcM2uqvxojsN uuDaRec6d+HPGGpcet4Df+kJT0Nh2e76goXVCHTgoHsSuP7w5p36cGjkmmgikD06gXw8 tpiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197379; x=1718802179; 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=yu1WY0FKnfrUCF7ffjbGaaeh3Ox0MGFf9/paH5Qp8yY=; b=NJpgNSJNQyvDaTE+omrygqz5TRhwcTALtjW9manQr+5Kkd4Pq1fH4EJQPTPE5chtl5 A3t+pUCfcruP1+tEFhS/rU30UfkFZH9hvg6Bjyf1KRAatPgx4p+WoNtj7RHUdvjKusqW RFkcttiHRJwP0mn/pW9a+MHrDR28qCdl/NtnlXGBL2bnP0NhUachHBfFFTb5EIT3h3Qz t4vg6ekRcM7SofqiJg9Fuffjc/IsMf9aU7fHtaMCS+q7tSFf5Dcq7VFth8d69jTksUTc MZvCmUx5l/0IkwERIcyIKtNiO3JDiyzZE2PZmqrOzxDlcp1Y0xxKQYvavvsnxj9mRhEE pXlQ== X-Gm-Message-State: AOJu0YzumE97lMamaq2fDFm/CgbVs/JdpGcJhc51Q3JElkDCuBxl3Z1h 91fcGYNHF2715qUU1mZ+lZVlWAQGDxsMcvtA8uAZXKZFwK/ESewjUgZjwrz2tJU= X-Google-Smtp-Source: AGHT+IE29qH/uLuUtOnfcN0SJrFpWcqgkdqJq34vBIczCDfX1/6nRDUutj8tW5NAxvPyvDS75Adw9g== X-Received: by 2002:a17:902:d512:b0:1f8:3c47:9d9d with SMTP id d9443c01a7336-1f83c47b2f7mr17290115ad.38.1718197378851; Wed, 12 Jun 2024 06:02:58 -0700 (PDT) Received: from Ubuntu.. ([106.206.196.39]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1f6bd7fd25fsm123942325ad.280.2024.06.12.06.02.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:02:58 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [PATCH v3 5/5] t-reftable-tree: improve the test for infix_walk() Date: Wed, 12 Jun 2024 18:23:03 +0530 Message-ID: <20240612130217.8877-6-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.2.404.g9eaef5822c In-Reply-To: <20240612130217.8877-1-chandrapratap3519@gmail.com> References: <20240612055031.3607-1-chandrapratap3519@gmail.com> <20240612130217.8877-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 once In fact, 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 | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/t/unit-tests/t-reftable-tree.c b/t/unit-tests/t-reftable-tree.c index f1adab4458..79c6bfd49a 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 len; }; -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->len++] = key; } static void test_tree_search(void) @@ -51,15 +50,24 @@ static void test_infix_walk(void) { struct tree_node *root = NULL; void *values[11] = { 0 }; - struct curry c = { 0 }; + void *out[11] = { 0 }; + struct curry c = { + .arr = (void **) &out, + }; size_t i = 1; + size_t count = 0; do { tree_search(values + i, &root, &test_compare, 1); i = (i * 7) % 11; + count++; } while (i != 1); - infix_walk(root, &check_increasing, &c); + infix_walk(root, &store, &c); + for (i = 1; i < ARRAY_SIZE(values); i++) + check_pointer_eq(values + i, out[i - 1]); + check(!out[i - 1]); + check_int(c.len, ==, count); tree_free(root); }