Skip to content

Commit

Permalink
Add tests for SMC Capability
Browse files Browse the repository at this point in the history
Signed-off-by: Robbie VanVossen <[email protected]>
  • Loading branch information
Furao committed Dec 8, 2022
1 parent 91d8da8 commit a07bdc0
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apps/sel4test-driver/include/test_init_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ typedef struct {
/* sched control cap */
seL4_CPtr sched_ctrl;

#ifdef CONFIG_ALLOW_SMC_CALLS
/* smc cap */
seL4_CPtr smc;
#endif /* CONFIG_ALLOW_SMC_CALLS */

/* device frame cap */
seL4_CPtr device_frame_cap;

Expand Down
5 changes: 5 additions & 0 deletions apps/sel4test-driver/src/testtypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ void basic_set_up(uintptr_t e)
sel4utils_copy_cap_to_process(&(env->test_process), &env->vka, sched_ctrl);
}
}
#ifdef CONFIG_ALLOW_SMC_CALLS
env->init->smc = sel4utils_copy_cap_to_process(&(env->test_process), &env->vka, simple_get_init_cap(&env->simple,
seL4_CapSMC));
#endif /* CONFIG_ALLOW_SMC_CALLS */

/* setup data about untypeds */
env->init->untypeds = copy_untypeds_to_process(&(env->test_process), env->untypeds, env->num_untypeds, env);
/* copy the fault endpoint - we wait on the endpoint for a message
Expand Down
3 changes: 3 additions & 0 deletions apps/sel4test-tests/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ int main(int argc, char **argv)
env.asid_pool = init_data->asid_pool;
env.asid_ctrl = init_data->asid_ctrl;
env.sched_ctrl = init_data->sched_ctrl;
#ifdef CONFIG_ALLOW_SMC_CALLS
env.smc = init_data->smc;
#endif
#ifdef CONFIG_IOMMU
env.io_space = init_data->io_space;
#endif
Expand Down
70 changes: 70 additions & 0 deletions apps/sel4test-tests/src/tests/smc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2017, Data61, CSIRO (ABN 41 687 119 230)
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <autoconf.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <sel4/sel4.h>
#include <sel4utils/arch/util.h>

#include <vka/object.h>
#include <vka/capops.h>

#include "../test.h"
#include "../helpers.h"

#ifdef CONFIG_ALLOW_SMC_CALLS

#define ARM_STD_SVC_VERSION 0x8400ff03
#define UNASSIGNED_SMC 0x82000000

static int test_smc_calls(env_t env)
{
seL4_ARM_SMCContext smc_args;
seL4_ARM_SMCContext smc_results;
int error;

seL4_CPtr smc_cap = env->smc;
seL4_CPtr badged_smc_cap = get_free_slot(env);

error = cnode_mint(env, smc_cap, badged_smc_cap, seL4_AllRights, ARM_STD_SVC_VERSION);
test_error_eq(error, seL4_NoError);

/* Set function and arguments */
smc_args.x0 = ARM_STD_SVC_VERSION;
smc_args.x1 = 0;
smc_args.x2 = 0;
smc_args.x3 = 0;
smc_args.x4 = 0;
smc_args.x5 = 0;
smc_args.x6 = 0;
smc_args.x7 = 0;

/* This should succeed */
error = seL4_ARM_SMC_Call(badged_smc_cap, &smc_args, &smc_results);
test_error_eq(error, seL4_NoError);

test_eq(smc_results.x0, 0UL);
test_eq(smc_results.x1, 1UL);
test_eq(smc_results.x2, 0UL);
test_eq(smc_results.x3, 0UL);

/* This should fail - SMC call with a different function id from badge */
smc_args.x0 = UNASSIGNED_SMC;
error = seL4_ARM_SMC_Call(badged_smc_cap, &smc_args, &smc_results);
test_error_eq(error, seL4_IllegalOperation);

/* This should fail - can't mint from cap with non-zero badge */
seL4_CPtr bad_badged_cap = get_free_slot(env);
error = cnode_mint(env, badged_smc_cap, bad_badged_cap, seL4_AllRights, UNASSIGNED_SMC);
test_error_eq(error, seL4_IllegalOperation);

return sel4test_get_result();
}
DEFINE_TEST(SMC0001, "Test SMC calls", test_smc_calls, true)

#endif

0 comments on commit a07bdc0

Please sign in to comment.