Skip to content

Commit 4c7f09a

Browse files
committed
selftests/nolibc: use a pipe to in vfprintf tests
Not all architectures implement lseek(), for example riscv32 only implements llseek() which is not equivalent to normal lseek(). Remove the need for lseek() by using a pipe instead. Link: https://lore.kernel.org/r/20241221-nolibc-rv32-v1-3-d9ef6dab7c63@weissschuh.net Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
1 parent a0bc894 commit 4c7f09a

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

tools/testing/selftests/nolibc/nolibc-test.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,19 +1229,20 @@ int run_stdlib(int min, int max)
12291229

12301230
static int expect_vfprintf(int llen, int c, const char *expected, const char *fmt, ...)
12311231
{
1232-
int ret, fd;
1232+
int ret, pipefd[2];
12331233
ssize_t w, r;
12341234
char buf[100];
12351235
FILE *memfile;
12361236
va_list args;
12371237

1238-
fd = open("/tmp", O_TMPFILE | O_EXCL | O_RDWR, 0600);
1239-
if (fd == -1) {
1240-
result(llen, SKIPPED);
1241-
return 0;
1238+
ret = pipe(pipefd);
1239+
if (ret == -1) {
1240+
llen += printf(" pipe() != %s", strerror(errno));
1241+
result(llen, FAIL);
1242+
return 1;
12421243
}
12431244

1244-
memfile = fdopen(fd, "w+");
1245+
memfile = fdopen(pipefd[1], "w");
12451246
if (!memfile) {
12461247
result(llen, FAIL);
12471248
return 1;
@@ -1257,13 +1258,10 @@ static int expect_vfprintf(int llen, int c, const char *expected, const char *fm
12571258
return 1;
12581259
}
12591260

1260-
fflush(memfile);
1261-
lseek(fd, 0, SEEK_SET);
1262-
1263-
r = read(fd, buf, sizeof(buf) - 1);
1264-
12651261
fclose(memfile);
12661262

1263+
r = read(pipefd[0], buf, sizeof(buf) - 1);
1264+
12671265
if (r != w) {
12681266
llen += printf(" written(%d) != read(%d)", (int)w, (int)r);
12691267
result(llen, FAIL);

0 commit comments

Comments
 (0)