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.c File Reference

Unit test module for the production console. More...

Macros

#define UT_CMD_MIN_ARGS   4

Functions

static int ut_command_handler (int argc, char **argv)
 Handles unit test commands by invoking the appropriate callback based on the module ID.
meshx_err_t register_ut_command ()
 Registers the unit test (ut) command with the MeshX shell.
meshx_err_t init_unit_test_console ()
 Initializes the unit test console using the platform shell.
meshx_err_t register_unit_test (module_id_t module_id, module_callback_t callback)
 Register a unit test for a specific module.

Variables

static unit_test_callback_t callback_list [MODULE_ID_MAX]

Detailed Description

Unit test module for the production console.

Copyright © 2024 - 2025 MeshX

This file contains the implementation of the unit test module for the production console. It provides functions to register unit test commands and initialize the console for production use.

Macro Definition Documentation

◆ UT_CMD_MIN_ARGS

#define UT_CMD_MIN_ARGS   4

Function Documentation

◆ init_unit_test_console()

meshx_err_t init_unit_test_console ( void )

Initializes the unit test console using the platform shell.

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 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

◆ ut_command_handler()

int ut_command_handler ( int argc,
char ** argv )
static

Handles unit test commands by invoking the appropriate callback based on the module ID.

This function processes unit test commands by parsing the provided arguments and invoking the corresponding callback function registered for the specified module ID.

Parameters
argcThe number of arguments passed to the command.
argvAn array of strings representing the arguments.
Returns
  • MESHX_SUCCESS: If the unit test callback was successfully invoked.
  • MESHX_INVALID_ARG: If the number of arguments is insufficient.
  • MESHX_NOT_FOUND: If no unit test is registered for the specified module ID.
36 {
37 for (int i = 0; i < argc; i++) {
38 MESHX_LOGD(MODULE_ID_COMMON, "Raw argv[%d]: %s", i, argv[i]);
39 }
40
41 if (argc < UT_CMD_MIN_ARGS) {
42 MESHX_LOGE(MODULE_ID_COMMON, "Insufficient arguments");
43 return MESHX_INVALID_ARG;
44 }
45
46 int cmd_id = UT_GET_ARG(2, uint16_t, argv);
47 int parsed_argc = UT_GET_ARG(3, uint16_t, argv);
48 module_id_t module_id = UT_GET_ARG(1, uint16_t, argv);
49 MESHX_LOGD(MODULE_ID_COMMON, "Unit Test: Params -> argc: %d, Module: %d, cmd_id: %d", parsed_argc, module_id , cmd_id);
50 if (parsed_argc > (argc - UT_CMD_MIN_ARGS))
51 {
52 MESHX_LOGE(MODULE_ID_COMMON, "Insufficient module arguments");
53 return MESHX_INVALID_ARG;
54 }
55
56 for (size_t i = 0; i < parsed_argc; i++)
57 {
58 MESHX_LOGD(MODULE_ID_COMMON, "argv[%d]: %s", i, argv[i + UT_CMD_MIN_ARGS]);
59 }
60
61 if (module_id >= MODULE_ID_MAX) {
62 MESHX_LOGE(MODULE_ID_COMMON, "Module ID %d unknown", module_id);
63 return MESHX_INVALID_ARG;
64 }
65
66 if(NULL != callback_list[module_id].callback)
67 {
68 return callback_list[module_id].callback(cmd_id, parsed_argc, (argv + UT_CMD_MIN_ARGS));
69 }
70
71 MESHX_LOGE(MODULE_ID_COMMON, "No unit test registered for module ID %d", module_id);
72 return MESHX_NOT_FOUND;
73}
@ MESHX_NOT_FOUND
Definition meshx_err.h:50
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:114
#define MESHX_LOGD(module_id, format,...)
Definition meshx_log.h:132
module_id_t
Enumeration of module IDs.
Definition module_id.h:27
@ MODULE_ID_COMMON
Definition module_id.h:36
#define UT_CMD_MIN_ARGS
Definition unit_test.c:18
#define UT_GET_ARG(_x, _type, _argv)
Macro to extract an argument from the argument list.
Definition unit_test.h:31

Variable Documentation

◆ callback_list

unit_test_callback_t callback_list[MODULE_ID_MAX]
static