Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */
2 :
3 : #include <stdbool.h>
4 :
5 : #include "journald-server.h"
6 :
7 : #define _COMPRESS_PARSE_CHECK(str, enab, thresh, varname) \
8 : do { \
9 : JournalCompressOptions varname = {true, 111}; \
10 : config_parse_compress("", "", 0, "", 0, "", 0, str, \
11 : &varname, NULL); \
12 : assert_se((enab) == varname.enabled); \
13 : if (varname.enabled) \
14 : assert_se((thresh) == varname.threshold_bytes); \
15 : } while (0)
16 :
17 : #define COMPRESS_PARSE_CHECK(str, enabled, threshold) \
18 : _COMPRESS_PARSE_CHECK(str, enabled, threshold, conf##__COUNTER__)
19 :
20 1 : static void test_config_compress(void) {
21 1 : COMPRESS_PARSE_CHECK("yes", true, 111);
22 1 : COMPRESS_PARSE_CHECK("no", false, 111);
23 1 : COMPRESS_PARSE_CHECK("y", true, 111);
24 1 : COMPRESS_PARSE_CHECK("n", false, 111);
25 1 : COMPRESS_PARSE_CHECK("true", true, 111);
26 1 : COMPRESS_PARSE_CHECK("false", false, 111);
27 1 : COMPRESS_PARSE_CHECK("t", true, 111);
28 1 : COMPRESS_PARSE_CHECK("f", false, 111);
29 1 : COMPRESS_PARSE_CHECK("on", true, 111);
30 1 : COMPRESS_PARSE_CHECK("off", false, 111);
31 :
32 : /* Weird size/bool overlapping case. We preserve backward compatibility instead of assuming these are byte
33 : * counts. */
34 1 : COMPRESS_PARSE_CHECK("1", true, 111);
35 1 : COMPRESS_PARSE_CHECK("0", false, 111);
36 :
37 : /* IEC sizing */
38 1 : COMPRESS_PARSE_CHECK("1B", true, 1);
39 1 : COMPRESS_PARSE_CHECK("1K", true, 1024);
40 1 : COMPRESS_PARSE_CHECK("1M", true, 1024 * 1024);
41 1 : COMPRESS_PARSE_CHECK("1G", true, 1024 * 1024 * 1024);
42 :
43 : /* Invalid Case */
44 1 : COMPRESS_PARSE_CHECK("-1", true, 111);
45 1 : COMPRESS_PARSE_CHECK("blah blah", true, 111);
46 1 : COMPRESS_PARSE_CHECK("", true, (uint64_t)-1);
47 1 : }
48 :
49 1 : int main(int argc, char *argv[]) {
50 1 : test_config_compress();
51 :
52 1 : return 0;
53 : }
|