NPE detection

This commit is contained in:
Christian Grothoff 2015-06-25 15:31:15 +02:00
parent c3b29bf7e7
commit 47262f4316
2 changed files with 59 additions and 55 deletions

View File

@ -31,17 +31,17 @@ main (int argc, char ** argv)
{ {
struct TALER_MINTDB_Plugin *plugin; struct TALER_MINTDB_Plugin *plugin;
struct GNUNET_CONFIGURATION_Handle *config; struct GNUNET_CONFIGURATION_Handle *config;
struct PERF_TALER_MINTDB_Cmd test[] = struct PERF_TALER_MINTDB_Cmd test[] =
{ {
PERF_TALER_MINTDB_INIT_CMD_LOOP ("loop_db_init_deposit", PERF_TALER_MINTDB_INIT_CMD_LOOP ("loop_db_init_deposit",
PERF_TALER_MINTDB_NB_DEPOSIT_INIT), PERF_TALER_MINTDB_NB_DEPOSIT_INIT),
PERF_TALER_MINTDB_INIT_CMD_START_TRANSACTION ("start_transaction_init"), PERF_TALER_MINTDB_INIT_CMD_START_TRANSACTION ("start_transaction_init"),
PERF_TALER_MINTDB_INIT_CMD_INSERT_DEPOSIT ("init_deposit_insert"), PERF_TALER_MINTDB_INIT_CMD_INSERT_DEPOSIT ("init_deposit_insert"),
PERF_TALER_MINTDB_INIT_CMD_COMMIT_TRANSACTION ("commit_transaction_init"), PERF_TALER_MINTDB_INIT_CMD_COMMIT_TRANSACTION ("commit_transaction_init"),
PERF_TALER_MINTDB_INIT_CMD_SAVE_ARRAY ("array_depo", PERF_TALER_MINTDB_INIT_CMD_SAVE_ARRAY ("array_depo",
"loop_db_init_deposit", "loop_db_init_deposit",
"init_deposit_insert", "init_deposit_insert",
PERF_TALER_MINTDB_NB_DEPOSIT_GET, PERF_TALER_MINTDB_NB_DEPOSIT_GET,
PERF_TALER_MINTDB_DEPOSIT), PERF_TALER_MINTDB_DEPOSIT),
PERF_TALER_MINTDB_INIT_CMD_END_LOOP ("endloop_init_deposit", PERF_TALER_MINTDB_INIT_CMD_END_LOOP ("endloop_init_deposit",
"loop_db_init_deposit"), "loop_db_init_deposit"),
@ -51,22 +51,26 @@ main (int argc, char ** argv)
PERF_TALER_MINTDB_INIT_CMD_LOOP ("loop_deposit_get", PERF_TALER_MINTDB_INIT_CMD_LOOP ("loop_deposit_get",
PERF_TALER_MINTDB_NB_DEPOSIT_GET), PERF_TALER_MINTDB_NB_DEPOSIT_GET),
PERF_TALER_MINTDB_INIT_CMD_START_TRANSACTION ("start_transaction_get"), PERF_TALER_MINTDB_INIT_CMD_START_TRANSACTION ("start_transaction_get"),
PERF_TALER_MINTDB_INIT_CMD_LOAD_ARRAY ("load deposit", PERF_TALER_MINTDB_INIT_CMD_LOAD_ARRAY ("load deposit",
"loop_deposit_get", "loop_deposit_get",
"array_depo"), "array_depo"),
PERF_TALER_MINTDB_INIT_CMD_GET_DEPOSIT ("get_deposit", PERF_TALER_MINTDB_INIT_CMD_GET_DEPOSIT ("get_deposit",
"load_deposit"), "load_deposit"),
PERF_TALER_MINTDB_INIT_CMD_COMMIT_TRANSACTION ("commit_transaction_init"), PERF_TALER_MINTDB_INIT_CMD_COMMIT_TRANSACTION ("commit_transaction_init"),
PERF_TALER_MINTDB_INIT_CMD_END_LOOP ("stop2", "loop_deposit_get"), PERF_TALER_MINTDB_INIT_CMD_END_LOOP ("stop2", "loop_deposit_get"),
PERF_TALER_MINTDB_INIT_CMD_GET_TIME ("deposit_get_end"), PERF_TALER_MINTDB_INIT_CMD_GET_TIME ("deposit_get_end"),
PERF_TALER_MINTDB_INIT_CMD_GAUGER ("deposit_get_commit", PERF_TALER_MINTDB_INIT_CMD_GAUGER ("deposit_get_commit",
"deposit_get_start", "deposit_get_start",
"deposit_get_end", "deposit_get_end",
"time per deposit check", "time per deposit check",
PERF_TALER_MINTDB_NB_DEPOSIT_GET), PERF_TALER_MINTDB_NB_DEPOSIT_GET),
PERF_TALER_MINTDB_INIT_CMD_END("end"), PERF_TALER_MINTDB_INIT_CMD_END("end"),
}; };
// Plugin init // Plugin init
GNUNET_log_setup ("perf-taler-mintdb",
"WARNING",
NULL);
config = GNUNET_CONFIGURATION_create(); config = GNUNET_CONFIGURATION_create();
GNUNET_CONFIGURATION_load(config, "./test-mint-db-postgres.conf"); GNUNET_CONFIGURATION_load(config, "./test-mint-db-postgres.conf");
GNUNET_assert (NULL != GNUNET_assert (NULL !=

View File

@ -86,7 +86,7 @@ data_free (union PERF_TALER_MINTDB_Data *data, enum PERF_TALER_MINTDB_Type type)
default: default:
return; return;
} }
} }
@ -109,7 +109,7 @@ cmd_find (const struct PERF_TALER_MINTDB_Cmd *cmd, const char *search)
/** /**
* Initialization of a command array * Initialization of a command array
*/ */
static int static int
cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[]) cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
@ -122,8 +122,8 @@ cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
{ {
case PERF_TALER_MINTDB_CMD_SAVE_ARRAY: case PERF_TALER_MINTDB_CMD_SAVE_ARRAY:
// Allocation of memory for saving data // Allocation of memory for saving data
cmd[i].details.save_array.data_saved = cmd[i].details.save_array.data_saved =
GNUNET_new_array (cmd[i].details.save_array.nb_saved, GNUNET_new_array (cmd[i].details.save_array.nb_saved,
union PERF_TALER_MINTDB_Data); union PERF_TALER_MINTDB_Data);
break; break;
@ -133,13 +133,13 @@ cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
(cmd[i].details.load_array.permutation = (cmd[i].details.load_array.permutation =
GNUNET_CRYPTO_random_permute ( GNUNET_CRYPTO_random_permute (
GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_QUALITY_WEAK,
cmd[cmd_find (cmd, cmd[cmd_find (cmd,
cmd[i].details cmd[i].details
.load_array.label_save)] .load_array.label_save)]
.details.save_array.nb_saved))); .details.save_array.nb_saved)));
// Initializing the type based on the type of the saved array // Initializing the type based on the type of the saved array
cmd[i].exposed_type = cmd[cmd_find (cmd, cmd[i].exposed_type = cmd[cmd_find (cmd,
cmd[i].details.load_array.label_save)] cmd[i].details.load_array.label_save)]
.details.save_array.type_saved; .details.save_array.type_saved;
break; break;
@ -200,7 +200,7 @@ interpret_end_loop (struct PERF_TALER_MINTDB_interpreter_state *state)
{ {
unsigned int i; unsigned int i;
union PERF_TALER_MINTDB_Data zero = {0}; union PERF_TALER_MINTDB_Data zero = {0};
unsigned int jump = cmd_find (state->cmd, unsigned int jump = cmd_find (state->cmd,
state->cmd[state->i].details.end_loop.label_loop); state->cmd[state->i].details.end_loop.label_loop);
// Cleaning up the memory in the loop // Cleaning up the memory in the loop
for (i = jump; i < state->i; i++) for (i = jump; i < state->i; i++)
@ -215,7 +215,7 @@ interpret_end_loop (struct PERF_TALER_MINTDB_interpreter_state *state)
state->cmd[jump].details.loop.curr_iteration++; state->cmd[jump].details.loop.curr_iteration++;
// If the loop is not finished // If the loop is not finished
if (state->cmd[jump].details.loop.max_iterations > if (state->cmd[jump].details.loop.max_iterations >
state->cmd[jump].details.loop.curr_iteration) state->cmd[jump].details.loop.curr_iteration)
{ {
// jump back to the start // jump back to the start
@ -239,16 +239,16 @@ interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state)
// Array initialization on first loop iteration // Array initialization on first loop iteration
// Alows for nested loops // Alows for nested loops
if (0 == state->cmd[cmd_find (state->cmd, if (0 == state->cmd[cmd_find (state->cmd,
state->cmd[state->i] state->cmd[state->i]
.details.save_array.label_loop)] .details.save_array.label_loop)]
.details.loop.curr_iteration) .details.loop.curr_iteration)
{ {
state->cmd[state->i].details.save_array.index = 0; state->cmd[state->i].details.save_array.index = 0;
} }
loop_index = cmd_find (state->cmd, loop_index = cmd_find (state->cmd,
state->cmd[state->i].details.save_array.label_loop); state->cmd[state->i].details.save_array.label_loop);
// The probobility distribution of the saved items will be a little biased // The probobility distribution of the saved items will be a little biased
// against the few last items but it should not be a big problem. // against the few last items but it should not be a big problem.
selection_chance = state->cmd[loop_index].details.loop.max_iterations / selection_chance = state->cmd[loop_index].details.loop.max_iterations /
state->cmd[state->i].details.save_array.nb_saved; state->cmd[state->i].details.save_array.nb_saved;
@ -258,13 +258,13 @@ interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state)
* *
* Else it is saved only if rdn is 0 * Else it is saved only if rdn is 0
*/ */
if ((0 < (state->cmd[state->i].details.save_array.nb_saved - if ((0 < (state->cmd[state->i].details.save_array.nb_saved -
state->cmd[state->i].details.save_array.index)) && state->cmd[state->i].details.save_array.index)) &&
(((state->cmd[loop_index].details.loop.max_iterations - (((state->cmd[loop_index].details.loop.max_iterations -
state->cmd[loop_index].details.loop.curr_iteration) == state->cmd[loop_index].details.loop.curr_iteration) ==
(state->cmd[state->i].details.save_array.nb_saved - (state->cmd[state->i].details.save_array.nb_saved -
state->cmd[state->i].details.save_array.index)) state->cmd[state->i].details.save_array.index))
|| (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, || (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
selection_chance)))) selection_chance))))
{ {
union PERF_TALER_MINTDB_Data *save_location; union PERF_TALER_MINTDB_Data *save_location;
@ -272,7 +272,7 @@ interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state)
save_location = &state->cmd[state->i].details.save_array save_location = &state->cmd[state->i].details.save_array
.data_saved[state->cmd[state->i].details.save_array.index]; .data_saved[state->cmd[state->i].details.save_array.index];
item_saved = &state->cmd[cmd_find (state->cmd, item_saved = &state->cmd[cmd_find (state->cmd,
state->cmd[state->i] state->cmd[state->i]
.details.save_array.label_save)] .details.save_array.label_save)]
.exposed; .exposed;
@ -320,9 +320,9 @@ interpret_load_array (struct PERF_TALER_MINTDB_interpreter_state *state)
union PERF_TALER_MINTDB_Data zero = {0}; union PERF_TALER_MINTDB_Data zero = {0};
union PERF_TALER_MINTDB_Data *loaded_data; union PERF_TALER_MINTDB_Data *loaded_data;
loop_index = cmd_find (state->cmd, loop_index = cmd_find (state->cmd,
state->cmd[state->i].details.load_array.label_loop); state->cmd[state->i].details.load_array.label_loop);
save_index = cmd_find (state->cmd, save_index = cmd_find (state->cmd,
state->cmd[state->i].details.load_array.label_save); state->cmd[state->i].details.load_array.label_save);
/* Extracting the data from the loop_indexth indice in save_index /* Extracting the data from the loop_indexth indice in save_index
* array. * array.
@ -362,7 +362,7 @@ interpret_load_array (struct PERF_TALER_MINTDB_interpreter_state *state)
/** /**
* Main interpreter loop. * Main interpreter loop.
* *
*/ */
static int static int
interpret (struct PERF_TALER_MINTDB_interpreter_state *state) interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
@ -392,22 +392,22 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
case PERF_TALER_MINTDB_CMD_GAUGER: case PERF_TALER_MINTDB_CMD_GAUGER:
{ {
unsigned int start_index, stop_index; unsigned int start_index, stop_index;
struct timespec start, stop; struct timespec start, stop;
unsigned long elapsed_ms; unsigned long elapsed_ms;
start_index = cmd_find (state->cmd, start_index = cmd_find (state->cmd,
state->cmd[state->i].details.gauger.label_start); state->cmd[state->i].details.gauger.label_start);
stop_index = cmd_find (state->cmd, stop_index = cmd_find (state->cmd,
state->cmd[state->i].details.gauger.label_stop); state->cmd[state->i].details.gauger.label_stop);
start = state->cmd[start_index].exposed.time; start = state->cmd[start_index].exposed.time;
stop = state->cmd[stop_index].exposed.time; stop = state->cmd[stop_index].exposed.time;
elapsed_ms = (start.tv_sec - stop.tv_sec) * 1000 + elapsed_ms = (start.tv_sec - stop.tv_sec) * 1000 +
(start.tv_nsec - stop.tv_nsec) / 1000000; (start.tv_nsec - stop.tv_nsec) / 1000000;
GAUGER ("MINTDB", GAUGER ("MINTDB",
state->cmd[state->i].details.gauger.description, state->cmd[state->i].details.gauger.description,
elapsed_ms / state->cmd[state->i].details.gauger.divide, elapsed_ms / state->cmd[state->i].details.gauger.divide,
"milliseconds"); "milliseconds");
} }
break; break;
@ -441,8 +441,8 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
PERF_TALER_MINTDB_deposit_init (); PERF_TALER_MINTDB_deposit_init ();
GNUNET_assert ( GNUNET_assert (
state->plugin->insert_deposit (state->plugin->cls, state->plugin->insert_deposit (state->plugin->cls,
state->session, state->session,
deposit)); deposit));
state->cmd[state->i].exposed.deposit = deposit; state->cmd[state->i].exposed.deposit = deposit;
} }
@ -450,24 +450,24 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
case PERF_TALER_MINTDB_CMD_GET_DEPOSIT: case PERF_TALER_MINTDB_CMD_GET_DEPOSIT:
{ {
struct TALER_MINTDB_Deposit *deposit = struct TALER_MINTDB_Deposit *deposit =
state->cmd[cmd_find (state->cmd, state->cmd[cmd_find (state->cmd,
state->cmd[state->i] state->cmd[state->i]
.details.get_deposit.label_source)] .details.get_deposit.label_source)]
.exposed.deposit; // Get the deposit from the source .exposed.deposit; // Get the deposit from the source
GNUNET_assert (NULL != deposit);
state->plugin->have_deposit (state->plugin->cls, state->plugin->have_deposit (state->plugin->cls,
state->session, state->session,
deposit); deposit);
} }
break; break;
case PERF_TALER_MINTDB_CMD_INSERT_RESERVE: case PERF_TALER_MINTDB_CMD_INSERT_RESERVE:
{ {
struct TALER_MINTDB_Reserve *reserve; struct TALER_MINTDB_Reserve *reserve;
json_t *details = json_pack ("si","justification", json_t *details = json_pack ("si","justification",
GNUNET_CRYPTO_random_u32 ( GNUNET_CRYPTO_random_u32 (
GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_QUALITY_WEAK,
UINT32_MAX)); UINT32_MAX));
reserve = PERF_TALER_MINTDB_reserve_init (); reserve = PERF_TALER_MINTDB_reserve_init ();
state->plugin->reserves_in_insert ( state->plugin->reserves_in_insert (
@ -476,7 +476,7 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
&reserve->pub, &reserve->pub,
&reserve->balance, &reserve->balance,
details details
); );
json_decref (details); json_decref (details);
state->cmd[state->i].exposed.reserve = reserve; state->cmd[state->i].exposed.reserve = reserve;
} }
@ -485,16 +485,16 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
case PERF_TALER_MINTDB_CMD_GET_RESERVE: case PERF_TALER_MINTDB_CMD_GET_RESERVE:
{ {
struct TALER_MINTDB_Reserve *reserve = struct TALER_MINTDB_Reserve *reserve =
state->cmd[cmd_find (state->cmd, state->cmd[cmd_find (state->cmd,
state->cmd[state->i] state->cmd[state->i]
.details.get_reserve.label_source)] .details.get_reserve.label_source)]
.exposed.reserve; // Get the deposit from the source .exposed.reserve; // Get the deposit from the source
state->plugin->reserve_get (state->plugin->cls, state->plugin->reserve_get (state->plugin->cls,
state->session, state->session,
reserve); reserve);
} }
break; break;
case PERF_TALER_MINTDB_CMD_INSERT_DENOMINATION: case PERF_TALER_MINTDB_CMD_INSERT_DENOMINATION:
{ {
@ -512,7 +512,7 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
case PERF_TALER_MINTDB_CMD_GET_DENOMINATION: case PERF_TALER_MINTDB_CMD_GET_DENOMINATION:
{ {
struct TALER_MINTDB_DenominationKeyIssueInformation *dki = struct TALER_MINTDB_DenominationKeyIssueInformation *dki =
state->cmd[cmd_find (state->cmd, state->cmd[cmd_find (state->cmd,
state->cmd[state->i] state->cmd[state->i]
.details.get_denomination.label_source)] .details.get_denomination.label_source)]
.exposed.dki; .exposed.dki;
@ -538,11 +538,11 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
case PERF_TALER_MINTDB_CMD_GET_WITHDRAW: case PERF_TALER_MINTDB_CMD_GET_WITHDRAW:
{ {
struct TALER_MINTDB_CollectableBlindcoin *blindcoin = struct TALER_MINTDB_CollectableBlindcoin *blindcoin =
state->cmd[cmd_find (state->cmd, state->cmd[cmd_find (state->cmd,
state->cmd[state->i] state->cmd[state->i]
.details.get_denomination.label_source)] .details.get_denomination.label_source)]
.exposed.blindcoin; .exposed.blindcoin;
state->plugin->get_withdraw_info (state->plugin->cls, state->plugin->get_withdraw_info (state->plugin->cls,
state->session, state->session,
&blindcoin->h_coin_envelope, &blindcoin->h_coin_envelope,
@ -566,7 +566,7 @@ int
PERF_TALER_MINTDB_interpret (struct TALER_MINTDB_Plugin *db_plugin, PERF_TALER_MINTDB_interpret (struct TALER_MINTDB_Plugin *db_plugin,
struct PERF_TALER_MINTDB_Cmd cmd[]) struct PERF_TALER_MINTDB_Cmd cmd[])
{ {
struct PERF_TALER_MINTDB_interpreter_state state = struct PERF_TALER_MINTDB_interpreter_state state =
{.i = 0, .cmd = cmd, .plugin = db_plugin}; {.i = 0, .cmd = cmd, .plugin = db_plugin};
// Initializing commands // Initializing commands