Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 | * Use of this source code is governed by a BSD-style license that can be |
| 3 | * found in the LICENSE file. |
| 4 | * |
| 5 | * Tests for vboot_api_firmware |
| 6 | */ |
| 7 | |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 8 | #include <stddef.h> |
Bill Richardson | 0c3ba24 | 2013-03-29 11:09:30 -0700 | [diff] [blame] | 9 | #include <stdint.h> |
Bill Richardson | 94d7034 | 2011-10-04 08:36:09 -0700 | [diff] [blame] | 10 | #include <stdio.h> |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 11 | #include <stdlib.h> |
| 12 | |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 13 | #include "2sysincludes.h" |
Joel Kitching | 8a4f0be | 2019-04-25 15:41:35 +0800 | [diff] [blame] | 14 | #include "2common.h" |
Randall Spangler | 5142132 | 2017-12-14 15:43:17 -0800 | [diff] [blame] | 15 | #include "2misc.h" |
Randall Spangler | dff5852 | 2017-11-27 15:37:13 -0800 | [diff] [blame] | 16 | #include "2nvstorage.h" |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 17 | #include "crc32.h" |
| 18 | #include "host_common.h" |
Bill Richardson | 94d7034 | 2011-10-04 08:36:09 -0700 | [diff] [blame] | 19 | #include "load_kernel_fw.h" |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 20 | #include "rollback_index.h" |
| 21 | #include "test_common.h" |
| 22 | #include "vboot_common.h" |
Bill Richardson | 94d7034 | 2011-10-04 08:36:09 -0700 | [diff] [blame] | 23 | #include "vboot_display.h" |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 24 | #include "vboot_kernel.h" |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 25 | #include "vboot_struct.h" |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 26 | |
| 27 | |
| 28 | /* Expected results */ |
| 29 | |
| 30 | #define MAX_NOTE_EVENTS 10 |
Bill Richardson | 037dba2 | 2012-01-19 13:47:33 -0800 | [diff] [blame] | 31 | #define TIME_FUZZ 500 |
| 32 | #define KBD_READ_TIME 60 |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 33 | |
| 34 | typedef struct { |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 35 | uint16_t msec; |
| 36 | uint16_t freq; |
| 37 | int time; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 38 | } note_event_t; |
| 39 | |
| 40 | typedef struct { |
Julius Werner | 52fa8c1 | 2019-05-07 12:59:47 -0700 | [diff] [blame] | 41 | const char *name; |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 42 | uint32_t gbb_flags; |
Joel Kitching | 90671fa | 2019-07-31 13:17:08 +0800 | [diff] [blame] | 43 | vb2_error_t beep_return; |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 44 | uint32_t keypress_key; |
| 45 | int keypress_at_count; |
| 46 | int num_events; |
| 47 | note_event_t notes[MAX_NOTE_EVENTS]; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 48 | } test_case_t; |
| 49 | |
| 50 | test_case_t test[] = { |
| 51 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 52 | { "VbBootDeveloperSoundTest( fast )", |
| 53 | VB2_GBB_FLAG_DEV_SCREEN_SHORT_DELAY, VBERROR_NO_BACKGROUND_SOUND, |
| 54 | 0, 0, |
| 55 | 1, |
| 56 | { |
Joel Kitching | 9ad8a41 | 2018-08-02 16:21:17 +0800 | [diff] [blame] | 57 | {0, 0, 2000}, // off and return at 2 seconds |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 58 | }}, |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 59 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 60 | { "VbBootDeveloperSoundTest( normal )", |
| 61 | 0, VBERROR_NO_BACKGROUND_SOUND, |
| 62 | 0, 0, |
| 63 | 3, |
| 64 | { |
Joel Kitching | 9ad8a41 | 2018-08-02 16:21:17 +0800 | [diff] [blame] | 65 | {250, 400, 20000}, // first beep at 20 seconds |
| 66 | {250, 400, 20510}, // second beep shortly after |
| 67 | {0, 0, 30020}, // off and return at 30 seconds |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 68 | }}, |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 69 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 70 | // Now with some keypresses |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 71 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 72 | { "VbBootDeveloperSoundTest( normal, Ctrl-D )", |
| 73 | 0, VBERROR_NO_BACKGROUND_SOUND, |
| 74 | 4, 20400, // Ctrl-D between beeps |
| 75 | 2, |
| 76 | { |
Joel Kitching | 9ad8a41 | 2018-08-02 16:21:17 +0800 | [diff] [blame] | 77 | {250, 400, 20000}, // first beep at 20 seconds |
| 78 | {0, 0, 20400}, // sees Ctrl-D, sound off, return |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 79 | }}, |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 80 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 81 | { "VbBootDeveloperSoundTest( normal, Ctrl-U not allowed )", |
| 82 | 0, VBERROR_NO_BACKGROUND_SOUND, |
| 83 | 21, 10000, // Ctrl-U at 10 seconds |
| 84 | 5, |
| 85 | { |
Joel Kitching | 9ad8a41 | 2018-08-02 16:21:17 +0800 | [diff] [blame] | 86 | {120, 400, 10000}, // complains about Ctrl-U (one beep) |
| 87 | {120, 400, 10240}, // complains about Ctrl-U (two beeps) |
| 88 | {250, 400, 20000}, // starts first beep at 20 seconds |
| 89 | {250, 400, 20510}, // starts second beep |
| 90 | {0, 0, 30020}, // returns at 30 seconds + 360ms |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 91 | }}, |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 94 | /* Mock data */ |
Randall Spangler | 5142132 | 2017-12-14 15:43:17 -0800 | [diff] [blame] | 95 | static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE]; |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 96 | static struct vb2_context ctx; |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 97 | static struct vb2_shared_data *sd; |
Joel Kitching | de2cae6 | 2019-05-21 12:20:38 +0800 | [diff] [blame] | 98 | static struct vb2_gbb_header gbb; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 99 | static uint8_t shared_data[VB_SHARED_DATA_MIN_SIZE]; |
| 100 | static VbSharedDataHeader* shared = (VbSharedDataHeader*)shared_data; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 101 | static int current_time; |
Bill Richardson | 037dba2 | 2012-01-19 13:47:33 -0800 | [diff] [blame] | 102 | static uint64_t current_ticks; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 103 | static int current_event; |
| 104 | static int max_events; |
| 105 | static int matched_events; |
| 106 | static int kbd_fire_at; |
| 107 | static uint32_t kbd_fire_key; |
Joel Kitching | 90671fa | 2019-07-31 13:17:08 +0800 | [diff] [blame] | 108 | static vb2_error_t beep_return; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 109 | static note_event_t *expected_event; |
| 110 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 111 | /* Audio open count, so we can reset it */ |
Shelley Chen | 356eab1 | 2017-07-07 09:57:22 -0700 | [diff] [blame] | 112 | extern int audio_open_count; |
| 113 | |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 114 | /* Reset mock data (for use before each test) */ |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 115 | static void ResetMocks(void) |
| 116 | { |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 117 | memset(&ctx, 0, sizeof(ctx)); |
| 118 | ctx.workbuf = workbuf; |
| 119 | ctx.workbuf_size = sizeof(workbuf); |
| 120 | vb2_init_context(&ctx); |
| 121 | vb2_nv_init(&ctx); |
Randall Spangler | 79c1c61 | 2018-01-03 13:42:40 -0800 | [diff] [blame] | 122 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 123 | sd = vb2_get_sd(&ctx); |
Randall Spangler | 79c1c61 | 2018-01-03 13:42:40 -0800 | [diff] [blame] | 124 | sd->vbsd = shared; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 125 | |
Joel Kitching | de2cae6 | 2019-05-21 12:20:38 +0800 | [diff] [blame] | 126 | memset(&gbb, 0, sizeof(gbb)); |
| 127 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 128 | memset(&shared_data, 0, sizeof(shared_data)); |
| 129 | VbSharedDataInit(shared, sizeof(shared_data)); |
| 130 | shared->fw_keyblock_flags = 0xABCDE0; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 131 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 132 | current_ticks = 0; |
| 133 | current_time = 0; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 134 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 135 | current_event = 0; |
| 136 | kbd_fire_at = 0; |
| 137 | kbd_fire_key = 0; |
Bill Richardson | 037dba2 | 2012-01-19 13:47:33 -0800 | [diff] [blame] | 138 | |
Joel Kitching | cf49e7b | 2019-07-29 18:51:00 +0800 | [diff] [blame] | 139 | beep_return = VB2_SUCCESS; |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 140 | audio_open_count = 0; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 141 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 142 | matched_events = 0; |
| 143 | max_events = 0; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /****************************************************************************/ |
| 147 | /* Mocked verification functions */ |
Joel Kitching | de2cae6 | 2019-05-21 12:20:38 +0800 | [diff] [blame] | 148 | struct vb2_gbb_header *vb2_get_gbb(struct vb2_context *c) |
| 149 | { |
| 150 | return &gbb; |
| 151 | } |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 152 | |
Joel Kitching | 90671fa | 2019-07-31 13:17:08 +0800 | [diff] [blame] | 153 | vb2_error_t VbExNvStorageRead(uint8_t* buf) |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 154 | { |
Joel Kitching | cf49e7b | 2019-07-29 18:51:00 +0800 | [diff] [blame] | 155 | return VB2_SUCCESS; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Joel Kitching | 90671fa | 2019-07-31 13:17:08 +0800 | [diff] [blame] | 158 | vb2_error_t VbExNvStorageWrite(const uint8_t* buf) |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 159 | { |
Joel Kitching | cf49e7b | 2019-07-29 18:51:00 +0800 | [diff] [blame] | 160 | return VB2_SUCCESS; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Joel Kitching | 90671fa | 2019-07-31 13:17:08 +0800 | [diff] [blame] | 163 | vb2_error_t VbExDiskGetInfo(VbDiskInfo** infos_ptr, uint32_t* count, |
| 164 | uint32_t disk_flags) |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 165 | { |
Joel Kitching | 9908a9a | 2019-07-29 18:53:38 +0800 | [diff] [blame^] | 166 | return VB2_ERROR_UNKNOWN; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Joel Kitching | 90671fa | 2019-07-31 13:17:08 +0800 | [diff] [blame] | 169 | vb2_error_t VbExDiskFreeInfo(VbDiskInfo* infos, |
| 170 | VbExDiskHandle_t preserve_handle) |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 171 | { |
Joel Kitching | cf49e7b | 2019-07-29 18:51:00 +0800 | [diff] [blame] | 172 | return VB2_SUCCESS; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Joel Kitching | 90671fa | 2019-07-31 13:17:08 +0800 | [diff] [blame] | 175 | vb2_error_t VbExDiskRead(VbExDiskHandle_t handle, uint64_t lba_start, |
| 176 | uint64_t lba_count, void* buffer) |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 177 | { |
Joel Kitching | 9908a9a | 2019-07-29 18:53:38 +0800 | [diff] [blame^] | 178 | return VB2_ERROR_UNKNOWN; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Joel Kitching | 90671fa | 2019-07-31 13:17:08 +0800 | [diff] [blame] | 181 | vb2_error_t VbExDiskWrite(VbExDiskHandle_t handle, uint64_t lba_start, |
| 182 | uint64_t lba_count, const void* buffer) |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 183 | { |
Joel Kitching | 9908a9a | 2019-07-29 18:53:38 +0800 | [diff] [blame^] | 184 | return VB2_ERROR_UNKNOWN; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 187 | uint32_t VbExIsShutdownRequested(void) |
| 188 | { |
| 189 | return 0; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 192 | uint32_t VbExKeyboardRead(void) |
| 193 | { |
| 194 | uint32_t tmp; |
| 195 | uint32_t now; |
Bill Richardson | 037dba2 | 2012-01-19 13:47:33 -0800 | [diff] [blame] | 196 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 197 | VbExSleepMs(KBD_READ_TIME); |
| 198 | now = current_time; |
Bill Richardson | 037dba2 | 2012-01-19 13:47:33 -0800 | [diff] [blame] | 199 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 200 | if (kbd_fire_key && now >= kbd_fire_at) { |
| 201 | VB2_DEBUG(" VbExKeyboardRead() - returning %d at %d msec\n", |
| 202 | kbd_fire_key, now); |
| 203 | tmp = kbd_fire_key; |
| 204 | kbd_fire_key = 0; |
| 205 | return tmp; |
| 206 | } |
| 207 | VB2_DEBUG(" VbExKeyboardRead() - returning %d at %d msec\n", |
| 208 | 0, now); |
| 209 | return 0; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 212 | void VbExSleepMs(uint32_t msec) |
| 213 | { |
Matt Delco | 45e420b | 2019-03-05 16:38:28 -0800 | [diff] [blame] | 214 | current_ticks += (uint64_t)msec * VB_USEC_PER_MSEC; |
| 215 | current_time = current_ticks / VB_USEC_PER_MSEC; |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 216 | VB2_DEBUG("VbExSleepMs(%d) -> %d\n", msec, current_time); |
Bill Richardson | 037dba2 | 2012-01-19 13:47:33 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 219 | uint64_t VbExGetTimer(void) |
| 220 | { |
| 221 | return current_ticks; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Joel Kitching | 90671fa | 2019-07-31 13:17:08 +0800 | [diff] [blame] | 224 | vb2_error_t VbExBeep(uint32_t msec, uint32_t frequency) |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 225 | { |
| 226 | VB2_DEBUG("VbExBeep(%d, %d) at %d msec\n", |
| 227 | msec, frequency, current_time); |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 228 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 229 | if (current_event < max_events && |
| 230 | msec == expected_event[current_event].msec && |
| 231 | frequency == expected_event[current_event].freq && |
| 232 | abs(current_time - expected_event[current_event].time) |
| 233 | < TIME_FUZZ ) { |
| 234 | matched_events++; |
| 235 | } |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 236 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 237 | if (msec) |
| 238 | VbExSleepMs(msec); |
| 239 | current_event++; |
| 240 | return beep_return; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Joel Kitching | 90671fa | 2019-07-31 13:17:08 +0800 | [diff] [blame] | 243 | vb2_error_t VbExDisplayScreen(uint32_t screen_type, uint32_t locale, |
| 244 | const VbScreenData *data) |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 245 | { |
| 246 | switch(screen_type) { |
| 247 | case VB_SCREEN_BLANK: |
| 248 | VB2_DEBUG("VbExDisplayScreen(BLANK)\n"); |
| 249 | break; |
| 250 | case VB_SCREEN_DEVELOPER_WARNING: |
| 251 | VB2_DEBUG("VbExDisplayScreen(DEV)\n"); |
| 252 | break; |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 253 | case VB_SCREEN_RECOVERY_INSERT: |
| 254 | VB2_DEBUG("VbExDisplayScreen(INSERT)\n"); |
| 255 | break; |
| 256 | case VB_SCREEN_RECOVERY_NO_GOOD: |
| 257 | VB2_DEBUG("VbExDisplayScreen(NO_GOOD)\n"); |
| 258 | break; |
| 259 | case VB_SCREEN_OS_BROKEN: |
| 260 | VB2_DEBUG("VbExDisplayScreen(BROKEN)\n"); |
| 261 | break; |
| 262 | default: |
| 263 | VB2_DEBUG("VbExDisplayScreen(%d)\n", screen_type); |
| 264 | } |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 265 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 266 | VB2_DEBUG(" current_time is %d msec\n", current_time); |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 267 | |
Joel Kitching | cf49e7b | 2019-07-29 18:51:00 +0800 | [diff] [blame] | 268 | return VB2_SUCCESS; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 271 | /****************************************************************************/ |
| 272 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 273 | static void VbBootDeveloperSoundTest(void) |
| 274 | { |
| 275 | int i; |
| 276 | int num_tests = sizeof(test) / sizeof(test_case_t); |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 277 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 278 | for (i=0; i<num_tests; i++) { |
| 279 | VB2_DEBUG("STARTING %s ...\n", test[i].name); |
| 280 | ResetMocks(); |
Joel Kitching | de2cae6 | 2019-05-21 12:20:38 +0800 | [diff] [blame] | 281 | gbb.flags = test[i].gbb_flags; |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 282 | beep_return = test[i].beep_return; |
| 283 | kbd_fire_key = test[i].keypress_key; |
| 284 | kbd_fire_at = test[i].keypress_at_count; |
| 285 | max_events = test[i].num_events; |
| 286 | expected_event = test[i].notes; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 287 | (void) VbBootDeveloper(&ctx); |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 288 | VbExBeep(0, 0); /* Dummy call to determine end time */ |
| 289 | VB2_DEBUG("INFO: matched %d total %d expected %d\n", |
| 290 | matched_events, current_event, test[i].num_events); |
| 291 | TEST_TRUE(matched_events == test[i].num_events && |
| 292 | current_event == test[i].num_events, test[i].name); |
| 293 | } |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Randall Spangler | 559a110 | 2016-10-18 14:41:22 -0700 | [diff] [blame] | 296 | int main(int argc, char* argv[]) |
| 297 | { |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 298 | VbBootDeveloperSoundTest(); |
| 299 | return gTestSuccess ? 0 : 255; |
Bill Richardson | 791c95f | 2011-09-30 15:23:15 -0700 | [diff] [blame] | 300 | } |