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 982C74576E; Thu, 8 Aug 2024 21:48:35 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C60B442DE3; Thu, 8 Aug 2024 21:48:14 +0200 (CEST) Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by mails.dpdk.org (Postfix) with ESMTP id 1205D42DB1 for ; Thu, 8 Aug 2024 21:48:11 +0200 (CEST) Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-7b594936e9bso934486a12.1 for ; Thu, 08 Aug 2024 12:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1723146490; x=1723751290; 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=2rwZlBG8abKJfoIMjqbIA+3btUaxKinEosLlyHzAiec=; b=gKT9OIDgMYjdZ9B4MrGu6BaY4jRaXCOBGBfXCtSkhqsSysLE9IlPm27Wz+NQrU298B clNGm+MD2bIfVt6CJH2yxY4JvN94mUmv4FpRO/58S6v3ulMCYPEobYf249XEcNGsxQwN gnLTxhTtIYa1LGU+7fHhk4chhrEg25p2F17zD0zZhBAJd9Dtn85AMQg+qLDKbTVlGfIL 3p/TduhR0dYomUAWGS1aph8nahCIKVblkr9SFizSZhaoMQQegvINwITgpjRkSSCXx5ww tsM/Ckl+mQ+kjASH/Lc/a2eBBG1tT2sJoXt64GmI3A/5ORFXlxRE6d+2IabZEdLhi4Mh 99WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723146490; x=1723751290; 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=2rwZlBG8abKJfoIMjqbIA+3btUaxKinEosLlyHzAiec=; b=rhKOqcZMMnVgqsLC+C5Eb2TTjQcY79gamiWcMwjvC2vuil0j3qia6U8SEFk0/948MX Su8vG9S5hQq+VPeZUp+U4eDceIbqKi91umbEKRpV4eyBLQ7nZOR0EotwhUIemZd4LWg6 nv4c10uMn+vFcBcvFWgZFq0gF1S9oQ4HZK5FJ8+o/+Co0+w+RsRhbWSBBcT/DUINEmlt 7BCoExLHlJQVM/GK/HPeJnMswfxRBkpTbaq3YNt3V3hEN7zWdpsW7F81j/euDkUVBKsQ vvqlZ6nJBUgntEUjimAvfDAq6Fu/ePpugUErSN+7XGyaOX/iZLG7YR0tIiE7WZ1c+lo+ oz1g== X-Gm-Message-State: AOJu0YyPnOPeozUcKJdPq4Z89Nmqg7EtnRQR9kxxPqasGnFpBYIHOE6b J2a9WdBO2sElbcORSsAlcx24DTT8GqcSIRdkMfaNGlCAk8fQawuKCQlCAvPFXTqlIVVY/zX1Fok 9 X-Google-Smtp-Source: AGHT+IHa8h3HXQq5XdkMEoQ2jTCv67NCxXjeZUhTwX3g2iZUlhZAjvnT8zkLIj3fTT6wso577oFOpw== X-Received: by 2002:a05:6a20:9184:b0:1c0:f315:ec7e with SMTP id adf61e73a8af0-1c6fcf1947fmr3507376637.28.1723146490051; Thu, 08 Aug 2024 12:48:10 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710cb2d376csm1469804b3a.111.2024.08.08.12.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 12:48:09 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff Subject: [PATCH 4/5] test/alarm: rewrite the alarm test Date: Thu, 8 Aug 2024 12:47:00 -0700 Message-ID: <20240808194756.167664-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240808194756.167664-1-stephen@networkplumber.org> References: <20240808194756.167664-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 alarm test had several issues: - only negative tests were done, no positive test to make sure API worked - the set/cancel test had too short an interval and the alarm might expire - the test should have used the standard TEST macros. Signed-off-by: Stephen Hemminger --- app/test/test_alarm.c | 77 ++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/app/test/test_alarm.c b/app/test/test_alarm.c index 0cdfad1374..67ca30b1fe 100644 --- a/app/test/test_alarm.c +++ b/app/test/test_alarm.c @@ -3,53 +3,76 @@ */ #include +#include #include -#include #include +#include +#include +#include +#include #include "test.h" -static volatile int flag; +#ifndef US_PER_SEC +#define US_PER_SEC 1000000u +#endif static void test_alarm_callback(void *cb_arg) { - flag = 1; - printf("Callback setting flag - OK. [cb_arg = %p]\n", cb_arg); + bool *triggered = cb_arg; + + rte_atomic_store_explicit(triggered, 1, rte_memory_order_release); } + static int test_alarm(void) { - /* check if it will fail to set alarm with wrong us value */ - printf("check if it will fail to set alarm with wrong ms values\n"); - if (rte_eal_alarm_set(0, test_alarm_callback, - NULL) >= 0) { - printf("should not be successful with 0 us value\n"); - return -1; - } - if (rte_eal_alarm_set(UINT64_MAX - 1, test_alarm_callback, - NULL) >= 0) { - printf("should not be successful with (UINT64_MAX-1) us value\n"); - return -1; - } + bool triggered = false; + bool later = false; + int ret; + + /* check if it will fail to set alarm with wrong us values */ + TEST_ASSERT_FAIL(rte_eal_alarm_set(0, test_alarm_callback, NULL), + "Expected rte_eal_alarm_set to fail with 0 us value"); + + /* check it if will fail with a very large timeout value */ + TEST_ASSERT_FAIL(rte_eal_alarm_set(UINT64_MAX - 1, test_alarm_callback, NULL), + "Expected rte_eal_alarm_set to fail with (UINT64_MAX-1) us value"); /* check if it will fail to set alarm with null callback parameter */ - printf("check if it will fail to set alarm with null callback parameter\n"); - if (rte_eal_alarm_set(10 /* ms */, NULL, NULL) >= 0) { - printf("should not be successful to set alarm with null callback parameter\n"); - return -1; - } + TEST_ASSERT_FAIL(rte_eal_alarm_set(US_PER_SEC, NULL, NULL), + "Expected rte_eal_alarm_set to fail with null callback parameter"); /* check if it will fail to remove alarm with null callback parameter */ - printf("check if it will fail to remove alarm with null callback parameter\n"); - if (rte_eal_alarm_cancel(NULL, NULL) == 0) { - printf("should not be successful to remove alarm with null callback parameter"); - return -1; - } + TEST_ASSERT_FAIL(rte_eal_alarm_cancel(NULL, NULL), + "Expected rte_eal_alarm_cancel to fail with null callback parameter"); + + /* check if can set a alarm for one second */ + TEST_ASSERT_SUCCESS(rte_eal_alarm_set(US_PER_SEC, test_alarm_callback, &triggered), + "Setting one second alarm failed"); + + /* set a longer alarm that will be canceled. */ + TEST_ASSERT_SUCCESS(rte_eal_alarm_set(10 * US_PER_SEC, test_alarm_callback, &later), + "Setting ten second alarm failed"); + + /* wait for alarm to happen */ + while (rte_atomic_load_explicit(&triggered, rte_memory_order_acquire) == false) + rte_delay_us_sleep(US_PER_SEC / 10); + + TEST_ASSERT(!rte_atomic_load_explicit(&later, rte_memory_order_acquire), + "Only one alarm should have fired."); + + ret = rte_eal_alarm_cancel(test_alarm_callback, &triggered); + TEST_ASSERT(ret == 0 && rte_errno == ENOENT, + "Canceling alarm after run ret %d: %s", ret, rte_strerror(rte_errno)); + + ret = rte_eal_alarm_cancel(test_alarm_callback, &later); + TEST_ASSERT(ret == 1, "Canceling ten second alarm failed %d: %s", ret, rte_strerror(rte_errno)); return 0; } -REGISTER_TEST_COMMAND(alarm_autotest, test_alarm); +REGISTER_FAST_TEST(alarm_autotest, true, true, test_alarm); -- 2.43.0