Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2344508lqp; Sun, 24 Mar 2024 14:45:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVuF7s9DseP7YvmCluizuWYol0TqTrciAplPA2qmxNFh+TSWQ7giukROcWkEgNGGbHUkhezllsoRMdjoA3Oi3xktaQRYzpMDfDmNJaOWw== X-Google-Smtp-Source: AGHT+IEzExjTAeAV/5OQSgIEKj4rZFQC4dyCZrwiGoGXbL1anzPr/xMQkYa3vlu+6SWbs2xKA+1D X-Received: by 2002:a19:7716:0:b0:513:dd66:d5ed with SMTP id s22-20020a197716000000b00513dd66d5edmr2974866lfc.29.1711316734509; Sun, 24 Mar 2024 14:45:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711316734; cv=pass; d=google.com; s=arc-20160816; b=QaUQxiGBEiVPKnDoJMNvw2sa5Hj5BIf/kXGpuPYqAB6CbBMiKSo8z6dDMk8RuIHFDW +jCMXEwo8B7nrVyaiKQ/Ss3sZ5D0hgH0/QEtalUjtYsuQJjPeMax+uX6/sdyYClnHeuW JKS5LNTVXOtRYjKDGs3dUZFmnwbwmHSab+wRLEKiMKQfTA4RieqSwo/EwmUqWpUvu0we IlnS5bXGj4BTCHUvUivyQI/unA9O2e2fm1AO84jcXVsQ2qqpfX9YLwFwlIJha82sEYjH vmSAJvDHoqM1e7SV+Pk5giwDE0nmbzvW8KNJPpe86/np1w0YzxCkO0K3aSyJsasafPXc fFsA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=qwsAY/PMAecJs3xHSlcN58/6nhzeih7nuL6YHNk5t0c=; fh=IOAmMl2pUcfREVIFRbPM3ij8RR1C9EQ0tWmUoS001jo=; b=iBXr0rjHwNe7m9aPnzKXva83IpxwgsIN5rFC/VE4ucTXnaKxm02BHMRxQAXKvzWCgA gaNRUo9A5TncZFbTx6QZ3gICIHp8Rrpatdfrzcxd3jEHBxbEW34n06Wxp8dBgRdLfilI DWV65ZPpPH68nxTOcUmwYFZnMq9NmHL6cjdOjnyFWhPsM7dpKKI+LTFPaoSzjXZYt1zY B1AnlVO5HMdIBo1rdpE3yoRTy8lnxSBpWBF8cXYMnOfx08J3Dqe6/BH7YGmUc83FVyKu QcedDFAtRPRIBOswO11Dcs8rnhkF5Cy4FgcFgHAMOdjEmmgXV2NlM7NQT5DuSeLMof1c 6B6w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="DDYrwCl/"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-112872-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112872-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g19-20020a17090613d300b00a46635ca50csi1878496ejc.883.2024.03.24.14.45.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 14:45:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112872-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="DDYrwCl/"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-112872-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112872-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id EC1991F21510 for ; Sun, 24 Mar 2024 21:45:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3CC0D3D996; Sun, 24 Mar 2024 21:44:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DDYrwCl/" Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE44C43ACC; Sun, 24 Mar 2024 21:44:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711316681; cv=none; b=WatpOjtVLEJNuqWx9qmunV1A8ao1Zt0NhIJhLKwVS20pcm39/tr+5/rTqutb9U354tOuhqRAR/76ty83vEnQ8iouMfnY3fgH/TyO1JJejFYMx8PVYdZBgozxH5jobEqKNjcjG3bbFQO+Hylf4S+0vOIWPD30IUcF80mCKOJpBBQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711316681; c=relaxed/simple; bh=eDIrS0VVRPXkwD7aNTqBTZq2rIf5/MoBWbIEz2aA+yk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nxT/3JO74xHB6BP2hA667T7+FPvj5K9GTQBQzt8imrbA8V9JpgUzQ/sr2zvp/5MkscbniwiOcfDOxQnYG5AzbjhOOmbSt/D87ARiMLi3MjxC6Bshu/o43mlzKSFQqeDNjXSb80QStYk6zlV6d4/aPxz2dNUmjuL94+IFn7ZxrXk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DDYrwCl/; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-513da1c1f26so4706492e87.3; Sun, 24 Mar 2024 14:44:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711316678; x=1711921478; darn=vger.kernel.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=qwsAY/PMAecJs3xHSlcN58/6nhzeih7nuL6YHNk5t0c=; b=DDYrwCl/fs0wZq5zp36Lwwl/1zR+IRc/ivGK+EcHxnncoZ1Pu2qYywO1ebeDwQnuy0 JGO0rwT+SMMKY2vcp54Pa1T58mPkf7f5cNtVHmZHNnJqOXYG+hd+JOqHIBghzQyVRRqw EdWYCPc/EGEDfl/Z3ueMubR8QsP9rbrH6dOqZCr9sGH6tO2C/8/lVx/sZgUnluIObR/j 003gVgHPSRGBxWKqhIh77wxdF4VqN4rpbLFBdpUCWs4WpNfK2Mo/Jj5KBOUmUfTUYhqo pFqh2aw1+f69Ph1qHX++UIbtZ2wXJXQtIqv1Wc8h2Nm4KmBVv+yXeP+Sv03HLnGuUccw qfSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711316678; x=1711921478; 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=qwsAY/PMAecJs3xHSlcN58/6nhzeih7nuL6YHNk5t0c=; b=l7mbYzi8jLdBy3XHnxqrHXsNJnYve38tQFdghlt19LA/KV0h7R0EePKdDmnx3W8MsQ 4em5IUwk9XtT75b9vcWia4lzJ3L5pJ2JGqzVrN2dLInCJqcP8cWFLHwJE6ueesjv5Thy OXQazFDShD/gNfVZBwBuWldyzKaOgYGnHCzDeSLIp5m0TRX/Nbac7rKTp4Zk4tvX7N6k /2E4E8C8Z0DI/ZPZZYVm+gqEkuLisFg7i42kjsXUOwQaM+flB8Gpk722WygyBnKhZXQq M5c6RbzJJPyJwSyWy9Gh0ZNU487rbh3B5gDWOzdv7yY/X0ff5DOt95/vQGpBRU1tXE1Q yLRQ== X-Forwarded-Encrypted: i=1; AJvYcCUpYbMrI1Xf/DRag8+KxRYR6x6FCvgR+B/ySMSzxthzMXWyOU0y7dBP9zp5RMfASP+EwICYi8cwRpR4DNPUqJya8n6qy6BQYdDrxjTdVCfpRp+ZL46bHE9UyedO4YMgI72OasSImdR7YM0H1fwg X-Gm-Message-State: AOJu0Yxxp7yAsTPQMssoudx5tQV3+6XXQI+BYwRDZEkuJ3LxGLtCOdgn 4KiiqaCIRLpPsN712xwiKA5JNrx+WvUb815iTUYLtzF4JHkBzg== X-Received: by 2002:a05:6512:44b:b0:513:d49a:7a0d with SMTP id y11-20020a056512044b00b00513d49a7a0dmr3373355lfk.42.1711316677479; Sun, 24 Mar 2024 14:44:37 -0700 (PDT) Received: from localhost.localdomain ([85.89.127.166]) by smtp.gmail.com with ESMTPSA id h22-20020a0565123c9600b00515a36f5735sm687609lfv.61.2024.03.24.14.44.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 14:44:36 -0700 (PDT) From: Shengyu Li To: shuah@kernel.org Cc: luto@amacapital.net, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, wad@chromium.org, Shengyu Li Subject: [PATCH] selftests/harness: Prevent infinite loop due to Assert in FIXTURE_TEARDOWN Date: Mon, 25 Mar 2024 05:44:19 +0800 Message-Id: <20240324214419.12577-1-shengyu.li.evgeny@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240314224323.23201-1-shengyu.li.evgeny@gmail.com> References: <20240314224323.23201-1-shengyu.li.evgeny@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patch addresses an issue in the selftests/harness where an assertion within FIXTURE_TEARDOWN could trigger an infinite loop. The problem arises because the teardown procedure is meant to execute once, but the presence of failing assertions (ASSERT_EQ(0, 1)) leads to repeated attempts to execute teardown due to the long jump mechanism used by the harness for handling assertions. To resolve this, the patch ensures that the teardown process runs only once, regardless of assertion outcomes, preventing the infinite loop and allowing tests to fail. A simple test demo, also this is related to the issue mentioned in this patch https://patchwork.kernel.org/project/linux-kselftest/patch/e2ba3f8c-80e6-477d-9cea-1c9af820e0ed@alu.unizg.hr/ #include "kselftest_harness.h" FIXTURE(f) { int fd; }; FIXTURE_SETUP(f) { self->fd = 0; } FIXTURE_TEARDOWN(f) { TH_LOG("TEARDOWN"); ASSERT_EQ(0, 1); self->fd = -1; } TEST_F(f, open_close) { ASSERT_NE(self->fd, 1); } TEST_HARNESS_MAIN Signed-off-by: Shengyu Li --- tools/testing/selftests/kselftest_harness.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 4fd735e48ee7..230d62884885 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -383,6 +383,7 @@ FIXTURE_DATA(fixture_name) self; \ pid_t child = 1; \ int status = 0; \ + bool jmp = false; \ memset(&self, 0, sizeof(FIXTURE_DATA(fixture_name))); \ if (setjmp(_metadata->env) == 0) { \ /* Use the same _metadata. */ \ @@ -399,8 +400,10 @@ _metadata->exit_code = KSFT_FAIL; \ } \ } \ + else \ + jmp = true; \ if (child == 0) { \ - if (_metadata->setup_completed && !_metadata->teardown_parent) \ + if (_metadata->setup_completed && !_metadata->teardown_parent && !jmp) \ fixture_name##_teardown(_metadata, &self, variant->data); \ _exit(0); \ } \ -- 2.25.1