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 EDC9E4577A; Fri, 9 Aug 2024 17:03:19 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C5EA742D78; Fri, 9 Aug 2024 17:03:19 +0200 (CEST) Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by mails.dpdk.org (Postfix) with ESMTP id C6F174025F for ; Fri, 9 Aug 2024 17:03:18 +0200 (CEST) Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1ff4fa918afso14697545ad.1 for ; Fri, 09 Aug 2024 08:03:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1723215798; x=1723820598; 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=rhZ8mcR+kgwY0+1YesRkf6UZivZ3wfKFwQzzt2yK2Yk=; b=culXgedkb5ZFYubTo0Zl659+A7OaJFd10rbP6dr7l4TW4z0NU0aLJ/6cicP6mUbdXw d4HGk0oeepidYKqJU5DB2MzBjwCHMsRhegZ3JzmJ6RabZPn/At0Nqpy1OfDL6deCUzcU wK5Nd0IMxhXuJyh2qcVooT6k26z0KFpdRPuFaTub3ToBXKp0MjKRPAzjPpkKAnQhIPjB TyTR4g06EJ15t9p3MuD2Qjk4QqYkRb1vSeKttc6lGWOpdqnk3Op678i1zZtQW75r/fxd SDOCKm1j/FoWm1NekqhYNqYvGgW9qazVLty81/7g4IHct7gUsNIWtyH5+KuqjEkN/1eK TU1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723215798; x=1723820598; 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=rhZ8mcR+kgwY0+1YesRkf6UZivZ3wfKFwQzzt2yK2Yk=; b=b9LKCdnb2egzK0cb7tDUPVQyK5l4YZqqzJPglEDjAyHk2he9wz94EfYMZHQcAK/8e5 0x58eAAYIVMHm4lCUU6/PfqSVr1VURJM4DR6LpujDn68N1NV/sWiBF6mDn1q1wsjWtte jnxMQem11M5Mi/V7w4hIZe4S7krX28CmujPl4Q7gkjjpDcJg5UEyfuSBAtt+TtBy/f2J 9pWfFURN02Mdy2Iv0XsxpJGUEY8g3xFDtk4/C6dmGKwhKX1jRGrzLGrbvVnmNgjOI0ui OMmo2rqvi3YtVNDv3sBcmwPzVQqbygzmPmjm4Vu+hxJrBjv/SEeiiXM73g4PdblzuGBx CJGQ== X-Gm-Message-State: AOJu0YzccOsexhus8HZUiVGDzsJpapA6s6dF7qLSFypzeI9gicxwkJz7 Zw239M9oZcHYAbCv8qP9TKJbg4LboqQDpdCQNLrfjrK8FKomTG04xzkuS9OgSj0= X-Google-Smtp-Source: AGHT+IEGk+FR+S5fBch5xQA/+ekzWgFa3gDShPTZaFwLBEspPRYLek0ASjNd4/q6ac/e4iODzlEuEQ== X-Received: by 2002:a17:903:2449:b0:1fb:8419:8384 with SMTP id d9443c01a7336-200ae4bb2fcmr19523325ad.13.1723215797664; Fri, 09 Aug 2024 08:03:17 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff58f53832sm143514695ad.73.2024.08.09.08.03.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Aug 2024 08:03:17 -0700 (PDT) Date: Fri, 9 Aug 2024 08:03:14 -0700 From: Stephen Hemminger To: Mattias =?UTF-8?B?UsO2bm5ibG9t?= Cc: , , 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: <20240809080314.51637b87@hermes.local> In-Reply-To: <20240809090439.589295-3-mattias.ronnblom@ericsson.com> References: <20240505083737.118649-2-mattias.ronnblom@ericsson.com> <20240809090439.589295-1-mattias.ronnblom@ericsson.com> <20240809090439.589295-3-mattias.ronnblom@ericsson.com> 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 11:04:36 +0200 Mattias R=C3=B6nnblom wrote: > -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) Having large macro like this for two cases adds complexity without additional clarity. Just duplicate the code please.