blob: 2a700b470416962e2f5df903bee67474746428cf [file] [log] [blame]
jk-arm957cfea2021-06-18 15:52:12 +05301/** @file
2 * Copyright (c) 2021 Arm Limited or its affiliates. All rights reserved.
3 * SPDX-License-Identifier : Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16**/
17
18#include "val_framework.h"
19#include "val_interfaces.h"
20#include "val_dispatcher.h"
21#include "val_peripherals.h"
22#include "pal_interfaces.h"
23
24
25extern val_api_t val_api;
26
27
28/* globals */
29test_status_buffer_t g_status_buffer;
30
31/**
32 @brief - Parses input status for a given test and
33 outputs appropriate information on the console
34 @return - Test state
35**/
36uint32_t val_report_status(void)
37{
38 uint32_t status, state;
39
40 status = val_get_status();
41
42 state = (status >> TEST_STATE_BIT) & TEST_STATE_MASK;
43 status = status & TEST_STATUS_MASK;
44
45 switch (state)
46 {
47 case TEST_START:
48 state = TEST_FAIL;
49 val_print(PRINT_ALWAYS, "\nTEST RESULT: FAILED (Error Code=0x%x)\n",
50 VAL_STATUS_INIT_FAILED);
51 break;
52
53 case TEST_END:
54 state = TEST_PASS;
55 val_print(PRINT_ALWAYS, "\nTEST RESULT: PASSED\n", 0);
56 break;
57
58 case TEST_FAIL:
59 val_print(PRINT_ALWAYS, "\nTEST RESULT: FAILED (Error Code=0x%x)\n", status);
60 break;
61
62 case TEST_SKIP:
63 state = TEST_SKIP;
64 val_print(PRINT_ALWAYS, "\nTEST RESULT: SKIPPED (Skip Code=0x%x)\n", status);
65 break;
66
67 case TEST_PENDING:
68 val_print(PRINT_ALWAYS, "\nTEST RESULT: SIM ERROR (Error Code=0x%x)\n", status);
69 break;
70
71 default:
72 state = TEST_FAIL;
73 val_print(PRINT_ALWAYS, "\nTEST RESULT: FAILED(Error Code=0x%x)\n", VAL_STATUS_INVALID);
74 break;
75
76 }
77
78 val_print(PRINT_ALWAYS, "\n******************************************\n", 0);
79 return state;
80}
81
82/**
83 @brief - Records the state and status of test
84 @return - val_status_t
85**/
86val_status_t val_set_status(uint32_t status)
87{
88 g_status_buffer.state = ((status >> TEST_STATE_BIT) & TEST_STATE_MASK);
89 g_status_buffer.status = (status & TEST_STATUS_MASK);
90
91 return VAL_STATUS_SUCCESS;
92}
93
94/**
95 @brief - Updates the state and status for a given test
96 @return - test status
97**/
98uint32_t val_get_status(void)
99{
100 return ((g_status_buffer.state) << TEST_STATE_BIT) | (g_status_buffer.status);
101}
102
103/*
104 @brief - This function checks if the input status argument is an error.
105 On error, we print the checkpoint value and set the status.
106 @param - checkpoint : Test debug checkpoint
107 - val_status_t : Test status
108 @return - returns the input status back to the program.
109*/
110
111val_status_t val_err_check_set(uint32_t checkpoint, val_status_t status)
112{
113 if (VAL_ERROR(status)) {
114 val_print(PRINT_ERROR, "\tCheckpoint %d : ", checkpoint);
115 val_print(PRINT_ERROR, "Error Code=0x%x \n", status);
116 val_set_status(RESULT_FAIL(status));
117 } else {
118 status = (val_get_status() & TEST_STATUS_MASK);
119 if (VAL_ERROR(status)) {
120 val_print(PRINT_ERROR, "\tCheckpoint %d : ", checkpoint);
121 val_print(PRINT_ERROR, "Error Code=0x%x \n", status);
122 } else {
123 val_print(PRINT_DEBUG, "\tCheckpoint %d \n", checkpoint);
124 }
125 }
126 return status;
127}
128
129/**
130 @brief This API prints the test number, description and
131 sets the test state to TEST_START on successful execution.
132 @param test_num :unique number identifying this test
133 @param desc :brief description of the test
134 @param test_bitfield :Addition test info such as
135 - test isolation level requirement
136 - Watchdog timeout type
137 @return void
138**/
139
140void val_test_init(uint32_t test_num, char8_t *desc)
141{
142 val_status_t status = VAL_STATUS_SUCCESS;
143
144 /*global init*/
145 g_status_buffer.state = TEST_FAIL;
146 g_status_buffer.status = VAL_STATUS_INVALID;
147
148 val_print(PRINT_ALWAYS, "\nTEST: %d | DESCRIPTION: ", test_num);
149 val_print(PRINT_ALWAYS, desc, 0);
150
151 val_set_status(RESULT_START(status));
152 return;
153}
154
155/**
156 @brief This API sets the test state to TEST_END if test is successfully passed.
157 @param none
158 @return none
159**/
160
161void val_test_exit(void)
162{
163 val_status_t status = VAL_STATUS_SUCCESS;
164
165 status = val_get_status();
166
167 /* return if test skipped or failed */
168 if (IS_TEST_FAIL(status) || IS_TEST_SKIP(status))
169 return;
170 else
171 val_set_status(RESULT_END(VAL_STATUS_SUCCESS));
172}