MeshX 0.4
This repository provides an implementation for Bluetooth Low Energy (BLE) Mesh network nodes. The project allows you to create BLE mesh nodes that can communicate with each other, enabling the development of smart home solutions or other IoT-based applications.
Loading...
Searching...
No Matches
unit_test.h File Reference

Header file for the production console unit test functionality. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "meshx_config_internal.h"
#include "argtable3/argtable3.h"
#include "module_id.h"
#include "meshx_err.h"

Go to the source code of this file.

Data Structures

struct  callback_node
 Structure to hold the unit test callback function. More...

Macros

#define UT_GET_ARG(_x, _type, _argv)
 Macro to extract an argument from the argument list.

Typedefs

typedef meshx_err_t(* module_callback_t) (int cmd_id, int argc, char **argv)
 Callback function for unit test modules.
typedef struct callback_node unit_test_callback_t
 Structure to hold the unit test callback function.

Functions

meshx_err_t register_ut_command ()
 Registers the unit test (ut) command with the MeshX shell.
meshx_err_t init_unit_test_console (void)
 Initialize the unit test console.
meshx_err_t register_unit_test (module_id_t module_id, module_callback_t callback)
 Register a unit test for a specific module.

Detailed Description

Header file for the production console unit test functionality.

Copyright © 2024 - 2025 MeshX

This file contains the declarations and definitions for initializing the production console and registering unit test callbacks for different modules.

Macro Definition Documentation

◆ UT_GET_ARG

#define UT_GET_ARG ( _x,
_type,
_argv )
Value:
(_type) atoi( _argv [_x] )

Macro to extract an argument from the argument list.

Typedef Documentation

◆ module_callback_t

typedef meshx_err_t(* module_callback_t) (int cmd_id, int argc, char **argv)

Callback function for unit test modules.

This function is used to define the callback function signature for unit test modules. The callback function is invoked when a unit test command is received by the production console.

Parameters
cmd_idThe command ID to be processed.
argcThe number of arguments provided.
argvThe array of arguments.
Returns
  • MESHX_SUCCESS: Success
  • MESHX_INVALID_ARG: Invalid arguments
  • Other error codes depending on the implementation

◆ unit_test_callback_t

Structure to hold the unit test callback function.

Function Documentation

◆ init_unit_test_console()

meshx_err_t init_unit_test_console ( void )

Initialize the unit test console.

This function initializes the unit test console for the application using the underlying shell.

Returns
  • MESHX_SUCCESS: Success
  • MESHX_FAIL: Initialization failed

Initialize the unit test console.

Returns
  • MESHX_SUCCESS: Success
  • Other error codes: Failure
103 {
105 if (err != MESHX_SUCCESS) {
106 return err;
107 }
108
109 err = register_ut_command();
110 if (err != MESHX_SUCCESS) {
111 return err;
112 }
113
114 // Register all GPIO subsystem tests
116 if (err != MESHX_SUCCESS) {
117 return err;
118 }
119
120 return meshx_shell_start();
121}
meshx_err_t register_all_gpio_tests(void)
Register all GPIO subsystem tests.
Definition gpio_test_registry.c:20
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
**This function is called by the parent element when a state change request *is received It validates the request and returns a result to the element not the model layer **return * MESHX_SUCCESS
Definition meshx_model_level.cpp:385
meshx_err_t meshx_shell_start(void)
Starts the MeshX shell task.
Definition meshx_shell.c:130
meshx_err_t meshx_shell_init(void)
Initializes the MeshX shell core and the underlying platform console.
Definition meshx_shell.c:102
meshx_err_t register_ut_command()
Registers the unit test (ut) command with the MeshX shell.
Definition unit_test.c:84

◆ register_unit_test()

meshx_err_t register_unit_test ( module_id_t module_id,
module_callback_t callback )

Register a unit test for a specific module.

This function registers a unit test callback for the given module ID.

Parameters
[in]module_idThe ID of the module for which the unit test is being registered.
[in]callbackThe callback function to be called for the unit test.
Returns
  • MESHX_SUCCESS: Success
  • MESHX_INVALID_ARG: Invalid arguments
  • MESHX_FAIL: Failed to register the unit test
137 {
138 if(module_id >= MODULE_ID_MAX)
139 return MESHX_INVALID_ARG;
140
141 callback_list[module_id].callback = callback;
142 return MESHX_SUCCESS;
143}
@ MESHX_INVALID_ARG
Definition meshx_err.h:46
@ MODULE_ID_MAX
Definition module_id.h:51
static unit_test_callback_t callback_list[MODULE_ID_MAX]
Definition unit_test.c:20

◆ register_ut_command()

meshx_err_t register_ut_command ( )

Registers the unit test (ut) command with the MeshX shell.

This function creates a new shell command "ut" which is used for running unit tests.

Returns
  • MESHX_SUCCESS: Success
  • Other error codes: Failure

This function creates a new console command "ut" which is used for running unit tests.

Returns
  • MESHX_SUCCESS: Success
  • Other error codes: Failure
84 {
85 const meshx_shell_cmd_t cmd = {
86 .command = "ut",
87 .help = "Run unit tests",
88 .hint = NULL,
89 .func = ut_command_handler,
90 };
92}
meshx_err_t meshx_shell_register_command(const meshx_shell_cmd_t *cmd)
Registers a command with the MeshX shell.
Definition meshx_shell.c:119
Shell command structure.
Definition meshx_shell.h:25
static int ut_command_handler(int argc, char **argv)
Handles unit test commands by invoking the appropriate callback based on the module ID.
Definition unit_test.c:36