MeshX 0.3
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"
Include dependency graph for unit_test.h:
This graph shows which files directly or indirectly include this file:

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 ESP console.
 
meshx_err_t init_unit_test_console (void)
 Initialize the production 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.

Definition in file unit_test.h.

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.

Definition at line 27 of file unit_test.h.

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

Definition at line 44 of file unit_test.h.

◆ 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 production console.

This function initializes the production console for the application.

Returns
  • MESHX_SUCCESS: Success
  • MESHX_FAIL: Initialization failed

Definition at line 100 of file unit_test.c.

100 {
101 // Initialize the console
103 esp_console_repl_t *repl = NULL;
104 esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
105
106 repl_config.prompt = "X>";
107
108 // install console REPL environment
109#if CONFIG_ESP_CONSOLE_UART
110 esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
111 ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));
112#endif
113#if CONFIG_ESP_CONSOLE_USB_CDC
114 esp_console_dev_usb_cdc_config_t cdc_config = ESP_CONSOLE_DEV_CDC_CONFIG_DEFAULT();
115 ESP_ERROR_CHECK(esp_console_new_repl_usb_cdc(&cdc_config, &repl_config, &repl));
116#endif
117#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
118 esp_console_dev_usb_serial_jtag_config_t usbjtag_config = ESP_CONSOLE_DEV_USB_SERIAL_JTAG_CONFIG_DEFAULT();
119 ESP_ERROR_CHECK(esp_console_new_repl_usb_serial_jtag(&usbjtag_config, &repl_config, &repl));
120#endif
121
122 // Register the unit test command
123 err = register_ut_command();
124 if (err != MESHX_SUCCESS) {
125 return err;
126 }
127
128 err = esp_console_start_repl(repl);
129 if (err != MESHX_SUCCESS) {
130 return err;
131 }
132
133 return MESHX_SUCCESS;
134}
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:39
@ MESHX_SUCCESS
Definition meshx_err.h:40
meshx_err_t register_ut_command()
Registers the unit test (ut) command with the ESP console.
Definition unit_test.c:81
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

Definition at line 149 of file unit_test.c.

149 {
150 if(module_id >= MODULE_ID_MAX)
151 return MESHX_INVALID_ARG;
152
153 callback_list[module_id].callback = callback;
154 return MESHX_SUCCESS;
155}
@ MESHX_INVALID_ARG
Definition meshx_err.h:42
@ MODULE_ID_MAX
Definition module_id.h:34
static unit_test_callback_t callback_list[MODULE_ID_MAX]
Definition unit_test.c:20
Here is the caller graph for this function:

◆ register_ut_command()

meshx_err_t register_ut_command ( )

Registers the unit test (ut) command with the ESP console.

This function creates a new console command "ut" which is used for running unit tests. The command is registered with the ESP console using the esp_console_cmd_register function.

Returns
  • MESHX_SUCCESS: Success
  • Other error codes: Failure

Definition at line 81 of file unit_test.c.

81 {
82 const esp_console_cmd_t cmd = {
83 .command = "ut",
84 .help = "Run unit tests",
85 .hint = NULL,
86 .func = (esp_console_cmd_func_t)&ut_command_handler,
87 };
88 return esp_console_cmd_register(&cmd);
89}
static meshx_err_t 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
Here is the call graph for this function:
Here is the caller graph for this function: