void debuglogger(void) { cp_context_t *ctx; struct log_count_t lc = { CP_LOG_DEBUG, 0, 0 }; ctx = init_context(CP_LOG_INFO, NULL); check(cp_register_logger(ctx, counting_logger, &lc, CP_LOG_DEBUG) == CP_OK); cp_destroy(); check(lc.count_max > 0 && lc.count_above_max == 0); }
void errorlogger(void) { cp_context_t *ctx; cp_status_t status; int errors; ctx = init_context(CP_LOG_ERROR + 1, &errors); check(cp_load_plugin_descriptor(ctx, "nonexisting", &status) == NULL && status != CP_OK); cp_destroy(); check(errors > 0); }
void warninglogger(void) { cp_context_t *ctx; struct log_count_t lc = { CP_LOG_WARNING, 0, 0 }; ctx = init_context(CP_LOG_ERROR, NULL); check(cp_register_logger(ctx, counting_logger, &lc, CP_LOG_WARNING) == CP_OK); check(cp_start_plugin(ctx, "nonexisting") == CP_ERR_UNKNOWN); cp_destroy(); check(lc.count_max > 0 && lc.count_above_max == 0); }
void islogged(void) { cp_context_t *ctx; ctx = init_context(CP_LOG_ERROR + 1, NULL); islogged_sev(ctx, CP_LOG_DEBUG); islogged_sev(ctx, CP_LOG_INFO); islogged_sev(ctx, CP_LOG_WARNING); islogged_sev(ctx, CP_LOG_ERROR); cp_destroy(); }
void logmsg(void) { cp_context_t *ctx; ctx = init_context(CP_LOG_ERROR + 1, NULL); logmsg_sev(ctx, CP_LOG_DEBUG, "debug"); logmsg_sev(ctx, CP_LOG_INFO, "info"); logmsg_sev(ctx, CP_LOG_WARNING, "warning"); logmsg_sev(ctx, CP_LOG_ERROR, "error"); cp_destroy(); }
void onecollection(void) { cp_context_t *ctx; int errors; ctx = init_context(CP_LOG_ERROR, &errors); check(cp_register_pcollection(ctx, pcollectiondir("collection1")) == CP_OK); check(cp_scan_plugins(ctx, 0) == CP_OK); check(cp_get_plugin_state(ctx, "plugin1") == CP_PLUGIN_INSTALLED); cp_destroy(); check(errors == 0); }
void loadonlymaximal(void) { cp_context_t *ctx; cp_plugin_info_t *plugin; cp_status_t status; int errors; ctx = init_context(CP_LOG_ERROR, &errors); check((plugin = cp_load_plugin_descriptor(ctx, plugindir("maximal"), &status)) != NULL && status == CP_OK); cp_release_info(ctx, plugin); cp_destroy(); check(errors == 0); }
void infologger(void) { cp_context_t *ctx; cp_plugin_info_t *plugin; cp_status_t status; struct log_count_t lc = { CP_LOG_INFO, 0, 0 }; ctx = init_context(CP_LOG_WARNING, NULL); check(cp_register_logger(ctx, counting_logger, &lc, CP_LOG_INFO) == CP_OK); check((plugin = cp_load_plugin_descriptor(ctx, plugindir("minimal"), &status)) != NULL && status == CP_OK); check(cp_install_plugin(ctx, plugin) == CP_OK); cp_release_info(ctx, plugin); cp_destroy(); check(lc.count_max > 0 && lc.count_above_max == 0); }
void nocollections(void) { cp_context_t *ctx; cp_plugin_info_t **plugins; cp_status_t status; int errors; int i; ctx = init_context(CP_LOG_ERROR, &errors); check(cp_scan_plugins(ctx, 0) == CP_OK); check((plugins = cp_get_plugins_info(ctx, &status, &i)) != NULL && status == CP_OK && i == 0); cp_release_info(ctx, plugins); cp_destroy(); check(errors == 0); }
void twologgers(void) { cp_context_t *ctx; cp_plugin_info_t *plugin; cp_status_t status; struct log_count_t lc = { CP_LOG_DEBUG, 0, 0 }; int count = 0; int errors; ctx = init_context(CP_LOG_ERROR, &errors); check(cp_register_logger(ctx, counting_logger, &lc, CP_LOG_DEBUG) == CP_OK); check(count == 0 && lc.count_max > 0 && lc.count_above_max == 0); check(cp_register_logger(ctx, increment_logger, &count, CP_LOG_INFO) == CP_OK); check(count == 0 && lc.count_max > 0 && lc.count_above_max == 0); check((plugin = cp_load_plugin_descriptor(ctx, plugindir("minimal"), &status)) != NULL && status == CP_OK); check(cp_install_plugin(ctx, plugin) == CP_OK); cp_release_info(ctx, plugin); check(count > 0 && lc.count_max > 0 && lc.count_above_max > 0); cp_destroy(); check(errors == 0); }
void scanupgrade(void) { cp_context_t *ctx; int errors; ctx = init_context(CP_LOG_ERROR, &errors); check(cp_register_pcollection(ctx, pcollectiondir("collection1")) == CP_OK); check(cp_register_pcollection(ctx, pcollectiondir("collection2")) == CP_OK); check(cp_scan_plugins(ctx, 0) == CP_OK); check(cp_get_plugin_state(ctx, "plugin1") == CP_PLUGIN_INSTALLED); check(cp_get_plugin_state(ctx, "plugin2a") == CP_PLUGIN_INSTALLED); check(cp_get_plugin_state(ctx, "plugin2b") == CP_PLUGIN_INSTALLED); scanupgrade_checkpver(ctx, "plugin1", NULL); // Register newer version of plugin1 but do not allow upgrades check(cp_start_plugin(ctx, "plugin1") == CP_OK); check(cp_get_plugin_state(ctx, "plugin1") == CP_PLUGIN_ACTIVE); check(cp_register_pcollection(ctx, pcollectiondir("collection1v2")) == CP_OK); check(cp_scan_plugins(ctx, 0) == CP_OK); check(cp_get_plugin_state(ctx, "plugin1") == CP_PLUGIN_ACTIVE); scanupgrade_checkpver(ctx, "plugin1", NULL); // Now allow upgrade of plugin1 check(cp_scan_plugins(ctx, CP_SP_UPGRADE) == CP_OK); scanupgrade_checkpver(ctx, "plugin1", "2"); // Register even new version and upgrade while running check(cp_register_pcollection(ctx, pcollectiondir("collection1v3")) == CP_OK); check(cp_start_plugin(ctx, "plugin1") == CP_OK); check(cp_get_plugin_state(ctx, "plugin1") == CP_PLUGIN_ACTIVE); check(cp_scan_plugins(ctx, CP_SP_UPGRADE) == CP_OK); check(cp_get_plugin_state(ctx, "plugin1") == CP_PLUGIN_INSTALLED); scanupgrade_checkpver(ctx, "plugin1", "3"); // Check that plug-in is not downgraded when newer versions are unregistered cp_unregister_pcollection(ctx, pcollectiondir("collection1v3")); check(cp_scan_plugins(ctx, CP_SP_UPGRADE) == CP_OK); scanupgrade_checkpver(ctx, "plugin1", "3"); cp_destroy(); check(errors == 0); }
void plugincallbacks(void) { cp_context_t *ctx; cp_status_t status; cp_plugin_info_t *plugin; int errors; cbc_counters_t *counters; ctx = init_context(CP_LOG_ERROR, &errors); cp_set_context_args(ctx, argv); check((plugin = cp_load_plugin_descriptor(ctx, "tmp/install/plugins/callbackcounter", &status)) != NULL && status == CP_OK); check(cp_install_plugin(ctx, plugin) == CP_OK); cp_release_info(ctx, plugin); // Start plug-in implicitly by resolving a symbol check((counters = cp_resolve_symbol(ctx, "callbackcounter", "cbc_counters", &status)) != NULL && status == CP_OK); check(counters->create == 1); check(counters->start == 1); check(counters->logger == 0); check(counters->listener == 1); check(counters->run == 0); check(counters->stop == 0); check(counters->destroy == 0); check(counters->context_arg_0 != NULL && strcmp(counters->context_arg_0, argv[0]) == 0); // Cause warning check(cp_start_plugin(ctx, "nonexisting") == CP_ERR_UNKNOWN); check(counters->create == 1); check(counters->start == 1); check(counters->logger == 1); check(counters->listener == 1); check(counters->run == 0); check(counters->stop == 0); check(counters->destroy == 0); // Run run function once check(cp_run_plugins_step(ctx)); check(counters->create == 1); check(counters->start == 1); check(counters->logger == 1); check(counters->listener == 1); check(counters->run == 1); check(counters->stop == 0); check(counters->destroy == 0); // Run run function until no more work to be done (run = 3) cp_run_plugins(ctx); check(counters->create == 1); check(counters->start == 1); check(counters->logger == 1); check(counters->listener == 1); check(counters->run == 3); check(counters->stop == 0); check(counters->destroy == 0); /* * Normally symbols must not be accessed after they have been released. * We still access counters here because we know that the plug-in * implementation does not free the counter data. */ cp_release_symbol(ctx, counters); // Stop plug-in check(cp_stop_plugin(ctx, "callbackcounter") == CP_OK); check(counters->create == 1); check(counters->start == 1); check(counters->logger == 1); check(counters->listener == 2); check(counters->run == 3); check(counters->stop == 1); // for now 1 but might be 0 in future (delay destroy) check(counters->destroy == 0 || counters->destroy == 1); // Uninstall plugin check(cp_uninstall_plugin(ctx, "callbackcounter") == CP_OK); check(counters->create == 1); check(counters->start == 1); check(counters->logger == 1); check(counters->listener == 2); check(counters->run == 3); check(counters->stop == 1); check(counters->destroy == 1); cp_destroy(); check(errors == 0); /* Free the counter data that was intentionally leaked by the plug-in */ free(counters); }