Diff of /libop/tests/mangle_tests.c [9871f0] .. [0d0e60] Maximize Restore

  Switch to side-by-side view

--- a/libop/tests/mangle_tests.c
+++ b/libop/tests/mangle_tests.c
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "op_libiberty.h"
 #include "op_mangle.h"
 #include "op_config.h"
 
@@ -21,25 +22,26 @@
 };
 
 static struct test_input const tests[] = {
-	{ { MANGLE_NONE, "foo", "bar", "EVENT", 0, 0, 0, 0, 0 },
-	  OP_SAMPLES_CURRENT_DIR "{root}/foo/EVENT.0.0.all.all.all" },
-	{ { MANGLE_DEP_NAME, "foo", "bar", "EVENT", 0, 0, 0, 0, 0 },
-	  OP_SAMPLES_CURRENT_DIR "{root}/bar/{dep}/{root}/foo/EVENT.0.0.all.all.all" },
-	{ { MANGLE_CPU, "foo", "bar", "EVENT", 0, 0, 0, 0, 2 },
-	  OP_SAMPLES_CURRENT_DIR "{root}/foo/EVENT.0.0.all.all.2" },
+	{ { MANGLE_NONE, "foo", "bar", NULL, "EVENT", 0, 0, 0, 0, 0 },
+	  "{root}/bar/{dep}/{root}/foo/EVENT.0.0.all.all.all" },
+	{ { MANGLE_CPU, "foo", "bar", NULL, "EVENT", 0, 0, 0, 0, 2 },
+	  "{root}/bar/{dep}/{root}/foo/EVENT.0.0.all.all.2" },
+	{ { MANGLE_TID, "foo", "bar", NULL, "EVENT", 0, 0, 0, 33, 0 },
+	  "{root}/bar/{dep}/{root}/foo/EVENT.0.0.all.33.all" },
+	{ { MANGLE_TGID, "foo", "bar", NULL, "EVENT", 0, 0, 34, 0, 0 },
+	  "{root}/bar/{dep}/{root}/foo/EVENT.0.0.34.all.all" },
+	{ { MANGLE_KERNEL, "foo", "bar", NULL, "EVENT", 0, 0, 0, 0, 0 },
+	  "{kern}/bar/{dep}/{kern}/foo/EVENT.0.0.all.all.all" },
+	{ { MANGLE_CALLGRAPH, "foo-from", "bar-from", "foo-to", "EVENT", 0, 0, 0, 0, 0 },
+	  "{root}/bar-from/{dep}/{root}/foo-from/{cg}/{root}/foo-to/EVENT.0.0.all.all.all" },
+	{ { MANGLE_CPU|MANGLE_TID|MANGLE_TID|MANGLE_TGID|MANGLE_KERNEL, "foo", "bar", NULL, "EVENT", 1234, 8192, 34, 35, 2 },
+	  "{kern}/bar/{dep}/{kern}/foo/EVENT.1234.8192.34.35.2" },
+	{ { MANGLE_CPU|MANGLE_TID|MANGLE_TID|MANGLE_TGID|MANGLE_KERNEL, "foo1/foo2", "bar1/bar2", NULL, "EVENT", 1234, 8192, 34, 35, 2 },
+	  "{root}/bar1/bar2/{dep}/{root}/foo1/foo2/EVENT.1234.8192.34.35.2" },
+	{ { MANGLE_CALLGRAPH|MANGLE_CPU|MANGLE_TID|MANGLE_TID|MANGLE_TGID|MANGLE_KERNEL, "bar1/bar2", "bar1/bar2", "bar1/bar2-to", "EVENT", 1234, 8192, 34, 35, 2 },
+	  "{root}/bar1/bar2/{dep}/{root}/bar1/bar2/{cg}/{root}/bar1/bar2-to/EVENT.1234.8192.34.35.2" },
 
-	{ { MANGLE_TID, "foo", "bar", "EVENT", 0, 0, 0, 33, 0 },
-	  OP_SAMPLES_CURRENT_DIR "{root}/foo/EVENT.0.0.all.33.all" },
-	{ { MANGLE_TGID, "foo", "bar", "EVENT", 0, 0, 34, 0, 0 },
-	  OP_SAMPLES_CURRENT_DIR "{root}/foo/EVENT.0.0.34.all.all" },
-	{ { MANGLE_KERNEL, "foo", "bar", "EVENT", 0, 0, 0, 0, 0 },
-	  OP_SAMPLES_CURRENT_DIR "{kern}/foo/EVENT.0.0.all.all.all" },
-	{ { MANGLE_DEP_NAME|MANGLE_CPU|MANGLE_TID|MANGLE_TID|MANGLE_TGID|MANGLE_KERNEL, "foo", "bar", "EVENT", 1234, 8192, 34, 35, 2 },
-	  OP_SAMPLES_CURRENT_DIR "{kern}/bar/{dep}/{kern}/foo/EVENT.1234.8192.34.35.2" },
-	{ { MANGLE_DEP_NAME|MANGLE_CPU|MANGLE_TID|MANGLE_TID|MANGLE_TGID|MANGLE_KERNEL, "foo1/foo2", "bar1/bar2", "EVENT", 1234, 8192, 34, 35, 2 },
-	  OP_SAMPLES_CURRENT_DIR "{root}/bar1/bar2/{dep}/{root}/foo1/foo2/EVENT.1234.8192.34.35.2" },
-
-	{ { 0, NULL, NULL, NULL, 0, 0, 0, 0, 0 }, NULL }
+	{ { 0, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0 }, NULL }
 };
 
 
@@ -48,11 +50,16 @@
 	struct test_input const * test;
 	for (test = tests; test->result; ++test) {
 		char * result = op_mangle_filename(&test->values);
-		if (strcmp(result, test->result)) {
-			fprintf(stderr, "test %d:\nfound: %s\nexpect:%s\n",
-				(int)(test - tests), result, test->result);
+		char * expect = xmalloc(strlen(test->result) +
+					strlen(OP_SAMPLES_CURRENT_DIR) + 1);
+		strcpy(expect, OP_SAMPLES_CURRENT_DIR);
+		strcat(expect, test->result);
+		if (strcmp(result, expect)) {
+			fprintf(stderr, "test %d:\nfound: %s\nexpect: %s\n",
+				(int)(test - tests), result, expect);
 			exit(EXIT_FAILURE);
 		}
+		free(expect);
 		free(result);
 	}