vswitchd: Make the MAC entry aging time configurable.
[sliver-openvswitch.git] / tests / test-ovsdb.c
index 0d7e8c5..990bf6d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010 Nicira Networks.
+ * Copyright (c) 2009, 2010, 2011 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -59,8 +59,6 @@ int
 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;
@@ -139,14 +137,11 @@ usage(void)
            "    print JSON ATOMs in sorted order\n"
            "  parse-data TYPE DATUM...\n"
            "    parse JSON DATUMs as data of given TYPE, and re-serialize\n"
-           "  parse-data-unique TYPE DATUM...\n"
-           "    parse JSON DATUMs as data of given TYPE, eliminating\n"
-           "    duplicate keys, and re-serialize\n"
            "  parse-data-strings TYPE DATUM...\n"
            "    parse string DATUMs as data of given TYPE, and re-serialize\n"
            "  parse-column NAME OBJECT\n"
            "    parse column NAME with info OBJECT, and re-serialize\n"
-           "  parse-table NAME OBJECT\n"
+           "  parse-table NAME OBJECT [DEFAULT-IS-ROOT]\n"
            "    parse table NAME with info OBJECT\n"
            "  parse-row TABLE ROW..., and re-serialize\n"
            "    parse each ROW of defined TABLE\n"
@@ -516,12 +511,6 @@ do_parse_data(int argc, char *argv[])
     do_parse_data__(argc, argv, ovsdb_datum_from_json);
 }
 
-static void
-do_parse_data_unique(int argc, char *argv[])
-{
-    do_parse_data__(argc, argv, ovsdb_datum_from_json_unique);
-}
-
 static void
 do_parse_data_strings(int argc, char *argv[])
 {
@@ -619,12 +608,15 @@ static void
 do_parse_table(int argc OVS_UNUSED, char *argv[])
 {
     struct ovsdb_table_schema *ts;
+    bool default_is_root;
     struct json *json;
 
+    default_is_root = argc > 3 && !strcmp(argv[3], "true");
+
     json = parse_json(argv[2]);
     check_ovsdb_error(ovsdb_table_schema_from_json(json, argv[1], &ts));
     json_destroy(json);
-    print_and_free_json(ovsdb_table_schema_to_json(ts));
+    print_and_free_json(ovsdb_table_schema_to_json(ts, default_is_root));
     ovsdb_table_schema_destroy(ts);
 }
 
@@ -1106,7 +1098,7 @@ do_query_distinct(int argc OVS_UNUSED, 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]));
@@ -1172,6 +1164,7 @@ do_query_distinct(int argc OVS_UNUSED, char *argv[])
     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));
@@ -1182,6 +1175,8 @@ do_query_distinct(int argc OVS_UNUSED, char *argv[])
         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)) {
@@ -1352,7 +1347,7 @@ static struct ovsdb_table *do_transact_table;
 static void
 do_transact_commit(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
 {
-    ovsdb_txn_commit(do_transact_txn, false);
+    ovsdb_error_destroy(ovsdb_txn_commit(do_transact_txn, false));
     do_transact_txn = NULL;
 }
 
@@ -1476,8 +1471,7 @@ do_transact_print(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
     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);
@@ -1758,7 +1752,9 @@ idl_set(struct ovsdb_idl *idl, char *commands, int step)
                 idltest_simple_set_s(s, arg3);
             } else if (!strcmp(arg2, "u")) {
                 struct uuid uuid;
-                uuid_from_string(&uuid, arg3);
+                if (!uuid_from_string(&uuid, arg3)) {
+                    ovs_fatal(0, "\"%s\" is not a valid UUID", arg3);
+                }
                 idltest_simple_set_u(s, uuid);
             } else if (!strcmp(arg2, "r")) {
                 idltest_simple_set_r(s, atof(arg3));
@@ -1788,9 +1784,36 @@ idl_set(struct ovsdb_idl *idl, char *commands, int step)
                           "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;
@@ -1824,7 +1847,7 @@ do_idl(int argc, char *argv[])
 
     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;
 
@@ -1844,7 +1867,6 @@ do_idl(int argc, char *argv[])
     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. */
@@ -1910,11 +1932,10 @@ static struct command all_commands[] = {
     { "parse-atoms", 2, INT_MAX, do_parse_atoms },
     { "parse-atom-strings", 2, INT_MAX, do_parse_atom_strings },
     { "parse-data", 2, INT_MAX, do_parse_data },
-    { "parse-data-unique", 2, INT_MAX, do_parse_data_unique },
     { "parse-data-strings", 2, INT_MAX, do_parse_data_strings },
     { "sort-atoms", 2, 2, do_sort_atoms },
     { "parse-column", 2, 2, do_parse_column },
-    { "parse-table", 2, 2, do_parse_table },
+    { "parse-table", 2, 3, do_parse_table },
     { "parse-rows", 2, INT_MAX, do_parse_rows },
     { "compare-rows", 2, INT_MAX, do_compare_rows },
     { "parse-conditions", 2, INT_MAX, do_parse_conditions },