FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
testScheduler.c
Go to the documentation of this file.
1 /*********************************************************************
2 Copyright (C) 2013 Hewlett-Packard Development Company, L.P.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 2 as published by the Free Software Foundation.
7 
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 *********************************************************************/
22 /* include functions to test */
23 #include <testRun.h>
24 
25 /* scheduler includes */
26 #include <scheduler.h>
27 #include <utils.h>
28 
33 {
34  return Prepare_Testing_Data(scheduler);
35 }
36 
37 
38 /* ************************************************************************** */
39 /* **** scheduler function tests ******************************************** */
40 /* ************************************************************************** */
41 
49 {
50  scheduler_t* scheduler;
51 
52  scheduler = scheduler_init(testdb, NULL);
53 
54  FO_ASSERT_PTR_NULL(scheduler->db_conn);
55  database_init(scheduler);
56  FO_ASSERT_PTR_NOT_NULL(scheduler->db_conn);
57 
59  scheduler_signal(scheduler);
60 
61  scheduler_destroy(scheduler);
62 }
63 
71 {
72  int res = 0;
73  char* str = "a";
74  char* str1 = "1";
75 
76  res = string_is_num(str);
77  FO_ASSERT_EQUAL(res, 0);
78 
79  res = string_is_num(str1);
80  FO_ASSERT_EQUAL(res, 1);
81 }
82 
91 {
92  scheduler_t* scheduler;
93  int res = 0;
94 
95  scheduler = scheduler_init(testdb, NULL);
96 
97  FO_ASSERT_PTR_NULL(scheduler->db_conn);
98  database_init(scheduler);
99  FO_ASSERT_PTR_NOT_NULL(scheduler->db_conn);
100 
101  res = scheduler_daemonize(scheduler);
102  FO_ASSERT_EQUAL(res, 0);
103 
104  res = kill_scheduler(1);
105  FO_ASSERT_EQUAL(res, -1);
106 
107  scheduler_destroy(scheduler);
108 }
109 
118 {
119  scheduler_t* scheduler;
120 
121  scheduler = scheduler_init(testdb, NULL);
122 
123  FO_ASSERT_PTR_NULL(scheduler->db_conn);
124  database_init(scheduler);
125  FO_ASSERT_PTR_NOT_NULL(scheduler->db_conn);
126 
127  scheduler_clear_config(scheduler);
128  FO_ASSERT_PTR_NULL(scheduler->db_conn);
129  FO_ASSERT_PTR_NULL(scheduler->host_queue);
130  FO_ASSERT_PTR_NULL(scheduler->host_url);
131  FO_ASSERT_PTR_NULL(scheduler->email_subject);
132  FO_ASSERT_PTR_NULL(scheduler->sysconfig);
133 
134  scheduler_destroy(scheduler);
135 }
136 /*
137 void test_database_update_job()
138 {
139  scheduler_t* scheduler;
140  job_t* job;
141  arg_int* params;
142  int jq_pk;
143  job_t tmp_job;
144 
145  scheduler = scheduler_init(testdb, NULL);
146 
147  FO_ASSERT_PTR_NULL(scheduler->db_conn);
148  database_init(scheduler);
149  FO_ASSERT_PTR_NOT_NULL(scheduler->db_conn);
150 
151  jq_pk = Prepare_Testing_Data(scheduler);
152 
153  params = g_new0(arg_int, 1);
154  params->second = jq_pk;
155  params->first = g_tree_lookup(scheduler->job_list, &params->second);
156  job = params->first;
157  if(params->first == NULL)
158  {
159  tmp_job.id = params->second;
160  tmp_job.status = JB_NOT_AVAILABLE;
161  tmp_job.running_agents = NULL;
162  tmp_job.message = NULL;
163 
164  job = &tmp_job;
165  }
166 
167  FO_ASSERT_STRING_EQUAL(job_status_strings[job->status], "JOB_NOT_AVAILABLE");
168  database_update_job(scheduler, job, JB_PAUSED);
169  //job = g_tree_lookup(scheduler->job_list, &params->second);
170  FO_ASSERT_STRING_EQUAL(job_status_strings[job->status], "JOB_NOT_AVAILABLE");
171 
172  g_free(params);
173  scheduler_destroy(scheduler);
174 }
175 
176 void test_database_job()
177 {
178  scheduler_t* scheduler;
179  job_t* job;
180  arg_int* params;
181  int jq_pk;
182  job_t tmp_job;
183 
184  scheduler = scheduler_init(testdb, NULL);
185 
186  FO_ASSERT_PTR_NULL(scheduler->db_conn);
187  database_init(scheduler);
188  FO_ASSERT_PTR_NOT_NULL(scheduler->db_conn);
189 
190  jq_pk = Prepare_Testing_Data(scheduler);
191 
192  params = g_new0(arg_int, 1);
193  params->second = jq_pk;
194  params->first = g_tree_lookup(scheduler->job_list, &params->second);
195  job = params->first;
196  if(params->first == NULL)
197  {
198  tmp_job.id = params->second;
199  tmp_job.status = JB_NOT_AVAILABLE;
200  tmp_job.running_agents = NULL;
201  tmp_job.message = NULL;
202 
203  job = &tmp_job;
204  }
205 
206  FO_ASSERT_STRING_EQUAL(job_status_strings[job->status], "JOB_NOT_AVAILABLE");
207 
208  printf("jq: %d\n", jq_pk);
209  database_job_processed(jq_pk, 2);
210  database_job_log(jq_pk, "test log");
211  database_job_priority(scheduler, job, 1);
212 
213  g_free(params);
214  scheduler_destroy(scheduler);
215 }
216 
217 void test_email_notify()
218 {
219  scheduler_t* scheduler;
220  job_t* job;
221  int jq_pk;
222 
223  scheduler = scheduler_init(testdb, NULL);
224 
225  FO_ASSERT_PTR_NULL(scheduler->db_conn);
226  database_init(scheduler);
227  email_init(scheduler);
228  FO_ASSERT_PTR_NOT_NULL(scheduler->db_conn);
229 
230  jq_pk = Prepare_Testing_Data(scheduler);
231  job = job_init(scheduler->job_list, scheduler->job_queue, "ununpack", "localhost", -1, 0, 0, 0, NULL);
232  job->id = jq_pk;
233 
234  database_update_job(scheduler, job, JB_FAILED);
235  FO_ASSERT_STRING_EQUAL(job_status_strings[job->status], "JOB_CHECKEDOUT");
236 
237  scheduler_destroy(scheduler);
238 }
239 */
240 /* ************************************************************************** */
241 /* **** suite declaration *************************************************** */
242 /* ************************************************************************** */
243 
244 CU_TestInfo tests_scheduler[] =
245 {
246  {"Test scheduler_sig_handle", test_scheduler_sig_handle },
247  {"Test string is number", test_string_is_num },
248 //TODO not working {"Test scheduler_daemonize", test_scheduler_daemonize },
249  {"Test scheduler_clear_config", test_scheduler_clear_config },
250  CU_TEST_INFO_NULL
251 };
252 
253 
254 
255 
PGconn * db_conn
The database connection.
Definition: scheduler.h:187
int Prepare_Testing_Data(scheduler_t *scheduler)
Definition: utils.c:32
int Prepare_Testing_Data_Scheduler(scheduler_t *scheduler)
Definition: testScheduler.c:32
int scheduler_daemonize(scheduler_t *scheduler)
Daemonizes the scheduler.
Definition: scheduler.c:984
fo_conf * sysconfig
Configuration information loaded from the configuration file.
Definition: scheduler.h:160
void scheduler_destroy(scheduler_t *scheduler)
Free any memory associated with a scheduler_t.
Definition: scheduler.c:373
void database_init(scheduler_t *scheduler)
Definition: database.c:781
GList * host_queue
Round-robin queue for choosing which host use next.
Definition: scheduler.h:172
void test_scheduler_sig_handle()
Test for scheduler_sig_handle()
Definition: testScheduler.c:48
void test_scheduler_clear_config()
Test for scheduler_clear_config()
gchar * host_url
The url that is used to get to the FOSSology instance.
Definition: scheduler.h:188
int kill_scheduler(int force)
Kills all other running scheduler.
Definition: scheduler.c:631
gint string_is_num(gchar *str)
Checks if a string is entirely composed of numeric characters.
Definition: scheduler.c:1052
void scheduler_clear_config(scheduler_t *scheduler)
Clears any information that is loaded when loading the configuration.
Definition: scheduler.c:682
void scheduler_sig_handle(int signo)
Handles any signals sent to the scheduler that are not SIGCHLD.
Definition: scheduler.c:104
scheduler_t * scheduler_init(gchar *sysconfigdir, log_t *log)
Create a new scheduler object.
Definition: scheduler.c:260
void test_scheduler_daemonize()
Test for scheduler_daemonize()
Definition: testScheduler.c:90
void test_string_is_num()
Test for string_is_num()
Definition: testScheduler.c:70
void scheduler_signal(scheduler_t *scheduler)
Function that handles certain signals being delivered to the scheduler.
Definition: scheduler.c:153
gchar * email_subject
The subject to be used for emails.
Definition: scheduler.h:189