FOSSology  4.4.0
Open Source License Compliance by Open Source Software
testJob.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2013 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
11 /* include functions to test */
12 #include <testRun.h>
13 
14 /* scheduler includes */
15 #include <scheduler.h>
16 #include <job.h>
17 
18 #include <utils.h>
19 
24  return Prepare_Testing_Data(scheduler);
25 }
26 
27 /* ************************************************************************** */
28 /* ********** job function tests ******************************************** */
29 /* ************************************************************************** */
30 
44 {
45  scheduler_t* scheduler;
46  job_t* job;
47  arg_int* params;
48  int jq_pk;
49 
50  scheduler = scheduler_init(testdb, NULL);
51 
52  FO_ASSERT_PTR_NULL(scheduler->db_conn);
53  database_init(scheduler);
54  FO_ASSERT_PTR_NOT_NULL_FATAL(scheduler->db_conn);
55 
56  jq_pk = Prepare_Testing_Data_Job(scheduler);
57 
58  database_update_event(scheduler, NULL);
59 
60  job = g_tree_lookup(scheduler->job_list, &jq_pk);
61  FO_ASSERT_PTR_NOT_NULL_FATAL(job);
62  job_verbose_event(scheduler, job);
63  FO_ASSERT_EQUAL(job->id, jq_pk);
64 
65  params = g_new0(arg_int, 1);
66  params->first = job;
67  params->second = jq_pk;
68  job_pause_event(scheduler, params);
69  FO_ASSERT_EQUAL(job->status, JB_PAUSED);
70 
71  params = g_new0(arg_int, 1);
72  params->first = job;
73  params->second = jq_pk;
74  job_restart_event(scheduler, params);
75  FO_ASSERT_EQUAL(job->status, JB_RESTART);
76 
77  params = g_new0(arg_int, 1);
78  params->first = job;
79  params->second = 1;
80  job_priority_event(scheduler, params);
81  FO_ASSERT_EQUAL(job->status, JB_RESTART);
82 
83  job_fail_event(scheduler, job);
84  FO_ASSERT_EQUAL(job->status, JB_FAILED);
85 
86  scheduler_update(scheduler);
87 
88  scheduler_destroy(scheduler);
89 }
90 
103 {
104  scheduler_t* scheduler;
105  job_t* job;
106  char* res = NULL;
107  uint32_t result = 0;
108  int jq_pk;
109 
110  scheduler = scheduler_init(testdb, NULL);
111  FO_ASSERT_PTR_NULL(scheduler->db_conn);
112  database_init(scheduler);
113  FO_ASSERT_PTR_NOT_NULL(scheduler->db_conn);
114 
115  jq_pk = Prepare_Testing_Data_Job(scheduler);
116 
117  database_update_event(scheduler, NULL);
118 
119  job = g_tree_lookup(scheduler->job_list, &jq_pk);
120  FO_ASSERT_PTR_NOT_NULL_FATAL(job);
121 
122  res = job_next(job);
123  FO_ASSERT_STRING_EQUAL(res, "6");
124  job = next_job(scheduler->job_queue);
125  FO_ASSERT_PTR_NOT_NULL_FATAL(job);
126  FO_ASSERT_EQUAL(job->id, 1);
127  job = peek_job(scheduler->job_queue);
128  FO_ASSERT_PTR_NOT_NULL_FATAL(job);
129  FO_ASSERT_EQUAL(job->id, 1);
130  result = active_jobs(scheduler->job_list);
131  FO_ASSERT_EQUAL(result, 0);
132 
133  scheduler_destroy(scheduler);
134 }
135 
136 /* ************************************************************************** */
137 /* **** suite declaration *************************************************** */
138 /* ************************************************************************** */
139 
140 CU_TestInfo tests_job[] =
141 {
142  {"Test job_event", test_job_event },
143  {"Test job_fun", test_job_fun },
144  CU_TEST_INFO_NULL
145 };
void job_fail_event(scheduler_t *scheduler, job_t *job)
Events that causes a job to be marked a failed.
Definition: job.c:406
void job_restart_event(scheduler_t *scheduler, arg_int *params)
Definition: job.c:342
job_t * next_job(GSequence *job_queue)
Gets the next job from the job queue.
Definition: job.c:681
char * job_next(job_t *job)
Definition: job.c:610
job_t * peek_job(GSequence *job_queue)
Gets the job that is at the top of the queue if there is one.
Definition: job.c:701
void job_verbose_event(scheduler_t *scheduler, job_t *job)
Definition: job.c:244
void job_pause_event(scheduler_t *scheduler, arg_int *params)
Event to pause a job.
Definition: job.c:312
void job_priority_event(scheduler_t *scheduler, arg_int *params)
Definition: job.c:385
uint32_t active_jobs(GTree *job_list)
Gets the number of jobs that are not paused.
Definition: job.c:720
void database_init(scheduler_t *scheduler)
Definition: database.c:770
void database_update_event(scheduler_t *scheduler, void *unused)
Checks the job queue for any new entries.
Definition: database.c:841
void scheduler_update(scheduler_t *scheduler)
Update function called after every event.
Definition: scheduler.c:433
scheduler_t * scheduler_init(gchar *sysconfigdir, log_t *log)
Create a new scheduler object.
Definition: scheduler.c:249
void scheduler_destroy(scheduler_t *scheduler)
Free any memory associated with a scheduler_t.
Definition: scheduler.c:362
int Prepare_Testing_Data(scheduler_t *scheduler)
Definition: utils.c:23
Definition: event.h:46
The job structure.
Definition: job.h:51
int32_t id
The identifier for this job.
Definition: job.h:73
job_status status
The current status for the job.
Definition: job.h:61
GTree * job_list
List of jobs that have been created.
Definition: scheduler.h:172
PGconn * db_conn
The database connection.
Definition: scheduler.h:176
GSequence * job_queue
heap of jobs that still need to be started
Definition: scheduler.h:173
void test_job_fun()
Test for job functions.
Definition: testJob.c:102
void test_job_event()
Test for job events.
Definition: testJob.c:43
int Prepare_Testing_Data_Job(scheduler_t *scheduler)
Definition: testJob.c:23