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 B4B5245CFB; Thu, 14 Nov 2024 01:15:13 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 67A95427A5; Thu, 14 Nov 2024 01:14:31 +0100 (CET) Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by mails.dpdk.org (Postfix) with ESMTP id CED774278C for ; Thu, 14 Nov 2024 01:14:26 +0100 (CET) Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-71e61b47c6cso6827951b3a.2 for ; Wed, 13 Nov 2024 16:14:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1731543266; x=1732148066; darn=dpdk.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=jLpfHLcb5U7+FRwuIryj+u20C1Anco0A/0b6dwRLMvc=; b=ESVCy0WFK63rudTFxNs2lApxxFqSLzX0XQ3BnRErg0cWKOJ13iiYr9trXJ6KDKU/b+ nP/Hm/WaEVjJWxYOREI+9tMkSeArlLtENpCsZQxSQbaHBNRa2y1fbxRkkudwNUpbkawU tB6o+XS+1TAVAJX/q04ga9lTKy5aDEpewqgaB5gLifRYR6riH6SQt+Kr3g1RWr3cI4Vv BaPYBoxUO6hCf34q5DwGtcqRu0umWrzRdxdT2zN40EmxOzXBNktiN6gHIF49QG8Oxw9t 2EiYtpcS4f7O6m2Jd0e9CGsd/pSuOlAaIR/LO2gwUVhgbVaBgHXgIwS9h9jcALQkAtgQ aniQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731543266; x=1732148066; 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=jLpfHLcb5U7+FRwuIryj+u20C1Anco0A/0b6dwRLMvc=; b=oySVKzg+QUwTrX0kymrTC1PJ5shZzuM4OpY+DOoKjU/EEjXOdjzgSsAarey42fEdbE 7nFWXYD/pT9FkvgmeGR6Oh7suqXmtRxGLAQXooE+inXPBwyQ8zsFznNMzN8ulwxyYMWT q94maDBxjtP97FZGiOR4zmWFNqyJqeXrPAFHqEw4tFC5uKQqUMsfY3ZhOR66TtXrXDVk idjhUCkVe2K5b3QHK3QXC5rSp+LKGvIvusS8GI3pRkcGN17pDFH5uExVILNH9JiTGAfo y503JmTjfpIy76pA9xVvuBcjKjTG2ANfW41OGpvE+RJfHjW+Vq/ksYabU+S0FwvG2Ni7 TY/A== X-Gm-Message-State: AOJu0Yzz66WCjl7kP1DRnt9ohVlvL13aw/7+HQNDXcS96Gdyr+2O2Grq RNpmN2+ple2nOF969b2NlHPHsAOg+sh+uVbW2q0szlWo72/frmL25ky0QsvlujRArZnA6hiJmTw d X-Google-Smtp-Source: AGHT+IGizOQvEtRVRi4U4mpV5Ri8tJd1g1gPHk86HZwhN4GTl80NOEEUnfhJn+RGJglADrtmqlpycw== X-Received: by 2002:a05:6a00:114f:b0:71e:768b:700a with SMTP id d2e1a72fcca58-72413368f1dmr31257982b3a.23.1731543265978; Wed, 13 Nov 2024 16:14:25 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7246a9a81a9sm9280b3a.99.2024.11.13.16.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2024 16:14:25 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff Subject: [RFC 10/10] app/test: fix operator precedence bug Date: Wed, 13 Nov 2024 16:12:22 -0800 Message-ID: <20241114001403.147609-11-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241114001403.147609-1-stephen@networkplumber.org> References: <20241114001403.147609-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 The test loop was much shorter than desired because when MAX_NUM is defined with out paren's the divide operator / takes precedence over shift. But when MAX_NUM is fixed, some tests take too long and have to modified to avoid running over full N^2 space of 1<<20. Note: this is a very old bug, goes back to 2013. Link: https://pvs-studio.com/en/blog/posts/cpp/1179/ Fixes: 1fb8b07ee511 ("app: add some tests") Signed-off-by: Stephen Hemminger --- app/test/test_common.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/app/test/test_common.c b/app/test/test_common.c index 21eb2285e1..6dbd7fc9a9 100644 --- a/app/test/test_common.c +++ b/app/test/test_common.c @@ -9,11 +9,12 @@ #include #include #include +#include #include #include "test.h" -#define MAX_NUM 1 << 20 +#define MAX_NUM (1 << 20) #define FAIL(x)\ {printf(x "() test failed!\n");\ @@ -218,19 +219,21 @@ test_align(void) } } - for (p = 1; p <= MAX_NUM / 2; p++) { - for (i = 1; i <= MAX_NUM / 2; i++) { - val = RTE_ALIGN_MUL_CEIL(i, p); - if (val % p != 0 || val < i) - FAIL_ALIGN("RTE_ALIGN_MUL_CEIL", i, p); - val = RTE_ALIGN_MUL_FLOOR(i, p); - if (val % p != 0 || val > i) - FAIL_ALIGN("RTE_ALIGN_MUL_FLOOR", i, p); - val = RTE_ALIGN_MUL_NEAR(i, p); - if (val % p != 0 || ((val != RTE_ALIGN_MUL_CEIL(i, p)) - & (val != RTE_ALIGN_MUL_FLOOR(i, p)))) - FAIL_ALIGN("RTE_ALIGN_MUL_NEAR", i, p); - } + /* testing the whole space of 2^20^2 takes too long. */ + for (j = 1; j <= MAX_NUM ; j++) { + i = rte_rand_max(MAX_NUM - 1) + 1; + p = rte_rand_max(MAX_NUM - 1) + 1; + + val = RTE_ALIGN_MUL_CEIL(i, p); + if (val % p != 0 || val < i) + FAIL_ALIGN("RTE_ALIGN_MUL_CEIL", i, p); + val = RTE_ALIGN_MUL_FLOOR(i, p); + if (val % p != 0 || val > i) + FAIL_ALIGN("RTE_ALIGN_MUL_FLOOR", i, p); + val = RTE_ALIGN_MUL_NEAR(i, p); + if (val % p != 0 || ((val != RTE_ALIGN_MUL_CEIL(i, p)) + & (val != RTE_ALIGN_MUL_FLOOR(i, p)))) + FAIL_ALIGN("RTE_ALIGN_MUL_NEAR", i, p); } return 0; -- 2.45.2