meta-agl-profile-telematics: recipes-core: systemd: change canbus systemd match regex
[AGL/meta-agl.git] / meta-agl-bsp / recipes-support / ptest-runner / ptest-runner / 0003-Add-support-to-avoid-load-run-twice-a-run_ptest-scri.patch
1 From 0e566f65fa31eaa5208d4a17413c7a4aad7eade5 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?An=C3=ADbal=20Lim=C3=B3n?= <anibal.limon@linaro.org>
3 Date: Thu, 7 Dec 2017 17:42:45 -0600
4 Subject: [PATCH 3/7] Add support to avoid load/run twice a run_ptest script
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 In some ptest packages exists symlink in the ptest directory causing
10 to load/run twice the same ptest,
11
12 For example in perl5:
13
14 /usr/lib/perl -> /usr/lib/perl5
15
16 Signed-off-by: Aníbal Limón <anibal.limon@linaro.org>
17 ---
18  ptest_list.c       | 40 ++++++++++++++++++++++++++++++++++++++++
19  ptest_list.h       |  3 +++
20  tests/data/python3 |  1 +
21  tests/utils.c      |  1 +
22  utils.c            |  6 ++++++
23  5 files changed, 51 insertions(+)
24  create mode 120000 tests/data/python3
25
26 diff --git a/ptest_list.c b/ptest_list.c
27 index 2e1aa305752d..3e393d5fabe2 100644
28 --- a/ptest_list.c
29 +++ b/ptest_list.c
30 @@ -110,6 +110,46 @@ ptest_list_search(struct ptest_list *head, char *ptest)
31         return q;
32  }
33  
34 +
35 +struct ptest_list *
36 +ptest_list_search_by_file(struct ptest_list *head, char *run_ptest, struct stat st_buf)
37 +{
38 +       struct ptest_list *q = NULL;
39 +       struct ptest_list *p;
40 +       struct stat st_buf_p;
41 +
42 +       VALIDATE_PTR_RNULL(head);
43 +       VALIDATE_PTR_RNULL(run_ptest);
44 +
45 +       for (p = head; p != NULL; p = p->next) {
46 +               if (p->ptest == NULL) 
47 +                       continue;
48 +
49 +               if (stat(p->run_ptest, &st_buf_p) == -1)
50 +                       continue;
51 +
52 +               if (strcmp(p->run_ptest, run_ptest) == 0) {
53 +                       q = p;
54 +                       break;
55 +               }
56 +
57 +               /* *
58 +                * In some ptest packages exists symlink in the ptest directory
59 +                * causing to load/run twice the same ptest, 
60 +                *
61 +                * For example in perl5:
62 +                * /usr/lib/perl -> /usr/lib/perl5
63 +                * */
64 +               if (st_buf.st_dev == st_buf_p.st_dev &&
65 +                   st_buf.st_ino == st_buf_p.st_ino) {
66 +                       q = p;
67 +                       break;
68 +               }
69 +       }
70 +
71 +       return q;
72 +}
73 +
74  struct ptest_list *
75  ptest_list_add(struct ptest_list *head, char *ptest, char *run_ptest)
76  {
77 diff --git a/ptest_list.h b/ptest_list.h
78 index 8b394853c25b..03d75390a51d 100644
79 --- a/ptest_list.h
80 +++ b/ptest_list.h
81 @@ -28,6 +28,8 @@
82  #define PTEST_LIST_ITERATE_START(head, p) for (p = head->next; p != NULL; p = p->next) { 
83  #define PTEST_LIST_ITERATE_END }
84  
85 +#include <sys/stat.h>
86 +
87  struct ptest_list {
88         char *ptest;
89         char *run_ptest;
90 @@ -42,6 +44,7 @@ extern int ptest_list_free_all(struct ptest_list *);
91  
92  extern int ptest_list_length(struct ptest_list *);
93  extern struct ptest_list *ptest_list_search(struct ptest_list *, char *);
94 +extern struct ptest_list *ptest_list_search_by_file(struct ptest_list *, char *, struct stat);
95  extern struct ptest_list *ptest_list_add(struct ptest_list *, char *, char *);
96  extern struct ptest_list *ptest_list_remove(struct ptest_list *, char *, int);
97  
98 diff --git a/tests/data/python3 b/tests/data/python3
99 new file mode 120000
100 index 000000000000..d8654aa0e2f2
101 --- /dev/null
102 +++ b/tests/data/python3
103 @@ -0,0 +1 @@
104 +python
105 \ No newline at end of file
106 diff --git a/tests/utils.c b/tests/utils.c
107 index ecf3e8af9a81..cf093793c4f2 100644
108 --- a/tests/utils.c
109 +++ b/tests/utils.c
110 @@ -48,6 +48,7 @@ static int ptests_found_length = 6;
111  static char *ptests_not_found[] = {
112         "busybox",
113         "perl",
114 +       "python3",
115         NULL,
116  };
117  
118 diff --git a/utils.c b/utils.c
119 index 933ecedf57e8..ed2eff7900c1 100644
120 --- a/utils.c
121 +++ b/utils.c
122 @@ -143,6 +143,12 @@ get_available_ptests(const char *dir)
123                                 continue;
124                         }
125  
126 +                       if (ptest_list_search_by_file(head, run_ptest, st_buf)) {
127 +                               free(run_ptest);
128 +                               free(d_name);
129 +                               continue;
130 +                       }
131 +
132                         struct ptest_list *p = ptest_list_add(head,
133                                 d_name, run_ptest);
134                         CHECK_ALLOCATION(p, sizeof(struct ptest_list *), 0);
135 -- 
136 2.11.0
137