Software APIs
status.c
1// Copyright lowRISC contributors (OpenTitan project).
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4
5#include "sw/device/lib/testing/test_framework/status.h"
6
7#include <stdatomic.h>
8
13
14/**
15 * Writes the test status to the test status device address.
16 *
17 * @param test_status current status of the test.
18 */
19static void test_status_device_write(test_status_t test_status) {
20 uintptr_t status_addr = device_test_status_address();
21 if (status_addr != 0) {
22 mmio_region_t test_status_device_addr = mmio_region_from_addr(status_addr);
23 mmio_region_write32(test_status_device_addr, 0x0, (uint32_t)test_status);
24 }
25}
26
27void test_status_set(test_status_t test_status) {
28 // This function is used to convey info to test harness, which may poke at
29 // backdoor variables. Add a fence to provide corrrect synchronization.
30 //
31 // This technically should be a thread fence, but use a signal fence to avoid
32 // emitting instructions as Ibex doesn't reorder memory accesses itself.
33 atomic_signal_fence(memory_order_release);
34
35 switch (test_status) {
36 case kTestStatusPassed: {
37 LOG_INFO("PASS!");
38 test_status_device_write(test_status);
39 abort();
40 break;
41 }
42 case kTestStatusFailed: {
43 LOG_INFO("FAIL!");
44 test_status_device_write(test_status);
45 abort();
46 break;
47 }
48 default: {
49 LOG_INFO("test_status_set to 0x%x", test_status);
50 test_status_device_write(test_status);
51 break;
52 }
53 }
54}