]>
Commit | Line | Data |
---|---|---|
abccc775 QY |
1 | /* |
2 | * Zlog tests. | |
3 | * Copyright (C) 2018 Cumulus Networks, Inc. | |
4 | * Quentin Young | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the Free | |
8 | * Software Foundation; either version 2 of the License, or (at your option) | |
9 | * any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
14 | * more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License along | |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | #include <zebra.h> | |
21 | #include <memory.h> | |
22 | #include "log.h" | |
23 | ||
24 | /* maximum amount of data to hexdump */ | |
25 | #define MAXDATA 16384 | |
26 | ||
27 | /* | |
28 | * Test hexdump functionality. | |
29 | * | |
30 | * At the moment, not crashing is considered success. | |
31 | */ | |
32 | static bool test_zlog_hexdump(void) | |
33 | { | |
34 | unsigned int nl = 1; | |
35 | ||
36 | do { | |
37 | long d[nl]; | |
38 | ||
39 | for (unsigned int i = 0; i < nl; i++) | |
40 | d[i] = random(); | |
41 | zlog_hexdump(d, nl * sizeof(long)); | |
42 | } while (++nl * sizeof(long) <= MAXDATA); | |
43 | ||
44 | return true; | |
45 | } | |
46 | ||
47 | bool (*tests[])(void) = { | |
48 | test_zlog_hexdump, | |
49 | }; | |
50 | ||
51 | int main(int argc, char **argv) | |
52 | { | |
53 | openzlog("testzlog", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID, | |
54 | LOG_ERR); | |
55 | zlog_set_file("test_zlog.log", LOG_DEBUG); | |
56 | ||
57 | for (unsigned int i = 0; i < array_size(tests); i++) | |
58 | if (!tests[i]()) | |
59 | return 1; | |
60 | return 0; | |
61 | } |