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

Property-based tests for GPIO platform abstraction validation. More...

Functions

static meshx_err_t test_property_platform_interface_adherence (void)
 Property 8.1: Platform Interface Adherence.
static meshx_err_t test_property_platform_interrupt_support (void)
 Property 8.2: Platform Interrupt Support.
static meshx_err_t run_gpio_platform_property_tests (void)
 Run all Property 8 tests.
static meshx_err_t gpio_platform_property_test_handler (int cmd_id, int argc, char **argv)
 GPIO platform property test command handler.
meshx_err_t register_gpio_platform_property_tests (void)
 Register GPIO platform property tests.

Detailed Description

Property-based tests for GPIO platform abstraction validation.

This file implements property-based tests for Property 8: BSP Abstraction and Platform Compatibility.

Author
MeshX Team
Date
2024

Function Documentation

◆ gpio_platform_property_test_handler()

meshx_err_t gpio_platform_property_test_handler ( int cmd_id,
int argc,
char ** argv )
static

GPIO platform property test command handler.

146{
147 (void)argc;
148 (void)argv;
149
150 switch (cmd_id) {
151 case 0: return run_gpio_platform_property_tests();
154 default: return MESHX_INVALID_ARG;
155 }
156}
static meshx_err_t test_property_platform_interface_adherence(void)
Property 8.1: Platform Interface Adherence.
Definition gpio_platform_property_test.c:29
static meshx_err_t run_gpio_platform_property_tests(void)
Run all Property 8 tests.
Definition gpio_platform_property_test.c:126
static meshx_err_t test_property_platform_interrupt_support(void)
Property 8.2: Platform Interrupt Support.
Definition gpio_platform_property_test.c:78
@ MESHX_INVALID_ARG
Definition meshx_err.h:46

◆ register_gpio_platform_property_tests()

meshx_err_t register_gpio_platform_property_tests ( void )

Register GPIO platform property tests.

Returns
meshx_err_t Registration result
162{
164}
static meshx_err_t gpio_platform_property_test_handler(int cmd_id, int argc, char **argv)
GPIO platform property test command handler.
Definition gpio_platform_property_test.c:145
@ MODULE_ID_GPIO_PLATFORM_TEST
Definition module_id.h:49
meshx_err_t register_unit_test(module_id_t module_id, module_callback_t callback)
Register a unit test for a specific module.
Definition unit_test.c:137

◆ run_gpio_platform_property_tests()

meshx_err_t run_gpio_platform_property_tests ( void )
static

Run all Property 8 tests.

127{
128 MESHX_LOGD(MODULE_ID_COMMON, "Starting GPIO Platform Property Tests (Property 8)");
129
130 meshx_err_t result;
131
133 if (result != MESHX_SUCCESS) return result;
134
136 if (result != MESHX_SUCCESS) return result;
137
138 MESHX_LOGI(MODULE_ID_COMMON, "All GPIO Platform Property Tests PASSED");
139 return MESHX_SUCCESS;
140}
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
#define MESHX_LOGI(module_id, format,...)
Definition meshx_log.h:126
#define MESHX_LOGD(module_id, format,...)
Definition meshx_log.h:132
**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
@ MODULE_ID_COMMON
Definition module_id.h:36

◆ test_property_platform_interface_adherence()

meshx_err_t test_property_platform_interface_adherence ( void )
static

Property 8.1: Platform Interface Adherence.

Validates that the platform interface functions are present and return expected results for basic operations.

30{
31 MESHX_LOGD(MODULE_ID_COMMON, "Testing Property 8.1: Platform Interface Adherence");
32
33 // Test platform initialization
35 if (err != MESHX_SUCCESS) {
36 MESHX_LOGE(MODULE_ID_COMMON, "FAIL: Platform initialization failed: %d", err);
37 return MESHX_FAIL;
38 }
39
40 // Test platform pin configuration with a known valid physical pin
41 // Note: This is platform-dependent, but we expect at least one pin to work
42 // For ESP32-C3, GPIO 4 is often available
43 uint8_t physical_pin = 4;
45 if (err != MESHX_SUCCESS) {
46 MESHX_LOGW(MODULE_ID_COMMON, "WARN: Could not configure physical pin %u, trying pin 0", physical_pin);
47 physical_pin = 0;
49 if (err != MESHX_SUCCESS) {
50 MESHX_LOGE(MODULE_ID_COMMON, "FAIL: Platform pin configuration failed: %d", err);
51 return MESHX_FAIL;
52 }
53 }
54
55 // Test platform level control
56 err = meshx_gpio_platform_set_level(physical_pin, 1);
57 if (err != MESHX_SUCCESS) {
58 MESHX_LOGE(MODULE_ID_COMMON, "FAIL: Platform set_level failed: %d", err);
59 return MESHX_FAIL;
60 }
61
62 uint8_t read_level = 0;
63 err = meshx_gpio_platform_get_level(physical_pin, &read_level);
64 if (err != MESHX_SUCCESS || read_level != 1) {
65 MESHX_LOGE(MODULE_ID_COMMON, "FAIL: Platform get_level failed or returned wrong value: %d, val=%u", err, read_level);
66 return MESHX_FAIL;
67 }
68
69 MESHX_LOGI(MODULE_ID_COMMON, "PASS: Property 8.1 - Platform Interface Adherence");
70 return MESHX_SUCCESS;
71}
@ MESHX_FAIL
Definition meshx_err.h:45
@ MESHX_GPIO_PULL_NONE
Definition meshx_gpio.h:42
@ MESHX_GPIO_MODE_OUTPUT
Definition meshx_gpio.h:30
@ MESHX_GPIO_DRIVE_MEDIUM
Definition meshx_gpio.h:54
meshx_err_t meshx_gpio_platform_get_level(uint8_t physical_pin, uint8_t *level)
Platform-specific pin level get.
meshx_err_t meshx_gpio_platform_init(void)
Platform-specific GPIO initialization.
meshx_err_t meshx_gpio_platform_set_level(uint8_t physical_pin, uint8_t level)
Platform-specific pin level set.
meshx_err_t meshx_gpio_platform_configure_pin(uint8_t physical_pin, meshx_gpio_mode_t mode, meshx_gpio_pull_t pull, meshx_gpio_drive_t drive)
Platform-specific pin mode configuration.
#define MESHX_LOGW(module_id, format,...)
Definition meshx_log.h:120
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:114

◆ test_property_platform_interrupt_support()

meshx_err_t test_property_platform_interrupt_support ( void )
static

Property 8.2: Platform Interrupt Support.

Validates that the platform correctly handles interrupt registration and enabling.

79{
80 MESHX_LOGD(MODULE_ID_COMMON, "Testing Property 8.2: Platform Interrupt Support");
81
82 uint8_t physical_pin = 5; // Use another pin for interrupt test
83
84 // Configure as input first
86 if (err != MESHX_SUCCESS) {
87 MESHX_LOGW(MODULE_ID_COMMON, "WARN: Could not configure physical pin %u for input, skip interrupt test", physical_pin);
88 return MESHX_SUCCESS; // Not a failure if pin is unavailable
89 }
90
91 // Register interrupt
93 if (err != MESHX_SUCCESS) {
94 MESHX_LOGE(MODULE_ID_COMMON, "FAIL: Platform interrupt registration failed: %d", err);
95 return MESHX_FAIL;
96 }
97
98 // Enable interrupt
99 err = meshx_gpio_platform_intr_enable(physical_pin, true);
100 if (err != MESHX_SUCCESS) {
101 MESHX_LOGE(MODULE_ID_COMMON, "FAIL: Platform interrupt enable failed: %d", err);
102 return MESHX_FAIL;
103 }
104
105 // Disable interrupt
106 err = meshx_gpio_platform_intr_enable(physical_pin, false);
107 if (err != MESHX_SUCCESS) {
108 MESHX_LOGE(MODULE_ID_COMMON, "FAIL: Platform interrupt disable failed: %d", err);
109 return MESHX_FAIL;
110 }
111
112 // Unregister interrupt
113 err = meshx_gpio_platform_unregister_intr(physical_pin);
114 if (err != MESHX_SUCCESS) {
115 MESHX_LOGE(MODULE_ID_COMMON, "FAIL: Platform interrupt unregistration failed: %d", err);
116 return MESHX_FAIL;
117 }
118
119 MESHX_LOGI(MODULE_ID_COMMON, "PASS: Property 8.2 - Platform Interrupt Support");
120 return MESHX_SUCCESS;
121}
@ MESHX_GPIO_PULL_UP
Definition meshx_gpio.h:43
@ MESHX_GPIO_MODE_INPUT
Definition meshx_gpio.h:29
meshx_err_t meshx_gpio_platform_unregister_intr(uint8_t physical_pin)
Platform-specific interrupt unregistration.
meshx_err_t meshx_gpio_platform_intr_enable(uint8_t physical_pin, bool enable)
Platform-specific interrupt enable/disable.
meshx_err_t meshx_gpio_platform_register_intr(uint8_t physical_pin, meshx_gpio_intr_type_t intr_type, void(*isr_handler)(void *), void *arg)
Platform-specific interrupt registration.
@ MESHX_GPIO_INTR_NEGATIVE_EDGE
Definition meshx_gpio_types.h:31