Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <debug.h> |
| 8 | #include <mmio.h> |
| 9 | #include <platform_def.h> |
| 10 | #include <stdint.h> |
| 11 | #include <stdlib.h> |
J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 12 | #include <ffa_svc.h> |
| 13 | |
| 14 | #include "sp_helpers.h" |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 15 | |
| 16 | uintptr_t bound_rand(uintptr_t min, uintptr_t max) |
| 17 | { |
| 18 | /* |
| 19 | * This is not ideal as some numbers will never be generated because of |
| 20 | * the integer arithmetic rounding. |
| 21 | */ |
| 22 | return ((rand() * (UINT64_MAX/RAND_MAX)) % (max - min)) + min; |
| 23 | } |
| 24 | |
| 25 | /******************************************************************************* |
| 26 | * Test framework helpers |
| 27 | ******************************************************************************/ |
| 28 | |
| 29 | void expect(int expr, int expected) |
| 30 | { |
| 31 | if (expr != expected) { |
| 32 | ERROR("Expected value %i, got %i\n", expected, expr); |
| 33 | while (1) |
| 34 | continue; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | void announce_test_section_start(const char *test_sect_desc) |
| 39 | { |
| 40 | INFO("========================================\n"); |
| 41 | INFO("Starting %s tests\n", test_sect_desc); |
| 42 | INFO("========================================\n"); |
| 43 | } |
| 44 | void announce_test_section_end(const char *test_sect_desc) |
| 45 | { |
| 46 | INFO("========================================\n"); |
| 47 | INFO("End of %s tests\n", test_sect_desc); |
| 48 | INFO("========================================\n"); |
| 49 | } |
| 50 | |
| 51 | void announce_test_start(const char *test_desc) |
| 52 | { |
| 53 | INFO("[+] %s\n", test_desc); |
| 54 | } |
| 55 | |
| 56 | void announce_test_end(const char *test_desc) |
| 57 | { |
J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 58 | INFO("Test \"%s\" end.\n", test_desc); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 59 | } |
| 60 | |
Antonio Nino Diaz | 2ac6f8f | 2018-07-02 09:04:07 +0100 | [diff] [blame] | 61 | void sp_sleep(uint32_t ms) |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 62 | { |
Manish Pandey | e540057 | 2021-01-12 15:15:32 +0000 | [diff] [blame] | 63 | uint64_t timer_freq = read_cntfrq_el0(); |
| 64 | |
Antonio Nino Diaz | 2ac6f8f | 2018-07-02 09:04:07 +0100 | [diff] [blame] | 65 | VERBOSE("%s: Timer frequency = %llu\n", __func__, timer_freq); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 66 | |
Antonio Nino Diaz | 2ac6f8f | 2018-07-02 09:04:07 +0100 | [diff] [blame] | 67 | VERBOSE("%s: Sleeping for %u milliseconds...\n", __func__, ms); |
Manish Pandey | e540057 | 2021-01-12 15:15:32 +0000 | [diff] [blame] | 68 | uint64_t time1 = read_cntvct_el0(); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 69 | volatile uint64_t time2 = time1; |
Antonio Nino Diaz | 2ac6f8f | 2018-07-02 09:04:07 +0100 | [diff] [blame] | 70 | while ((time2 - time1) < ((ms * timer_freq) / 1000U)) { |
Manish Pandey | e540057 | 2021-01-12 15:15:32 +0000 | [diff] [blame] | 71 | time2 = read_cntvct_el0(); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 72 | } |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 73 | } |