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