aboutsummaryrefslogtreecommitdiff
path: root/components/service/test_runner/test/service/test_runner_service_tests.cpp
blob: c4ba0e07f4cf579edef61eaf3877dbe46a9a4d95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <service/test_runner/client/cpp/test_runner_client.h>
#include <protocols/rpc/common/packed-c/encoding.h>
#include <protocols/service/test_runner/packed-c/status.h>
#include <service_locator.h>
#include <CppUTest/TestHarness.h>
#include <vector>
#include <cstring>

/*
 * Service-level tests for the test_runner service.  These tests assume
 * that the mock_test_runner backend is used as the only registered
 * backend.  It includes some referenece test cases that are assumed
 * by these tests.
 */
TEST_GROUP(TestRunnerServiceTests)
{
    void setup()
    {
        struct rpc_caller *caller;
        int status;

        m_rpc_session_handle = NULL;
        m_test_runner_service_context = NULL;
        m_test_runner_client = NULL;

        service_locator_init();

        m_test_runner_service_context = service_locator_query("sn:trustedfirmware.org:test-runner:0", &status);
        CHECK(m_test_runner_service_context);

        m_rpc_session_handle = service_context_open(m_test_runner_service_context, TS_RPC_ENCODING_PACKED_C, &caller);
        CHECK(m_rpc_session_handle);

        m_test_runner_client = new test_runner_client(caller);
    }

    void teardown()
    {
        delete m_test_runner_client;
        m_test_runner_client = NULL;

        service_context_close(m_test_runner_service_context, m_rpc_session_handle);
        m_rpc_session_handle = NULL;

        service_context_relinquish(m_test_runner_service_context);
        m_test_runner_service_context = NULL;
    }

    rpc_session_handle m_rpc_session_handle;
    struct service_context *m_test_runner_service_context;
    test_runner_client *m_test_runner_client;
};

TEST(TestRunnerServiceTests, listAllTests)
{
    int test_status;
    struct test_spec spec;
    struct test_summary summary;
    std::vector<struct test_result> results;

    /* Create spec that qualifies all tests */
    spec.name[0] = 0;
    spec.group[0] = 0;

    test_status = m_test_runner_client->list_tests(spec, summary, results);

    CHECK_EQUAL(TS_TEST_RUNNER_STATUS_SUCCESS, test_status);

    /* Check test summary */
    CHECK_EQUAL(4, summary.num_tests);
    CHECK_EQUAL(4, summary.num_results);
    CHECK_EQUAL(0, summary.num_passed);
    CHECK_EQUAL(0, summary.num_failed);

    /* Check each test result is listed but not run */
    CHECK(strcmp(results[0].group, "PlatformTests") == 0);
    CHECK(strcmp(results[0].name, "Trng") == 0);
    CHECK_EQUAL(TEST_RUN_STATE_NOT_RUN, results[0].run_state);

    CHECK(strcmp(results[1].group, "PlatformTests") == 0);
    CHECK(strcmp(results[1].name, "CheckIOmap") == 0);
    CHECK_EQUAL(TEST_RUN_STATE_NOT_RUN, results[1].run_state);

    CHECK(strcmp(results[2].group, "ConfigTests") == 0);
    CHECK(strcmp(results[2].name, "ValidateConfig") == 0);
    CHECK_EQUAL(TEST_RUN_STATE_NOT_RUN, results[2].run_state);

    CHECK(strcmp(results[3].group, "ConfigTests") == 0);
    CHECK(strcmp(results[3].name, "ApplyConfig") == 0);
    CHECK_EQUAL(TEST_RUN_STATE_NOT_RUN, results[3].run_state);
}

TEST(TestRunnerServiceTests, runAllTests)
{
    int test_status;
    struct test_spec spec;
    struct test_summary summary;
    std::vector<struct test_result> results;

    /* Create spec that qualifies all tests */
    spec.name[0] = 0;
    spec.group[0] = 0;

    test_status = m_test_runner_client->run_tests(spec, summary, results);

    CHECK_EQUAL(TS_TEST_RUNNER_STATUS_SUCCESS, test_status);

    CHECK_EQUAL(4, summary.num_tests);
    CHECK_EQUAL(4, summary.num_results);
    CHECK_EQUAL(3, summary.num_passed);
    CHECK_EQUAL(1, summary.num_failed);

    /* Check each test result has run with the expected outcome */
    CHECK(strcmp(results[0].group, "PlatformTests") == 0);
    CHECK(strcmp(results[0].name, "Trng") == 0);
    CHECK_EQUAL(TEST_RUN_STATE_PASSED, results[0].run_state);

    CHECK(strcmp(results[1].group, "PlatformTests") == 0);
    CHECK(strcmp(results[1].name, "CheckIOmap") == 0);
    CHECK_EQUAL(TEST_RUN_STATE_PASSED, results[1].run_state);

    CHECK(strcmp(results[2].group, "ConfigTests") == 0);
    CHECK(strcmp(results[2].name, "ValidateConfig") == 0);
    CHECK_EQUAL(TEST_RUN_STATE_FAILED, results[2].run_state);

    CHECK(strcmp(results[3].group, "ConfigTests") == 0);
    CHECK(strcmp(results[3].name, "ApplyConfig") == 0);
    CHECK_EQUAL(TEST_RUN_STATE_PASSED, results[3].run_state);
}

TEST(TestRunnerServiceTests, listPlatformTests)
{
    int test_status;
    struct test_spec spec;
    struct test_summary summary;
    std::vector<struct test_result> results;

    /* Create spec that qualifies all tests in a group*/
    spec.name[0] = 0;
    strcpy(spec.group, "PlatformTests");

    test_status = m_test_runner_client->list_tests(spec, summary, results);

    CHECK_EQUAL(TS_TEST_RUNNER_STATUS_SUCCESS, test_status);

    /* Check test summary */
    CHECK_EQUAL(2, summary.num_tests);
    CHECK_EQUAL(2, summary.num_results);
    CHECK_EQUAL(0, summary.num_passed);
    CHECK_EQUAL(0, summary.num_failed);
}

TEST(TestRunnerServiceTests, runConfigTests)
{
    int test_status;
    struct test_spec spec;
    struct test_summary summary;
    std::vector<struct test_result> results;

    /* Create spec that qualifies all tests in a group*/
    spec.name[0] = 0;
    strcpy(spec.group, "ConfigTests");

    test_status = m_test_runner_client->run_tests(spec, summary, results);

    CHECK_EQUAL(TS_TEST_RUNNER_STATUS_SUCCESS, test_status);

    /* Check test summary */
    CHECK_EQUAL(2, summary.num_tests);
    CHECK_EQUAL(2, summary.num_results);
    CHECK_EQUAL(1, summary.num_passed);
    CHECK_EQUAL(1, summary.num_failed);
}

TEST(TestRunnerServiceTests, runSpecificTest)
{
    int test_status;
    struct test_spec spec;
    struct test_summary summary;
    std::vector<struct test_result> results;

    /* Create spec that qualifies a specific test */
    strcpy(spec.name, "ValidateConfig");
    strcpy(spec.group, "ConfigTests");

    test_status = m_test_runner_client->run_tests(spec, summary, results);

    CHECK_EQUAL(TS_TEST_RUNNER_STATUS_SUCCESS, test_status);

    /* Check test summary */
    CHECK_EQUAL(1, summary.num_tests);
    CHECK_EQUAL(1, summary.num_results);
    CHECK_EQUAL(0, summary.num_passed);
    CHECK_EQUAL(1, summary.num_failed);
}