FOSSology  4.4.0
Open Source License Compliance by Open Source Software
testScheduler.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 <utils.h>
17 
22 {
23  return Prepare_Testing_Data(scheduler);
24 }
25 
26 
27 /* ************************************************************************** */
28 /* **** scheduler function tests ******************************************** */
29 /* ************************************************************************** */
30 
38 {
39  scheduler_t* scheduler;
40 
41  scheduler = scheduler_init(testdb, NULL);
42 
43  FO_ASSERT_PTR_NULL(scheduler->db_conn);
44  database_init(scheduler);
45  FO_ASSERT_PTR_NOT_NULL(scheduler->db_conn);
46 
48  scheduler_signal(scheduler);
49 
50  scheduler_destroy(scheduler);
51 }
52 
60 {
61  int res = 0;
62  char* str = "a";
63  char* str1 = "1";
64 
65  res = string_is_num(str);
66  FO_ASSERT_EQUAL(res, 0);
67 
68  res = string_is_num(str1);
69  FO_ASSERT_EQUAL(res, 1);
70 }
71 
80 {
81  scheduler_t* scheduler;
82  int res = 0;
83 
84  scheduler = scheduler_init(testdb, NULL);
85 
86  FO_ASSERT_PTR_NULL(scheduler->db_conn);
87  database_init(scheduler);
88  FO_ASSERT_PTR_NOT_NULL(scheduler->db_conn);
89 
90  res = scheduler_daemonize(scheduler);
91  FO_ASSERT_EQUAL(res, 0);
92 
93  res = kill_scheduler(1);
94  FO_ASSERT_EQUAL(res, -1);
95 
96  scheduler_destroy(scheduler);
97 }
98 
107 {
108  scheduler_t* scheduler;
109 
110  scheduler = scheduler_init(testdb, NULL);
111 
112  FO_ASSERT_PTR_NULL(scheduler->db_conn);
113  database_init(scheduler);
114  FO_ASSERT_PTR_NOT_NULL(scheduler->db_conn);
115 
116  scheduler_clear_config(scheduler);
117  FO_ASSERT_PTR_NULL(scheduler->db_conn);
118  FO_ASSERT_PTR_NULL(scheduler->host_queue);
119  FO_ASSERT_PTR_NULL(scheduler->host_url);
120  FO_ASSERT_PTR_NULL(scheduler->email_subject);
121  FO_ASSERT_PTR_NULL(scheduler->sysconfig);
122 
123  scheduler_destroy(scheduler);
124 }
125 /*
126 void test_database_update_job()
127 {
128  scheduler_t* scheduler;
129  job_t* job;
130  arg_int* params;
131  int jq_pk;
132  job_t tmp_job;
133 
134  scheduler = scheduler_init(testdb, NULL);
135 
136  FO_ASSERT_PTR_NULL(scheduler->db_conn);
137  database_init(scheduler);
138  FO_ASSERT_PTR_NOT_NULL(scheduler->db_conn);
139 
140  jq_pk = Prepare_Testing_Data(scheduler);
141 
142  params = g_new0(arg_int, 1);
143  params->second = jq_pk;
144  params->first = g_tree_lookup(scheduler->job_list, &params->second);
145  job = params->first;
146  if(params->first == NULL)
147  {
148  tmp_job.id = params->second;
149  tmp_job.status = JB_NOT_AVAILABLE;
150  tmp_job.running_agents = NULL;
151  tmp_job.message = NULL;
152 
153  job = &tmp_job;
154  }
155 
156  FO_ASSERT_STRING_EQUAL(job_status_strings[job->status], "JOB_NOT_AVAILABLE");
157  database_update_job(scheduler, job, JB_PAUSED);
158  //job = g_tree_lookup(scheduler->job_list, &params->second);
159  FO_ASSERT_STRING_EQUAL(job_status_strings[job->status], "JOB_NOT_AVAILABLE");
160 
161  g_free(params);
162  scheduler_destroy(scheduler);
163 }
164 
165 void test_database_job()
166 {
167  scheduler_t* scheduler;
168  job_t* job;
169  arg_int* params;
170  int jq_pk;
171  job_t tmp_job;
172 
173  scheduler = scheduler_init(testdb, NULL);
174 
175  FO_ASSERT_PTR_NULL(scheduler->db_conn);
176  database_init(scheduler);
177  FO_ASSERT_PTR_NOT_NULL(scheduler->db_conn);
178 
179  jq_pk = Prepare_Testing_Data(scheduler);
180 
181  params = g_new0(arg_int, 1);
182  params->second = jq_pk;
183  params->first = g_tree_lookup(scheduler->job_list, &params->second);
184  job = params->first;
185  if(params->first == NULL)
186  {
187  tmp_job.id = params->second;
188  tmp_job.status = JB_NOT_AVAILABLE;
189  tmp_job.running_agents = NULL;
190  tmp_job.message = NULL;
191 
192  job = &tmp_job;
193  }
194 
195  FO_ASSERT_STRING_EQUAL(job_status_strings[job->status], "JOB_NOT_AVAILABLE");
196 
197  printf("jq: %d\n", jq_pk);
198  database_job_processed(jq_pk, 2);
199  database_job_log(jq_pk, "test log");
200  database_job_priority(scheduler, job, 1);
201 
202  g_free(params);
203  scheduler_destroy(scheduler);
204 }
205 
206 void test_email_notify()
207 {
208  scheduler_t* scheduler;
209  job_t* job;
210  int jq_pk;
211 
212  scheduler = scheduler_init(testdb, NULL);
213 
214  FO_ASSERT_PTR_NULL(scheduler->db_conn);
215  database_init(scheduler);
216  email_init(scheduler);
217  FO_ASSERT_PTR_NOT_NULL(scheduler->db_conn);
218 
219  jq_pk = Prepare_Testing_Data(scheduler);
220  job = job_init(scheduler->job_list, scheduler->job_queue, "ununpack", "localhost", -1, 0, 0, 0, NULL);
221  job->id = jq_pk;
222 
223  database_update_job(scheduler, job, JB_FAILED);
224  FO_ASSERT_STRING_EQUAL(job_status_strings[job->status], "JOB_CHECKEDOUT");
225 
226  scheduler_destroy(scheduler);
227 }
228 */
229 /* ************************************************************************** */
230 /* **** suite declaration *************************************************** */
231 /* ************************************************************************** */
232 
233 CU_TestInfo tests_scheduler[] =
234 {
235  {"Test scheduler_sig_handle", test_scheduler_sig_handle },
236  {"Test string is number", test_string_is_num },
237 //TODO not working {"Test scheduler_daemonize", test_scheduler_daemonize },
238  {"Test scheduler_clear_config", test_scheduler_clear_config },
239  CU_TEST_INFO_NULL
240 };
241 
242 
243 
244 
void database_init(scheduler_t *scheduler)
Definition: database.c:770
int scheduler_daemonize(scheduler_t *scheduler)
Daemonizes the scheduler.
Definition: scheduler.c:973
gint string_is_num(gchar *str)
Checks if a string is entirely composed of numeric characters.
Definition: scheduler.c:1041
void scheduler_sig_handle(int signo)
Handles any signals sent to the scheduler that are not SIGCHLD.
Definition: scheduler.c:93
void scheduler_clear_config(scheduler_t *scheduler)
Clears any information that is loaded when loading the configuration.
Definition: scheduler.c:671
scheduler_t * scheduler_init(gchar *sysconfigdir, log_t *log)
Create a new scheduler object.
Definition: scheduler.c:249
int kill_scheduler(int force)
Kills all other running scheduler.
Definition: scheduler.c:620
void scheduler_destroy(scheduler_t *scheduler)
Free any memory associated with a scheduler_t.
Definition: scheduler.c:362
void scheduler_signal(scheduler_t *scheduler)
Function that handles certain signals being delivered to the scheduler.
Definition: scheduler.c:142
int Prepare_Testing_Data(scheduler_t *scheduler)
Definition: utils.c:23
PGconn * db_conn
The database connection.
Definition: scheduler.h:176
GList * host_queue
Round-robin queue for choosing which host use next.
Definition: scheduler.h:161
gchar * email_subject
The subject to be used for emails.
Definition: scheduler.h:178
gchar * host_url
The url that is used to get to the FOSSology instance.
Definition: scheduler.h:177
fo_conf * sysconfig
Configuration information loaded from the configuration file.
Definition: scheduler.h:149
int Prepare_Testing_Data_Scheduler(scheduler_t *scheduler)
Definition: testScheduler.c:21
void test_scheduler_sig_handle()
Test for scheduler_sig_handle()
Definition: testScheduler.c:37
void test_scheduler_daemonize()
Test for scheduler_daemonize()
Definition: testScheduler.c:79
void test_scheduler_clear_config()
Test for scheduler_clear_config()
void test_string_is_num()
Test for string_is_num()
Definition: testScheduler.c:59