blob: a2f6a05c29850c1760bd58178810947f9f85f4c6 [file] [log] [blame]
Holger Hans Peter Freytherbce56752012-11-22 14:59:46 +01001/*
2 * (C) 2012 by Holger Hans Peter Freyther <zecke@selfish.org>
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20#include <stdio.h>
21#include <stdlib.h>
22
23#include <osmocom/core/application.h>
24#include <osmocom/core/utils.h>
25
26#include <openbsc/gsm_data.h>
27#include <openbsc/abis_nm.h>
28#include <openbsc/debug.h>
29
30static const uint8_t simple_config[] = {
31 /*0, 13, */
32 66, 18, 0, 3, 1, 2, 3, 19, 0, 3, 3, 4, 5,
33};
34
35static const uint8_t dual_config[] = {
36 /*0, 26, */
37 66, 18, 0, 3, 1, 2, 3, 19, 0, 3, 3, 4, 5,
38 66, 18, 0, 3, 9, 7, 5, 19, 0, 3, 6, 7, 8,
39};
40
41static void test_simple_sw_config(void)
42{
43 struct abis_nm_sw_descr descr[1];
44 int rc;
45
46 rc = abis_nm_parse_sw_config(simple_config, ARRAY_SIZE(simple_config),
47 &descr[0], ARRAY_SIZE(descr));
48 if (rc != 1) {
49 printf("FAILED to parse the File Id/File version\n");
50 abort();
51 }
52
53 if (descr[0].len != 13) {
54 printf("WRONG SIZE: %d\n", descr[0].len);
55 abort();
56 }
57
58 printf("Start: %u len: %zu\n", descr[0].start - simple_config, descr[0].len);
59 printf("file_id: %s\n", osmo_hexdump(descr[0].file_id, descr[0].file_id_len));
60 printf("file_ver: %s\n", osmo_hexdump(descr[0].file_ver, descr[0].file_ver_len));
61}
62
63static void test_simple_sw_short(void)
64{
65 struct abis_nm_sw_descr descr[1];
66 int i;
67
68 for (i = 1; i < ARRAY_SIZE(simple_config); ++i) {
69 int rc = abis_nm_parse_sw_config(simple_config,
70 ARRAY_SIZE(simple_config) - i, &descr[0],
71 ARRAY_SIZE(descr));
72 if (rc >= 1) {
73 printf("SHOULD not have parsed: %d\n", rc);
74 abort();
75 }
76 }
77}
78
79static void test_dual_sw_config(void)
80{
81 struct abis_nm_sw_descr descr[2];
82 int rc;
83
84 rc = abis_nm_parse_sw_config(dual_config, ARRAY_SIZE(dual_config),
85 &descr[0], ARRAY_SIZE(descr));
86 if (rc != 2) {
87 printf("FAILED to parse the File Id/File version\n");
88 abort();
89 }
90
91 if (descr[0].len != 13) {
92 printf("WRONG SIZE0: %d\n", descr[0].len);
93 abort();
94 }
95
96 if (descr[1].len != 13) {
97 printf("WRONG SIZE1: %d\n", descr[1].len);
98 abort();
99 }
100
101 printf("Start: %u len: %zu\n", descr[0].start - dual_config, descr[0].len);
102 printf("file_id: %s\n", osmo_hexdump(descr[0].file_id, descr[0].file_id_len));
103 printf("file_ver: %s\n", osmo_hexdump(descr[0].file_ver, descr[0].file_ver_len));
104
105 printf("Start: %u len: %zu\n", descr[1].start - dual_config, descr[1].len);
106 printf("file_id: %s\n", osmo_hexdump(descr[1].file_id, descr[1].file_id_len));
107 printf("file_ver: %s\n", osmo_hexdump(descr[1].file_ver, descr[1].file_ver_len));
108}
109
110int main(int argc, char **argv)
111{
112 osmo_init_logging(&log_info);
113 test_simple_sw_config();
114 test_simple_sw_short();
115 test_dual_sw_config();
116
117 return EXIT_SUCCESS;
118}