Skip to content

Commit 103cf5b

Browse files
committed
match tests
1 parent ffc4ea7 commit 103cf5b

File tree

3 files changed

+1231
-25
lines changed

3 files changed

+1231
-25
lines changed

src/modules/job-list/Makefile.am

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ libjob_list_la_SOURCES = \
3434
match.c
3535

3636
TESTS = \
37-
test_job_data.t
37+
test_job_data.t \
38+
test_match.t
3839

3940
test_ldadd = \
4041
$(builddir)/libjob-list.la \
@@ -67,6 +68,14 @@ test_job_data_t_LDADD = \
6768
test_job_data_t_LDFLAGS = \
6869
$(test_ldflags)
6970

71+
test_match_t_SOURCES = test/match.c
72+
test_match_t_CPPFLAGS = \
73+
$(test_cppflags)
74+
test_match_t_LDADD = \
75+
$(test_ldadd)
76+
test_match_t_LDFLAGS = \
77+
$(test_ldflags)
78+
7079
EXTRA_DIST = \
7180
test/R/1node_1core.R \
7281
test/R/1node_4core.R \

src/modules/job-list/match.c

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ static struct list_constraint *list_constraint_new (flux_error_t *errp)
4848
return c;
4949
}
5050

51-
bool list_constraint_match (struct list_constraint *c, const struct job *job)
52-
{
53-
return c->match (c, job);
54-
}
55-
5651
static void list_constraint_destructor (void **item)
5752
{
5853
if (item) {
@@ -186,32 +181,42 @@ static struct list_constraint *create_string_constraint (const char *op,
186181
flux_error_t *errp)
187182
{
188183
struct list_constraint *c;
189-
json_t *v = json_array_get (values, 0);
190-
char *s = NULL;
191-
if (!v || !json_is_string (v)) {
192-
errprintf (errp, "%s value must be a string", op);
193-
return NULL;
194-
}
195-
if (!(s = strdup (json_string_value (v))))
196-
return NULL;
197-
if (!(c = list_constraint_new (errp))
198-
|| !zlistx_add_end (c->values, s)) {
199-
list_constraint_destroy (c);
200-
free (s);
184+
json_t *entry;
185+
size_t index;
186+
187+
if (!(c = list_constraint_new (errp)))
201188
return NULL;
189+
json_array_foreach (values, index, entry) {
190+
char *s = NULL;
191+
if (!json_is_string (entry)) {
192+
errprintf (errp, "%s value must be a string", op);
193+
goto error;
194+
}
195+
if (!(s = strdup (json_string_value (entry))))
196+
return NULL;
197+
if (!zlistx_add_end (c->values, s)) {
198+
free (s);
199+
goto error;
200+
}
202201
}
203202
zlistx_set_destructor (c->values, wrap_free);
204203
c->match = match_cb;
205204
return c;
205+
error:
206+
list_constraint_destroy (c);
207+
return NULL;
206208
}
207209

208210
static bool match_name (struct list_constraint *c,
209211
const struct job *job)
210212
{
211213
const char *name = zlistx_first (c->values);
212-
if (!job->name)
213-
return false;
214-
return streq (name, job->name);
214+
while (name) {
215+
if (job->name && streq (name, job->name))
216+
return true;
217+
name = zlistx_next (c->values);
218+
}
219+
return false;
215220
}
216221

217222
static struct list_constraint *create_name_constraint (json_t *values,
@@ -224,9 +229,12 @@ static bool match_queue (struct list_constraint *c,
224229
const struct job *job)
225230
{
226231
const char *queue = zlistx_first (c->values);
227-
if (!job->queue)
228-
return false;
229-
return streq (queue, job->queue);
232+
while (queue) {
233+
if (job->queue && streq (queue, job->queue))
234+
return true;
235+
queue = zlistx_next (c->values);
236+
}
237+
return false;
230238
}
231239

232240
static struct list_constraint *create_queue_constraint (json_t *values,
@@ -274,7 +282,8 @@ static int array_to_states_bitmask (json_t *values,
274282
int states = 0;
275283
json_t *entry;
276284
size_t index;
277-
int valid_states = (FLUX_JOB_STATE_PENDING
285+
int valid_states = (FLUX_JOB_STATE_NEW
286+
| FLUX_JOB_STATE_PENDING
278287
| FLUX_JOB_STATE_RUNNING
279288
| FLUX_JOB_STATE_INACTIVE);
280289

0 commit comments

Comments
 (0)