blob: 822b26a367aeca760d8c8a7902deb42d38dfbf96 [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001From 83d165442d1c3658b6bafa28ddade8ffee7092ad Mon Sep 17 00:00:00 2001
2From: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
3Date: Wed, 6 Mar 2019 16:46:49 -0500
4Subject: [PATCH lttng-tools 2/2] Fix: test: unit: the tree origin can be a
5 symlink itself
6
7Problem:
8
9The base tree is defined as "/tmp/.....XXXXXX".
10On systems where "/tmp/" is itself a symlink utils_expand_path will
11expand the tree origin itself.
12
13For example on a base core-image-minimal Yocto build /tmp is a symlink
14to "/var/tmp", which is a symlink to "/var/volatile".
15
16utils_expand_path will return something like this for the symlink test:
17"/var/volative/.....XXXXXX/...." which is the valid result.
18
19Solution:
20
21Simply use realpath on the tree_origin and use this path to perform the
22test validation.
23
24This work was performed in the effort to support yocto fully and be able
25to run the test suite to detect problem as early as possible.
26
27
28Upstream-Status: Accepted [f66e964a2e0c75f5e1a55fbcc963b1c5e2b4519d]
29Backported to 2.11 and 2.10
30
31Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
32---
33 tests/unit/test_utils_expand_path.c | 18 ++++++++++++++----
34 1 file changed, 14 insertions(+), 4 deletions(-)
35
36diff --git a/tests/unit/test_utils_expand_path.c b/tests/unit/test_utils_expand_path.c
37index d5cab002e..d047c207d 100644
38--- a/tests/unit/test_utils_expand_path.c
39+++ b/tests/unit/test_utils_expand_path.c
40@@ -281,8 +281,8 @@ error:
41 static void test_utils_expand_path(void)
42 {
43 char *result;
44- char name[100], tmppath[PATH_MAX];
45- int i;
46+ char name[100], tmppath[PATH_MAX], real_tree_origin[PATH_MAX];
47+ int i, treelen;
48
49 /* Test valid cases */
50 for (i = 0; i < num_valid_tests; i++) {
51@@ -295,14 +295,24 @@ static void test_utils_expand_path(void)
52 free(result);
53 }
54
55+ /*
56+ * Get the realpath for the tree_origin since it can itself be a
57+ * symlink.
58+ */
59+ result = realpath(tree_origin, real_tree_origin);
60+ if (!result) {
61+ fail("realpath failed.");
62+ return;
63+ }
64+
65 /* Test symlink tree cases */
66- int treelen = strlen(tree_origin) + 1;
67+ treelen = strlen(real_tree_origin) + 1;
68 for (i = 0; i < num_symlink_tests; i++) {
69 sprintf(name, "symlink tree test case: [tmppath/]%s",
70 symlink_tests_inputs[i].input);
71
72 snprintf(tmppath, PATH_MAX, "%s/%s",
73- tree_origin, symlink_tests_inputs[i].input);
74+ real_tree_origin, symlink_tests_inputs[i].input);
75 result = utils_expand_path(tmppath);
76 ok(result != NULL && strcmp(result + treelen,
77 symlink_tests_inputs[i].expected_result) == 0, name);
78--
792.17.1
80