core: Apply the same treatment to the in errno message in __igt_fail_assert()
authorDamien Lespiau <damien.lespiau@intel.com>
Wed, 9 Jul 2014 10:40:16 +0000 (11:40 +0100)
committerDamien Lespiau <damien.lespiau@intel.com>
Thu, 10 Jul 2014 17:05:33 +0000 (18:05 +0100)
Just like the it was done for the requirement message, display the errno
message only if errno is set, and display it at the end of the assert
message.

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
lib/igt_core.c

index 03c1f61..bdeeb59 100644 (file)
@@ -678,11 +678,17 @@ void __igt_fail_assert(int exitcode, const char *file,
 {
        va_list args;
        int err = errno;
+       char *err_str = NULL;
+
+       if (err)
+               asprintf(&err_str, "Last errno: %i, %s\n", err, strerror(err));
 
        printf("Test assertion failure function %s, file %s:%i:\n"
-              "Last errno: %i, %s\n"
-              "Failed assertion: %s\n",
-              func, file, line, err, strerror(err), assertion);
+              "Failed assertion: %s\n"
+              "%s",
+              func, file, line, assertion, err_str ?: "");
+
+       free(err_str);
 
        if (f) {
                va_start(args, f);