julhal01 | 37e1aea | 2021-02-09 15:22:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | #include <service/test_runner/provider/backend/simple_c/simple_c_test_runner.h> |
| 7 | #include <config/interface/platform_config.h> |
| 8 | #include <stdint.h> |
| 9 | |
| 10 | /** |
| 11 | * Secure Partition configuration tests for checking configuartion |
| 12 | * data passed to an SP at initialisation. These tests assume |
| 13 | * use of the FFA manifest for any SP deployments of |
| 14 | * deployments/env_test. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * Check that the loaded configuration includes one or more |
| 19 | * device regions. |
| 20 | */ |
| 21 | static bool check_device_region_loaded(struct test_failure *failure) |
| 22 | { |
| 23 | return platform_config_device_region_count() > 0; |
| 24 | } |
| 25 | |
| 26 | /* |
| 27 | * Check that a device region for a 'trng' device has been loaded |
| 28 | * and that values are as expected. |
| 29 | */ |
| 30 | static bool check_trng_device_region_loaded(struct test_failure *failure) |
| 31 | { |
| 32 | bool passed = false; |
| 33 | struct device_region *dev_region = platform_config_device_query("trng", 0); |
| 34 | |
| 35 | if (dev_region) { |
| 36 | |
| 37 | passed = |
| 38 | (dev_region->dev_instance == 0) && |
| 39 | (dev_region->io_region_size == 0x1000); |
| 40 | } |
| 41 | |
| 42 | platform_config_device_query_free(dev_region); |
| 43 | |
| 44 | return passed; |
| 45 | } |
| 46 | |
| 47 | /* |
| 48 | * Check access to some trng registers |
| 49 | */ |
| 50 | static bool check_trng_register_access(struct test_failure *failure) |
| 51 | { |
| 52 | bool passed = false; |
| 53 | |
| 54 | struct device_region *dev_region = platform_config_device_query("trng", 0); |
| 55 | |
| 56 | if (dev_region) { |
| 57 | |
| 58 | /* Expect reset values to be read from a selection of TRNG registers */ |
| 59 | uint32_t reg_val; |
| 60 | passed = true; |
| 61 | |
| 62 | /* PID4 */ |
| 63 | if (passed) { |
| 64 | reg_val = *((volatile uint32_t*)((uint8_t*)dev_region->base_addr + 0xfd0)); |
| 65 | passed = (reg_val == 0x00000004); |
| 66 | failure->line_num = __LINE__; |
| 67 | failure->info = reg_val; |
| 68 | } |
| 69 | |
| 70 | /* PID0 */ |
| 71 | if (passed) { |
| 72 | reg_val = *((volatile uint32_t*)((uint8_t*)dev_region->base_addr + 0xfe0)); |
| 73 | passed = (reg_val == 0x000000aa); |
| 74 | failure->line_num = __LINE__; |
| 75 | failure->info = reg_val; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | return passed; |
| 80 | } |
| 81 | |
| 82 | |
| 83 | /** |
| 84 | * Define an register test group |
| 85 | */ |
| 86 | void sp_config_tests_register(void) |
| 87 | { |
| 88 | static const struct simple_c_test_case sp_config_tests[] = { |
| 89 | {.name = "DevRegionLoaded", .test_func = check_device_region_loaded}, |
| 90 | {.name = "TrngDevRegionLoaded", .test_func = check_trng_device_region_loaded}, |
| 91 | {.name = "TrngRegAccess", .test_func = check_trng_register_access} |
| 92 | }; |
| 93 | |
| 94 | static const struct simple_c_test_group sp_config_test_group = |
| 95 | { |
| 96 | .group = "SpConfigTests", |
| 97 | .num_test_cases = sizeof(sp_config_tests)/sizeof(struct simple_c_test_case), |
| 98 | .test_cases = sp_config_tests |
| 99 | }; |
| 100 | |
| 101 | simple_c_test_runner_register_group(&sp_config_test_group); |
| 102 | } |