FOSSology  4.4.0
Open Source License Compliance by Open Source Software
testInterface.c File Reference

Unit test for interface operations. More...

#include <testRun.h>
#include <event.h>
#include <host.h>
#include <interface.h>
#include <scheduler.h>
#include <gio/gio.h>
#include <glib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
Include dependency graph for testInterface.c:

Go to the source code of this file.

Macros

#define mint_t   int32_t
 
#define CREATE_INTERFACE(name)
 
#define SEND_RECEIVE(string, len, res)
 

Functions

int socket_connect (char *host, char *port)
 Create a socket connection. More...
 
void * interface_listen_thread (void *unused)
 
void test_interface_init ()
 Test for interface_init() More...
 
void test_interface_destroy ()
 Test for interface_destroy() More...
 
void test_interface_listen_thread ()
 Test for interface_listen_thread() More...
 
void test_interface_pool ()
 Test for interface_init() thread pool. More...
 
void test_sending_close ()
 Test for close message on interface. More...
 
void test_sending_load ()
 Test for load message on interface. More...
 
void test_sending_kill ()
 Test for kill message on interface. More...
 
void test_sending_pause ()
 Test for pause message on interface. More...
 
void test_sending_reload ()
 Test for reload message on interface. More...
 
void test_sending_agents ()
 Test for agent message on interface. More...
 

Variables

CU_TestInfo tests_interface []
 
CU_TestInfo tests_interface_thread []
 

Detailed Description

Unit test for interface operations.

Definition in file testInterface.c.

Macro Definition Documentation

◆ CREATE_INTERFACE

#define CREATE_INTERFACE (   name)
Value:
scheduler_t* name; \
name = scheduler_init(testdb, NULL); \
scheduler_foss_config(name); \
scheduler_agent_config(name); \
event_loop_destroy(); \
interface_init(name)
scheduler_t * scheduler_init(gchar *sysconfigdir, log_t *log)
Create a new scheduler object.
Definition: scheduler.c:249

Definition at line 248 of file testInterface.c.

◆ mint_t

#define mint_t   int32_t

Check the processor architecture (32/64 bit)

Definition at line 39 of file testInterface.c.

◆ SEND_RECEIVE

#define SEND_RECEIVE (   string,
  len,
  res 
)
Value:
snprintf(buffer, sizeof(buffer), string); \
result = write(soc, buffer, strlen(buffer)); \
FO_ASSERT_EQUAL((int)result, (int)strlen(buffer)); \
sleep(1); \
memset(buffer, '\0', sizeof(buffer)); \
result = read(soc, buffer, sizeof(buffer)); \
FO_ASSERT_EQUAL((int)result, (int)len); \
FO_ASSERT_STRING_EQUAL(buffer, res)
char buffer[2048]
The last thing received from the scheduler.

Definition at line 256 of file testInterface.c.

Function Documentation

◆ socket_connect()

int socket_connect ( char *  host,
char *  port 
)

Create a socket connection.

Creates a new socket that connects to the given host and port.

Parameters
hostCstring name of the host to connect to
portCstring representation of the port to connec to
Returns
The file descriptor of the new socket

Definition at line 51 of file testInterface.c.

◆ test_interface_destroy()

void test_interface_destroy ( )

Test for interface_destroy()

Test:
  1. Initialize scheduler using scheduler_init()
  2. Destroy interface on the scheduler using interface_destroy() multiple times
  3. Check the scheduler for
    1. i_created as FALSE
    2. i_terminate as FALSE

Definition at line 150 of file testInterface.c.

◆ test_interface_init()

void test_interface_init ( )

Test for interface_init()

Test:
  1. Initialize scheduler using scheduler_init()
  2. Initialize interface on the scheduler using interface_init()
  3. Check the scheduler for
    1. i_created as TRUE
    2. i_terminate as FALSE
    3. server as not NULL
    4. workers as not NULL
    5. cancel as not NULL
  4. Destroy the scheduler and interface

Definition at line 112 of file testInterface.c.

◆ test_interface_listen_thread()

void test_interface_listen_thread ( )

Test for interface_listen_thread()

Test:
  1. Initialize scheduler using scheduler_init()
  2. Set scheduler's i_terminate and i_created to TRUE and call interface_listen_thread()
  3. Check for the result
  4. Set scheduler's i_terminate and i_created to FALSE and call interface_listen_thread()
  5. Check for the result

Definition at line 185 of file testInterface.c.

◆ test_interface_pool()

void test_interface_pool ( )

Test for interface_init() thread pool.

Test:
  1. Initialize scheduler using scheduler_init()
  2. Initialize interface using interface_init()
  3. Check the pool's max threads equals the value set in fossology.conf
  4. Check the unprocessed workers in pool is 0
  5. Connect to the scheduler port and check if result is TRUE

Definition at line 214 of file testInterface.c.

◆ test_sending_agents()

void test_sending_agents ( )

Test for agent message on interface.

Test:
  1. Initialize scheduler and interface
  2. Create a socket connection to scheduler
  3. Send valid agent message on the interface (pause <job id>)
  4. Check for the result on socket which should contain
    received and a new event list_agents_event should be triggered

Definition at line 523 of file testInterface.c.

◆ test_sending_close()

void test_sending_close ( )

Test for close message on interface.

Test:
  1. Initialize scheduler and interface
  2. Create a socket connection to scheduler
  3. Send close message on the interface
  4. Check for the result on socket which should contain
    recieved\nCLOSE

Definition at line 275 of file testInterface.c.

◆ test_sending_kill()

void test_sending_kill ( )

Test for kill message on interface.

Test:
  1. Initialize scheduler and interface
  2. Create a socket connection to scheduler
  3. Send invalid kill message on the interface
  4. Check for the result on socket which should contain
    received\nInvalid kill command: <kill message>
  5. Send valid kill message on the interface
  6. Check for the result on socket which should contain
    received and queue length should decrease

Definition at line 353 of file testInterface.c.

◆ test_sending_load()

void test_sending_load ( )

Test for load message on interface.

Test:
  1. Initialize scheduler and interface
  2. Create a socket connection to scheduler
  3. Send load message on the interface
  4. Check for the result on socket which should contain
    received\nhost:<host> address:<address> max:<max> running:0\nend

Definition at line 317 of file testInterface.c.

◆ test_sending_pause()

void test_sending_pause ( )

Test for pause message on interface.

Test:
  1. Initialize scheduler and interface
  2. Create a socket connection to scheduler
  3. Send invalid pause message on the interface
  4. Check for the result on socket which should contain
    received\nInvalid pause command: <pause message>
  5. Send valid pause message on the interface (pause <job id>)
  6. Check for the result on socket which should contain
    received and queue length should decrease

Definition at line 426 of file testInterface.c.

◆ test_sending_reload()

void test_sending_reload ( )

Test for reload message on interface.

Test:
  1. Initialize scheduler and interface
  2. Create a socket connection to scheduler
  3. Send valid reload message on the interface (pause <job id>)
  4. Check for the result on socket which should contain
    received and a new event scheduler_config_event should be triggered

Definition at line 485 of file testInterface.c.

Variable Documentation

◆ tests_interface

CU_TestInfo tests_interface[]
Initial value:
=
{
{"Test interface_init", test_interface_init },
{"Test interface_destroy", test_interface_destroy },
{"Test interface_listen_thread", test_interface_listen_thread },
{"Test interface_pool", test_interface_pool },
CU_TEST_INFO_NULL
}
void test_interface_init()
Test for interface_init()
void test_interface_destroy()
Test for interface_destroy()
void test_interface_listen_thread()
Test for interface_listen_thread()
void test_interface_pool()
Test for interface_init() thread pool.

Definition at line 556 of file testInterface.c.

◆ tests_interface_thread

CU_TestInfo tests_interface_thread[]
Initial value:
=
{
{"Test sending \"close\"", test_sending_close },
{"Test sending \"load\"", test_sending_load },
{"Test sending \"kill\"", test_sending_kill },
{"Test sending \"pause\"", test_sending_pause },
{"Test sending \"status\"", test_sending_reload },
CU_TEST_INFO_NULL
}
void test_sending_reload()
Test for reload message on interface.
void test_sending_pause()
Test for pause message on interface.
void test_sending_close()
Test for close message on interface.
void test_sending_kill()
Test for kill message on interface.
void test_sending_load()
Test for load message on interface.

Definition at line 565 of file testInterface.c.