meta-agl-core: update ptest-runner patch
[AGL/meta-agl.git] / meta-agl-core / recipes-support / ptest-runner / ptest-runner / 0007-WIP-Initial-LAVA-support.patch
1 From bdcbb0e78bbffe45719d0a27954544120f37442a Mon Sep 17 00:00:00 2001
2 From: Tim Orling <timothy.t.orling@linux.intel.com>
3 Date: Mon, 15 Oct 2018 18:30:42 -0700
4 Subject: [PATCH] Initial LAVA support
5
6 Linaro Automated Validation Architecture (LAVA) launches a test suite
7 on the target but thereafter only observes stdout.
8
9 LAVA knows that a test case has started or ended based on signals
10 emitted to stdout:
11 (setup)
12 <LAVA_SIGNAL_STARTTC test_case_name>
13 (teardown)
14 <LAVA_SIGNAL_ENDTC test_case_name>
15 <LAVA_SIGNAL_TESTCASE TEST_CASE_ID=test_case_name RESULT=pass|fail \
16   [[ MEASUREMENT=numeric_measurement ][ UNITS=units_string]]>
17
18 It is valid to have a measurement without units, but not units without a measurement.
19
20 Upstream-Status: Pending
21
22 Signed-off-by: Tim Orling <timothy.t.orling@linux.intel.com>
23 [updated for ptest-runner 2.3.2]
24 [updated for ptest-runner 2.4.1]
25 [updated for ptest-runner 2.4.2]
26 [updated for ptest-runner 2.4.4]
27 Signed-off-by: Scott Murray <scott.murray@konsulko.com>
28 ---
29  flags.h | 10 ++++++++++
30  main.c  |  9 ++++++++-
31  utils.c | 20 +++++++++++++++++++-
32  utils.h |  2 +-
33  4 files changed, 38 insertions(+), 3 deletions(-)
34  create mode 100644 flags.h
35
36 diff --git a/flags.h b/flags.h
37 new file mode 100644
38 index 0000000..0dac223
39 --- /dev/null
40 +++ b/flags.h
41 @@ -0,0 +1,10 @@
42 +/* SPDX-License-Identifier: GPL-2.0 */
43 +
44 +/* Flag bit definitions */
45 +
46 +#ifndef __FLAGS_H__
47 +#define __FLAGS_H__
48 +
49 +#define LAVA_SIGNAL_ENABLE     (0x0001)
50 +
51 +#endif                         /* __FLAGS_H__ */
52 diff --git a/main.c b/main.c
53 index 31e4dd5..f12d6d6 100644
54 --- a/main.c
55 +++ b/main.c
56 @@ -38,6 +38,7 @@
57  #endif
58  
59  #include "utils.h"
60 +#include "flags.h"
61  
62  #ifndef DEFAULT_DIRECTORY
63  #define DEFAULT_DIRECTORY "/usr/lib"
64 @@ -130,8 +131,9 @@ main(int argc, char *argv[])
65         opts.timeout = DEFAULT_TIMEOUT;
66         opts.ptests = NULL;
67         opts.xml_filename = NULL;
68 +       opts.flags = 0;
69  
70 -       while ((opt = getopt(argc, argv, "d:e:lt:x:h")) != -1) {
71 +       while ((opt = getopt(argc, argv, "d:e:lt:x:Lh")) != -1) {
72                 switch (opt) {
73                         case 'd':
74                                 free(opts.dirs[0]);
75 @@ -156,6 +158,11 @@ main(int argc, char *argv[])
76                                 opts.xml_filename = strdup(optarg);
77                                 CHECK_ALLOCATION(opts.xml_filename, 1, 1);
78                         break;
79 +                       case 'L':
80 +                               // set LAVA signal mode
81 +                               opts.flags |= LAVA_SIGNAL_ENABLE;
82 +                               fprintf(stdout, "LAVA_SIGNAL_ENABLE == %d\n", opts.flags);
83 +                       break;
84                         default:
85                                 print_usage(stdout, argv[0]);
86                                 exit(1);
87 diff --git a/utils.c b/utils.c
88 index 6cf7705..f6a3a2a 100644
89 --- a/utils.c
90 +++ b/utils.c
91 @@ -49,6 +49,7 @@
92  
93  #include "ptest_list.h"
94  #include "utils.h"
95 +#include "flags.h"
96  
97  #define GET_STIME_BUF_SIZE 1024
98  #define WAIT_CHILD_BUF_MAX_SIZE 1024
99 @@ -369,6 +370,9 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
100                         strcpy(ptest_dir, p->run_ptest);
101                         dirname(ptest_dir);
102  
103 +                       char *ptest = strdup(p->ptest);
104 +                       CHECK_ALLOCATION(ptest, 1, 1);
105 +
106                         if (pipe2(pipefd_stdout, 0) == -1) {
107                                 fprintf(fp, "ERROR: pipe2() failed with: %s.\n", strerror(errno));
108                                 rc = -1;
109 @@ -425,7 +429,10 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
110                                 do_close(&pipefd_stdout[PIPE_WRITE]);
111                                 do_close(&pipefd_stderr[PIPE_WRITE]);
112  
113 -                               time_t start_time= time(NULL);
114 +                               if (opts.flags & LAVA_SIGNAL_ENABLE) {
115 +                                       fprintf(stdout, "<LAVA_SIGNAL_STARTTC %s>\n", ptest);
116 +                               }
117 +                               time_t start_time = time(NULL);
118                                 fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE, start_time));
119                                 fprintf(fp, "BEGIN: %s\n", ptest_dir);
120  
121 @@ -542,6 +549,16 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
122  
123                                 fprintf(fp, "END: %s\n", ptest_dir);
124                                 fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE, end_time));
125 +                               if (opts.flags & LAVA_SIGNAL_ENABLE) {
126 +                                       char result[5]; // pass\0, fail\0, skip\0
127 +
128 +                                       if (status)
129 +                                               sprintf(result, "fail");
130 +                                       else
131 +                                               sprintf(result, "pass");
132 +                                       fprintf(stdout, "<LAVA_SIGNAL_ENDTC %s>\n", ptest);
133 +                                       fprintf(stdout, "<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=%s RESULT=%s>\n", ptest, result);
134 +                               }
135                         }
136  
137  ptest_list_fail4:
138 @@ -556,6 +573,7 @@ ptest_list_fail2:
139                         do_close(&pipefd_stdout[PIPE_WRITE]);
140  
141  ptest_list_fail1:
142 +                       free(ptest);
143                         fflush(fp);
144                         fflush(fp_stderr);
145  
146 diff --git a/utils.h b/utils.h
147 index 04fc666..ad702d8 100644
148 --- a/utils.h
149 +++ b/utils.h
150 @@ -42,9 +42,9 @@ struct ptest_options {
151         unsigned int timeout;
152         char **ptests;
153         char *xml_filename;
154 +       unsigned int flags;
155  };
156  
157 -
158  extern void check_allocation1(void *, size_t, char *, int, int);
159  extern struct ptest_list *get_available_ptests(const char *);
160  extern int print_ptests(struct ptest_list *, FILE *);
161 -- 
162 2.44.0
163