blob: bcffe5c9ed4a31685277be065fd2045bda345ef4 [file] [log] [blame]
Andrew Scull18834872018-10-12 11:48:09 +01001/*
Andrew Walbran692b3252019-03-07 15:51:31 +00002 * Copyright 2018 The Hafnium Authors.
Andrew Scull18834872018-10-12 11:48:09 +01003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Andrew Scullbc7189d2018-08-14 09:35:13 +010017#pragma once
18
19#include <stdbool.h>
20#include <stddef.h>
21#include <stdint.h>
22
23#include "hf/dlog.h"
24
25/*
26 * Define a set up function to be run before every test in a test suite.
27 */
28#define SET_UP(suite) HFTEST_SET_UP(suite)
29
30/*
31 * Define a tear down function to be run after every test in a test suite.
32 */
33#define TEAR_DOWN(suite) HFTEST_TEAR_DOWN(suite)
34
35/*
36 * Define a test as part of a test suite.
37 */
38#define TEST(suite, test) HFTEST_TEST(suite, test)
39
Andrew Scullf0551c82018-12-15 20:38:47 +000040/*
41 * Define a test service.
42 */
43#define TEST_SERVICE(service) HFTEST_TEST_SERVICE(service)
44
Andrew Scullbc7189d2018-08-14 09:35:13 +010045/* Assertions. */
Andrew Scullf0551c82018-12-15 20:38:47 +000046#define ASSERT_EQ(x, y) HFTEST_ASSERT_OP(x, y, ==, true)
47#define ASSERT_NE(x, y) HFTEST_ASSERT_OP(x, y, !=, true)
48#define ASSERT_LE(x, y) HFTEST_ASSERT_OP(x, y, <=, true)
49#define ASSERT_LT(x, y) HFTEST_ASSERT_OP(x, y, <, true)
50#define ASSERT_GE(x, y) HFTEST_ASSERT_OP(x, y, >=, true)
51#define ASSERT_GT(x, y) HFTEST_ASSERT_OP(x, y, >, true)
Andrew Scullbc7189d2018-08-14 09:35:13 +010052
Andrew Walbranb90daf12018-12-11 14:25:54 +000053#define ASSERT_TRUE(x) ASSERT_EQ(x, true)
54#define ASSERT_FALSE(x) ASSERT_EQ(x, false)
Andrew Scull7fd4bb72018-12-08 23:40:12 +000055
Andrew Scullf0551c82018-12-15 20:38:47 +000056#define EXPECT_EQ(x, y) HFTEST_ASSERT_OP(x, y, ==, false)
57#define EXPECT_NE(x, y) HFTEST_ASSERT_OP(x, y, !=, false)
58#define EXPECT_LE(x, y) HFTEST_ASSERT_OP(x, y, <=, false)
59#define EXPECT_LT(x, y) HFTEST_ASSERT_OP(x, y, <, false)
60#define EXPECT_GE(x, y) HFTEST_ASSERT_OP(x, y, >=, false)
61#define EXPECT_GT(x, y) HFTEST_ASSERT_OP(x, y, >, false)
Andrew Scullbc7189d2018-08-14 09:35:13 +010062
Andrew Walbranb90daf12018-12-11 14:25:54 +000063#define EXPECT_TRUE(x) EXPECT_EQ(x, true)
64#define EXPECT_FALSE(x) EXPECT_EQ(x, false)
65
Andrew Walbran78a63b72019-03-18 17:28:22 +000066#define FAIL(...) HFTEST_FAIL(true, __VA_ARGS__)
Andrew Scull7fd4bb72018-12-08 23:40:12 +000067
Andrew Scullf0551c82018-12-15 20:38:47 +000068/* Service utilities. */
Andrew Scull4a867bc2019-04-08 10:15:11 +010069#define SERVICE_NAME_MAX_LENGTH 64
Andrew Scullf0551c82018-12-15 20:38:47 +000070#define SERVICE_SELECT(vm_id, service, send_buffer) \
71 HFTEST_SERVICE_SELECT(vm_id, service, send_buffer)
72
73#define SERVICE_SEND_BUFFER() HFTEST_SERVICE_SEND_BUFFER()
74#define SERVICE_RECV_BUFFER() HFTEST_SERVICE_RECV_BUFFER()
Andrew Walbran2b87c702019-04-16 18:16:05 +010075#define SERVICE_MEMORY_SIZE() HFTEST_SERVICE_MEMORY_SIZE()
Andrew Scullf0551c82018-12-15 20:38:47 +000076
Andrew Scullbc7189d2018-08-14 09:35:13 +010077/*
78 * This must be used exactly once in a test image to signal to the linker that
79 * the .hftest section is allowed to be included in the generated image.
80 */
81#define HFTEST_ENABLE() int hftest_enable
82
83/*
84 * Prefixed to log lines from tests for easy filtering in the console.
85 */
86#define HFTEST_LOG_PREFIX "[hftest] "
87
Andrew Scullbc7189d2018-08-14 09:35:13 +010088/*
Andrew Scullf0551c82018-12-15 20:38:47 +000089 * Indentation used e.g. to give the reason for an assertion failure.
Andrew Scullbc7189d2018-08-14 09:35:13 +010090 */
Andrew Scullf0551c82018-12-15 20:38:47 +000091#define HFTEST_LOG_INDENT " "
Andrew Scullbc7189d2018-08-14 09:35:13 +010092
Andrew Walbranafabe852019-03-20 17:55:11 +000093uintptr_t hftest_get_cpu_id(size_t index);
94
Andrew Scullf0551c82018-12-15 20:38:47 +000095/* Above this point is the public API. Now include the implementation. */
96#include <hftest_impl.h>