Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp920735lqh; Sun, 5 May 2024 07:48:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVmIpz/lyzVv7oQPo15CFEo3arrWyulJnSz7FsSLmZJbfelxknaY95cSZ3O2xc6xbnYSQUNMtARIUhosTKUstuDZ1SStrw1EdJTSYIfyA== X-Google-Smtp-Source: AGHT+IH+NQHR1o78d87GAZRpGRxgLcxM1BcTEsVi9Yd5cnHK7WE6ezbSYJGLTnX9EZJEvLpQ3OhR X-Received: by 2002:a05:6a00:2e0f:b0:6ec:f712:8a69 with SMTP id fc15-20020a056a002e0f00b006ecf7128a69mr10714455pfb.29.1714920485864; Sun, 05 May 2024 07:48:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714920485; cv=pass; d=google.com; s=arc-20160816; b=TPnAbiYF4XcE7DVmMtL7ro9L31FH1x6f/uewnMiJc4NmcoEN1LPMkTNKFbFp3j6L0f lROWlPIGyAAuY7llsZEAwPBzENVWXPugs+unSE+xn61P9kIds4pqy9XT3Mf6xbd9C7Hk S9ZrsEV+E2ATjNPcbxSP2d7z843AMLI22PIiL0iDC2RoTjM12mkYVPCfLDLrLFDP7l7Y /lx7iSfCfi84MOaspwNZtaRGfLXAgxqz4B/vJQP5bmd8+1L7eLri1OJRHMUQ5DJfrFOT SFwrVELyVAzCn/IX2qM9yYLjqNgDAR2O62wR4S4MdLcHIVKnIeCCOhwcmbHsCk2MmIUl AN/w== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=Tc3YJvIL7QGAQVhuutxmpEra90eyjyBh3d8zSxBAx9g=; fh=vHaRsesZBBHuC6sBxZdVjTfO69Q2CyAW8wWrUS6ZNKk=; b=jbar9aDgHUP7D946Uy76An3TLFNGYmEOGu2ozglXcDvyOD/k+8GnZmijaKfa63oZpK rLKZmMvX+tPare4VMGLJuoZnrppfy5SyORYiZZSYbNjlbX0hR6gKarjUea/H9BScZZnk ms3GfoCzzeHHaMe2d8ivVKkZaZTICOo6Fr5fRl/yHOfCsRKFKq3tHQZ3VVEqzt2J5qYG 3PICVblMYrrG+c6TV/bGi/HeDwH+uy2CS9FTnxOrMW3GxE5+1QsGHpaQduSwknv+RUhd emWo9eTQUQ7BW3N8SqmrmxMOh34op8CKDhYs7ibJv01/I1uW8gZ4o4m5f/lW1SCY9Usr tYLg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=iFEnMqQm; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-169020-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169020-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id x17-20020a656ab1000000b005f80a3a9b62si6588554pgu.314.2024.05.05.07.48.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 May 2024 07:48:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169020-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=iFEnMqQm; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-169020-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169020-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 8D5E5B20E04 for ; Sun, 5 May 2024 14:48:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A7DB2C1A7; Sun, 5 May 2024 14:47:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="iFEnMqQm" Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A335328DD1 for ; Sun, 5 May 2024 14:47:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714920476; cv=none; b=jD19rI39kFnVv+OILJI5zTPxJEcnDZ5ZvXe8OTtBlB/8DDjzNRn/2/uENQ0lZfiR7MYG8GIb5KtncfVVkmRn09hFAOxzL6tdYRphoFG/lAYv9zSwB0nZLiZHGvoi48CcTViyHqs/t3a/Csod12yW0TInQ0FAh6V8NjDjXaboP/c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714920476; c=relaxed/simple; bh=+DMiNVd2HWVjgTdx5Fs3V5Te9zWFm2HRZEQM0YLCGlA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Zrl5hI2ZCwPu1WphpnkkiMyKc+onvLfYKCrxFOz0GAYudBpfem8aYfrIkTVSd7BDF7I5pE9Hq2BCbyDIK+FnzE+3CCTrdeD/95KP8OaZztObUioTsnuFSB7A/AHS3mjViBvvmRxNJ36Pm4MX4+STNJy6sD7MQf7o9syOXN6hV4U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=iFEnMqQm; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1714920470; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Tc3YJvIL7QGAQVhuutxmpEra90eyjyBh3d8zSxBAx9g=; b=iFEnMqQmdLFQwks9/CHAVbqQsE3uozNnXX+wc0pTfsp+AbLhkvabZEi2VqdUweAskLrUgg XJI2ZsFeSlzVr5U135rs4dwbxcnRBVGlFq2PSK9QZ3cXIa9o9e8D3oXwo6muaKHbthnHMH wfplZR91tw1UTxws3hA4hbxEPoomET0= From: Wen Yang To: Shuah Khan , Christian Brauner , Andrew Morton Cc: Wen Yang , SShuah Khan , Andrei Vagin , Mathieu Desnoyers , Steven Rostedt , Dave Young , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] selftests: introduce additional eventfd test coverage Date: Sun, 5 May 2024 22:46:48 +0800 Message-Id: <20240505144648.18347-1-wen.yang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Add several new test cases which assert corner cases on the eventfd mechanism, for example, the supplied buffer is less than 8 bytes, attempting to write a value that is too large, etc. ./eventfd_test # Starting 9 tests from 1 test cases. # RUN global.eventfd01 ... # OK global.eventfd01 ok 1 global.eventfd01 # RUN global.eventfd02 ... # OK global.eventfd02 ok 2 global.eventfd02 # RUN global.eventfd03 ... # OK global.eventfd03 ok 3 global.eventfd03 # RUN global.eventfd04 ... # OK global.eventfd04 ok 4 global.eventfd04 # RUN global.eventfd05 ... # OK global.eventfd05 ok 5 global.eventfd05 # RUN global.eventfd06 ... # OK global.eventfd06 ok 6 global.eventfd06 # RUN global.eventfd07 ... # OK global.eventfd07 ok 7 global.eventfd07 # RUN global.eventfd08 ... # OK global.eventfd08 ok 8 global.eventfd08 # RUN global.eventfd09 ... # OK global.eventfd09 ok 9 global.eventfd09 # PASSED: 9 / 9 tests passed. # Totals: pass:9 fail:0 xfail:0 xpass:0 skip:0 error:0 Signed-off-by: Wen Yang Cc: SShuah Khan Cc: Christian Brauner Cc: Andrei Vagin Cc: Mathieu Desnoyers Cc: Steven Rostedt Cc: Andrew Morton Cc: Dave Young Cc: linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- .../filesystems/eventfd/eventfd_test.c | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/tools/testing/selftests/filesystems/eventfd/eventfd_test.c b/tools/testing/selftests/filesystems/eventfd/eventfd_test.c index f142a137526c..eeab8df5b1b5 100644 --- a/tools/testing/selftests/filesystems/eventfd/eventfd_test.c +++ b/tools/testing/selftests/filesystems/eventfd/eventfd_test.c @@ -183,4 +183,120 @@ TEST(eventfd05) close(fd); } +/* + * A write(2) fails with the error EINVAL if the size of the supplied buffer + * is less than 8 bytes, or if an attempt is made to write the value + * 0xffffffffffffffff. + */ +TEST(eventfd06) +{ + uint64_t value = 1; + ssize_t size; + int fd; + + fd = sys_eventfd2(0, 0); + ASSERT_GE(fd, 0); + + size = write(fd, &value, sizeof(int)); + EXPECT_EQ(size, -1); + EXPECT_EQ(errno, EINVAL); + + value = (uint64_t)-1; + size = write(fd, &value, sizeof(value)); + EXPECT_EQ(size, -1); + EXPECT_EQ(errno, EINVAL); + + close(fd); +} + +/* + * A read(2) fails with the error EINVAL if the size of the supplied buffer is + * less than 8 bytes. + */ +TEST(eventfd07) +{ + int value = 0; + ssize_t size; + int fd; + + fd = sys_eventfd2(0, 0); + ASSERT_GE(fd, 0); + + size = write(fd, &value, sizeof(value)); + EXPECT_EQ(size, -1); + EXPECT_EQ(errno, EINVAL); + + close(fd); +} + +/* + * If EFD_SEMAPHORE was not specified and the eventfd counter has a nonzero + * value, then a read(2) returns 8 bytes containing that value, and the + * counter's value is reset to zero. + * If the eventfd counter is zero at the time of the call to read(2), then the + * call fails with the error EAGAIN if the file descriptor has been made nonblocking. + */ +TEST(eventfd08) +{ + uint64_t value; + ssize_t size; + int fd; + int i; + + fd = sys_eventfd2(0, EFD_NONBLOCK); + ASSERT_GE(fd, 0); + + value = 1; + for (i = 0; i < 10000000; i++) { + size = write(fd, &value, sizeof(value)); + EXPECT_EQ(size, sizeof(value)); + } + + size = read(fd, &value, sizeof(value)); + EXPECT_EQ(size, sizeof(uint64_t)); + EXPECT_EQ(value, 10000000); + + size = read(fd, &value, sizeof(value)); + EXPECT_EQ(size, -1); + EXPECT_EQ(errno, EAGAIN); + + close(fd); +} + +/* + * If EFD_SEMAPHORE was specified and the eventfd counter has a nonzero value, + * then a read(2) returns 8 bytes containing the value 1, and the counter's + * value is decremented by 1. + * If the eventfd counter is zero at the time of the call to read(2), then the + * call fails with the error EAGAIN if the file descriptor has been made nonblocking. + */ +TEST(eventfd09) +{ + uint64_t value; + ssize_t size; + int fd; + int i; + + fd = sys_eventfd2(0, EFD_SEMAPHORE|EFD_NONBLOCK); + ASSERT_GE(fd, 0); + + value = 1; + for (i = 0; i < 10000000; i++) { + size = write(fd, &value, sizeof(value)); + EXPECT_EQ(size, sizeof(value)); + } + + for (i = 0; i < 10000000; i++) { + size = read(fd, &value, sizeof(value)); + EXPECT_EQ(size, sizeof(value)); + EXPECT_EQ(value, 1); + } + + size = read(fd, &value, sizeof(value)); + EXPECT_EQ(size, -1); + EXPECT_EQ(errno, EAGAIN); + + close(fd); +} + TEST_HARNESS_MAIN -- 2.25.1