| 123 | } |
| 124 | |
| 125 | static int tic_select(int argc, char **argv) { |
| 126 | const char *repo = NULL, *base = NULL, *config = NULL, *artifact = NULL; |
| 127 | const char *artifact_commit = NULL, *platform = NULL, *work = NULL, *deadline = NULL; |
| 128 | bool verified = false; |
| 129 | const tic_option_t options[] = {{"--repo", &repo, NULL}, |
| 130 | {"--base", &base, NULL}, |
| 131 | {"--config", &config, NULL}, |
| 132 | {"--artifact", &artifact, NULL}, |
| 133 | {"--artifact-commit", &artifact_commit, NULL}, |
| 134 | {"--artifact-verified", NULL, &verified}, |
| 135 | {"--platform", &platform, NULL}, |
| 136 | {"--work", &work, NULL}, |
| 137 | {"--deadline-s", &deadline, NULL}}; |
| 138 | if (!tic_parse(argc, argv, options, sizeof(options) / sizeof(options[0])) || !repo || !base) { |
| 139 | return tic_usage(); |
| 140 | } |
| 141 | int64_t seconds = tic_number(deadline, TIC_DEFAULT_DEADLINE_S); |
| 142 | char work_buf[4096]; |
| 143 | const char *work_parent = tic_work(work, work_buf, sizeof(work_buf)); |
| 144 | if (seconds < 0 || !work_parent) { |
| 145 | return tic_usage(); |
| 146 | } |
| 147 | cbm_test_impact_request_t request = {.repo_root = repo, |
| 148 | .base_ref = base, |
| 149 | .work_parent = work_parent, |
| 150 | .config_path = config, |
| 151 | .deadline_ms = cbm_now_ms() + (uint64_t)seconds * 1000ULL, |
| 152 | .artifact_dir = artifact, |
| 153 | .artifact_commit = artifact_commit, |
| 154 | .artifact_verified = verified, |
| 155 | .platform = platform}; |
| 156 | cbm_test_result_t *result = NULL; |
| 157 | char diagnostic[512] = ""; |
| 158 | cbm_test_impact_status_t status = |
| 159 | cbm_test_impact_run(&request, &result, diagnostic, sizeof(diagnostic)); |
| 160 | if (diagnostic[0]) { |
| 161 | (void)fprintf(stderr, "test-impact select: %s\n", diagnostic); |
| 162 | } |
| 163 | if (status != CBM_TEST_IMPACT_OK) { |
| 164 | (void)fprintf(stderr, "test-impact select: status %d\n", (int)status); |
| 165 | return 1; |
| 166 | } |
| 167 | size_t length = 0; |
| 168 | const char *json = cbm_test_result_json(result, &length); |
| 169 | bool ok = json && fwrite(json, 1, length, stdout) == length && fputc('\n', stdout) != EOF; |
| 170 | cbm_test_result_free(result); |
| 171 | return ok ? 0 : 1; |
| 172 | } |
| 173 | |
| 174 | int cbm_test_impact_cli(int argc, char **argv) { |
| 175 | if (argc < 1) { |
no test coverage detected