2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
18 #include <sys/types.h>
21 #include <netinet/in.h>
28 #include <vppinfra/clib.h>
29 #include <vppinfra/vec.h>
30 #include <vppinfra/hash.h>
31 #include <vppinfra/bitmap.h>
32 #include <vppinfra/fifo.h>
33 #include <vppinfra/time.h>
34 #include <vppinfra/mheap.h>
35 #include <vppinfra/heap.h>
36 #include <vppinfra/pool.h>
37 #include <vppinfra/format.h>
38 #include <vppinfra/serialize.h>
42 get_string (char *chroot_path, u8 * vbl)
47 c = svmdb_map_chroot (chroot_path);
49 rv = svmdb_local_get_string_variable (c, (char *) vbl);
51 fformat (stdout, "%s\n", rv ? rv : "UNSET");
57 set_string (char *chroot_path, u8 * vbl, u8 * value)
61 c = svmdb_map_chroot (chroot_path);
62 svmdb_local_set_string_variable (c, (char *) vbl, (char *) value);
67 unset_string (char *chroot_path, u8 * vbl)
71 c = svmdb_map_chroot (chroot_path);
72 svmdb_local_unset_string_variable (c, (char *) vbl);
77 dump_strings (char *chroot_path)
81 c = svmdb_map_chroot (chroot_path);
82 svmdb_local_dump_strings (c);
87 test_vlib_vec_rate (char *chroot_path, f64 vr)
94 c = svmdb_map_chroot (chroot_path);
96 svmdb_local_set_vec_variable (c, "vlib_vector_rate", (char *) tv,
106 test_vec (char *chroot_path, u8 * vbl)
112 /* my amp goes to 11 */
113 for (i = 0; i < 11; i++)
118 c = svmdb_map_chroot (chroot_path);
119 svmdb_local_set_vec_variable (c, (char *) vbl, (char *) tv, sizeof (tv[0]));
126 fake_install (char *chroot_path, u8 * add_value)
136 c = svmdb_map_chroot (chroot_path);
138 oldvalue = svmdb_local_get_vec_variable (c, "installed_sw", 1);
141 unserialize_open_data (&m, oldvalue, vec_len (oldvalue));
142 nitems = unserialize_likely_small_unsigned_integer (&m);
143 for (i = 0; i < nitems; i++)
145 unserialize_cstring (&m, (char **) &value);
146 vec_add1 (values, value);
151 value = format (0, "%s%c", add_value, 0);
153 vec_add1 (values, value);
155 fformat (stdout, "Resulting installed_sw vector:\n");
157 serialize_open_vector (&m, v);
158 serialize_likely_small_unsigned_integer (&m, vec_len (values));
159 for (i = 0; i < vec_len (values); i++)
161 fformat (stdout, "%s\n", values[i]);
162 serialize_cstring (&m, (char *) values[i]);
165 v = serialize_close_vector (&m);
167 svmdb_local_set_vec_variable (c, "installed_sw", v, sizeof (v[0]));
170 for (i = 0; i < vec_len (values); i++)
171 vec_free (values[i]);
176 sigaction_handler (int signum, siginfo_t * i, void *notused)
180 action = (u32) (uword) i->si_ptr;
182 opaque = (u32) (uword) i->si_ptr;
183 opaque &= ~(0xF0000000);
185 clib_warning ("signal %d, action %d, opaque %x", signum, action, opaque);
189 test_reg (char *chroot_path, u8 * vbl)
192 svmdb_notification_args_t args;
193 svmdb_notification_args_t *a = &args;
196 memset (&sa, 0, sizeof (sa));
197 sa.sa_sigaction = sigaction_handler;
198 sa.sa_flags = SA_SIGINFO;
199 if (sigaction (SIGUSR2, &sa, 0) < 0)
201 clib_unix_warning ("sigaction");
205 memset (a, 0, sizeof (*a));
207 c = svmdb_map_chroot (chroot_path);
209 a->add_del = 1 /* add */ ;
210 a->nspace = SVMDB_NAMESPACE_STRING;
211 a->var = (char *) vbl;
214 a->action = SVMDB_ACTION_GET;
215 a->opaque = 0x0eadbeef;
217 svmdb_local_add_del_notification (c, a);
219 (void) svmdb_local_get_string_variable (c, (char *) vbl);
221 a->add_del = 0; /* del */
222 svmdb_local_add_del_notification (c, a);
230 unset_vec (char *chroot_path, u8 * vbl)
234 c = svmdb_map_chroot (chroot_path);
235 svmdb_local_unset_vec_variable (c, (char *) vbl);
240 dump_vecs (char *chroot_path)
244 c = svmdb_map_chroot (chroot_path);
245 svmdb_local_dump_vecs (c);
250 crash_test (char *chroot_path)
254 c = svmdb_map_chroot (chroot_path);
256 clib_warning ("Grab region mutex and crash deliberately!");
257 c->db_rp->mutex_owner_pid = getpid ();
258 c->db_rp->mutex_owner_tag = -13;
259 pthread_mutex_lock (&c->db_rp->mutex);
265 map_with_size (char *chroot_path, uword size)
268 c = svmdb_map_chroot_size (chroot_path, size);
273 main (int argc, char **argv)
275 unformat_input_t input;
277 u8 *vbl = 0, *value = 0;
278 char *chroot_path = 0;
283 unformat_init_command_line (&input, argv);
285 while (unformat_check_input (&input) != UNFORMAT_END_OF_INPUT)
287 if (unformat (&input, "get-string %s", &vbl))
289 get_string (chroot_path, vbl);
293 else if (unformat (&input, "set-string %s %s", &vbl, &value))
295 set_string (chroot_path, vbl, value);
300 else if (unformat (&input, "unset-string %s", &vbl))
302 unset_string (chroot_path, vbl);
306 else if (unformat (&input, "dump-strings"))
308 dump_strings (chroot_path);
311 else if (unformat (&input, "unset-vec %s", &vbl))
313 unset_vec (chroot_path, vbl);
317 else if (unformat (&input, "dump-vecs"))
319 dump_vecs (chroot_path);
322 else if (unformat (&input, "test-vec %s", &vbl))
324 test_vec (chroot_path, vbl);
328 else if (unformat (&input, "vlib-vec-rate %f", &vr))
330 test_vlib_vec_rate (chroot_path, vr);
333 else if (unformat (&input, "test-reg %s", &vbl))
335 test_reg (chroot_path, vbl);
338 else if (unformat (&input, "crash-test"))
340 crash_test (chroot_path);
342 else if (unformat (&input, "chroot %s", &chroot_path_u8))
344 chroot_path = (char *) chroot_path_u8;
346 else if (unformat (&input, "fake-install %s", &value))
348 fake_install (chroot_path, value);
351 else if (unformat (&input, "size %d", &size))
353 map_with_size (chroot_path, size);
362 unformat_free (&input);
366 fformat (stdout, "%s: get-string <name> | set-string <name> <value>\n",
368 fformat (stdout, " unset-string <name> | dump-strings\n");
369 fformat (stdout, " test-vec <name> |\n");
370 fformat (stdout, " unset-vec <name> | dump-vecs\n");
377 * fd.io coding-style-patch-verification: ON
380 * eval: (c-set-style "gnu")