]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
tests: log api reboot test failures
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 9 Jan 2020 16:10:14 +0000 (17:10 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 9 Jan 2020 16:10:14 +0000 (17:10 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/tests/api_reboot.c

index f6864e8777accc72353ec25d961b42db6707be8c..9b5de497040234d5969802c9f93a17fa0b0c2294 100644 (file)
 
 #include "lxc/lxccontainer.h"
 #include "lxctest.h"
+#include "utils.h"
+
+#ifndef HAVE_STRLCPY
+#include "include/strlcpy.h"
+#endif
+
+#define TSTNAME "lxc-api-reboot"
 
 int main(int argc, char *argv[])
 {
        int i;
        struct lxc_container *c;
        int ret = EXIT_FAILURE;
+       struct lxc_log log;
+       char template[sizeof(P_tmpdir"/reboot_XXXXXX")];
+
+       (void)strlcpy(template, P_tmpdir"/reboot_XXXXXX", sizeof(template));
+
+       i = lxc_make_tmpfile(template, false);
+       if (i < 0) {
+               lxc_error("Failed to create temporary log file for container %s\n", TSTNAME);
+               exit(EXIT_FAILURE);
+       } else {
+               lxc_debug("Using \"%s\" as temporary log file for container %s\n", template, TSTNAME);
+               close(i);
+       }
+
+       log.name = TSTNAME;
+       log.file = template;
+       log.level = "TRACE";
+       log.prefix = "reboot";
+       log.quiet = false;
+       log.lxcpath = NULL;
+       if (lxc_log_init(&log))
+               exit(ret);
 
        /* Test that the reboot() API function properly waits for containers to
         * restart.
         */
-       c = lxc_container_new("reboot", NULL);
+       c = lxc_container_new(TSTNAME, NULL);
        if (!c) {
                lxc_error("%s", "Failed to create container \"reboot\"");
                exit(ret);
@@ -120,8 +149,24 @@ on_error_stop:
 on_error_put:
        lxc_container_put(c);
 
-       if (ret == EXIT_SUCCESS)
+       if (ret == EXIT_SUCCESS) {
                lxc_debug("%s\n", "All reboot tests passed");
+       } else {
+               int fd;
+
+               fd = open(template, O_RDONLY);
+               if (fd >= 0) {
+                       char buf[4096];
+                       ssize_t buflen;
+                       while ((buflen = read(fd, buf, 1024)) > 0) {
+                               buflen = write(STDERR_FILENO, buf, buflen);
+                               if (buflen <= 0)
+                                       break;
+                       }
+                       close(fd);
+               }
+       }
+       (void)unlink(template);
 
        exit(ret);
 }