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

Unit test for event operations. More...

#include <testRun.h>
#include <event.h>
Include dependency graph for testEvent.c:

Go to the source code of this file.

Functions

event_loop_tevent_loop_get ()
 
void sample_event (scheduler_t *scheduler, void *args)
 Sample event. More...
 
void other_event (void *args)
 Sample event 2. More...
 
void sample_callback (scheduler_t *scheduler)
 Sample callback function. More...
 
void terminate_event (void *args)
 Terminate event. More...
 
void test_event_loop_get ()
 Test for event_loop_get() More...
 
void test_event_init ()
 Test for event_init() More...
 
void test_event_signal_ext ()
 Test for event_signal_ext() More...
 
void test_event_signal ()
 Test for event_signal() More...
 
void test_event_loop_enter ()
 Test for event_loop_enter() More...
 
void test_event_loop_terminate ()
 Test for event_loop_enter() with terminate_event. More...
 
void test_event_loop_take ()
 Test for event_loop_take() More...
 
void test_event_loop_put ()
 Test for event_loop_put() More...
 

Variables

struct event_loop_internal vl_singleton
 
int el_created
 
void * sample_args
 Sample args to pass.
 
int call_num
 Number of callback calls.
 
int samp_num
 Number of sample event calls.
 
char * s_name = NULL
 Sample source file name.
 
uint16_t s_line = 0
 Sample source line number.
 
CU_TestInfo tests_event []
 

Detailed Description

Unit test for event operations.

Definition in file testEvent.c.

Function Documentation

◆ event_loop_get()

event_loop_t* event_loop_get ( )

There is only one instance of an event loop in any program. This function will control access to that event loop. If the event loop hasn't been created yet, it will create and return the event loop. If it has been created, this function will simple return it to the caller. This first call to this function should be made from the thread that will be running the event loop.

This is to prevent confusion on if the event loop has been created.

Returns

Definition at line 48 of file event.c.

◆ other_event()

void other_event ( void *  args)

Sample event 2.

Decrease samp_num on every call

Definition at line 45 of file testEvent.c.

◆ sample_callback()

void sample_callback ( scheduler_t scheduler)

Sample callback function.

Increases call_num on every call

Definition at line 55 of file testEvent.c.

◆ sample_event()

void sample_event ( scheduler_t scheduler,
void *  args 
)

Sample event.

Increase samp_num on every call

Definition at line 35 of file testEvent.c.

◆ terminate_event()

void terminate_event ( void *  args)

Terminate event.

Calls event_loop_terminate()

Definition at line 65 of file testEvent.c.

◆ test_event_init()

void test_event_init ( )

Test for event_init()

Test:
  1. Call event_init() with appropriate values to create an event
  2. Check if the event created have appropriate values

Definition at line 108 of file testEvent.c.

◆ test_event_loop_enter()

void test_event_loop_enter ( )

Test for event_loop_enter()

Test:
  1. Generate several events using event_signal()
  2. Get the return value from event_loop_enter() with sample_callback as argument
  3. Check the return value and count of callback calls

Definition at line 189 of file testEvent.c.

◆ test_event_loop_get()

void test_event_loop_get ( )

Test for event_loop_get()

Test:
  1. Check if no event loop is created
  2. Get the vl_addr and call event_loop_get()
  3. Check if vl_addr and event loop are equal
  4. Check if event loop is created and is not occupied or terminated
  5. Call event_loop_get() one more time
  6. Check if value return matches previous values

Definition at line 83 of file testEvent.c.

◆ test_event_loop_put()

void test_event_loop_put ( )

Test for event_loop_put()

Test:
  1. Pass sample_event and sample_args to event_signal()
  2. Check if the event loop gets the values in the queue
  3. Call event_loop_put()

Definition at line 328 of file testEvent.c.

◆ test_event_loop_take()

void test_event_loop_take ( )

Test for event_loop_take()

Test:
  1. Get an event_loop from event_loop_get()
  2. Set the occupied and terminated values for the event_loop
  3. Pass the event_loop to event_loop_take()
  4. Check the return value is NULL

Definition at line 302 of file testEvent.c.

◆ test_event_loop_terminate()

void test_event_loop_terminate ( )

Test for event_loop_enter() with terminate_event.

Test:
  1. Call event_signal() with terminate_event() callback
  2. Get the return value from event_loop_enter() with NULL as the parameters
  3. Check the return value is 0x0
  4. Check if the occupied is false for event_loop
  5. Check if terminated is true for event_loop

Definition at line 274 of file testEvent.c.

◆ test_event_signal()

void test_event_signal ( )

Test for event_signal()

Test:
  1. Use the macro event_signal() to create an event
  2. Get the new event from event loop
  3. Check if the event get the name "sample_event" and have proper function and argument assigned

Definition at line 162 of file testEvent.c.

◆ test_event_signal_ext()

void test_event_signal_ext ( )

Test for event_signal_ext()

Test:
  1. Call event_signal_ext() with appropriate values to create an event
  2. Check if the event created have appropriate values

Definition at line 133 of file testEvent.c.

Variable Documentation

◆ el_created

int el_created
extern

Flag used to check if the event loop has been created

Definition at line 35 of file event.c.

◆ tests_event

CU_TestInfo tests_event[]
Initial value:
=
{
{"Test event_loop_get", test_event_loop_get },
{"Test event_init", test_event_init },
{"Test event_signal_ext", test_event_signal_ext },
{"Test event_signal", test_event_signal },
{"Test event_loop_terminate", test_event_loop_terminate },
{"Test event_loop_take", test_event_loop_take },
{"Test event_loop_put", test_event_loop_put },
CU_TEST_INFO_NULL
}
void test_event_init()
Test for event_init()
Definition: testEvent.c:108
void test_event_loop_put()
Test for event_loop_put()
Definition: testEvent.c:328
void test_event_signal()
Test for event_signal()
Definition: testEvent.c:162
void test_event_loop_terminate()
Test for event_loop_enter() with terminate_event.
Definition: testEvent.c:274
void test_event_signal_ext()
Test for event_signal_ext()
Definition: testEvent.c:133
void test_event_loop_take()
Test for event_loop_take()
Definition: testEvent.c:302
void test_event_loop_get()
Test for event_loop_get()
Definition: testEvent.c:83

Definition at line 352 of file testEvent.c.

◆ vl_singleton

struct event_loop_internal vl_singleton
extern

The event loop is a singleton, this is the only actual event loop

Definition at line 29 of file event.c.