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 69FEB456F9; Wed, 31 Jul 2024 06:23:54 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D808740A6B; Wed, 31 Jul 2024 06:23:41 +0200 (CEST) Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by mails.dpdk.org (Postfix) with ESMTP id 97D134042E for ; Wed, 31 Jul 2024 06:21:53 +0200 (CEST) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1fd6ed7688cso39554035ad.3 for ; Tue, 30 Jul 2024 21:21:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1722399713; x=1723004513; 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=+z476KqZsuCuyBfTTRVD+7bk4KXIdN5WQ3/8CMTuQio=; b=wpurE+x57x5VhffaS3rSaDOesRhX+T/683tszVBvHe9+oiJ7mc03fhw/Ow9JxqFN8v TANSalH5UnYaVR5ypkEB5KnOMtFZ+fUUFsBx9lLh2el6EmYQrwdW6aHpOzthwVg6FLxo Jl1KVb46oYL1V2Je8z58uf9pVNhS5PAZldCYYSXgDFPDL5QTdnFcDHnIYXN9tUcowjK0 ddpmT2KKmixDWrRd/ZHhbhFN0anjX7OFyWAJ7ZKB5J1glakF5IS/2KgD51yEtlUVlCo/ JyrI50i436Zh2egvCz/cSMq2DNvewzJIcTXTOR/uu45FUGIddDE6o1c9p5YoXnWcxwEf LbkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722399713; x=1723004513; 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=+z476KqZsuCuyBfTTRVD+7bk4KXIdN5WQ3/8CMTuQio=; b=BN8TdYJ59CrkWfpSU7boHxQs00aqr5RO651PDOs2rbNU/4TGT4GyRUIfeIfaJZaxOP JMz2swWfqnB9O+chhFwE9L6vMHbqglymMFJSqitEjn8ZwInRXv77glgz3XYVg7TYhXiQ pqY6nLrm7foptXoBpfuQSdZeoObnvMjBljxGV9JKNBTu5TAe0JkVsihcdooWgoa4XFBa rol2r/X7rGj2J3JyDu3vWWpr7dfh2799OT6XgPR6kxOKFJVnem/XbAYcmWhHUPbIGY6/ iU3ggZP89ygKny3dweiWe1Vh1OsTtvUinQrPBNXlLcp9MblKDdAk5Ce/Ai2l/XEXeoWG G3aQ== X-Gm-Message-State: AOJu0YyaIMmUniE8hE2YvA8ZfCYOlnMBt+9CvPGVD7tGi67np5JHHEW/ HfP6639QuG78jUdq8bjE2bmqSxw97ZlOtCAm5Om9sFPEOtlH/Q1VDBIV+oJn3OK4yEw7lOf1E5+ v X-Google-Smtp-Source: AGHT+IGiAGiGWY81q5hCbCsGR4gmdpreng87Lzdn3KlGujNKRjT+8NslIUB7LjL/SvJUPRhIPmJ2kg== X-Received: by 2002:a17:902:d50d:b0:1fd:7293:3d70 with SMTP id d9443c01a7336-1ff04805ec7mr145683565ad.8.1722399712701; Tue, 30 Jul 2024 21:21:52 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7c80044sm110093375ad.14.2024.07.30.21.21.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jul 2024 21:21:52 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v2 2/3] test: restore cfgfile tests Date: Tue, 30 Jul 2024 21:20:30 -0700 Message-ID: <20240731042141.76985-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240731042141.76985-1-stephen@networkplumber.org> References: <20240730225520.83314-1-stephen@networkplumber.org> <20240731042141.76985-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 These tests were not built since the conversion to meson. Instead of using embedded resource functions, put data in include file and generate before the test. Signed-off-by: Stephen Hemminger --- app/meson.build | 3 +- app/test/meson.build | 6 +- app/test/test_cfgfile.c | 160 ++++++++++++++++++----------- app/test/test_cfgfiles/meson.build | 19 ++++ 4 files changed, 127 insertions(+), 61 deletions(-) create mode 100644 app/test/test_cfgfiles/meson.build diff --git a/app/meson.build b/app/meson.build index 5b2c80c7a1..e2db888ae1 100644 --- a/app/meson.build +++ b/app/meson.build @@ -55,6 +55,7 @@ foreach app:apps build = true reason = '' # set if build == false to explain sources = [] + resources = [] includes = [] cflags = default_cflags ldflags = default_ldflags @@ -115,7 +116,7 @@ foreach app:apps endif exec = executable('dpdk-' + name, - sources, + [ sources, resources ], c_args: cflags, link_args: ldflags, link_whole: link_libs, diff --git a/app/test/meson.build b/app/test/meson.build index e29258e6ec..c99d768ead 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -36,7 +36,7 @@ source_file_deps = { 'test_bitratestats.c': ['metrics', 'bitratestats', 'ethdev'] + sample_packet_forward_deps, 'test_bpf.c': ['bpf', 'net'], 'test_byteorder.c': [], -# 'test_cfgfile.c': ['cfgfile'], + 'test_cfgfile.c': ['cfgfile'], 'test_cksum.c': ['net'], 'test_cksum_perf.c': ['net'], 'test_cmdline.c': [], @@ -263,3 +263,7 @@ if not is_windows build_by_default: true, install: false) endif + +subdir('test_cfgfiles') + +resources += test_cfgfile_h diff --git a/app/test/test_cfgfile.c b/app/test/test_cfgfile.c index a5e3d8699c..f34838dd85 100644 --- a/app/test/test_cfgfile.c +++ b/app/test/test_cfgfile.c @@ -5,47 +5,31 @@ #include #include #include -#include +#include #include #include "test.h" -#include "resource.h" - -#define CFG_FILES_ETC "test_cfgfiles/etc" - -REGISTER_LINKED_RESOURCE(test_cfgfiles); +#include "test_cfgfiles.h" static int -test_cfgfile_setup(void) +test_cfgfile_init(char *filename, const char *data) { - const struct resource *r; - int ret; + size_t len = strlen(data); + int fd; - r = resource_find("test_cfgfiles"); - TEST_ASSERT_NOT_NULL(r, "missing resource test_cfgfiles"); + fd = mkstemps(filename, strlen(".ini")); + if (fd < 0) + return fd; - ret = resource_untar(r); - TEST_ASSERT_SUCCESS(ret, "failed to untar %s", r->name); - - return 0; + if (write(fd, data, len) != (int)len) { + close(fd); + return -1; + } + return fd; } -static int -test_cfgfile_cleanup(void) -{ - const struct resource *r; - int ret; - - r = resource_find("test_cfgfiles"); - TEST_ASSERT_NOT_NULL(r, "missing resource test_cfgfiles"); - - ret = resource_rm_by_tar(r); - TEST_ASSERT_SUCCESS(ret, "Failed to delete resource %s", r->name); - - return 0; -} static int _test_cfgfile_sample(struct rte_cfgfile *cfgfile) @@ -87,9 +71,14 @@ static int test_cfgfile_sample1(void) { struct rte_cfgfile *cfgfile; - int ret; + char filename[] = "/tmp/cfg_sample1_XXXXXX.ini"; + int fd, ret; - cfgfile = rte_cfgfile_load(CFG_FILES_ETC "/sample1.ini", 0); + fd = test_cfgfile_init(filename, sample1_ini); + TEST_ASSERT(fd >= 0, "Failed to setup temp file"); + + cfgfile = rte_cfgfile_load(filename, 0); + close(fd); TEST_ASSERT_NOT_NULL(cfgfile, "Failed to load config file"); ret = _test_cfgfile_sample(cfgfile); @@ -98,6 +87,8 @@ test_cfgfile_sample1(void) ret = rte_cfgfile_close(cfgfile); TEST_ASSERT_SUCCESS(ret, "Failed to close cfgfile"); + unlink(filename); + return 0; } @@ -106,14 +97,18 @@ test_cfgfile_sample2(void) { struct rte_cfgfile_parameters params; struct rte_cfgfile *cfgfile; - int ret; + char filename[] = "/tmp/cfgile_sample2_XXXXXX.ini"; + int fd, ret; + + fd = test_cfgfile_init(filename, sample2_ini); + TEST_ASSERT(fd >= 0, "Failed to setup temp file"); /* override comment character */ memset(¶ms, 0, sizeof(params)); params.comment_character = '#'; - cfgfile = rte_cfgfile_load_with_params(CFG_FILES_ETC "/sample2.ini", 0, - ¶ms); + cfgfile = rte_cfgfile_load_with_params(filename, 0, ¶ms); + close(fd); TEST_ASSERT_NOT_NULL(cfgfile, "Failed to parse sample2.ini"); ret = _test_cfgfile_sample(cfgfile); @@ -122,6 +117,8 @@ test_cfgfile_sample2(void) ret = rte_cfgfile_close(cfgfile); TEST_ASSERT_SUCCESS(ret, "Failed to close cfgfile"); + unlink(filename); + return 0; } @@ -129,10 +126,15 @@ static int test_cfgfile_realloc_sections(void) { struct rte_cfgfile *cfgfile; - int ret; + char filename[] = "/tmp/cfg_realloc_XXXXXX.ini"; + int fd, ret; const char *value; - cfgfile = rte_cfgfile_load(CFG_FILES_ETC "/realloc_sections.ini", 0); + fd = test_cfgfile_init(filename, realloc_sections_ini); + TEST_ASSERT(fd >= 0, "Failed to setup temp file"); + + cfgfile = rte_cfgfile_load(filename, 0); + close(fd); TEST_ASSERT_NOT_NULL(cfgfile, "Failed to load config file"); ret = rte_cfgfile_num_sections(cfgfile, NULL, 0); @@ -152,13 +154,15 @@ test_cfgfile_realloc_sections(void) TEST_ASSERT(strcmp("value8_section9", value) == 0, "key unexpected value: %s", value); - ret = rte_cfgfile_save(cfgfile, "/tmp/cfgfile_save.ini"); + ret = rte_cfgfile_save(cfgfile, "/tmp/cfg_save.ini"); TEST_ASSERT_SUCCESS(ret, "Failed to save *.ini file"); - remove("/tmp/cfgfile_save.ini"); + remove("/tmp/cfg_save.ini"); ret = rte_cfgfile_close(cfgfile); TEST_ASSERT_SUCCESS(ret, "Failed to close cfgfile"); + unlink(filename); + return 0; } @@ -166,10 +170,17 @@ static int test_cfgfile_invalid_section_header(void) { struct rte_cfgfile *cfgfile; + char filename[] = "/tmp/cfg_invalid_section_XXXXXX.ini"; + int fd; - cfgfile = rte_cfgfile_load(CFG_FILES_ETC "/invalid_section.ini", 0); + fd = test_cfgfile_init(filename, invalid_section_ini); + TEST_ASSERT(fd >= 0, "Failed to setup temp file"); + + cfgfile = rte_cfgfile_load(filename, 0); TEST_ASSERT_NULL(cfgfile, "Expected failure did not occur"); + close(fd); + unlink(filename); return 0; } @@ -178,15 +189,21 @@ test_cfgfile_invalid_comment(void) { struct rte_cfgfile_parameters params; struct rte_cfgfile *cfgfile; + char filename[] = "/tmp/cfg_sample2_XXXXXX.ini"; + int fd; /* override comment character with an invalid one */ memset(¶ms, 0, sizeof(params)); params.comment_character = '$'; - cfgfile = rte_cfgfile_load_with_params(CFG_FILES_ETC "/sample2.ini", 0, - ¶ms); + fd = test_cfgfile_init(filename, sample2_ini); + TEST_ASSERT(fd >= 0, "Failed to setup temp file"); + + cfgfile = rte_cfgfile_load_with_params(filename, 0, ¶ms); TEST_ASSERT_NULL(cfgfile, "Expected failure did not occur"); + close(fd); + unlink(filename); return 0; } @@ -194,10 +211,17 @@ static int test_cfgfile_invalid_key_value_pair(void) { struct rte_cfgfile *cfgfile; + char filename[] = "/tmp/cfg_empty_key_XXXXXX.ini"; + int fd; - cfgfile = rte_cfgfile_load(CFG_FILES_ETC "/empty_key_value.ini", 0); + fd = test_cfgfile_init(filename, empty_key_value_ini); + TEST_ASSERT(fd >= 0, "Failed to setup temp file"); + + cfgfile = rte_cfgfile_load(filename, 0); + close(fd); TEST_ASSERT_NULL(cfgfile, "Expected failure did not occur"); + unlink(filename); return 0; } @@ -206,10 +230,15 @@ test_cfgfile_empty_key_value_pair(void) { struct rte_cfgfile *cfgfile; const char *value; - int ret; + char filename[] = "/tmp/cfg_empty_key_XXXXXX.ini"; + int fd, ret; + + fd = test_cfgfile_init(filename, empty_key_value_ini); + TEST_ASSERT(fd >= 0, "Failed to setup temp file"); + + cfgfile = rte_cfgfile_load(filename, CFG_FLAG_EMPTY_VALUES); + close(fd); - cfgfile = rte_cfgfile_load(CFG_FILES_ETC "/empty_key_value.ini", - CFG_FLAG_EMPTY_VALUES); TEST_ASSERT_NOT_NULL(cfgfile, "Failed to parse empty_key_value.ini"); ret = rte_cfgfile_num_sections(cfgfile, NULL, 0); @@ -227,6 +256,7 @@ test_cfgfile_empty_key_value_pair(void) ret = rte_cfgfile_close(cfgfile); TEST_ASSERT_SUCCESS(ret, "Failed to close cfgfile"); + unlink(filename); return 0; } @@ -234,10 +264,17 @@ static int test_cfgfile_missing_section(void) { struct rte_cfgfile *cfgfile; + char filename[] = "/tmp/cfg_missing_section_XXXXXX.ini"; + int fd; - cfgfile = rte_cfgfile_load(CFG_FILES_ETC "/missing_section.ini", 0); - TEST_ASSERT_NULL(cfgfile, "Expected failure did not occur"); + fd = test_cfgfile_init(filename, missing_section_ini); + TEST_ASSERT(fd >= 0, "Failed to setup temp file"); + cfgfile = rte_cfgfile_load(filename, 0); + close(fd); + + TEST_ASSERT_NULL(cfgfile, "Expected failure did not occur"); + unlink(filename); return 0; } @@ -246,10 +283,14 @@ test_cfgfile_global_properties(void) { struct rte_cfgfile *cfgfile; const char *value; - int ret; + char filename[] = "/tmp/cfg_missing_section_XXXXXX.ini"; + int fd, ret; - cfgfile = rte_cfgfile_load(CFG_FILES_ETC "/missing_section.ini", - CFG_FLAG_GLOBAL_SECTION); + fd = test_cfgfile_init(filename, missing_section_ini); + TEST_ASSERT(fd >= 0, "Failed to setup temp file"); + + cfgfile = rte_cfgfile_load(filename, CFG_FLAG_GLOBAL_SECTION); + close(fd); TEST_ASSERT_NOT_NULL(cfgfile, "Failed to load config file"); ret = rte_cfgfile_num_sections(cfgfile, NULL, 0); @@ -268,6 +309,7 @@ test_cfgfile_global_properties(void) ret = rte_cfgfile_close(cfgfile); TEST_ASSERT_SUCCESS(ret, "Failed to close cfgfile"); + unlink(filename); return 0; } @@ -275,9 +317,14 @@ static int test_cfgfile_empty_file(void) { struct rte_cfgfile *cfgfile; - int ret; + char filename[] = "/tmp/cfg_empty_XXXXXX.ini"; + int fd, ret; - cfgfile = rte_cfgfile_load(CFG_FILES_ETC "/empty.ini", 0); + fd = test_cfgfile_init(filename, empty_ini); + TEST_ASSERT(fd >= 0, "Failed to setup temp file"); + + cfgfile = rte_cfgfile_load(filename, 0); + close(fd); TEST_ASSERT_NOT_NULL(cfgfile, "Failed to load config file"); ret = rte_cfgfile_num_sections(cfgfile, NULL, 0); @@ -286,15 +333,13 @@ test_cfgfile_empty_file(void) ret = rte_cfgfile_close(cfgfile); TEST_ASSERT_SUCCESS(ret, "Failed to close cfgfile"); + unlink(filename); return 0; } static int test_cfgfile(void) { - if (test_cfgfile_setup()) - return -1; - if (test_cfgfile_sample1()) return -1; @@ -325,10 +370,7 @@ test_cfgfile(void) if (test_cfgfile_empty_file()) return -1; - if (test_cfgfile_cleanup()) - return -1; - return 0; } -REGISTER_TEST_COMMAND(cfgfile_autotest, test_cfgfile); +REGISTER_FAST_TEST(cfgfile_autotest, true, true, test_cfgfile); diff --git a/app/test/test_cfgfiles/meson.build b/app/test/test_cfgfiles/meson.build new file mode 100644 index 0000000000..068b61044a --- /dev/null +++ b/app/test/test_cfgfiles/meson.build @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: BSD-3-Clause + +test_cfgfiles = files( + 'etc/empty.ini', + 'etc/empty_key_value.ini', + 'etc/invalid_section.ini', + 'etc/line_too_long.ini', + 'etc/missing_section.ini', + 'etc/realloc_sections.ini', + 'etc/sample1.ini', + 'etc/sample2.ini', +) + +# generate the header file used in cfgfile test +test_cfgfile_h = custom_target('test_cfgfile', + output: 'test_cfgfiles.h', + input: test_cfgfiles, + capture: true, + command: [ header_gen_cmd, '@INPUT@']) -- 2.43.0