From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CAF154577B; Fri, 9 Aug 2024 18:31:41 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 97B5342EE4; Fri, 9 Aug 2024 18:31:41 +0200 (CEST) Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by mails.dpdk.org (Postfix) with ESMTP id 8EF6D42DE9 for ; Fri, 9 Aug 2024 18:31:40 +0200 (CEST) Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1fc5296e214so23141435ad.0 for ; Fri, 09 Aug 2024 09:31:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1723221099; x=1723825899; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=0urqLA+OU6Mv+UID8NAlAmg+wFFqRsQ5jQm1FrPNmD8=; b=cpVzhXLQrQYkqcBd9Hz5j5ZshabhWBDuEobWaulRGrd/8bIO41E/RuUZMZKU8E8ybs dSYXSOIIjOI6pBqst90mdwgBvZD7MYNKWzTqqWvh4LeQLJo6WGQfAyNItxKu0flHsl7T Q6s/fiVEekXxPDmqXty7CB/fBKo1U6WAeun8YrB3NDeOZplafigZSB80U/DJvpWhhdLk 1hPnl6hMdsfPdz7kOrsfJXRl+Xiy32U/Sp+Vnut54Vcq6K7INqnx6XS5W+VOQcxmUbcp PT3ioTseyPgO+Lvx9D1Gub6Aw/FykrOpbZCs1pcH5AFlo9bYHi0HqcBEQ5rw9cpslJvY YzAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723221099; x=1723825899; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0urqLA+OU6Mv+UID8NAlAmg+wFFqRsQ5jQm1FrPNmD8=; b=nB/SyT1vhUCJ7Ky5Fydi959YELiVyb3amzxOOQ49jD9ySsP70kUqj3i3LCnJAp5dIM 2hf7+vmSBnTBaES86OJSSffwmY5tJQK/ucuR+2VbkN87hwjIyPSPYvImy5j0wGjJWQEL IaEt4vrNnH4CVAyNdG42Gyx50zxIZgjE1f+3MfdJgOu77v0NNSFRzrodbl3BRSWSGDQi LF2/IseoiEZXaj2X4QIiI8YSkriDMtPsUbNn+XFPVJVYQQqXvbobdJeXDAxmxsbfzBkC kDCNbH76BLtjBM0JUjr24FqI0EDapL2eNV0bskWPEf6w1MChhtJeGKZVVwOLrDaQEL3p /H4g== X-Forwarded-Encrypted: i=1; AJvYcCXItRMIP7sb9qbHt0Nxq9Ix+tvxv2EcGfVVQ8O5KUiz3JoiUSdX9SBk+1x6yjnS1CkYxJdo/imu+AHkcXA= X-Gm-Message-State: AOJu0YyBAxLKyJ4aKY1dMHqc68m8yIQ/mtyPTmBMPE46EXuBECZNUi54 1UU2Zn7qMESGWT9QwlRcHo9BhDOndV5xC6VNeuNMpAKfDoVuxC5PbTNW79lmDQY= X-Google-Smtp-Source: AGHT+IH5sF74/tuxk14SKM7+WcPSX/AD2jDHv8aBrb2ELgnRXZnl7dSamdgwOJS1ISXk6BNaePqcNA== X-Received: by 2002:a17:903:2312:b0:1fd:acd1:b658 with SMTP id d9443c01a7336-200ae5f679amr26109445ad.55.1723221099503; Fri, 09 Aug 2024 09:31:39 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff58f18616sm144382715ad.39.2024.08.09.09.31.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Aug 2024 09:31:39 -0700 (PDT) Date: Fri, 9 Aug 2024 09:31:36 -0700 From: Stephen Hemminger To: Mattias =?UTF-8?B?UsO2bm5ibG9t?= Cc: Mattias =?UTF-8?B?UsO2bm5ibG9t?= , dev@dpdk.org, Heng Wang , Joyce Kong , Tyler Retzlaff , Morten =?UTF-8?B?QnLDuHJ1cA==?= Subject: Re: [PATCH 2/5] eal: add unit tests for bit operations Message-ID: <20240809093136.487249e7@hermes.local> In-Reply-To: <201141b3-d8f2-4445-88d3-d8480b1c8761@lysator.liu.se> References: <20240505083737.118649-2-mattias.ronnblom@ericsson.com> <20240809090439.589295-1-mattias.ronnblom@ericsson.com> <20240809090439.589295-3-mattias.ronnblom@ericsson.com> <20240809080314.51637b87@hermes.local> <201141b3-d8f2-4445-88d3-d8480b1c8761@lysator.liu.se> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Fri, 9 Aug 2024 17:37:08 +0200 Mattias R=C3=B6nnblom wrote: > On 2024-08-09 17:03, Stephen Hemminger wrote: > > On Fri, 9 Aug 2024 11:04:36 +0200 > > Mattias R=C3=B6nnblom wrote: > > =20 > >> -uint32_t val32; > >> -uint64_t val64; > >> +#define GEN_TEST_BIT_ACCESS(test_name, set_fun, clear_fun, assign_fun= , \ > >> + flip_fun, test_fun, size) \ > >> + static int \ > >> + test_name(void) \ > >> + { \ > >> + uint ## size ## _t reference =3D (uint ## size ## _t)rte_rand(); \ > >> + unsigned int bit_nr; \ > >> + uint ## size ## _t word =3D (uint ## size ## _t)rte_rand(); \ > >> + \ > >> + for (bit_nr =3D 0; bit_nr < size; bit_nr++) { \ > >> + bool reference_bit =3D (reference >> bit_nr) & 1; \ > >> + bool assign =3D rte_rand() & 1; \ > >> + if (assign) \ > >> + assign_fun(&word, bit_nr, reference_bit); \ > >> + else { \ > >> + if (reference_bit) \ > >> + set_fun(&word, bit_nr); \ > >> + else \ > >> + clear_fun(&word, bit_nr); \ > >> + \ > >> + } \ > >> + TEST_ASSERT(test_fun(&word, bit_nr) =3D=3D reference_bit, \ > >> + "Bit %d had unexpected value", bit_nr); \ > >> + flip_fun(&word, bit_nr); \ > >> + TEST_ASSERT(test_fun(&word, bit_nr) !=3D reference_bit, \ > >> + "Bit %d had unflipped value", bit_nr); \ > >> + flip_fun(&word, bit_nr); \ > >> + \ > >> + const uint ## size ## _t *const_ptr =3D &word; \ > >> + TEST_ASSERT(test_fun(const_ptr, bit_nr) =3D=3D \ > >> + reference_bit, \ > >> + "Bit %d had unexpected value", bit_nr); \ > >> + } \ > >> + \ > >> + for (bit_nr =3D 0; bit_nr < size; bit_nr++) { \ > >> + bool reference_bit =3D (reference >> bit_nr) & 1; \ > >> + TEST_ASSERT(test_fun(&word, bit_nr) =3D=3D reference_bit, \ > >> + "Bit %d had unexpected value", bit_nr); \ > >> + } \ > >> + \ > >> + TEST_ASSERT(reference =3D=3D word, "Word had unexpected value"); \ > >> + \ > >> + return TEST_SUCCESS; \ > >> + } > >> + > >> +GEN_TEST_BIT_ACCESS(test_bit_access32, rte_bit_set, rte_bit_clear, > >> + rte_bit_assign, rte_bit_flip, rte_bit_test, 32) > >> + > >> +GEN_TEST_BIT_ACCESS(test_bit_access64, rte_bit_set, rte_bit_clear, > >> + rte_bit_assign, rte_bit_flip, rte_bit_test, 64) =20 > >=20 > > Having large macro like this for two cases adds complexity without > > additional clarity. Just duplicate the code please. =20 >=20 > GEN_TEST_BIT_ACCESS is being used by six more test cases in later=20 > patches in the series. Would it be possible to make it a function and pass function pointers with Generic?