From patchwork Thu Apr 4 16:22:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 139102 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9C8B043DFB; Thu, 4 Apr 2024 18:24:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DD30140A72; Thu, 4 Apr 2024 18:24:42 +0200 (CEST) Received: from mail-oa1-f44.google.com (mail-oa1-f44.google.com [209.85.160.44]) by mails.dpdk.org (Postfix) with ESMTP id BBA7B402BC for ; Thu, 4 Apr 2024 18:24:39 +0200 (CEST) Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-22ec890ee96so154868fac.1 for ; Thu, 04 Apr 2024 09:24:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1712247879; x=1712852679; 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=O2hbXsi8PUIPXcDbPGNQLDAn/Jd2tgQRFFjFN8WIeOQ=; b=tvleSgtzUEwfMMvlS3TpchwCuTinNdrL2ABqxoiQCTXVgwWFMAME9xHr8SWxMHBihq vqse/vhRnHkemf++eeSw+cEvDUeNJXk8yXSnpi3Lzb8nAyd/JrW89jGB3iAVYjR0rOZi 8sYtY9C9zoeGF69FOpGkIfeyfgVQdcx2IWaOV5w4hPNYGfNRLbSSlnPa/0tU90f7+CGd AMYBXkMSc5Xqs91f+SUV3u4ve0zS34O0J9+KIul82LuOIPAFBb67HePGwq3G/+F1psuE 3vaC5MibRtHo8K+hn7xnSPC410sLH+4g9474XnosLcckDBI5sgc6DMmKfGnAaarb0byc aqFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712247879; x=1712852679; 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=O2hbXsi8PUIPXcDbPGNQLDAn/Jd2tgQRFFjFN8WIeOQ=; b=BuIIdsGtwMsUe6xpFs3hxC195EbRwLE0YtP+J68xXWAe2eEkAfSulbyeMILBMx++lj SJsXj5kUBZgJLMN5DILARTH0yxMKsmb5SDyKIhRmZW3nTLfVvYCMKAJ5XStTQ1pqHzAy yVRG9VibwNYNwqavTzIZwnEMBQDYJ8jbVEWNh6qKzpw9M+NfJ1PcZPLCqt6lHz1svngb i+M+Q41+5DvBP1Pp0it447JG+xES8ufkVGd6zWb1mgRaJBk3x+mik9+H9Bf2eL2VpO/Y twq7ugDNzXivG3fm5kSpSBiXPAnhWz+aySWJ7/RetVKj0w/kMZmL8d0NxBB/udgcYZ6j ahgw== X-Gm-Message-State: AOJu0Yx/b2dCYRvcJi55SqMeWlQ/57vGH2LGJuDHpaHkqCqWL6xpmQGs LfPXuU6XLiAAdx4tMsUTf5rfarXO+VVcncLoO1aDGHE8UuHsBv9smR7dIb5orLDDC0TouK+8kT3 k1Lg= X-Google-Smtp-Source: AGHT+IGRVtyi+ECXBbWGedIOW8/BvhIKc9JHKHkY1Wc49ndKCDtDvZ2oeyTQyr2G2Ng3jkJiV/OZPQ== X-Received: by 2002:a05:6871:828:b0:22a:7c81:1e2e with SMTP id q40-20020a056871082800b0022a7c811e2emr3205445oap.16.1712247879028; Thu, 04 Apr 2024 09:24:39 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id k196-20020a633dcd000000b005ceeeea1816sm13784188pga.77.2024.04.04.09.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 09:24:38 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v3 2/2] test: add functional test for uuid Date: Thu, 4 Apr 2024 09:22:14 -0700 Message-ID: <20240404162422.61510-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240404162422.61510-1-stephen@networkplumber.org> References: <20240403163432.437275-1-stephen@networkplumber.org> <20240404162422.61510-1-stephen@networkplumber.org> MIME-Version: 1.0 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 uuid functions in EAL were not covered by existing functional tests. Signed-off-by: Stephen Hemminger --- app/test/meson.build | 1 + app/test/test_uuid.c | 138 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 app/test/test_uuid.c diff --git a/app/test/meson.build b/app/test/meson.build index 7d909039ae..11fb7dbffa 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -198,6 +198,7 @@ source_file_deps = { 'test_trace.c': [], 'test_trace_perf.c': [], 'test_trace_register.c': [], + 'test_uuid.c' : [], 'test_vdev.c': ['kvargs', 'bus_vdev'], 'test_version.c': [], } diff --git a/app/test/test_uuid.c b/app/test/test_uuid.c new file mode 100644 index 0000000000..a4b1b34786 --- /dev/null +++ b/app/test/test_uuid.c @@ -0,0 +1,138 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 Stephen Hemminger + */ + +#include + +#include "test.h" + +#define NROUNDS 100 + +static int +check_duplicate_uuid(rte_uuid_t uids[]) +{ + int i, j; + char out[256]; + + for (i = 0; i < NROUNDS - 1; i++) { + for (j = i + 1; j < NROUNDS; j++) { + if (rte_uuid_compare(uids[i], uids[j]) == 0) { + rte_uuid_unparse(uids[i], out, sizeof(out)); + printf("Generated duplicate random uuids %d == %d : %s\n", + i, j, out); + return TEST_FAILED; + } + } + } + return TEST_SUCCESS; +} + + +static const struct uuid_case { + const char *in; + rte_uuid_t result; +} good_cases[] = { + { "02ce8e94-5b84-47fc-8f86-72633c5b5061", + RTE_UUID_INIT(0x02ce8e94, 0x5b84, 0x47fc, 0x8f86, 0x72633c5b5061) }, + { "2c72af87-d220-4931-98ec-45c8520c94e1", + RTE_UUID_INIT(0x2c72af87, 0xd220, 0x4931, 0x98ec, 0x45c8520c94e1) }, + { "441edca1-0942-4ccd-9b33-233e0454fe5b", + RTE_UUID_INIT(0x441edca1, 0x0942, 0x4ccd, 0x9b33, 0x233e0454fe5b) }, +}; + +static const char * const bad_cases[] = { + "", /* empty */ + "41edca1-0942-4ccd-9b33-233e0454fe5b", /* too short */ + "d5cecbac-531b-4527-b0629-2bc3011dc9c", /* hyphen in wrong place */ + "db318745-1347-4f5e-m142-d86dc41172b2", /* bad hex */ +}; + +static int +test_uuid(void) +{ + rte_uuid_t uids[NROUNDS] = { }; + rte_uuid_t clone[NROUNDS] = { }; + unsigned int i; + int ret; + + /* Test generate random uuid */ + for (i = 0; i < NROUNDS; i++) { + if (!rte_uuid_is_null(uids[i])) { + printf("Zero'd uuid %d is not null\n", i); + return TEST_FAILED; + } + + rte_uuid_generate_random(uids[i]); + + if (rte_uuid_is_null(uids[i])) { + printf("Generated random uuid %d is null\n", i); + return TEST_FAILED; + } + } + + ret = check_duplicate_uuid(uids); + if (ret != TEST_SUCCESS) + return ret; + + /* Test generate time */ + for (i = 0; i < NROUNDS; i++) { + rte_uuid_generate_time(uids[i]); + + if (rte_uuid_is_null(uids[i])) { + printf("Generated random uuid %d is null\n", i); + return TEST_FAILED; + } + } + + + /* Test that copy works */ + for (i = 0; i < NROUNDS; i++) { + if (!rte_uuid_is_null(clone[i])) { + printf("Zero'd clone %d is not null\n", i); + return TEST_FAILED; + } + + rte_uuid_copy(clone[i], uids[i]); + + if (rte_uuid_compare(uids[i], clone[i]) != 0) { + printf("Copied uuid does not match\n"); + return TEST_FAILED; + } + } + + for (i = 0; i < RTE_DIM(good_cases); i++) { + const struct uuid_case *c = &good_cases[i]; + char out[37]; + rte_uuid_t uu; + + if (rte_uuid_parse(c->in, uu) != 0) { + printf("Failed to parse '%s'\n", c->in); + return TEST_FAILED; + } + if (rte_uuid_compare(uu, c->result) != 0) { + printf("Parse mismatch for '%s'\n", c->in); + return TEST_FAILED; + } + + rte_uuid_unparse(uu, out, sizeof(out)); + if (strcmp(out, c->in) != 0) { + printf("Parse/unparse mismatch (%s != %s)\n", + out, c->in); + return TEST_FAILED; + } + } + + for (i = 0; i < RTE_DIM(bad_cases); i++) { + const char *s = bad_cases[i]; + rte_uuid_t uu; + + if (rte_uuid_parse(s, uu) == 0) { + printf("Accepted parse of '%s'\n", s); + return TEST_FAILED; + } + } + return TEST_SUCCESS; +} + + +REGISTER_FAST_TEST(uuid_autotest, true, true, test_uuid);