From patchwork Thu Jan 16 16:15:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seyi Kuforiji X-Patchwork-Id: 13941907 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 689CD8635B for ; Thu, 16 Jan 2025 16:16:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737044178; cv=none; b=e2z9LsB+lQVG4efteRPdv7UxvhcMqXN/qnVtVdCLfqYOxaPtN1u0sqCIH2CaggPXzAN6yZwX68ngy+Aus/A6yozQNT4oYS4O36WZguqvp2Q83uWdWPC8yx9PqekWND7S73OikfWoaw/TGqHetqL5UGdzbc92GbK/BOFEudtYM84= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737044178; c=relaxed/simple; bh=AY/A6JcW4j5PNTEUvkx8ZwmTTQCtgxAZVI0tMd8z6Dk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PzXfJUfabMtJReND2TwHNxy2hu3EjEgckVtkXEBRxQF3vWLyePKCD2tNiIUaC6dapz4izsqWRmW7OABKeNU5CMTcsa9b+qvcweFNyt3LgN77CW4JsGlXj3clp0l00jkl5ecwMc+idGZafeg9zHtlmhLDSvIdj5jKiC+VYFmlM1Q= 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=DJdKu52N; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DJdKu52N" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-436345cc17bso7464605e9.0 for ; Thu, 16 Jan 2025 08:16:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737044174; x=1737648974; 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=yR0QMyZhvkOz9hBR6NZ/o6Ku/vPQYlB258CFhflv5Hk=; b=DJdKu52NsQ3GrzwFlZTTINMocidfKC4/2U4rmgyZp6vEc5GYr88YeofCRc1cBfjlJm /0COM9IIPA7ov6nUlgEsSTzdAYjOxs1DhTbJQfRdPtYVairnA+wjxyU7YVCjQ3lDE/gH 3VLowoS4sFsSX0T2HbzkAKJ5rxGg8ntBaMN7l0GkJ0kVMO2eZJ/aQCK0HxalgA6e9nq1 Ccjyvq2EyJcSyV/WCHKks6u64pGa+8dVNjcMGkbMeygMH6bJ4070xTTSC1b2V0rgKHBV UpLefVkQlvxBbXRLbyKbScYXGkKvDIlRbnnv5IiBpz+dkuGnzCyYIpCIY+XjJnPw1lSx g2MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737044174; x=1737648974; 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=yR0QMyZhvkOz9hBR6NZ/o6Ku/vPQYlB258CFhflv5Hk=; b=IEDkzxeUZV1Z5K4+/mA6+f3kaGhkrnYlCpTPjWPhjqokw29EOU3UOO03z8IJ3V2Kre pe7UPwP/cx0hV7SAnttajQakiTxqBEASZPcP+kBhyaDH86AnbEqGwYIv1zQw/ary9/3k 92kgQKRkMYPxh3+19MxmRUcMeY6Gb99VXacP7dOMC0NT91XYamvR4/vpP/MN3UOzSobF eo1maCuOt65qBvCd9jnqmt5aOEWdzrocbh82kt1UOzEWndmjVywqi2TtqNvkZYPbzthl qn2TtTHrmlod7rFMh7iZVubAeDE1ZMWkHnNNt+fUpPeWwNSo6d7zg3RLHU9RivP5mnV4 4G1Q== X-Gm-Message-State: AOJu0Yy+vQ43ywNAB4zHcsbw2Bq44+LbecN1l5d7MgLmAF7Y4CZRfS1o 0p6GNkGjGtFNYKLpFni0DYx1m55kHYne/E0X1sm6yfil30lbibuWl1CBOLm3ZveRSA== X-Gm-Gg: ASbGncvdGYaRTdu1RLcFk/24p/oXaT27VODRVUQ/KfXB+v6ZPqDyORogUmhWTXPV84K xDudPiFnWUK8jtNOLS0ZJLxfJTFaodiJfePYJciftqVxLVRAMZUZbaQfFLyns6wYGEUWOVPW7/V JGA23K6ZQE+kljpX1OL2Td3fW+FbdyyaYVXKGCWS0dugAReTRsIzL9hIVFEvw7RMLo+ojNOHjI2 YST8asOKViDNkL3ODovMCJ1KJsoNTQIwXrpGXIG1ZZ0XLOYRH2SWWT/avnnBMkK0imUrA== X-Google-Smtp-Source: AGHT+IEZihNnSGYdsQOrAAeJ2BR0nk/HG7TIhJRiPawCou4eBbYqT8Lmb5dSVXdWjKRzk3A3AsrDsg== X-Received: by 2002:a05:600c:3514:b0:434:a367:2bd9 with SMTP id 5b1f17b1804b1-436e26a607fmr352858715e9.14.1737044172798; Thu, 16 Jan 2025 08:16:12 -0800 (PST) Received: from localhost.localdomain ([154.118.34.84]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-437c752935csm63177025e9.26.2025.01.16.08.16.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 08:16:12 -0800 (PST) From: Seyi Kuforiji To: git@vger.kernel.org Cc: ps@pks.im, phillip.wood@dunelm.org.uk, Seyi Kuforiji Subject: [PATCH v2 1/4] t/unit-tests: handle dashes in test suite filenames Date: Thu, 16 Jan 2025 17:15:56 +0100 Message-ID: <20250116161559.91038-2-kuforiji98@gmail.com> X-Mailer: git-send-email 2.47.0.86.g15030f9556 In-Reply-To: <20250116161559.91038-1-kuforiji98@gmail.com> References: <20250116104911.77405-1-kuforiji98@gmail.com> <20250116161559.91038-1-kuforiji98@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The script is designed to extract function signatures that match a specific pattern derived from the unit test file's name. `generate-clar-decls.sh` does not pick up dashes in filenames, which prevents the scripts from being run. Adapt script to translate dashes (`-`) in test suite filenames to underscores (`_`) to correctly extract the function signatures and run the corresponding tests. This will be used by subsequent commits which follows the same construct. Mentored-by: Patrick Steinhardt Signed-off-by: Seyi Kuforiji --- t/unit-tests/generate-clar-decls.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/t/unit-tests/generate-clar-decls.sh b/t/unit-tests/generate-clar-decls.sh index 3b315c64b3..abf6a2ea2a 100755 --- a/t/unit-tests/generate-clar-decls.sh +++ b/t/unit-tests/generate-clar-decls.sh @@ -14,6 +14,7 @@ do suite_name=$(basename "$suite") suite_name=${suite_name%.c} suite_name=${suite_name#u-} + suite_name=$(echo "$suite_name" | tr '-' '_') sed -ne "s/^\(void test_${suite_name}__[a-zA-Z_0-9][a-zA-Z_0-9]*(void)\)$/extern \1;/p" "$suite" || exit 1 done >"$OUTPUT" From patchwork Thu Jan 16 16:15:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seyi Kuforiji X-Patchwork-Id: 13941908 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 3B60E132117 for ; Thu, 16 Jan 2025 16:16:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737044185; cv=none; b=KCpUjCyCihpsW6eTVg6JWZzj8moSQXnmkGXNuzZzGlTUWOKH9Dr0lGtNEYfYHZj2Zbqq3n2OrXGyXLgHbvpM5N6m4KhNpYD/NJytCLaZVcA5UcCmw0BKJbMMzLj53S4q/PU+XdxkFCPKsas3/RdGN8DkVfY/KBIlvxdYLem7LUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737044185; c=relaxed/simple; bh=6K/e8WYJqsLYizO+fJi/1H/TJJqTyblk3zV47tvHNKw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PbrSDg04T+9sLIYVJOoZnxfe4MKaqBm4mZ5HemUVlVZgukdXHc50SzsuiQ2TQv+bJ7UFWnnUA/v87opxoVUut3RDASY1dhhute0GAm+9Iv25LFTkaS7gy4NxUi63NQNp97UiOG9IrZYdI1ZN2thzgsD8/Hq4G/X4/07+hO4mCek= 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=atG40fLU; arc=none smtp.client-ip=209.85.128.48 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="atG40fLU" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-43634b570c1so7602505e9.0 for ; Thu, 16 Jan 2025 08:16:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737044181; x=1737648981; 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=rdMNfYg/Nq9UYuGTGNO4U1NkxgEnTvWULcXRtGl+3jY=; b=atG40fLUISYqxSh7kYjLlrIUlWygnxS2zaTu1wvOrAyNsLrX71n+S8aBOgxRexbfed SYCQr+YNRgBbsNMFXRxdzwIeEdG0OMkbGBRXNNEKMqzjui65efyx5RIK7GJT4imvYgBE umnpLcN630Jetfv8zjdwajCcDSb40W2mVhZdak/vmfLXT575HBe+fpxRaTkXoafzSO3w CJvGiqNzvoUO72xG2jU/s46Mi8ZiEoxGSUo0OKybLvr1N30i5y2C8P6O4H2IaJaMyRk3 Ckfit8MZPpRD8wGN2CgPCAM6XLblOt0MM7KdWExFvnJNq3M5HM3BM0R62y2e1VrWBRJN c/mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737044181; x=1737648981; 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=rdMNfYg/Nq9UYuGTGNO4U1NkxgEnTvWULcXRtGl+3jY=; b=JV+Ppq4LsuyFOc1/eyXAAYKHH6N5Es9iwJsBSYsut3kUUHoMdtpFp7xRf0jDwQ+UdD JDsCo7/8+xAMqPBfKaQXhCDlfjtdsIMHoeaV0ZvTxXVop/r8h4plICUqjjj1tEl6JJoO d1uFyph+sWcvqokcZm7ANFtHDzTkGa19xR5PcWC0RxR5CrCJ0HaIjqvV3MW6yR9IxKph q6bXJdU/EDZGjnh8wKG9eU2vvK/SuLBdqgAVfK7aVT/lQ3jgOOilv0M3aTt6q/cg8oSB AVYLE78F0tTu94Hg4rs5hSHZD5gE6VX6xyBkNxCsr3TBuZTHYzhZ8rifnS5OhBqmjl3P m/9w== X-Gm-Message-State: AOJu0YxTnaK914TvEZ1goVHbfJM+sCqu9oLqza2FLY0+I5lMzQAAi6xU Qj3Bm+Gs5LP1BxqrprZzVyvj9MMzJMhAAYNcL3/zUFx6R23fO4F34mmhNwEUqbh2zA== X-Gm-Gg: ASbGncs0HWDjxK2dqLgQepy5xO2pq6kh35yq2mS0Pjtrz6r+TrzOkXRoeNHKo9q6AiZ VYKGrjyO1EgWTQ+0GYbPmWBRSK+soCKp3Ge6pgI54p2ULMMz76Dncwbdj8pCShuC9kbOP5potCU UdoARnY4i8scCF+VZUMTwOoS5FEhrg10HwtIP/ZpxawZoZ7d6HIaBWV90Hjzt9O448uYlA0wp31 qxKnNxgbvxlglovwK0y+UWf9z449PMcwMM/+47degjgwog+iKux+ZorRxCl/FGrT9syVg== X-Google-Smtp-Source: AGHT+IFqK2K1zN2OFciJ6+Tt44ITtzv8rPUv8BrNCTcMHnudLDqk3/pIfJPP7w7yQEouBfX6JSHH4g== X-Received: by 2002:a05:600c:4fc2:b0:434:f3d8:62d0 with SMTP id 5b1f17b1804b1-436e26803f4mr299036085e9.3.1737044180933; Thu, 16 Jan 2025 08:16:20 -0800 (PST) Received: from localhost.localdomain ([154.118.34.84]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-437c752935csm63177025e9.26.2025.01.16.08.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 08:16:20 -0800 (PST) From: Seyi Kuforiji To: git@vger.kernel.org Cc: ps@pks.im, phillip.wood@dunelm.org.uk, Seyi Kuforiji Subject: [PATCH v2 2/4] t/unit-tests: convert mem-pool test to use clar test framework Date: Thu, 16 Jan 2025 17:15:57 +0100 Message-ID: <20250116161559.91038-3-kuforiji98@gmail.com> X-Mailer: git-send-email 2.47.0.86.g15030f9556 In-Reply-To: <20250116161559.91038-1-kuforiji98@gmail.com> References: <20250116104911.77405-1-kuforiji98@gmail.com> <20250116161559.91038-1-kuforiji98@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Adapt the mem-pool test script to use clar framework by using clar assertions where necessary.Test functions are created as a standalone to test different test cases. Mentored-by: Patrick Steinhardt Signed-off-by: Seyi Kuforiji --- Makefile | 2 +- t/meson.build | 2 +- t/unit-tests/t-mem-pool.c | 31 ------------------------------- t/unit-tests/u-mem-pool.c | 25 +++++++++++++++++++++++++ 4 files changed, 27 insertions(+), 33 deletions(-) delete mode 100644 t/unit-tests/t-mem-pool.c create mode 100644 t/unit-tests/u-mem-pool.c diff --git a/Makefile b/Makefile index 97e8385b66..49ada4169d 100644 --- a/Makefile +++ b/Makefile @@ -1338,6 +1338,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/% THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/% CLAR_TEST_SUITES += u-ctype +CLAR_TEST_SUITES += u-mem-pool CLAR_TEST_SUITES += u-strvec CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X) CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES)) @@ -1347,7 +1348,6 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o UNIT_TEST_PROGRAMS += t-example-decorate UNIT_TEST_PROGRAMS += t-hash UNIT_TEST_PROGRAMS += t-hashmap -UNIT_TEST_PROGRAMS += t-mem-pool UNIT_TEST_PROGRAMS += t-oid-array UNIT_TEST_PROGRAMS += t-oidmap UNIT_TEST_PROGRAMS += t-oidtree diff --git a/t/meson.build b/t/meson.build index 602ebfe6a2..ffe951f9be 100644 --- a/t/meson.build +++ b/t/meson.build @@ -1,5 +1,6 @@ clar_test_suites = [ 'unit-tests/u-ctype.c', + 'unit-tests/u-mem-pool.c', 'unit-tests/u-strvec.c', ] @@ -43,7 +44,6 @@ unit_test_programs = [ 'unit-tests/t-example-decorate.c', 'unit-tests/t-hash.c', 'unit-tests/t-hashmap.c', - 'unit-tests/t-mem-pool.c', 'unit-tests/t-oid-array.c', 'unit-tests/t-oidmap.c', 'unit-tests/t-oidtree.c', diff --git a/t/unit-tests/t-mem-pool.c b/t/unit-tests/t-mem-pool.c deleted file mode 100644 index fe500c704b..0000000000 --- a/t/unit-tests/t-mem-pool.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "test-lib.h" -#include "mem-pool.h" - -static void setup_static(void (*f)(struct mem_pool *), size_t block_alloc) -{ - struct mem_pool pool = { .block_alloc = block_alloc }; - f(&pool); - mem_pool_discard(&pool, 0); -} - -static void t_calloc_100(struct mem_pool *pool) -{ - size_t size = 100; - char *buffer = mem_pool_calloc(pool, 1, size); - for (size_t i = 0; i < size; i++) - check_int(buffer[i], ==, 0); - if (!check(pool->mp_block != NULL)) - return; - check(pool->mp_block->next_free != NULL); - check(pool->mp_block->end != NULL); -} - -int cmd_main(int argc UNUSED, const char **argv UNUSED) -{ - TEST(setup_static(t_calloc_100, 1024 * 1024), - "mem_pool_calloc returns 100 zeroed bytes with big block"); - TEST(setup_static(t_calloc_100, 1), - "mem_pool_calloc returns 100 zeroed bytes with tiny block"); - - return test_done(); -} diff --git a/t/unit-tests/u-mem-pool.c b/t/unit-tests/u-mem-pool.c new file mode 100644 index 0000000000..2bc2493b7e --- /dev/null +++ b/t/unit-tests/u-mem-pool.c @@ -0,0 +1,25 @@ +#include "unit-test.h" +#include "mem-pool.h" + +static void test_many_pool_allocations(size_t block_alloc) +{ + struct mem_pool pool = { .block_alloc = block_alloc }; + size_t size = 100; + char *buffer = mem_pool_calloc(&pool, 1, size); + for (size_t i = 0; i < size; i++) + cl_assert_equal_i(0, buffer[i]); + cl_assert(pool.mp_block != NULL); + cl_assert(pool.mp_block->next_free != NULL); + cl_assert(pool.mp_block->end != NULL); + mem_pool_discard(&pool, 0); +} + +void test_mem_pool__big_block(void) +{ + test_many_pool_allocations(1024 * 1024); +} + +void test_mem_pool__tiny_block(void) +{ + test_many_pool_allocations(1); +} From patchwork Thu Jan 16 16:15:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seyi Kuforiji X-Patchwork-Id: 13941909 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 09F858635B for ; Thu, 16 Jan 2025 16:16:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737044189; cv=none; b=Qis2LK4uEt8wI7XAFCFzbENie+6R4E6COqSuPhXSznEojUqlUUafHmV/96NzgVQciFDXNjPnYyxAsjbKcKD2UFugTaIZ+XCSba/Cm1/fVyXLr/AwYInkv9y7i/44/7QHS187C9D5UJeKOFkHDJzko20tf8ewuHR6uFJ52tVLwFs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737044189; c=relaxed/simple; bh=0PfZZchRGvwEj9MKjZkX2TKoeQjjs9/nibor6yetpWs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LweQWARwqPrrcYoo+Ndx42VvMf/qIm9bOTCKTmQ7qlSyhzhKouuSe+IsnbgvBfo2rBWTVrEkBbSaq3v09ytNBhkAWvAWnQkNuoycAVC40X+Ai250Dru0eeaDWHwUTtdlBpOz11ArHJT1xSiaS7pXRar1+fy2g+grnz/Ko1GTd8Y= 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=GTF/8mmx; arc=none smtp.client-ip=209.85.128.48 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="GTF/8mmx" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4361b6f9faeso7458705e9.1 for ; Thu, 16 Jan 2025 08:16:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737044186; x=1737648986; 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=p2D1ZQgyigSiR29ims/9YVQ82J01XGMI+3TgqZULvx0=; b=GTF/8mmx+wENRMu+ldiwMuYOpbmPCr3EDpBwSVQStgT8SJ5ToUlqk+z51K3BEX2ULL 9FhYujStJm4+6DejxmBGHE8w/wGOkgaVi01vJFCGkHADmVPc9Bq5fu0xJpWc6NfRhmwc LPFnWZCGGWRU+cvINYPRX0tZvEieZWNjP2hEG9YY7ZP3jUQGN/gBIcFjiIanXG7+9v0W Usxnu2TTB1SrlKZvPR6LaVDcBx5qoMu6A4gkVLV3E42hf5EiNyYEAmeyF7iqtsxWAk0M Q393CPC9C49z7c6D1mWbZHFg3ZQBqw4WmHnwL9ksKIHikDs5m1f11EkWU6e86jS2cjnv 8yHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737044186; x=1737648986; 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=p2D1ZQgyigSiR29ims/9YVQ82J01XGMI+3TgqZULvx0=; b=aNeuQUFg6D3oB1tlRHV6C847yBH6S5hczhcJWo72lxEuzGY38qXf9q/ePBcmvgmWKO SrnQFPZvgdAxaGZ2/y4nOHwYhCQjBJFtOhWVl027Qg+jJJjsP5GeZ3NIH4s362w5c7IZ txepshcZN5OyDKvFlnM4IpHLsq1ayRriFumkZARY4eBYm9oE+UyFgRKpITo9hXhnB6SQ mG9ZtXg9PWXIlZT7Ta+ktwFGU+GxD4IxQIX9HVSTdGR88ITFZAE0iROzlbtz3e/r97U0 GtLLJJt5UW7jmtWpD5fDummnWZ0loPjmfeBuS5t/2Z7fYWGvJcYWTANtsBNeuBombNmT xlfQ== X-Gm-Message-State: AOJu0Yzt5KVAqtNw6BbvCnbsT8eEjlaVhX5SME9Z9UHNRpmHgRBbapIr 0xnA6nGWv9ZU5hTFrRLzRa656CuPe6V7ESGjXR6c1CT5oxBMO2jTFBpkxhJKgvFHfQ== X-Gm-Gg: ASbGncvtfr5gqNz6d4Yy/zQ33ynr72Z9UEWclmS6PhVQrC5vF8bXzxW3pIaLL1H6QSJ l6T/g22/CgtoMUlc5NGw75/SgYf9EaTyeADR30qxuVzFGInvGZojiMfR5bavIiXMfXwRX2IM9JC 8pLvSdtCSpbqKgbggmGeqRvNS7VxJNj/+Ol9oLw/2mp8uiWXCbYnfvC8AwqqZ/Tsibsis3wfcva Q8pPcOT6n/qroqrWKRCtIt76C4pMFb4Eg1nCVm5NIOczTgdmFbdomKZeCHTT2ZCxUQ9yg== X-Google-Smtp-Source: AGHT+IFiCDJUySSs8Bf6AL+vUQWxXvxImeplISB9CfVvUY571wlC4BMEnLAanIB3B9ifnGZqiJw0wA== X-Received: by 2002:a05:600c:1e09:b0:434:9e17:190c with SMTP id 5b1f17b1804b1-437c6a89cc3mr64688895e9.0.1737044185549; Thu, 16 Jan 2025 08:16:25 -0800 (PST) Received: from localhost.localdomain ([154.118.34.84]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-437c752935csm63177025e9.26.2025.01.16.08.16.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 08:16:25 -0800 (PST) From: Seyi Kuforiji To: git@vger.kernel.org Cc: ps@pks.im, phillip.wood@dunelm.org.uk, Seyi Kuforiji Subject: [PATCH v2 3/4] t/unit-tests: adapt priority queue test to use clar test framework Date: Thu, 16 Jan 2025 17:15:58 +0100 Message-ID: <20250116161559.91038-4-kuforiji98@gmail.com> X-Mailer: git-send-email 2.47.0.86.g15030f9556 In-Reply-To: <20250116161559.91038-1-kuforiji98@gmail.com> References: <20250116104911.77405-1-kuforiji98@gmail.com> <20250116161559.91038-1-kuforiji98@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Convert the prio-queue test script to clar framework by using clar assertions where necessary. Test functions are created as a standalone to test different cases. update the type of the variable `j` from int to `size_t`, this ensures compatibility with the type used for result_size, which is also size_t, preventing a potential warning or error caused by comparisons between signed and unsigned integers. Mentored-by: Patrick Steinhardt Signed-off-by: Seyi Kuforiji --- Makefile | 2 +- t/meson.build | 2 +- t/unit-tests/t-prio-queue.c | 91 ----------------------------------- t/unit-tests/u-prio-queue.c | 94 +++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 93 deletions(-) delete mode 100644 t/unit-tests/t-prio-queue.c create mode 100644 t/unit-tests/u-prio-queue.c diff --git a/Makefile b/Makefile index 49ada4169d..049f857512 100644 --- a/Makefile +++ b/Makefile @@ -1339,6 +1339,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/% CLAR_TEST_SUITES += u-ctype CLAR_TEST_SUITES += u-mem-pool +CLAR_TEST_SUITES += u-prio-queue CLAR_TEST_SUITES += u-strvec CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X) CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES)) @@ -1351,7 +1352,6 @@ UNIT_TEST_PROGRAMS += t-hashmap UNIT_TEST_PROGRAMS += t-oid-array UNIT_TEST_PROGRAMS += t-oidmap UNIT_TEST_PROGRAMS += t-oidtree -UNIT_TEST_PROGRAMS += t-prio-queue UNIT_TEST_PROGRAMS += t-reftable-basics UNIT_TEST_PROGRAMS += t-reftable-block UNIT_TEST_PROGRAMS += t-reftable-merged diff --git a/t/meson.build b/t/meson.build index ffe951f9be..09232967cd 100644 --- a/t/meson.build +++ b/t/meson.build @@ -1,6 +1,7 @@ clar_test_suites = [ 'unit-tests/u-ctype.c', 'unit-tests/u-mem-pool.c', + 'unit-tests/u-prio-queue.c', 'unit-tests/u-strvec.c', ] @@ -47,7 +48,6 @@ unit_test_programs = [ 'unit-tests/t-oid-array.c', 'unit-tests/t-oidmap.c', 'unit-tests/t-oidtree.c', - 'unit-tests/t-prio-queue.c', 'unit-tests/t-reftable-basics.c', 'unit-tests/t-reftable-block.c', 'unit-tests/t-reftable-merged.c', diff --git a/t/unit-tests/t-prio-queue.c b/t/unit-tests/t-prio-queue.c deleted file mode 100644 index a053635000..0000000000 --- a/t/unit-tests/t-prio-queue.c +++ /dev/null @@ -1,91 +0,0 @@ -#include "test-lib.h" -#include "prio-queue.h" - -static int intcmp(const void *va, const void *vb, void *data UNUSED) -{ - const int *a = va, *b = vb; - return *a - *b; -} - - -#define MISSING -1 -#define DUMP -2 -#define STACK -3 -#define GET -4 -#define REVERSE -5 - -static int show(int *v) -{ - return v ? *v : MISSING; -} - -static void test_prio_queue(int *input, size_t input_size, - int *result, size_t result_size) -{ - struct prio_queue pq = { intcmp }; - int j = 0; - - for (size_t i = 0; i < input_size; i++) { - void *peek, *get; - switch(input[i]) { - case GET: - peek = prio_queue_peek(&pq); - get = prio_queue_get(&pq); - if (!check(peek == get)) - return; - if (!check_uint(j, <, result_size)) - break; - if (!check_int(result[j], ==, show(get))) - test_msg(" j: %d", j); - j++; - break; - case DUMP: - while ((peek = prio_queue_peek(&pq))) { - get = prio_queue_get(&pq); - if (!check(peek == get)) - return; - if (!check_uint(j, <, result_size)) - break; - if (!check_int(result[j], ==, show(get))) - test_msg(" j: %d", j); - j++; - } - break; - case STACK: - pq.compare = NULL; - break; - case REVERSE: - prio_queue_reverse(&pq); - break; - default: - prio_queue_put(&pq, &input[i]); - break; - } - } - check_uint(j, ==, result_size); - clear_prio_queue(&pq); -} - -#define TEST_INPUT(input, result) \ - test_prio_queue(input, ARRAY_SIZE(input), result, ARRAY_SIZE(result)) - -int cmd_main(int argc UNUSED, const char **argv UNUSED) -{ - TEST(TEST_INPUT(((int []){ 2, 6, 3, 10, 9, 5, 7, 4, 5, 8, 1, DUMP }), - ((int []){ 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10 })), - "prio-queue works for basic input"); - TEST(TEST_INPUT(((int []){ 6, 2, 4, GET, 5, 3, GET, GET, 1, DUMP }), - ((int []){ 2, 3, 4, 1, 5, 6 })), - "prio-queue works for mixed put & get commands"); - TEST(TEST_INPUT(((int []){ 1, 2, GET, GET, GET, 1, 2, GET, GET, GET }), - ((int []){ 1, 2, MISSING, 1, 2, MISSING })), - "prio-queue works when queue is empty"); - TEST(TEST_INPUT(((int []){ STACK, 8, 1, 5, 4, 6, 2, 3, DUMP }), - ((int []){ 3, 2, 6, 4, 5, 1, 8 })), - "prio-queue works when used as a LIFO stack"); - TEST(TEST_INPUT(((int []){ STACK, 1, 2, 3, 4, 5, 6, REVERSE, DUMP }), - ((int []){ 1, 2, 3, 4, 5, 6 })), - "prio-queue works when LIFO stack is reversed"); - - return test_done(); -} diff --git a/t/unit-tests/u-prio-queue.c b/t/unit-tests/u-prio-queue.c new file mode 100644 index 0000000000..145e689c9c --- /dev/null +++ b/t/unit-tests/u-prio-queue.c @@ -0,0 +1,94 @@ +#include "unit-test.h" +#include "prio-queue.h" + +static int intcmp(const void *va, const void *vb, void *data UNUSED) +{ + const int *a = va, *b = vb; + return *a - *b; +} + + +#define MISSING -1 +#define DUMP -2 +#define STACK -3 +#define GET -4 +#define REVERSE -5 + +static int show(int *v) +{ + return v ? *v : MISSING; +} + +static void test_prio_queue(int *input, size_t input_size, + int *result, size_t result_size) +{ + struct prio_queue pq = { intcmp }; + size_t j = 0; + + for (size_t i = 0; i < input_size; i++) { + void *peek, *get; + switch(input[i]) { + case GET: + peek = prio_queue_peek(&pq); + get = prio_queue_get(&pq); + cl_assert(peek == get); + cl_assert(j < result_size); + cl_assert_equal_i(result[j], show(get)); + j++; + break; + case DUMP: + while ((peek = prio_queue_peek(&pq))) { + get = prio_queue_get(&pq); + cl_assert(peek == get); + cl_assert(j < result_size); + cl_assert_equal_i(result[j], show(get)); + j++; + } + break; + case STACK: + pq.compare = NULL; + break; + case REVERSE: + prio_queue_reverse(&pq); + break; + default: + prio_queue_put(&pq, &input[i]); + break; + } + } + cl_assert_equal_i(j, result_size); + clear_prio_queue(&pq); +} + +#define TEST_INPUT(input, result) \ + test_prio_queue(input, ARRAY_SIZE(input), result, ARRAY_SIZE(result)) + +void test_prio_queue__basic(void) +{ + TEST_INPUT(((int []){ 2, 6, 3, 10, 9, 5, 7, 4, 5, 8, 1, DUMP }), + ((int []){ 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10 })); +} + +void test_prio_queue__mixed(void) +{ + TEST_INPUT(((int []){ 6, 2, 4, GET, 5, 3, GET, GET, 1, DUMP }), + ((int []){ 2, 3, 4, 1, 5, 6 })); +} + +void test_prio_queue__empty(void) +{ + TEST_INPUT(((int []){ 1, 2, GET, GET, GET, 1, 2, GET, GET, GET }), + ((int []){ 1, 2, MISSING, 1, 2, MISSING })); +} + +void test_prio_queue__stack(void) +{ + TEST_INPUT(((int []){ STACK, 8, 1, 5, 4, 6, 2, 3, DUMP }), + ((int []){ 3, 2, 6, 4, 5, 1, 8 })); +} + +void test_prio_queue__reverse_stack(void) +{ + TEST_INPUT(((int []){ STACK, 1, 2, 3, 4, 5, 6, REVERSE, DUMP }), + ((int []){ 1, 2, 3, 4, 5, 6 })); +} From patchwork Thu Jan 16 16:15:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seyi Kuforiji X-Patchwork-Id: 13941910 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 7CE0922BAC6 for ; Thu, 16 Jan 2025 16:16:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737044194; cv=none; b=up3c/SBKirivIgl+L1/M6n8VN2DOUJghiNrBlk7YX5Pa2mUn/tUNfii7kA9apE+9qoUI+jLcryusP8J6HTeJt7c4bDlPoxCAMMgR6Em1zqKF/laI6XAI/MUtpZ6dfXPYVbiw3uJGooxYRGEacu7+LlDX0lX2QKti/u76AnLL8e8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737044194; c=relaxed/simple; bh=hMuLxxnRyZACqRSR7y7hec5PqrUH+3FgmDqAhpXq0Q8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F/wIFHdkeL9DHEHtzAd85Id+pr/Oemqcq+WsCxk8CCbXt0BjVj/JuMxNP2gFUrPr3hqBW35scyz444RBlfVkLVNHv0i656+bnvjVkGa6eXPyE4CkTLTbIXQ6tNaFkhT7/QFPxaPeq+3yHY7QUNe8DemxThZpv5uwAAu8vXvhY/M= 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=Ixo7cjyC; arc=none smtp.client-ip=209.85.221.44 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="Ixo7cjyC" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-38a25d4b9d4so641911f8f.0 for ; Thu, 16 Jan 2025 08:16:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737044190; x=1737648990; 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=F90VIJ7J6doYK5Te5Ja/fbNBxHBFIjMxoM8CsXFtbEQ=; b=Ixo7cjyC4/5opgrY/8C3IRhyoOm6M/Z57EJHu3DtmWXwMvOK7bGk2fabvtxQ3ioGzv eAgHQOZk0sIwzCGOkqQPBXZZ+FU96mkz3eirh3VT83s7r1rUMrLQ8HUF1ggMX7RtXf3s e2rvKrPuavW6EfbZTaG1Oz8VtgumnESsHuD+QWtR+xNuPT240R5F8DZdylkRIid1tl4I LrdbbAxb1evGa0D5B5cTcDiPx8y0zKxZkDHiJRfVY50lkSg0Gj/88SR34VoX63/8qe9f QPlA1BQ52R7aCwNNfsrxyaehrgJPvyx7GXNK9bKPkUZjIiyVIqQXhNI7nX+6CiuM+WaL 9NJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737044190; x=1737648990; 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=F90VIJ7J6doYK5Te5Ja/fbNBxHBFIjMxoM8CsXFtbEQ=; b=CK4L1RcSrz7ZIcnEnBHBXn7bVOrhuoksgbh2p66lFybO3BmgGAXdViQjvlaE3WhrEX 3kd3+9VOuH2x3A32DPpKyVP3sprnnixDZg7AGwIZ47K48P7sG/IAd3+h7Nskbk1Z8g6s Rz+xgnooPkEtfz11sGJth2QoGuD2L5B2CY3/b1bvjAsRiIyUplPcj6iaPHeya+UI4IXn mz0C1j+WUWwTqeQSipkBZnA853O9PDUbPeGvU+FTwA+H8dpThwlJqqOXyyGUFARfkD8k oMeuTDbCp2ILCDXqWoMWfcPj8lG5kMFOEYrfrlg8fGmTwRlANnBGHlxLxTpNecU57Qsx hbtQ== X-Gm-Message-State: AOJu0YwobGxbLbUgoLKRfrKqAru5G6ZZ9frRRw73ElU+gfM6Q2k330SN GljHmMaWW/zXgFHj8DOED7g0rzKMS7km7JyXrTnYsXg0iTDD+RIHg+k0unQCny1Oag== X-Gm-Gg: ASbGncvY4U8C+L/KLIuCUEnZGPZbKvSl5dxCIa26pMMeHgf02swFRLcsRhVK/KGtXc8 24si48+14RD451PhhOnv/UbRmA7YMVXLWRY6K1fbUz1XlStANptc2RNO8eMPNsuYmnI1Aa1c7TB YQQSOdjeHMMemmZVRbIumDYIsAYR6OWuLSVgTdNhFurgDpZpvkkolTHR4ewaacacIWtcrIGQJps liAplvWXiU3Jl7Re/Gonyu/tFDNRnrwdjuo6a/7O7zdSUyplk9sQMuaaa0FDsfrGh5rKg== X-Google-Smtp-Source: AGHT+IHAO5Mpn5U5grfoAqoH55s5Yjq+LwZSvjNT3Pa2R6aJKGmgBjyNvnQ7WsPcfjvOmDfUhLlpSA== X-Received: by 2002:a5d:64e7:0:b0:385:df2c:91aa with SMTP id ffacd0b85a97d-38a872c8882mr27891149f8f.7.1737044190471; Thu, 16 Jan 2025 08:16:30 -0800 (PST) Received: from localhost.localdomain ([154.118.34.84]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-437c752935csm63177025e9.26.2025.01.16.08.16.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 08:16:30 -0800 (PST) From: Seyi Kuforiji To: git@vger.kernel.org Cc: ps@pks.im, phillip.wood@dunelm.org.uk, Seyi Kuforiji Subject: [PATCH v2 4/4] t/unit-tests: convert reftable tree test to use clar test framework Date: Thu, 16 Jan 2025 17:15:59 +0100 Message-ID: <20250116161559.91038-5-kuforiji98@gmail.com> X-Mailer: git-send-email 2.47.0.86.g15030f9556 In-Reply-To: <20250116161559.91038-1-kuforiji98@gmail.com> References: <20250116104911.77405-1-kuforiji98@gmail.com> <20250116161559.91038-1-kuforiji98@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Adapts reftable tree test script to clar framework by using clar assertions where necessary. Mentored-by: Patrick Steinhardt Signed-off-by: Seyi Kuforiji --- Makefile | 2 +- t/meson.build | 2 +- t/unit-tests/t-reftable-tree.c | 86 ---------------------------------- t/unit-tests/u-reftable-tree.c | 78 ++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 88 deletions(-) delete mode 100644 t/unit-tests/t-reftable-tree.c create mode 100644 t/unit-tests/u-reftable-tree.c diff --git a/Makefile b/Makefile index 049f857512..75dbb8e25f 100644 --- a/Makefile +++ b/Makefile @@ -1340,6 +1340,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/% CLAR_TEST_SUITES += u-ctype CLAR_TEST_SUITES += u-mem-pool CLAR_TEST_SUITES += u-prio-queue +CLAR_TEST_SUITES += u-reftable-tree CLAR_TEST_SUITES += u-strvec CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X) CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES)) @@ -1360,7 +1361,6 @@ UNIT_TEST_PROGRAMS += t-reftable-reader UNIT_TEST_PROGRAMS += t-reftable-readwrite UNIT_TEST_PROGRAMS += t-reftable-record UNIT_TEST_PROGRAMS += t-reftable-stack -UNIT_TEST_PROGRAMS += t-reftable-tree UNIT_TEST_PROGRAMS += t-strbuf UNIT_TEST_PROGRAMS += t-strcmp-offset UNIT_TEST_PROGRAMS += t-trailer diff --git a/t/meson.build b/t/meson.build index 09232967cd..6dd41216ef 100644 --- a/t/meson.build +++ b/t/meson.build @@ -2,6 +2,7 @@ clar_test_suites = [ 'unit-tests/u-ctype.c', 'unit-tests/u-mem-pool.c', 'unit-tests/u-prio-queue.c', + 'unit-tests/u-reftable-tree.c', 'unit-tests/u-strvec.c', ] @@ -56,7 +57,6 @@ unit_test_programs = [ 'unit-tests/t-reftable-readwrite.c', 'unit-tests/t-reftable-record.c', 'unit-tests/t-reftable-stack.c', - 'unit-tests/t-reftable-tree.c', 'unit-tests/t-strbuf.c', 'unit-tests/t-strcmp-offset.c', 'unit-tests/t-trailer.c', diff --git a/t/unit-tests/t-reftable-tree.c b/t/unit-tests/t-reftable-tree.c deleted file mode 100644 index 79b175a45a..0000000000 --- a/t/unit-tests/t-reftable-tree.c +++ /dev/null @@ -1,86 +0,0 @@ -/* -Copyright 2020 Google LLC - -Use of this source code is governed by a BSD-style -license that can be found in the LICENSE file or at -https://developers.google.com/open-source/licenses/bsd -*/ - -#include "test-lib.h" -#include "reftable/tree.h" - -static int t_compare(const void *a, const void *b) -{ - return (char *)a - (char *)b; -} - -struct curry { - void **arr; - size_t len; -}; - -static void store(void *arg, void *key) -{ - struct curry *c = arg; - c->arr[c->len++] = key; -} - -static void t_tree_search(void) -{ - struct tree_node *root = NULL; - void *values[11] = { 0 }; - struct tree_node *nodes[11] = { 0 }; - size_t i = 1; - - /* - * Pseudo-randomly insert the pointers for elements between - * values[1] and values[10] (inclusive) in the tree. - */ - do { - nodes[i] = tree_insert(&root, &values[i], &t_compare); - check(nodes[i] != NULL); - i = (i * 7) % 11; - } while (i != 1); - - for (i = 1; i < ARRAY_SIZE(nodes); i++) { - check_pointer_eq(&values[i], nodes[i]->key); - check_pointer_eq(nodes[i], tree_search(root, &values[i], &t_compare)); - } - - check(!tree_search(root, values, t_compare)); - tree_free(root); -} - -static void t_infix_walk(void) -{ - struct tree_node *root = NULL; - void *values[11] = { 0 }; - void *out[11] = { 0 }; - struct curry c = { - .arr = (void **) &out, - }; - size_t i = 1; - size_t count = 0; - - do { - struct tree_node *node = tree_insert(&root, &values[i], t_compare); - check(node != NULL); - i = (i * 7) % 11; - count++; - } while (i != 1); - - 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); -} - -int cmd_main(int argc UNUSED, const char *argv[] UNUSED) -{ - TEST(t_tree_search(), "tree_search works"); - TEST(t_infix_walk(), "infix_walk works"); - - return test_done(); -} diff --git a/t/unit-tests/u-reftable-tree.c b/t/unit-tests/u-reftable-tree.c new file mode 100644 index 0000000000..bcf9061071 --- /dev/null +++ b/t/unit-tests/u-reftable-tree.c @@ -0,0 +1,78 @@ +/* +Copyright 2020 Google LLC + +Use of this source code is governed by a BSD-style +license that can be found in the LICENSE file or at +https://developers.google.com/open-source/licenses/bsd +*/ + +#include "unit-test.h" +#include "reftable/tree.h" + +static int t_compare(const void *a, const void *b) +{ + return (char *)a - (char *)b; +} + +struct curry { + void **arr; + size_t len; +}; + +static void store(void *arg, void *key) +{ + struct curry *c = arg; + c->arr[c->len++] = key; +} + +void test_reftable_tree__tree_search(void) +{ + struct tree_node *root = NULL; + void *values[11] = { 0 }; + struct tree_node *nodes[11] = { 0 }; + size_t i = 1; + + /* + * Pseudo-randomly insert the pointers for elements between + * values[1] and values[10] (inclusive) in the tree. + */ + do { + nodes[i] = tree_insert(&root, &values[i], &t_compare); + cl_assert(nodes[i] != NULL); + i = (i * 7) % 11; + } while (i != 1); + + for (i = 1; i < ARRAY_SIZE(nodes); i++) { + cl_assert_equal_p(&values[i], nodes[i]->key); + cl_assert_equal_p(nodes[i], tree_search(root, &values[i], &t_compare)); + } + + cl_assert(tree_search(root, values, t_compare) == NULL); + tree_free(root); +} + +void test_reftable_tree__infix_walk(void) +{ + struct tree_node *root = NULL; + void *values[11] = { 0 }; + void *out[11] = { 0 }; + struct curry c = { + .arr = (void **) &out, + }; + size_t i = 1; + size_t count = 0; + + do { + struct tree_node *node = tree_insert(&root, &values[i], t_compare); + cl_assert(node != NULL); + i = (i * 7) % 11; + count++; + } while (i != 1); + + infix_walk(root, &store, &c); + for (i = 1; i < ARRAY_SIZE(values); i++) + cl_assert_equal_p(&values[i], out[i - 1]); + cl_assert(out[i - 1] == NULL); + cl_assert_equal_i(c.len, count); + tree_free(root); +}