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 9B2C045D16 for ; Fri, 15 Nov 2024 21:08:14 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7538F432C2; Fri, 15 Nov 2024 21:08:12 +0100 (CET) Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by mails.dpdk.org (Postfix) with ESMTP id 4690C43289 for ; Fri, 15 Nov 2024 21:08:07 +0100 (CET) Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-71e681bc315so1634631b3a.0 for ; Fri, 15 Nov 2024 12:08:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1731701286; x=1732306086; 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=CkSNpv+CgrtJB7HB3k6Xyc72k5klplmQdezcwf1ENjI=; b=fWTTDqVT+f/Nwbj84pxyda3RLQimzbz20OLmla4WL/ORWXun/Ki7Bkqru6HnIZOLXx rgtWTNhS0W+ZW5/HbzZYcFkZZC4E6Cx9ycyj35k00h7n0ZYJoQMPIWbeugVEFZ1a4ura /ZYICXseIw9s6FelGDq356dPZ1TvBe8B5OWQI7OtbgbSAnJI0w+AozECe05nstP4uCFP u0kwEKNTJ5IriRT0WxQPtF9BckUMg5smUhtzTI8Zq8un9EIcwKpSkqkn7msOl36/YD3j xLi0jegrETaiu8STOyPIK4QixTAUZmFI9qXmMmffw0rj5drnyiXcs9xR1ImjQaN9Mep3 bWZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731701286; x=1732306086; 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=CkSNpv+CgrtJB7HB3k6Xyc72k5klplmQdezcwf1ENjI=; b=mALbrC9nwTvDjucqMWyxzW/NYVhPFaICjpwTr7nUBs8B+roCZ9QDuQQcNy4Rj3jrPM tADRchBdZFi0qU6759chXBGkD0PD6i+d6dH9u6bQ/dtyFdgNejwO8+PLnBAFf4fTVqKk LXGfL/slQmxZA0UlE89WaSt25BQWD1Kf/W90Z+t3FHhZKrBVX4L1/OWFVf1f4G8r3LI5 XvbSQA59oTyRNjn1GaFQo8iHoss2E5EqoigEGD2JXhC5i/B0CVXG91KxLMZJb9oyEJHS 5NL4c5JwKgI57drTH2IaYqUAZ42YiHyLGJ42Fe7X1vOrX01kXJVx6+vU3RvMvx10NC0i jQRg== X-Forwarded-Encrypted: i=1; AJvYcCV+uZYnANh2h5L8fU/vKD8oR1P2dJNUC2g9J4YLEnE5NLmRZTggKn859ARXiAsO63ItDiHc/eo=@dpdk.org X-Gm-Message-State: AOJu0YwFCpkTkzQemcsIFKCOwhYWrEp2jMjCzmF571tuQ19Ho9T9DaBA FkKiTx87KjfL9WQitWk2aPIHJXzZH1vkfqB0nllvaDoaJGN/XZNX6o3m0AbEViM= X-Google-Smtp-Source: AGHT+IHofIMGBOuFuRKcX6+bsYP583HKDejx52sEKZ5zqb58xobiolDk6OodKhwniJ5TkrCdoecv8g== X-Received: by 2002:a05:6a00:90a4:b0:724:6aa0:90ef with SMTP id d2e1a72fcca58-7246aa09305mr11970431b3a.11.1731701286447; Fri, 15 Nov 2024 12:08:06 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724771e11f0sm1759686b3a.131.2024.11.15.12.08.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 12:08:06 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , stable@dpdk.org, Bruce Richardson , Tyler Retzlaff Subject: [PATCH v3 06/10] app/test: fix operator precedence bug Date: Fri, 15 Nov 2024 12:06:50 -0800 Message-ID: <20241115200751.17141-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241115200751.17141-1-stephen@networkplumber.org> References: <20241114001403.147609-1-stephen@networkplumber.org> <20241115200751.17141-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-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 be 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") Cc: stable@dpdk.org Signed-off-by: Stephen Hemminger Acked-by: Bruce Richardson --- 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