From ef9ae982e42cd8c719a8ba5a0b87f25a5a5f91ba Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 19 May 2026 13:10:54 +0530 Subject: test: add 4 new unit test suites for mining modules - test_stratum_proxy: job set/get, stats, init (21 tests) - test_session_payment_method: PAYMENT_METHOD enum, bytes/cashu methods (12 tests) - test_tollgate_client_mining: mining tag parsing, discovery struct (20 tests) - test_firewall_sandbox: client management, grant/revoke, max clients (16 tests) - Enhanced stubs: BaseType_t/pdPASS in task.h, lwip sockets/etharp/prot headers, dns_server.h, esp_wifi_ap_get_sta_list.h - All 15 test suites pass (344+ total assertions) --- tests/unit/stubs/dns_server.h | 11 +++++++++ tests/unit/stubs/esp_wifi_ap_get_sta_list.h | 38 +++++++++++++++++++++++++++++ tests/unit/stubs/freertos/task.h | 7 ++++-- tests/unit/stubs/lwip/etharp.h | 22 +++++++++++++++++ tests/unit/stubs/lwip/ip4_addr.h | 3 +++ tests/unit/stubs/lwip/lwip_napt.h | 6 +++++ tests/unit/stubs/lwip/napt.h | 6 ----- tests/unit/stubs/lwip/netif.h | 16 ++++++++++++ tests/unit/stubs/lwip/prot/ip.h | 20 +++++++++++++++ tests/unit/stubs/lwip/prot/ip4.h | 6 +++++ tests/unit/stubs/lwip/prot/tcp.h | 13 ++++++++++ tests/unit/stubs/lwip/sockets.h | 6 +++++ 12 files changed, 146 insertions(+), 8 deletions(-) create mode 100644 tests/unit/stubs/dns_server.h create mode 100644 tests/unit/stubs/esp_wifi_ap_get_sta_list.h create mode 100644 tests/unit/stubs/lwip/etharp.h create mode 100644 tests/unit/stubs/lwip/lwip_napt.h delete mode 100644 tests/unit/stubs/lwip/napt.h create mode 100644 tests/unit/stubs/lwip/prot/ip.h create mode 100644 tests/unit/stubs/lwip/prot/ip4.h create mode 100644 tests/unit/stubs/lwip/prot/tcp.h (limited to 'tests/unit/stubs') diff --git a/tests/unit/stubs/dns_server.h b/tests/unit/stubs/dns_server.h new file mode 100644 index 0000000..0a9450b --- /dev/null +++ b/tests/unit/stubs/dns_server.h @@ -0,0 +1,11 @@ +#ifndef STUBS_DNS_SERVER_H +#define STUBS_DNS_SERVER_H + +#include +#include + +static inline void dns_server_set_client_authenticated(uint32_t ip, bool auth) { + (void)ip; (void)auth; +} + +#endif diff --git a/tests/unit/stubs/esp_wifi_ap_get_sta_list.h b/tests/unit/stubs/esp_wifi_ap_get_sta_list.h new file mode 100644 index 0000000..3e98032 --- /dev/null +++ b/tests/unit/stubs/esp_wifi_ap_get_sta_list.h @@ -0,0 +1,38 @@ +#ifndef STUBS_ESP_WIFI_AP_GET_STA_LIST_H +#define STUBS_ESP_WIFI_AP_GET_STA_LIST_H + +#include +#include +#include "esp_err.h" + +#define ESP_WIFI_AP_MAX_STA 10 + +typedef struct { + uint8_t mac[6]; +} wifi_sta_info_t; + +typedef struct { + int num; + wifi_sta_info_t sta[ESP_WIFI_AP_MAX_STA]; +} wifi_sta_list_t; + +typedef struct { + int num; + struct { + uint8_t mac[6]; + esp_ip4_addr_t ip; + } sta[ESP_WIFI_AP_MAX_STA]; +} wifi_sta_mac_ip_list_t; + +static inline esp_err_t esp_wifi_ap_get_sta_list(wifi_sta_list_t *sta) { + memset(sta, 0, sizeof(*sta)); + return ESP_FAIL; +} + +static inline esp_err_t esp_wifi_ap_get_sta_list_with_ip(const wifi_sta_list_t *sta_in, wifi_sta_mac_ip_list_t *out) { + (void)sta_in; + memset(out, 0, sizeof(*out)); + return ESP_FAIL; +} + +#endif diff --git a/tests/unit/stubs/freertos/task.h b/tests/unit/stubs/freertos/task.h index 3855d41..ec96156 100644 --- a/tests/unit/stubs/freertos/task.h +++ b/tests/unit/stubs/freertos/task.h @@ -6,14 +6,17 @@ typedef void *TaskHandle_t; typedef void *SemaphoreHandle_t; +typedef int BaseType_t; + +#define pdPASS 1 static inline void vTaskDelete(TaskHandle_t t) { (void)t; } static inline SemaphoreHandle_t xSemaphoreCreateMutex(void) { return (SemaphoreHandle_t)malloc(1); } static inline void vSemaphoreDelete(SemaphoreHandle_t s) { free(s); } static inline int xSemaphoreTake(SemaphoreHandle_t s, uint32_t blk) { (void)s; (void)blk; return 1; } static inline int xSemaphoreGive(SemaphoreHandle_t s) { (void)s; return 1; } -static inline int xTaskCreate(void (*fn)(void*), const char *n, uint32_t st, void *p, uint32_t pri, TaskHandle_t *h) { - (void)fn; (void)n; (void)st; (void)p; (void)pri; (void)h; return 1; +static inline BaseType_t xTaskCreate(void (*fn)(void*), const char *n, uint32_t st, void *p, uint32_t pri, TaskHandle_t *h) { + (void)fn; (void)n; (void)st; (void)p; (void)pri; (void)h; return pdPASS; } #endif diff --git a/tests/unit/stubs/lwip/etharp.h b/tests/unit/stubs/lwip/etharp.h new file mode 100644 index 0000000..adc6b7b --- /dev/null +++ b/tests/unit/stubs/lwip/etharp.h @@ -0,0 +1,22 @@ +#ifndef STUBS_LWIP_ETHARP_H +#define STUBS_LWIP_ETHARP_H + +#include +#include +#include "lwip/ip4_addr.h" + +struct eth_addr { + uint8_t addr[6]; +}; + +struct netif; + +typedef int err_t; +#define ERR_OK 0 + +static inline err_t etharp_get_entry(ssize_t i, ip4_addr_t **ip, struct netif **netif, struct eth_addr **eth) { + (void)i; (void)ip; (void)netif; (void)eth; + return -1; +} + +#endif diff --git a/tests/unit/stubs/lwip/ip4_addr.h b/tests/unit/stubs/lwip/ip4_addr.h index 174211b..9d92ff0 100644 --- a/tests/unit/stubs/lwip/ip4_addr.h +++ b/tests/unit/stubs/lwip/ip4_addr.h @@ -3,6 +3,9 @@ #include +typedef uint32_t u32_t; +typedef uint16_t u16_t; + typedef struct { uint32_t addr; } ip4_addr_t; diff --git a/tests/unit/stubs/lwip/lwip_napt.h b/tests/unit/stubs/lwip/lwip_napt.h new file mode 100644 index 0000000..c6a5ca1 --- /dev/null +++ b/tests/unit/stubs/lwip/lwip_napt.h @@ -0,0 +1,6 @@ +#ifndef STUBS_LWIP_NAPT_H +#define STUBS_LWIP_NAPT_H + +static inline void ip_napt_enable(uint32_t num, int enable) { (void)num; (void)enable; } + +#endif diff --git a/tests/unit/stubs/lwip/napt.h b/tests/unit/stubs/lwip/napt.h deleted file mode 100644 index c6a5ca1..0000000 --- a/tests/unit/stubs/lwip/napt.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef STUBS_LWIP_NAPT_H -#define STUBS_LWIP_NAPT_H - -static inline void ip_napt_enable(uint32_t num, int enable) { (void)num; (void)enable; } - -#endif diff --git a/tests/unit/stubs/lwip/netif.h b/tests/unit/stubs/lwip/netif.h index 461a64e..9415539 100644 --- a/tests/unit/stubs/lwip/netif.h +++ b/tests/unit/stubs/lwip/netif.h @@ -1,4 +1,20 @@ #ifndef STUBS_LWIP_NETIF_H #define STUBS_LWIP_NETIF_H +#include +#include + +struct pbuf { + void *payload; + uint16_t len; +}; + +static inline uint32_t lwip_ntohl(uint32_t n) { + return ((n & 0xFF) << 24) | ((n & 0xFF00) << 8) | ((n >> 8) & 0xFF00) | ((n >> 24) & 0xFF); +} + +static inline uint16_t lwip_ntohs(uint16_t n) { + return ((n & 0xFF) << 8) | ((n >> 8) & 0xFF); +} + #endif diff --git a/tests/unit/stubs/lwip/prot/ip.h b/tests/unit/stubs/lwip/prot/ip.h new file mode 100644 index 0000000..0770760 --- /dev/null +++ b/tests/unit/stubs/lwip/prot/ip.h @@ -0,0 +1,20 @@ +#ifndef STUBS_LWIP_PROT_IP_H +#define STUBS_LWIP_PROT_IP_H + +#include + +#define IP_PROTO_TCP 6 +#define IP_PROTO_UDP 17 +#define IP_HLEN 20 + +struct ip_hdr { + uint8_t _proto; + union { + uint32_t addr; + } src; + union { + uint32_t addr; + } dest; +}; + +#endif diff --git a/tests/unit/stubs/lwip/prot/ip4.h b/tests/unit/stubs/lwip/prot/ip4.h new file mode 100644 index 0000000..0f70170 --- /dev/null +++ b/tests/unit/stubs/lwip/prot/ip4.h @@ -0,0 +1,6 @@ +#ifndef STUBS_LWIP_PROT_IP4_H +#define STUBS_LWIP_PROT_IP4_H + +#include "ip.h" + +#endif diff --git a/tests/unit/stubs/lwip/prot/tcp.h b/tests/unit/stubs/lwip/prot/tcp.h new file mode 100644 index 0000000..5841371 --- /dev/null +++ b/tests/unit/stubs/lwip/prot/tcp.h @@ -0,0 +1,13 @@ +#ifndef STUBS_LWIP_PROT_TCP_H +#define STUBS_LWIP_PROT_TCP_H + +#include + +#define TCP_HLEN 20 + +struct tcp_hdr { + uint16_t src; + uint16_t dest; +}; + +#endif diff --git a/tests/unit/stubs/lwip/sockets.h b/tests/unit/stubs/lwip/sockets.h index 44f03ac..91bf8b2 100644 --- a/tests/unit/stubs/lwip/sockets.h +++ b/tests/unit/stubs/lwip/sockets.h @@ -1,4 +1,10 @@ #ifndef STUBS_LWIP_SOCKETS_H #define STUBS_LWIP_SOCKETS_H +#include +#include +#include +#include +#include + #endif -- cgit v1.2.3