blob: d4779d03eee54f0caf9a46bcbe1f5177953f454c [file] [log] [blame]
* Copyright 2018 The Hafnium Authors.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* See the License for the specific language governing permissions and
* limitations under the License.
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdnoreturn.h>
#include "hf/dlog.h"
#include "hf/fdt.h"
#include "hf/memiter.h"
* Define a set up function to be run before every test in a test suite.
#define SET_UP(suite) HFTEST_SET_UP(suite)
* Define a tear down function to be run after every test in a test suite.
#define TEAR_DOWN(suite) HFTEST_TEAR_DOWN(suite)
* Define a test as part of a test suite.
#define TEST(suite, test) HFTEST_TEST(suite, test, false)
* Define a test as part of a test suite and mark it long-running.
#define TEST_LONG_RUNNING(suite, test) HFTEST_TEST(suite, test, true)
* Define a test service.
#define TEST_SERVICE(service) HFTEST_TEST_SERVICE(service)
/* Assertions. */
#define ASSERT_EQ(x, y) HFTEST_ASSERT_OP(x, y, ==, true)
#define ASSERT_NE(x, y) HFTEST_ASSERT_OP(x, y, !=, true)
#define ASSERT_LE(x, y) HFTEST_ASSERT_OP(x, y, <=, true)
#define ASSERT_LT(x, y) HFTEST_ASSERT_OP(x, y, <, true)
#define ASSERT_GE(x, y) HFTEST_ASSERT_OP(x, y, >=, true)
#define ASSERT_GT(x, y) HFTEST_ASSERT_OP(x, y, >, true)
#define ASSERT_TRUE(x) ASSERT_EQ(x, true)
#define ASSERT_FALSE(x) ASSERT_EQ(x, false)
#define EXPECT_EQ(x, y) HFTEST_ASSERT_OP(x, y, ==, false)
#define EXPECT_NE(x, y) HFTEST_ASSERT_OP(x, y, !=, false)
#define EXPECT_LE(x, y) HFTEST_ASSERT_OP(x, y, <=, false)
#define EXPECT_LT(x, y) HFTEST_ASSERT_OP(x, y, <, false)
#define EXPECT_GE(x, y) HFTEST_ASSERT_OP(x, y, >=, false)
#define EXPECT_GT(x, y) HFTEST_ASSERT_OP(x, y, >, false)
#define EXPECT_TRUE(x) EXPECT_EQ(x, true)
#define EXPECT_FALSE(x) EXPECT_EQ(x, false)
#define FAIL(...) HFTEST_FAIL(true, __VA_ARGS__)
/* Service utilities. */
#define SERVICE_SELECT(vm_id, service, send_buffer) \
HFTEST_SERVICE_SELECT(vm_id, service, send_buffer)
* This must be used exactly once in a test image to signal to the linker that
* the .hftest section is allowed to be included in the generated image.
#define HFTEST_ENABLE() int hftest_enable
* Prefixed to log lines from tests for easy filtering in the console.
#define HFTEST_LOG_PREFIX "[hftest] "
* Indentation used e.g. to give the reason for an assertion failure.
/** Initializes stage-1 MMU for tests running in a VM. */
bool hftest_mm_init(void);
/** Adds stage-1 identity mapping for pages covering bytes [base, base+size). */
void hftest_mm_identity_map(const void *base, size_t size, uint32_t mode);
void hftest_mm_vcpu_init(void);
* Returns a pointer to stage-1 mappings.
* Note: There is no locking as all existing users are on the same vCPU.
struct mm_stage1_locked hftest_mm_get_stage1(void);
/** Returns a pointer to the page-table pool. */
struct mpool *hftest_mm_get_ppool(void);
* Inform a host that this is the start of a test run and obtain the command
* line arguments for it.
bool hftest_ctrl_start(const struct fdt_header *fdt, struct memiter *cmd);
/** Inform a host that this test run has finished and clean up. */
void hftest_ctrl_finish(void);
/** Reboot the device. */
noreturn void hftest_device_reboot(void);
* Device-specific operation to escape from the test environment.
* For example, an Android device with UART test controller will reboot after
* every test run back into hftest. So as to flash the device with a different
* system image, the device must escape this loop and boot into the Android
* bootloader.
* If successful, this function will not return.
* It may not be supported on all devices.
void hftest_device_exit_test_environment(void);
* Starts the CPU with the given ID. It will start at the provided entry point
* with the provided argument. It is a wrapper around the generic cpu_start()
* and takes care of MMU initialization.
bool hftest_cpu_start(uintptr_t id, void *stack, size_t stack_size,
void (*entry)(uintptr_t arg), uintptr_t arg);
uintptr_t hftest_get_cpu_id(size_t index);
/* Above this point is the public API. Now include the implementation. */
#include "hftest_impl.h"