2 * collectd - src/ceph_test.c
3 * Copyright (C) 2015 Florian octo Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian octo Forster <octo at collectd.org>
22 #include "ceph.c" /* sic */
29 typedef struct case_s case_t;
35 typedef struct test_s test_t;
37 static int test_handler(void *user, char const *val, char const *key) {
44 /* special case for latency metrics. */
45 if (strcmp("filestore.example_latency", key) == 0)
46 return RETRY_AVGCOUNT;
48 snprintf(status, sizeof(status),
49 "unexpected call: test_handler(\"%s\") = \"%s\"", key, val);
52 for (i = 0; i < t->cases_num; i++) {
53 if (strcmp(key, t->cases[i].key) != 0)
56 if (strcmp(val, t->cases[i].value) != 0) {
57 snprintf(status, sizeof(status),
58 "test_handler(\"%s\") = \"%s\", want \"%s\"", key, val,
64 snprintf(status, sizeof(status), "test_handler(\"%s\") = \"%s\"", key, val);
73 DEF_TEST(traverse_json) {
76 " \"WBThrottle\": {\n"
77 " \"bytes_dirtied\": {\n"
79 " \"description\": \"Dirty data\",\n"
84 " \"description\": \"Written data\",\n"
87 " \"ios_dirtied\": {\n"
89 " \"description\": \"Dirty operations\",\n"
94 " \"description\": \"Written operations\",\n"
97 " \"inodes_dirtied\": {\n"
99 " \"description\": \"Entries waiting for write\",\n"
102 " \"inodes_wb\": {\n"
104 " \"description\": \"Written entries\",\n"
108 " \"filestore\": {\n"
109 " \"journal_wr_bytes\": {\n"
110 " \"avgcount\": 23,\n"
113 " \"example_latency\": {\n"
114 " \"avgcount\": 42,\n"
120 {"WBThrottle.bytes_dirtied.type", "2"},
121 {"WBThrottle.bytes_wb.type", "2"},
122 {"WBThrottle.ios_dirtied.type", "2"},
123 {"WBThrottle.ios_wb.type", "2"},
124 {"WBThrottle.inodes_dirtied.type", "2"},
125 {"WBThrottle.inodes_wb.type", "10"},
126 {"filestore.journal_wr_bytes.sum", "3117"},
127 {"filestore.example_latency.avgcount", "42"},
128 {"filestore.example_latency.sum", "4711"},
130 test_t t = {cases, STATIC_ARRAY_SIZE(cases)};
132 yajl_struct ctx = {test_handler, &t};
136 hndl = yajl_alloc(&callbacks, NULL, &ctx);
138 traverse_json((const unsigned char *)json, (uint32_t)strlen(json), hndl));
139 CHECK_ZERO(yajl_complete_parse(hndl));
141 hndl = yajl_alloc(&callbacks, NULL, NULL, &ctx);
143 traverse_json((const unsigned char *)json, (uint32_t)strlen(json), hndl));
144 CHECK_ZERO(yajl_parse_complete(hndl));
151 DEF_TEST(parse_keys) {
156 {"WBThrottle.bytes_dirtied.description.bytes_wb.description.ios_dirtied."
157 "description.ios_wb.type",
158 "WBThrottle.bytesDirtied.description.bytesWb.description.iosDirt"},
159 {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:"
160 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
161 "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},
162 {"foo:bar", "FooBar"},
163 {"foo:bar+", "FooBarPlus"},
164 {"foo:bar-", "FooBarMinus"},
165 {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa+",
166 "AaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaPlus"},
167 {"aa.bb.cc.dd.ee.ff", "Aa.bb.cc.dd.ee.ff"},
168 {"aa.bb.cc.dd.ee.ff.type", "Aa.bb.cc.dd.ee.ff"},
169 {"aa.type", "Aa.type"},
170 {"WBThrottle.bytes_dirtied.type", "WBThrottle.bytesDirtied"},
174 for (i = 0; i < STATIC_ARRAY_SIZE(cases); i++) {
177 CHECK_ZERO(parse_keys(got, sizeof(got), cases[i].str));
178 EXPECT_EQ_STR(cases[i].want, got);
185 RUN_TEST(traverse_json);
186 RUN_TEST(parse_keys);