blob: b819779b52add1802d6966fb50c79e0f5214632c [file] [log] [blame]
julhal013ec4c322021-02-05 17:30:49 +00001/*
2 * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include "remote_test_runner.h"
8#include <protocols/service/test_runner/packed-c/status.h>
9#include <vector>
10#include <string>
11#include <cstring>
12#include <cstdio>
13
14remote_test_runner::remote_test_runner() :
15 m_client(NULL)
16{
17
18}
19
20remote_test_runner::remote_test_runner(test_runner_client *client) :
21 m_client(client)
22{
23
24}
25
26remote_test_runner::~remote_test_runner()
27{
28
29}
30
31void remote_test_runner::set_client(test_runner_client *client)
32{
33 m_client = client;
34}
35
36int remote_test_runner::execute(int argc, char *argv[])
37{
38 int test_status = TS_TEST_RUNNER_STATUS_ERROR;
39 struct test_spec spec;
40
41 /* Parse command line parameters */
42 bool list_only = option_selected("-l", argc, argv);
43 parse_test_spec_params(argc, argv, spec);
44
45 /* Run or list tests qualified bu spec */
46 struct test_summary summary;
47 std::vector<struct test_result> results;
48
49 if (list_only) {
50
51 test_status = m_client->list_tests(spec, summary, results);
52 output_list(summary, results);
53 }
54 else {
55
56 test_status = m_client->run_tests(spec, summary, results);
57 output_results(summary, results);
58 }
59
60 if (test_status != TS_TEST_RUNNER_STATUS_SUCCESS) {
61
62 printf("Tests failed to run with error: %d\n", test_status);
63 }
64
65 return test_status;
66}
67
68void remote_test_runner::parse_test_spec_params(int argc, char *argv[], struct test_spec &spec) const
69{
70 std::string name = parse_option("-n", argc, argv);
71 std::string group = parse_option("-g", argc, argv);
72
73 memset(spec.name, 0, TEST_NAME_MAX_LEN);
74 name.copy(spec.name, TEST_NAME_MAX_LEN - 1);
75
76 memset(spec.group, 0, TEST_GROUP_MAX_LEN);
77 group.copy(spec.group, TEST_GROUP_MAX_LEN - 1);
78}
79
80std::string remote_test_runner::parse_option(const char *option_switch, int argc, char *argv[]) const
81{
82 std::string option;
83
84 for (int i = 1; i + 1 < argc; ++i) {
85
86 if (strcmp(argv[i], option_switch) == 0) {
87
88 option = std::string(argv[i +1]);
89 break;
90 }
91 }
92
93 return option;
94}
95
96bool remote_test_runner::option_selected(const char *option_switch, int argc, char *argv[]) const
97{
98 bool selected = false;
99
100 for (int i = 1; (i < argc) && !selected; ++i) {
101
102 selected = (strcmp(argv[i], option_switch) == 0);
103 }
104
105 return selected;
106}
107
108void remote_test_runner::output_summary(const struct test_summary &summary)
109{
110 printf("\n");
111
112 if (summary.num_failed == 0) printf("OK (");
113 else printf("Errors (%d failures, ", summary.num_failed);
114
115 printf("%d tests, %d ran)\n", summary.num_tests, summary.num_failed + summary.num_passed);
116}
117
118
119void remote_test_runner::output_list(const struct test_summary &summary,
120 const std::vector<struct test_result> &results)
121{
122
123}
124
125void remote_test_runner::output_results(const struct test_summary &summary,
126 const std::vector<struct test_result> &results)
127{
128 for (int i = 0; i < results.size(); ++i) {
129
130 printf("TEST(%s, %s) ", results[i].group, results[i].name);
131
132 if (results[i].run_state == TEST_RUN_STATE_PASSED) {
133
134 printf("OK\n");
135 }
136 else if (results[i].run_state == TEST_RUN_STATE_FAILED) {
137
138 printf("error\n");
julhal0137e1aea2021-02-09 15:22:20 +0000139 printf("\tline number: %d\n", results[i].failure.line_num);
140 printf("\tinfo: 0x%016lx\n", results[i].failure.info);
julhal013ec4c322021-02-05 17:30:49 +0000141 }
142 else {
143
144 printf("did not run\n");
145 }
146 }
147
148 output_summary(summary);
149}