/* * subtest_populate -- * Populate the tables. */ static void subtest_populate(TEST_OPTS *opts, bool close_test) { WT_CURSOR *maincur, *maincur2; WT_RAND_STATE rnd; WT_SESSION *session; uint64_t i, nrecords; uint32_t rndint; int key, v0, v1, v2; char *big, *bigref; bool failed; failed = false; __wt_random_init_seed(NULL, &rnd); CHECK(create_big_string(&bigref), false); nrecords = opts->nrecords; CHECK(opts->conn->open_session( opts->conn, NULL, NULL, &session), false); CHECK(session->open_cursor(session, "table:subtest", NULL, NULL, &maincur), false); CHECK(session->open_cursor(session, "table:subtest2", NULL, NULL, &maincur2), false); for (i = 0; i < nrecords && !failed; i++) { rndint = __wt_random(&rnd); generate_key(i, &key); generate_value(rndint, i, bigref, &v0, &v1, &v2, &big); CHECK(session->begin_transaction(session, NULL), false); maincur->set_key(maincur, key); maincur->set_value(maincur, v0, v1, v2, big); CHECK(maincur->insert(maincur), false); maincur2->set_key(maincur2, key); maincur2->set_value(maincur2, rndint); CHECK(maincur2->insert(maincur2), false); CHECK(session->commit_transaction(session, NULL), false); if (i == 0) /* * Force an initial checkpoint, that helps to * distinguish a clear failure from just not running * long enough. */ CHECK(session->checkpoint(session, NULL), false); if ((i + 1) % VERBOSE_PRINT == 0 && opts->verbose) printf(" %" PRIu64 "/%" PRIu64 "\n", (i + 1), nrecords); /* Attempt to isolate the failures to checkpointing. */ if (i == (nrecords/100)) { enable_failures(opts->nops, 1000000); /* CHECK should expect failures. */ CHECK(session->checkpoint(session, NULL), true); disable_failures(); if (failed && opts->verbose) printf("checkpoint failed (expected).\n"); } } /* * Closing handles after an extreme fail is likely to cause * cascading failures (or crashes), so recommended practice is * to immediately exit. We're interested in testing both with * and without the recommended practice. */ if (failed) { if (!close_test) { fprintf(stderr, "exit early.\n"); exit(0); } else fprintf(stderr, "closing after failure.\n"); } free(bigref); CHECK(maincur->close(maincur), false); CHECK(maincur2->close(maincur2), false); CHECK(session->close(session, NULL), false); }
void handle_firmware_configuration_request(const char *name, const char* value) { ConfigurationTree tree; if (*name == '\0') { send_app_error_response(PARAM_APP_ERROR_TYPE_BAD_PARAMETER_FORMAT, 0); return; } ConfigurationTreeNode *node = tree.FindNode(name); if (node == 0) { // TODO: improve on this error message send_app_error_response(PARAM_APP_ERROR_TYPE_BAD_PARAMETER_VALUE, PMSG(ERR_MSG_CONFIG_NODE_NOT_FOUND), name); return; } if (!node->IsLeafNode()) { // TODO: improve on this error message send_app_error_response(PARAM_APP_ERROR_TYPE_BAD_PARAMETER_VALUE, PMSG(ERR_MSG_CONFIG_NODE_NOT_COMPLETE), name); return; } if (value == 0) { if ((node->GetLeafOperations() & FIRMWARE_CONFIG_OPS_READABLE) == 0) { send_app_error_response(PARAM_APP_ERROR_TYPE_BAD_PARAMETER_VALUE, PMSG(ERR_MSG_CONFIG_NODE_NOT_READABLE)); return; } generate_value(node->GetNodeType(), tree.GetParentNode(node)->GetInstanceId(), node->GetInstanceId()); } else { if ((node->GetLeafOperations() & FIRMWARE_CONFIG_OPS_WRITEABLE) == 0) { send_app_error_response(PARAM_APP_ERROR_TYPE_BAD_PARAMETER_VALUE, PMSG(ERR_MSG_CONFIG_NODE_NOT_WRITEABLE)); return; } generate_response_start(RSP_APPLICATION_ERROR, 1); // ensure value has correct format and then attempt to set switch (node->GetLeafSetDataType()) { case LEAF_SET_DATATYPE_PIN: { long number; if (!read_pin(number, value) || number < 0 || number > UINT8_MAX) { send_app_error_response(PARAM_APP_ERROR_TYPE_BAD_PARAMETER_FORMAT, PMSG(ERR_MSG_INVALID_PIN_NUMBER), number); return; } if (!set_uint8_value(node->GetNodeType(), tree.GetParentNode(node)->GetInstanceId(), node->GetInstanceId(), number)) { return; // assume that set function has generated an error response } break; } case LEAF_SET_DATATYPE_UINT8: { long number; if (!read_number(number, value) || number < 0 || number > UINT8_MAX) { send_app_error_response(PARAM_APP_ERROR_TYPE_BAD_PARAMETER_FORMAT, PMSG(ERR_MSG_EXPECTED_UINT8_VALUE)); return; } if (!set_uint8_value(node->GetNodeType(), tree.GetParentNode(node)->GetInstanceId(), node->GetInstanceId(), number)) { return; // assume that set function has generated an error response } break; } case LEAF_SET_DATATYPE_INT16: { long number; if (!read_number(number, value)) { send_app_error_response(PARAM_APP_ERROR_TYPE_BAD_PARAMETER_FORMAT, PMSG(ERR_MSG_EXPECTED_INT16_VALUE)); return; } if (!set_int16_value(node->GetNodeType(), tree.GetParentNode(node)->GetInstanceId(), node->GetInstanceId(), number)) { return; // assume that set function has generated an error response } break; } case LEAF_SET_DATATYPE_BOOL: { bool val; if (strcmp(value, "true") == 0 || strcmp(value, "1") == 0) { val = true; } else if (strcmp(value, "false") == 0 || strcmp(value, "0") == 0) { val = false; } else { send_app_error_response(PARAM_APP_ERROR_TYPE_BAD_PARAMETER_FORMAT, PMSG(ERR_MSG_EXPECTED_BOOL_VALUE)); return; } if (!set_bool_value(node->GetNodeType(), tree.GetParentNode(node)->GetInstanceId(), node->GetInstanceId(), val)) { return; // assume that set function has generated an error response } break; } case LEAF_SET_DATATYPE_STRING: { if (!set_string_value(node->GetNodeType(), tree.GetParentNode(node)->GetInstanceId(), node->GetInstanceId(), value)) { return; // assume that set function has generated an error response } break; } case LEAF_SET_DATATYPE_FLOAT: { char *end; float val = strtod(value, &end); if (end == value || *end != '\0') { send_app_error_response(PARAM_APP_ERROR_TYPE_BAD_PARAMETER_FORMAT, PMSG(ERR_MSG_EXPECTED_FLOAT_VALUE)); return; } if (!set_float_value(node->GetNodeType(), tree.GetParentNode(node)->GetInstanceId(), node->GetInstanceId(), val)) { return; // assume that set function has generated an error response } break; } default: send_app_error_response(PARAM_APP_ERROR_TYPE_BAD_PARAMETER_FORMAT, PMSG(MSG_ERR_CANNOT_HANDLE_FIRMWARE_CONFIG_REQUEST), __LINE__); return; } send_OK_response(); } }
/* * check_results -- * Check all the tables and verify the results. */ static int check_results(TEST_OPTS *opts, uint64_t *foundp) { WT_CURSOR *maincur, *maincur2, *v0cur, *v1cur, *v2cur; WT_SESSION *session; uint64_t count, idxcount, nrecords; uint32_t rndint; int key, key_got, ret, v0, v1, v2; char *big, *bigref; testutil_check(create_big_string(&bigref)); nrecords = opts->nrecords; testutil_check(wiredtiger_open(opts->home, NULL, "create,log=(enabled)", &opts->conn)); testutil_check( opts->conn->open_session(opts->conn, NULL, NULL, &session)); testutil_check(session->open_cursor(session, "table:subtest", NULL, NULL, &maincur)); testutil_check(session->open_cursor(session, "table:subtest2", NULL, NULL, &maincur2)); testutil_check(session->open_cursor(session, "index:subtest:v0", NULL, NULL, &v0cur)); testutil_check(session->open_cursor(session, "index:subtest:v1", NULL, NULL, &v1cur)); testutil_check(session->open_cursor(session, "index:subtest:v2", NULL, NULL, &v2cur)); count = 0; while ((ret = maincur->next(maincur)) == 0) { testutil_check(maincur2->next(maincur2)); testutil_check(maincur2->get_key(maincur2, &key_got)); testutil_check(maincur2->get_value(maincur2, &rndint)); generate_key(count, &key); generate_value(rndint, count, bigref, &v0, &v1, &v2, &big); testutil_assert(key == key_got); /* Check the key/values in main table. */ testutil_check(maincur->get_key(maincur, &key_got)); testutil_assert(key == key_got); check_values(maincur, v0, v1, v2, big); /* Check the values in the indices. */ v0cur->set_key(v0cur, v0); testutil_check(v0cur->search(v0cur)); check_values(v0cur, v0, v1, v2, big); v1cur->set_key(v1cur, v1); testutil_check(v1cur->search(v1cur)); check_values(v1cur, v0, v1, v2, big); v2cur->set_key(v2cur, v2); testutil_check(v2cur->search(v2cur)); check_values(v2cur, v0, v1, v2, big); count++; if (count % VERBOSE_PRINT == 0 && opts->verbose) printf("checked %" PRIu64 "/%" PRIu64 "\n", count, nrecords); } if (count % VERBOSE_PRINT != 0 && opts->verbose) printf("checked %" PRIu64 "/%" PRIu64 "\n", count, nrecords); /* * Always expect at least one entry, as populate does a * checkpoint after the first insert. */ testutil_assert(count > 0); testutil_assert(ret == WT_NOTFOUND); testutil_assert(maincur2->next(maincur2) == WT_NOTFOUND); cursor_count_items(v0cur, &idxcount); testutil_assert(count == idxcount); cursor_count_items(v1cur, &idxcount); testutil_assert(count == idxcount); cursor_count_items(v2cur, &idxcount); testutil_assert(count == idxcount); testutil_check(opts->conn->close(opts->conn, NULL)); opts->conn = NULL; free(bigref); *foundp = count; return (0); }
static void format(Sink& sink, unsigned short value) { generate_value(sink, value, boost::spirit::ushort_); }
static value_type generate_value(Gen& r_gen, size_t max) { return generate_value(r_gen, max, value_type()); }
static void format(Sink& sink, bool value) { generate_value(sink, value, boost::spirit::bool_); }
static void format(Sink& sink, signed char value) { generate_value(sink, value, boost::spirit::short_); }
static void format(Sink& sink, std::wstring const& value) { generate_value(sink, value, boost::spirit::standard_wide::string); }
static void format(Sink& sink, Value const& value) { generate_value(sink, value, boost::spirit::stream); }
static void format(Sink& sink, char value) { generate_value(sink, value, boost::spirit::standard_wide::char_); }
static void format(Sink& sink, wchar_t const* value) { generate_value(sink, value, boost::spirit::standard_wide::string); }
static void format(Sink& sink, long double value) { generate_value(sink, value, long_double_generator); }
static void format(Sink& sink, float value) { generate_value(sink, value, float_generator); }
static void format(Sink& sink, long long value) { generate_value(sink, value, boost::spirit::long_long); }
static void format(Sink& sink, unsigned long value) { generate_value(sink, value, boost::spirit::ulong_); }
static void format(Sink& sink, int value) { generate_value(sink, value, boost::spirit::int_); }