17 #include <interface.h>
18 #include <scheduler.h>
23 #include <sys/socket.h>
24 #include <sys/types.h>
25 #include <netinet/in.h>
36 #if defined(__amd64__)
37 #define mint_t int64_t
39 #define mint_t int32_t
54 struct addrinfo hints;
55 struct addrinfo* servs, * curr;
60 memset(&hints, 0,
sizeof(hints));
61 hints.ai_family = AF_UNSPEC;
62 hints.ai_socktype = SOCK_STREAM;
63 if(getaddrinfo(host, port, &hints, &servs) == -1)
65 fprintf(stderr,
"ERROR: %s.%d: unable to connect to %s port: %s\n",
66 __FILE__, __LINE__, host, port);
67 fprintf(stderr,
"ERROR: errno: %s\n", strerror(errno));
71 for(curr = servs; curr != NULL; curr = curr->ai_next)
73 if((fd = socket(curr->ai_family, hints.ai_socktype, curr->ai_protocol)) < 0)
76 if(connect(fd, curr->ai_addr, curr->ai_addrlen) == -1)
84 fprintf(stderr,
"ERROR: %s.%d: unable to connect to %s port: %s\n",
85 __FILE__, __LINE__, host, port);
124 FO_ASSERT_PTR_NOT_NULL(scheduler->
server);
125 FO_ASSERT_PTR_NOT_NULL(scheduler->
workers);
126 FO_ASSERT_PTR_NOT_NULL(scheduler->
cancel);
134 FO_ASSERT_PTR_NOT_NULL(scheduler->
server);
195 FO_ASSERT_FALSE(result);
200 FO_ASSERT_FALSE(result);
227 FO_ASSERT_EQUAL(g_thread_pool_get_max_threads(scheduler->
workers), CONF_interface_nthreads);
228 FO_ASSERT_EQUAL(g_thread_pool_unprocessed(scheduler->
workers), 0);
235 FO_ASSERT_EQUAL(g_thread_pool_unprocessed(scheduler->
workers), 0);
248 #define CREATE_INTERFACE(name) \
250 name = scheduler_init(testdb, NULL); \
251 scheduler_foss_config(name); \
252 scheduler_agent_config(name); \
253 event_loop_destroy(); \
256 #define SEND_RECEIVE(string, len, res) \
257 snprintf(buffer, sizeof(buffer), string); \
258 result = write(soc, buffer, strlen(buffer)); \
259 FO_ASSERT_EQUAL((int)result, (int)strlen(buffer)); \
261 memset(buffer, '\0', sizeof(buffer)); \
262 result = read(soc, buffer, sizeof(buffer)); \
263 FO_ASSERT_EQUAL((int)result, (int)len); \
264 FO_ASSERT_STRING_EQUAL(buffer, res)
283 CREATE_INTERFACE(scheduler);
286 snprintf(
buffer,
sizeof(
buffer),
"%d", scheduler->i_port);
288 FO_ASSERT_TRUE_FATAL(soc);
293 FO_ASSERT_EQUAL((
int)result, 5);
298 FO_ASSERT_EQUAL((
int)result, 15)
299 FO_ASSERT_STRING_EQUAL(
buffer,
324 CREATE_INTERFACE(scheduler);
328 snprintf(
buffer,
sizeof(
buffer),
"%d", scheduler->i_port);
330 FO_ASSERT_TRUE_FATAL(soc);
331 SEND_RECEIVE(
"load", 64,
333 "host:localhost address:localhost max:10 running:0\n"
360 CREATE_INTERFACE(scheduler);
364 snprintf(
buffer,
sizeof(
buffer),
"%d", scheduler->i_port);
366 FO_ASSERT_TRUE_FATAL(soc);
374 SEND_RECEIVE(
"kill", 38,
376 "Invalid kill command: \"kill\"\n");
384 SEND_RECEIVE(
"kill 1", 40,
386 "Invalid kill command: \"kill 1\"\n");
394 SEND_RECEIVE(
"kill \"test\"", 45,
396 "Invalid kill command: \"kill \"test\"\"\n");
403 SEND_RECEIVE(
"kill 1 \"test\"", 9,
407 FO_ASSERT_EQUAL((
int)result, 1);
433 CREATE_INTERFACE(scheduler);
436 snprintf(
buffer,
sizeof(
buffer),
"%d", scheduler->i_port);
438 FO_ASSERT_TRUE_FATAL(soc);
446 SEND_RECEIVE(
"pause", 40,
448 "Invalid pause command: \"pause\"\n");
456 SEND_RECEIVE(
"pause \"test\"", 47,
458 "Invalid pause command: \"pause \"test\"\"\n");
465 SEND_RECEIVE(
"pause 1", 9,
469 FO_ASSERT_EQUAL((
int)result, 1);
493 CREATE_INTERFACE(scheduler);
496 snprintf(
buffer,
sizeof(
buffer),
"%d", scheduler->i_port);
498 FO_ASSERT_TRUE_FATAL(soc);
500 SEND_RECEIVE(
"reload", 9,
505 FO_ASSERT_EQUAL((
int)result, 1);
507 FO_ASSERT_STRING_EQUAL(event->
source_name,
"interface.c");
531 CREATE_INTERFACE(scheduler);
534 snprintf(
buffer,
sizeof(
buffer),
"%d", scheduler->i_port);
536 FO_ASSERT_TRUE_FATAL(soc);
538 SEND_RECEIVE(
"agents", 9,
543 FO_ASSERT_EQUAL((
int)result, 1);
545 FO_ASSERT_STRING_EQUAL(event->
source_name,
"interface.c");
556 CU_TestInfo tests_interface[] =
565 CU_TestInfo tests_interface_thread[] =
void list_agents_event(scheduler_t *scheduler, GOutputStream *ostr)
Receive agent on interface.
event_loop_t * event_loop_get()
Event handling operations.
void host_insert(host_t *host, scheduler_t *scheduler)
Inserts a new host into the scheduler structure.
host_t * host_init(char *name, char *address, char *agent_dir, int max)
Creates a new host, and adds it to the host list.
void interface_thread(interface_connection *conn, scheduler_t *scheduler)
Function that will run the thread associated with a particular interface instance.
void interface_destroy(scheduler_t *scheduler)
Closes the server socket and thread pool that service UI connections.
void * interface_listen_thread(scheduler_t *scheduler)
Function that will listen for new connections to the server sockets.
void interface_init(scheduler_t *scheduler)
Create the interface thread and thread pool that handle UI connections.
char buffer[2048]
The last thing received from the scheduler.
void scheduler_config_event(scheduler_t *scheduler, void *unused)
Load both the fossology configuration and all the agent configurations.
scheduler_t * scheduler_init(gchar *sysconfigdir, log_t *log)
Create a new scheduler object.
void scheduler_foss_config(scheduler_t *scheduler)
Loads the configuration data from fossology.conf.
void scheduler_destroy(scheduler_t *scheduler)
Free any memory associated with a scheduler_t.
char * source_name
Name of the source file creating the event.
void(* func)(scheduler_t *, void *)
The function that will be executed for this event.
GThread * server
Thread that is listening to the server socket.
GThreadPool * workers
Threads to handle incoming network communication.
gboolean i_terminate
Has the interface been terminated.
GCancellable * cancel
Used to stop the listening thread when it is running.
gboolean i_created
Has the interface been created.
uint16_t i_port
The port that the scheduler is listening on.
void test_sending_reload()
Test for reload message on interface.
void test_interface_init()
Test for interface_init()
void test_sending_pause()
Test for pause message on interface.
void test_interface_destroy()
Test for interface_destroy()
void test_interface_listen_thread()
Test for interface_listen_thread()
void test_sending_close()
Test for close message on interface.
void test_sending_kill()
Test for kill message on interface.
void test_sending_agents()
Test for agent message on interface.
int socket_connect(char *host, char *port)
Create a socket connection.
void test_interface_pool()
Test for interface_init() thread pool.
void test_sending_load()
Test for load message on interface.