From nobody Mon Feb 9 17:24:27 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1711632840681941.541192397645; Thu, 28 Mar 2024 06:34:00 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 32A911730; Thu, 28 Mar 2024 09:33:59 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 38C25220D; Thu, 28 Mar 2024 09:23:10 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2431D1F3A; Thu, 28 Mar 2024 09:22:59 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 5C0071F2C for ; Thu, 28 Mar 2024 09:22:45 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-17-8zLHTQFtP5K8NXvZrzt7Jw-1; Thu, 28 Mar 2024 09:22:43 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3359A185A78E for ; Thu, 28 Mar 2024 13:22:43 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0D97200A384 for ; Thu, 28 Mar 2024 13:22:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: 8zLHTQFtP5K8NXvZrzt7Jw-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 08/35] vrishtest: Prepare for simpler testing - echo tests Date: Thu, 28 Mar 2024 14:22:30 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 3OUHPYO3W5JVG4LES6ZBHOWQH6YRIGER X-Message-ID-Hash: 3OUHPYO3W5JVG4LES6ZBHOWQH6YRIGER X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1711632841728100001 Embedding the expected output in a C source code makes it very hard to extend tests. In order to be able to test the outputs against data in files on disk we need better naming of the tests themselves. Use virTestCounterNext/Reset with appropriate tags to give reasonable names to the 'virsh echo' tests' and prepare the 'DO_TEST' macro for wider use. Signed-off-by: Peter Krempa --- tests/virshtest.c | 99 +++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 55 deletions(-) diff --git a/tests/virshtest.c b/tests/virshtest.c index 4b02ef3a49..fc1246a96d 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -581,77 +581,66 @@ mymain(void) ret =3D -1; \ } while (0); - /* It's a bit awkward listing result before argument, but that's a - * limitation of C99 vararg macros. */ -# define DO_TEST(i, result, ...) \ +# define DO_TEST_FULL(testname_, filter, result, ...) \ do { \ - const char *myargv[] =3D { VIRSH_DEFAULT, __VA_ARGS__, NULL }; \ + const char *testname =3D testname_; \ + const char *myargv[] =3D { __VA_ARGS__, NULL }; \ const struct testInfo info =3D { NULL, NULL, myargv, result }; \ - if (virTestRun("virsh echo " #i, testCompare, &info) < 0) \ + if (virTestRun(testname, testCompare, &info) < 0) \ ret =3D -1; \ } while (0) + /* automatically numbered test invocation */ +# define DO_TEST(result, ...) \ + DO_TEST_FULL(virTestCounterNext(), NULL, result, VIRSH_DEFAULT, __VA_A= RGS__); + + /* Arg parsing quote removal tests. */ - DO_TEST(3, "a b\n", - "echo a \t b"); - DO_TEST(4, "a \t b\n", - "echo \"a \t b\""); - DO_TEST(5, "a \t b\n", - "echo 'a \t b'"); - DO_TEST(6, "a \t b\n", - "echo a\\ \\\t\\ b"); - DO_TEST(9, "' \" \\;echo\ta\n", - "echo", "'", "\"", "\\;echo\ta"); - DO_TEST(10, "' \" ;echo a\n", - "echo \\' \\\" \\;echo\ta"); - DO_TEST(11, "' \" \\\na\n", - "echo \\' \\\" \\\\;echo\ta"); - DO_TEST(12, "' \" \\\\\n", - "echo \"'\" '\"' '\\'\"\\\\\""); + virTestCounterReset("echo-quote-removal-"); + DO_TEST("a b\n", "echo a \t b"); + DO_TEST("a \t b\n", "echo \"a \t b\""); + DO_TEST("a \t b\n", "echo 'a \t b'"); + DO_TEST("a \t b\n", "echo a\\ \\\t\\ b"); + DO_TEST("' \" \\;echo\ta\n", "echo", "'", "\"", "\\;echo\ta"); + DO_TEST("' \" ;echo a\n", "echo \\' \\\" \\;echo\ta"); + DO_TEST("' \" \\\na\n", "echo \\' \\\" \\\\;echo\ta"); + DO_TEST("' \" \\\\\n", "echo \"'\" '\"' '\\'\"\\\\\""); /* Tests of echo flags. */ DO_TEST_SCRIPT("echo-escaping", NULL, VIRSH_DEFAULT); - DO_TEST(13, "a A 0 + * ; . ' \" / ? =3D \n < > &\n", - "echo", "a", "A", "0", "+", "*", ";", ".", "'", "\"", "/", "?", - "=3D", " ", "\n", "<", ">", "&"); - DO_TEST(14, "a A 0 + '*' ';' . ''\\''' '\"' / '?' =3D ' ' '\n' '<' '>'= '&'\n", - "echo", "--shell", "a", "A", "0", "+", "*", ";", ".", "'", "\"= ", - "/", "?", "=3D", " ", "\n", "<", ">", "&"); - DO_TEST(15, "a A 0 + * ; . ' " / ? =3D \n < > &\= n", - "echo", "--xml", "a", "A", "0", "+", "*", ";", ".", "'", "\"", - "/", "?", "=3D", " ", "\n", "<", ">", "&"); + + virTestCounterReset("echo-escaping-"); + DO_TEST("a A 0 + * ; . ' \" / ? =3D \n < > &\n", "echo", "a", "A", "= 0", "+", "*", ";", ".", "'", "\"", "/", "?", "=3D", " ", "\n", "<", ">", "&= "); + DO_TEST("a A 0 + '*' ';' . ''\\''' '\"' / '?' =3D ' ' '\n' '<' '>' '&'= \n", "echo", "--shell", "a", "A", "0", "+", "*", ";", ".", "'", "\"", "/", = "?", "=3D", " ", "\n", "<", ">", "&"); + DO_TEST("a A 0 + * ; . ' " / ? =3D \n < > &\n", = "echo", "--xml", "a", "A", "0", "+", "*", ";", ".", "'", "\"", "/", "?", "= =3D", " ", "\n", "<", ">", "&"); /* Tests of -- handling. */ - DO_TEST(25, "a\n", - "--", "echo", "--shell", "a"); - DO_TEST(26, "a\n", - "--", "echo", "a", "--shell"); - DO_TEST(27, "a --shell\n", - "--", "echo", "--", "a", "--shell"); - DO_TEST(28, "-- --shell a\n", - "echo", "--", "--", "--shell", "a"); - DO_TEST(29, "a\n", - "echo --s\\h'e'\"l\"l -- a"); - DO_TEST(30, "--shell a\n", - "echo \t '-'\"-\" \t --shell \t a"); + virTestCounterReset("dash-dash-argument-"); + DO_TEST("a\n", "--", "echo", "--shell", "a"); + DO_TEST("a\n", "--", "echo", "a", "--shell"); + DO_TEST("a --shell\n", "--", "echo", "--", "a", "--shell"); + DO_TEST("-- --shell a\n", "echo", "--", "--", "--shell", "a"); + DO_TEST("a\n", "echo --s\\h'e'\"l\"l -- a"); + DO_TEST("--shell a\n", "echo \t '-'\"-\" \t --shell \t a"); /* Tests of alias handling. */ DO_TEST_SCRIPT("echo-alias", NULL, VIRSH_DEFAULT); - DO_TEST(33, "hello\n", "echo", "--str", "hello"); + DO_TEST_FULL("echo-alias-argv", NULL, "hello\n", VIRSH_DEFAULT, "echo"= , "--str", "hello"); /* Tests of multiple commands. */ - DO_TEST(36, "a\nb\n", " echo a; echo b;"); - DO_TEST(37, "a\nb\n", "\necho a\n echo b\n"); - DO_TEST(38, "a\nb\n", "ec\\\nho a\n echo \\\n b;"); - DO_TEST(39, "a\n b\n", "\"ec\\\nho\" a\n echo \"\\\n b\";"); - DO_TEST(40, "a\n\\\n b\n", "ec\\\nho a\n echo '\\\n b';"); - DO_TEST(41, "a\n", "echo a # b"); - DO_TEST(42, "a\nc\n", "echo a #b\necho c"); - DO_TEST(43, "a\nc\n", "echo a # b\\\necho c"); - DO_TEST(44, "a # b\n", "echo a '#' b"); - DO_TEST(45, "a # b\n", "echo a \\# b"); - DO_TEST(46, "a\n", "#unbalanced; 'quotes\"\necho a # b"); - DO_TEST(47, "a\n", "\\# ignored;echo a\n'#also' ignored"); + virTestCounterReset("multiple-commands-"); + DO_TEST("a\nb\n", " echo a; echo b;"); + DO_TEST("a\nb\n", "\necho a\n echo b\n"); + DO_TEST("a\nb\n", "ec\\\nho a\n echo \\\n b;"); + DO_TEST("a\n b\n", "\"ec\\\nho\" a\n echo \"\\\n b\";"); + DO_TEST("a\n\\\n b\n", "ec\\\nho a\n echo '\\\n b';"); + DO_TEST("a\n", "echo a # b"); + DO_TEST("a\nc\n", "echo a #b\necho c"); + DO_TEST("a\nc\n", "echo a # b\\\necho c"); + DO_TEST("a # b\n", "echo a '#' b"); + DO_TEST("a # b\n", "echo a \\# b"); + DO_TEST("a\n", "#unbalanced; 'quotes\"\necho a # b"); + DO_TEST("a\n", "\\# ignored;echo a\n'#also' ignored"); /* test of splitting in vshStringToArray */ DO_TEST_SCRIPT("echo-split", NULL, VIRSH_DEFAULT, "-q"); --=20 2.44.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org