Sort variables in config_mgr_t.all_vars alphabetically

This commit is contained in:
Nick Mathewson 2019-07-23 09:17:51 -04:00
parent dde091ebc7
commit a1b2817abe
2 changed files with 49 additions and 39 deletions

View File

@ -169,6 +169,16 @@ config_mgr_get_obj(const config_mgr_t *mgr, const void *toplevel, int idx)
return config_mgr_get_obj_mutable(mgr, (void*)toplevel, idx); return config_mgr_get_obj_mutable(mgr, (void*)toplevel, idx);
} }
/** Sorting helper for smartlist of managed_var_t */
static int
managed_var_cmp(const void **a, const void **b)
{
const managed_var_t *mv1 = *(const managed_var_t**)a;
const managed_var_t *mv2 = *(const managed_var_t**)b;
return strcasecmp(mv1->cvar->member.name, mv2->cvar->member.name);
}
/** /**
* Mark a configuration manager as "frozen", so that no more formats can be * Mark a configuration manager as "frozen", so that no more formats can be
* added, and so that it can be used for manipulating configuration objects. * added, and so that it can be used for manipulating configuration objects.
@ -176,6 +186,7 @@ config_mgr_get_obj(const config_mgr_t *mgr, const void *toplevel, int idx)
void void
config_mgr_freeze(config_mgr_t *mgr) config_mgr_freeze(config_mgr_t *mgr)
{ {
smartlist_sort(mgr->all_vars, managed_var_cmp);
mgr->frozen = true; mgr->frozen = true;
} }

View File

@ -527,78 +527,77 @@ test_confparse_dump(void *arg)
/* Minimal version. */ /* Minimal version. */
dumped = config_dump(mgr, NULL, tst, 1, 0); dumped = config_dump(mgr, NULL, tst, 1, 0);
tt_str_op(dumped, OP_EQ, tt_str_op(dumped, OP_EQ,
"s this is a\n"
"fn /simple/test of the\n"
"pos 77\n"
"i 3\n"
"u64 1000000000000\n"
"interval 300\n"
"msec_interval 300000\n"
"mem 10\n"
"dbl 6.060842\n"
"boolean 1\n"
"autobool 0\n" "autobool 0\n"
"time 2019-06-14 13:58:51\n" "boolean 1\n"
"csv configuration,parsing,system\n" "csv configuration,parsing,system\n"
"csv_interval 10\n" "csv_interval 10\n"
"dbl 6.060842\n"
"fn /simple/test of the\n"
"i 3\n"
"interval 300\n"
"lines hello\n" "lines hello\n"
"lines world\n" "lines world\n"
"mem 10\n"
"VisibleLineB ABC\n"
"LineTypeA i d\n" "LineTypeA i d\n"
"LineTypeB i c\n" "LineTypeB i c\n"
"msec_interval 300000\n"
"pos 77\n"
"routerset $FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n" "routerset $FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n"
"VisibleLineB ABC\n"); "s this is a\n"
"time 2019-06-14 13:58:51\n"
"u64 1000000000000\n");
/* Maximal */
tor_free(dumped); tor_free(dumped);
dumped = config_dump(mgr, NULL, tst, 0, 0); dumped = config_dump(mgr, NULL, tst, 0, 0);
tt_str_op(dumped, OP_EQ, tt_str_op(dumped, OP_EQ,
"s this is a\n"
"fn /simple/test of the\n"
"pos 77\n"
"i 3\n"
"deprecated_int 3\n"
"u64 1000000000000\n"
"interval 300\n"
"msec_interval 300000\n"
"mem 10\n"
"dbl 6.060842\n"
"boolean 1\n"
"autobool 0\n" "autobool 0\n"
"time 2019-06-14 13:58:51\n" "boolean 1\n"
"csv configuration,parsing,system\n" "csv configuration,parsing,system\n"
"csv_interval 10\n" "csv_interval 10\n"
"dbl 6.060842\n"
"deprecated_int 3\n"
"fn /simple/test of the\n"
"i 3\n"
"interval 300\n"
"lines hello\n" "lines hello\n"
"lines world\n" "lines world\n"
"mem 10\n"
"VisibleLineB ABC\n"
"LineTypeA i d\n" "LineTypeA i d\n"
"LineTypeB i c\n" "LineTypeB i c\n"
"msec_interval 300000\n"
"pos 77\n"
"routerset $FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n" "routerset $FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n"
"VisibleLineB ABC\n"); "s this is a\n"
"time 2019-06-14 13:58:51\n"
"u64 1000000000000\n");
/* commented */ /* commented */
tor_free(dumped); tor_free(dumped);
dumped = config_dump(mgr, NULL, tst, 0, 1); dumped = config_dump(mgr, NULL, tst, 0, 1);
tt_str_op(dumped, OP_EQ, tt_str_op(dumped, OP_EQ,
"s this is a\n"
"fn /simple/test of the\n"
"pos 77\n"
"i 3\n"
"# deprecated_int 3\n"
"u64 1000000000000\n"
"interval 300\n"
"msec_interval 300000\n"
"mem 10\n"
"dbl 6.060842\n"
"boolean 1\n"
"autobool 0\n" "autobool 0\n"
"time 2019-06-14 13:58:51\n" "boolean 1\n"
"csv configuration,parsing,system\n" "csv configuration,parsing,system\n"
"csv_interval 10\n" "csv_interval 10\n"
"dbl 6.060842\n"
"# deprecated_int 3\n"
"fn /simple/test of the\n"
"i 3\n"
"interval 300\n"
"lines hello\n" "lines hello\n"
"lines world\n" "lines world\n"
"mem 10\n"
"VisibleLineB ABC\n"
"LineTypeA i d\n" "LineTypeA i d\n"
"LineTypeB i c\n" "LineTypeB i c\n"
"msec_interval 300000\n"
"pos 77\n"
"routerset $FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n" "routerset $FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n"
"VisibleLineB ABC\n"); "s this is a\n"
"time 2019-06-14 13:58:51\n"
"u64 1000000000000\n");
done: done:
config_free(mgr, tst); config_free(mgr, tst);