[rtems commit] libtest: Output basename of source files

Sebastian Huber sebh at rtems.org
Mon Nov 25 10:45:28 UTC 2019


Module:    rtems
Branch:    master
Commit:    a0304e8d62325b4f3c07c0c520220c7929eea1c0
Changeset: http://git.rtems.org/rtems/commit/?id=a0304e8d62325b4f3c07c0c520220c7929eea1c0

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Nov 22 11:28:55 2019 +0100

libtest: Output basename of source files

Output only the basename of source files to be independent of the build
system source paths.

In the future it may be better to use the GCC -fmacro-prefix-map option.
This option is available in GCC 8 and later.  It is not yet available in
clang.

Update #3818.

---

 cpukit/libtest/t-test.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/cpukit/libtest/t-test.c b/cpukit/libtest/t-test.c
index 6338750..5e9be54 100644
--- a/cpukit/libtest/t-test.c
+++ b/cpukit/libtest/t-test.c
@@ -480,6 +480,20 @@ T_case_name(void)
 	}
 }
 
+static const char *
+T_file(const T_check_context *t)
+{
+	const char *file;
+
+	file = strrchr(t->file, '/');
+
+	if (file == NULL) {
+		return t->file;
+	}
+
+	return file + 1;
+}
+
 void
 T_check_true(bool ok, const T_check_context *t, const char *fmt, ...)
 {
@@ -502,7 +516,7 @@ T_check_true(bool ok, const T_check_context *t, const char *fmt, ...)
 		     step != T_CHECK_STEP_FROM_FLAGS(t->flags)) {
 			T_add_failure(ctx);
 			T_printf("F:%u:%i:%s:%s:%i:planned step (%u)\n", step,
-			    T_cpu(), T_scope(scope), t->file, t->line,
+			    T_cpu(), T_scope(scope), T_file(t), t->line,
 			    T_CHECK_STEP_FROM_FLAGS(t->flags));
 		} else if (!ok) {
 			T_add_failure(ctx);
@@ -511,10 +525,10 @@ T_check_true(bool ok, const T_check_context *t, const char *fmt, ...)
 				if ((t->flags & T_CHECK_QUIET) == 0) {
 					T_printf("F:%u:%i:%s:%s:%i:",
 					    step, T_cpu(), T_scope(scope),
-					    t->file, t->line);
+					    T_file(t), t->line);
 				} else {
 					T_printf("F:*:%i:%s:%s:%i:", T_cpu(),
-					    T_scope(scope), t->file, t->line);
+					    T_scope(scope), T_file(t), t->line);
 				}
 
 				va_start(ap, fmt);
@@ -530,7 +544,7 @@ T_check_true(bool ok, const T_check_context *t, const char *fmt, ...)
 		} else if ((t->flags & T_CHECK_QUIET) == 0 &&
 		    ctx->verbosity >= T_VERBOSE) {
 			T_printf("P:%u:%i:%s:%s:%i\n", step, T_cpu(),
-			    T_scope(scope), t->file, t->line);
+			    T_scope(scope), T_file(t), t->line);
 		}
 	} else if (!ok) {
 		T_add_failure(ctx);



More information about the vc mailing list