Refresh ptest-runner patch for latest dunfell
[AGL/meta-agl.git] / meta-agl-core / recipes-support / ptest-runner / ptest-runner / 0007-WIP-Initial-LAVA-support.patch
1 From edb252e5dae20869081a22e1e18cde4336c7b31c 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 Signed-off-by: Tim Orling <timothy.t.orling@linux.intel.com>
21 [updated for ptest-runner 2.3.2]
22 Signed-off-by: Scott Murray <scott.murray@konsulko.com>
23
24 ---
25  flags.h | 10 ++++++++++
26  main.c  |  9 ++++++++-
27  utils.c | 14 ++++++++++++++
28  utils.h |  2 +-
29  4 files changed, 33 insertions(+), 2 deletions(-)
30  create mode 100644 flags.h
31
32 diff --git a/flags.h b/flags.h
33 new file mode 100644
34 index 0000000..0dac223
35 --- /dev/null
36 +++ b/flags.h
37 @@ -0,0 +1,10 @@
38 +/* SPDX-License-Identifier: GPL-2.0 */
39 +
40 +/* Flag bit definitions */
41 +
42 +#ifndef __FLAGS_H__
43 +#define __FLAGS_H__
44 +
45 +#define LAVA_SIGNAL_ENABLE     (0x0001)
46 +
47 +#endif                         /* __FLAGS_H__ */
48 diff --git a/main.c b/main.c
49 index e3a1b69..4807183 100644
50 --- a/main.c
51 +++ b/main.c
52 @@ -38,6 +38,7 @@
53  #endif
54  
55  #include "utils.h"
56 +#include "flags.h"
57  
58  #ifndef DEFAULT_DIRECTORY
59  #define DEFAULT_DIRECTORY "/usr/lib"
60 @@ -110,8 +111,9 @@ main(int argc, char *argv[])
61         opts.timeout = DEFAULT_TIMEOUT;
62         opts.ptests = NULL;
63         opts.xml_filename = NULL;
64 +       opts.flags = 0;
65  
66 -       while ((opt = getopt(argc, argv, "d:e:lt:x:h")) != -1) {
67 +       while ((opt = getopt(argc, argv, "d:e:lt:x:Lh")) != -1) {
68                 switch (opt) {
69                         case 'd':
70                                 free(opts.dirs[0]);
71 @@ -136,6 +138,11 @@ main(int argc, char *argv[])
72                                 opts.xml_filename = strdup(optarg);
73                                 CHECK_ALLOCATION(opts.xml_filename, 1, 1);
74                         break;
75 +                       case 'L':
76 +                               // set LAVA signal mode
77 +                               opts.flags |= LAVA_SIGNAL_ENABLE;
78 +                               fprintf(stdout, "LAVA_SIGNAL_ENABLE == %d\n", opts.flags);
79 +                       break;
80                         default:
81                                 print_usage(stdout, argv[0]);
82                                 exit(1);
83 diff --git a/utils.c b/utils.c
84 index a4e190e..29f40f3 100644
85 --- a/utils.c
86 +++ b/utils.c
87 @@ -47,6 +47,7 @@
88  
89  #include "ptest_list.h"
90  #include "utils.h"
91 +#include "flags.h"
92  
93  #define GET_STIME_BUF_SIZE 1024
94  #define WAIT_CHILD_POLL_TIMEOUT_MS 200
95 @@ -442,6 +443,7 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
96                 }
97                 PTEST_LIST_ITERATE_START(head, p)
98                         char *ptest_dir = strdup(p->run_ptest);
99 +                       char *ptest = strdup(p->ptest);
100                         if (ptest_dir == NULL) {
101                                 rc = -1;
102                                 break;
103 @@ -480,11 +482,15 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
104                                 int status;
105                                 int fds[2]; fds[0] = pipefd_stdout[0]; fds[1] = pipefd_stderr[0];
106                                 FILE *fps[2]; fps[0] = fp; fps[1] = fp_stderr;
107 +                               char result[5]; // pass\0, fail\0, skip\0
108  
109                                 if (setpgid(child, pgid) == -1) {
110                                         fprintf(fp, "ERROR: setpgid() failed, %s\n", strerror(errno));
111                                 }
112  
113 +                               if (opts.flags & LAVA_SIGNAL_ENABLE) {
114 +                                       fprintf(stdout, "<LAVA_SIGNAL_STARTTC %s>\n", ptest);
115 +                               }
116                                 sttime = time(NULL);
117                                 fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE, sttime));
118                                 fprintf(fp, "BEGIN: %s\n", ptest_dir);
119 @@ -506,6 +512,14 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
120  
121                                 fprintf(fp, "END: %s\n", ptest_dir);
122                                 fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE, entime));
123 +                               if (opts.flags & LAVA_SIGNAL_ENABLE) {
124 +                                       if (status)
125 +                                               sprintf(result, "fail");
126 +                                       else
127 +                                               sprintf(result, "pass");
128 +                                       fprintf(stdout, "<LAVA_SIGNAL_ENDTC %s>\n", ptest);
129 +                                       fprintf(stdout, "<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=%s RESULT=%s>\n", ptest, result);
130 +                               }
131                         }
132                 PTEST_LIST_ITERATE_END
133                 fprintf(fp, "STOP: %s\n", progname);
134 diff --git a/utils.h b/utils.h
135 index 39832e6..8137bd6 100644
136 --- a/utils.h
137 +++ b/utils.h
138 @@ -41,9 +41,9 @@ struct ptest_options {
139         int timeout;
140         char **ptests;
141         char *xml_filename;
142 +       unsigned int flags;
143  };
144  
145 -
146  extern void check_allocation1(void *, size_t, char *, int, int);
147  extern struct ptest_list *get_available_ptests(const char *);
148  extern int print_ptests(struct ptest_list *, FILE *);