summaryrefslogtreecommitdiff
path: root/src/test/test-fd-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-11-19 19:49:11 +0100
committerGitHub <noreply@github.com>2017-11-19 19:49:11 +0100
commit0133d5553a1b24185f251ebbc4d873606118780f (patch)
treea226c702e98793585741d7c0183c631e419ec12a /src/test/test-fd-util.c
parent0b252fc0bea31141c0073f7cd20b825d2f69284d (diff)
parent370f9c21b9560883ccbbf1cea4c94c9a6b81d8bd (diff)
downloadsystemd-0133d5553a1b24185f251ebbc4d873606118780f.tar.gz
Merge pull request #7198 from poettering/stdin-stdout
Add StandardInput=data, StandardInput=file:... and more
Diffstat (limited to 'src/test/test-fd-util.c')
-rw-r--r--src/test/test-fd-util.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/test/test-fd-util.c b/src/test/test-fd-util.c
index 4ad8fe75ea..f45fbbe7e3 100644
--- a/src/test/test-fd-util.c
+++ b/src/test/test-fd-util.c
@@ -25,6 +25,9 @@
#include "fd-util.h"
#include "fileio.h"
#include "macro.h"
+#include "random-util.h"
+#include "string-util.h"
+#include "util.h"
static void test_close_many(void) {
int fds[3];
@@ -104,11 +107,60 @@ static void test_open_serialization_fd(void) {
write(fd, "test\n", 5);
}
+static void test_acquire_data_fd_one(unsigned flags) {
+ char wbuffer[196*1024 - 7];
+ char rbuffer[sizeof(wbuffer)];
+ int fd;
+
+ fd = acquire_data_fd("foo", 3, flags);
+ assert_se(fd >= 0);
+
+ zero(rbuffer);
+ assert_se(read(fd, rbuffer, sizeof(rbuffer)) == 3);
+ assert_se(streq(rbuffer, "foo"));
+
+ fd = safe_close(fd);
+
+ fd = acquire_data_fd("", 0, flags);
+ assert_se(fd >= 0);
+
+ zero(rbuffer);
+ assert_se(read(fd, rbuffer, sizeof(rbuffer)) == 0);
+ assert_se(streq(rbuffer, ""));
+
+ fd = safe_close(fd);
+
+ random_bytes(wbuffer, sizeof(wbuffer));
+
+ fd = acquire_data_fd(wbuffer, sizeof(wbuffer), flags);
+ assert_se(fd >= 0);
+
+ zero(rbuffer);
+ assert_se(read(fd, rbuffer, sizeof(rbuffer)) == sizeof(rbuffer));
+ assert_se(memcmp(rbuffer, wbuffer, sizeof(rbuffer)) == 0);
+
+ fd = safe_close(fd);
+}
+
+static void test_acquire_data_fd(void) {
+
+ test_acquire_data_fd_one(0);
+ test_acquire_data_fd_one(ACQUIRE_NO_DEV_NULL);
+ test_acquire_data_fd_one(ACQUIRE_NO_MEMFD);
+ test_acquire_data_fd_one(ACQUIRE_NO_DEV_NULL|ACQUIRE_NO_MEMFD);
+ test_acquire_data_fd_one(ACQUIRE_NO_PIPE);
+ test_acquire_data_fd_one(ACQUIRE_NO_DEV_NULL|ACQUIRE_NO_PIPE);
+ test_acquire_data_fd_one(ACQUIRE_NO_MEMFD|ACQUIRE_NO_PIPE);
+ test_acquire_data_fd_one(ACQUIRE_NO_DEV_NULL|ACQUIRE_NO_MEMFD|ACQUIRE_NO_PIPE);
+ test_acquire_data_fd_one(ACQUIRE_NO_DEV_NULL|ACQUIRE_NO_MEMFD|ACQUIRE_NO_PIPE|ACQUIRE_NO_TMPFILE);
+}
+
int main(int argc, char *argv[]) {
test_close_many();
test_close_nointr();
test_same_fd();
test_open_serialization_fd();
+ test_acquire_data_fd();
return 0;
}