summaryrefslogtreecommitdiffstats
path: root/test/test_filesystem.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-06-23 08:41:36 -0400
committerDavid Robillard <d@drobilla.net>2024-06-23 08:50:07 -0400
commitc147881d999fa966ea266d6feac2a3fabeef511b (patch)
tree27ba19de9546f33b7f270faf674eb032b1349487 /test/test_filesystem.c
parent94f97199da6064080ae1cdf99048c8d4f01600a5 (diff)
downloadzix-c147881d999fa966ea266d6feac2a3fabeef511b.tar.gz
zix-c147881d999fa966ea266d6feac2a3fabeef511b.tar.bz2
zix-c147881d999fa966ea266d6feac2a3fabeef511b.zip
Skip socket file type test with absurdly long TMPDIR
If TMPDIR is so long that it doesn't fit in the socket address field, then it's impossible to create a socket in the temporary directory. This is a pretty weird situation that would never happen on a normal system, so I think the test can just be skipped without the reduced coverage being a problem.
Diffstat (limited to 'test/test_filesystem.c')
-rw-r--r--test/test_filesystem.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/test/test_filesystem.c b/test/test_filesystem.c
index 4a1ad4f..87a3d15 100644
--- a/test/test_filesystem.c
+++ b/test/test_filesystem.c
@@ -162,14 +162,18 @@ test_file_type(void)
const socklen_t addr_len = sizeof(struct sockaddr_un);
struct sockaddr_un* const addr = (struct sockaddr_un*)calloc(1, addr_len);
- addr->sun_family = AF_UNIX;
- strncpy(addr->sun_path, file_path, sizeof(addr->sun_path) - 1);
-
- const int fd = bind(sock, (struct sockaddr*)addr, addr_len);
- if (fd >= 0) {
- assert(zix_file_type(file_path) == ZIX_FILE_TYPE_SOCKET);
- assert(!zix_remove(file_path));
- close(fd);
+ if (strlen(file_path) < sizeof(addr->sun_path)) {
+ addr->sun_family = AF_UNIX;
+ strncpy(addr->sun_path, file_path, sizeof(addr->sun_path) - 1);
+
+ const int fd = bind(sock, (struct sockaddr*)addr, addr_len);
+ if (fd >= 0) {
+ assert(zix_file_type(file_path) == ZIX_FILE_TYPE_SOCKET);
+ assert(!zix_remove(file_path));
+ close(fd);
+ }
+ } else {
+ fprintf(stderr, "warning: Skipped socket test with oddly long TMPDIR\n");
}
close(sock);