Skip to content

feat(starry): add mosquitto MQTT broker app with multi-level tests#1072

Merged
ZR233 merged 3 commits into
rcore-os:devfrom
zyc107109102:pr/mosquitto
Jun 2, 2026
Merged

feat(starry): add mosquitto MQTT broker app with multi-level tests#1072
ZR233 merged 3 commits into
rcore-os:devfrom
zyc107109102:pr/mosquitto

Conversation

@zyc107109102

Copy link
Copy Markdown
Contributor

mosquitto是一个开源消息代理软件,可以低开销实现物联网设备通信。starryos作为嵌入式操作系统,可以实现多个物联网设备联网通信,有一定实用价值。

本次移植并且增加了mosquitto的功能测试,包含大部分功能。

测试方法为本机开server和client,进行各种功能测试。

可能存在的问题是,qemu中难以真正实现跨网络设备的测试和验证,而且也不便在ci容器测试。所以网络测试会回环到本机,未来会尝试增加多实体机之间的测试。

概述

在 StarryOS 中添加 Mosquitto MQTT broker 应用,支持三级测试(Smoke/Normal/Stress),覆盖 MQTT 协议核心功能和 IoT 场景。

测试内容

Smoke 测试(7个场景)

  • 基本发布/订阅
  • 多主题测试
  • 通配符订阅
  • QoS 0/1 级别
  • Last Will and Testament (LWT)
  • Keep-alive 机制
  • 传感器数据模式

普通测试(12个场景)

  • 基本发布/订阅
  • 多消息传输
  • 通配符主题
  • QoS 0/1/2 级别
  • 保留消息
  • 持久化会话
  • 大消息负载(10KB)
  • 多客户端并发
  • 主题特殊字符
  • LWT 设备离线检测
  • 用户名/密码认证
  • 设备层级主题(IoT 标准模式)

压力测试(11个场景)

  • 高频消息发布/订阅(100条)
  • 多客户端并发压力(5客户端)
  • 大消息压力测试(40KB)
  • 通配符压力测试
  • 混合 QoS 压力测试
  • 持久化重启测试
  • 嵌入式设备突发测试(20设备×10消息)
  • LWT 风暴测试(20设备同时离线)

运行命令

# 运行全部测试
cargo xtask starry app run -t mosquitto --arch x86_64

# 仅 Smoke 测试
cargo xtask starry app run -t mosquitto --arch x86_64 --qemu-config qemu-x86_64-smoke.toml

# 仅普通测试
cargo xtask starry app run -t mosquitto --arch x86_64 --qemu-config qemu-x86_64-normal.toml

# 仅压力测试
cargo xtask starry app run -t mosquitto --arch x86_64 --qemu-config qemu-x86_64-stress.toml

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #1072 Review: feat(starry): add mosquitto MQTT broker app with multi-level tests

改动概述

本 PR 在 apps/starry/mosquitto/ 下新增 Mosquitto MQTT broker 应用,包含三级测试(Smoke/Normal/Stress),共 30 个测试场景。新增 11 个文件,1199 行代码,均为新增。

实现逻辑

  • prebuild.sh: 遵循 redis/nginx 的既有模式,通过 apk 安装 mosquitto 及客户端到 rootfs overlay,使用 copy_runtime_dependencies 自动处理共享库依赖。
  • build-x86_64-unknown-none.toml: 使用与 nginx 相同的显式 feature 声明模式(ax-hal/x86-pcax-driver/plat-staticvirtio-blkvirtio-net),为 mosquitto 提供网络支持。与 redis 的简洁 features = ["qemu"] 模式不同但同样有效。
  • 测试脚本: 使用 set -eu 错误处理,wait "$pid" || true 等待后台进程,grep -q 断言验证消息接收。LWT 测试正确使用 SIGKILL 触发遗嘱消息,认证测试正确配置密码文件。
  • QEMU 配置: 四个 TOML 配置分别对应默认(全部)、Smoke、Normal、Stress 级别。使用 -machine q35-m 1G-snapshot 和 virtio 设备。

验证结果

  • CI 状态: 全部 49 个 CI 检查均为 skipped(fork PR 需要 CI 审批才能运行)。
  • 本地 QEMU 验证: 无法运行。cargo xtask starry app run -t mosquitto --arch x86_64 --qemu-config qemu-x86_64-smoke.toml 在 prebuild 阶段失败:apk-tools 不在 Ubuntu 软件源中。此问题影响所有使用 apk 的 app(redis 也同样失败),是环境限制而非 PR 问题。
  • App 发现: cargo xtask starry app list 确认 mosquitto prebuild 被正确发现。

重复/重叠分析

  • Base 分支: origin/dev 上不存在 mosquitto/MQTT 相关代码。
  • 开放 PR: PR #1074(移除 AArch64 静态平台)和 PR #1075(重构 linker script)与本 PR 无关。
  • 结论: 无重复或冲突风险。

CI 失败分析

所有 CI 检查均为 skipped 状态。这是因为 PR 来自 fork(zyc107109102/tgoskits),需要项目维护者批准 CI 运行。非 PR 本身问题。

待改进项(非阻塞)

  1. shell_init_cmd 不一致: qemu-x86_64-stress.toml 使用 /bin/sh /usr/bin/mosquitto-stress-tests.sh,而 smoke/normal 配置直接使用脚本路径。建议统一。
  2. 仅支持 x86_64: 可后续添加 aarch64/riscv64 支持(参考 redis 的多架构配置)。
  3. 压力测试资源: 20 个 LWT 设备并发可能在 QEMU 中消耗大量资源,建议在 CI 中验证是否能正常完成。

总结

PR 结构合理,遵循项目既定模式(nginx build config、redis prebuild pattern),测试覆盖全面。由于环境限制无法本地运行 QEMU 验证,但代码静态分析未发现阻塞问题。建议批准后在 CI 中运行完整验证。

Powered by mimo-v2.5-pro

"-device",
"virtio-net-pci,netdev=net0",
"-netdev",
"user,id=net0",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议统一 shell_init_cmd 格式。smoke 和 normal 配置直接使用脚本路径(如 /usr/bin/mosquitto-smoke-tests.sh),而 stress 配置使用 /bin/sh 前缀。脚本本身已有 #!/bin/sh shebang,可以直接调用。建议改为:

shell_init_cmd = "/usr/bin/mosquitto-stress-tests.sh"

@mai-team-app
mai-team-app Bot requested review from ZR233 and yfblock June 1, 2026 12:41

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #1072 审查:feat(starry): add mosquitto MQTT broker app with multi-level tests

改动概述

本 PR 在 apps/starry/mosquitto/ 下新增 Mosquitto MQTT broker 应用,包含 11 个文件(1199 行纯新增),支持三级测试(Smoke/Normal/Stress),覆盖 30 个 MQTT 协议测试场景。

实现逻辑

  • prebuild.sh: 完全遵循 redis/nginx 的既定模式,通过 apk 安装 mosquitto 及客户端到 rootfs overlay,使用 copy_runtime_dependencies 自动递归解析共享库依赖。populate_overlay 正确复制 broker 二进制、客户端工具、测试脚本和默认配置。
  • build-x86_64-unknown-none.toml: 使用显式 feature 声明(ax-hal/x86-pcax-driver/plat-staticvirtio-blkvirtio-net),与 redis 的 features = ["qemu"] 模式不同但同样有效,且更清晰地表明了网络依赖。
  • 测试脚本: 三个测试脚本均使用 set -eu 错误处理,trap on_exit EXIT 确保清理,wait "$pid" || true 正确等待后台进程,grep -q 断言验证消息接收。LWT 测试正确使用 SIGKILL 触发遗嘱消息(clean disconnect 不会触发 LWT),认证测试正确配置密码文件。
  • QEMU 配置: 四个 TOML 配置分别对应默认(全部)、Smoke、Normal、Stress 级别。success_regex/fail_regex 准确匹配测试输出标记。压力测试 timeout=3600s 合理。
  • test_mosquitto.sh: 统一入口,按序运行 Smoke → Normal → Stress 三个级别,success_regex 匹配 ALL MOSQUITTO TESTS PASSED

验证结果

  • App 发现: cargo xtask starry app list 确认 mosquitto prebuild 在 PR 分支中被正确发现。
  • QEMU 验证: 无法在当前环境运行。cargo xtask starry app run -t mosquitto --arch x86_64 --qemu-config qemu-x86_64-smoke.toml 在 prebuild 阶段失败:E: Unable to locate package apk-tools。已验证 redis 同样失败(相同的环境限制),这不是 PR 问题。
  • CI 状态: 所有 CI 检查为 skipped(fork PR 需要维护者批准才能运行 CI)。
  • 代码审查: 测试脚本结构正确,遵循项目模式,错误处理完善。

重复/重叠分析

  • Base 分支: origin/dev 上不存在 mosquitto/MQTT 相关代码。
  • 开放 PR: PR #1074(移除 AArch64 静态平台)和 PR #1075(重构 linker script)与本 PR 完全无关。
  • 结论: 无重复或冲突风险。

CI 失败分析

所有 CI 检查为 skipped 状态,因为 PR 来自 fork(zyc107109102/tgoskits),需要项目维护者批准 CI 运行。非 PR 本身问题。

前次审查评论处理

前次 bot 审查遗留的 inline comment 建议统一 shell_init_cmd 格式(stress 使用 /bin/sh 前缀而 smoke/normal 不使用)。经检查,redis 的 qemu-x86_64-stress.toml 同样使用 shell_init_cmd = "/bin/sh /usr/bin/redis-stress-tests.sh" 模式,因此本 PR 的 stress 配置实际上与既有模式一致。该建议为非阻塞性风格偏好,不影响功能。

总结

PR 结构合理,完全遵循项目既定模式(redis prebuild pattern、nginx build config pattern),测试覆盖全面(7+12+11=30 个场景),应用正确放置在 apps/starry/mosquitto/ 下。环境限制导致无法本地运行 QEMU 验证,但这是所有 apk-based app 的共同限制。代码静态分析未发现阻塞问题。建议批准。

Powered by mimo-v2.5-pro

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #1072 审查:feat(starry): add mosquitto MQTT broker app with multi-level tests

改动概述

本 PR 在 apps/starry/mosquitto/ 下新增 Mosquitto MQTT broker 应用,包含 11 个文件(1199 行纯新增),支持三级测试(Smoke/Normal/Stress),覆盖 30 个 MQTT 协议测试场景。

实现逻辑

  • prebuild.sh:遵循 redis 的既定模式,通过 apk 安装 mosquitto 及客户端到 rootfs overlay,使用 copy_runtime_dependencies 递归解析共享库依赖,populate_overlay 正确复制 broker 二进制、客户端工具、测试脚本和默认配置。
  • build-x86_64-unknown-none.toml:使用显式 feature 声明(ax-hal/x86-pcax-driver/plat-staticvirtio-blkvirtio-net),比 redis 的 features = ["qemu"] 更清晰地声明了网络依赖,但功能等效。
  • 测试脚本:三个脚本均使用 set -eu + trap on_exit EXIT 正确处理错误和清理,LWT 测试正确使用 SIGKILL 触发遗嘱消息,认证测试正确配置密码文件。run_publisher/run_subscriber 函数封装合理。
  • QEMU 配置:四个 TOML 配置分别对应默认(全部)、Smoke、Normal、Stress 级别,fail_regex 覆盖 panic 和各级失败标记。

发现的阻塞性问题

success_regextest_mosquitto.sh 输出不匹配:默认配置 qemu-x86_64.tomlsuccess_regex^ALL MOSQUITTO TESTS PASSED\s*$,但 test_mosquitto.sh 输出 echo "===== ALL MOSQUITTO TESTS PASSED ====="(带装饰前缀/后缀),正则永远无法匹配。这意味着使用默认配置运行全部测试时,runner 无法检测成功,最终会超时失败。详见 inline comment。

CI 状态

所有 49 个 CI 检查均为 skipped(fork PR 需维护者批准才能运行),非 PR 本身问题。

本地验证

  • App 发现cargo xtask starry app list 确认 mosquitto prebuild 被正确发现。
  • QEMU 验证:环境缺少 apk-tools,无法运行 prebuild(影响所有基于 apk 的 app,redis 同样失败),属于环境限制。

重复/重叠分析

  • Base 分支 origin/dev 上不存在 mosquitto/MQTT 相关代码。
  • 已检查开放 PR,PR #1074(移除 AArch64 静态平台)和 PR #1075(重构 linker script)与本 PR 无关。
  • 无重复或冲突风险。

前次审查评论

前次 bot 审查遗留的 inline comment 建议统一 shell_init_cmd 格式(stress 使用 /bin/sh 前缀)。经检查 redis 的 stress 配置同样使用 /bin/sh 前缀模式,因此本 PR 的 stress 配置与既有模式一致,该建议为非阻塞性偏好。本次审查不重复此建议。

总结

PR 整体结构合理,遵循项目既定模式,测试覆盖全面。但默认 QEMU 配置的 success_regex 存在匹配 bug,需要修复后才能保证默认测试命令正常工作。修复后建议重新验证。

Powered by mimo-v2.5-pro

Comment thread apps/starry/mosquitto/test_mosquitto.sh Outdated
…to.sh

The success_regex in qemu-x86_64.toml expects ^ALL MOSQUITTO TESTS PASSED
but the script was echoing ===== ALL MOSQUITTO TESTS PASSED =====, causing
the runner to never detect success and timeout.

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #1072 审查:feat(starry): add mosquitto MQTT broker app with multi-level tests

改动概述

本 PR 在 apps/starry/mosquitto/ 下新增 Mosquitto MQTT broker 应用,包含 11 个文件(1199 行纯新增),支持三级测试(Smoke/Normal/Stress),覆盖 30 个 MQTT 协议测试场景。纯新增,不修改任何现有代码。

实现逻辑

  • prebuild.sh:完全遵循 redis 的既定模式,通过 apk 安装 mosquitto 及客户端到 rootfs overlay,使用 copy_runtime_dependencies 递归解析共享库依赖,populate_overlay 正确复制 broker 二进制、客户端工具(mosquitto_pub/sub/passwd)、测试脚本和默认配置。
  • build-x86_64-unknown-none.toml:使用显式 feature 声明(ax-hal/x86-pcqemuax-driver/plat-staticvirtio-blkvirtio-net),比 redis 的 features = ["qemu"] 更明确声明了网络依赖,功能等效。
  • 测试脚本:三个脚本均使用 set -eu + trap on_exit EXIT 正确处理错误和清理。LWT 测试正确使用 SIGKILL 触发遗嘱消息(clean disconnect 不触发 LWT)。认证测试正确配置密码文件。run_publisher/run_subscriber 函数封装合理。
  • QEMU 配置:四个 TOML 配置分别对应默认(全部)、Smoke、Normal、Stress 级别。success_regex/fail_regex 与各脚本输出标记完全对齐。压力测试 timeout=3600s 合理。
  • test_mosquitto.sh:统一入口,按序运行 Smoke → Normal → Stress。最新提交已修复输出标记格式,success_regex 匹配正确。

前次审查评论处理

前次 bot 审查(review #4406120317)在 test_mosquitto.sh 第 16 行标记了阻塞性 Bug:success_regex 与实际输出不匹配(正则要求行首 ALL MOSQUITTO TESTS PASSED,但输出带 ===== 前缀)。

已修复:当前 HEAD(ddcb8f4b)已将该行改为 echo "ALL MOSQUITTO TESTS PASSED",与正则 (?m)^ALL MOSQUITTO TESTS PASSED\s*$ 完全匹配。验证结果:

  • qemu-x86_64.tomlsuccess_regex = "(?m)^ALL MOSQUITTO TESTS PASSED\s*$"echo "ALL MOSQUITTO TESTS PASSED"
  • qemu-x86_64-smoke.tomlsuccess_regex = "(?m)^MOSQUITTO_SMOKE_TEST_PASSED\s*$" ↔ 对应脚本 ✓
  • qemu-x86_64-normal.tomlsuccess_regex = "(?m)^MOSQUITTO_TEST_PASSED\s*$" ↔ 对应脚本 ✓
  • qemu-x86_64-stress.tomlsuccess_regex = "(?m)^MOSQUITTO_STRESS_TEST_PASSED\s*$" ↔ 对应脚本 ✓

前次审查遗留的 inline comment(shell_init_cmd 格式不一致)为非阻塞性风格偏好。redis 的 stress 配置同样使用 /bin/sh 前缀模式,本 PR 与既有模式一致。

CI 状态

所有 CI 检查为 skipped(fork PR 需维护者批准才能运行),非 PR 本身问题。

本地验证

  • App 发现cargo xtask starry app list 确认 mosquitto prebuild 被正确发现。
  • QEMU 验证:环境缺少 apk-tools,无法运行 prebuild(影响所有基于 apk 的 app,redis 同样失败),属于环境限制而非 PR 问题。
  • HEAD 一致性:本地 clone SHA ddcb8f4 与远程 PR head 一致。

重复/重叠分析

  • Base 分支 origin/dev 上不存在 mosquitto/MQTT 相关代码。
  • 已检查开放 PR,PR #1074(移除 AArch64 静态平台)和 PR #1075(重构 linker script)与本 PR 完全无关。
  • 无重复或冲突风险。

非阻塞建议

  1. 仅支持 x86_64:可后续添加 aarch64/riscv64 支持(参考 redis 的多架构配置)。
  2. 压力测试资源:20 个 LWT 设备并发可能在 QEMU 中消耗较多资源,建议在 CI 中验证是否能正常完成。

总结

PR 结构合理,完全遵循项目既定模式(redis prebuild pattern、nginx build config pattern),测试覆盖全面(7+12+11=30 个场景),应用正确放置在 apps/starry/mosquitto/ 下。前次审查的阻塞性 success_regex Bug 已在最新提交中修复。代码静态分析未发现阻塞问题。建议批准。

Powered by mimo-v2.5-pro

@ZR233 ZR233 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本次审查基于当前 head ddcb8f4b29ef494135ef9fb6cdd469aa517887dc

该 PR 在 apps/starry/mosquitto/ 下新增 Mosquitto QEMU app 场景,包括 x86_64 构建配置、默认/Smoke/Normal/Stress 四个 QEMU 配置、prebuild overlay 脚本,以及三个分层测试脚本和统一入口。实现上沿用了现有 Redis app 的 apk staging + overlay 注入模式:先从 Alpine rootfs 提取 staging root,再安装 mosquittomosquitto-clients,复制 broker、client 工具、运行时依赖库和测试脚本到 app rootfs overlay。测试脚本使用明确的成功/失败标记,QEMU 配置中的 success_regex/fail_regex 与当前输出一致。

本地验证:

  • cargo fmt --all -- --check:通过。
  • sh -n apps/starry/mosquitto/test_mosquitto.sh apps/starry/mosquitto/mosquitto-smoke-tests.sh apps/starry/mosquitto/mosquitto-tests.sh apps/starry/mosquitto/mosquitto-stress-tests.sh && bash -n apps/starry/mosquitto/prebuild.sh:通过。
  • git diff --check origin/dev...HEAD:通过。
  • cargo xtask starry app list:通过,确认 qemu mosquitto prebuild 能被发现。
  • cargo xtask starry app run -t mosquitto --arch x86_64 --qemu-config qemu-x86_64-smoke.toml:通过,输出 MOSQUITTO_SMOKE_TEST_PASSED 并匹配成功正则。
  • cargo xtask starry app run -t mosquitto --arch x86_64:通过,Smoke/Normal/Stress 全部完成,输出 ALL MOSQUITTO TESTS PASSED 并匹配成功正则。

本机没有系统级 apk 且当前用户不能使用 apt-get 安装宿主包;为了验证 app runner 的真实路径,我临时下载 apk-tools-static/tmp 并通过 PATH 提供 apk。在该环境下 prebuild、rootfs 注入、StarryOS 构建和 QEMU 运行均完成。debugfs rdump 过程中出现的 ownership warning 是非 root 解包已有 rootfs 元数据时的宿主权限提示,未影响 overlay 注入和 QEMU 测试结果。

CI 状态:当前检查中 container 侧 Check formattingRun clippyRun sync-lintTest starry x86_64 qemuTest with std 等关键检查为通过;部分 host/container 互斥矩阵项为 skipped,属于该 workflow 的选择结果,不是 PR 相关失败。

重复/重叠分析:

  • origin/dev 上没有 mosquitto/MQTT 相关 app 或测试实现。
  • 搜索开放 PR 后,只有 #1072 本身和 #1024 命中相关关键词。#1024 是 x86_64 动态平台/CI 方向的大范围改动,不新增 Mosquitto,也不改本 PR 的文件;它与本 PR没有同文件冲突。若 #1024 先合入,后续 rebase 时可以顺手检查本 app 的 x86_64 build config 是否也要跟随动态平台方向,这属于非阻塞的后续一致性问题。

前次 success_regextest_mosquitto.sh 输出不匹配的问题已由当前 head 修复,我已将对应 outdated review thread 标记为 resolved。另一个 qemu-x86_64-stress.tomlshell_init_cmd 是否带 /bin/sh 的线程仍未解决;现有 Redis stress 配置也使用 /bin/sh /usr/bin/... 这种模式,因此这里不构成功能阻塞。

未发现需要阻塞合入的问题。

@ZR233
ZR233 merged commit d4f1725 into rcore-os:dev Jun 2, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants