- add implement job related objs based on librtti

- add lock()/unlock() to job object
This commit is contained in:
Rongsong Shen 2026-02-23 11:18:36 +08:00
parent f582742e77
commit 532c68e6e1
13 changed files with 1136 additions and 12 deletions

View file

@ -24,6 +24,7 @@ extern void test_xvec(void);
extern void test_resreq(void);
extern void test_bitset(void);
extern void test_kv(void);
extern void test_jobobj(void);
void setUp(void) { return; }
@ -117,6 +118,7 @@ int main(int argc, char* argv[])
TEST(test_resreq);
TEST(test_bitset);
TEST(test_kv);
TEST(test_jobobj);
return UNITY_END();
}

View file

@ -0,0 +1,290 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unity/unity.h>
#include "jobj.h"
#include "utils.h"
#include "xstring.h"
static void test_startinfo_create()
{
int rc;
job_startinfo_t s1 = { .exechome = "/homes/rshen",
.execcwd = "/tmp",
.execuser = "rshen",
.cmdline = "sleep 3000",
.exdata = "Hello",
.q_pre_exec = "sleep 1",
.q_post_exec = "sleep 10",
.job_pre_exec = "pwd",
.job_post_exec = "hello" };
job_startinfo_t* s2 = NULL;
rc = xstring_table_init(32);
TEST_ASSERT_TRUE(rc >= 0);
rc = job_obj_init(31, 31);
TEST_ASSERT_TRUE(rc >= 0);
s2 = makeJobstartinfo(&s1);
TEST_ASSERT_TRUE(s2 != NULL);
TEST_ASSERT_TRUE(EQUAL_STRING(s1.exechome, s2->exechome)
&& EQUAL_STRING(s1.execcwd, s2->execcwd)
&& EQUAL_STRING(s1.execuser, s2->execuser)
&& EQUAL_STRING(s1.cmdline, s2->cmdline)
&& EQUAL_STRING(s1.exdata, s2->exdata)
&& EQUAL_STRING(s1.q_pre_exec, s2->q_pre_exec)
&& EQUAL_STRING(s1.q_post_exec, s2->q_post_exec)
&& EQUAL_STRING(s1.job_pre_exec, s2->job_pre_exec)
&& EQUAL_STRING(s1.job_post_exec, s2->job_post_exec));
job_obj_fini();
xstring_table_fini();
}
static void test_startinfo_share()
{
int rc;
job_startinfo_t s1 = { .exechome = "/homes/rshen",
.execcwd = "/tmp",
.execuser = "rshen",
.cmdline = "sleep 3000",
.exdata = "Hello",
.q_pre_exec = "sleep 1",
.q_post_exec = "sleep 10",
.job_pre_exec = "pwd",
.job_post_exec = "hello" };
job_startinfo_t* s2 = NULL;
job_startinfo_t* s3 = NULL;
rc = xstring_table_init(32);
TEST_ASSERT_TRUE(rc >= 0);
rc = job_obj_init(31, 31);
TEST_ASSERT_TRUE(rc >= 0);
s2 = makeJobstartinfo(&s1);
TEST_ASSERT_TRUE(s2 != NULL);
TEST_ASSERT_TRUE(EQUAL_STRING(s1.exechome, s2->exechome)
&& EQUAL_STRING(s1.execcwd, s2->execcwd)
&& EQUAL_STRING(s1.execuser, s2->execuser)
&& EQUAL_STRING(s1.cmdline, s2->cmdline)
&& EQUAL_STRING(s1.exdata, s2->exdata)
&& EQUAL_STRING(s1.q_pre_exec, s2->q_pre_exec)
&& EQUAL_STRING(s1.q_post_exec, s2->q_post_exec)
&& EQUAL_STRING(s1.job_pre_exec, s2->job_pre_exec)
&& EQUAL_STRING(s1.job_post_exec, s2->job_post_exec));
s3 = makeJobstartinfo(&s1);
TEST_ASSERT_TRUE(s2 == s3);
job_obj_fini();
xstring_table_fini();
}
static void test_jobsub_create(void)
{
int rc;
job_startinfo_t s1 = { .exechome = "/homes/rshen",
.execcwd = "/tmp",
.execuser = "rshen",
.cmdline = "sleep 3000",
.exdata = "Hello",
.q_pre_exec = "sleep 1",
.q_post_exec = "sleep 10",
.job_pre_exec = "pwd",
.job_post_exec = "hello" };
job_submit_data_t jobsub1 = { .queue = "xce",
.user = "rshen",
.mintasks = 1,
.maxtasks = 5,
.start_info = &s1,
.job_name = "J1",
.project_name = "default",
.user_group = NULL,
.job_description = "no description",
.resreq = "type == any" };
job_submit_data_t* s2 = NULL;
rc = xstring_table_init(32);
TEST_ASSERT_TRUE(rc >= 0);
rc = job_obj_init(31, 31);
TEST_ASSERT_TRUE(rc >= 0);
s2 = makeJobsub(&jobsub1);
TEST_ASSERT_TRUE(s2 != NULL);
TEST_ASSERT_TRUE(
EQUAL_STRING(s1.exechome, s2->start_info->exechome)
&& EQUAL_STRING(s1.execcwd, s2->start_info->execcwd)
&& EQUAL_STRING(s1.execuser, s2->start_info->execuser)
&& EQUAL_STRING(s1.cmdline, s2->start_info->cmdline)
&& EQUAL_STRING(s1.exdata, s2->start_info->exdata)
&& EQUAL_STRING(s1.q_pre_exec, s2->start_info->q_pre_exec)
&& EQUAL_STRING(s1.q_post_exec, s2->start_info->q_post_exec)
&& EQUAL_STRING(s1.job_pre_exec, s2->start_info->job_pre_exec)
&& EQUAL_STRING(s1.job_post_exec, s2->start_info->job_post_exec)
&& EQUAL_STRING(s2->queue, "xce") && EQUAL_STRING(s2->user, "rshen")
&& EQUAL_STRING(s2->job_name, "J1")
&& EQUAL_STRING(s2->project_name, "default")
&& EQUAL_STRING(s2->job_description, "no description")
&& EQUAL_STRING(s2->resreq, "type == any") && (s2->mintasks == 1)
&& (s2->maxtasks == 5) && (s2->user_group == NULL));
job_obj_fini();
xstring_table_fini();
}
static void test_jobsub_share(void)
{
int rc;
job_startinfo_t s1 = { .exechome = "/homes/rshen",
.execcwd = "/tmp",
.execuser = "rshen",
.cmdline = "sleep 3000",
.exdata = "Hello",
.q_pre_exec = "sleep 1",
.q_post_exec = "sleep 10",
.job_pre_exec = "pwd",
.job_post_exec = "hello" };
job_submit_data_t jobsub1 = { .queue = "xce",
.user = "rshen",
.mintasks = 1,
.maxtasks = 5,
.start_info = &s1,
.job_name = "J1",
.project_name = "default",
.user_group = NULL,
.job_description = "no description",
.resreq = "type == any" };
job_submit_data_t* s2 = NULL;
job_submit_data_t* s3 = NULL;
rc = xstring_table_init(32);
TEST_ASSERT_TRUE(rc >= 0);
rc = job_obj_init(31, 31);
TEST_ASSERT_TRUE(rc >= 0);
s2 = makeJobsub(&jobsub1);
TEST_ASSERT_TRUE(s2 != NULL);
TEST_ASSERT_TRUE(
EQUAL_STRING(s1.exechome, s2->start_info->exechome)
&& EQUAL_STRING(s1.execcwd, s2->start_info->execcwd)
&& EQUAL_STRING(s1.execuser, s2->start_info->execuser)
&& EQUAL_STRING(s1.cmdline, s2->start_info->cmdline)
&& EQUAL_STRING(s1.exdata, s2->start_info->exdata)
&& EQUAL_STRING(s1.q_pre_exec, s2->start_info->q_pre_exec)
&& EQUAL_STRING(s1.q_post_exec, s2->start_info->q_post_exec)
&& EQUAL_STRING(s1.job_pre_exec, s2->start_info->job_pre_exec)
&& EQUAL_STRING(s1.job_post_exec, s2->start_info->job_post_exec)
&& EQUAL_STRING(s2->queue, "xce") && EQUAL_STRING(s2->user, "rshen")
&& EQUAL_STRING(s2->job_name, "J1")
&& EQUAL_STRING(s2->project_name, "default")
&& EQUAL_STRING(s2->job_description, "no description")
&& EQUAL_STRING(s2->resreq, "type == any") && (s2->mintasks == 1)
&& (s2->maxtasks == 5) && (s2->user_group == NULL));
s3 = makeJobsub(&jobsub1);
TEST_ASSERT_TRUE(s2 == s3);
job_obj_fini();
xstring_table_fini();
}
static void test_job_create(void)
{
int rc;
job_startinfo_t s1 = { .exechome = "/homes/rshen",
.execcwd = "/tmp",
.execuser = "rshen",
.cmdline = "sleep 3000",
.exdata = "Hello",
.q_pre_exec = "sleep 1",
.q_post_exec = "sleep 10",
.job_pre_exec = "pwd",
.job_post_exec = "hello" };
job_submit_data_t jobsub1 = { .queue = "xce",
.user = "rshen",
.mintasks = 1,
.maxtasks = 5,
.start_info = &s1,
.job_name = "J1",
.project_name = "default",
.user_group = NULL,
.job_description = "no description",
.resreq = "type == any" };
xce_job_t job1 = { .submit = &jobsub1 };
xce_job_t* j2 = NULL;
time_t now = time(NULL);
rc = xstring_table_init(32);
TEST_ASSERT_TRUE(rc >= 0);
rc = job_obj_init(31, 31);
TEST_ASSERT_TRUE(rc >= 0);
job1.sub_time = now;
job1.queue_time = now;
job1.start_time = 0;
job1.finish_time = 0;
job1.pidinfo = NULL;
job1.state = JOB_STAT_PEND;
job1.allocs = NULL;
job1.run_time = 0;
job1.run_usage = NULL;
job1.exit_info = NULL;
job1.ckptinfo = NULL;
job1.pending_ctrl = 0;
job1.jobid = 100;
j2 = makeJob(&job1);
TEST_ASSERT_TRUE(j2 != NULL);
TEST_ASSERT_TRUE(
EQUAL_STRING(s1.exechome, j2->submit->start_info->exechome)
&& EQUAL_STRING(s1.execcwd, j2->submit->start_info->execcwd)
&& EQUAL_STRING(s1.execuser, j2->submit->start_info->execuser)
&& EQUAL_STRING(s1.cmdline, j2->submit->start_info->cmdline)
&& EQUAL_STRING(s1.exdata, j2->submit->start_info->exdata)
&& EQUAL_STRING(s1.q_pre_exec, j2->submit->start_info->q_pre_exec)
&& EQUAL_STRING(s1.q_post_exec, j2->submit->start_info->q_post_exec)
&& EQUAL_STRING(s1.job_pre_exec, j2->submit->start_info->job_pre_exec)
&& EQUAL_STRING(s1.job_post_exec, j2->submit->start_info->job_post_exec)
&& EQUAL_STRING(j2->submit->queue, "xce")
&& EQUAL_STRING(j2->submit->user, "rshen")
&& EQUAL_STRING(j2->submit->job_name, "J1")
&& EQUAL_STRING(j2->submit->project_name, "default")
&& EQUAL_STRING(j2->submit->job_description, "no description")
&& EQUAL_STRING(j2->submit->resreq, "type == any")
&& (j2->submit->mintasks == 1) && (j2->submit->maxtasks == 5)
&& (j2->submit->user_group == NULL));
destroy(j2);
job_obj_fini();
xstring_table_fini();
}
void test_jobobj(void)
{
printf("\n>> job obj test\n\n");
RUN_TEST(test_startinfo_create);
RUN_TEST(test_startinfo_share);
RUN_TEST(test_jobsub_create);
RUN_TEST(test_jobsub_share);
RUN_TEST(test_job_create);
}