main(int argc, char *argv[])
{
set_program_name(argv[0]);
- time_init();
- vlog_init();
parse_options(argc, argv);
run_command(argc - optind, argv + optind, all_commands);
return 0;
"usage: %s [OPTIONS] COMMAND [ARG...]\n\n"
" log-io FILE FLAGS COMMAND...\n"
" open FILE with FLAGS, run COMMANDs\n"
+ " default-atoms\n"
+ " test ovsdb_atom_default()\n"
+ " default-data\n"
+ " test ovsdb_datum_default()\n"
" parse-atomic-type TYPE\n"
" parse TYPE as OVSDB atomic type, and re-serialize\n"
" parse-base-type TYPE\n"
ovsdb_log_close(log);
}
+static void
+do_default_atoms(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+{
+ int type;
+
+ for (type = 0; type < OVSDB_N_TYPES; type++) {
+ union ovsdb_atom atom;
+
+ if (type == OVSDB_TYPE_VOID) {
+ continue;
+ }
+
+ printf("%s: ", ovsdb_atomic_type_to_string(type));
+
+ ovsdb_atom_init_default(&atom, type);
+ if (!ovsdb_atom_equals(&atom, ovsdb_atom_default(type), type)) {
+ printf("wrong\n");
+ exit(1);
+ }
+ ovsdb_atom_destroy(&atom, type);
+
+ printf("OK\n");
+ }
+}
+
+static void
+do_default_data(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+{
+ unsigned int n_min;
+ int key, value;
+
+ for (n_min = 0; n_min <= 1; n_min++) {
+ for (key = 0; key < OVSDB_N_TYPES; key++) {
+ if (key == OVSDB_TYPE_VOID) {
+ continue;
+ }
+ for (value = 0; value < OVSDB_N_TYPES; value++) {
+ struct ovsdb_datum datum;
+ struct ovsdb_type type;
+
+ ovsdb_base_type_init(&type.key, key);
+ ovsdb_base_type_init(&type.value, value);
+ type.n_min = n_min;
+ type.n_max = 1;
+ assert(ovsdb_type_is_valid(&type));
+
+ printf("key %s, value %s, n_min %u: ",
+ ovsdb_atomic_type_to_string(key),
+ ovsdb_atomic_type_to_string(value), n_min);
+
+ ovsdb_datum_init_default(&datum, &type);
+ if (!ovsdb_datum_equals(&datum, ovsdb_datum_default(&type),
+ &type)) {
+ printf("wrong\n");
+ exit(1);
+ }
+ ovsdb_datum_destroy(&datum, &type);
+ ovsdb_type_destroy(&type);
+
+ printf("OK\n");
+ }
+ }
+ }
+}
+
static void
do_parse_atomic_type(int argc OVS_UNUSED, char *argv[])
{
}
static void
-do_parse_data(int argc, char *argv[])
+do_parse_data__(int argc, char *argv[],
+ struct ovsdb_error *
+ (*parse)(struct ovsdb_datum *datum,
+ const struct ovsdb_type *type,
+ const struct json *json,
+ struct ovsdb_symbol_table *symtab))
{
struct ovsdb_type type;
struct json *json;
struct ovsdb_datum datum;
json = unbox_json(parse_json(argv[i]));
- check_ovsdb_error(ovsdb_datum_from_json(&datum, &type, json, NULL));
+ check_ovsdb_error(parse(&datum, &type, json, NULL));
json_destroy(json);
print_and_free_json(ovsdb_datum_to_json(&datum, &type));
ovsdb_type_destroy(&type);
}
+static void
+do_parse_data(int argc, char *argv[])
+{
+ do_parse_data__(argc, argv, ovsdb_datum_from_json);
+}
+
static void
do_parse_data_strings(int argc, char *argv[])
{
size_t n_classes;
struct json *json;
int exit_code = 0;
- size_t i, j, k;
+ size_t i;
/* Parse table schema, create table. */
json = unbox_json(parse_json(argv[1]));
for (i = 0; i < json->u.array.n; i++) {
struct ovsdb_row_set results;
struct ovsdb_condition cnd;
+ size_t j;
check_ovsdb_error(ovsdb_condition_from_json(ts, json->u.array.elems[i],
NULL, &cnd));
ovsdb_row_set_init(&results);
ovsdb_query_distinct(table, &cnd, &columns, &results);
for (j = 0; j < results.n_rows; j++) {
+ size_t k;
+
for (k = 0; k < n_rows; k++) {
if (uuid_equals(ovsdb_row_get_uuid(results.rows[j]),
&rows[k].uuid)) {
n_rows = hmap_count(&do_transact_table->rows);
rows = xmalloc(n_rows * sizeof *rows);
i = 0;
- HMAP_FOR_EACH (row, struct ovsdb_row, hmap_node,
- &do_transact_table->rows) {
+ HMAP_FOR_EACH (row, hmap_node, &do_transact_table->rows) {
rows[i++] = row;
}
assert(i == n_rows);
"i=%d", atoi(arg1));
}
idltest_simple_delete(s);
+ } else if (!strcmp(name, "verify")) {
+ const struct idltest_simple *s;
+
+ if (!arg2 || arg3) {
+ ovs_fatal(0, "\"verify\" command requires 2 arguments");
+ }
+
+ s = idltest_find_simple(idl, atoi(arg1));
+ if (!s) {
+ ovs_fatal(0, "\"verify\" command asks for nonexistent "
+ "i=%d", atoi(arg1));
+ }
+
+ if (!strcmp(arg2, "i")) {
+ idltest_simple_verify_i(s);
+ } else if (!strcmp(arg2, "b")) {
+ idltest_simple_verify_b(s);
+ } else if (!strcmp(arg2, "s")) {
+ idltest_simple_verify_s(s);
+ } else if (!strcmp(arg2, "u")) {
+ idltest_simple_verify_s(s);
+ } else if (!strcmp(arg2, "r")) {
+ idltest_simple_verify_r(s);
+ } else {
+ ovs_fatal(0, "\"verify\" command asks for unknown column %s",
+ arg2);
+ }
} else if (!strcmp(name, "increment")) {
if (!arg2 || arg3) {
- ovs_fatal(0, "\"set\" command requires 2 arguments");
+ ovs_fatal(0, "\"increment\" command requires 2 arguments");
}
ovsdb_idl_txn_increment(txn, arg1, arg2, NULL);
increment = true;
idltest_init();
- idl = ovsdb_idl_create(argv[1], &idltest_idl_class);
+ idl = ovsdb_idl_create(argv[1], &idltest_idl_class, true);
if (argc > 2) {
struct stream *stream;
for (i = 2; i < argc; i++) {
char *arg = argv[i];
struct jsonrpc_msg *request, *reply;
- int error;
if (*arg == '+') {
/* The previous transaction didn't change anything. */
static struct command all_commands[] = {
{ "log-io", 2, INT_MAX, do_log_io },
+ { "default-atoms", 0, 0, do_default_atoms },
+ { "default-data", 0, 0, do_default_data },
{ "parse-atomic-type", 1, 1, do_parse_atomic_type },
{ "parse-base-type", 1, 1, do_parse_base_type },
{ "parse-type", 1, 1, do_parse_type },