From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id D81B83858C74 for ; Sun, 21 Jan 2024 03:57:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D81B83858C74 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D81B83858C74 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705809434; cv=none; b=f/DCMJf0THmrSJoAPUr1hU6ZNfGOLYl0ynFOfmAAPP6AFkXwdmfILu9jOGvq+yNfS5klfMxKD6woBoVdMGDlstEoAhdzUIhNwp80NLaCo/ifPsUUFiWOmrS8+/5IKrMWh9N9a2mMM4AEbyYHO6sAHWPRTgnulDkKNV8WQQ9vp1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705809434; c=relaxed/simple; bh=W3mOmtjteZcf3Li7O3JfkmwFZwJ0iczUW0SRVABpLE4=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=Ko6D3FWpWuV2hIVBG2dIwi72DT2I45ILdVrVbJOP8aUTp7ybaTVdHYLsnOYBD1OiXfB263PEgMB6UKd8lqHLFdPl03uRYtS5TBs3hwPgpPXEcL3acl4Ki20gZcAxa/g8nO8qqGJtEEzbgpGsF2rbr35yO2SBWHll936LY83HhTk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705809432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DZeWRc5zrVYNSHKFu6kjVYhzwuGKFGfrLFMG8ps03/Q=; b=Kih4kd4nLL1z71n3cS5Ejx4fRNvRAm6pp8KK7aShzbxyapZPab/FHZLTDFTIv86zYBNm0E 3lygbS9/DdWR4QKHMJQbJNhVd8Q0DbkyE6rEGp1mCk/hGTPM0yE7T00Y0+jhaWNVcbSBNy 22EuCdIYozNGfFzcpRXLP6iKeZucFRk= Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-637-5epoziX1PdqW83Nc928rHw-1; Sat, 20 Jan 2024 22:57:11 -0500 X-MC-Unique: 5epoziX1PdqW83Nc928rHw-1 Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3bda48b93ffso2562399b6e.2 for ; Sat, 20 Jan 2024 19:57:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705809430; x=1706414230; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DZeWRc5zrVYNSHKFu6kjVYhzwuGKFGfrLFMG8ps03/Q=; b=M1dPlwUwY0iUiHNhdVl8nNJ0GwklDUaobV8dauL9EzpytV/GIuOR9IvCcFope1P+N5 vq7w5Q13RTPOoYrK/x0R4Ed3VbqAwoBlrsgrrEFMbbBhsPooLhM294885ttBJAxgxKNr fa3ENfvvByUsBVsi0FcOS47/OIU/Hk0DCWmuaozl9z69eqqXQWPXFuV1R7uhOD+aDDJS +h4wCHCLYXwBK/cp/Y1hamcpXTFylOPPgbGUokV6vpjE2d6yRbiUEK/wM3AIhLQMsfKr +2BGR/4eOW66G0qzLi9pW0sblDPfWlHTxHwsiVPsKm1q20SP8hzf5sgPmy9I0N+Er/XL FgeQ== X-Gm-Message-State: AOJu0YyufkCK6XWBH3ZP0I92fmbH5C74xbWmtv6hkm7WJZoVxPEYlzgI m6WHS/sSa4DEwXvjh4qTygvhq8YMvJ7tk5NM6aVghQ5tjtV8cwN948qcW3IppcOrxQ0GFb/DYtd yuYT5hv/TsNjlK/f8jNXtsxuclwIlqnYrWsEXpmliQf2xWKpZkNnVlaiqp8XvY28sH4E= X-Received: by 2002:a05:6808:1186:b0:3bd:5a62:494a with SMTP id j6-20020a056808118600b003bd5a62494amr2450355oil.95.1705809430202; Sat, 20 Jan 2024 19:57:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IH4NU8dC55SFdfG+4JUEHOGFGR7CMZki//GDcBZnPhjuU5+YEwMJab1EXe1OlMZwmxFCNIYvw== X-Received: by 2002:a05:6808:1186:b0:3bd:5a62:494a with SMTP id j6-20020a056808118600b003bd5a62494amr2450347oil.95.1705809429931; Sat, 20 Jan 2024 19:57:09 -0800 (PST) Received: from [150.1.200.12] (174-21-92-140.tukw.qwest.net. [174.21.92.140]) by smtp.gmail.com with ESMTPSA id db11-20020a17090ad64b00b002900eeada1asm6834134pjb.43.2024.01.20.19.57.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 20 Jan 2024 19:57:09 -0800 (PST) Message-ID: <7c8aa778-7033-431f-b6c1-aab940e22e64@redhat.com> Date: Sat, 20 Jan 2024 19:57:09 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 10/16] gdb: add remote argument passing self tests To: Andrew Burgess , gdb-patches@sourceware.org References: From: Keith Seitz In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Just some typos, I think. On 1/9/24 06:26, Andrew Burgess wrote: > diff --git a/gdb/unittests/remote-arg-selftests.c b/gdb/unittests/remote-arg-selftests.c > new file mode 100644 > index 00000000000..3240ab9aeea > --- /dev/null > +++ b/gdb/unittests/remote-arg-selftests.c > @@ -0,0 +1,189 @@ > +/* Self tests for GDB's argument splitting and merging. > + > + Copyright (C) 2023 Free Software Foundation, Inc. > + > + This file is part of GDB. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +#include "defs.h" > +#include "gdbsupport/selftest.h" > +#include "gdbsupport/buildargv.h" > +#include "gdbsupport/common-inferior.h" > +#include "gdbsupport/remote-args.h" > + > +namespace selftests { > +namespace remote_args_tests { > + > +/* The data needed to perform a single remote argument test. */ > +struct arg_test_desc > +{ > + /* The original inferior argument string. */ > + std::string input; > + > + /* The individual arguments once they have been split. */ > + std::vector split; > + > + /* The new inferior argument string, created by joining SPLIT. */ > + std::string joined; > +}; > + > +/* The list of tests. */ > +arg_test_desc desc[] = { > + { "abc", { "abc" }, "abc" }, > + { "a b c", { "a", "b", "c" }, "a b c" }, > + { "\"a b\" 'c d'", { "a b", "c d" }, "a\\ b c\\ d" }, > + { "\\' \\\"", { "'", "\"" }, "\\' \\\"" }, > + { "'\\'", { "\\" }, "\\\\" }, > + { "\"\\\\\" \"\\\\\\\"\"", { "\\", "\\\"" }, "\\\\ \\\\\\\"" }, > + { "\\ \" \" ' '", { " ", " ", " "}, "\\ \\ \\ " }, > + { "\"'\"", { "'" }, "\\'" }, > + { "'\"' '\\\"'", { "\"", "\\\"" } , "\\\" \\\\\\\""}, > + { "\"first arg\" \"\" \"third-arg\" \"'\" \"\\\"\" \"\\\\\\\"\" \" \" \"\"", > + { "first arg", "", "third-arg", "'", "\"", "\\\""," ", "" }, > + "first\\ arg '' third-arg \\' \\\" \\\\\\\" \\ ''"}, > + { "\"\\a\" \"\\&\" \"\\#\" \"\\<\" \"\\^\"", > + { "\\a", "\\&", "\\#" , "\\<" , "\\^"}, > + "\\\\a \\\\\\& \\\\\\# \\\\\\< \\\\\\^" }, > + { "1 '\n' 3", { "1", "\n", "3" }, "1 '\n' 3" }, > +}; > + > +/* Convert a std::vector into std::vector. This > + requires copying all of the string content. This class takes care of > + freeing the memory once we are done with it. */ > + > +struct args_as_c_strings > +{ > + args_as_c_strings (std::vector args) > + { > + for (const auto & a : args) > + m_data.push_back (xstrdup (a.c_str ())); > + } > + > + ~args_as_c_strings () > + { > + free_vector_argv (m_data); > + } > + > + std::vector &get () > + { > + return m_data; > + } > + > +private: > + std::vector m_data; > +}; > + > +/* Run the remote argument passing self tests. */ > + > +static void > +self_test () > +{ > + int failure_count = 0; > + for (const auto &d : desc) > + { > + if (run_verbose ()) > + { > + if (&d != &desc[0]) > + debug_printf ("------------------------------\n"); > + debug_printf ("Input (%s)\n", d.input.c_str ()); > + } > + > + /* Split argument string into individual arguments. */ > + std::vector split_args = gdb::remote_args::split (d.input); > + > + if (run_verbose ()) > + { > + debug_printf ("Split:\n"); > + > + size_t len = std::max (split_args.size (), d.split.size ()); > + for (size_t i = 0; i < len; ++i) > + { > + const char *got = "N/A"; > + const char *expected = got; > + > + if (i < split_args.size ()) > + got = split_args[i].c_str (); > + > + if (i < d.split.size ()) > + expected = d.split[i].c_str (); > + > + debug_printf (" got (%s), expected (%s)\n", got, expected); > + } > + } > + > + if (split_args != d.split) > + { > + ++failure_count; > + if (run_verbose ()) > + debug_printf ("FAIL\n"); > + continue; > + } > + > + /* Now join the arguments. */ > + args_as_c_strings split_args_c_str (split_args); > + std::string joined_args > + = gdb::remote_args::join (split_args_c_str.get ()); > + > + if (run_verbose ()) > + debug_printf ("Joined (%s), expected (%s)\n", > + joined_args.c_str (), d.joined.c_str ()); > + > + if (joined_args != d.joined) > + { > + ++failure_count; > + if (run_verbose ()) > + debug_printf ("FAIL\n"); > + continue; > + } > + > + /* The contents of JOINED_ARGS will not be identical to D.INPUT. > + There are multiple ways that an argument can be escaped, and out "and our"? > + join function just picks one. However, if we split JOINED_ARGS > + again then each individual argument should be the same as those in > + SPLIT_ARGS. So lets test that next. */ "let's" > + std::vector split_args_v2 > + = gdb::remote_args::split (joined_args); > + > + if (split_args_v2 != split_args) > + { > + ++failure_count; > + if (run_verbose ()) > + { > + debug_printf ("Re-split:\n"); > + for (const auto &a : split_args_v2) > + debug_printf (" got (%s)\n", a.c_str ()); > + debug_printf ("FAIL\n"); > + } > + continue; > + } > + > + if (run_verbose ()) > + debug_printf ("PASS\n"); > + } > + > + SELF_CHECK (failure_count == 0); > +} > + > +} /* namespace remote_args_tests */ > +} /* namespace selftests */ > + > +void _initialize_remote_arg_selftests (); > + > +void > +_initialize_remote_arg_selftests () > +{ > + selftests::register_test ("remote-args", > + selftests::remote_args_tests::self_test); > +}