soc/intel/pantherlake: Enable CPU feature programming in coreboot
[coreboot.git] / tests / lib / hexstrtobin-test.c
blobaaad0d6b313607d841ed67539a56924739befc21
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <stdlib.h>
4 #include <string.h>
5 #include <lib.h>
6 #include <stdint.h>
7 #include <tests/test.h>
9 struct hexstr_t {
10 char *str;
11 int *val;
12 size_t res;
13 } hexstr[] = {
14 {.str = "A", .res = 0},
15 {.str = "AB", .val = (int[]){171}, .res = 1},
16 {.str = "277a", .val = (int[]){39, 122}, .res = 2},
17 {.str = "277ab", .val = (int[]){39, 122}, .res = 2},
18 {.str = "\n\rx1234567ijkl", .val = (int[]){18, 52, 86}, .res = 3},
19 {.str = "\nB*e/ef-", .val = (int[]){190, 239}, .res = 2},
22 static void test_hexstrtobin(void **state)
24 uint8_t *buf;
25 size_t res, len;
27 for (int i = 0; i < ARRAY_SIZE(hexstr); i++) {
28 len = strlen(hexstr[i].str) / 2 + 1;
29 buf = malloc(len);
30 res = hexstrtobin(hexstr[i].str, buf, len);
32 assert_int_equal(hexstr[i].res, res);
34 for (int j = 0; j < res; j++)
35 assert_int_equal(hexstr[i].val[j], buf[j]);
37 free(buf);
41 int main(void)
43 const struct CMUnitTest tests[] = {
44 cmocka_unit_test(test_hexstrtobin),
47 return cb_run_group_tests(tests, NULL, NULL);