summaryrefslogtreecommitdiff
path: root/lib/x1000-installer/test/test_flashmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/x1000-installer/test/test_flashmap.c')
-rw-r--r--lib/x1000-installer/test/test_flashmap.c140
1 files changed, 0 insertions, 140 deletions
diff --git a/lib/x1000-installer/test/test_flashmap.c b/lib/x1000-installer/test/test_flashmap.c
deleted file mode 100644
index 5e7aa39d78..0000000000
--- a/lib/x1000-installer/test/test_flashmap.c
+++ /dev/null
@@ -1,140 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2021 Aidan MacDonald
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "test.h"
23#include "xf_stream.h"
24#include "xf_flashmap.h"
25#include "xf_error.h"
26#include "file.h"
27#include <string.h>
28#include <stdbool.h>
29#include <stdio.h>
30
31#define MD5SUM \
32 "abcdef012345ABCDEF012345abcdef01"
33#define MD5SUM_L \
34 "abcdef012345abcdef012345abcdef01"
35#define LONG_NAME \
36 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
37#define OVERLONG_NAME \
38 LONG_NAME "a"
39
40static const struct parseline_test {
41 const char* line;
42 int rc;
43 const char* name;
44 const char* md5;
45 uint32_t file_length;
46 uint32_t offset;
47 uint32_t length;
48 int flags;
49} parseline_tests[] = {
50 {"test1 " MD5SUM " 1234 0x9876 42",
51 XF_E_SUCCESS, "test1", MD5SUM_L, 1234, 0x9876, 42,
52 XF_MAP_HAS_FILE_LENGTH|XF_MAP_HAS_MD5},
53 {" test1 " MD5SUM " 1234 0x9876 42",
54 XF_E_SUCCESS, "test1", MD5SUM_L, 1234, 0x9876, 42,
55 XF_MAP_HAS_FILE_LENGTH|XF_MAP_HAS_MD5},
56 {"test1 " MD5SUM " 1234 0x9876 42 \r",
57 XF_E_SUCCESS, "test1", MD5SUM_L, 1234, 0x9876, 42,
58 XF_MAP_HAS_FILE_LENGTH|XF_MAP_HAS_MD5},
59 {"test1 " MD5SUM " 1234 0x9876 42 # junk",
60 XF_E_SYNTAX_ERROR, NULL, NULL, 0, 0, 0, 0},
61 {OVERLONG_NAME,
62 XF_E_FILENAME_TOO_LONG, NULL, NULL, 0, 0, 0, 0},
63 {LONG_NAME " " MD5SUM " 1234 0x9876 42",
64 XF_E_SUCCESS, LONG_NAME, MD5SUM_L, 1234, 0x9876, 42,
65 XF_MAP_HAS_FILE_LENGTH|XF_MAP_HAS_MD5},
66 {"test1 " MD5SUM " 4294967295 0 0xffffffff",
67 XF_E_SUCCESS, "test1", MD5SUM_L, 4294967295, 0, 0xfffffffful,
68 XF_MAP_HAS_FILE_LENGTH|XF_MAP_HAS_MD5},
69 {"test1 " MD5SUM " 4294967295 1 0xffffffff",
70 XF_E_INT_OVERFLOW, NULL, NULL, 0, 0, 0, 0},
71 {"test1 " MD5SUM " 4294967296 0 0xffffffff",
72 XF_E_INT_OVERFLOW, NULL, NULL, 0, 0, 0, 0},
73 {"test1 " MD5SUM " 100294967295 0 0xffffffff",
74 XF_E_INT_OVERFLOW, NULL, NULL, 0, 0, 0, 0},
75 {"test1 " MD5SUM " 0 0 0xffffffff0",
76 XF_E_INT_OVERFLOW, NULL, NULL, 0, 0, 0, 0},
77 {"test1 " MD5SUM " 0 0 0x100000000",
78 XF_E_INT_OVERFLOW, NULL, NULL, 0, 0, 0, 0},
79 {"test1 " MD5SUM " 0 0 0x100000001",
80 XF_E_INT_OVERFLOW, NULL, NULL, 0, 0, 0, 0},
81 {"<",
82 XF_E_SYNTAX_ERROR, NULL, NULL, 0, 0, 0, 0},
83 {"test1 abcXdef",
84 XF_E_SYNTAX_ERROR, NULL, NULL, 0, 0, 0, 0},
85 {"test1 " MD5SUM "0",
86 XF_E_SYNTAX_ERROR, NULL, NULL, 0, 0, 0, 0},
87 {"test1 - 4567 0xabcd",
88 XF_E_SUCCESS, "test1", NULL, 0, 4567, 0xabcd, 0},
89 {"test1 - 0 0x123456789",
90 XF_E_INT_OVERFLOW, NULL, NULL, 0, 0, 0, 0},
91 {"test1 - 4f",
92 XF_E_SYNTAX_ERROR, NULL, NULL, 0, 0, 0, 0},
93};
94
95static void md5_to_string(char* buf, const uint8_t* md5)
96{
97 const char* hex = "0123456789abcdef";
98 for(int i = 0; i < 16; ++i) {
99 uint8_t byte = md5[i];
100 buf[2*i] = hex[(byte >> 4) & 0xf];
101 buf[2*i+1] = hex[byte & 0xf];
102 }
103
104 buf[32] = '\0';
105}
106
107int test_flashmap_parseline(void)
108{
109 int rc;
110 struct xf_map map;
111 char md5string[33];
112
113 size_t num_cases = sizeof(parseline_tests) / sizeof(struct parseline_test);
114 const struct parseline_test* test = &parseline_tests[0];
115
116 for(; num_cases > 0; --num_cases, ++test) {
117 rc = xf_map_parseline(test->line, &map);
118
119 T_ASSERT(rc == test->rc);
120 if(rc != XF_E_SUCCESS)
121 continue;
122
123 T_ASSERT(strcmp(map.name, test->name) == 0);
124 T_ASSERT(map.offset == test->offset);
125 T_ASSERT(map.length == test->length);
126 T_ASSERT(map.flags == test->flags);
127
128 if(test->flags & XF_MAP_HAS_MD5) {
129 md5_to_string(md5string, map.md5);
130 T_ASSERT(strcmp(md5string, test->md5) == 0);
131 }
132
133 if(test->flags & XF_MAP_HAS_FILE_LENGTH) {
134 T_ASSERT(map.file_length == test->file_length);
135 }
136 }
137
138 cleanup:
139 return rc;
140}