From patchwork Wed Mar 6 14:40:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 778293 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:47:b0:33e:474f:8c56 with SMTP id k7csp324624wrx; Wed, 6 Mar 2024 06:41:14 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVQSywLmI+rhH2mQaS3PjjqWk7Krbblf0OS5RvfFVCInA2+lzQ0rhmAmyP1cVzv4hXAPhl+7cypEYCzuqGXHX6y X-Google-Smtp-Source: AGHT+IH+xRau4EJXX1EVst1rIl0TILQWz3dtZ/DqUfa394620hBxON2Rvckib74icXSPN9hOmepq X-Received: by 2002:a05:6102:2371:b0:470:4716:70ca with SMTP id o17-20020a056102237100b00470471670camr4978561vsa.6.1709736074634; Wed, 06 Mar 2024 06:41:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709736074; cv=none; d=google.com; s=arc-20160816; b=YL6Ex0iRlzu2Rl4Q510apmLUyYyKVB+iPpziePT6VR8OmDkUhbzXn15dXfILEfVNrm mXOTJKqDb1/Kdh+JFVmrny4AP08RR+Cx9XmLJoJbtN1Q7KJANL7csd6EExW2bK78nres ARujJhkxrd/Zkl4y+id0ksvTfJLaza9ehhFCWmVqs7ol8Z6xBirxb9ndW6mCYeFfe5it OSa7xJxLoPwEqG7vQv9PW9ladyPXTrU9rU3JmVv8JOi2dIEIG6e5yE3HUQGn8ZxJe5XJ 3nUSJEu/cyZgFnPNPVUIJVzZxiRba/lkH+NW1o3QSrlswEDDLEPh66c+I9cG/FPNjxwV tR8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=M1lmVAwQWxhk52Kx07GGW6iRDF0OX21kw+KdP65AfDk=; fh=U8v/Dtss/m4oPeJtZ17DHKEvZGyePY/+mu3CqtBX2ks=; b=UNiYJUTnL/t9ltV4elZxwy7wu9878IEcpMvX7DlAFCNnCMCg4tMcg7+DgFwUb6V13U N0dQGElMBno/iLvy7P4CykgYB58uwd94qurjp9GP/fsqNPBLfWOOm5NpSFlYaYYC8ZRz TStNTD2hm1mb3LUqtnK1IrWg3elBIXqdY1blwhd9n7+YmAu7jt3ikjZuVLej79g1d1Tr LdEK1swJQDNQXpovrb0Tc8A91fQIVyOVumfiSSJfD0EQHOYy/FaT/oxtTc/X76VhBUYU y5ruHey4VsuL94wrTy2KCSmxC2CgkNqDleB/fMSWHUX20sW0ma2TlvZ3odIAQD94egLN JQ0A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RTvPlTHg; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j2-20020a67e3a2000000b0046d1f69c4c2si1963454vsm.272.2024.03.06.06.41.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Mar 2024 06:41:14 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RTvPlTHg; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhsS9-0007m0-V1; Wed, 06 Mar 2024 09:41:05 -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 1rhsS8-0007h7-Dx for qemu-devel@nongnu.org; Wed, 06 Mar 2024 09:41:04 -0500 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhsS0-0001UP-HF for qemu-devel@nongnu.org; Wed, 06 Mar 2024 09:41:03 -0500 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-33e17fc5aceso563896f8f.0 for ; Wed, 06 Mar 2024 06:40:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709736054; x=1710340854; 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=M1lmVAwQWxhk52Kx07GGW6iRDF0OX21kw+KdP65AfDk=; b=RTvPlTHgtQYwu5QcxAuwdIdOcfLs+cThVHWD2ul8yxP3ZV1X1debIKcihOyh7hGqks VyZP5R8O6gfKp2mXQ9T03LuiLn052+zomz0RYOgHMpUmZ/np9+nSgauw3SnCExuKvAVo RC29PMnQ94yZblf3SAsvBByhJMNssJE6w66ExmKWq/frmXgjZ4Nc3zEOufnH4TA1ZeII MhSVUunDV25n4IoQvWN8Bd1yzYPlEu/QVbA76/N0hRdgbBQhO8+/tDR9df4abJcZNaiH d3NEN6VbqwHJza753ZhvmUueqJ8oQkWOV3u2eKLfilQxNkW7TkSNYQSsLXhZEGIOw+XH UxhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709736054; x=1710340854; 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=M1lmVAwQWxhk52Kx07GGW6iRDF0OX21kw+KdP65AfDk=; b=wipSJGlqBQefF3ry+Uq2lIN29Cb2WBQg2B57y4E9yvoFIJFm83u+oUaHy6eeotY6ji pGMb0nYQfYkavJ+WwUS6KjJgOr97Q6hoZRIln7SgIUbso/S2qz4pqWKuvytczxG7Q4Uf bYN1HoMTasajWzH2ZXgRJ+Tjy4If8tA96dkpARZ9Sif/SqJ6G3K5/ZED1UQQ0uUy7i0J uFwEfiUN4mcNPSUKCyWKw3W6wFBD1c/Yc3PmT/E+529B8Ffx7LNh2TBe3d9BLKlloPMD wRJIaoMKqu1cL7zRhTSlwm9DIPOgXoCdfm2RNvbeYLAhMazZqhASva46XzI6SvFJxtuE fWSA== X-Gm-Message-State: AOJu0YxGMcK49H8j+G8A6mM2jOWuCi8oDrumjFSitFmCek2oDQdIqrxz CSjr8lwrvXTx3PT9lClugMm014c3SvcqewV6lMDlHulx97wEMM8UQUMNDUyTxEY= X-Received: by 2002:a5d:4d82:0:b0:33d:f60c:53e2 with SMTP id b2-20020a5d4d82000000b0033df60c53e2mr5312132wru.11.1709736053824; Wed, 06 Mar 2024 06:40:53 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id bv28-20020a0560001f1c00b0033d70dd0e04sm18074128wrb.8.2024.03.06.06.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 06:40:49 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id CCB115F891; Wed, 6 Mar 2024 14:40:42 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Subject: [PULL 13/29] tests/tcg: Add two follow-fork-mode tests Date: Wed, 6 Mar 2024 14:40:25 +0000 Message-Id: <20240306144041.3787188-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240306144041.3787188-1-alex.bennee@linaro.org> References: <20240306144041.3787188-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x432.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée Message-Id: <20240305121005.3528075-14-alex.bennee@linaro.org> diff --git a/tests/tcg/multiarch/follow-fork-mode.c b/tests/tcg/multiarch/follow-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 = 42, err, i, fd[2], status; + pid_t child, pid; + ssize_t n; + char b; + + for (i = 0; i < depth; i++) { + err = pipe(fd); + assert(err == 0); + child = fork(); + break_after_fork(); + assert(child != -1); + if (child == 0) { + close(fd[1]); + + n = read(fd[0], &b, 1); + close(fd[0]); + assert(n == 1); + assert(b == (char)i); + } else { + close(fd[0]); + + b = (char)i; + n = write(fd[1], &b, 1); + close(fd[1]); + assert(n == 1); + + pid = waitpid(child, &status, 0); + assert(pid == child); + assert(WIFEXITED(status)); + return WEXITSTATUS(status) - 1; + } + } + + return depth; +} diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Makefile.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) +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 += 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 # 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 = 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 = True + gdb.execute("continue") + for i in range(42): + if have_fork_syscall: + # syscall entry. + if i % 2 == 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 = int(gdb.parse_and_eval("$_exitcode")) + report(exitcode == 42, "{} == 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 = int(gdb.parse_and_eval("$_exitcode")) + report(exitcode == 0, "{} == 0".format(exitcode)) + + +main(run_test)