From nobody Tue Nov 26 07:23:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709641077; cv=none; d=zohomail.com; s=zohoarc; b=JdFb7bMdI/aKqnD5SWfiPDlNCCA2tVUjj5gZNVeGHEOQSRC7kd9q04mDayK0EYAzkJv0qyZsJdNiKy1LC7V1ifFCYz0GinOXB5a3V0lf+CpK0aD1k6iSFde+btCLmw1FngbBdrq9AV/gAlix7K7MZVu0cqZCL5yyjLjw4gR7Qug= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709641077; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=WooNzOV/us8bLuMeAwrWGnmqqnwveEN5CVxp1t3KKRI=; b=IMhaWuhsS782A9KJrOWKnBhlzIP5YfOhJnUMQ+UX96R86V27rRgXhdASB8ftxBxFaUhbPic78OR8E2p5WaVN5QCvwTw8N5lMhG20IxseDcGxxE8L1wu+fy175/WWHhvjSGJmmS4Zh462vWEdWoc6sWT8JtSLgFBgMDNGbTvI3Cs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709641077616529.069397395678; Tue, 5 Mar 2024 04:17:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhTeb-0004V9-TJ; Tue, 05 Mar 2024 07:12:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhTdL-0001wH-PB for qemu-devel@nongnu.org; Tue, 05 Mar 2024 07:11:04 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhTch-0001UI-Vz for qemu-devel@nongnu.org; Tue, 05 Mar 2024 07:10:57 -0500 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-33e2268ed96so3532900f8f.3 for ; Tue, 05 Mar 2024 04:10:19 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id f10-20020a5d58ea000000b0033d4cf751b2sm14731989wrd.33.2024.03.05.04.10.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 04:10:12 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id B6EA15F9DA; Tue, 5 Mar 2024 12:10:06 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709640618; x=1710245418; darn=nongnu.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=WooNzOV/us8bLuMeAwrWGnmqqnwveEN5CVxp1t3KKRI=; b=ewhbZIQa42obNozwJyQmBs70PDQ1JmFoxR5gSo0sbtIn6lbPgkTcTlhPwX7ZtuWJ6I aJC2+ofUmMi2iOehRDiP/6oQjS+O+4MpslM/ILkrGEXWZ2XLZeH8xiOAFYytdbM0lK2M eAdHfJ9DyjZsmKpnndqOQzeuW8iTxloxU4mrf2scIEQPtzLq+oBXTpVLc8UiB8IGB2lc EN5Hlf7JLWz62/08Ci0qbAFxdFI+TXRoBIrfnMd8U+9tlErnOJthYKT7AJAli9OUUM8L vt8q6nnR59cEacKeeuPRgWNLon6PWXMgZ7baZ9mDY1Ala0a4Fm7udCI+hXM3+c7iv9Mv /hdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709640618; x=1710245418; 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=WooNzOV/us8bLuMeAwrWGnmqqnwveEN5CVxp1t3KKRI=; b=Ynwg7GVRyoPjU4erHtIG4oiQ3xLBxJmSD2aK9nJwzOn7ET6q3NtB2dAdiostM2pbwX v5zT9zucmG1uLG4YxPA68bdn7/49RxXEMgjwdaeJBa5fjk59ZcNxh4zh9xJfUJaS8egb 5RQQQ3Sx1hXhRxxMsoq8XrYZFWlkI+OJx1A5GLYJ53Edk2LCD96Z9dUQk9pIBKD28UNM 9b4KjlAF6mj9xGoZwEb44tomHfBl4QErg2tADCfHQHZeFPhCy1lmPWviLn2E2UruW8HZ TVnEmCvApDX0NPIJWbC0JPkT/wnkIC6K9g9O30OuFhLR3NviD8vyz8lWgnOffo2lvt89 No3w== X-Gm-Message-State: AOJu0YzAKtsWfTwolJUZ1fiVY+lDkVEpUSvBw+XWzSVzDAZw+O1jhsoZ 2IXHc0y5xS0xidB/ss4hXvNtEbE6uL5G3VZ4DCjNNAIJjRf5G9r3bK8Dr8fGC5A= X-Google-Smtp-Source: AGHT+IH/bFZkJLW9C0nEA6geVUtEWC+DP7m7ABlvX9K83JZCZItT7nWbkFN3prZoThSKDfhWw1SWAw== X-Received: by 2002:a5d:6986:0:b0:33d:d792:c7c7 with SMTP id g6-20020a5d6986000000b0033dd792c7c7mr7907924wru.10.1709640618264; Tue, 05 Mar 2024 04:10:18 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Wainer dos Santos Moschetta , Alistair Francis , Nicholas Piggin , Liu Zhiwei , Richard Henderson , Yanan Wang , qemu-s390x@nongnu.org, "Edgar E. Iglesias" , Eduardo Habkost , Daniel Henrique Barboza , Michael Rolnik , Daniel Henrique Barboza , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Laurent Vivier , Yoshinori Sato , Laurent Vivier , Thomas Huth , Peter Maydell , Mahmoud Mandour , Brad Smith , Alistair Francis , Brian Cain , Cleber Rosa , John Snow , Marcel Apfelbaum , Pierrick Bouvier , Palmer Dabbelt , Riku Voipio , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Weiwei Li , Bin Meng , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Beraldo Leal , Kyle Evans , David Hildenbrand , Song Gao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , Alexandre Iooss , Warner Losh , qemu-riscv@nongnu.org, Ilya Leoshkevich Subject: [PATCH 13/29] tests/tcg: Add two follow-fork-mode tests Date: Tue, 5 Mar 2024 12:09:49 +0000 Message-Id: <20240305121005.3528075-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240305121005.3528075-1-alex.bennee@linaro.org> References: <20240305121005.3528075-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709641079354100007 From: Ilya Leoshkevich Add follow-fork-mode child and and follow-fork-mode parent tests. Check for the obvious pitfalls, such as lingering breakpoints, catchpoints, and single-step mode. Signed-off-by: Ilya Leoshkevich Message-Id: <20240219141628.246823-13-iii@linux.ibm.com> Signed-off-by: Alex Benn=C3=A9e --- tests/tcg/multiarch/follow-fork-mode.c | 56 +++++++++++++++++++ tests/tcg/multiarch/Makefile.target | 17 +++++- .../gdbstub/follow-fork-mode-child.py | 40 +++++++++++++ .../gdbstub/follow-fork-mode-parent.py | 16 ++++++ 4 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/multiarch/follow-fork-mode.c create mode 100644 tests/tcg/multiarch/gdbstub/follow-fork-mode-child.py create mode 100644 tests/tcg/multiarch/gdbstub/follow-fork-mode-parent.py diff --git a/tests/tcg/multiarch/follow-fork-mode.c b/tests/tcg/multiarch/f= ollow-fork-mode.c new file mode 100644 index 00000000000..cb6b032b388 --- /dev/null +++ b/tests/tcg/multiarch/follow-fork-mode.c @@ -0,0 +1,56 @@ +/* + * Test GDB's follow-fork-mode. + * + * fork() a chain of processes. + * Parents sends one byte to their children, and children return their + * position in the chain, in order to prove that they survived GDB's fork() + * handling. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include +#include +#include +#include + +void break_after_fork(void) +{ +} + +int main(void) +{ + int depth =3D 42, err, i, fd[2], status; + pid_t child, pid; + ssize_t n; + char b; + + for (i =3D 0; i < depth; i++) { + err =3D pipe(fd); + assert(err =3D=3D 0); + child =3D fork(); + break_after_fork(); + assert(child !=3D -1); + if (child =3D=3D 0) { + close(fd[1]); + + n =3D read(fd[0], &b, 1); + close(fd[0]); + assert(n =3D=3D 1); + assert(b =3D=3D (char)i); + } else { + close(fd[0]); + + b =3D (char)i; + n =3D write(fd[1], &b, 1); + close(fd[1]); + assert(n =3D=3D 1); + + pid =3D waitpid(child, &status, 0); + assert(pid =3D=3D child); + assert(WIFEXITED(status)); + return WEXITSTATUS(status) - 1; + } + } + + return depth; +} diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Make= file.target index f11f3b084d7..979a0dd1bc2 100644 --- a/tests/tcg/multiarch/Makefile.target +++ b/tests/tcg/multiarch/Makefile.target @@ -106,6 +106,20 @@ run-gdbstub-catch-syscalls: catch-syscalls --bin $< --test $(MULTIARCH_SRC)/gdbstub/catch-syscalls.py, \ hitting a syscall catchpoint) =20 +run-gdbstub-follow-fork-mode-child: follow-fork-mode + $(call run-test, $@, $(GDB_SCRIPT) \ + --gdb $(GDB) \ + --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \ + --bin $< --test $(MULTIARCH_SRC)/gdbstub/follow-fork-mode-child.py, \ + following children on fork) + +run-gdbstub-follow-fork-mode-parent: follow-fork-mode + $(call run-test, $@, $(GDB_SCRIPT) \ + --gdb $(GDB) \ + --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \ + --bin $< --test $(MULTIARCH_SRC)/gdbstub/follow-fork-mode-parent.py, \ + following parents on fork) + else run-gdbstub-%: $(call skip-test, "gdbstub test $*", "need working gdb with $(patsubst -%= ,,$(TARGET_NAME)) support") @@ -113,7 +127,8 @@ endif EXTRA_RUNS +=3D run-gdbstub-sha1 run-gdbstub-qxfer-auxv-read \ run-gdbstub-proc-mappings run-gdbstub-thread-breakpoint \ run-gdbstub-registers run-gdbstub-prot-none \ - run-gdbstub-catch-syscalls + run-gdbstub-catch-syscalls run-gdbstub-follow-fork-mode-child \ + run-gdbstub-follow-fork-mode-parent =20 # ARM Compatible Semi Hosting Tests # diff --git a/tests/tcg/multiarch/gdbstub/follow-fork-mode-child.py b/tests/= tcg/multiarch/gdbstub/follow-fork-mode-child.py new file mode 100644 index 00000000000..72a6e440c08 --- /dev/null +++ b/tests/tcg/multiarch/gdbstub/follow-fork-mode-child.py @@ -0,0 +1,40 @@ +"""Test GDB's follow-fork-mode child. + +SPDX-License-Identifier: GPL-2.0-or-later +""" +from test_gdbstub import main, report + + +def run_test(): + """Run through the tests one by one""" + gdb.execute("set follow-fork-mode child") + # Check that the parent breakpoints are unset. + gdb.execute("break break_after_fork") + # Check that the parent syscall catchpoints are unset. + # Skip this check on the architectures that don't have them. + have_fork_syscall =3D False + for fork_syscall in ("fork", "clone", "clone2", "clone3"): + try: + gdb.execute("catch syscall {}".format(fork_syscall)) + except gdb.error: + pass + else: + have_fork_syscall =3D True + gdb.execute("continue") + for i in range(42): + if have_fork_syscall: + # syscall entry. + if i % 2 =3D=3D 0: + # Check that the parent single-stepping is turned off. + gdb.execute("si") + else: + gdb.execute("continue") + # syscall exit. + gdb.execute("continue") + # break_after_fork() + gdb.execute("continue") + exitcode =3D int(gdb.parse_and_eval("$_exitcode")) + report(exitcode =3D=3D 42, "{} =3D=3D 42".format(exitcode)) + + +main(run_test) diff --git a/tests/tcg/multiarch/gdbstub/follow-fork-mode-parent.py b/tests= /tcg/multiarch/gdbstub/follow-fork-mode-parent.py new file mode 100644 index 00000000000..5c2fe722088 --- /dev/null +++ b/tests/tcg/multiarch/gdbstub/follow-fork-mode-parent.py @@ -0,0 +1,16 @@ +"""Test GDB's follow-fork-mode parent. + +SPDX-License-Identifier: GPL-2.0-or-later +""" +from test_gdbstub import main, report + + +def run_test(): + """Run through the tests one by one""" + gdb.execute("set follow-fork-mode parent") + gdb.execute("continue") + exitcode =3D int(gdb.parse_and_eval("$_exitcode")) + report(exitcode =3D=3D 0, "{} =3D=3D 0".format(exitcode)) + + +main(run_test) --=20 2.39.2