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> |
| 12 | |
| 13 | uintptr_t bound_rand(uintptr_t min, uintptr_t max) |
| 14 | { |
| 15 | /* |
| 16 | * This is not ideal as some numbers will never be generated because of |
| 17 | * the integer arithmetic rounding. |
| 18 | */ |
| 19 | return ((rand() * (UINT64_MAX/RAND_MAX)) % (max - min)) + min; |
| 20 | } |
| 21 | |
| 22 | /******************************************************************************* |
| 23 | * Test framework helpers |
| 24 | ******************************************************************************/ |
| 25 | |
| 26 | void expect(int expr, int expected) |
| 27 | { |
| 28 | if (expr != expected) { |
| 29 | ERROR("Expected value %i, got %i\n", expected, expr); |
| 30 | while (1) |
| 31 | continue; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | void announce_test_section_start(const char *test_sect_desc) |
| 36 | { |
| 37 | INFO("========================================\n"); |
| 38 | INFO("Starting %s tests\n", test_sect_desc); |
| 39 | INFO("========================================\n"); |
| 40 | } |
| 41 | void announce_test_section_end(const char *test_sect_desc) |
| 42 | { |
| 43 | INFO("========================================\n"); |
| 44 | INFO("End of %s tests\n", test_sect_desc); |
| 45 | INFO("========================================\n"); |
| 46 | } |
| 47 | |
| 48 | void announce_test_start(const char *test_desc) |
| 49 | { |
| 50 | INFO("[+] %s\n", test_desc); |
| 51 | } |
| 52 | |
| 53 | void announce_test_end(const char *test_desc) |
| 54 | { |
| 55 | INFO("Test \"%s\" passed.\n", test_desc); |
| 56 | } |
| 57 | |
| 58 | void sp_sleep(uint32_t duration_sec) |
| 59 | { |
| 60 | uint32_t timer_freq = mmio_read_32(SYS_CNT_CONTROL_BASE + CNTFID_OFF); |
| 61 | VERBOSE("%s: Timer frequency = %u\n", __func__, timer_freq); |
| 62 | |
| 63 | INFO("%s: Sleeping for %u seconds...\n", __func__, duration_sec); |
| 64 | uint64_t time1 = mmio_read_64(SYS_CNT_READ_BASE); |
| 65 | volatile uint64_t time2 = time1; |
| 66 | while ((time2 - time1) < duration_sec * timer_freq) { |
| 67 | time2 = mmio_read_64(SYS_CNT_READ_BASE); |
| 68 | } |
| 69 | |
| 70 | INFO("%s: Done\n", __func__); |
| 71 | } |