From d9cf568454686e48aa1401e0be2db3234be92aa9 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 16 Jun 2009 15:07:54 -0700 Subject: [PATCH] osdmaptool: crush regression test --- src/osdmaptool.cc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/osdmaptool.cc b/src/osdmaptool.cc index 954c0abb0794b..ac9b926992891 100644 --- a/src/osdmaptool.cc +++ b/src/osdmaptool.cc @@ -61,6 +61,7 @@ int main(int argc, const char **argv) const char *import_crush = 0; list add, rm; const char *test_map_pg = 0; + bool test_crush = false; FOR_EACH_ARG(args) { if (CONF_ARG_EQ("print", 'p')) { @@ -82,6 +83,8 @@ int main(int argc, const char **argv) CONF_SAFE_SET_ARG_VAL(&import_crush, OPT_STR); } else if (CONF_ARG_EQ("test_map_pg", '\0')) { CONF_SAFE_SET_ARG_VAL(&test_map_pg, OPT_STR); + } else if (CONF_ARG_EQ("test_crush", '\0')) { + CONF_SAFE_SET_ARG_VAL(&test_crush, OPT_BOOL); } else if (!fn) fn = args[i]; else @@ -168,6 +171,36 @@ int main(int argc, const char **argv) osdmap.pg_to_acting_osds(pgid, acting); cout << pgid << " maps to " << acting << std::endl; } + if (test_crush) { + int pass = 0; + while (1) { + cout << "pass " << ++pass << std::endl; + + hash_map > m; + for (map::const_iterator p = osdmap.get_pools().begin(); + p != osdmap.get_pools().end(); + p++) { + const pg_pool_t& pool = osdmap.get_pg_pool(p->first); + for (int ps = 0; ps < pool.get_pg_num(); ps++) { + pg_t pgid(ps, p->first, -1); + for (int i=0; i<100; i++) { + cout << pgid << " attempt " << i << std::endl; + + vector r, s; + osdmap.pg_to_acting_osds(pgid, r); + //cout << pgid << " " << r << std::endl; + if (m.count(pgid)) { + if (m[pgid] != r) { + cout << pgid << " had " << m[pgid] << " now " << r << std::endl; + assert(0); + } + } else + m[pgid] = r; + } + } + } + } + } if (!print && !modified && !export_crush && !import_crush && !test_map_pg) { cerr << me << ": no action specified?" << std::endl; -- 2.39.5