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 8119B45D6B for ; Thu, 21 Nov 2024 19:25:09 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D824F4327C; Thu, 21 Nov 2024 19:25:06 +0100 (CET) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by mails.dpdk.org (Postfix) with ESMTP id 4307F42FB7 for ; Thu, 21 Nov 2024 19:25:00 +0100 (CET) Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-724d8422f37so556637b3a.2 for ; Thu, 21 Nov 2024 10:25:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1732213499; x=1732818299; 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=z6HkJ/Zot/Wv2zoIWpk3zejCo6Nh/8rhhBaUYn0B19kTKZo06/xUiFItSVB60BWNP8 oBYQIU2Y9OQGo06HEdqdRChQvFjo+dkpyYpou9uSN8MsJppOb0NPrd4pJj1S5FiVAvqu /TeqoLnIpGS5rDVOX8dtZ55SDl5boONayxpdwWYbMJuUQOezBD9T7w8Dmz/GSaWDMzsr rS6g09HJpx9uaarVcWsyTcu0/a7jGjDMY4i/0/zGwmjuaOE+12nwebiypZFEB3H/4HCk 4xFFGUTYVgJVqwl/PJkVrQnpGQU9tIgINy/sbMzH0/SZ9d9glFBrSv/PkvTcgID8u63z GeTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732213499; x=1732818299; 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=qdkeK1/P+3bG0mvPHpb2hABgopVus4rk1Pm3RwHGbwVUl5YvdKM+VUwBOXiNymK/ys P4PE1+jMWP3gR8UlBUT8CwMrO/vcK5n5dqTvl8I16Lcih+bSsFVvHAw+eThvHr025+UK y3zNqgKSLvUlUxjemrI1rZS5prQU7uD+H3BLkkzzf5G933Zt73UCQqW2Eo19Lo8grlIi St3DjcQRkck7/Dc4w+PB2fi72R8j+tcr/sJLKLzYZeB0Dgy2quDFy96ChqrMlZhdkYgJ 5Q++oT5rUxUg3NLbQzYMRYPkIrF4UQxUK0AhDlodkzMdb5QcRzepzwnBaX2eotgH3v/C 49RA== X-Forwarded-Encrypted: i=1; AJvYcCX4bz/Fxmnbi/bPAuF39vpI+mIYM640muzrK13QouAvprfKIR0Bo0kwLyiEOvx3JPIHbt/V6p8=@dpdk.org X-Gm-Message-State: AOJu0YwVP2B9s7699iNpAOaltb+M0wHYYqMNQcAEpcVU6lZTZ3sebWsL BZpev3MWujNHDUTzLwiQNd2KHWB3B6h7otPeNTvEMlkHRm22lNCpaBatLGbDO2M= X-Gm-Gg: ASbGnctYMLKnx6MHiwaFPJZmlOtmDmHJrEHQZgGhVGy9R2Wb6/AbDQ6LzvZhy1ofdBC lKHgeFsB22bTNrBiAH0iVNGhuJq0BQrpKJ4WO8BNzyLDUGGoVVrqC0vxEn4+DnnzxgyLwnGP/ey ACq0REEVuDJbzYYla9mmHQnS/nZ82B4ZTbsRxr45MIJp5vWLlFidB23Oum13gfxT1yyEduRugF5 0SBWDMsEqSEUWrDb2DWWkCTpNN7QHklQPQSsxDfWAUL/1sBelaIgVaB9pjMqhePu936+1CNaAt3 bRowOqlPv13vIIpYfWfRuyDfvuw= X-Google-Smtp-Source: AGHT+IEDoep8p1+jGuJv6ST0+69QOcUfUirivxwyBJIbQbROQnaMBp09XAhxfLbHS6C24/ibUuu4Tg== X-Received: by 2002:a05:6a00:3499:b0:724:dba1:61ef with SMTP id d2e1a72fcca58-724dba163ffmr1283403b3a.24.1732213499307; Thu, 21 Nov 2024 10:24:59 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724de454aa1sm70201b3a.4.2024.11.21.10.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 10:24:58 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , stable@dpdk.org, Bruce Richardson , Tyler Retzlaff Subject: [PATCH v4 6/9] app/test: fix operator precedence bug Date: Thu, 21 Nov 2024 10:23:27 -0800 Message-ID: <20241121182443.68025-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241121182443.68025-1-stephen@networkplumber.org> References: <20241114001403.147609-1-stephen@networkplumber.org> <20241121182443.68025-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