]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/test-json.c
tests: sigma_dut controlled STA and beacon protection
[thirdparty/hostap.git] / tests / test-json.c
1 /*
2 * JSON parser - test program
3 * Copyright (c) 2019, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #include "utils/includes.h"
10 #include "utils/common.h"
11 #include "utils/os.h"
12 #include "utils/json.h"
13 #include "utils/wpa_debug.h"
14
15
16 void run_test(const char *buf, size_t len)
17 {
18 struct json_token *root;
19 char *txt;
20 size_t buflen = 10000;
21
22 root = json_parse(buf, len);
23 if (!root) {
24 wpa_printf(MSG_DEBUG, "JSON parsing failed");
25 return;
26 }
27
28 txt = os_zalloc(buflen);
29 if (txt) {
30 json_print_tree(root, txt, buflen);
31 wpa_printf(MSG_DEBUG, "%s", txt);
32 os_free(txt);
33 }
34 json_free(root);
35 }
36
37
38 #ifdef TEST_LIBFUZZER
39 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
40 {
41 run_test((const char *) data, size);
42 return 0;
43 }
44 #else /* TEST_LIBFUZZER */
45 int main(int argc, char *argv[])
46 {
47 char *buf;
48 size_t len;
49
50 wpa_debug_level = 0;
51
52 if (argc < 2)
53 return -1;
54
55 buf = os_readfile(argv[1], &len);
56 if (!buf)
57 return -1;
58
59 run_test(buf, len);
60 os_free(buf);
61
62 return 0;
63 }
64 #endif /* TEST_LIBFUZZER */