#include #include #include #include #include #include "jobj.h" #include "kvmgr.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; kvmgr_params_t jobmgr_params = { .key_type = KVMGR_KEY_INT, .nslots = 32, .delta = 32, .datakiller = destroy }; var jobmgr; 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 }; 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; jobmgr = makeInstance(&xkvmgr_type, &jobmgr_params); TEST_ASSERT_TRUE(jobmgr != NULL); j2 = makeJob(jobmgr, &job1); TEST_ASSERT_TRUE(j2 != NULL); TEST_ASSERT_TRUE( EQUAL_STRING(s1.exechome, j2->job.submit->start_info->exechome) && EQUAL_STRING(s1.execcwd, j2->job.submit->start_info->execcwd) && EQUAL_STRING(s1.execuser, j2->job.submit->start_info->execuser) && EQUAL_STRING(s1.cmdline, j2->job.submit->start_info->cmdline) && EQUAL_STRING(s1.exdata, j2->job.submit->start_info->exdata) && EQUAL_STRING(s1.q_pre_exec, j2->job.submit->start_info->q_pre_exec) && EQUAL_STRING(s1.q_post_exec, j2->job.submit->start_info->q_post_exec) && EQUAL_STRING(s1.job_pre_exec, j2->job.submit->start_info->job_pre_exec) && EQUAL_STRING(s1.job_post_exec, j2->job.submit->start_info->job_post_exec) && EQUAL_STRING(j2->job.submit->queue, "xce") && EQUAL_STRING(j2->job.submit->user, "rshen") && EQUAL_STRING(j2->job.submit->job_name, "J1") && EQUAL_STRING(j2->job.submit->project_name, "default") && EQUAL_STRING(j2->job.submit->job_description, "no description") && EQUAL_STRING(j2->job.submit->resreq, "type == any") && (j2->job.submit->mintasks == 1) && (j2->job.submit->maxtasks == 5) && (j2->job.submit->user_group == NULL)); destroy(jobmgr); 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); }