From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS54825 147.75.48.0/24 X-Spam-Status: No, score=-3.1 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [147.75.48.161]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id C25831F451 for ; Wed, 17 Jan 2024 21:52:33 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; unprotected) header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=sasl header.b=DfKZ7pgu; dkim-atps=neutral Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 55FF2B2300F for ; Wed, 17 Jan 2024 21:52:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF9282562F; Wed, 17 Jan 2024 21:52:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="DfKZ7pgu" Received: from pb-smtp1.pobox.com (pb-smtp1.pobox.com [64.147.108.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 076BC2556C for ; Wed, 17 Jan 2024 21:52:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.108.70 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705528343; cv=none; b=fOfFNLCYeMt9rXVrnEfpdmgsgT7YF1BYkR1ASRT4bmc4qW+fDRIrNcpeRn2ZRJ6LIqrbY8GCJQTZJJtZD+6PU92GJOaq5H/QCYeB2E+MrD++CaCGs3HPngrfFRwAtGFNEEIfriNg6DmagU+kcCG44HCIsRRky2iskmIqSv1C+Do= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705528343; c=relaxed/simple; bh=KwctIMwsN1zUtYShHS/nUVsI65CkXGsAQfq7i8/Ae1E=; h=Received:DKIM-Signature:Received:Received:From:To:Cc:Subject: In-Reply-To:References:Date:Message-ID:User-Agent:MIME-Version: Content-Type:X-Pobox-Relay-ID; b=CksaCqbsOjtwJgYRLKca/GCy6CczyRPRw9HLVcHJvcaj1Jffz52HTc5tyonshEMFtBEkm/XXUGPax/1VaceQ2jaFMhQFJpLJo4zCraceJXGMtdeNTLoG2tqX2i2Q4qCQvnNl//GrO8nvpTeGXrkdYrtAJefDqI/VXNYLc+18HZw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=DfKZ7pgu; arc=none smtp.client-ip=64.147.108.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 64AE31C236E; Wed, 17 Jan 2024 16:52:15 -0500 (EST) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:in-reply-to:references:date:message-id:mime-version :content-type; s=sasl; bh=KwctIMwsN1zUtYShHS/nUVsI65CkXGsAQfq7i8 /Ae1E=; b=DfKZ7pguud+bL0xRM3h6qzEuvJo2Pd4Ve8514tnmq7osKSiIaHwc7+ 6dyOYSyoEkdgoSeIuokPBZVJpR0lIMczuY0D3novSZXMZSy0koszIz8uKLuZrTzZ NS4ULiFuYTGug/uvZL/r4VIJfqWlylYrCr8uFAwns6J4GKhXniUlM= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 5B98D1C236D; Wed, 17 Jan 2024 16:52:15 -0500 (EST) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [34.125.200.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id C131E1C236C; Wed, 17 Jan 2024 16:52:14 -0500 (EST) (envelope-from junio@pobox.com) From: Junio C Hamano To: "Chandra Pratap via GitGitGadget" Cc: git@vger.kernel.org, Chandra Pratap , Chandra Pratap Subject: Re: [PATCH v3] tests: move t0009-prio-queue.sh to the new unit testing framework In-Reply-To: (Chandra Pratap via GitGitGadget's message of "Wed, 17 Jan 2024 14:38:23 +0000") References: Date: Wed, 17 Jan 2024 13:52:13 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: AD02864C-B582-11EE-8C2D-78DCEB2EC81B-77302942!pb-smtp1.pobox.com "Chandra Pratap via GitGitGadget" writes: > +static int test_prio_queue(int *input, int *result) > +{ > + struct prio_queue pq = { intcmp }; > + int i = 0; > + > + while (*input) { > + int *val = input++; > + void *peek, *get; > + switch(*val) { Ah, this one is a bit tricky. I would have expected that we can make val a pure integer, but because we need to give the address of the element to be placed in the queue, not the value to be placed as an element in the queue, to prio_queue_put(), we would need the pointer. I wonder if writing this as a more conventional for(;;) loop would make it easier to handle, i.e. int val, i; for (i = 0; (val = *input); input++) { switch (val) { case ...: ... default: prio_queue_put(&pq, input); break; } } > +... > + default: > + prio_queue_put(&pq, val); > + break; > + } > + } > + clear_prio_queue(&pq); > + return 0; > +} > +#define TEST_INPUT(INPUT, EXPECTED, name) \ > + static void test_##name(void) \ > +{ \ > + int input[] = {INPUT}; \ I think I missed this myself in my review the last round, but we need the sentinel value 0 at the end, i.e., int input[] = {INPUT, 0}; because the test_prio_queue() loops "while (*input)". Otherwise the loop would not terminate. > + int expected[] = {EXPECTED}; \ > + int result[ARRAY_SIZE(expected)]; \ These arrays are correct. > + test_prio_queue(input, result); \ > + check(!memcmp(expected, result, sizeof(expected))); \ So is this check. > +} > + > +TEST_INPUT(BASIC_INPUT, BASIC_EXPECTED, basic) > +TEST_INPUT(MIXED_PUT_GET_INPUT, MIXED_PUT_GET_EXPECTED, mixed) > +TEST_INPUT(EMPTY_QUEUE_INPUT, EMPTY_QUEUE_EXPECTED, empty) > +TEST_INPUT(STACK_INPUT, STACK_EXPECTED, stack) > +TEST_INPUT(REVERSE_STACK_INPUT, REVERSE_STACK_EXPECTED, reverse) > + > +int cmd_main(int argc, const char **argv) > +{ > + TEST(test_basic(), "prio-queue works for basic input"); > + TEST(test_mixed(), "prio-queue works for mixed put & get commands"); > + TEST(test_empty(), "prio-queue works when queue is empty"); > + TEST(test_stack(), "prio-queue works when used as a LIFO stack"); > + TEST(test_reverse(), "prio-queue works when LIFO stack is reversed"); > + > + return test_done(); > +} Other than that, looking good. Thanks.