From patchwork Wed May 29 06:55:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13677942 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 7A20415EFA7 for ; Wed, 29 May 2024 07:04:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966275; cv=none; b=PmZvGY3V091MKkdBufbXcxlBW5MZtylN+lXRxu2jWtD13ysGJ3q7atfJnzRzwQCFzneCfOoNduDY2e/04GXb8DNPBErvT5UBpP8KiDNfnOhtg/Yy0Hy0JIrvX3Yy0emserTOyhiK4gxpOtkADIZo/88+CX7+6AaNwmJ/r0OYeDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966275; c=relaxed/simple; bh=/+aGEYVCOMt3BDaTUudEV0KrKN/9yegm/HoSNkEWai0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OZ4v85Q8vGgMNK9+r3movdMrRxac/HAVVuJBGaSOC3A3O/6Msz37rcxXGOwkc2PRSJpmWcfCUsTNNBCECypcwgTNEelN6m1GH2RCTclEQyuwurK66YRY50I5cBL6THTKj7GMKyIKukqZUkbvBrKgjfeHzazuoFrYhhl+lYYC1aA= 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=VzuWYNl7; arc=none smtp.client-ip=209.85.210.179 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="VzuWYNl7" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-701b0b0be38so1401584b3a.0 for ; Wed, 29 May 2024 00:04:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716966273; x=1717571073; 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=tjntirJwz5N0hilgEj+W5M3lOc4eyCJjtBTq8ybzxHc=; b=VzuWYNl7ASIW/ULGkhccka+o8awBw3ep3p0Aw7VIhGh+gzfzFBr6dlbEuBjF29VA2/ /9MZ1PcbPKMO8bjaiCEvyq07uufs/1dtO5ZPhECbLSEBfeSBQE7ksPM62GocrACHL17j Qcjm/3LIrJnyR8DGLqe8aiaQFPBuIH09AehewBrvcUnH74xMwUK20xOI/iJbL5gaYyHM euxSmOTVGMxwPSTM5jD0P8wRFsoQ60hJ/tzYmSRCQBOzbclp4/XZLtKsqiPJXnXei/Eu hdks/1syrloTuXzJ2vxz4UhGLqO8SlcZpYaO/Qsm9aLyvfvff9XBCtu5Ecv4L7+yMP9Y 5kDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716966273; x=1717571073; 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=tjntirJwz5N0hilgEj+W5M3lOc4eyCJjtBTq8ybzxHc=; b=aVBi7EDkQS6PTE1jzXPZTMay3KU5leIcFhiM0rmqKp9aOZiY5rEP/fhSkTJ5GlZ4+3 Jl6HCmar1027ONhVcgQt20jd2U7BIoiyMy9G7UNxixVKiYEYGrNO963wx4bUssKAjhZG tnU2VJZa9T3DtRKPfwwG3VwsK32F5NsQzP5viHdmzQxCGSfUIWe4C/VjrxSkoBcPK6bc EckhHDlwhdk7GC1yg0fpLMkllMq17LqzZJE6ecaitDZDAyz1KTgTysjkzRtGLO3UL+Oo XRVVu88c+vk0Glhx/EEBMwx6lRGSgj/Bo1+jaGmv1GGeuThhNVwyLUsezLtK4XbIbCDf rUag== X-Gm-Message-State: AOJu0YwxAvRfp52TugNjkgxjYnW9JYj5EWIJWeErh1NopuPlp1uxZ3Ci A7+xvknQHWGGFLFCjZexndI1V/sKA/8lzRU2mRN1KPBWZgESICXOfimZioxwYxY= X-Google-Smtp-Source: AGHT+IG7J1RS6sEmSiviaT40PTh3sqH+Hd5jERVtOp8xlARzsKLmMDnBy6CHs4VEh9w/vPoP37FY4g== X-Received: by 2002:a05:6a00:8c11:b0:6e7:4abe:85a0 with SMTP id d2e1a72fcca58-6f8f3916015mr14997185b3a.14.1716966273307; Wed, 29 May 2024 00:04:33 -0700 (PDT) Received: from Ubuntu.. ([171.51.188.185]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-6f8fbd3ea03sm7473376b3a.39.2024.05.29.00.04.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 00:04:32 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [GSoC][PATCH v2 1/4] t: move reftable/basics_test.c to the unit testing framework Date: Wed, 29 May 2024 12:25:09 +0530 Message-ID: <20240529070341.4248-2-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240529070341.4248-1-chandrapratap3519@gmail.com> References: <--in-reply-to=20240528113856.8348-1-chandrapratap3519@gmail.com> <20240529070341.4248-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 reftable/basics_test.c exercise the functions defined in reftable/basics.{c, h}. Migrate reftable/basics_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-basics.c | 41 +++++++++---------- 3 files changed, 20 insertions(+), 24 deletions(-) rename reftable/basics_test.c => t/unit-tests/t-reftable-basics.c (65%) diff --git a/Makefile b/Makefile index 8f4432ae57..36188ca256 100644 --- a/Makefile +++ b/Makefile @@ -1337,6 +1337,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-basics UNIT_TEST_PROGRAMS += t-strbuf UNIT_TEST_PROGRAMS += t-trailer UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS)) @@ -2671,7 +2672,6 @@ REFTABLE_OBJS += reftable/stack.o REFTABLE_OBJS += reftable/tree.o REFTABLE_OBJS += reftable/writer.o -REFTABLE_TEST_OBJS += reftable/basics_test.o REFTABLE_TEST_OBJS += reftable/block_test.o REFTABLE_TEST_OBJS += reftable/dump.o REFTABLE_TEST_OBJS += reftable/merged_test.o diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index bae731669c..9160bc5da6 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -5,7 +5,6 @@ int cmd__reftable(int argc, const char **argv) { /* test from simple to complex. */ - basics_test_main(argc, argv); record_test_main(argc, argv); block_test_main(argc, argv); tree_test_main(argc, argv); diff --git a/reftable/basics_test.c b/t/unit-tests/t-reftable-basics.c similarity index 65% rename from reftable/basics_test.c rename to t/unit-tests/t-reftable-basics.c index 997c4d9e01..99e6c89120 100644 --- a/reftable/basics_test.c +++ b/t/unit-tests/t-reftable-basics.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 "basics.h" -#include "test_framework.h" -#include "reftable-tests.h" +#include "test-lib.h" +#include "reftable/basics.h" struct integer_needle_lesseq_args { int needle; @@ -42,9 +39,8 @@ static void test_binsearch(void) {11, 5}, {9000, 5}, }; - size_t i = 0; - for (i = 0; i < ARRAY_SIZE(testcases); i++) { + for (size_t i = 0; i < ARRAY_SIZE(testcases); i++) { struct integer_needle_lesseq_args args = { .haystack = haystack, .needle = testcases[i].needle, @@ -52,14 +48,14 @@ static void test_binsearch(void) size_t idx; idx = binsearch(ARRAY_SIZE(haystack), &integer_needle_lesseq, &args); - EXPECT(idx == testcases[i].expected_idx); + check_int(idx, ==, testcases[i].expected_idx); } } static void test_names_length(void) { char *a[] = { "a", "b", NULL }; - EXPECT(names_length(a) == 2); + check_int(names_length(a), ==, 2); } static void test_parse_names_normal(void) @@ -67,9 +63,9 @@ static void test_parse_names_normal(void) char in[] = "a\nb\n"; char **out = NULL; parse_names(in, strlen(in), &out); - EXPECT(!strcmp(out[0], "a")); - EXPECT(!strcmp(out[1], "b")); - EXPECT(!out[2]); + check_str(out[0], "a"); + check_str(out[1], "b"); + check(!out[2]); free_names(out); } @@ -78,8 +74,8 @@ static void test_parse_names_drop_empty(void) char in[] = "a\n\n"; char **out = NULL; parse_names(in, strlen(in), &out); - EXPECT(!strcmp(out[0], "a")); - EXPECT(!out[1]); + check_str(out[0], "a"); + check(!out[1]); free_names(out); } @@ -89,17 +85,18 @@ static void test_common_prefix(void) struct strbuf s2 = STRBUF_INIT; strbuf_addstr(&s1, "abcdef"); strbuf_addstr(&s2, "abc"); - EXPECT(common_prefix_size(&s1, &s2) == 3); + check_int(common_prefix_size(&s1, &s2), ==, 3); strbuf_release(&s1); strbuf_release(&s2); } -int basics_test_main(int argc, const char *argv[]) +int cmd_main(int argc, const char *argv[]) { - RUN_TEST(test_common_prefix); - RUN_TEST(test_parse_names_normal); - RUN_TEST(test_parse_names_drop_empty); - RUN_TEST(test_binsearch); - RUN_TEST(test_names_length); - return 0; + TEST(test_common_prefix(), "common_prefix_size works"); + TEST(test_parse_names_normal(), "parse_names works for basic input"); + TEST(test_parse_names_drop_empty(), "parse_names drops empty string"); + TEST(test_binsearch(), "binary search with binsearch works"); + TEST(test_names_length(), "names_length retuns size of a NULL-terminated string array"); + + return test_done(); } From patchwork Wed May 29 06:55:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13677943 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9EEB1667C2 for ; Wed, 29 May 2024 07:04:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966278; cv=none; b=ea1s8LoLMkbeklllX3X2rJCTopqgRW+R/iqljrjpRZti25S5LkYw1/2tIbXB0ZCJF+DYaMQhaUda3qM3AKEZl3DIQT7qCw9dxG17tmdXZXFRRFiPvxrWPKaAZxIHqdSMFv8muml5fEVVxaVNGL1V3xWGwFQgKpaIE1MKhsnMk54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966278; c=relaxed/simple; bh=xg3BzUGxdqlLQJCI2sza5JvZPdESVZ31Y6f7GLMd+4k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cHYphge1bSYGWSzFBaKYMZa8qi+4ADQf8/xncUXSpXCWu2dhBADjsWeYCzpmjO/i5EJGTbECTq+oXlweNU87eV2yW+GMS/Fcd/FQ6IO09fE5gKUEe3MxQcIS6R9m/6wGW6KrtluFpbLlZERHpoflePtu37yeCnvd1K6++Iip4qM= 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=DreEtIG/; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DreEtIG/" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-701ae8698d8so1378630b3a.0 for ; Wed, 29 May 2024 00:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716966276; x=1717571076; 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=wr8ozju04b/fENvmFIgkx7p6m+nNn/O94ghV0XkCMIc=; b=DreEtIG/RjzdZkmbY+ANWLdXmczfTyWBj4XbAZErfGh+Qm16bUdp3hU2q+OtYEEoDs iFZE+PuBNckQAddZ3gXRZQhNmBRJ1Dj/BNI4iRor8XAy6Y4eTlkSfUvLd/jCZ+CBtf0r NUtUVi+khnbuFTyzyASF1MLJFmMGLIhI+Ct7aJmaWsa9F6D28B1E2W9HIRfE3oaYfbzo 5b1tPBl8G5r5a4b2aMNcGgCQvhbwmyxaf0ZhoFZeUnFAQ1lKAWckKSb/J88noG/bwcV2 qrUxVYeXYq0ljf3fKdkTeAgQGflkkJ61vkqmZbmHHccvHztJI8GSzm8bNOpp2taJqpsN j81w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716966276; x=1717571076; 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=wr8ozju04b/fENvmFIgkx7p6m+nNn/O94ghV0XkCMIc=; b=WdJPWSuVLKCjzARLo6RettiyJ23VLH66nK/i9bVViyVHoSu35w1m2NdOLlSDY9zzKT G0KpF481Jyj4d/z2mYuXDRIlPoOsWHtQ8fMQSD75vlnIpYQMHXFNvJjVTLo1d7Cv8YCg nP0o2I6g+F1r0NAR37JBYLYgulhTKWF0HF0NySGJItpieMlIho5yyOD80ZbOB4Xi2r88 93fwbbKjIjNX+tbKIPw+lb1uXMJlUW8MF3jFFttODdWrf9j2zQVbT6bMeJOTphvzkDpR CCOIIJY31ePapYW2bNehgHObPqiVFSFfbxHVBfXPMbK5oMUZlLpWy8qbi/sPEKd1YqAE 5zyA== X-Gm-Message-State: AOJu0YwS2vEd1PPAGiW3/CUnFDMV3ai4p0j0zHBBtLK3gUNuplTglE6g MKpXSqVkbU6vFBGGqctkV8ZyUXIbUJQQicMCFOl7mNANJGvR/DbgYfsISKO2yvc= X-Google-Smtp-Source: AGHT+IEDxy18WfNUqPKiKLMndHGcbLpzx4bPQ9f1gKFlGxOKBp5tRlW94JX8ymdSABJbhVMzeWZx6A== X-Received: by 2002:a05:6a00:28cd:b0:6ea:c2a2:5648 with SMTP id d2e1a72fcca58-6f8f2c3f9b4mr16496700b3a.3.1716966275762; Wed, 29 May 2024 00:04:35 -0700 (PDT) Received: from Ubuntu.. ([171.51.188.185]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-6f8fbd3ea03sm7473376b3a.39.2024.05.29.00.04.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 00:04:35 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [GSoC][PATCH v2 2/4] t: move tests from reftable/stack_test.c to the new unit test Date: Wed, 29 May 2024 12:25:10 +0530 Message-ID: <20240529070341.4248-3-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240529070341.4248-1-chandrapratap3519@gmail.com> References: <--in-reply-to=20240528113856.8348-1-chandrapratap3519@gmail.com> <20240529070341.4248-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 parse_names() and names_equal() are functions defined in reftable/basics.{c, h}. Move the tests for these functions from reftable/stack_test.c to the newly ported test. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- reftable/stack_test.c | 25 ------------------------- t/unit-tests/t-reftable-basics.c | 25 ++++++++++++++++++++++--- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/reftable/stack_test.c b/reftable/stack_test.c index 7889f818d1..6f6af11e53 100644 --- a/reftable/stack_test.c +++ b/reftable/stack_test.c @@ -102,29 +102,6 @@ static void test_read_file(void) (void) remove(fn); } -static void test_parse_names(void) -{ - char buf[] = "line\n"; - char **names = NULL; - parse_names(buf, strlen(buf), &names); - - EXPECT(NULL != names[0]); - EXPECT(0 == strcmp(names[0], "line")); - EXPECT(NULL == names[1]); - free_names(names); -} - -static void test_names_equal(void) -{ - char *a[] = { "a", "b", "c", NULL }; - char *b[] = { "a", "b", "d", NULL }; - char *c[] = { "a", "b", NULL }; - - EXPECT(names_equal(a, a)); - EXPECT(!names_equal(a, b)); - EXPECT(!names_equal(a, c)); -} - static int write_test_ref(struct reftable_writer *wr, void *arg) { struct reftable_ref_record *ref = arg; @@ -1048,8 +1025,6 @@ static void test_reftable_stack_compaction_concurrent_clean(void) int stack_test_main(int argc, const char *argv[]) { RUN_TEST(test_empty_add); - RUN_TEST(test_names_equal); - RUN_TEST(test_parse_names); RUN_TEST(test_read_file); RUN_TEST(test_reflog_expire); RUN_TEST(test_reftable_stack_add); diff --git a/t/unit-tests/t-reftable-basics.c b/t/unit-tests/t-reftable-basics.c index 99e6c89120..55fcff12d9 100644 --- a/t/unit-tests/t-reftable-basics.c +++ b/t/unit-tests/t-reftable-basics.c @@ -58,14 +58,32 @@ static void test_names_length(void) check_int(names_length(a), ==, 2); } +static void test_names_equal(void) +{ + char *a[] = { "a", "b", "c", NULL }; + char *b[] = { "a", "b", "d", NULL }; + char *c[] = { "a", "b", NULL }; + + check(names_equal(a, a)); + check(!names_equal(a, b)); + check(!names_equal(a, c)); +} + static void test_parse_names_normal(void) { - char in[] = "a\nb\n"; + char in1[] = "line\n"; + char in2[] = "a\nb\nc"; char **out = NULL; - parse_names(in, strlen(in), &out); + parse_names(in1, strlen(in1), &out); + check_str(out[0], "line"); + check(!out[1]); + free_names(out); + + parse_names(in2, strlen(in2), &out); check_str(out[0], "a"); check_str(out[1], "b"); - check(!out[2]); + check_str(out[2], "c"); + check(!out[3]); free_names(out); } @@ -97,6 +115,7 @@ int cmd_main(int argc, const char *argv[]) TEST(test_parse_names_drop_empty(), "parse_names drops empty string"); TEST(test_binsearch(), "binary search with binsearch works"); TEST(test_names_length(), "names_length retuns size of a NULL-terminated string array"); + TEST(test_names_equal(), "names_equal compares NULL-terminated string arrays"); return test_done(); } From patchwork Wed May 29 06:55:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13677944 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.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 687051667EC for ; Wed, 29 May 2024 07:04:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966282; cv=none; b=fQdkq+ZHiUc2fsbDx8fP4zMXNkphRBQj18oI03cta0rIk4dyzcS0Owxw4HEECpQ+pzbxDsChnQzIWGwVUI3v7oSDmkW2rD2YfHPaH9fJX+MO3v2TorsCzETxZqB6WpJ/jLKLW8urDVjWIZFqk0G0hV3Pe6wYX5vHM9dJKHHDJ9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966282; c=relaxed/simple; bh=imdnwdQUYDNWkCiEh4mYuhPwizZLaM7MOlyvKNKB1vw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pwmTEryb5yv/1rX5+eCLuvrhdrhl5qxfMzuvV9tDVr1x21lDxfUDJmXjphuqVoYRtjMLN0ixL++I1+AwqrBq3vINn3xqmsUfTjVeFJmhy/RZ95ljpIJ++r2K4X1/FuatA6ZIl26bd6HWKkbj6obctMPrfT91Q0i9GUcnnT1AWqM= 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=m4S1Snc8; arc=none smtp.client-ip=209.85.210.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="m4S1Snc8" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-6f8eba8f25eso1408769b3a.3 for ; Wed, 29 May 2024 00:04:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716966278; x=1717571078; 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=wJZL6qpmxYDLfog5CD0nPWSmmHVEn+XkBlmUnCocPwc=; b=m4S1Snc84afkEba1BnwbJMIRVYlPQiBxuhBf7733zO4PZPEPzjXqPGYICQfC+82pqJ B4QFF7OQvspcAMBoV/28pjI7s79tXeXa4OZnUCXxOFhxm5UZS87WFwChagymQUa5br86 1yMvQy/PVtlb1e5ug/yE1ncCD5sAeEYJdF4W+5dUpW3Nwag+Qx3neGEWCOdo0DKDYcUx 7eRmh5GAX/exWPj7GLNyZNKHcgu6WdKaS/ApKs+Vl25jhZaoYaQXfpZCypCmxBJY/pTH wDSlP5pxLbsVm9GhFCfNlo5r3qittlLgqMzceXoWPeSnWeJa3/PbehP0K63z/GZR7VOs nnWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716966278; x=1717571078; 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=wJZL6qpmxYDLfog5CD0nPWSmmHVEn+XkBlmUnCocPwc=; b=I4gRio+GMZ0CDC5uJAEF3X6PyGEkKhXhk+PyH3UUsYt7oG8bf2d623+NbaN9GgfReL 3Ylz1oIydBkarpmYmUT2vO2Ro26VAfBZSB0Frsis41rGxearqf20UT/u0msuPyIF8HBQ YIrfHLm2MPZIsgYYEVoXH1HCVNXxlk2NNgqgRwk3kYRgw9SHy22ZXdVb1nXxPSdoblNE 07TUmLGwTmcPCQMoLRy1oHcHOxRx0aGOyRo/4XLGguYz832b3J0ULm82hVcHx9BL1wXU bMb1NwOg2es6x8J6cTFfvJ2CyhBPpUQwkITDSuFSmDD9zHxbTXk/p72ercNQZjKg4ZdP i87w== X-Gm-Message-State: AOJu0YzN3h97wQUqV1IvxX+uauhK31AjrmtC7V9ECjc7nzBGFgDbcM1f dJbgS/zyIOxiR9zuc3RVRZAqTPjFD78kjwQ9WcGabJTt4GLHmNp2pmrLhn850vo= X-Google-Smtp-Source: AGHT+IGmWgtCDtM/8HbWkw/NdS00lb24420BAxUPeeDkITzxNvtbgfAJiHVQfT4bemtIvwPuixRTPw== X-Received: by 2002:aa7:9316:0:b0:6f8:b990:aafb with SMTP id d2e1a72fcca58-6f8f2b48beamr14096139b3a.7.1716966278380; Wed, 29 May 2024 00:04:38 -0700 (PDT) Received: from Ubuntu.. ([171.51.188.185]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-6f8fbd3ea03sm7473376b3a.39.2024.05.29.00.04.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 00:04:37 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [GSoC][PATCH v2 3/4] t: move tests from reftable/record_test.c to the new unit test Date: Wed, 29 May 2024 12:25:11 +0530 Message-ID: <20240529070341.4248-4-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240529070341.4248-1-chandrapratap3519@gmail.com> References: <--in-reply-to=20240528113856.8348-1-chandrapratap3519@gmail.com> <20240529070341.4248-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 common_prefix_size(), get_be24() and put_be24() are functions defined in reftable/basics.{c, h}. Move the tests for these functions from reftable/record_test.c to the newly ported test. Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- reftable/record_test.c | 37 ----------------------------- t/unit-tests/t-reftable-basics.c | 40 ++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 44 deletions(-) diff --git a/reftable/record_test.c b/reftable/record_test.c index c158ee79ff..58290bdba3 100644 --- a/reftable/record_test.c +++ b/reftable/record_test.c @@ -64,31 +64,6 @@ static void test_varint_roundtrip(void) } } -static void test_common_prefix(void) -{ - struct { - const char *a, *b; - int want; - } cases[] = { - { "abc", "ab", 2 }, - { "", "abc", 0 }, - { "abc", "abd", 2 }, - { "abc", "pqr", 0 }, - }; - - int i = 0; - for (i = 0; i < ARRAY_SIZE(cases); i++) { - struct strbuf a = STRBUF_INIT; - struct strbuf b = STRBUF_INIT; - strbuf_addstr(&a, cases[i].a); - strbuf_addstr(&b, cases[i].b); - EXPECT(common_prefix_size(&a, &b) == cases[i].want); - - strbuf_release(&a); - strbuf_release(&b); - } -} - static void set_hash(uint8_t *h, int j) { int i = 0; @@ -258,16 +233,6 @@ static void test_reftable_log_record_roundtrip(void) strbuf_release(&scratch); } -static void test_u24_roundtrip(void) -{ - uint32_t in = 0x112233; - uint8_t dest[3]; - uint32_t out; - put_be24(dest, in); - out = get_be24(dest); - EXPECT(in == out); -} - static void test_key_roundtrip(void) { uint8_t buffer[1024] = { 0 }; @@ -411,9 +376,7 @@ int record_test_main(int argc, const char *argv[]) RUN_TEST(test_reftable_ref_record_roundtrip); RUN_TEST(test_varint_roundtrip); RUN_TEST(test_key_roundtrip); - RUN_TEST(test_common_prefix); RUN_TEST(test_reftable_obj_record_roundtrip); RUN_TEST(test_reftable_index_record_roundtrip); - RUN_TEST(test_u24_roundtrip); return 0; } diff --git a/t/unit-tests/t-reftable-basics.c b/t/unit-tests/t-reftable-basics.c index 55fcff12d9..b02ca02040 100644 --- a/t/unit-tests/t-reftable-basics.c +++ b/t/unit-tests/t-reftable-basics.c @@ -99,13 +99,38 @@ static void test_parse_names_drop_empty(void) static void test_common_prefix(void) { - struct strbuf s1 = STRBUF_INIT; - struct strbuf s2 = STRBUF_INIT; - strbuf_addstr(&s1, "abcdef"); - strbuf_addstr(&s2, "abc"); - check_int(common_prefix_size(&s1, &s2), ==, 3); - strbuf_release(&s1); - strbuf_release(&s2); + struct strbuf a = STRBUF_INIT; + struct strbuf b = STRBUF_INIT; + struct { + const char *a, *b; + int want; + } cases[] = { + {"abcdef", "abc", 3}, + { "abc", "ab", 2 }, + { "", "abc", 0 }, + { "abc", "abd", 2 }, + { "abc", "pqr", 0 }, + }; + + for (size_t i = 0; i < ARRAY_SIZE(cases); i++) { + strbuf_addstr(&a, cases[i].a); + strbuf_addstr(&b, cases[i].b); + check_int(common_prefix_size(&a, &b), ==, cases[i].want); + strbuf_reset(&a); + strbuf_reset(&b); + } + strbuf_release(&a); + strbuf_release(&b); +} + +static void test_u24_roundtrip(void) +{ + uint32_t in = 0x112233; + uint8_t dest[3]; + uint32_t out; + put_be24(dest, in); + out = get_be24(dest); + check_int(in, ==, out); } int cmd_main(int argc, const char *argv[]) @@ -116,6 +141,7 @@ int cmd_main(int argc, const char *argv[]) TEST(test_binsearch(), "binary search with binsearch works"); TEST(test_names_length(), "names_length retuns size of a NULL-terminated string array"); TEST(test_names_equal(), "names_equal compares NULL-terminated string arrays"); + TEST(test_u24_roundtrip(), "put_be24 and get_be24 work"); return test_done(); } From patchwork Wed May 29 06:55:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Pratap X-Patchwork-Id: 13677945 Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53D9A16132F for ; Wed, 29 May 2024 07:04:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966283; cv=none; b=NZI03Ew4E56P8/Viji9a0lzgeGaQSe035+VEebtD7wnYZXQzBmrU2I1GAVaL2agVyE2fAJI3eBjL1wpESdbLeKUBJBoTZUL7WRrxWTwhK52/tt0PF6zOeckqnC3bceFaxk6yIt3e1I6oJc2RbAj1hk51g15JRul8Am87w7aWTI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966283; c=relaxed/simple; bh=kSNssLn5S6lGUu4EoqYl362AzN0Z9SLkClAQ2miicgU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W/qrk1+02BPFbSwGMSgoTfQcKLVLFAf/QqxcozY8pmtKMN8ld3rp9okJRjw2Jeu6AnORYyDHm4zT+K774kn6/3sBiJQbqxExrF2bR1kiECkVT8oZEOZ2w/YceUM9X+VabV8ryLc07KNhQ6/mk9piPevoStQMOSmGqFG11imS3yQ= 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=KBEgo1xS; arc=none smtp.client-ip=209.85.167.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KBEgo1xS" Received: by mail-oi1-f171.google.com with SMTP id 5614622812f47-3d1bdefedc0so880609b6e.1 for ; Wed, 29 May 2024 00:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716966281; x=1717571081; 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=++G2t6HsCRl/XSEBFC/36t17LGbY11tjVUCaSDLrOKM=; b=KBEgo1xS4XOxGUV04HKtFScJ3mLFM5TAAeTaWcELIvSQBM4dYy9P/2LebOWglYJ5mz SZaYQ0PlNUkdlOFEY6EmWJAZhR/9F/A6O2xTjl5xZ6u/DKsAhaV7sD7nbu4TEtQD9LqN 9DCAA4tOoWAx2h5agzPsW2OMuksILETg7LnS6zcAJt1cPjlsCPdRw2CTnrX20kfXNstN K3JkbtJSPUfSctsoXiw5tQq7MOVpdot1rLLeuzbNB/31WO8GyvQBdZhS3HUNW0fcNcdM 4xIjFGvTkMinmqB1INPUoH8El6aQknYCX1Viur8NmRbr8vVXL8QkdCxPS838PZS3Xw4G gAKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716966281; x=1717571081; 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=++G2t6HsCRl/XSEBFC/36t17LGbY11tjVUCaSDLrOKM=; b=sKA5c5vM8m8FFU7hlC2nl4dlscMEO5uPVdYWjpDi3z8lAbo19nQCDDKYPGHEQt4pju NMvZNrn9P6oOdqfg3i7Lm+r877D9pwp6hhaTlyPjFJJhMt2GSVrddBgtrNGK0ZoQ+gy8 XTMFy42Ry6JH5gMMrWEeJTVs7PU7vNnI0FskBBo4//FQLqZ5M92m/kN3X7ikR2U8p7X+ kY4YhF651olG89g8h/24eH4icse0Z/bEI4zBVSV6Jz/h491DloLG6k7pjVaCkZ5LNKGg n+NWEpAnTHg682SgKdR5LT4lLfJCUS22Tk2dK1rg3wRScGsKaYoYIVlqn6py2xuoXxok rs6w== X-Gm-Message-State: AOJu0YxV61ys1a5wMhOxBaDgmIYHYVtyVKJT2xrpbErrrsGifbOlpwVP ATneP85BUQ0f+mFU+eih27fopZ3rtEw4wluf0uiStN9FBG4ZXxSQ3pRd8kI7NC8= X-Google-Smtp-Source: AGHT+IHsvyN+udsgbj6J6OE0jvVIEjFsKW+qGmcl8cLbg2r+l3qdPr8Ovq7JlwPWV8K1hRmNsU6iMg== X-Received: by 2002:a05:6808:1510:b0:3c3:de8e:5411 with SMTP id 5614622812f47-3d1a7646fb3mr18636353b6e.38.1716966280846; Wed, 29 May 2024 00:04:40 -0700 (PDT) Received: from Ubuntu.. ([171.51.188.185]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-6f8fbd3ea03sm7473376b3a.39.2024.05.29.00.04.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 00:04:40 -0700 (PDT) From: Chandra Pratap To: git@vger.kernel.org Cc: Chandra Pratap , Patrick Steinhardt , Christian Couder Subject: [GSoC][PATCH v2 4/4] t: add test for put_be16() and improve test-case for parse_names() Date: Wed, 29 May 2024 12:25:12 +0530 Message-ID: <20240529070341.4248-5-chandrapratap3519@gmail.com> X-Mailer: git-send-email 2.45.GIT In-Reply-To: <20240529070341.4248-1-chandrapratap3519@gmail.com> References: <--in-reply-to=20240528113856.8348-1-chandrapratap3519@gmail.com> <20240529070341.4248-1-chandrapratap3519@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 put_be16() is a function defined in reftable/basics.{c, h} for which there are no tests in the current setup. Add a test for the same and improve the existing test-case for parse_names(). Mentored-by: Patrick Steinhardt Mentored-by: Christian Couder Signed-off-by: Chandra Pratap --- t/unit-tests/t-reftable-basics.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/t/unit-tests/t-reftable-basics.c b/t/unit-tests/t-reftable-basics.c index b02ca02040..8372faec8c 100644 --- a/t/unit-tests/t-reftable-basics.c +++ b/t/unit-tests/t-reftable-basics.c @@ -89,11 +89,13 @@ static void test_parse_names_normal(void) static void test_parse_names_drop_empty(void) { - char in[] = "a\n\n"; + char in[] = "a\n\nb\n"; char **out = NULL; parse_names(in, strlen(in), &out); check_str(out[0], "a"); - check(!out[1]); + /* simply '\n' should be dropped as empty string */ + check_str(out[1], "b"); + check(!out[2]); free_names(out); } @@ -123,14 +125,20 @@ static void test_common_prefix(void) strbuf_release(&b); } -static void test_u24_roundtrip(void) +static void test_be_roundtrip(void) { uint32_t in = 0x112233; uint8_t dest[3]; uint32_t out; + /* test put_be24 and get_be24 roundtrip */ put_be24(dest, in); out = get_be24(dest); check_int(in, ==, out); + /* test put_be16 and get_be16 roundtrip */ + in = 0xfef1; + put_be16(dest, in); + out = get_be16(dest); + check_int(in, ==, out); } int cmd_main(int argc, const char *argv[]) @@ -141,7 +149,7 @@ int cmd_main(int argc, const char *argv[]) TEST(test_binsearch(), "binary search with binsearch works"); TEST(test_names_length(), "names_length retuns size of a NULL-terminated string array"); TEST(test_names_equal(), "names_equal compares NULL-terminated string arrays"); - TEST(test_u24_roundtrip(), "put_be24 and get_be24 work"); + TEST(test_be_roundtrip(), "put_be24, get_be24 and put_be16 work"); return test_done(); }