Linux-kselftest Archive mirror
 help / color / mirror / Atom feed
From: Wen Yang <wen.yang@linux.dev>
To: "Bird, Tim" <Tim.Bird@sony.com>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Christian Brauner <brauner@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: SShuah Khan <shuah@kernel.org>, Andrei Vagin <avagin@google.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Dave Young <dyoung@redhat.com>,
	"linux-kselftest@vger.kernel.org"
	<linux-kselftest@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] selftests: introduce additional eventfd test coverage
Date: Tue, 7 May 2024 22:59:36 +0800	[thread overview]
Message-ID: <ee6e9e36-999a-42ab-80de-2ff4c4df3ae3@linux.dev> (raw)
In-Reply-To: <SA3PR13MB6372229283A34550FD52F913FD1C2@SA3PR13MB6372.namprd13.prod.outlook.com>



On 2024/5/7 02:30, Bird, Tim wrote:
> 
> 
>> -----Original Message-----
>> From: Wen Yang <wen.yang@linux.dev>
>> 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
> 
> These are horrible test case names.  Can you please use strings which indicate
> what is being tested, that are useful to a human?
>   -- Tim
> 

Thank you for the review.
I will do the change and send v2 soon.

--
Best wishes,
Wen

>> 	#  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 <wen.yang@linux.dev>
>> Cc: SShuah Khan <shuah@kernel.org>
>> Cc: Christian Brauner <brauner@kernel.org>
>> Cc: Andrei Vagin <avagin@google.com>
>> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
>> Cc: Steven Rostedt <rostedt@goodmis.org>
>> Cc: Andrew Morton <akpm@linux-foundation.org>
>> Cc: Dave Young <dyoung@redhat.com>
>> 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
>>
> 

      reply	other threads:[~2024-05-07 15:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-05 14:46 [PATCH] selftests: introduce additional eventfd test coverage Wen Yang
2024-05-06 18:30 ` Bird, Tim
2024-05-07 14:59   ` Wen Yang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ee6e9e36-999a-42ab-80de-2ff4c4df3ae3@linux.dev \
    --to=wen.yang@linux.dev \
    --cc=Tim.Bird@sony.com \
    --cc=akpm@linux-foundation.org \
    --cc=avagin@google.com \
    --cc=brauner@kernel.org \
    --cc=dyoung@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=rostedt@goodmis.org \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).