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 */
30 typedef struct case_s case_t;
37 typedef struct test_s test_t;
39 static int test_handler(void *user, char const *val, char const *key)
47 /* special case for latency metrics. */
48 if (strcmp ("filestore.example_latency", key) == 0)
49 return RETRY_AVGCOUNT;
51 snprintf (status, sizeof (status), "unexpected call: test_handler(\"%s\") = \"%s\"", key, val);
54 for (i = 0; i < t->cases_num; i++)
56 if (strcmp (key, t->cases[i].key) != 0)
59 if (strcmp (val, t->cases[i].value) != 0)
61 snprintf (status, sizeof (status), "test_handler(\"%s\") = \"%s\", want \"%s\"", key, val, t->cases[i].value);
66 snprintf (status, sizeof (status), "test_handler(\"%s\") = \"%s\"", key, val);
75 DEF_TEST(traverse_json)
77 char const *json = "{\n"
78 " \"WBThrottle\": {\n"
79 " \"bytes_dirtied\": {\n"
81 " \"description\": \"Dirty data\",\n"
86 " \"description\": \"Written data\",\n"
89 " \"ios_dirtied\": {\n"
91 " \"description\": \"Dirty operations\",\n"
96 " \"description\": \"Written operations\",\n"
99 " \"inodes_dirtied\": {\n"
101 " \"description\": \"Entries waiting for write\",\n"
104 " \"inodes_wb\": {\n"
106 " \"description\": \"Written entries\",\n"
110 " \"filestore\": {\n"
111 " \"journal_wr_bytes\": {\n"
112 " \"avgcount\": 23,\n"
115 " \"example_latency\": {\n"
116 " \"avgcount\": 42,\n"
122 {"WBThrottle.bytes_dirtied.type", "2"},
123 {"WBThrottle.bytes_wb.type", "2"},
124 {"WBThrottle.ios_dirtied.type", "2"},
125 {"WBThrottle.ios_wb.type", "2"},
126 {"WBThrottle.inodes_dirtied.type", "2"},
127 {"WBThrottle.inodes_wb.type", "10"},
128 {"filestore.journal_wr_bytes", "3117"},
129 {"filestore.example_latency.avgcount", "42"},
130 {"filestore.example_latency.sum", "4711"},
132 test_t t = {cases, STATIC_ARRAY_SIZE (cases)};
134 yajl_struct ctx = {test_handler, &t};
138 hndl = yajl_alloc (&callbacks, NULL, &ctx);
139 CHECK_ZERO (traverse_json ((const unsigned char *) json, (uint32_t) strlen (json), hndl));
140 CHECK_ZERO (yajl_complete_parse (hndl));
142 hndl = yajl_alloc (&callbacks, NULL, NULL, &ctx);
143 CHECK_ZERO (traverse_json ((const unsigned char *) json, (uint32_t) strlen (json), hndl));
144 CHECK_ZERO (yajl_parse_complete (hndl));
157 {"WBThrottle.bytes_dirtied.description.bytes_wb.description.ios_dirtied.description.ios_wb.type", "WBThrottle.bytesDirtied.description.bytesWb.description.iosDirt"},
158 {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},
159 {"foo:bar", "FooBar"},
160 {"foo:bar+", "FooBarPlus"},
161 {"foo:bar-", "FooBarMinus"},
162 {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa+", "AaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaPlus"},
163 {"aa.bb.cc.dd.ee.ff", "Aa.bb.cc.dd.ee.ff"},
164 {"aa.bb.cc.dd.ee.ff.type", "Aa.bb.cc.dd.ee.ff"},
165 {"aa.type", "Aa.type"},
166 {"WBThrottle.bytes_dirtied.type", "WBThrottle.bytesDirtied"},
170 for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++)
172 char got[DATA_MAX_NAME_LEN];
174 CHECK_ZERO (parse_keys (got, sizeof (got), cases[i].str));
175 EXPECT_EQ_STR (cases[i].want, got);
183 RUN_TEST(traverse_json);
184 RUN_TEST(parse_keys);
189 /* vim: set sw=2 sts=2 et : */