From patchwork Thu Jan 16 10:49:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seyi Kuforiji X-Patchwork-Id: 13941570 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE98C19539F for ; Thu, 16 Jan 2025 10:49:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737024566; cv=none; b=KmNI4uRgNLwkGq3v0KaPkBrh9zBBmAJA7SrX+jasxuUa88XmwpYqT5tVBzfEVQq7UppTr9tqaXzpfqAjVS1HgWyYrusz/+WaFLH+YRyrrfMoTnCwuWu7s9SNa1aYJruadLWEK59Uy1ZKoeRB/0yywLpkPwUbDQHs5aRZFWNhGXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737024566; c=relaxed/simple; bh=bL8VSI/kPoXKUqA7KlK8sK5tQ7o+Trrh6e/zC76/wgE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fQt54AftSLg9thB8aZlBXVoYKMS73Ntb+KghqFKFYLOsYLvoQrSVFi/qhVghjVCxxWsgdjAqX10Oy9B+d9/5Z4gcij6WeRd/nAieQ/NlDOSCADkdSpYl1FvE+Oa3fqrgbDUHp93lGhfpMDKBMsqYn4v0Q4KjkPrze8CE7h1M1nU= 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=iitFGayo; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iitFGayo" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-aaecf50578eso179914666b.2 for ; Thu, 16 Jan 2025 02:49:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737024563; x=1737629363; 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=3Mbo3uevmHZzZ4NPsGtHNcIjYB/AlAjkq2ns2LSEvW8=; b=iitFGayoc6Z9AZDe1rH18TJlzwlnimyuAyEXvgyNjQjraqkWGHt76UAZTUWxHQSJBY 4wuIpg2XH5xw0JI5oILfTS7Prk7VKAMU14ic4m7Rjvx747gAT1y1+zSQrwJ5lYgC2TbE nDWG/U2hAz5kxqMMxL7fZ1XKuyK9DdLq9SEzOL8k2BcIYI0TAFaygvvmoiWM7HbOyOmu Xj8QNZlqbwufRV0pYK1dcxt73dkTXv/Cptt0GLu8uRyE3wsENh1QRTCkO7N0muw4hixG zTbubpfYl6TC44c/6g/VjRdfhKp8Hg2tRQYPCaQ/8OxhsxSbhDHLUQvm1+wd9lKa4Bkp B0UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737024563; x=1737629363; 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=3Mbo3uevmHZzZ4NPsGtHNcIjYB/AlAjkq2ns2LSEvW8=; b=cyZLQcKu0GuToU7JukeeFp6XbWKwtWdKPvp7zXNOrpiOCTGVrYVQX88f+DTNVofKWv ksp7bwe9LPzvZVqDYyDqsF+Xyf4W5Ubzc5aDqv4IX/7bqtXzG8UcaON3gxATcxESRW8t YG4ZxFfc0zx3BZIYN8HuiZqzKcrHrn3yx3k3jzFQIFZb4JNtuXRkZVgeXHM8VAcbhwE8 cbSiWAl3nvPfjf1en+sXWYs0wwzgWKS4d6OSCC6HCtwyHBw+t1B4xNsfY5gQW5AS7OeQ 8jaITBjmCLFRkXNdOeChxmcIWDuloj7ufG/k4UJWuAF82guSVlgHQATl5v5lEx8MbI+Q mPGw== X-Gm-Message-State: AOJu0YxebmBkodA6KngABF/oQj6dy7cj3kda5NxIj/tZnVA02OG/nKq5 aVR8PbsHKyg/bd+CqeBwNuS5g40VeU+4msoWtQqWjN81U3f6jU3R6O1VBXx5SjGGLQ== X-Gm-Gg: ASbGncvYh0HgJLCwdfRKzYmsSUqmq2h3+tcia8MrrxjEb4o+XTy3rGvTMNcKUNJw69N 4Xet6TibUjmvweTrqRp/rnJUvCFD3OGsdtTZlqnil1hgLA11I2YdBfti0oaQ23Rv90yKbO4gHUC +EP3p+uy4U0GqG9Y+/KvNfePAmEqIJfn5I8eNxVIo9xli1xNa2hPwqzrOcEr7zl2dTSv40zTqRM Q7A2yWBiyXqPiPvOIzX0cXsXk2u01o6BODTUpBYflBWvodQVTqWXmhv/zSOIDakLTFRig== X-Google-Smtp-Source: AGHT+IE634iUWuPOG5WVWYUpA3PXKT9UFDYE90pScPcAk0byxMmSsXnt4PsTxUuk2jJFm/Yr9m9aMw== X-Received: by 2002:a17:907:d87:b0:aa6:519c:ef9a with SMTP id a640c23a62f3a-ab2ab70ac8cmr3287567566b.53.1737024562952; Thu, 16 Jan 2025 02:49:22 -0800 (PST) Received: from localhost.localdomain ([154.118.34.84]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-ab2c9646be5sm901203966b.174.2025.01.16.02.49.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 02:49:22 -0800 (PST) From: Seyi Kuforiji To: git@vger.kernel.org Cc: ps@pks.im, phillip.wood@dunelm.org.uk, Seyi Kuforiji Subject: [PATCH 1/4] t/unit-tests: handle dashes in test suite filenames Date: Thu, 16 Jan 2025 11:49:08 +0100 Message-ID: <20250116104911.77405-2-kuforiji98@gmail.com> X-Mailer: git-send-email 2.47.0.86.g15030f9556 In-Reply-To: <20250116104911.77405-1-kuforiji98@gmail.com> References: <20250116104911.77405-1-kuforiji98@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Adapt script to translate dashes (`-`) in test suite filenames to underscores (`_`) to ensure proper extraction of test function names. `generate-clar-decls.sh` does not pick up dashes in filenames such as `u-mem-pool.c`, which prevents the scripts from being run. 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 10:49:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seyi Kuforiji X-Patchwork-Id: 13941571 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.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 6606719539F for ; Thu, 16 Jan 2025 10:49:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737024571; cv=none; b=Iq/h0778BHSm7OrsRDF2e7C0zE3GuG3FlB4HU9hr7RZBbAmN7Y+xtVakKenU6lGQHIh60TompcvZN/cH88BqCdefVyOcs/eEsiOoWX1LXlWZNEXzNGhQkgnyrXmq4yIosxqV6+lCC066Es6iOhkuPHwEWiICWoi9Z/V8FxHR0tU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737024571; c=relaxed/simple; bh=Bo8ojpGZ3vtto3R+jupgcUFC3rekAbsIsp5jL/Ru2/o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B85N6WVsYbnQiYVMJUZh9uXlnH+WyE/iKVSdU/q2+DtBv3I6X9GCY8Vd7wJtADPgzvFp0T19Z4L5zinzsjqABMwBC/+Dbwb9esI3mObyaV39mADjyfyud6aRiiox5R/EYFEMLgTTybdrUPSPqoAXyh6rNOSq1c4DZkBVxIqAWpk= 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=QHHtkqLq; arc=none smtp.client-ip=209.85.218.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="QHHtkqLq" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-aafc9d75f8bso138810666b.2 for ; Thu, 16 Jan 2025 02:49:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737024567; x=1737629367; 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=6iXtlJs4Rcx29VFlm0PpIoOsU5JQxfixMasimpPPt/A=; b=QHHtkqLqGa/8oRQtpesYPBp6+m8mWe6OCXphg4W41S3LV7gFJHaF1zotoOVMCrwlr+ gbhvQbRNW7MqWPX0EV27q2lQqN1mbUzx57KG2PqVwzc4bxrIbmp84GMZGhsRmI/NJFrG EsUSDgidI5vZ4heP3slIIZIvS91tlcHMSPREzkyKkp7kaYiFw2oXC33aLI67wyZCxrWI esHESuyYiVpD74nN74LjnUFaHaq17cnzO9+RNNu1dAn9EawMgSGAtnmQ17a2/9hlhp07 +UBp7dr5oqmRuZqDV1tkBfVI4rjqwmSR3/rVQGqHleIwsji4ln8WmiMGHMvEh5bmmQAT mecQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737024567; x=1737629367; 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=6iXtlJs4Rcx29VFlm0PpIoOsU5JQxfixMasimpPPt/A=; b=tGgqmYZGLV0xQPf7VahH6ZvdI3shmQf+lQPzNVr7teX40CpNIyei22RSDclnvaGPP2 hObZIfY4f158QPUM8j6CQ7uMf1cz7jwrD9KtyEMwKyTAzlMERqOO5zPjjC97S+ZJ71K+ RxFGHLp1+YAbECVJPKTM5UPIM4rd6OGVP9atRRg3Sejgh814lrmvL1F8+OjklV6/zkaA 0fS+ktTZ50JJ5TW9LeNFWWnhzjfcqauGFm+7fOH0lWD2gQkm6gGXaPV5VxlhtAaSOx6r dritrVyHr8s1Q0QccRQzoOCiZk1JRhE6dgl57UHqdQAvN4eIxq2GY/AjW4dFFPuBlCWA 6zuw== X-Gm-Message-State: AOJu0YzT8cvtIwWIRNXEQhRqvmdGAzP9EH+u3MZZlzxGwHH7pOjzdzTo zyp1V/hVmViCahZdUAFaL5k3AInE3xc8nhg7t4oHT+oG30sa53MFbHCSB3ZO00j1ug== X-Gm-Gg: ASbGncthqxwKir2ls5plrB9vnG2Mhm3e9Mcmype4Vq2cTgavfs/cf+9/F0Lhn8j1lD9 DD/dXesMOHKgeP4WEm+2xsIckaPUqj2SoyVCga24l3lTFQyL2gLyMWfLwDAHsRE1aOigDMR0BEv SGjd7znV5q1r1YEjiDohhrKitjcWhHogTL7PucoNq17cSW+0IBLpHz28BTqM2vexhuOdXU+5fXl 1ZRc5WC+rbj3e3eAE+63AqQ3Bookn1Q5jkrTlQIn03bQqP6OS6+PfUjet1vb4OKJjYTWg== X-Google-Smtp-Source: AGHT+IEC4Db42XnRiuDt3gMNCO/QxxjAahGqvHSWnc/5lDFNEEI0+qyWGMRSEB54W41cbBtST4uAeQ== X-Received: by 2002:a17:907:3da8:b0:aae:ce4c:ca40 with SMTP id a640c23a62f3a-ab2ab740698mr2754510866b.32.1737024567176; Thu, 16 Jan 2025 02:49:27 -0800 (PST) Received: from localhost.localdomain ([154.118.34.84]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-ab2c9646be5sm901203966b.174.2025.01.16.02.49.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 02:49:26 -0800 (PST) From: Seyi Kuforiji To: git@vger.kernel.org Cc: ps@pks.im, phillip.wood@dunelm.org.uk, Seyi Kuforiji Subject: [PATCH 2/4] t/unit-tests: convert mem-pool test to use clar test framework Date: Thu, 16 Jan 2025 11:49:09 +0100 Message-ID: <20250116104911.77405-3-kuforiji98@gmail.com> X-Mailer: git-send-email 2.47.0.86.g15030f9556 In-Reply-To: <20250116104911.77405-1-kuforiji98@gmail.com> References: <20250116104911.77405-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. Following the consensus to convert the unit-tests scripts found in the t/unit-tests folder to clar driven by Patrick Steinhardt. 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 | 26 ++++++++++++++++++++++++++ 4 files changed, 28 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..36e31a3201 --- /dev/null +++ b/t/unit-tests/u-mem-pool.c @@ -0,0 +1,26 @@ +#include "unit-test.h" +#include "mem-pool.h" + +static void t_calloc_100(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) +{ + t_calloc_100(1024 * 1024); + +} + +void test_mem_pool__tiny_block(void) +{ + t_calloc_100(1); +} From patchwork Thu Jan 16 10:49:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seyi Kuforiji X-Patchwork-Id: 13941572 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 806EF19539F for ; Thu, 16 Jan 2025 10:49:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737024575; cv=none; b=QVTyy8beoNG/RyIpe3Lr4y1wnYhRJ3fBkAbSgNm4Jq/JgO/QjFjtpeF3zltod9UP549jdjEvCa7nNFN9i32Nfn5HmL7M75dPyNeZJM4Dm7nro2zxAFj0VLtJcpYCM3Ov/Jyf1mk9exBYzduHqiJv6WiWJY10iRV6eMkcSZlEkio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737024575; c=relaxed/simple; bh=DbPX6D12GxhdN3qzYg4/Vab3F26mD935zsUiOTG45/c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g15Y+Rg5VgmytZNoDrfWlkivMWkRgVcWtp28XtGEo2ZAtoOokJqm7QipgvNFLhV96+FZN4zAoDtprB67mH5ofM4R1sSDH3m6x1uYi835sBdMbcaMEXq0von1x3OzP8OnRSrP8y5ph3BJtloADaWumqWjLPLhSTEbxdtxpiHztEM= 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=R3A6DvPB; arc=none smtp.client-ip=209.85.208.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R3A6DvPB" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5d3f57582a2so3998405a12.1 for ; Thu, 16 Jan 2025 02:49:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737024571; x=1737629371; 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=EJvcLFKgmN73MRFm4SSLtPZUoW2jWicimY1MQGCFFvo=; b=R3A6DvPBhZAvcQU4u5EKgjDKdjFzxlzxnxk5r36U4rnu03gNBIMkcV8IHkLEWv8ItH ZIac50/DlmrFwIYj94N2yU4HMGX0+k2ILJ5uoL26R4B9Ft/3dZIsK4aPWjkg9Xv+i9ka 7YwkxsBgQj6I49YQuDQgfyg5ZIITNbnZVZusWWJStA7yOOKdy23H0xo3OfS3g2j4Iu9L l0+yAqOxazsQZV56qmH6GoK7u2N3ImnpiFxDeOSSUvQWLJO9Gg5PC4GWdZh2tP1vr7TE hFHHyt/MG0wXxMMpClvInxS7dDU1cS3B/JM/WI3FtZlj2E1YbZIez56ZP/RqPJdXQi9w LDKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737024571; x=1737629371; 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=EJvcLFKgmN73MRFm4SSLtPZUoW2jWicimY1MQGCFFvo=; b=O/OiphXe0njUbgM0h0U2aztZGa97OY1itDHh6I0QcsmovDqLY91i2OY32XBt/GIQQd ZvzQZ4KHZD47RxezqBxCtrPzyLBby71SAunfzcubE/niEVraRjqVp85crb949RZcZR9K JPZm69UoUf/W21ceaxT+kfKI15GtIZp0r7Br703LL9F1c/ImPnsG2l1ObQINXefKhTN0 eSED6FdqA4mfu7rf24JK6iMAYt9/0sdV1UL2ha6cgme2qNQBCVAV2PxT+r7ZKh5Qr6ey UTeQy5QV3zGU1JYMDFhPnbQL5RiaafqopIf2LYxk1ZgL0hCEQFUwcz6ItwpxJPeoXGeK GR2Q== X-Gm-Message-State: AOJu0YyQGcULhmGCW0TY+/zs5SlvX2mCGu2wPJMBzATKh0Mxm40jE3Z0 hJc6gbVFKb78fjgpLt+H2VM36Iloz/uBWGoIwAM5k0YbMeXXCJUMVS/AZOwT78ALFQ== X-Gm-Gg: ASbGncuQJ/KNggP4WtlcSbsVLehI1H4G1gnEYCp7FFWglKr+GWxu+t5MmqbYjIhMrAS B5by7IvsIPkDrLpuUskw+cwC67FEA+t4QxhFWSyRs1BOtTaSmnZTB2pJXbyNgGx1KBczqKgzqdl ZVfKC3+IirCkmobHgPeovZrNuYNB753J50AICR7f6IisM5ZaBH9iMvkBVwJxgPXgqP7rKCz4i3g VbeZW4Cm0q8Ak4ty8vpIWTeoOXH68gU0jf+UaZgd5h/R6K/7N68J8HT6rjXMqR8B5Mieg== X-Google-Smtp-Source: AGHT+IG7GWMlDGPK7Qx2Sj0jX0c7+kWIKUBHmpW85D+7TcSuVpX3//E32YC5SoRHIOzc+sUfjCfs/A== X-Received: by 2002:a17:906:f90b:b0:ab3:47cc:a7e0 with SMTP id a640c23a62f3a-ab36e35f4d5mr206728266b.13.1737024571377; Thu, 16 Jan 2025 02:49:31 -0800 (PST) Received: from localhost.localdomain ([154.118.34.84]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-ab2c9646be5sm901203966b.174.2025.01.16.02.49.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 02:49:30 -0800 (PST) From: Seyi Kuforiji To: git@vger.kernel.org Cc: ps@pks.im, phillip.wood@dunelm.org.uk, Seyi Kuforiji Subject: [PATCH 3/4] t/unit-tests: adapt priority queue test to use clar test framework Date: Thu, 16 Jan 2025 11:49:10 +0100 Message-ID: <20250116104911.77405-4-kuforiji98@gmail.com> X-Mailer: git-send-email 2.47.0.86.g15030f9556 In-Reply-To: <20250116104911.77405-1-kuforiji98@gmail.com> References: <20250116104911.77405-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. Following the consensus to convert the unit-tests scripts found in the t/unit-tests folder to clar driven by Patrick Steinhardt. Test functions are created as a standalone to test different cases. 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..d36a565e6f --- /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((size_t)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 10:49:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seyi Kuforiji X-Patchwork-Id: 13941573 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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 C11D51DE2DE for ; Thu, 16 Jan 2025 10:49:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737024579; cv=none; b=dy86Ys25nSjqWGPAPzMi/EYCvW+VnAtwzFL/mGZAnTnYehk17r5dmWMgBTJkWINVyFWraEd3jNVMTuxSwZZFfjR9qa/o3rJwuozkZMAkqOFOnvvDAT6fIgER5A2BiN5CZgyJ3D+9QRHxHEvboOnNlXwNKz5F94ax3CI4JXhEYPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737024579; c=relaxed/simple; bh=xZ7b30CTc5gSlyMKbvXC/YmtPa0PJEiX26wFnnXp8pM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mG5Y6b3KevhVVznPU8RTLWyGvC6ILDAipird4GR13WdVgMbGGQyBRyO+7AayhvAl85jGwoA5aoN64++G3h+mKtnXF3NX0nBloSv6Ukm9pAABnN/W4FWPR8ceK9WXxci1eRCO0y8OJ2+hFBqOPlHnskX2uef3MZeFCGvAiezsuV8= 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=gUbKsTbU; arc=none smtp.client-ip=209.85.218.42 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="gUbKsTbU" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-aa6c0d1833eso163773566b.1 for ; Thu, 16 Jan 2025 02:49:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737024576; x=1737629376; 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=WJHH7GrYBFM889FNKVErs4HRkv8yDSCyGi+3QA7/UeE=; b=gUbKsTbUj9OutcIDfYN/jvLjke9U38NBF3fqN6/uHgi/CDzKidjACYypbS42sinC+D QXhuxvoFWSOCw5FdqsA7K5hwFGkAdc4BtN3WUdQafdZizlaO9yfGMF0hW8yXuoN8iFLx a8jACIQuShU1831nvvwL1VKrCN6AkmeILwqaUoGcX+c2qeQJewMwXm6NoL+Yhggc8NV4 Wr8qLtmpx+LdUs2ls2WXQqBIGbRhFU0xr1DLb8T09o4Bed38CYzL1Dp66tGllKplRNsI fF5XFSdFEN/XS3OXy0pnnMHa7UzstzfNp7hYNYhX209t6Ryaf0KZw1oBrZdvXkie2LVg SItw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737024576; x=1737629376; 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=WJHH7GrYBFM889FNKVErs4HRkv8yDSCyGi+3QA7/UeE=; b=kJlgohRGRY0+a87OwBL+8ssR1q3ErT8c/bd99emC/cCzPyjsyEDdjIC9f6HhiHfZ7i n+QaShX/dwz1vLBah47A2yNcx12I1Uh3e9ip6pDaRX0KGVLfEKKeXmFeL4jH11UyePtr 3Y7mqEyi6rMU8QCqzyUgkcnvX1amYGClWEQ95tAamXYQLtyUMVV1uPaL7w4qR+/URPTC sWcN3uCBjgJrm96sQVvFXbjxPRMbJCK2aMlXCbkW7g6BpKcaZXUP1RRZ3pzPrNTPIcz9 noSa5iQRwqpKaDHoFvfJa+ho9t1O8hf0Yy2Z9ATf/d4qUTOSlVnY8VmW38DKud9ykf+h WEhA== X-Gm-Message-State: AOJu0YxAUhIDYnW/G85n//6tmBHA0E7txoW2Uu4u6sBSwxMdMQgDj9vG jUTEdJwYXJ9ye1LuylMHrQOz9k+khqNWHatAEZBzl1GoDX4rxTF6zHTtua/pLVFzRw== X-Gm-Gg: ASbGncsOATas3h8udrQq/HEIJoOngRkw106RgmonJ7tvnXDW5/WfHFJDG9T/oXZp9of ne3eb1XdLQA6f/8l9YO/W7cBL2Z7awC5K+2f2tZm3KvVlJ11Tg0+V/62ZZCL0H0DbBWdfeDdUba jBgriCRtn1NZyb8JdXjGiCgVDpGBjnHegbP32rLN2y80X8PoqqXbyCDuvYT0lXfZ4kLnBsp3xEc J4YuReJqCqui2xvZOp8ha7HDYouzd0tj057+gKGu3hCycufeSa4yqP3npv/UusbNnvY4g== X-Google-Smtp-Source: AGHT+IFpR+OvWl+h/tMQT7FB2Cl/wcaAyal/19BLclg3dmZC4r5Rb+2FWXM56/A5OKHxuy8yENrBxw== X-Received: by 2002:a17:907:2ce3:b0:ab2:f937:b3aa with SMTP id a640c23a62f3a-ab2f937b97emr1942593466b.56.1737024575595; Thu, 16 Jan 2025 02:49:35 -0800 (PST) Received: from localhost.localdomain ([154.118.34.84]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-ab2c9646be5sm901203966b.174.2025.01.16.02.49.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 02:49:35 -0800 (PST) From: Seyi Kuforiji To: git@vger.kernel.org Cc: ps@pks.im, phillip.wood@dunelm.org.uk, Seyi Kuforiji Subject: [PATCH 4/4] t/unit-tests: convert reftable tree test to use clar test framework Date: Thu, 16 Jan 2025 11:49:11 +0100 Message-ID: <20250116104911.77405-5-kuforiji98@gmail.com> X-Mailer: git-send-email 2.47.0.86.g15030f9556 In-Reply-To: <20250116104911.77405-1-kuforiji98@gmail.com> References: <20250116104911.77405-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. Following the consensus to convert the unit-tests scripts found in the t/unit-tests folder to clar driven by Patrick Steinhardt. 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); +}