blob: bf7af91d04485a53c414a58b6c6501e6f1f0ef38 [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"
jk-arm957cfea2021-06-18 15:52:12 +053022
23extern val_api_t val_api;
24
jk-arm957cfea2021-06-18 15:52:12 +053025/* globals */
26test_status_buffer_t g_status_buffer;
27
28/**
29 @brief - Parses input status for a given test and
30 outputs appropriate information on the console
31 @return - Test state
32**/
33uint32_t val_report_status(void)
34{
35 uint32_t status, state;
36
37 status = val_get_status();
38
39 state = (status >> TEST_STATE_BIT) & TEST_STATE_MASK;
40 status = status & TEST_STATUS_MASK;
41
42 switch (state)
43 {
44 case TEST_START:
45 state = TEST_FAIL;
46 val_print(PRINT_ALWAYS, "\nTEST RESULT: FAILED (Error Code=0x%x)\n",
47 VAL_STATUS_INIT_FAILED);
48 break;
49
50 case TEST_END:
51 state = TEST_PASS;
52 val_print(PRINT_ALWAYS, "\nTEST RESULT: PASSED\n", 0);
53 break;
54
55 case TEST_FAIL:
56 val_print(PRINT_ALWAYS, "\nTEST RESULT: FAILED (Error Code=0x%x)\n", status);
57 break;
58
59 case TEST_SKIP:
60 state = TEST_SKIP;
61 val_print(PRINT_ALWAYS, "\nTEST RESULT: SKIPPED (Skip Code=0x%x)\n", status);
62 break;
63
64 case TEST_PENDING:
65 val_print(PRINT_ALWAYS, "\nTEST RESULT: SIM ERROR (Error Code=0x%x)\n", status);
66 break;
67
68 default:
69 state = TEST_FAIL;
70 val_print(PRINT_ALWAYS, "\nTEST RESULT: FAILED(Error Code=0x%x)\n", VAL_STATUS_INVALID);
71 break;
jk-arm957cfea2021-06-18 15:52:12 +053072 }
73
74 val_print(PRINT_ALWAYS, "\n******************************************\n", 0);
75 return state;
76}
77
78/**
79 @brief - Records the state and status of test
80 @return - val_status_t
81**/
82val_status_t val_set_status(uint32_t status)
83{
84 g_status_buffer.state = ((status >> TEST_STATE_BIT) & TEST_STATE_MASK);
85 g_status_buffer.status = (status & TEST_STATUS_MASK);
86
87 return VAL_STATUS_SUCCESS;
88}
89
90/**
91 @brief - Updates the state and status for a given test
92 @return - test status
93**/
94uint32_t val_get_status(void)
95{
96 return ((g_status_buffer.state) << TEST_STATE_BIT) | (g_status_buffer.status);
97}
98
99/*
100 @brief - This function checks if the input status argument is an error.
101 On error, we print the checkpoint value and set the status.
102 @param - checkpoint : Test debug checkpoint
103 - val_status_t : Test status
104 @return - returns the input status back to the program.
105*/
106
107val_status_t val_err_check_set(uint32_t checkpoint, val_status_t status)
108{
109 if (VAL_ERROR(status)) {
110 val_print(PRINT_ERROR, "\tCheckpoint %d : ", checkpoint);
111 val_print(PRINT_ERROR, "Error Code=0x%x \n", status);
112 val_set_status(RESULT_FAIL(status));
113 } else {
114 status = (val_get_status() & TEST_STATUS_MASK);
115 if (VAL_ERROR(status)) {
116 val_print(PRINT_ERROR, "\tCheckpoint %d : ", checkpoint);
117 val_print(PRINT_ERROR, "Error Code=0x%x \n", status);
jk-arm01ee3ff2021-10-18 22:41:47 +0530118 } else
jk-arm957cfea2021-06-18 15:52:12 +0530119 val_print(PRINT_DEBUG, "\tCheckpoint %d \n", checkpoint);
jk-arm957cfea2021-06-18 15:52:12 +0530120 }
121 return status;
122}
123
124/**
125 @brief This API prints the test number, description and
126 sets the test state to TEST_START on successful execution.
127 @param test_num :unique number identifying this test
128 @param desc :brief description of the test
129 @param test_bitfield :Addition test info such as
130 - test isolation level requirement
131 - Watchdog timeout type
132 @return void
133**/
134
135void val_test_init(uint32_t test_num, char8_t *desc)
136{
137 val_status_t status = VAL_STATUS_SUCCESS;
138
139 /*global init*/
140 g_status_buffer.state = TEST_FAIL;
141 g_status_buffer.status = VAL_STATUS_INVALID;
142
143 val_print(PRINT_ALWAYS, "\nTEST: %d | DESCRIPTION: ", test_num);
144 val_print(PRINT_ALWAYS, desc, 0);
145
146 val_set_status(RESULT_START(status));
147 return;
148}
149
150/**
151 @brief This API sets the test state to TEST_END if test is successfully passed.
152 @param none
153 @return none
154**/
155
156void val_test_exit(void)
157{
158 val_status_t status = VAL_STATUS_SUCCESS;
159
160 status = val_get_status();
161
162 /* return if test skipped or failed */
163 if (IS_TEST_FAIL(status) || IS_TEST_SKIP(status))
164 return;
165 else
166 val_set_status(RESULT_END(VAL_STATUS_SUCCESS));
167}