blob: a8ed1ee566f67f3cbc51cbe65476c4c766bd4547 [file] [log] [blame]
// Copyright Microsoft and CHERIoT Contributors.
// SPDX-License-Identifier: MIT
#include "compartment.h"
#define TEST_NAME "Compartment calls (main runner)"
#include "compartment_calls.h"
#include "tests.hh"
#include <cheri.hh>
#include <errno.h>
#include <switcher.h>
#include <thread_pool.h>
using namespace CHERI;
void test_number_of_arguments()
{
debug_log(
"Test argument calls with different number and type of arguments");
int ret;
int value = ConstantValue;
ret = compartment_call_inner(value);
TEST(ret == 0, "compartment_call_inner returned {}", ret);
ret = compartment_call_inner(value, value);
TEST(ret == 0, "compartment_call_inner returned {}", ret);
ret = compartment_call_inner(value, value, &value);
TEST(ret == 0, "compartment_call_inner returned {}", ret);
ret = compartment_call_inner(value, value, &value, value);
TEST(ret == 0, "compartment_call_inner returned {}", ret);
ret = compartment_call_inner(value, value, &value, value, &value);
TEST(ret == 0, "compartment_call_inner returned {}", ret);
ret = compartment_call_inner(value, value, &value, value, &value, value);
TEST(ret == 0, "compartment_call_inner returned {}", ret);
ret =
compartment_call_inner(value, value, &value, value, &value, value, value);
TEST(ret == 0, "compartment_call_inner returned {}", ret);
}
int test_compartment_call()
{
bool outTestFailed = false;
int ret = 0;
TEST(trusted_stack_has_space(0),
"Trusted stack should have space for 0 more calls");
TEST(trusted_stack_has_space(1),
"Trusted stack should have space for 1 more calls");
TEST(trusted_stack_has_space(7),
"Trusted stack should have space for 7 more calls");
TEST(!trusted_stack_has_space(9),
"Trusted stack should not have space for 9 more calls");
CHERI::Capability<void> csp{__builtin_cheri_stack_get()};
CHERI::Capability<void> originalCSP{switcher_recover_stack()};
csp.address() = originalCSP.address();
TEST(csp == originalCSP,
"Original stack pointer: {}\ndoes not match current stack pointer: {}",
originalCSP,
csp);
test_number_of_arguments();
test_incorrect_export_table(nullptr, &outTestFailed);
TEST(outTestFailed == false,
"Test incorrect entry point without error handler failed");
return 0;
}