28 #include <interface.h> 29 #include <scheduler.h> 34 #include <sys/socket.h> 35 #include <sys/types.h> 36 #include <netinet/in.h> 47 #if defined(__amd64__) 48 #define mint_t int64_t 50 #define mint_t int32_t 65 struct addrinfo hints;
66 struct addrinfo* servs, * curr;
71 memset(&hints, 0,
sizeof(hints));
72 hints.ai_family = AF_UNSPEC;
73 hints.ai_socktype = SOCK_STREAM;
74 if(getaddrinfo(host, port, &hints, &servs) == -1)
76 fprintf(stderr,
"ERROR: %s.%d: unable to connect to %s port: %s\n",
77 __FILE__, __LINE__, host, port);
78 fprintf(stderr,
"ERROR: errno: %s\n", strerror(errno));
82 for(curr = servs; curr != NULL; curr = curr->ai_next)
84 if((fd = socket(curr->ai_family, hints.ai_socktype, curr->ai_protocol)) < 0)
87 if(connect(fd, curr->ai_addr, curr->ai_addrlen) == -1)
95 fprintf(stderr,
"ERROR: %s.%d: unable to connect to %s port: %s\n",
96 __FILE__, __LINE__, host, port);
135 FO_ASSERT_PTR_NOT_NULL(scheduler->
server);
136 FO_ASSERT_PTR_NOT_NULL(scheduler->
workers);
137 FO_ASSERT_PTR_NOT_NULL(scheduler->
cancel);
139 interface_thread = scheduler->
server;
145 FO_ASSERT_PTR_NOT_NULL(scheduler->
server);
146 FO_ASSERT_PTR_EQUAL(scheduler->
server, interface_thread);
206 FO_ASSERT_FALSE(result);
211 FO_ASSERT_FALSE(result);
238 FO_ASSERT_EQUAL(g_thread_pool_get_max_threads(scheduler->
workers), CONF_interface_nthreads);
239 FO_ASSERT_EQUAL(g_thread_pool_unprocessed(scheduler->
workers), 0);
241 snprintf(buffer,
sizeof(buffer),
"%d", scheduler->
i_port);
246 FO_ASSERT_EQUAL(g_thread_pool_unprocessed(scheduler->
workers), 0);
259 #define CREATE_INTERFACE(name) \ 261 name = scheduler_init(testdb, NULL); \ 262 scheduler_foss_config(name); \ 263 scheduler_agent_config(name); \ 264 event_loop_destroy(); \ 267 #define SEND_RECEIVE(string, len, res) \ 268 snprintf(buffer, sizeof(buffer), string); \ 269 result = write(soc, buffer, strlen(buffer)); \ 270 FO_ASSERT_EQUAL((int)result, (int)strlen(buffer)); \ 272 memset(buffer, '\0', sizeof(buffer)); \ 273 result = read(soc, buffer, sizeof(buffer)); \ 274 FO_ASSERT_EQUAL((int)result, (int)len); \ 275 FO_ASSERT_STRING_EQUAL(buffer, res) 294 CREATE_INTERFACE(scheduler);
297 snprintf(buffer,
sizeof(buffer),
"%d", scheduler->i_port);
299 FO_ASSERT_TRUE_FATAL(soc);
301 snprintf(buffer,
sizeof(buffer),
"close");
303 result = write(soc, buffer, strlen(buffer));
304 FO_ASSERT_EQUAL((
int)result, 5);
307 memset(buffer,
'\0',
sizeof(buffer));
308 result = read(soc, buffer,
sizeof(buffer));
309 FO_ASSERT_EQUAL((
int)result, 15)
310 FO_ASSERT_STRING_EQUAL(buffer,
335 CREATE_INTERFACE(scheduler);
339 snprintf(buffer,
sizeof(buffer),
"%d", scheduler->i_port);
341 FO_ASSERT_TRUE_FATAL(soc);
342 SEND_RECEIVE(
"load", 64,
344 "host:localhost address:localhost max:10 running:0\n" 371 CREATE_INTERFACE(scheduler);
375 snprintf(buffer,
sizeof(buffer),
"%d", scheduler->i_port);
377 FO_ASSERT_TRUE_FATAL(soc);
385 SEND_RECEIVE(
"kill", 38,
387 "Invalid kill command: \"kill\"\n");
395 SEND_RECEIVE(
"kill 1", 40,
397 "Invalid kill command: \"kill 1\"\n");
405 SEND_RECEIVE(
"kill \"test\"", 45,
407 "Invalid kill command: \"kill \"test\"\"\n");
414 SEND_RECEIVE(
"kill 1 \"test\"", 9,
418 FO_ASSERT_EQUAL((
int)result, 1);
444 CREATE_INTERFACE(scheduler);
447 snprintf(buffer,
sizeof(buffer),
"%d", scheduler->i_port);
449 FO_ASSERT_TRUE_FATAL(soc);
457 SEND_RECEIVE(
"pause", 40,
459 "Invalid pause command: \"pause\"\n");
467 SEND_RECEIVE(
"pause \"test\"", 47,
469 "Invalid pause command: \"pause \"test\"\"\n");
476 SEND_RECEIVE(
"pause 1", 9,
480 FO_ASSERT_EQUAL((
int)result, 1);
504 CREATE_INTERFACE(scheduler);
507 snprintf(buffer,
sizeof(buffer),
"%d", scheduler->i_port);
509 FO_ASSERT_TRUE_FATAL(soc);
511 SEND_RECEIVE(
"reload", 9,
516 FO_ASSERT_EQUAL((
int)result, 1);
518 FO_ASSERT_STRING_EQUAL(event->
source_name,
"interface.c");
542 CREATE_INTERFACE(scheduler);
545 snprintf(buffer,
sizeof(buffer),
"%d", scheduler->i_port);
547 FO_ASSERT_TRUE_FATAL(soc);
549 SEND_RECEIVE(
"agents", 9,
554 FO_ASSERT_EQUAL((
int)result, 1);
556 FO_ASSERT_STRING_EQUAL(event->
source_name,
"interface.c");
567 CU_TestInfo tests_interface[] =
576 CU_TestInfo tests_interface_thread[] =
void test_sending_agents()
Test for agent message on interface.
void interface_thread(interface_connection *conn, scheduler_t *scheduler)
Function that will run the thread associated with a particular interface instance.
void list_agents_event(scheduler_t *scheduler, GOutputStream *ostr)
Receive agent on interface.
GCancellable * cancel
Used to stop the listening thread when it is running.
void interface_destroy(scheduler_t *scheduler)
Closes the server socket and thread pool that service UI connections.
void scheduler_destroy(scheduler_t *scheduler)
Free any memory associated with a scheduler_t.
void test_sending_reload()
Test for reload message on interface.
gboolean i_created
Has the interface been created.
uint16_t i_port
The port that the scheduler is listening on.
GThread * server
Thread that is listening to the server socket.
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 test_interface_destroy()
Test for interface_destroy()
void host_insert(host_t *host, scheduler_t *scheduler)
Inserts a new host into the scheduler structure.
void(* func)(scheduler_t *, void *)
The function that will be executed for this event.
void test_sending_pause()
Test for pause message on interface.
void scheduler_foss_config(scheduler_t *scheduler)
Loads the configuration data from fossology.conf.
gboolean i_terminate
Has the interface been terminated.
scheduler_t * scheduler_init(gchar *sysconfigdir, log_t *log)
Create a new scheduler object.
void test_interface_init()
Test for interface_init()
char buffer[2048]
The last thing received from the scheduler.
void test_sending_kill()
Test for kill message on interface.
Event handling operations.
void scheduler_config_event(scheduler_t *scheduler, void *unused)
Load both the fossology configuration and all the agent configurations.
void interface_init(scheduler_t *scheduler)
Create the interface thread and thread pool that handle UI connections.
void * interface_listen_thread(scheduler_t *scheduler)
Function that will listen for new connections to the server sockets.
void test_sending_close()
Test for close message on interface.
void test_interface_pool()
Test for interface_init() thread pool.
int socket_connect(char *host, char *port)
Create a socket connection.
GThreadPool * workers
Threads to handle incoming network communication.
void test_interface_listen_thread()
Test for interface_listen_thread()
char * source_name
Name of the source file creating the event.
event_loop_t * event_loop_get()
void test_sending_load()
Test for load message on interface.