diff options
author | Roberto Vargas <roberto.vargas@arm.com> | 2017-08-14 15:07:18 +0100 |
---|---|---|
committer | Roberto Vargas <roberto.vargas@arm.com> | 2017-11-08 08:11:41 +0000 |
commit | beff689eb2001ea7891b37296db911dd757a97bf (patch) | |
tree | 03429414660a80597907a600f632d51147403f93 /tests/runtime_services | |
parent | 721a59349d3c9c8df5301fc8775ac5b7df1f53bf (diff) |
Add test for mem_protect_check_range
This is an optional PSCI feature that allows the caller to
ask if some specific memory region is protected by the mem_protect
feature.
Change-Id: I75d4a6402d9c4db1bc4c266746e58cc96b73b91c
Signed-off-by: Roberto Vargas <roberto.vargas@arm.com>
Diffstat (limited to 'tests/runtime_services')
-rw-r--r-- | tests/runtime_services/standard_service/psci/api_tests/mem_protect_check/mem_protect_check.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/runtime_services/standard_service/psci/api_tests/mem_protect_check/mem_protect_check.c b/tests/runtime_services/standard_service/psci/api_tests/mem_protect_check/mem_protect_check.c new file mode 100644 index 0000000..fd78e67 --- /dev/null +++ b/tests/runtime_services/standard_service/psci/api_tests/mem_protect_check/mem_protect_check.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of ARM nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include <psci.h> +#include <stdlib.h> +#include <test_helpers.h> +#include <tftf_lib.h> + +/* + * DRAM_SIZE is the size of the full DRAM1, but mem_protect only protects + * the non-secure part of it. + */ +#define SECURE_CARVEOUT_SIZE DRAM_TZ_SIZE +#define MAX_SIZE (DRAM_SIZE - SECURE_CARVEOUT_SIZE) +#define MAX_ADDR (DRAM_SIZE + MAX_SIZE) + +/* + * Test to verify that mem_protect_check_range returns correct answer + * for known memory locations. + * + * Returns: + * TEST_RESULT_SUCCESS : When all the checks return the expected value + * TEST_RESULT_FAIL : when some check fails or return an unepected value + */ +test_result_t test_mem_protect_check(void) +{ + int ret; + static int dummy; + struct { + uintptr_t addr; + size_t size; + int expected; + } *bp, check[] = { + {-1, 1, PSCI_E_DENIED}, + {1, -1, PSCI_E_DENIED}, + {-1, 0, PSCI_E_DENIED}, + {0, 0x100, PSCI_E_DENIED}, + + {DRAM_BASE, 0, PSCI_E_DENIED}, + {DRAM_BASE, -1, PSCI_E_DENIED}, + {DRAM_BASE, 1, PSCI_E_SUCCESS}, + {DRAM_BASE, MAX_SIZE-1, PSCI_E_SUCCESS}, + {MAX_ADDR-1, 1, PSCI_E_SUCCESS}, + {MAX_ADDR, 1, PSCI_E_DENIED}, + + {(uintptr_t) &dummy, sizeof(dummy), PSCI_E_SUCCESS}, + }; + + ret = tftf_get_psci_feature_info(SMC_PSCI_MEM_PROTECT_CHECK); + if (ret == PSCI_E_NOT_SUPPORTED) + return TEST_RESULT_SKIPPED; + + for (bp = check; bp < &check[ARRAY_SIZE(check)]; ++bp) { + if (psci_mem_protect_check(bp->addr, bp->size) != bp->expected) + return TEST_RESULT_FAIL; + } + + return TEST_RESULT_SUCCESS; +} |