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