Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 1 | /* |
Andrew Walbran | 692b325 | 2019-03-07 15:51:31 +0000 | [diff] [blame] | 2 | * Copyright 2018 The Hafnium Authors. |
Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 3 | * |
| 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 Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 17 | #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 Scull | f0551c8 | 2018-12-15 20:38:47 +0000 | [diff] [blame] | 40 | /* |
| 41 | * Define a test service. |
| 42 | */ |
| 43 | #define TEST_SERVICE(service) HFTEST_TEST_SERVICE(service) |
| 44 | |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 45 | /* Assertions. */ |
Andrew Scull | f0551c8 | 2018-12-15 20:38:47 +0000 | [diff] [blame] | 46 | #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 Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 52 | |
Andrew Walbran | b90daf1 | 2018-12-11 14:25:54 +0000 | [diff] [blame] | 53 | #define ASSERT_TRUE(x) ASSERT_EQ(x, true) |
| 54 | #define ASSERT_FALSE(x) ASSERT_EQ(x, false) |
Andrew Scull | 7fd4bb7 | 2018-12-08 23:40:12 +0000 | [diff] [blame] | 55 | |
Andrew Scull | f0551c8 | 2018-12-15 20:38:47 +0000 | [diff] [blame] | 56 | #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 Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 62 | |
Andrew Walbran | b90daf1 | 2018-12-11 14:25:54 +0000 | [diff] [blame] | 63 | #define EXPECT_TRUE(x) EXPECT_EQ(x, true) |
| 64 | #define EXPECT_FALSE(x) EXPECT_EQ(x, false) |
| 65 | |
Andrew Walbran | 78a63b7 | 2019-03-18 17:28:22 +0000 | [diff] [blame] | 66 | #define FAIL(...) HFTEST_FAIL(true, __VA_ARGS__) |
Andrew Scull | 7fd4bb7 | 2018-12-08 23:40:12 +0000 | [diff] [blame] | 67 | |
Andrew Scull | f0551c8 | 2018-12-15 20:38:47 +0000 | [diff] [blame] | 68 | /* Service utilities. */ |
Andrew Scull | 4a867bc | 2019-04-08 10:15:11 +0100 | [diff] [blame] | 69 | #define SERVICE_NAME_MAX_LENGTH 64 |
Andrew Scull | f0551c8 | 2018-12-15 20:38:47 +0000 | [diff] [blame] | 70 | #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 Walbran | 2b87c70 | 2019-04-16 18:16:05 +0100 | [diff] [blame] | 75 | #define SERVICE_MEMORY_SIZE() HFTEST_SERVICE_MEMORY_SIZE() |
Andrew Scull | f0551c8 | 2018-12-15 20:38:47 +0000 | [diff] [blame] | 76 | |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 77 | /* |
| 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 Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 88 | /* |
Andrew Scull | f0551c8 | 2018-12-15 20:38:47 +0000 | [diff] [blame] | 89 | * Indentation used e.g. to give the reason for an assertion failure. |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 90 | */ |
Andrew Scull | f0551c8 | 2018-12-15 20:38:47 +0000 | [diff] [blame] | 91 | #define HFTEST_LOG_INDENT " " |
Andrew Scull | bc7189d | 2018-08-14 09:35:13 +0100 | [diff] [blame] | 92 | |
Andrew Walbran | afabe85 | 2019-03-20 17:55:11 +0000 | [diff] [blame] | 93 | uintptr_t hftest_get_cpu_id(size_t index); |
| 94 | |
Andrew Scull | f0551c8 | 2018-12-15 20:38:47 +0000 | [diff] [blame] | 95 | /* Above this point is the public API. Now include the implementation. */ |
| 96 | #include <hftest_impl.h> |