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