14c90b714ac7a183418ae650e9c3793d092cfa0b
[AGL/meta-agl.git] / meta-agl-core / recipes-support / ptest-runner / ptest-runner / 0007-WIP-Initial-LAVA-support.patch
1 From 552f06e025493f7e634ea9e27489861b88f45555 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 Signed-off-by: Scott Murray <scott.murray@konsulko.com>
27
28 ---
29  flags.h | 10 ++++++++++
30  main.c  |  9 ++++++++-
31  utils.c | 15 +++++++++++++++
32  utils.h |  2 +-
33  4 files changed, 34 insertions(+), 2 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 a67ac11..0c081ce 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 @@ -483,6 +484,7 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
100                 fprintf(fp, "START: %s\n", progname);
101                 PTEST_LIST_ITERATE_START(head, p)
102                         char *ptest_dir = strdup(p->run_ptest);
103 +                       char *ptest = strdup(p->ptest);
104                         if (ptest_dir == NULL) {
105                                 rc = -1;
106                                 break;
107 @@ -525,6 +527,9 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
108                                         fprintf(fp, "ERROR: setpgid() failed, %s\n", strerror(errno));
109                                 }
110  
111 +                               if (opts.flags & LAVA_SIGNAL_ENABLE) {
112 +                                       fprintf(stdout, "<LAVA_SIGNAL_STARTTC %s>\n", ptest);
113 +                               }
114                                 sttime = time(NULL);
115                                 fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE, sttime));
116                                 fprintf(fp, "BEGIN: %s\n", ptest_dir);
117 @@ -548,6 +553,16 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
118  
119                                 fprintf(fp, "END: %s\n", ptest_dir);
120                                 fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE, entime));
121 +                               if (opts.flags & LAVA_SIGNAL_ENABLE) {
122 +                                       char result[5]; // pass\0, fail\0, skip\0
123 +
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                         free(ptest_dir);
133                 PTEST_LIST_ITERATE_END
134 diff --git a/utils.h b/utils.h
135 index 04fc666..ad702d8 100644
136 --- a/utils.h
137 +++ b/utils.h
138 @@ -42,9 +42,9 @@ struct ptest_options {
139         unsigned 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 *);