static void test_utils_expand_path(void) { char *result; int i; /* Test valid cases */ for (i = 0; i < num_valid_tests; i++) { char name[100]; sprintf(name, "valid test case: %s", valid_tests_inputs[i].input); result = utils_expand_path(valid_tests_inputs[i].input); ok(strcmp(result, valid_tests_expected_results[i]) == 0, name); free(result); } /* Test invalid cases */ for (i = 0; i < num_invalid_tests; i++) { char name[100]; sprintf(name, "invalid test case: %s", invalid_tests_inputs[i]); result = utils_expand_path(invalid_tests_inputs[i]); if (result != NULL) { free(result); } ok(result == NULL, name); } }
static void test_utils_expand_path(void) { char *result; char name[100], tmppath[PATH_MAX]; int i; /* Test valid cases */ for (i = 0; i < num_valid_tests; i++) { sprintf(name, "valid test case: %s", valid_tests_inputs[i].input); result = utils_expand_path(valid_tests_inputs[i].input); ok(result != NULL && strcmp(result, valid_tests_expected_results[i]) == 0, name); free(result); } /* Test symlink tree cases */ int treelen = strlen(tree_origin) + 1; for (i = 0; i < num_symlink_tests; i++) { sprintf(name, "symlink tree test case: [tmppath/]%s", symlink_tests_inputs[i].input); snprintf(tmppath, PATH_MAX, "%s/%s", tree_origin, symlink_tests_inputs[i].input); result = utils_expand_path(tmppath); ok(result != NULL && strcmp(result + treelen, symlink_tests_inputs[i].expected_result) == 0, name); free(result); } /* Test invalid cases */ for (i = 0; i < num_invalid_tests; i++) { sprintf(name, "invalid test case: %s", invalid_tests_inputs[i]); result = utils_expand_path(invalid_tests_inputs[i]); if (result != NULL) { free(result); } ok(result == NULL, name); } }
int main(int argc, char **argv) { char *path = NULL; int ret; struct state state = {}; if (argc < 2) { diag("Usage: path_to_sample_INI_file"); goto end; } path = utils_expand_path(argv[1]); if (!path) { fail("Failed to resolve sample INI file path") } plan_no_plan(); ret = config_get_section_entries(path, NULL, (config_entry_handler_cb)entry_handler, &state); ok(ret == 0, "Successfully opened a config file, registered to all sections"); ok(state.section_1 && state.section_2 && state.section_3 && state.section_global, "Processed entries from each sections"); ok(state.text_entry, "Text value parsed correctly"); memset(&state, 0, sizeof(struct state)); ret = config_get_section_entries(path, "section1", (config_entry_handler_cb)entry_handler, &state); ok(ret == 0, "Successfully opened a config file, registered to one section"); ok(state.section_1 && !state.section_2 && !state.section_3 && !state.section_global, "Processed an entry from section1 only"); ok(state.int_entry, "Int value parsed correctly"); memset(&state, 0, sizeof(struct state)); ret = config_get_section_entries(path, "", (config_entry_handler_cb)entry_handler, &state); ok(ret == 0, "Successfully opened a config file, registered to the global section"); ok(!state.section_1 && !state.section_2 && !state.section_3 && state.section_global, "Processed an entry from the global section only"); end: free(path); return exit_status(); }
static struct lttng_session_descriptor *create_session_descriptor(void) { int ret; ssize_t uri_count; enum output_type output_type; struct lttng_uri *uris = NULL; struct lttng_session_descriptor *descriptor = NULL; const char *uri_str1 = NULL, *uri_str2 = NULL; char local_output_path[LTTNG_PATH_MAX] = {}; if (opt_no_output) { output_type = OUTPUT_NONE; } else if (opt_output_path) { char *expanded_output_path; output_type = OUTPUT_LOCAL; expanded_output_path = utils_expand_path(opt_output_path); if (!expanded_output_path) { ERR("Failed to expand output path."); goto end; } ret = lttng_strncpy(local_output_path, expanded_output_path, sizeof(local_output_path)); free(expanded_output_path); if (ret) { ERR("Output path exceeds the maximal supported length (%zu bytes)", sizeof(local_output_path)); goto end; } } else if (opt_url || opt_ctrl_url) { uri_str1 = opt_ctrl_url ? opt_ctrl_url : opt_url; uri_str2 = opt_data_url; uri_count = uri_parse_str_urls(uri_str1, uri_str2, &uris); if (uri_count != 1 && uri_count != 2) { ERR("Unrecognized URL format."); goto end; } switch (uri_count) { case 1: output_type = OUTPUT_LOCAL; if (uris[0].dtype != LTTNG_DST_PATH) { ERR("Unrecognized URL format."); goto end; } ret = lttng_strncpy(local_output_path, uris[0].dst.path, sizeof(local_output_path)); if (ret) { ERR("Output path exceeds the maximal supported length (%zu bytes)", sizeof(local_output_path)); } break; case 2: output_type = OUTPUT_NETWORK; break; default: /* Already checked. */ abort(); } } else { output_type = OUTPUT_UNSPECIFIED; } if (opt_snapshot) { /* Snapshot session. */ switch (output_type) { case OUTPUT_UNSPECIFIED: case OUTPUT_LOCAL: descriptor = lttng_session_descriptor_snapshot_local_create( opt_session_name, output_type == OUTPUT_LOCAL ? local_output_path : NULL); break; case OUTPUT_NONE: descriptor = lttng_session_descriptor_snapshot_create( opt_session_name); break; case OUTPUT_NETWORK: descriptor = lttng_session_descriptor_snapshot_network_create( opt_session_name, uri_str1, uri_str2); break; default: abort(); } } else if (opt_live_timer) { /* Live session. */ if (output_type != OUTPUT_UNSPECIFIED && output_type != OUTPUT_NETWORK) { ERR("Unsupported output type specified for live session."); goto end; } descriptor = lttng_session_descriptor_live_network_create( opt_session_name, uri_str1, uri_str2, opt_live_timer); } else { /* Regular session. */ switch (output_type) { case OUTPUT_UNSPECIFIED: case OUTPUT_LOCAL: descriptor = lttng_session_descriptor_local_create( opt_session_name, output_type == OUTPUT_LOCAL ? local_output_path : NULL); break; case OUTPUT_NONE: descriptor = lttng_session_descriptor_create( opt_session_name); break; case OUTPUT_NETWORK: descriptor = lttng_session_descriptor_network_create( opt_session_name, uri_str1, uri_str2); break; default: abort(); } } if (!descriptor) { ERR("Failed to initialize session creation command."); } else { /* * Auto-launch the relay daemon when a live session * is created using default URLs. */ if (!opt_url && !opt_ctrl_url && !opt_data_url && opt_live_timer && !check_relayd()) { int ret; const char *pathname = opt_relayd_path ? : INSTALL_BIN_PATH "/lttng-relayd"; ret = spawn_relayd(pathname, 0); if (ret < 0) { lttng_session_descriptor_destroy(descriptor); descriptor = NULL; } } }