tests: provide test_tool_stdin_write()
authorBartosz Golaszewski <bartekgola@gmail.com>
Mon, 12 Jun 2017 20:02:37 +0000 (22:02 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Mon, 12 Jun 2017 20:02:37 +0000 (22:02 +0200)
Implement a routine allowing the test code to write a formatted string
to the child process' standard input.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
tests/gpiod-test.c
tests/gpiod-test.h

index e273ab394f1e10c6299327ccc92ffa7a472d3c34..6a671e6aa40bec31a61d7b14463ac679af0149fa 100644 (file)
@@ -446,6 +446,28 @@ void test_tool_signal(int signum)
                die_perr("unable to send signal to process %d", proc->pid);
 }
 
+void test_tool_stdin_write(const char *fmt, ...)
+{
+       struct gpiotool_proc *proc = &globals.test_ctx.tool_proc;
+       ssize_t written;
+       va_list va;
+       char *in;
+       int rv;
+
+       va_start(va, fmt);
+       rv = vasprintf(&in, fmt, va);
+       va_end(va);
+       if (rv < 0)
+               die_perr("error building string");
+
+       written = write(proc->stdin_fd, in, rv);
+       free(in);
+       if (written < 0)
+               die_perr("error writing to child process' stdin");
+       if (written != rv)
+               die("unable to write all data to child process' stdin");
+}
+
 void test_tool_run(char *tool, ...)
 {
        int in_fds[2], out_fds[2], err_fds[2], status;
index 4ba89ed32e25138831909ea866fd30d9e1c28a10..e342677c41b60140dc494553280c6bdf1f522d24 100644 (file)
@@ -110,6 +110,7 @@ const char * test_tool_stderr(void);
 bool test_tool_exited(void);
 int test_tool_exit_status(void);
 void test_tool_signal(int signum);
+void test_tool_stdin_write(const char *fmt, ...) TEST_PRINTF(1, 2);
 
 /*
  * Every TEST_ASSERT_*() macro expansion can make a test function return, so