Motr  M0
client.c File Reference
#include "ut/ut.h"
#include "motr/ut/client.h"
#include "motr/client.h"
#include "motr/client_internal.h"
#include "motr/client.c"
#include "motr/client_init.c"
#include "lib/ub.h"
#include "lib/errno.h"
#include "lib/timer.h"
#include "lib/finject.h"
#include "conf/objs/common.h"
#include "lib/trace.h"
Include dependency graph for client.c:

Go to the source code of this file.

Macros

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_CLIENT
 

Functions

M0_INTERNAL void ut_realm_entity_setup (struct m0_realm *realm, struct m0_entity *ent, struct m0_client *cinst)
 
static bool ut_test_floor_tick_cb (struct m0_clink *cl)
 
static void ut_test_m0_client_init_floor_tick (struct m0_client *instance, int start_state, int stop_state)
 
static void ut_test_m0_client_init_floors (struct m0_client *instance, int limit, bool fail)
 
static void ut_test_m0_client_init (void)
 
M0_INTERNAL int ut_m0_client_init (struct m0_client **instance)
 
M0_INTERNAL void ut_test_m0_client_fini (void)
 
M0_INTERNAL void ut_m0_client_fini (struct m0_client **instance)
 
static void ut_test_entity_invariant_locked (void)
 
static void ut_test_m0_entity_init (void)
 
static void ut_test_m0_obj_init (void)
 
static void ut_launch_cb_pass (struct m0_op_common *oc)
 
static void ut_launch_cb_fail (struct m0_op_common *oc)
 
static void ut_init_fake_op (struct m0_op_common *cop, struct m0_entity *ent, void(*cb)(struct m0_op_common *oc))
 
static void ut_test_m0_op_launch_one (void)
 
static void ut_test_m0_op_launch (void)
 
static void ut_test_op_sm_callme (struct m0_op *op)
 
static void ut_test_op_sm_dont_callme (struct m0_op *op)
 
static void ut_test_op_sm_cbs_helper (struct m0_op_ops *cbs, int executed, int stable, int failed)
 
static void ut_test_op_sm (void)
 
unsigned long ut_test_m0_op_wait_timer (unsigned long data)
 
void ut_test_m0_op_wait (void)
 
static void ut_test_m0_op_alloc (void)
 
static void ut_test_m0_op_init (void)
 
static void ut_test_m0_entity_fini (void)
 
static void ut_test_m0_obj_fini (void)
 
static void ut_m0_op_fini_cb (struct m0_op_common *oc)
 
static void ut_test_m0_op_fini (void)
 
static void ut_test_m0_op_free (void)
 
static void ut_test_m0_op_setup (void)
 
static void ut_test_m0_op_kick (void)
 
int rand (void)
 
M0_INTERNAL void ut_shuffle_test_order (struct m0_ut_suite *suite)
 
M0_INTERNAL int ut_init (void)
 
M0_INTERNAL int ut_fini (void)
 

Variables

static uint32_t ut_launch_cb_pass_count
 
static uint32_t ut_launch_cb_fail_count
 
static uint32_t ut_m0_op_fini_cb_count
 
static int ut_test_op_sm_callme_counter
 
static int ut_test_initlift_gnf_counter
 
struct m0_config default_config
 
struct m0_ut_suite ut_suite
 

Macro Definition Documentation

◆ M0_TRACE_SUBSYSTEM

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_CLIENT

Definition at line 41 of file client.c.

Function Documentation

◆ rand()

int rand ( void  )
Here is the caller graph for this function:

◆ ut_fini()

M0_INTERNAL int ut_fini ( void  )

Finalises the client UT environment.

Definition at line 1257 of file client.c.

Here is the call graph for this function:

◆ ut_init()

M0_INTERNAL int ut_init ( void  )

Initialises the client UT environment.

Definition at line 1245 of file client.c.

Here is the call graph for this function:

◆ ut_init_fake_op()

static void ut_init_fake_op ( struct m0_op_common cop,
struct m0_entity ent,
void(*)(struct m0_op_common *oc)  cb 
)
static

Initialises an operation for use as a fake-operation.

Definition at line 531 of file client.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ut_launch_cb_fail()

static void ut_launch_cb_fail ( struct m0_op_common oc)
static

Callback for fake-operation launch, increments a local counter, and moves the state machine along. Called with the m0_sm_group lock held.

Definition at line 519 of file client.c.

Here is the caller graph for this function:

◆ ut_launch_cb_pass()

static void ut_launch_cb_pass ( struct m0_op_common oc)
static

Callback for fake-operation launch, increments a local counter, and moves the state machine along. Called with the m0_sm_group lock held.

Definition at line 503 of file client.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ut_m0_client_fini()

M0_INTERNAL void ut_m0_client_fini ( struct m0_client **  instance)

A version of m0_client_fini for use in unit tests. This will finalise whatever was done in ut_m0_client_init.

Parameters
instanceA pointer to where the instance should be stored.

Definition at line 354 of file client.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ut_m0_client_init()

M0_INTERNAL int ut_m0_client_init ( struct m0_client **  instance)

A version of m0_client_init for use in unit tests. This will initialise client as far as we can in this environment.

Parameters
instanceA pointer to where the instance should be stored.
Returns
The value of m0_client_init.

Definition at line 265 of file client.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ut_m0_op_fini_cb()

static void ut_m0_op_fini_cb ( struct m0_op_common oc)
static

Callback for op_fini, used for unit tests to check the callback is occuring.

Parameters
octhe common operation that has been finished.

Definition at line 1012 of file client.c.

Here is the caller graph for this function:

◆ ut_realm_entity_setup()

M0_INTERNAL void ut_realm_entity_setup ( struct m0_realm realm,
struct m0_entity ent,
struct m0_client cinst 
)

Fake setup for a realm and entity.

Definition at line 60 of file client.c.

Here is the call graph for this function:

◆ ut_shuffle_test_order()

M0_INTERNAL void ut_shuffle_test_order ( struct m0_ut_suite suite)

A trick to force the UTs to run in random order every time. This allows the tester to discover hidden dependencies among tests (bonus score!).

Definition at line 1205 of file client.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ut_test_entity_invariant_locked()

static void ut_test_entity_invariant_locked ( void  )
static

Definition at line 390 of file client.c.

Here is the call graph for this function:

◆ ut_test_floor_tick_cb()

static bool ut_test_floor_tick_cb ( struct m0_clink cl)
static

Definition at line 80 of file client.c.

Here is the caller graph for this function:

◆ ut_test_m0_client_fini()

M0_INTERNAL void ut_test_m0_client_fini ( void  )

Unit tests m0_client_fini.

Definition at line 330 of file client.c.

Here is the call graph for this function:

◆ ut_test_m0_client_init()

static void ut_test_m0_client_init ( void  )
static

Partial Unit tests m0_client_init.

Unit tests uses fault injections to make initlift_get_next_floor be a no-op, so that they can manually move the 'initlift' between floors to test cleanup/failures etc. In a real environment, the 'initlift' would be moved through all the states to IL_INITIALISED by 'm0_client_init()'.

It isn't possible to test connecting to services and confd etc from here.

Definition at line 211 of file client.c.

Here is the call graph for this function:

◆ ut_test_m0_client_init_floor_tick()

static void ut_test_m0_client_init_floor_tick ( struct m0_client instance,
int  start_state,
int  stop_state 
)
static

Make an arbitrary move between 'floors' of the client init state machine. Makes various asserts about sane behaviour.

Parameters
instanceThe client instance we are working with.
start_stateThe state we believe we are in.
stop_stateThe state we would like to be in.

Definition at line 94 of file client.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ut_test_m0_client_init_floors()

static void ut_test_m0_client_init_floors ( struct m0_client instance,
int  limit,
bool  fail 
)
static

Move the client init state machine from the IL_UNINITIALISED state to the specified state, then back again, optionally due to a failure.

Parameters
instanceThe client instance we are working with.
limitThe maximum 'floor' to reach.
failWhether a simulated failure causes us to return to IL_UNINITIALISED

Definition at line 136 of file client.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ut_test_m0_entity_fini()

static void ut_test_m0_entity_fini ( void  )
static

Tests m0_entity_fini().

Definition at line 937 of file client.c.

Here is the call graph for this function:

◆ ut_test_m0_entity_init()

static void ut_test_m0_entity_init ( void  )
static

Tests the pre and post conditions of the m0_entity_init() helper function. The testee is seen as a black box that has to react as expected to some specific input and generate some valid output.

Definition at line 434 of file client.c.

Here is the call graph for this function:

◆ ut_test_m0_obj_fini()

static void ut_test_m0_obj_fini ( void  )
static

Tests m0_obj_fini().

Definition at line 974 of file client.c.

Here is the call graph for this function:

◆ ut_test_m0_obj_init()

static void ut_test_m0_obj_init ( void  )
static

Tests the pre and post conditions of the m0_obj_init() entry point. Also checks the object is correctly initialised. The testee is seen as a black box that has to react as expected to some specific input and generate some valid output.

Definition at line 465 of file client.c.

Here is the call graph for this function:

◆ ut_test_m0_op_alloc()

static void ut_test_m0_op_alloc ( void  )
static

Tests m0_op_alloc(), focusing on its pre-conditions. Also checks the output is right when function succeeds.

Definition at line 882 of file client.c.

Here is the call graph for this function:

◆ ut_test_m0_op_fini()

static void ut_test_m0_op_fini ( void  )
static

Tests the pre and post conditions of the m0_op_fini() entry point. Tests the optional callback is called if specified, and the state machine is set to UNINITIALISED.

Definition at line 1023 of file client.c.

Here is the call graph for this function:

◆ ut_test_m0_op_free()

static void ut_test_m0_op_free ( void  )
static

Tests memory allocated by op_init/op_alloc can only be freed in the appropriate circumstances.

Definition at line 1067 of file client.c.

Here is the call graph for this function:

◆ ut_test_m0_op_init()

static void ut_test_m0_op_init ( void  )
static

Tests m0_op_init().

Definition at line 900 of file client.c.

Here is the call graph for this function:

◆ ut_test_m0_op_kick()

static void ut_test_m0_op_kick ( void  )
static

Tests an operation can be kicked without any side effects.

Definition at line 1121 of file client.c.

Here is the call graph for this function:

◆ ut_test_m0_op_launch()

static void ut_test_m0_op_launch ( void  )
static

Unit tests m0_op_launch.

Definition at line 578 of file client.c.

Here is the call graph for this function:

◆ ut_test_m0_op_launch_one()

static void ut_test_m0_op_launch_one ( void  )
static

Tests m0_op_launch().

Definition at line 554 of file client.c.

Here is the call graph for this function:

◆ ut_test_m0_op_setup()

static void ut_test_m0_op_setup ( void  )
static

Tests setting up an operation.

Definition at line 1092 of file client.c.

Here is the call graph for this function:

◆ ut_test_m0_op_wait()

void ut_test_m0_op_wait ( void  )

Unit tests m0_op_wait().

Definition at line 780 of file client.c.

Here is the call graph for this function:

◆ ut_test_m0_op_wait_timer()

unsigned long ut_test_m0_op_wait_timer ( unsigned long  data)

Callback for the op_wait timer. Moves the provided operation state machine into the EXECUTED state.

Parameters
datathe operation to move, as an ugly integer.

Definition at line 768 of file client.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ut_test_op_sm()

static void ut_test_op_sm ( void  )
static

Tests the operation state machine by moving it through all valid transitions. Also checks the optional callback mechanism works as expected.

Definition at line 671 of file client.c.

Here is the call graph for this function:

◆ ut_test_op_sm_callme()

static void ut_test_op_sm_callme ( struct m0_op op)
static

An ops callback that increments a counter, used to check the callbacks were correctly called.

Definition at line 625 of file client.c.

Here is the caller graph for this function:

◆ ut_test_op_sm_cbs_helper()

static void ut_test_op_sm_cbs_helper ( struct m0_op_ops cbs,
int  executed,
int  stable,
int  failed 
)
static

Helper method for setting many op_ops values in a one-liner.

Parameters
opsthe ops structure to pack.
executedwhether the execute callback should assert immediately.
stablewhether the stable callback should assert immediately.
failedwhether the failed callback should assert immediately.

Definition at line 647 of file client.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ut_test_op_sm_dont_callme()

static void ut_test_op_sm_dont_callme ( struct m0_op op)
static

An ops callback that asserts immediatly. Don't call me - its a trap.

Definition at line 634 of file client.c.

Here is the caller graph for this function:

Variable Documentation

◆ default_config

struct m0_config default_config

Definition at line 58 of file client.c.

◆ ut_launch_cb_fail_count

uint32_t ut_launch_cb_fail_count
static

Definition at line 46 of file client.c.

◆ ut_launch_cb_pass_count

uint32_t ut_launch_cb_pass_count
static

Counter for op_launch callback.

Definition at line 45 of file client.c.

◆ ut_m0_op_fini_cb_count

uint32_t ut_m0_op_fini_cb_count
static

Counter for op_fini callbacks.

Definition at line 49 of file client.c.

◆ ut_suite

struct m0_ut_suite ut_suite

Definition at line 1201 of file client.c.

◆ ut_test_initlift_gnf_counter

int ut_test_initlift_gnf_counter
static

Counter for initlift get next floor callbacks.

Definition at line 55 of file client.c.

◆ ut_test_op_sm_callme_counter

int ut_test_op_sm_callme_counter
static

Counter for op_sm callbacks.

Definition at line 52 of file client.c.