ltp.lists.linux.it archive mirror
 help / color / mirror / Atom feed
* [LTP] [PATCH] syscalls/read05: Test read with zero count
@ 2022-07-25  7:02 Liao Huangjie
  2022-07-26  9:52 ` Richard Palethorpe
  0 siblings, 1 reply; 3+ messages in thread
From: Liao Huangjie @ 2022-07-25  7:02 UTC (permalink / raw)
  To: ltp

From: Huangjie Liao <liaohj.jy@fujitsu.com>

Signed-off-by: Huangjie Liao <liaohj.jy@fujitsu.com>
---
 runtest/syscalls                          |  1 +
 testcases/kernel/syscalls/read/.gitignore |  1 +
 testcases/kernel/syscalls/read/read05.c   | 44 +++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+)
 create mode 100644 testcases/kernel/syscalls/read/read05.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 3847e8a..0bd47fc 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1094,6 +1094,7 @@ read01 read01
 read02 read02
 read03 read03
 read04 read04
+read05 read05
 
 readahead01 readahead01
 readahead02 readahead02
diff --git a/testcases/kernel/syscalls/read/.gitignore b/testcases/kernel/syscalls/read/.gitignore
index e89c008..69d97b3 100644
--- a/testcases/kernel/syscalls/read/.gitignore
+++ b/testcases/kernel/syscalls/read/.gitignore
@@ -2,3 +2,4 @@
 /read02
 /read03
 /read04
+/read05
diff --git a/testcases/kernel/syscalls/read/read05.c b/testcases/kernel/syscalls/read/read05.c
new file mode 100644
index 0000000..83ac763
--- /dev/null
+++ b/testcases/kernel/syscalls/read/read05.c
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 FUJITSU LIMITED. All Rights Reserved.
+ * Author: Huangjie Liao <liaohj.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * In the absence of any errors, a read() with a count of 0 returns zero.
+ */
+
+#include <errno.h>
+#include "tst_test.h"
+
+#define SIZE 512
+
+static int fd;
+static char buf[SIZE];
+
+static void verify_read(void)
+{
+	TST_EXP_VAL(read(fd, buf, 0), 0);
+}
+
+static void setup(void)
+{
+	memset(buf, '*', SIZE);
+	fd = SAFE_OPEN("testfile", O_RDWR | O_CREAT, 0700);
+	SAFE_WRITE(1, fd, buf, SIZE);
+}
+
+static void cleanup(void)
+{
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = verify_read,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+};
-- 
1.8.3.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH] syscalls/read05: Test read with zero count
  2022-07-25  7:02 [LTP] [PATCH] syscalls/read05: Test read with zero count Liao Huangjie
@ 2022-07-26  9:52 ` Richard Palethorpe
  2022-08-19  8:59   ` liaohj.jy
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Palethorpe @ 2022-07-26  9:52 UTC (permalink / raw)
  To: Liao Huangjie; +Cc: ltp

Hello,

Liao Huangjie <liaohj.jy@fujitsu.com> writes:

> From: Huangjie Liao <liaohj.jy@fujitsu.com>
>
> Signed-off-by: Huangjie Liao <liaohj.jy@fujitsu.com>
> ---
>  runtest/syscalls                          |  1 +
>  testcases/kernel/syscalls/read/.gitignore |  1 +
>  testcases/kernel/syscalls/read/read05.c   | 44 +++++++++++++++++++++++++++++++
>  3 files changed, 46 insertions(+)
>  create mode 100644 testcases/kernel/syscalls/read/read05.c
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 3847e8a..0bd47fc 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -1094,6 +1094,7 @@ read01 read01
>  read02 read02
>  read03 read03
>  read04 read04
> +read05 read05
>  
>  readahead01 readahead01
>  readahead02 readahead02
> diff --git a/testcases/kernel/syscalls/read/.gitignore b/testcases/kernel/syscalls/read/.gitignore
> index e89c008..69d97b3 100644
> --- a/testcases/kernel/syscalls/read/.gitignore
> +++ b/testcases/kernel/syscalls/read/.gitignore
> @@ -2,3 +2,4 @@
>  /read02
>  /read03
>  /read04
> +/read05
> diff --git a/testcases/kernel/syscalls/read/read05.c b/testcases/kernel/syscalls/read/read05.c
> new file mode 100644
> index 0000000..83ac763
> --- /dev/null
> +++ b/testcases/kernel/syscalls/read/read05.c
> @@ -0,0 +1,44 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2022 FUJITSU LIMITED. All Rights Reserved.
> + * Author: Huangjie Liao <liaohj.jy@fujitsu.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * In the absence of any errors, a read() with a count of 0 returns
>  zero.

This test is quite similar to read04. You could modify that test to read
multiple times from 0 bytes to the total number of bytes available.

> + */
> +
> +#include <errno.h>
> +#include "tst_test.h"
> +
> +#define SIZE 512

This could be set to 2*getpagesize() at runtime. Then you can try
reading every length between 0 and 2*getpagesize().

Errors tend to be made on page boundaries and similar.

> +
> +static int fd;
> +static char buf[SIZE];
> +
> +static void verify_read(void)
> +{
> +	TST_EXP_VAL(read(fd, buf, 0), 0);
> +}
> +
> +static void setup(void)
> +{
> +	memset(buf, '*', SIZE);
> +	fd = SAFE_OPEN("testfile", O_RDWR | O_CREAT, 0700);
> +	SAFE_WRITE(1, fd, buf, SIZE);
> +}
> +
> +static void cleanup(void)
> +{
> +	if (fd > 0)
> +		SAFE_CLOSE(fd);
> +}
> +
> +static struct tst_test test = {
> +	.test_all = verify_read,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.needs_tmpdir = 1,

It would increase test coverage greatly to run this on all filesystems
(i.e. set .all_filesystems = 1). For an example see rename10.

> +};
> -- 
> 1.8.3.1


-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH] syscalls/read05: Test read with zero count
  2022-07-26  9:52 ` Richard Palethorpe
@ 2022-08-19  8:59   ` liaohj.jy
  0 siblings, 0 replies; 3+ messages in thread
From: liaohj.jy @ 2022-08-19  8:59 UTC (permalink / raw)
  To: rpalethorpe; +Cc: ltp

Hi Richard


> Hello,
> 
> Liao Huangjie <liaohj.jy@fujitsu.com> writes:
> 
>> From: Huangjie Liao <liaohj.jy@fujitsu.com>
>>
>> Signed-off-by: Huangjie Liao <liaohj.jy@fujitsu.com>
>> ---
>>   runtest/syscalls                          |  1 +
>>   testcases/kernel/syscalls/read/.gitignore |  1 +
>>   testcases/kernel/syscalls/read/read05.c   | 44 +++++++++++++++++++++++++++++++
>>   3 files changed, 46 insertions(+)
>>   create mode 100644 testcases/kernel/syscalls/read/read05.c
>>
>> diff --git a/runtest/syscalls b/runtest/syscalls
>> index 3847e8a..0bd47fc 100644
>> --- a/runtest/syscalls
>> +++ b/runtest/syscalls
>> @@ -1094,6 +1094,7 @@ read01 read01
>>   read02 read02
>>   read03 read03
>>   read04 read04
>> +read05 read05
>>   
>>   readahead01 readahead01
>>   readahead02 readahead02
>> diff --git a/testcases/kernel/syscalls/read/.gitignore b/testcases/kernel/syscalls/read/.gitignore
>> index e89c008..69d97b3 100644
>> --- a/testcases/kernel/syscalls/read/.gitignore
>> +++ b/testcases/kernel/syscalls/read/.gitignore
>> @@ -2,3 +2,4 @@
>>   /read02
>>   /read03
>>   /read04
>> +/read05
>> diff --git a/testcases/kernel/syscalls/read/read05.c b/testcases/kernel/syscalls/read/read05.c
>> new file mode 100644
>> index 0000000..83ac763
>> --- /dev/null
>> +++ b/testcases/kernel/syscalls/read/read05.c
>> @@ -0,0 +1,44 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * Copyright (c) 2022 FUJITSU LIMITED. All Rights Reserved.
>> + * Author: Huangjie Liao <liaohj.jy@fujitsu.com>
>> + */
>> +
>> +/*\
>> + * [Description]
>> + *
>> + * In the absence of any errors, a read() with a count of 0 returns
>>   zero.
> 
> This test is quite similar to read04. You could modify that test to read
> multiple times from 0 bytes to the total number of bytes available.
OK
> 
>> + */
>> +
>> +#include <errno.h>
>> +#include "tst_test.h"
>> +
>> +#define SIZE 512
> 
> This could be set to 2*getpagesize() at runtime. Then you can try
> reading every length between 0 and 2*getpagesize().

Then we can increase 2kb length every time, ie  0 2k 4k 6k 8kb.

But I have a question that used which patten to fill the 8KB space.

Maybe write  "A" in the [0-4k] and "B" in the [4-8k]. Or use "A" to
fill the whole 8k space?

> 
> Errors tend to be made on page boundaries and similar.
> 
>> +
>> +static int fd;
>> +static char buf[SIZE];
>> +
>> +static void verify_read(void)
>> +{
>> +	TST_EXP_VAL(read(fd, buf, 0), 0);
>> +}
>> +
>> +static void setup(void)
>> +{
>> +	memset(buf, '*', SIZE);
>> +	fd = SAFE_OPEN("testfile", O_RDWR | O_CREAT, 0700);
>> +	SAFE_WRITE(1, fd, buf, SIZE);
>> +}
>> +
>> +static void cleanup(void)
>> +{
>> +	if (fd > 0)
>> +		SAFE_CLOSE(fd);
>> +}
>> +
>> +static struct tst_test test = {
>> +	.test_all = verify_read,
>> +	.setup = setup,
>> +	.cleanup = cleanup,
>> +	.needs_tmpdir = 1,
> 
> It would increase test coverage greatly to run this on all filesystems
> (i.e. set .all_filesystems = 1). For an example see rename10.

Yes.

Best Regards
> 
>> +};
>> -- 
>> 1.8.3.1
> 
> 

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-19  8:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-25  7:02 [LTP] [PATCH] syscalls/read05: Test read with zero count Liao Huangjie
2022-07-26  9:52 ` Richard Palethorpe
2022-08-19  8:59   ` liaohj.jy

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 NNTP newsgroup(s).