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 D0A4445CC3 for ; Thu, 14 Nov 2024 20:26:30 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6BDD442EFB; Thu, 14 Nov 2024 20:26:27 +0100 (CET) Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by mails.dpdk.org (Postfix) with ESMTP id A28F342EDC for ; Thu, 14 Nov 2024 20:26:21 +0100 (CET) Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-7f4324503d7so767916a12.3 for ; Thu, 14 Nov 2024 11:26:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1731612381; x=1732217181; 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=HqzueQE+0xRrTjaGTDo1fD5BKlDNLXU1UxxoDpYWagk=; b=w8L9dhCSpysBqsdDiJcuDvDhE8sX/fBklExiQdiBM6NJ/uTcCQNazo+/AqyQaOrGB6 u0cjJZc4QIz6MYQMcymo4xZzj8nFyHzkq6qcLFiRXJ8+Udr7Q2I9mGtQohrUj1uwUz26 m6YcGpPuvbVw7uNwMlVHZE2Nz4wKrNgJoz50A7FqKBDnWn92eeTbP/ENXpIJKLrqwWu0 1QKmYJUS95x7Dq4neMrGkeCi0QDEQUB/uEnUKO06Czg1ewP+fG0eX8f/M70E1YzaUYDQ xbyuecpoOALOBmg+5VSPCxznx9Txqx9XTQvcnyOT4eOtlU0LUGhPB8hOWrqyD8nQf+cv NXpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731612381; x=1732217181; 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=HqzueQE+0xRrTjaGTDo1fD5BKlDNLXU1UxxoDpYWagk=; b=ego8RNjiYzhdK0uKMZnc0Fpz1k25qCTgHH0IeoV20JsUuYTnIoA4u3g6zzKc5Cviq7 J9UER3ND4tAa5/5xgWw1e0MTNBHQ++Ih4a0yi9bFzmXyDssxMtmZBOPupmWNVlOikg2G mFnNOIqkgrUmQkJYtM0tZgNMrouzT6EI6W+GaXfFE3NBBCJEyCw5cRh2H6InTKLBYw/Q MwhQbyc5TjTH8yK6YwSIOq8bioxJlaLQwMYTDAitl0bjtkOohmYyxOtNMS9Gn7miDi9S 0JU1cFSvsnva2T+m4OjRy646xxn/zBVohw5xESBde/CfNt0p9O/Dv9lnk2Ul9ZsnFaXI g1MA== X-Forwarded-Encrypted: i=1; AJvYcCWyQLrPi4ugFHmNmZ6JcD4/uHfl+RLZsQALV9vnrqOEHnfY/6o+fhn3uBDnqDzpBx4HxH7uBYM=@dpdk.org X-Gm-Message-State: AOJu0YwOmdnL9v2RIUnkxDBpl/yy+4rqwDb8vHAi+YW6NcVnJ2S2O8J+ SX+Qhcg4fcu3JQW3Cyl9o748RKUCdK8ea7tXQR8VJexoRi6nNrKM3+F+3TZQ25s= X-Google-Smtp-Source: AGHT+IEom7tkWr8cS6/6jCPMHt10JpDLc4POQAlCUOgveJRE8xfF9ranXUo/ukfxzR58lMFkepqgGw== X-Received: by 2002:a05:6a21:6d90:b0:1dc:32a:d40a with SMTP id adf61e73a8af0-1dc2292bebamr36803407637.18.1731612380765; Thu, 14 Nov 2024 11:26:20 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7f8b37f3466sm1461632a12.35.2024.11.14.11.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:26:20 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , stable@dpdk.org, Tyler Retzlaff Subject: [PATCH v2 06/10] app/test: fix operator precedence bug Date: Thu, 14 Nov 2024 11:25:04 -0800 Message-ID: <20241114192603.41145-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241114192603.41145-1-stephen@networkplumber.org> References: <20241114001403.147609-1-stephen@networkplumber.org> <20241114192603.41145-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 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 --- 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