@mikrojs/firmware 0.4.0 → 0.5.0-pr-26.g363c07b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -64,6 +64,7 @@ idf_component_register(
64
64
  "${MIK_SRC_DIR}/mik_text_encoding.cpp"
65
65
  "${MIK_SRC_DIR}/mik_cbor.cpp"
66
66
  "${MIK_SRC_DIR}/mik_result.cpp"
67
+ "${MIK_SRC_DIR}/mik_udp.cpp"
67
68
  "${MIK_SRC_DIR}/mikrojs.cpp"
68
69
  # nanocbor CBOR codec
69
70
  "${MIK_NANOCBOR_DIR}/src/encoder.c"
@@ -130,7 +131,7 @@ include("${MIK_BYTECODE_CMAKE}")
130
131
 
131
132
  # Force linker to include self-registering native modules
132
133
  set(_MIK_MODULES cbor pin i2c spi http wifi rtc nvs_kv sntp sleep neopixel pwm uart)
133
- set(_MIK_BYTECODE_MODULES cbor env result schema fs http/helpers http/request i2c kv/nvs kv/rtc kv/shared neopixel pin pwm reader sleep spi sntp stdio stream sys test uart wifi)
134
+ set(_MIK_BYTECODE_MODULES cbor env result schema fs http/helpers http/request i2c kv/nvs kv/rtc kv/shared neopixel pin pwm reader sleep spi sntp stdio stream sys test uart udp wifi)
134
135
  if(CONFIG_BT_ENABLED)
135
136
  list(APPEND _MIK_MODULES ble)
136
137
  list(APPEND _MIK_BYTECODE_MODULES ble)
@@ -20,6 +20,7 @@ set(_MIK_TEST_SRCS
20
20
  text_encoding_test.cpp
21
21
  timers_js_test.cpp
22
22
  timers_test.cpp
23
+ udp_test.cpp
23
24
  wifi_test.cpp
24
25
  )
25
26
  if(CONFIG_BT_ENABLED)
@@ -0,0 +1,91 @@
1
+ #include "mikrojs.h"
2
+ #include "private.h"
3
+ #include "quickjs.h"
4
+ #include "unity.h"
5
+
6
+ /* native:udp lives in @mikrojs/native and is initialized eagerly via
7
+ * MIK_NewRuntime — no force-include needed. These tests are smoke-level:
8
+ * verify the module loads and a basic bind/close cycle works. Full
9
+ * roundtrip + multicast tests live host-side (ctest). */
10
+
11
+ static MIKRuntime* rt;
12
+ static JSContext* ctx;
13
+
14
+ static void setup() {
15
+ rt = MIK_NewRuntime();
16
+ ctx = MIK_GetJSContext(rt);
17
+ }
18
+
19
+ static void teardown() { MIK_FreeRuntime(rt); }
20
+
21
+ static JSValue eval_module(const char* code) {
22
+ JSValue ret = MIK_EvalModuleContent(ctx, "mikrojs/test", code, strlen(code));
23
+ if (!JS_IsException(ret)) {
24
+ JS_FreeValue(ctx, ret);
25
+ mik__execute_jobs(ctx);
26
+ }
27
+ return ret;
28
+ }
29
+
30
+ TEST_CASE("mikrojs/udp module is importable", "[modules]") {
31
+ setup();
32
+
33
+ JSValue ret = eval_module(R"(
34
+ import {bind} from "mikrojs/udp";
35
+ globalThis.__hasBind = typeof bind === "function";
36
+ )");
37
+ TEST_ASSERT_FALSE_MESSAGE(JS_IsException(ret), "Module eval should not throw");
38
+
39
+ JSValue g = JS_GetGlobalObject(ctx);
40
+ JSValue v = JS_GetPropertyStr(ctx, g, "__hasBind");
41
+ TEST_ASSERT_TRUE_MESSAGE(JS_ToBool(ctx, v), "bind should be a function");
42
+ JS_FreeValue(ctx, v);
43
+ JS_FreeValue(ctx, g);
44
+
45
+ teardown();
46
+ }
47
+
48
+ TEST_CASE("mikrojs/udp bind and close work on device", "[modules]") {
49
+ setup();
50
+
51
+ /* Drives a bind+close, holds the socket on globalThis to keep it alive
52
+ * past the IIFE, then verifies port assignment and idempotent close. */
53
+ JSValue ret = eval_module(R"(
54
+ import {bind} from "mikrojs/udp";
55
+ globalThis.__phase = "init";
56
+ (async () => {
57
+ const r = await bind({port: 0, family: 'ipv4'});
58
+ if (!r.ok) {
59
+ globalThis.__phase = "bind-fail:" + r.error.name;
60
+ return;
61
+ }
62
+ globalThis.__sock = r.value;
63
+ globalThis.__port = r.value.port;
64
+ r.value.close();
65
+ r.value.close();
66
+ globalThis.__phase = "done";
67
+ })();
68
+ )");
69
+ TEST_ASSERT_FALSE_MESSAGE(JS_IsException(ret), "Module eval should not throw");
70
+
71
+ /* Spin the loop a few times so the IIFE settles. */
72
+ for (int i = 0; i < 10; i++) {
73
+ MIK_Loop(rt);
74
+ }
75
+
76
+ JSValue g = JS_GetGlobalObject(ctx);
77
+ JSValue phase = JS_GetPropertyStr(ctx, g, "__phase");
78
+ const char* phase_str = JS_ToCString(ctx, phase);
79
+ TEST_ASSERT_EQUAL_STRING("done", phase_str);
80
+ JS_FreeCString(ctx, phase_str);
81
+ JS_FreeValue(ctx, phase);
82
+
83
+ JSValue port_v = JS_GetPropertyStr(ctx, g, "__port");
84
+ int32_t port = -1;
85
+ JS_ToInt32(ctx, &port, port_v);
86
+ TEST_ASSERT_GREATER_THAN(0, port);
87
+ JS_FreeValue(ctx, port_v);
88
+
89
+ JS_FreeValue(ctx, g);
90
+ teardown();
91
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikrojs/firmware",
3
- "version": "0.4.0",
3
+ "version": "0.5.0-pr-26.g363c07b",
4
4
  "description": "Mikro.js ESP32 firmware: ESP-IDF component, build tools, and project template",
5
5
  "keywords": [
6
6
  "esp-idf",
@@ -51,8 +51,8 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "esbuild": "^0.28.0",
54
- "@mikrojs/native": "0.4.0",
55
- "@mikrojs/quickjs": "0.4.0"
54
+ "@mikrojs/quickjs": "0.5.0-pr-26.g363c07b",
55
+ "@mikrojs/native": "0.5.0-pr-26.g363c07b"
56
56
  },
57
57
  "engines": {
58
58
  "node": ">=24.0.0"
Binary file
Binary file
Binary file
Binary file
@@ -97,7 +97,11 @@ CONFIG_ESP_ERR_TO_NAME_LOOKUP=n
97
97
  CONFIG_HAL_DEFAULT_ASSERTION_LEVEL=0
98
98
 
99
99
  # --- lwIP ---
100
- CONFIG_LWIP_IPV6=n
100
+ # IPv6 enabled so mikrojs/udp dual-stack sockets work and to keep the
101
+ # door open for Thread (which is IPv6-only). Required for AF_INET6 /
102
+ # sockaddr_in6 to be defined in lwIP headers — without it, the UDP
103
+ # native module won't even compile. Cost is roughly 5–10 KB flash.
104
+ CONFIG_LWIP_IPV6=y
101
105
 
102
106
  # --- MbedTLS: TLS 1.2 + 1.3, AES-GCM/CCM, ECDHE ---
103
107
  CONFIG_MBEDTLS_SSL_PROTO_TLS1_3=y