meta-agl-distro: Add inc file for next branch over-rides
[AGL/meta-agl.git] / meta-agl-bsp / recipes-support / ptest-runner / ptest-runner / 0007-WIP-Initial-LAVA-support.patch
1 From 11b29ce444610a07067a89b38e9e85c2162bbf67 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 7/7] [WIP] 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 ---
22  flags.h | 10 ++++++++++
23  main.c  |  9 ++++++++-
24  utils.c | 15 +++++++++++++++
25  utils.h |  2 +-
26  4 files changed, 34 insertions(+), 2 deletions(-)
27  create mode 100644 flags.h
28
29 diff --git a/flags.h b/flags.h
30 new file mode 100644
31 index 000000000000..0dac2234e0b4
32 --- /dev/null
33 +++ b/flags.h
34 @@ -0,0 +1,10 @@
35 +/* SPDX-License-Identifier: GPL-2.0 */
36 +
37 +/* Flag bit definitions */
38 +
39 +#ifndef __FLAGS_H__
40 +#define __FLAGS_H__
41 +
42 +#define LAVA_SIGNAL_ENABLE     (0x0001)
43 +
44 +#endif                         /* __FLAGS_H__ */
45 diff --git a/main.c b/main.c
46 index 83600b7d1b31..92ced6926c3d 100644
47 --- a/main.c
48 +++ b/main.c
49 @@ -36,6 +36,7 @@
50  #endif
51  
52  #include "utils.h"
53 +#include "flags.h"
54  
55  #define DEFAULT_DIRECTORY "/usr/lib"
56  #define DEFAULT_TIMEOUT 300
57 @@ -70,8 +71,9 @@ main(int argc, char *argv[])
58         opts.timeout = DEFAULT_TIMEOUT;
59         opts.ptests = NULL;
60         opts.xml_filename = NULL;
61 +       opts.flags = 0;
62  
63 -       while ((opt = getopt(argc, argv, "d:e:lt:x:h")) != -1) {
64 +       while ((opt = getopt(argc, argv, "d:e:lt:x:Lh")) != -1) {
65                 switch (opt) {
66                         case 'd':
67                                 free(opts.directory);
68 @@ -118,6 +120,11 @@ main(int argc, char *argv[])
69                                 opts.xml_filename = strdup(optarg);
70                                 CHECK_ALLOCATION(opts.xml_filename, 1, 1);
71                         break;
72 +                       case 'L':
73 +                               // set LAVA signal mode
74 +                               opts.flags |= LAVA_SIGNAL_ENABLE;
75 +                               fprintf(stdout, "LAVA_SIGNAL_ENABLE == %d\n", opts.flags);
76 +                       break;
77                         default:
78                                 print_usage(stdout, argv[0]);
79                                 exit(1);
80 diff --git a/utils.c b/utils.c
81 index ed2eff7900c1..0fd1da6aec92 100644
82 --- a/utils.c
83 +++ b/utils.c
84 @@ -39,6 +39,7 @@
85  
86  #include "ptest_list.h"
87  #include "utils.h"
88 +#include "flags.h"
89  
90  #define GET_STIME_BUF_SIZE 1024
91  #define WAIT_CHILD_POLL_TIMEOUT_MS 200
92 @@ -358,6 +359,7 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
93                 fprintf(fp, "START: %s\n", progname);
94                 PTEST_LIST_ITERATE_START(head, p);
95                         char *ptest_dir = strdup(p->run_ptest);
96 +                       char *ptest = strdup(p->ptest);
97                         if (ptest_dir == NULL) {
98                                 rc = -1;
99                                 break;
100 @@ -376,6 +378,11 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
101                                 int fds[2]; fds[0] = pipefd_stdout[0]; fds[1] = pipefd_stderr[0];
102                                 FILE *fps[2]; fps[0] = fp; fps[1] = fp_stderr;
103  
104 +                               char result[5]; // pass\0, fail\0, skip\0
105 +
106 +                               if (opts.flags & LAVA_SIGNAL_ENABLE) {
107 +                                       fprintf(stdout, "<LAVA_SIGNAL_STARTTC %s>\n", ptest);
108 +                               }
109                                 fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE));
110                                 fprintf(fp, "BEGIN: %s\n", ptest_dir);
111  
112 @@ -389,6 +396,14 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
113  
114                                 fprintf(fp, "END: %s\n", ptest_dir);
115                                 fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE));
116 +                               if (opts.flags & LAVA_SIGNAL_ENABLE) {
117 +                                       if (status)
118 +                                               sprintf(result, "fail");
119 +                                       else
120 +                                               sprintf(result, "pass");
121 +                                       fprintf(stdout, "<LAVA_SIGNAL_ENDTC %s>\n", ptest);
122 +                                       fprintf(stdout, "<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=%s RESULT=%s>\n", ptest, result);
123 +                               }
124                         }
125                 PTEST_LIST_ITERATE_END;
126                 fprintf(fp, "STOP: %s\n", progname);
127 diff --git a/utils.h b/utils.h
128 index ee85163ddfff..06d4c100d151 100644
129 --- a/utils.h
130 +++ b/utils.h
131 @@ -37,9 +37,9 @@ struct ptest_options {
132         int timeout;
133         char **ptests;
134         char *xml_filename;
135 +       unsigned int flags;
136  };
137  
138 -
139  extern void check_allocation1(void *, size_t, char *, int, int);
140  extern struct ptest_list *get_available_ptests(const char *);
141  extern int print_ptests(struct ptest_list *, FILE *);
142 -- 
143 2.11.0
144