* [LTP] [PATCH v2] syscalls: Fix tst_res() format string for 64-bit offset
@ 2022-09-20 11:43 Randolph Lin
2022-09-20 18:49 ` Petr Vorel
0 siblings, 1 reply; 2+ messages in thread
From: Randolph Lin @ 2022-09-20 11:43 UTC (permalink / raw)
To: ltp, rpalethorpe, chrubis; +Cc: Mina, kester.tw, alankao
From: Randolph <randolph@andestech.com>
When compiling format string contains off_t type, to print off_t
correctly is cast it to (long long int) type and change the format
string to %lli.
Fix format string for type block_size.
Co-developed-by: Randolph <randolph@andestech.com>
Signed-off-by: Mina <minachou@andestech.com>
---
testcases/kernel/syscalls/lseek/lseek01.c | 17 +++++++++--------
testcases/kernel/syscalls/lseek/lseek07.c | 17 +++++++++--------
testcases/kernel/syscalls/lseek/lseek11.c | 11 ++++++-----
testcases/kernel/syscalls/sendfile/sendfile05.c | 3 ++-
4 files changed, 26 insertions(+), 22 deletions(-)
diff --git a/testcases/kernel/syscalls/lseek/lseek01.c b/testcases/kernel/syscalls/lseek/lseek01.c
index 22d9fbfd7..a48b2d4c0 100644
--- a/testcases/kernel/syscalls/lseek/lseek01.c
+++ b/testcases/kernel/syscalls/lseek/lseek01.c
@@ -46,25 +46,26 @@ static void verify_lseek(unsigned int n)
TEST(lseek(fd, tc->off, tc->whence));
if (TST_RET == (off_t) -1) {
- tst_res(TFAIL | TTERRNO, "lseek(%s, %ld, %s) failed", TFILE,
- tc->off, tc->wname);
+ tst_res(TFAIL | TTERRNO, "lseek(%s, %lli, %s) failed", TFILE,
+ (long long int)tc->off, tc->wname);
return;
}
if (TST_RET != tc->exp_off) {
- tst_res(TFAIL, "lseek(%s, %ld, %s) returned %ld, expected %ld",
- TFILE, tc->off, tc->wname, TST_RET, tc->exp_off);
+ tst_res(TFAIL, "lseek(%s, %lli, %s) returned %ld, expected %lli",
+ TFILE, (long long int)tc->off, tc->wname, TST_RET,
+ (long long int)tc->exp_off);
return;
}
SAFE_READ(1, fd, read_buf, tc->exp_size);
if (tc->exp_data && strcmp(read_buf, tc->exp_data)) {
- tst_res(TFAIL, "lseek(%s, %ld, %s) read incorrect data",
- TFILE, tc->off, tc->wname);
+ tst_res(TFAIL, "lseek(%s, %lli, %s) read incorrect data",
+ TFILE, (long long int)tc->off, tc->wname);
} else {
- tst_res(TPASS, "lseek(%s, %ld, %s) read correct data",
- TFILE, tc->off, tc->wname);
+ tst_res(TPASS, "lseek(%s, %lli, %s) read correct data",
+ TFILE, (long long int)tc->off, tc->wname);
}
}
diff --git a/testcases/kernel/syscalls/lseek/lseek07.c b/testcases/kernel/syscalls/lseek/lseek07.c
index ae6f48f37..62d399797 100644
--- a/testcases/kernel/syscalls/lseek/lseek07.c
+++ b/testcases/kernel/syscalls/lseek/lseek07.c
@@ -43,14 +43,15 @@ static void verify_lseek(unsigned int n)
TEST(lseek(*tc->fd, tc->off, SEEK_SET));
if (TST_RET == (off_t) -1) {
- tst_res(TFAIL | TTERRNO, "lseek(%s, %ld, SEEK_SET) failed",
- tc->fname, tc->off);
+ tst_res(TFAIL | TTERRNO, "lseek(%s, %lli, SEEK_SET) failed",
+ tc->fname, (long long int)tc->off);
return;
}
if (TST_RET != tc->exp_off) {
- tst_res(TFAIL, "lseek(%s, %ld, SEEK_SET) returned %ld, expected %ld",
- tc->fname, tc->off, TST_RET, tc->exp_off);
+ tst_res(TFAIL, "lseek(%s, %lli, SEEK_SET) returned %ld, expected %lli",
+ tc->fname, (long long int)tc->off, TST_RET,
+ (long long int)tc->exp_off);
return;
}
@@ -63,11 +64,11 @@ static void verify_lseek(unsigned int n)
SAFE_READ(1, *tc->fd, read_buf, tc->exp_size);
if (strcmp(read_buf, tc->exp_data)) {
- tst_res(TFAIL, "lseek(%s, %ld, SEEK_SET) wrote incorrect data %s",
- tc->fname, tc->off, read_buf);
+ tst_res(TFAIL, "lseek(%s, %lli, SEEK_SET) wrote incorrect data %s",
+ tc->fname, (long long int)tc->off, read_buf);
} else {
- tst_res(TPASS, "lseek(%s, %ld, SEEK_SET) wrote correct data %s",
- tc->fname, tc->off, read_buf);
+ tst_res(TPASS, "lseek(%s, %lli, SEEK_SET) wrote correct data %s",
+ tc->fname, (long long int)tc->off, read_buf);
}
}
diff --git a/testcases/kernel/syscalls/lseek/lseek11.c b/testcases/kernel/syscalls/lseek/lseek11.c
index 14435f617..2a2383a4a 100644
--- a/testcases/kernel/syscalls/lseek/lseek11.c
+++ b/testcases/kernel/syscalls/lseek/lseek11.c
@@ -159,7 +159,7 @@ static void setup(void)
fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0666);
get_blocksize();
- tst_res(TINFO, "The block size is %lu", block_size);
+ tst_res(TINFO, "The block size is %d", block_size);
/*
* truncate to the expected file size directly, to keep away the effect
@@ -202,14 +202,15 @@ static void test_lseek(unsigned int n)
if (rc != 0) {
tst_res(TFAIL,
- "The %uth test failed: %s from startblock %ld offset %ld, expect \'%s\' return \'%s\'",
+ "The %uth test failed: %s from startblock %lli offset %lli, expect \'%s\' return \'%s\'",
n, (tp->whence == SEEK_DATA) ? "SEEK_DATA" : "SEEK_HOLE",
- tp->startblock, tp->offset, tp->data ? tp->data : "", buf);
+ (long long int)tp->startblock, (long long int)tp->offset,
+ tp->data ? tp->data : "", buf);
} else {
tst_res(TPASS,
- "The %uth test passed: %s from startblock %ld offset %ld",
+ "The %uth test passed: %s from startblock %lli offset %lli",
n, (tp->whence == SEEK_DATA) ? "SEEK_DATA" : "SEEK_HOLE",
- tp->startblock, tp->offset);
+ (long long int)tp->startblock, (long long int)tp->offset);
}
}
diff --git a/testcases/kernel/syscalls/sendfile/sendfile05.c b/testcases/kernel/syscalls/sendfile/sendfile05.c
index e271a47d4..1879b4666 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile05.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile05.c
@@ -39,7 +39,8 @@ static void run(void)
off_t offset = -1;
TST_EXP_FAIL(sendfile(out_fd, in_fd, &offset, 1), EINVAL,
- "sendfile(out, in, &offset, ..) with offset=%ld", offset);
+ "sendfile(out, in, &offset, ..) with offset=%lli",
+ (long long int)offset);
}
static struct tst_test test = {
--
2.34.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [LTP] [PATCH v2] syscalls: Fix tst_res() format string for 64-bit offset
2022-09-20 11:43 [LTP] [PATCH v2] syscalls: Fix tst_res() format string for 64-bit offset Randolph Lin
@ 2022-09-20 18:49 ` Petr Vorel
0 siblings, 0 replies; 2+ messages in thread
From: Petr Vorel @ 2022-09-20 18:49 UTC (permalink / raw)
To: Randolph Lin; +Cc: alankao, Mina, kester.tw, ltp
Hi Randolph,
> When compiling format string contains off_t type, to print off_t
> correctly is cast it to (long long int) type and change the format
> string to %lli.
LGTM, I'd just use %lld instead of %lli (it's exactly the same, but %lld is IMHO
more common.
Kind regards,
Petr
...
> +++ b/testcases/kernel/syscalls/lseek/lseek11.c
> @@ -159,7 +159,7 @@ static void setup(void)
> fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0666);
> get_blocksize();
> - tst_res(TINFO, "The block size is %lu", block_size);
> + tst_res(TINFO, "The block size is %d", block_size);
This is wrong. While blksize_t is on aarch64 and riscv64 int, on
most archs is long, thus this needs to have the same approach as the rest
(%lld and (long long int) cast.
with these 2 changes:
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-09-20 18:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-20 11:43 [LTP] [PATCH v2] syscalls: Fix tst_res() format string for 64-bit offset Randolph Lin
2022-09-20 18:49 ` Petr Vorel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox