Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: tests/vboot_nvstorage_test.c

Issue 6597011: Add NV storage fields for firmware flags (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git@master
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« host/lib/crossystem.c ('K') | « host/lib/crossystem.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 * 4 *
5 * Tests for firmware image library. 5 * Tests for firmware NV storage library.
6 */ 6 */
7 7
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
11 11
12 #include "test_common.h" 12 #include "test_common.h"
13 #include "vboot_common.h" 13 #include "vboot_common.h"
14 #include "vboot_nvstorage.h" 14 #include "vboot_nvstorage.h"
15 15
16 /* Single NV storage field to test */
17 typedef struct VbNvField {
18 VbNvParam param; /* Parameter index */
19 uint32_t default_value; /* Expected default value */
20 uint32_t test_value; /* Value to test writing */
21 uint32_t test_value2; /* Second value to test writing */
22 char* desc; /* Field description */
23 } VbNvField;
24
25 /* Array of fields to test, terminated with a field with desc==NULL. */
26 static VbNvField nvfields[] = {
27 {VBNV_DEBUG_RESET_MODE, 0, 1, 0, "debug reset mode"},
28 {VBNV_TRY_B_COUNT, 0, 6, 15, "try B count"},
29 {VBNV_RECOVERY_REQUEST, 0, 0x42, 0xED, "recovery request"},
30 {VBNV_LOCALIZATION_INDEX, 0, 0x69, 0xB0, "localization index"},
31 {VBNV_KERNEL_FIELD, 0, 0x12345678, 0xFEDCBA98, "kernel field"},
32 {VBNV_FW_USED_TRY_B, 0, 1, 0, "firmware used try B"},
33 {VBNV_FW_VERIFIED_KERNEL_KEY, 0, 1, 0, "firmware verified kernel key"},
34 {0, 0, 0, 0, NULL}
35 };
16 36
17 static void VbNvStorageTest(void) { 37 static void VbNvStorageTest(void) {
18 38
39 VbNvField* vnf;
19 VbNvContext c; 40 VbNvContext c;
20 uint8_t goodcrc; 41 uint8_t goodcrc;
21 uint32_t data; 42 uint32_t data;
22 43
23 memset(&c, 0xA6, sizeof(c)); 44 memset(&c, 0xA6, sizeof(c));
24 45
25 /* Open with invalid data should set defaults */ 46 /* Open with invalid data should set defaults */
26 TEST_EQ(VbNvSetup(&c), 0, "VbNvSetup()"); 47 TEST_EQ(VbNvSetup(&c), 0, "VbNvSetup()");
27 TEST_EQ(c.raw[0], 0x70, "VbNvSetup() reset header byte"); 48 TEST_EQ(c.raw[0], 0x70, "VbNvSetup() reset header byte");
28 /* Close then regenerates the CRC */ 49 /* Close then regenerates the CRC */
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 TEST_EQ(data, 1, "Kernel settings are reset"); 91 TEST_EQ(data, 1, "Kernel settings are reset");
71 TEST_EQ(VbNvSet(&c, VBNV_KERNEL_SETTINGS_RESET, 0), 0, 92 TEST_EQ(VbNvSet(&c, VBNV_KERNEL_SETTINGS_RESET, 0), 0,
72 "Clear kernel settings reset"); 93 "Clear kernel settings reset");
73 VbNvGet(&c, VBNV_KERNEL_SETTINGS_RESET, &data); 94 VbNvGet(&c, VBNV_KERNEL_SETTINGS_RESET, &data);
74 TEST_EQ(data, 0, "Kernel settings are clear"); 95 TEST_EQ(data, 0, "Kernel settings are clear");
75 TEST_EQ(c.raw[0], 0x40, "Header byte now just has the header bit"); 96 TEST_EQ(c.raw[0], 0x40, "Header byte now just has the header bit");
76 VbNvTeardown(&c); 97 VbNvTeardown(&c);
77 /* That should have changed the CRC */ 98 /* That should have changed the CRC */
78 TEST_NEQ(c.raw[15], goodcrc, "VbNvTeardown() CRC changed due to flags clear"); 99 TEST_NEQ(c.raw[15], goodcrc, "VbNvTeardown() CRC changed due to flags clear");
79 100
80 /* Test debug reset mode field */ 101 /* Test other fields */
81 VbNvSetup(&c); 102 VbNvSetup(&c);
82 TEST_EQ(VbNvGet(&c, VBNV_DEBUG_RESET_MODE, &data), 0, 103 for (vnf = nvfields; vnf->desc; vnf++) {
83 "Get debug reset mode"); 104 TEST_EQ(VbNvGet(&c, vnf->param, &data), 0, vnf->desc);
84 TEST_EQ(data, 0, "Debug reset mode default"); 105 TEST_EQ(data, vnf->default_value, vnf->desc);
85 TEST_EQ(VbNvSet(&c, VBNV_DEBUG_RESET_MODE, 1), 0,
86 "Set debug reset mode");
87 VbNvGet(&c, VBNV_DEBUG_RESET_MODE, &data);
88 TEST_EQ(data, 1, "Debug reset mode set");
89 VbNvTeardown(&c);
90 106
91 /* Test try B count */ 107 TEST_EQ(VbNvSet(&c, vnf->param, vnf->test_value), 0, vnf->desc);
92 VbNvSetup(&c); 108 TEST_EQ(VbNvGet(&c, vnf->param, &data), 0, vnf->desc);
93 TEST_EQ(VbNvGet(&c, VBNV_TRY_B_COUNT, &data), 0, "Get try b count"); 109 TEST_EQ(data, vnf->test_value, vnf->desc);
94 TEST_EQ(data, 0, "Try b count default");
95 TEST_EQ(VbNvSet(&c, VBNV_TRY_B_COUNT, 6), 0, "Set try b count");
96 VbNvGet(&c, VBNV_TRY_B_COUNT, &data);
97 TEST_EQ(data, 6, "Try b count set");
98 VbNvSet(&c, VBNV_TRY_B_COUNT, 15);
99 VbNvGet(&c, VBNV_TRY_B_COUNT, &data);
100 TEST_EQ(data, 15, "Try b count set 2");
101 VbNvTeardown(&c);
102 110
103 /* Test recovery request */ 111 TEST_EQ(VbNvSet(&c, vnf->param, vnf->test_value2), 0, vnf->desc);
104 VbNvSetup(&c); 112 TEST_EQ(VbNvGet(&c, vnf->param, &data), 0, vnf->desc);
105 TEST_EQ(VbNvGet(&c, VBNV_RECOVERY_REQUEST, &data), 0, "Get recovery request"); 113 TEST_EQ(data, vnf->test_value2, vnf->desc);
106 TEST_EQ(data, 0, "Default recovery request"); 114 }
107 TEST_EQ(VbNvSet(&c, VBNV_RECOVERY_REQUEST, 0x42), 0, "Set recovery request");
108 VbNvGet(&c, VBNV_RECOVERY_REQUEST, &data);
109 TEST_EQ(data, 0x42, "Set recovery request");
110 VbNvSet(&c, VBNV_RECOVERY_REQUEST, 0xED);
111 VbNvGet(&c, VBNV_RECOVERY_REQUEST, &data);
112 TEST_EQ(data, 0xED, "Set recovery request 2");
113 VbNvTeardown(&c);
114
115 /* Test localization index */
116 VbNvSetup(&c);
117 TEST_EQ(VbNvGet(&c, VBNV_LOCALIZATION_INDEX, &data), 0,
118 "Get localization index");
119 TEST_EQ(data, 0, "Default localization index");
120 TEST_EQ(VbNvSet(&c, VBNV_LOCALIZATION_INDEX, 0x69), 0,
121 "Set localization index");
122 VbNvGet(&c, VBNV_LOCALIZATION_INDEX, &data);
123 TEST_EQ(data, 0x69, "Set localization index");
124 VbNvSet(&c, VBNV_LOCALIZATION_INDEX, 0xB0);
125 VbNvGet(&c, VBNV_LOCALIZATION_INDEX, &data);
126 TEST_EQ(data, 0xB0, "Set localization index 2");
127 VbNvTeardown(&c);
128
129 /* Test kernel field */
130 VbNvSetup(&c);
131 TEST_EQ(VbNvGet(&c, VBNV_KERNEL_FIELD, &data), 0, "Get kernel field");
132 TEST_EQ(data, 0, "Default kernel field");
133 TEST_EQ(VbNvSet(&c, VBNV_KERNEL_FIELD, 0x12345678), 0, "Set kernel field");
134 VbNvGet(&c, VBNV_KERNEL_FIELD, &data);
135 TEST_EQ(data, 0x12345678, "Set kernel field");
136 VbNvSet(&c, VBNV_KERNEL_FIELD, 0xFEDCBA98);
137 VbNvGet(&c, VBNV_KERNEL_FIELD, &data);
138 TEST_EQ(data, 0xFEDCBA98, "Set kernel field 2");
139 VbNvTeardown(&c); 115 VbNvTeardown(&c);
140 116
141 /* None of those changes should have caused a reset to defaults */ 117 /* None of those changes should have caused a reset to defaults */
142 VbNvSetup(&c); 118 VbNvSetup(&c);
143 VbNvGet(&c, VBNV_FIRMWARE_SETTINGS_RESET, &data); 119 VbNvGet(&c, VBNV_FIRMWARE_SETTINGS_RESET, &data);
144 TEST_EQ(data, 0, "Firmware settings are still clear"); 120 TEST_EQ(data, 0, "Firmware settings are still clear");
145 VbNvGet(&c, VBNV_KERNEL_SETTINGS_RESET, &data); 121 VbNvGet(&c, VBNV_KERNEL_SETTINGS_RESET, &data);
146 TEST_EQ(data, 0, "Kernel settings are still clear"); 122 TEST_EQ(data, 0, "Kernel settings are still clear");
147 VbNvTeardown(&c); 123 VbNvTeardown(&c);
148 124
149 /* Verify writing identical settings doesn't cause the CRC to regenerate */ 125 /* Verify writing identical settings doesn't cause the CRC to regenerate */
150 VbNvSetup(&c); 126 VbNvSetup(&c);
151 TEST_EQ(c.regenerate_crc, 0, "No regen CRC on open"); 127 TEST_EQ(c.regenerate_crc, 0, "No regen CRC on open");
152 VbNvSet(&c, VBNV_DEBUG_RESET_MODE, 1); 128 for (vnf = nvfields; vnf->desc; vnf++)
153 VbNvSet(&c, VBNV_RECOVERY_REQUEST, 0xED); 129 TEST_EQ(VbNvSet(&c, vnf->param, vnf->test_value2), 0, vnf->desc);
154 VbNvSet(&c, VBNV_LOCALIZATION_INDEX, 0xB0);
155 VbNvSet(&c, VBNV_KERNEL_FIELD, 0xFEDCBA98);
156 TEST_EQ(c.regenerate_crc, 0, "No regen CRC if data not changed"); 130 TEST_EQ(c.regenerate_crc, 0, "No regen CRC if data not changed");
157 VbNvTeardown(&c); 131 VbNvTeardown(&c);
158 TEST_EQ(c.raw_changed, 0, "No raw change if data not changed"); 132 TEST_EQ(c.raw_changed, 0, "No raw change if data not changed");
159 } 133 }
160 134
161 135
162 /* disable MSVC warnings on unused arguments */ 136 /* disable MSVC warnings on unused arguments */
163 __pragma(warning (disable: 4100)) 137 __pragma(warning (disable: 4100))
164 138
165 int main(int argc, char* argv[]) { 139 int main(int argc, char* argv[]) {
166 int error_code = 0; 140 int error_code = 0;
167 141
168 VbNvStorageTest(); 142 VbNvStorageTest();
169 143
170 if (!gTestSuccess) 144 if (!gTestSuccess)
171 error_code = 255; 145 error_code = 255;
172 146
173 return error_code; 147 return error_code;
174 } 148 }
OLDNEW
« host/lib/crossystem.c ('K') | « host/lib/crossystem.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698