From patchwork Tue Sep 20 07:30:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12981478 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A5FAC6FA91 for ; Tue, 20 Sep 2022 07:32:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229437AbiITHcP (ORCPT ); Tue, 20 Sep 2022 03:32:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229572AbiITHcM (ORCPT ); Tue, 20 Sep 2022 03:32:12 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECCF15727D; Tue, 20 Sep 2022 00:32:11 -0700 (PDT) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28K7C0If005810; Tue, 20 Sep 2022 07:32:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : mime-version; s=pp1; bh=/wpnWlchDiGjvVFkjqRLpcTYWZijj2Qkk4hqEz7u4wY=; b=TzSOl9p6Rgm5Pt/0A2OONBCl7kzmm3xn0kv9qijI+XBts4/YGOjcI/ymxFOPUNLXI7L0 3pcRDMr/V4rpzUD02Q5V40aFQh7ka7001HKmqz9OSN9DyhRqj1/KSHidtpLu+Un6LyCT /ma5V71T7MfAvGRL68ltzSgJrFtgqzUPaIwqd4LblFseO+nVU5tBEWmir/BxBCXu8EKi UpNF17epAgqRtNSS/Rv3peC7Lb3WmvmbZ/+hN2ooHzxHyVQ0JgADvFJeIAJ/I2I4EpMS pzWzXFGZEzzoGT9AWPI/oEdvYhcO9EMMNmyPun4XhLdYlh/CrqfHB7kO4XWSgsK1i3Zx uA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jq8wu8hwk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Sep 2022 07:32:11 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 28K7CH4N007199; Tue, 20 Sep 2022 07:32:11 GMT Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jq8wu8hv5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Sep 2022 07:32:11 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28K7KnWi021819; Tue, 20 Sep 2022 07:32:08 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma02fra.de.ibm.com with ESMTP id 3jn5v8tj8y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Sep 2022 07:32:08 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28K7W54T54067504 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Sep 2022 07:32:05 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F384E11C050; Tue, 20 Sep 2022 07:32:04 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 04A6A11C04A; Tue, 20 Sep 2022 07:32:04 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 20 Sep 2022 07:32:03 +0000 (GMT) From: Janosch Frank To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, frankja@linux.ibm.com, david@redhat.com, borntraeger@de.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org, imbrenda@linux.ibm.com, thuth@redhat.com, Nico Boehr Subject: [kvm-unit-tests GIT PULL 05/11] runtime: add support for panic tests Date: Tue, 20 Sep 2022 07:30:29 +0000 Message-Id: <20220920073035.29201-6-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220920073035.29201-1-frankja@linux.ibm.com> References: <20220920073035.29201-1-frankja@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: AXbuuk03gs9yDQEN_95slE4BAWfTFQT7 X-Proofpoint-GUID: ixqTCWGMMxAQsvx4haIkT29z2PVz_p2d X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-20_02,2022-09-16_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 mlxscore=0 malwarescore=0 suspectscore=0 phishscore=0 priorityscore=1501 adultscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209200045 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Nico Boehr QEMU supports a guest state "guest-panicked" which indicates something in the guest went wrong. For example on s390x, when an external interrupt loop was triggered. Since the guest does not continue to run when it is in the guest-panicked state, it is currently impossible to write panicking tests in kvm-unit-tests. Support from the runtime is needed to check that the guest enters the guest-panicked state. Similar to migration tests, add a new "panic" group. Tests in this group must enter the guest-panicked state to succeed. The runtime will spawn a QEMU instance, connect to the QMP and listen for events. To parse the QMP protocol, jq[1] is used. Same as with netcat in the migration tests, panic tests won't run if jq is not installed. The guest is created in the stopped state and only is resumed when connection to the QMP was successful. This ensures no events are missed between QEMU start and the connect to the QMP. [1] https://stedolan.github.io/jq/ Signed-off-by: Nico Boehr Reviewed-by: Thomas Huth Reviewed-by: Claudio Imbrenda Acked-by: Janosch Frank Link: https://lore.kernel.org/r/20220823103833.156942-2-nrb@linux.ibm.com Message-Id: <20220823103833.156942-2-nrb@linux.ibm.com> Signed-off-by: Janosch Frank --- s390x/run | 2 +- scripts/arch-run.bash | 49 +++++++++++++++++++++++++++++++++++++++++++ scripts/runtime.bash | 3 +++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/s390x/run b/s390x/run index 24138f68..f1111dbd 100755 --- a/s390x/run +++ b/s390x/run @@ -30,7 +30,7 @@ M+=",accel=$ACCEL" command="$qemu -nodefaults -nographic $M" command+=" -chardev stdio,id=con0 -device sclpconsole,chardev=con0" command+=" -kernel" -command="$(migration_cmd) $(timeout_cmd) $command" +command="$(panic_cmd) $(migration_cmd) $(timeout_cmd) $command" # We return the exit code via stdout, not via the QEMU return code run_qemu_status $command "$@" diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index 0dfaf017..51e4b97b 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -104,6 +104,14 @@ qmp () echo '{ "execute": "qmp_capabilities" }{ "execute":' "$2" '}' | ncat -U $1 } +qmp_events () +{ + while ! test -S "$1"; do sleep 0.1; done + echo '{ "execute": "qmp_capabilities" }{ "execute": "cont" }' | + ncat --no-shutdown -U $1 | + jq -c 'select(has("event"))' +} + run_migration () { if ! command -v ncat >/dev/null 2>&1; then @@ -164,6 +172,40 @@ run_migration () return $ret } +run_panic () +{ + if ! command -v ncat >/dev/null 2>&1; then + echo "${FUNCNAME[0]} needs ncat (netcat)" >&2 + return 77 + fi + + if ! command -v jq >/dev/null 2>&1; then + echo "${FUNCNAME[0]} needs jq" >&2 + return 77 + fi + + qmp=$(mktemp -u -t panic-qmp.XXXXXXXXXX) + + trap 'kill 0; exit 2' INT TERM + trap 'rm -f ${qmp}' RETURN EXIT + + # start VM stopped so we don't miss any events + eval "$@" -chardev socket,id=mon1,path=${qmp},server=on,wait=off \ + -mon chardev=mon1,mode=control -S & + + panic_event_count=$(qmp_events ${qmp} | jq -c 'select(.event == "GUEST_PANICKED")' | wc -l) + if [ "$panic_event_count" -lt 1 ]; then + echo "FAIL: guest did not panic" + ret=3 + else + # some QEMU versions report multiple panic events + echo "PASS: guest panicked" + ret=1 + fi + + return $ret +} + migration_cmd () { if [ "$MIGRATION" = "yes" ]; then @@ -171,6 +213,13 @@ migration_cmd () fi } +panic_cmd () +{ + if [ "$PANIC" = "yes" ]; then + echo "run_panic" + fi +} + search_qemu_binary () { local save_path=$PATH diff --git a/scripts/runtime.bash b/scripts/runtime.bash index bbf87cf4..f8794e9a 100644 --- a/scripts/runtime.bash +++ b/scripts/runtime.bash @@ -145,6 +145,9 @@ function run() if find_word "migration" "$groups"; then cmdline="MIGRATION=yes $cmdline" fi + if find_word "panic" "$groups"; then + cmdline="PANIC=yes $cmdline" + fi if [ "$verbose" = "yes" ]; then echo $cmdline fi