All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] lseek: Add negative tests for lseek
@ 2024-04-25  5:25 Yang Xu via ltp
  2024-05-13 11:31 ` Avinesh Kumar
  0 siblings, 1 reply; 5+ messages in thread
From: Yang Xu via ltp @ 2024-04-25  5:25 UTC (permalink / raw)
  To: ltp

Add negative tests for lseek(), when errno is ENXIO

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 runtest/syscalls                           |  1 +
 testcases/kernel/syscalls/lseek/.gitignore |  1 +
 testcases/kernel/syscalls/lseek/lseek12.c  | 80 ++++++++++++++++++++++
 3 files changed, 82 insertions(+)
 create mode 100644 testcases/kernel/syscalls/lseek/lseek12.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 62eb4c1cd..7575b27b1 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -726,6 +726,7 @@ lseek01 lseek01
 lseek02 lseek02
 lseek07 lseek07
 lseek11 lseek11
+lseek12 lseek12
 
 lstat01A symlink01 -T lstat01
 lstat01A_64 symlink01 -T lstat01_64
diff --git a/testcases/kernel/syscalls/lseek/.gitignore b/testcases/kernel/syscalls/lseek/.gitignore
index 1dc1465ee..c49728607 100644
--- a/testcases/kernel/syscalls/lseek/.gitignore
+++ b/testcases/kernel/syscalls/lseek/.gitignore
@@ -2,3 +2,4 @@
 /lseek02
 /lseek07
 /lseek11
+/lseek12
diff --git a/testcases/kernel/syscalls/lseek/lseek12.c b/testcases/kernel/syscalls/lseek/lseek12.c
new file mode 100644
index 000000000..9d80e632b
--- /dev/null
+++ b/testcases/kernel/syscalls/lseek/lseek12.c
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2024 FUJITSU LIMITED. All Rights Reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that lseek(2) fails with
+ *
+ * - ENXIO when whence is SEEK_DATA, file offset is beyond the end of the file
+ * - ENXIO when whence is SEEK_HOLE, file offset is beyond the end of the file
+ */
+
+#define _GNU_SOURCE
+
+#include <sys/types.h>
+#include "tst_test.h"
+#include "lapi/seek.h"
+
+#define TEST_ENXIO "test_enxio"
+
+static int fd_enxio;
+
+static struct test_case_t {
+	int *fd;
+	off_t offset;
+	int whence;
+	int expected_errno;
+	char *desc;
+} tcases[] = {
+	{&fd_enxio, 10, SEEK_DATA, ENXIO,
+		"whence is SEEK_DATA, "
+		"file offset is beyond the end of the file"},
+	{&fd_enxio, 10, SEEK_HOLE, ENXIO,
+		"whence is SEEK_HOLE, "
+		"file offset is beyond the end of the file"},
+};
+
+static void setup(void)
+{
+	SAFE_TOUCH(TEST_ENXIO, 0777, NULL);
+	fd_enxio = SAFE_OPEN(TEST_ENXIO, O_RDWR, 0777);
+}
+
+static void cleanup(void)
+{
+	SAFE_CLOSE(fd_enxio);
+}
+
+static void verify_lseek(unsigned int i)
+{
+	struct test_case_t *tc = &tcases[i];
+	off_t offset;
+
+	offset = lseek(*(tc->fd), tc->offset, tc->whence);
+	if (offset == -1) {
+		if (errno == EINVAL) {
+			tst_res(TCONF, "SEEK_DATA/SEEK_HOLE are not supported");
+		} else {
+			if (errno == tc->expected_errno) {
+				tst_res(TPASS | TERRNO, tc->desc);
+			} else {
+				tst_res(TFAIL | TERRNO,
+					"lseek() failed unexpectedly");
+			}
+		}
+	} else {
+		tst_res(TFAIL, "lseek() succeeded unexpectedly");
+	}
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_lseek,
+	.needs_tmpdir = 1,
+};
-- 
2.39.3


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

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

* Re: [LTP] [PATCH] lseek: Add negative tests for lseek
  2024-04-25  5:25 [LTP] [PATCH] lseek: Add negative tests for lseek Yang Xu via ltp
@ 2024-05-13 11:31 ` Avinesh Kumar
  2024-05-14  2:41   ` Yang Xu (Fujitsu) via ltp
  0 siblings, 1 reply; 5+ messages in thread
From: Avinesh Kumar @ 2024-05-13 11:31 UTC (permalink / raw)
  To: ltp

Hi Yang Xu,

Overall test looks fine. But I think we should enable this for all filesystems.

On Thursday, April 25, 2024 7:25:36 AM GMT+2 Yang Xu via ltp wrote:
> Add negative tests for lseek(), when errno is ENXIO
> 
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
>  runtest/syscalls                           |  1 +
>  testcases/kernel/syscalls/lseek/.gitignore |  1 +
>  testcases/kernel/syscalls/lseek/lseek12.c  | 80 ++++++++++++++++++++++
>  3 files changed, 82 insertions(+)
>  create mode 100644 testcases/kernel/syscalls/lseek/lseek12.c
> 
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 62eb4c1cd..7575b27b1 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -726,6 +726,7 @@ lseek01 lseek01
>  lseek02 lseek02
>  lseek07 lseek07
>  lseek11 lseek11
> +lseek12 lseek12
>  
>  lstat01A symlink01 -T lstat01
>  lstat01A_64 symlink01 -T lstat01_64
> diff --git a/testcases/kernel/syscalls/lseek/.gitignore b/testcases/kernel/syscalls/lseek/.gitignore
> index 1dc1465ee..c49728607 100644
> --- a/testcases/kernel/syscalls/lseek/.gitignore
> +++ b/testcases/kernel/syscalls/lseek/.gitignore
> @@ -2,3 +2,4 @@
>  /lseek02
>  /lseek07
>  /lseek11
> +/lseek12
> diff --git a/testcases/kernel/syscalls/lseek/lseek12.c b/testcases/kernel/syscalls/lseek/lseek12.c
> new file mode 100644
> index 000000000..9d80e632b
> --- /dev/null
> +++ b/testcases/kernel/syscalls/lseek/lseek12.c
> @@ -0,0 +1,80 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2024 FUJITSU LIMITED. All Rights Reserved.
> + * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * Verify that lseek(2) fails with
> + *
> + * - ENXIO when whence is SEEK_DATA, file offset is beyond the end of the file
> + * - ENXIO when whence is SEEK_HOLE, file offset is beyond the end of the file
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include <sys/types.h>
> +#include "tst_test.h"
> +#include "lapi/seek.h"
> +
> +#define TEST_ENXIO "test_enxio"
> +
> +static int fd_enxio;
> +
> +static struct test_case_t {
> +	int *fd;
> +	off_t offset;
> +	int whence;
> +	int expected_errno;
> +	char *desc;
> +} tcases[] = {
> +	{&fd_enxio, 10, SEEK_DATA, ENXIO,
> +		"whence is SEEK_DATA, "
> +		"file offset is beyond the end of the file"},
> +	{&fd_enxio, 10, SEEK_HOLE, ENXIO,
> +		"whence is SEEK_HOLE, "
> +		"file offset is beyond the end of the file"},
> +};
> +
> +static void setup(void)
> +{
> +	SAFE_TOUCH(TEST_ENXIO, 0777, NULL);
> +	fd_enxio = SAFE_OPEN(TEST_ENXIO, O_RDWR, 0777);
> +}
> +
> +static void cleanup(void)
> +{
> +	SAFE_CLOSE(fd_enxio);
> +}
> +
> +static void verify_lseek(unsigned int i)
> +{
> +	struct test_case_t *tc = &tcases[i];
> +	off_t offset;
> +
> +	offset = lseek(*(tc->fd), tc->offset, tc->whence);
> +	if (offset == -1) {
> +		if (errno == EINVAL) {
> +			tst_res(TCONF, "SEEK_DATA/SEEK_HOLE are not supported");
> +		} else {
> +			if (errno == tc->expected_errno) {
> +				tst_res(TPASS | TERRNO, tc->desc);
> +			} else {
> +				tst_res(TFAIL | TERRNO,
> +					"lseek() failed unexpectedly");
> +			}
> +		}
> +	} else {
> +		tst_res(TFAIL, "lseek() succeeded unexpectedly");
> +	}

> +}
> +
> +static struct tst_test test = {
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.test = verify_lseek,
> +	.needs_tmpdir = 1,
> +};
> 

Regards,
Avinesh



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

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

* Re: [LTP] [PATCH] lseek: Add negative tests for lseek
  2024-05-13 11:31 ` Avinesh Kumar
@ 2024-05-14  2:41   ` Yang Xu (Fujitsu) via ltp
  2024-05-15  6:49     ` Petr Vorel
  2025-01-14 11:58     ` Andrea Cervesato via ltp
  0 siblings, 2 replies; 5+ messages in thread
From: Yang Xu (Fujitsu) via ltp @ 2024-05-14  2:41 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp@lists.linux.it

Hi Avinesh

Thanks for your reviewing.

According to the man page, not all file systems support SEEK_DATA/SEEK_HOLE.

Users may run LTP on an old kernel, or on a file system that does not 
support SEEK_DATA/SEEK_HOLE If returning TFAIL directly, this may make 
user confused.

So in the case I check the errno of lseek(), and return TCONF if 
SEEK_DATA/SEEK_HOLE are not supported.

I think this is easier to understand for users.

Best Regards
Yang Xu

> Hi Yang Xu,
> 
> Overall test looks fine. But I think we should enable this for all filesystems.
> 
> On Thursday, April 25, 2024 7:25:36 AM GMT+2 Yang Xu via ltp wrote:
>> Add negative tests for lseek(), when errno is ENXIO
>>
>> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
>> ---
>>   runtest/syscalls                           |  1 +
>>   testcases/kernel/syscalls/lseek/.gitignore |  1 +
>>   testcases/kernel/syscalls/lseek/lseek12.c  | 80 ++++++++++++++++++++++
>>   3 files changed, 82 insertions(+)
>>   create mode 100644 testcases/kernel/syscalls/lseek/lseek12.c
>>
>> diff --git a/runtest/syscalls b/runtest/syscalls
>> index 62eb4c1cd..7575b27b1 100644
>> --- a/runtest/syscalls
>> +++ b/runtest/syscalls
>> @@ -726,6 +726,7 @@ lseek01 lseek01
>>   lseek02 lseek02
>>   lseek07 lseek07
>>   lseek11 lseek11
>> +lseek12 lseek12
>>   
>>   lstat01A symlink01 -T lstat01
>>   lstat01A_64 symlink01 -T lstat01_64
>> diff --git a/testcases/kernel/syscalls/lseek/.gitignore b/testcases/kernel/syscalls/lseek/.gitignore
>> index 1dc1465ee..c49728607 100644
>> --- a/testcases/kernel/syscalls/lseek/.gitignore
>> +++ b/testcases/kernel/syscalls/lseek/.gitignore
>> @@ -2,3 +2,4 @@
>>   /lseek02
>>   /lseek07
>>   /lseek11
>> +/lseek12
>> diff --git a/testcases/kernel/syscalls/lseek/lseek12.c b/testcases/kernel/syscalls/lseek/lseek12.c
>> new file mode 100644
>> index 000000000..9d80e632b
>> --- /dev/null
>> +++ b/testcases/kernel/syscalls/lseek/lseek12.c
>> @@ -0,0 +1,80 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * Copyright (c) 2024 FUJITSU LIMITED. All Rights Reserved.
>> + * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
>> + */
>> +
>> +/*\
>> + * [Description]
>> + *
>> + * Verify that lseek(2) fails with
>> + *
>> + * - ENXIO when whence is SEEK_DATA, file offset is beyond the end of the file
>> + * - ENXIO when whence is SEEK_HOLE, file offset is beyond the end of the file
>> + */
>> +
>> +#define _GNU_SOURCE
>> +
>> +#include <sys/types.h>
>> +#include "tst_test.h"
>> +#include "lapi/seek.h"
>> +
>> +#define TEST_ENXIO "test_enxio"
>> +
>> +static int fd_enxio;
>> +
>> +static struct test_case_t {
>> +	int *fd;
>> +	off_t offset;
>> +	int whence;
>> +	int expected_errno;
>> +	char *desc;
>> +} tcases[] = {
>> +	{&fd_enxio, 10, SEEK_DATA, ENXIO,
>> +		"whence is SEEK_DATA, "
>> +		"file offset is beyond the end of the file"},
>> +	{&fd_enxio, 10, SEEK_HOLE, ENXIO,
>> +		"whence is SEEK_HOLE, "
>> +		"file offset is beyond the end of the file"},
>> +};
>> +
>> +static void setup(void)
>> +{
>> +	SAFE_TOUCH(TEST_ENXIO, 0777, NULL);
>> +	fd_enxio = SAFE_OPEN(TEST_ENXIO, O_RDWR, 0777);
>> +}
>> +
>> +static void cleanup(void)
>> +{
>> +	SAFE_CLOSE(fd_enxio);
>> +}
>> +
>> +static void verify_lseek(unsigned int i)
>> +{
>> +	struct test_case_t *tc = &tcases[i];
>> +	off_t offset;
>> +
>> +	offset = lseek(*(tc->fd), tc->offset, tc->whence);
>> +	if (offset == -1) {
>> +		if (errno == EINVAL) {
>> +			tst_res(TCONF, "SEEK_DATA/SEEK_HOLE are not supported");
>> +		} else {
>> +			if (errno == tc->expected_errno) {
>> +				tst_res(TPASS | TERRNO, tc->desc);
>> +			} else {
>> +				tst_res(TFAIL | TERRNO,
>> +					"lseek() failed unexpectedly");
>> +			}
>> +		}
>> +	} else {
>> +		tst_res(TFAIL, "lseek() succeeded unexpectedly");
>> +	}
> 
>> +}
>> +
>> +static struct tst_test test = {
>> +	.setup = setup,
>> +	.cleanup = cleanup,
>> +	.tcnt = ARRAY_SIZE(tcases),
>> +	.test = verify_lseek,
>> +	.needs_tmpdir = 1,
>> +};
>>
> 
> Regards,
> Avinesh
> 
> 

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

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

* Re: [LTP] [PATCH] lseek: Add negative tests for lseek
  2024-05-14  2:41   ` Yang Xu (Fujitsu) via ltp
@ 2024-05-15  6:49     ` Petr Vorel
  2025-01-14 11:58     ` Andrea Cervesato via ltp
  1 sibling, 0 replies; 5+ messages in thread
From: Petr Vorel @ 2024-05-15  6:49 UTC (permalink / raw)
  To: Yang Xu (Fujitsu); +Cc: ltp@lists.linux.it

> Hi Avinesh

> Thanks for your reviewing.

> According to the man page, not all file systems support SEEK_DATA/SEEK_HOLE.

> Users may run LTP on an old kernel, or on a file system that does not 
> support SEEK_DATA/SEEK_HOLE If returning TFAIL directly, this may make 
> user confused.

> So in the case I check the errno of lseek(), and return TCONF if 
> SEEK_DATA/SEEK_HOLE are not supported.

Sounds good.

Kind regards,
Petr

> I think this is easier to understand for users.

> Best Regards
> Yang Xu

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

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

* Re: [LTP] [PATCH] lseek: Add negative tests for lseek
  2024-05-14  2:41   ` Yang Xu (Fujitsu) via ltp
  2024-05-15  6:49     ` Petr Vorel
@ 2025-01-14 11:58     ` Andrea Cervesato via ltp
  1 sibling, 0 replies; 5+ messages in thread
From: Andrea Cervesato via ltp @ 2025-01-14 11:58 UTC (permalink / raw)
  To: ltp

Hi Yang,

"struct tst_test" definition has now an attribute called "filesystems" 
that permits to define filesystems where to run the specific test. This 
might be our case. Feel free to adapt the test and I will merge it 
afterwards.

Kind regards,
Andrea Cervesato

On 5/14/24 04:41, Yang Xu (Fujitsu) via ltp wrote:
> Hi Avinesh
>
> Thanks for your reviewing.
>
> According to the man page, not all file systems support SEEK_DATA/SEEK_HOLE.
>
> Users may run LTP on an old kernel, or on a file system that does not
> support SEEK_DATA/SEEK_HOLE If returning TFAIL directly, this may make
> user confused.
>
> So in the case I check the errno of lseek(), and return TCONF if
> SEEK_DATA/SEEK_HOLE are not supported.
>
> I think this is easier to understand for users.
>
> Best Regards
> Yang Xu
>
>> Hi Yang Xu,
>>
>> Overall test looks fine. But I think we should enable this for all filesystems.
>>
>> On Thursday, April 25, 2024 7:25:36 AM GMT+2 Yang Xu via ltp wrote:
>>> Add negative tests for lseek(), when errno is ENXIO
>>>
>>> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
>>> ---
>>>    runtest/syscalls                           |  1 +
>>>    testcases/kernel/syscalls/lseek/.gitignore |  1 +
>>>    testcases/kernel/syscalls/lseek/lseek12.c  | 80 ++++++++++++++++++++++
>>>    3 files changed, 82 insertions(+)
>>>    create mode 100644 testcases/kernel/syscalls/lseek/lseek12.c
>>>
>>> diff --git a/runtest/syscalls b/runtest/syscalls
>>> index 62eb4c1cd..7575b27b1 100644
>>> --- a/runtest/syscalls
>>> +++ b/runtest/syscalls
>>> @@ -726,6 +726,7 @@ lseek01 lseek01
>>>    lseek02 lseek02
>>>    lseek07 lseek07
>>>    lseek11 lseek11
>>> +lseek12 lseek12
>>>    
>>>    lstat01A symlink01 -T lstat01
>>>    lstat01A_64 symlink01 -T lstat01_64
>>> diff --git a/testcases/kernel/syscalls/lseek/.gitignore b/testcases/kernel/syscalls/lseek/.gitignore
>>> index 1dc1465ee..c49728607 100644
>>> --- a/testcases/kernel/syscalls/lseek/.gitignore
>>> +++ b/testcases/kernel/syscalls/lseek/.gitignore
>>> @@ -2,3 +2,4 @@
>>>    /lseek02
>>>    /lseek07
>>>    /lseek11
>>> +/lseek12
>>> diff --git a/testcases/kernel/syscalls/lseek/lseek12.c b/testcases/kernel/syscalls/lseek/lseek12.c
>>> new file mode 100644
>>> index 000000000..9d80e632b
>>> --- /dev/null
>>> +++ b/testcases/kernel/syscalls/lseek/lseek12.c
>>> @@ -0,0 +1,80 @@
>>> +// SPDX-License-Identifier: GPL-2.0-or-later
>>> +/*
>>> + * Copyright (c) 2024 FUJITSU LIMITED. All Rights Reserved.
>>> + * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
>>> + */
>>> +
>>> +/*\
>>> + * [Description]
>>> + *
>>> + * Verify that lseek(2) fails with
>>> + *
>>> + * - ENXIO when whence is SEEK_DATA, file offset is beyond the end of the file
>>> + * - ENXIO when whence is SEEK_HOLE, file offset is beyond the end of the file
>>> + */
>>> +
>>> +#define _GNU_SOURCE
>>> +
>>> +#include <sys/types.h>
>>> +#include "tst_test.h"
>>> +#include "lapi/seek.h"
>>> +
>>> +#define TEST_ENXIO "test_enxio"
>>> +
>>> +static int fd_enxio;
>>> +
>>> +static struct test_case_t {
>>> +	int *fd;
>>> +	off_t offset;
>>> +	int whence;
>>> +	int expected_errno;
>>> +	char *desc;
>>> +} tcases[] = {
>>> +	{&fd_enxio, 10, SEEK_DATA, ENXIO,
>>> +		"whence is SEEK_DATA, "
>>> +		"file offset is beyond the end of the file"},
>>> +	{&fd_enxio, 10, SEEK_HOLE, ENXIO,
>>> +		"whence is SEEK_HOLE, "
>>> +		"file offset is beyond the end of the file"},
>>> +};
>>> +
>>> +static void setup(void)
>>> +{
>>> +	SAFE_TOUCH(TEST_ENXIO, 0777, NULL);
>>> +	fd_enxio = SAFE_OPEN(TEST_ENXIO, O_RDWR, 0777);
>>> +}
>>> +
>>> +static void cleanup(void)
>>> +{
>>> +	SAFE_CLOSE(fd_enxio);
>>> +}
>>> +
>>> +static void verify_lseek(unsigned int i)
>>> +{
>>> +	struct test_case_t *tc = &tcases[i];
>>> +	off_t offset;
>>> +
>>> +	offset = lseek(*(tc->fd), tc->offset, tc->whence);
>>> +	if (offset == -1) {
>>> +		if (errno == EINVAL) {
>>> +			tst_res(TCONF, "SEEK_DATA/SEEK_HOLE are not supported");
>>> +		} else {
>>> +			if (errno == tc->expected_errno) {
>>> +				tst_res(TPASS | TERRNO, tc->desc);
>>> +			} else {
>>> +				tst_res(TFAIL | TERRNO,
>>> +					"lseek() failed unexpectedly");
>>> +			}
>>> +		}
>>> +	} else {
>>> +		tst_res(TFAIL, "lseek() succeeded unexpectedly");
>>> +	}
>>> +}
>>> +
>>> +static struct tst_test test = {
>>> +	.setup = setup,
>>> +	.cleanup = cleanup,
>>> +	.tcnt = ARRAY_SIZE(tcases),
>>> +	.test = verify_lseek,
>>> +	.needs_tmpdir = 1,
>>> +};
>>>
>> Regards,
>> Avinesh
>>
>>

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

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

end of thread, other threads:[~2025-01-14 11:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-25  5:25 [LTP] [PATCH] lseek: Add negative tests for lseek Yang Xu via ltp
2024-05-13 11:31 ` Avinesh Kumar
2024-05-14  2:41   ` Yang Xu (Fujitsu) via ltp
2024-05-15  6:49     ` Petr Vorel
2025-01-14 11:58     ` Andrea Cervesato via ltp

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.