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

Unit tests for the fossscheduler library section of libfossology. More...

#include <libfossscheduler.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <libfocunit.h>
Include dependency graph for test_fossscheduler.c:

Go to the source code of this file.

Macros

#define COMMIT_HASH   "COMMIT_HASH Unknown"
 
#define FROM_UNIT   "UNIT\n"
 
#define VERBOSE_TEST   7
 
#define NC_TEST   "Not a Command\n"
 
#define write_con(...)
 

Functions

void fo_heartbeat ()
 Internal function to send a heartbeat to the scheduler along with the number of items processed. More...
 
void set_up (void)
 Since the fossscheduler library depends on reading and writing very specific data to stdin and stdout, these both need to be replaced with pipes. The set_up function pretends to be a test so that it can do this before any other test gets run. More...
 
void tear_down (void)
 This function closes the pipes created in the setup function and returns stdin and stdout to their original values. This essentially is the inverse of the set_up() function. More...
 
void signal_connect_end ()
 Test for fo_scheduler_next() blocking. More...
 
void signal_connect_verbose ()
 Serves the same purpose for the verbose command as the signal_connect_end() function does for the end command. More...
 
void signal_connect_version ()
 Test for version string. More...
 
void test_scheduler_no_connect ()
 Test for fo_scheduler_connect() with no new connection. More...
 
void test_scheduler_connect ()
 Test for fo_scheduler_connect() with a new connection. More...
 
void test_scheduler_next_close ()
 Tests sending "CLOSE\n" to stdin for the scheduler next function. More...
 
void test_scheduler_next_end ()
 Tests sending "END\n" to the stdin for the scheduler next function. More...
 
void test_scheduler_next_verbose ()
 Tests sending "VERBOSE #\n" to the stdin for the scheduler next function. More...
 
void test_scheduler_next_version ()
 Tests sending "VERSION\n" to the stdin for the scheduler next function. More...
 
void test_scheduler_next_oth ()
 Tests scheduler for non commands. More...
 
void test_scheduler_current ()
 Tests the scheduler current function. More...
 
void test_scheduler_disconnect ()
 Tests the scheduler disconnection function. More...
 
void test_scheduler_heart ()
 Test the scheduler heart function. This function must set up the heartbeat again so that it can check that the heartbeat will increase correctly. More...
 

Variables

int items_processed
 The number of items processed by the agent.
 
int valid
 If the information stored in buffer is valid.
 
int sscheduler
 Whether the agent was started by the scheduler.
 
int agent_verbose
 Common verbose flags for the agents, this is used so that the scheduler can change the verbose level for a particular agent. All agents should use this flag for verbose instead of one declared within the agent. This can be set by the scheduler to enable different levels of verbose. More...
 
char tbuffer [1024]
 
int in_sub [2]
 
int out_sub [2]
 
int stdin_t
 
int stdout_t
 
FILE * read_from
 
FILE * write_to
 
CU_TestInfo fossscheduler_testcases []
 

Detailed Description

Unit tests for the fossscheduler library section of libfossology.

Definition in file test_fossscheduler.c.

Macro Definition Documentation

◆ write_con

#define write_con (   ...)
Value:
fprintf(write_to, __VA_ARGS__); \
fflush(write_to);

Definition at line 53 of file test_fossscheduler.c.

Function Documentation

◆ fo_heartbeat()

void fo_heartbeat ( )

Internal function to send a heartbeat to the scheduler along with the number of items processed.

Note
Agents should NOT call this function directly.
This is the alarm SIGALRM function.
Returns
void
Todo:
These functions are not safe for a signal handler

Definition at line 75 of file libfossscheduler.c.

◆ set_up()

void set_up ( void  )

Since the fossscheduler library depends on reading and writing very specific data to stdin and stdout, these both need to be replaced with pipes. The set_up function pretends to be a test so that it can do this before any other test gets run.

Returns
void

Definition at line 65 of file test_fossscheduler.c.

◆ signal_connect_end()

void signal_connect_end ( )

Test for fo_scheduler_next() blocking.

Test:
Since the fo_scheduler_next() function will block until either a "CLOSE\n" or a non-command message is sent a signal is needed to test the intermediate state of the connection. This will check that the "END\n" command left the connection in the correct state and then send a "CLOSE\n" command so that fo_scheduler_next() will return in the main thread.
Returns
void

Definition at line 112 of file test_fossscheduler.c.

◆ signal_connect_verbose()

void signal_connect_verbose ( )

Serves the same purpose for the verbose command as the signal_connect_end() function does for the end command.

Test:
  1. Check the agent_verbose at begin
  2. Update the verbose value
Returns
void

Definition at line 129 of file test_fossscheduler.c.

◆ signal_connect_version()

void signal_connect_version ( )

Test for version string.

Test:
  1. Read from the scheduler connection
  2. Check the version string with COMMIT_HASH

Definition at line 145 of file test_fossscheduler.c.

◆ tear_down()

void tear_down ( void  )

This function closes the pipes created in the setup function and returns stdin and stdout to their original values. This essentially is the inverse of the set_up() function.

Returns
void

Definition at line 88 of file test_fossscheduler.c.

◆ test_scheduler_connect()

void test_scheduler_connect ( )

Test for fo_scheduler_connect() with a new connection.

Test:
Tests calling an fo_scheduler_connect() in a situation where it will create a connection to the scheduler. This will pass --scheduler_start as a command line arg to fo_scheduler_connect(). The alarm, sleep and following assert check that the heart beat was correctly created.
Returns
void

Definition at line 199 of file test_fossscheduler.c.

◆ test_scheduler_current()

void test_scheduler_current ( )

Tests the scheduler current function.

Test:
  1. Send CLOSE\n to the scheduler
  2. Check if fo_scheduler_next() and fo_scheduler_current() returns NULL
Returns
void

Definition at line 335 of file test_fossscheduler.c.

◆ test_scheduler_disconnect()

void test_scheduler_disconnect ( )

Tests the scheduler disconnection function.

Test:
  1. Call fo_scheduler_disconnect()
  2. Check if scheduler returns BYE #\n
Returns
void

Definition at line 352 of file test_fossscheduler.c.

◆ test_scheduler_heart()

void test_scheduler_heart ( )

Test the scheduler heart function. This function must set up the heartbeat again so that it can check that the heartbeat will increase correctly.

Test:
  1. Send heart beat 1 using fo_scheduler_heart() and check if items_processed is updated.
  2. Send heart beat 10 and check if items_processed is updated with 11.
  3. Send SIGALRM and check if scheduler returns HEART: 11.
Returns
void

Definition at line 373 of file test_fossscheduler.c.

◆ test_scheduler_next_close()

void test_scheduler_next_close ( )

Tests sending "CLOSE\n" to stdin for the scheduler next function.

Test:
  1. Send CLOSE\n to the scheduler
  2. Call fo_scheduler_next().
  3. Check if NULL is returned.
Returns
void

Definition at line 238 of file test_fossscheduler.c.

◆ test_scheduler_next_end()

void test_scheduler_next_end ( )

Tests sending "END\n" to the stdin for the scheduler next function.

Test:
  1. Send END\n to the scheduler
  2. Send a SIGALRM
  3. Call fo_scheduler_next().
  4. Check if NULL is returned.
Returns
void

Definition at line 255 of file test_fossscheduler.c.

◆ test_scheduler_next_oth()

void test_scheduler_next_oth ( )

Tests scheduler for non commands.

Test:
Send a non-command to the stdin for the scheduler next function. Unlike the other scheduler next test functions, this does not need to setup a signal since fo_scheduler_next() will return without any extra commands.
Returns
void

Definition at line 317 of file test_fossscheduler.c.

◆ test_scheduler_next_verbose()

void test_scheduler_next_verbose ( )

Tests sending "VERBOSE #\n" to the stdin for the scheduler next function.

Test:
  1. Send VERBOSE #\n to the scheduler
  2. Send a SIGALRM
  3. Call fo_scheduler_next().
  4. Check if NULL is returned.
Returns
void

Definition at line 276 of file test_fossscheduler.c.

◆ test_scheduler_next_version()

void test_scheduler_next_version ( )

Tests sending "VERSION\n" to the stdin for the scheduler next function.

Test:
  1. Send VERSION\n to the scheduler
  2. Send a SIGALRM
  3. Call fo_scheduler_next().
  4. Check if NULL is returned.
Returns
void

Definition at line 297 of file test_fossscheduler.c.

◆ test_scheduler_no_connect()

void test_scheduler_no_connect ( )

Test for fo_scheduler_connect() with no new connection.

Test:
Tests calling an fo_scheduler_connect() in a situation where it wouldn't create a connection to the scheduler. This will not pass --scheduler_start as a command line arg to fo_scheduler_connect()
Returns
void

Definition at line 167 of file test_fossscheduler.c.

Variable Documentation

◆ agent_verbose

int agent_verbose
extern

Common verbose flags for the agents, this is used so that the scheduler can change the verbose level for a particular agent. All agents should use this flag for verbose instead of one declared within the agent. This can be set by the scheduler to enable different levels of verbose.

Global verbose flags that agents should use instead of specific verbose flags. This is used by the scheduler to turn verbose on a particular agent on during run time. When the verbose flag is turned on by the scheduler the on_verbose function will be called. If nothing needs to be done when verbose is turned on, simply pass NULL to scheduler_connect

Definition at line 64 of file libfossscheduler.c.

◆ fossscheduler_testcases

CU_TestInfo fossscheduler_testcases[]
Initial value:
=
{
{"fossscheduler set up", set_up},
{"fossscheduler no connect", test_scheduler_no_connect},
{"fossscheduler connect", test_scheduler_connect},
{"fossscheduler next close", test_scheduler_next_close},
{"fossscheduler next end", test_scheduler_next_end},
{"fossscheduler next verbose", test_scheduler_next_verbose},
{"fossscheduler next version", test_scheduler_next_version},
{"fossscheduler next oth", test_scheduler_next_oth},
{"fossscheduler current", test_scheduler_current},
{"fossscheduler disconnect", test_scheduler_disconnect},
{"fossscheduler heat", test_scheduler_heart},
{"fossscheduler tear down", tear_down},
CU_TEST_INFO_NULL
}
void set_up(void)
Since the fossscheduler library depends on reading and writing very specific data to stdin and stdout...
void test_scheduler_connect()
Test for fo_scheduler_connect() with a new connection.
void test_scheduler_next_oth()
Tests scheduler for non commands.
void test_scheduler_no_connect()
Test for fo_scheduler_connect() with no new connection.
void test_scheduler_next_version()
Tests sending "VERSION\n" to the stdin for the scheduler next function.
void tear_down(void)
This function closes the pipes created in the setup function and returns stdin and stdout to their or...
void test_scheduler_next_end()
Tests sending "END\n" to the stdin for the scheduler next function.
void test_scheduler_heart()
Test the scheduler heart function. This function must set up the heartbeat again so that it can check...
void test_scheduler_current()
Tests the scheduler current function.
void test_scheduler_next_verbose()
Tests sending "VERBOSE #\n" to the stdin for the scheduler next function.
void test_scheduler_next_close()
Tests sending "CLOSE\n" to stdin for the scheduler next function.
void test_scheduler_disconnect()
Tests the scheduler disconnection function.

Definition at line 394 of file test_fossscheduler.c.