Skip to content

Commit

Permalink
tests: Conditionalize openat64() calls
Browse files Browse the repository at this point in the history
Only test that libc call if it is actually available. It disappeared on
latest Alpine, which only has openat() now.
  • Loading branch information
martinpitt committed Dec 8, 2023
1 parent 11d6d3f commit 508a7d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ if cc.has_function('__fxstatat', prefix: '#include <sys/stat.h>')
add_project_arguments('-DHAVE_FXSTATAT', language: 'c')
endif

# Not always explicit
if cc.has_function('openat64', prefix: '#include <fcntl.h>')
add_project_arguments('-DHAVE_OPENAT64', language: 'c')
endif

meson.add_dist_script(srcdir / 'getversion.sh')

#
Expand Down
5 changes: 4 additions & 1 deletion tests/test-umockdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,11 +1131,13 @@ t_testbed_libc(UMockdevTestbedFixture * fixture, UNUSED_DATA)
g_assert_cmpint(fd, >=, 0);
close(fd);

#ifdef HAVE_OPENAT64
fd = openat64(dirfd, "sys/devices/dev1/simple_attr", O_RDONLY);
if (fd < 0)
perror("openat64");
g_assert_cmpint(fd, >=, 0);
close(fd);
#endif

close(dirfd);

Expand All @@ -1146,14 +1148,15 @@ t_testbed_libc(UMockdevTestbedFixture * fixture, UNUSED_DATA)
g_assert_cmpint(openat(dirfd, "sys", O_RDONLY), <, 0);
g_assert_cmpint(errno, ==, ENOENT);

g_assert_cmpint(errno, ==, ENOENT);
#ifdef HAVE_OPENAT64
g_assert_cmpint(openat64(dirfd, "sys", O_RDONLY), <, 0);
close(dirfd);

errno = 0;
g_assert_cmpint(openat(AT_FDCWD, "sys/devices", O_RDONLY), <, 0);
g_assert_cmpint(errno, ==, ENOENT);
g_assert_cmpint(openat64(AT_FDCWD, "sys/devices", O_RDONLY), <, 0);
#endif

/* stat */
g_assert_cmpint(stat ("/sys/bus/pci/devices", &st), ==, 0);
Expand Down

0 comments on commit 508a7d8

Please sign in to comment.