forked from lei.chen/myxce
feat(xce-test-e2e-primitives): joblist_query helper + $jobcount capture (task 5.1)
This commit is contained in:
parent
fae0bc0ff4
commit
171c88fcec
2 changed files with 65 additions and 15 deletions
|
|
@ -139,11 +139,13 @@ static int g_last_status = 0;
|
|||
*
|
||||
* g_last_jobid most recently acknowledged JobId as a string; empty ("")
|
||||
* means unset. Populated later by cmd_jobsub (task 4.1).
|
||||
* g_last_jobcount most recent job count; -1 means unset. Populated later by
|
||||
* cmd_joblist (task 5.1).
|
||||
* g_last_jobcount most recent job count; -1 means unset. Populated by
|
||||
* cmd_joblist on a successful `joblist` (task 5.1, Req 3.4);
|
||||
* a failed joblist leaves it untouched so no fake count is
|
||||
* advertised.
|
||||
*
|
||||
* Until those tasks land, both are always unset — which is exactly what makes
|
||||
* an unset `$jobid`/`$jobcount` reference fail the command (Req 3.6). */
|
||||
* Until a command sets one, it stays unset — which is exactly what makes an
|
||||
* unset `$jobid`/`$jobcount` reference fail the command (Req 3.6). */
|
||||
static char g_last_jobid[XCE_MAXNAME_LEN] = { 0 };
|
||||
static int g_last_jobcount = -1;
|
||||
|
||||
|
|
@ -877,11 +879,30 @@ static char* job_state_str(int state)
|
|||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
int cmd_joblist(int argc, char* argv[])
|
||||
/* Shared, print-free joblist core for `cmd_joblist` and the `expect-jobs` /
|
||||
* `expect-job` assertions (xce-test-e2e-primitives task 5.1, design.md:81,
|
||||
* 116-117).
|
||||
*
|
||||
* Performs the single `xcecli_joblist` call (through the failover-aware client
|
||||
* context) and returns the current job count (>= 0), or a negative errno-style
|
||||
* value on failure. When `find_jobid != NULL`, `*contains` is set to 1 if a job
|
||||
* whose `fmt_jobid(...)` string equals `find_jobid` is present, else 0; the
|
||||
* `fmt_jobid` representation matches the one `cmd_joblist` prints and the one
|
||||
* `cmd_jobsub` captures into `$jobid` (task 4.1), so `expect-job $jobid` lines
|
||||
* up. When `print_table` is set, the human-readable table is printed (the
|
||||
* `cmd_joblist` path). The job array is always freed internally.
|
||||
*
|
||||
* On error this returns the negative rc WITHOUT setting any auto-variable, so a
|
||||
* failed joblist never advertises a fake `$jobcount` (Req 3.6). */
|
||||
static int joblist_query(const char* find_jobid, int* contains, int print_table)
|
||||
{
|
||||
int rc, i;
|
||||
xce_job_t** jobs;
|
||||
|
||||
if (contains != NULL) {
|
||||
*contains = 0;
|
||||
}
|
||||
|
||||
rc = xcecli_joblist(active_ctx->ctx, &jobs);
|
||||
|
||||
if (rc < 0) {
|
||||
|
|
@ -890,21 +911,30 @@ int cmd_joblist(int argc, char* argv[])
|
|||
return rc;
|
||||
}
|
||||
|
||||
printf("%-26s%-10s%-10s%-8s%-16s%-16s%-16s%10s%30s\n", "JobId", "User",
|
||||
"Queue", "State", "SubmitTime", "StartTime", "FinishTime", "NTasks",
|
||||
"Command");
|
||||
if (print_table) {
|
||||
printf("%-26s%-10s%-10s%-8s%-16s%-16s%-16s%10s%30s\n", "JobId", "User",
|
||||
"Queue", "State", "SubmitTime", "StartTime", "FinishTime",
|
||||
"NTasks", "Command");
|
||||
}
|
||||
|
||||
for (i = 0; i < rc; i++) {
|
||||
char buf[128];
|
||||
|
||||
fmt_jobid(buf, sizeof(buf) - 1, jobs[i]->jobid);
|
||||
|
||||
printf("%-26s%-10s%-10s%-8s%-16ld%-16ld%-16ld%4d,%-5d%30s\n", buf,
|
||||
jobs[i]->submit->user, jobs[i]->submit->queue,
|
||||
job_state_str(jobs[i]->state), jobs[i]->queue_time,
|
||||
jobs[i]->start_time, jobs[i]->finish_time,
|
||||
jobs[i]->submit->mintasks, jobs[i]->submit->maxtasks,
|
||||
jobs[i]->submit->start_info->cmdline);
|
||||
if ((find_jobid != NULL) && (contains != NULL)
|
||||
&& (strcmp(buf, find_jobid) == 0)) {
|
||||
*contains = 1;
|
||||
}
|
||||
|
||||
if (print_table) {
|
||||
printf("%-26s%-10s%-10s%-8s%-16ld%-16ld%-16ld%4d,%-5d%30s\n", buf,
|
||||
jobs[i]->submit->user, jobs[i]->submit->queue,
|
||||
job_state_str(jobs[i]->state), jobs[i]->queue_time,
|
||||
jobs[i]->start_time, jobs[i]->finish_time,
|
||||
jobs[i]->submit->mintasks, jobs[i]->submit->maxtasks,
|
||||
jobs[i]->submit->start_info->cmdline);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < rc; i++) {
|
||||
|
|
@ -913,6 +943,25 @@ int cmd_joblist(int argc, char* argv[])
|
|||
|
||||
free(jobs);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int cmd_joblist(int argc, char* argv[])
|
||||
{
|
||||
int count;
|
||||
|
||||
count = joblist_query(NULL, NULL, 1);
|
||||
|
||||
if (count < 0) {
|
||||
return count;
|
||||
}
|
||||
|
||||
/* Capture $jobcount (Req 3.4): a successful joblist publishes the returned
|
||||
* job count so a later `echo $jobcount` / `expect-jobs` substitutes it. On
|
||||
* failure we returned above without touching g_last_jobcount, so a failed
|
||||
* joblist never advertises a fake count (Req 3.6). */
|
||||
g_last_jobcount = count;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue