upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests/unit/stubs
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-17 01:31:49 +0530
committerYour Name <you@example.com>2026-05-17 01:31:49 +0530
commit347d29658959c7e4b368a15134c183f4ce7a25bc (patch)
tree362b3e40273e3c1435bdd0745de61006041bb803 /tests/unit/stubs
parent4c47ae188b288e7d24bd9566ab3e6a6805d9484f (diff)
Testing infrastructure: AGENTS.md rules + unit test framework + geohash tests (11/11 pass)
- Add AGENTS.md: full project context + mandatory testing rules for AI sessions - Add tests/unit/ with host-compiled C unit test infrastructure - Clean stubs approach: ESP-IDF type stubs in tests/unit/stubs/, no source modifications - Fix geohash.c bit extraction bug (3-byte span) found by unit tests - test_geohash: 11/11 passing with reference vectors (Munich, NYC, origin, boundaries)
Diffstat (limited to 'tests/unit/stubs')
-rw-r--r--tests/unit/stubs/dhcpserver/dhcpserver.h4
-rw-r--r--tests/unit/stubs/esp_crt_bundle.h6
-rw-r--r--tests/unit/stubs/esp_err.h18
-rw-r--r--tests/unit/stubs/esp_event.h8
-rw-r--r--tests/unit/stubs/esp_http_client.h12
-rw-r--r--tests/unit/stubs/esp_http_server.h10
-rw-r--r--tests/unit/stubs/esp_log.h10
-rw-r--r--tests/unit/stubs/esp_mac.h19
-rw-r--r--tests/unit/stubs/esp_netif.h17
-rw-r--r--tests/unit/stubs/esp_spiffs.h15
-rw-r--r--tests/unit/stubs/esp_system.h4
-rw-r--r--tests/unit/stubs/esp_tls.h25
-rw-r--r--tests/unit/stubs/esp_wifi.h40
-rw-r--r--tests/unit/stubs/freertos/FreeRTOS.h11
-rw-r--r--tests/unit/stubs/freertos/event_groups.h13
-rw-r--r--tests/unit/stubs/freertos/task.h19
-rw-r--r--tests/unit/stubs/freertos/timers.h15
-rw-r--r--tests/unit/stubs/lwip/ip4_addr.h19
-rw-r--r--tests/unit/stubs/lwip/napt.h6
-rw-r--r--tests/unit/stubs/lwip/netdb.h4
-rw-r--r--tests/unit/stubs/lwip/netif.h4
-rw-r--r--tests/unit/stubs/lwip/sockets.h4
-rw-r--r--tests/unit/stubs/nvs_flash.h12
23 files changed, 295 insertions, 0 deletions
diff --git a/tests/unit/stubs/dhcpserver/dhcpserver.h b/tests/unit/stubs/dhcpserver/dhcpserver.h
new file mode 100644
index 0000000..659f2c3
--- /dev/null
+++ b/tests/unit/stubs/dhcpserver/dhcpserver.h
@@ -0,0 +1,4 @@
1#ifndef STUBS_DHCPSERVER_DHCP_H
2#define STUBS_DHCPSERVER_DHCP_H
3
4#endif
diff --git a/tests/unit/stubs/esp_crt_bundle.h b/tests/unit/stubs/esp_crt_bundle.h
new file mode 100644
index 0000000..dfb9bb1
--- /dev/null
+++ b/tests/unit/stubs/esp_crt_bundle.h
@@ -0,0 +1,6 @@
1#ifndef STUBS_ESP_CRT_BUNDLE_H
2#define STUBS_ESP_CRT_BUNDLE_H
3
4static inline void *esp_crt_bundle_attach(void *conf) { (void)conf; return NULL; }
5
6#endif
diff --git a/tests/unit/stubs/esp_err.h b/tests/unit/stubs/esp_err.h
new file mode 100644
index 0000000..84c3734
--- /dev/null
+++ b/tests/unit/stubs/esp_err.h
@@ -0,0 +1,18 @@
1#ifndef STUBS_ESP_ERR_H
2#define STUBS_ESP_ERR_H
3
4#include <stdint.h>
5#include <stdio.h>
6#include <stdlib.h>
7
8typedef int esp_err_t;
9
10#define ESP_OK 0
11#define ESP_FAIL -1
12#define ESP_ERR_INVALID_ARG 0x102
13#define ESP_ERR_NO_MEM 0x101
14#define ESP_ERR_NOT_FOUND 0x104
15
16#define ESP_ERROR_CHECK(x) do { if ((x) != 0) { fprintf(stderr, "ESP_ERROR_CHECK failed: 0x%x\n", (int)(x)); abort(); } } while(0)
17
18#endif
diff --git a/tests/unit/stubs/esp_event.h b/tests/unit/stubs/esp_event.h
new file mode 100644
index 0000000..baea064
--- /dev/null
+++ b/tests/unit/stubs/esp_event.h
@@ -0,0 +1,8 @@
1#ifndef STUBS_ESP_EVENT_H
2#define STUBS_ESP_EVENT_H
3
4#include "esp_err.h"
5
6static inline esp_err_t esp_event_loop_create_default(void) { return ESP_OK; }
7
8#endif
diff --git a/tests/unit/stubs/esp_http_client.h b/tests/unit/stubs/esp_http_client.h
new file mode 100644
index 0000000..4169714
--- /dev/null
+++ b/tests/unit/stubs/esp_http_client.h
@@ -0,0 +1,12 @@
1#ifndef STUBS_ESP_HTTP_CLIENT_H
2#define STUBS_ESP_HTTP_CLIENT_H
3
4#include "esp_err.h"
5
6typedef void *esp_http_client_handle_t;
7
8typedef struct {
9 int cert_pem;
10} esp_http_client_config_t;
11
12#endif
diff --git a/tests/unit/stubs/esp_http_server.h b/tests/unit/stubs/esp_http_server.h
new file mode 100644
index 0000000..22a5624
--- /dev/null
+++ b/tests/unit/stubs/esp_http_server.h
@@ -0,0 +1,10 @@
1#ifndef STUBS_ESP_HTTP_SERVER_H
2#define STUBS_ESP_HTTP_SERVER_H
3
4#include "esp_err.h"
5#include <stdint.h>
6
7typedef void *httpd_handle_t;
8typedef struct httpd_req httpd_req_t;
9
10#endif
diff --git a/tests/unit/stubs/esp_log.h b/tests/unit/stubs/esp_log.h
new file mode 100644
index 0000000..f353fe9
--- /dev/null
+++ b/tests/unit/stubs/esp_log.h
@@ -0,0 +1,10 @@
1#ifndef STUBS_ESP_LOG_H
2#define STUBS_ESP_LOG_H
3
4#include <stdio.h>
5
6#define ESP_LOGI(tag, fmt, ...) do { printf("I %s: " fmt "\n", tag, ##__VA_ARGS__); } while(0)
7#define ESP_LOGW(tag, fmt, ...) do { printf("W %s: " fmt "\n", tag, ##__VA_ARGS__); } while(0)
8#define ESP_LOGE(tag, fmt, ...) do { fprintf(stderr, "E %s: " fmt "\n", tag, ##__VA_ARGS__); } while(0)
9
10#endif
diff --git a/tests/unit/stubs/esp_mac.h b/tests/unit/stubs/esp_mac.h
new file mode 100644
index 0000000..ddc80d4
--- /dev/null
+++ b/tests/unit/stubs/esp_mac.h
@@ -0,0 +1,19 @@
1#ifndef STUBS_ESP_MAC_H
2#define STUBS_ESP_MAC_H
3
4#include <stdint.h>
5#include <string.h>
6
7static inline int esp_read_mac(uint8_t *mac, int type) {
8 (void)type;
9 memset(mac, 0, 6);
10 mac[0] = 0x02;
11 mac[1] = 0x00;
12 mac[2] = 0x00;
13 mac[3] = 0x00;
14 mac[4] = 0xBE;
15 mac[5] = 0xEF;
16 return 0;
17}
18
19#endif
diff --git a/tests/unit/stubs/esp_netif.h b/tests/unit/stubs/esp_netif.h
new file mode 100644
index 0000000..f009537
--- /dev/null
+++ b/tests/unit/stubs/esp_netif.h
@@ -0,0 +1,17 @@
1#ifndef STUBS_ESP_NETIF_H
2#define STUBS_ESP_NETIF_H
3
4#include <stdint.h>
5
6typedef struct {
7 uint32_t addr;
8} esp_ip4_addr_t;
9
10#define IPSTR "%d.%d.%d.%d"
11#define IP2STR(ip) ((ip)->addr & 0xff), (((ip)->addr >> 8) & 0xff), (((ip)->addr >> 16) & 0xff), (((ip)->addr >> 24) & 0xff)
12
13static inline void IP4_ADDR(esp_ip4_addr_t *ip, uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
14 ip->addr = ((uint32_t)a) | ((uint32_t)b << 8) | ((uint32_t)c << 16) | ((uint32_t)d << 24);
15}
16
17#endif
diff --git a/tests/unit/stubs/esp_spiffs.h b/tests/unit/stubs/esp_spiffs.h
new file mode 100644
index 0000000..ae6a127
--- /dev/null
+++ b/tests/unit/stubs/esp_spiffs.h
@@ -0,0 +1,15 @@
1#ifndef STUBS_ESP_SPIFFS_H
2#define STUBS_ESP_SPIFFS_H
3
4#include "esp_err.h"
5
6typedef struct {
7 const char *base_path;
8 const char *partition_label;
9 int max_files;
10 bool format_if_mount_failed;
11} esp_vfs_spiffs_conf_t;
12
13static inline esp_err_t esp_vfs_spiffs_register(const esp_vfs_spiffs_conf_t *conf) { (void)conf; return ESP_OK; }
14
15#endif
diff --git a/tests/unit/stubs/esp_system.h b/tests/unit/stubs/esp_system.h
new file mode 100644
index 0000000..8e63c80
--- /dev/null
+++ b/tests/unit/stubs/esp_system.h
@@ -0,0 +1,4 @@
1#ifndef STUBS_ESP_SYSTEM_H
2#define STUBS_ESP_SYSTEM_H
3
4#endif
diff --git a/tests/unit/stubs/esp_tls.h b/tests/unit/stubs/esp_tls.h
new file mode 100644
index 0000000..7ded63a
--- /dev/null
+++ b/tests/unit/stubs/esp_tls.h
@@ -0,0 +1,25 @@
1#ifndef STUBS_ESP_TLS_H
2#define STUBS_ESP_TLS_H
3
4#include "esp_err.h"
5
6typedef struct esp_tls esp_tls_t;
7
8typedef struct {
9 void *crt_bundle_attach;
10 int use_global_ca_store;
11} esp_tls_cfg_t;
12
13static inline esp_tls_t *esp_tls_init(void) { return (esp_tls_t*)1; }
14static inline int esp_tls_conn_new_sync(const char *h, int hl, int port, const esp_tls_cfg_t *cfg, esp_tls_t *tls) {
15 (void)h; (void)hl; (void)port; (void)cfg; (void)tls; return -1;
16}
17static inline int esp_tls_conn_write(esp_tls_t *tls, const void *data, size_t len) {
18 (void)tls; (void)data; (void)len; return len;
19}
20static inline int esp_tls_conn_read(esp_tls_t *tls, void *data, size_t len) {
21 (void)tls; (void)data; (void)len; return 0;
22}
23static inline void esp_tls_conn_destroy(esp_tls_t *tls) { (void)tls; }
24
25#endif
diff --git a/tests/unit/stubs/esp_wifi.h b/tests/unit/stubs/esp_wifi.h
new file mode 100644
index 0000000..6aa5787
--- /dev/null
+++ b/tests/unit/stubs/esp_wifi.h
@@ -0,0 +1,40 @@
1#ifndef STUBS_ESP_WIFI_H
2#define STUBS_ESP_WIFI_H
3
4#include <stdint.h>
5#include <string.h>
6#include "esp_err.h"
7
8#define WIFI_IF_STA 0
9#define WIFI_IF_AP 1
10
11#define WIFI_AUTH_WPA2_PSK 3
12#define WIFI_AUTH_OPEN 0
13
14#define WIFI_MODE_APSTA 3
15
16typedef struct {
17 struct {
18 uint8_t ssid[32];
19 uint8_t password[64];
20 uint8_t channel;
21 uint8_t max_connection;
22 uint8_t ssid_hidden;
23 int authmode;
24 } ap;
25 struct {
26 uint8_t ssid[32];
27 uint8_t password[64];
28 int threshold;
29 struct {
30 int authmode;
31 } sta;
32 } sta;
33} wifi_config_t;
34
35static inline esp_err_t esp_wifi_set_mac(int ifx, const uint8_t *mac) { (void)ifx; (void)mac; return ESP_OK; }
36static inline esp_err_t esp_wifi_set_config(int ifx, const wifi_config_t *cfg) { (void)ifx; (void)cfg; return ESP_OK; }
37static inline esp_err_t esp_wifi_set_mode(uint8_t mode) { (void)mode; return ESP_OK; }
38static inline esp_err_t esp_wifi_start(void) { return ESP_OK; }
39
40#endif
diff --git a/tests/unit/stubs/freertos/FreeRTOS.h b/tests/unit/stubs/freertos/FreeRTOS.h
new file mode 100644
index 0000000..0fee758
--- /dev/null
+++ b/tests/unit/stubs/freertos/FreeRTOS.h
@@ -0,0 +1,11 @@
1#ifndef STUBS_FREERTOS_FREERTOS_H
2#define STUBS_FREERTOS_FREERTOS_H
3
4#include <stdint.h>
5
6static inline uint32_t xTaskGetTickCount(void) { return 0; }
7static inline void vTaskDelay(uint32_t ticks) { (void)ticks; }
8#define pdMS_TO_TICKS(ms) ((ms) / 10)
9#define portMAX_DELAY 0xFFFFFFFF
10
11#endif
diff --git a/tests/unit/stubs/freertos/event_groups.h b/tests/unit/stubs/freertos/event_groups.h
new file mode 100644
index 0000000..28f6403
--- /dev/null
+++ b/tests/unit/stubs/freertos/event_groups.h
@@ -0,0 +1,13 @@
1#ifndef STUBS_FREERTOS_EVENT_GROUPS_H
2#define STUBS_FREERTOS_EVENT_GROUPS_H
3
4#include <stdint.h>
5
6typedef void *EventGroupHandle_t;
7#define BIT0 (1 << 0)
8
9static inline EventGroupHandle_t xEventGroupCreate(void) { return (EventGroupHandle_t)1; }
10static inline uint32_t xEventGroupSetBits(EventGroupHandle_t eg, uint32_t bits) { (void)eg; return bits; }
11static inline uint32_t xEventGroupClearBits(EventGroupHandle_t eg, uint32_t bits) { (void)eg; return bits; }
12
13#endif
diff --git a/tests/unit/stubs/freertos/task.h b/tests/unit/stubs/freertos/task.h
new file mode 100644
index 0000000..3855d41
--- /dev/null
+++ b/tests/unit/stubs/freertos/task.h
@@ -0,0 +1,19 @@
1#ifndef STUBS_FREERTOS_TASK_H
2#define STUBS_FREERTOS_TASK_H
3
4#include <stdint.h>
5#include <stdlib.h>
6
7typedef void *TaskHandle_t;
8typedef void *SemaphoreHandle_t;
9
10static inline void vTaskDelete(TaskHandle_t t) { (void)t; }
11static inline SemaphoreHandle_t xSemaphoreCreateMutex(void) { return (SemaphoreHandle_t)malloc(1); }
12static inline void vSemaphoreDelete(SemaphoreHandle_t s) { free(s); }
13static inline int xSemaphoreTake(SemaphoreHandle_t s, uint32_t blk) { (void)s; (void)blk; return 1; }
14static inline int xSemaphoreGive(SemaphoreHandle_t s) { (void)s; return 1; }
15static inline int xTaskCreate(void (*fn)(void*), const char *n, uint32_t st, void *p, uint32_t pri, TaskHandle_t *h) {
16 (void)fn; (void)n; (void)st; (void)p; (void)pri; (void)h; return 1;
17}
18
19#endif
diff --git a/tests/unit/stubs/freertos/timers.h b/tests/unit/stubs/freertos/timers.h
new file mode 100644
index 0000000..7575807
--- /dev/null
+++ b/tests/unit/stubs/freertos/timers.h
@@ -0,0 +1,15 @@
1#ifndef STUBS_FREERTOS_TIMERS_H
2#define STUBS_FREERTOS_TIMERS_H
3
4#include <stdint.h>
5
6typedef void *TimerHandle_t;
7
8static inline TimerHandle_t xTimerCreate(const char *n, uint32_t pd, int ux, void *id, void *cb) {
9 (void)n; (void)pd; (void)ux; (void)id; (void)cb; return (TimerHandle_t)1;
10}
11static inline int xTimerStart(TimerHandle_t t, uint32_t blk) { (void)t; (void)blk; return 1; }
12static inline int xTimerStop(TimerHandle_t t, uint32_t blk) { (void)t; (void)blk; return 1; }
13static inline void xTimerDelete(TimerHandle_t t, uint32_t blk) { (void)t; (void)blk; }
14
15#endif
diff --git a/tests/unit/stubs/lwip/ip4_addr.h b/tests/unit/stubs/lwip/ip4_addr.h
new file mode 100644
index 0000000..174211b
--- /dev/null
+++ b/tests/unit/stubs/lwip/ip4_addr.h
@@ -0,0 +1,19 @@
1#ifndef STUBS_LWIP_IP4_ADDR_H
2#define STUBS_LWIP_IP4_ADDR_H
3
4#include <stdint.h>
5
6typedef struct {
7 uint32_t addr;
8} ip4_addr_t;
9
10typedef ip4_addr_t esp_ip4_addr_t;
11
12#define IPSTR "%d.%d.%d.%d"
13#define IP2STR(ip) ((ip)->addr & 0xff), (((ip)->addr >> 8) & 0xff), (((ip)->addr >> 16) & 0xff), (((ip)->addr >> 24) & 0xff)
14
15static inline void IP4_ADDR(esp_ip4_addr_t *ip, uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
16 ip->addr = ((uint32_t)a) | ((uint32_t)b << 8) | ((uint32_t)c << 16) | ((uint32_t)d << 24);
17}
18
19#endif
diff --git a/tests/unit/stubs/lwip/napt.h b/tests/unit/stubs/lwip/napt.h
new file mode 100644
index 0000000..c6a5ca1
--- /dev/null
+++ b/tests/unit/stubs/lwip/napt.h
@@ -0,0 +1,6 @@
1#ifndef STUBS_LWIP_NAPT_H
2#define STUBS_LWIP_NAPT_H
3
4static inline void ip_napt_enable(uint32_t num, int enable) { (void)num; (void)enable; }
5
6#endif
diff --git a/tests/unit/stubs/lwip/netdb.h b/tests/unit/stubs/lwip/netdb.h
new file mode 100644
index 0000000..b71bab8
--- /dev/null
+++ b/tests/unit/stubs/lwip/netdb.h
@@ -0,0 +1,4 @@
1#ifndef STUBS_LWIP_NETDB_H
2#define STUBS_LWIP_NETDB_H
3
4#endif
diff --git a/tests/unit/stubs/lwip/netif.h b/tests/unit/stubs/lwip/netif.h
new file mode 100644
index 0000000..461a64e
--- /dev/null
+++ b/tests/unit/stubs/lwip/netif.h
@@ -0,0 +1,4 @@
1#ifndef STUBS_LWIP_NETIF_H
2#define STUBS_LWIP_NETIF_H
3
4#endif
diff --git a/tests/unit/stubs/lwip/sockets.h b/tests/unit/stubs/lwip/sockets.h
new file mode 100644
index 0000000..44f03ac
--- /dev/null
+++ b/tests/unit/stubs/lwip/sockets.h
@@ -0,0 +1,4 @@
1#ifndef STUBS_LWIP_SOCKETS_H
2#define STUBS_LWIP_SOCKETS_H
3
4#endif
diff --git a/tests/unit/stubs/nvs_flash.h b/tests/unit/stubs/nvs_flash.h
new file mode 100644
index 0000000..4424a9a
--- /dev/null
+++ b/tests/unit/stubs/nvs_flash.h
@@ -0,0 +1,12 @@
1#ifndef STUBS_NVS_FLASH_H
2#define STUBS_NVS_FLASH_H
3
4#include "esp_err.h"
5
6#define ESP_ERR_NVS_NO_FREE_PAGES 0x1101
7#define ESP_ERR_NVS_NEW_VERSION_FOUND 0x1102
8
9static inline esp_err_t nvs_flash_init(void) { return ESP_OK; }
10static inline esp_err_t nvs_flash_erase(void) { return ESP_OK; }
11
12#endif