Files
CCSDS_study/test/netzob_test_folder_analysis.md
2026-05-05 21:54:35 +08:00

107 lines
4.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
以下是 `/home/zjz/CCSDS_study/netzob-030/test` 目录的详细分析:
---
## 目录结构
```
test/
├── README_TEST.rst
├── resources/
│ ├── files/ # 原始消息文件dat/txt
│ ├── pcaps/ # PCAP抓包文件
│ └── test_netzob/ # 各模块专用测试向量
│ ├── test_Checksums/ # CRC测试向量
│ ├── test_Hashes/ # NIST CAVS哈希测试向量
│ └── test_Hmacs/ # NIST HMAC测试向量
└── src/
├── common/ # 测试基础设施
└── test_netzob/ # 所有测试模块
```
---
## 测试入口与基础设施
**`suite_global.py`** — 全局入口,当前**只激活了 `suite_DocTests`**,其余套件被注释掉。
**`NetzobTestCase.py`** — 所有测试的基类,继承 `unittest.TestCase`
**`xmlrunner.py`** — JUnit 兼容的 XML 报告输出器,用于 CI 集成。
---
## 核心测试套件
### 1. suite_DocTests唯一激活的套件
从 50+ 个源码模块的 docstring 中提取 doctest覆盖
| 模块类别 | 代表模块 |
| ----------- | ------------------------------------------------------------ |
| 类型系统 | `String`, `Integer`, `BitArray`, `Raw`, `IPv4`, `Timestamp` |
| 词汇表/格式 | `Symbol`, `Field`, `Protocol`, `Alt`, `Agg`, `Repeat` |
| 字段切分 | `FieldSplitStatic`, `FieldSplitAligned`, `FieldSplitDelimiter` |
| 聚类推断 | `ClusterByKeyField`, `ClusterByAlignment`, `ClusterBySize` |
| 密码学字段 | HMAC×5, Hash×6, CRC×6 |
| 状态机 | `State`, `Transition`, `Automata`, `AbstractionLayer` |
| 模糊测试 | 13种 Mutator + 4种 Generator |
| 协议仿真 | `Actor`, `TCPServer/Client`, `UDPServer/Client`, `SSLClient` |
| 导入导出 | `PCAPImporter`, `FileImporter` |
---
### 2. test_Tutorials教程集成测试
| 文件 | 功能 |
| ---------------------------- | ---------------------------------------------------- |
| `test_ICMP.py` | 构建 ICMP 报文,含 CRC16 自动计算校验和 |
| `test_USBMouseProtocol.py` | 对 USB 鼠标数据包做 `splitStatic()` 字段推断 |
| `test_ImportPCAP.py` | 从 `botnet_irc_bot.pcap` 导入17条消息测试 BPF 过滤 |
| `test_StaticFieldSlicing.py` | 不同粒度SIZE_8/16和合并策略的字段切分 |
| `test_ManualFieldStatic.py` | 自动切分后手动 `mergeFields()` 合并字段 |
---
### 3. 密码学正确性测试(使用 NIST 标准向量)
**`test_Checksums.py`** — 6种CRCCRC16、CRC16DNP、CRC16Kermit、CRC16SICK、CRC32、CRCCCITT
**`test_Hashes.py`** — 6种哈希MD5、SHA1、SHA2-224/256/384/512短消息+长消息)
**`test_Hmacs.py`** — 5种HMACHMAC-SHA1/224/256/384/512
验证方式:构建 `Symbol([data_field, crypto_field])``specialize()` 后与 NIST 预期值比对。
---
### 4. test_Common单元测试
| 文件 | 测试内容 |
| ------------------------ | ------------------------------------------------------------ |
| `test_Field.py` | Field 的7种属性格式/字节序/符号/编码/可视化/变换函数) |
| `test_Encoding.py` | FormatFunction 在 HEX/STRING/DECIMAL/OCTAL/BINARY × 3种单位大小下的输出 |
| `test_TypeIdentifier.py` | 自动识别数字/字母/Base64/十六进制字符串类型 |
| `test_Endianness.py` | 字节序常量值验证 |
---
### 5. test_Alignment对齐算法
- **`test_Needleman.py`** — Needleman-Wunsch 语义对齐,含回归测试(验证已知 bug 不再出现)
- **`test_UPGMA.py`** — UPGMA 层次聚类,验证法语问候消息能正确分组
- **`test_NeedlemanInC.py` / `test_UPGMAInC.py`** — 对应 C 语言加速版本的测试
---
### 6. 其他
**`test_public_api.py`** — 通过 AST 解析验证所有 `@public_api` 方法都有完整类型注解(当前宽松模式,失败只打印不报错)。
**`test_Export/test_ScapyExporter.py`** — 验证将 Symbol 导出为 Scapy 协议定义 Python 文件。
---
## 总结
测试目录以 **doctest 为主要测试方式**测试即文档辅以密码学正确性测试NIST 标准向量)和教程式集成测试。当前只有 `suite_DocTests` 被激活其余套件处于注释状态。密码学模块Hash/HMAC/CRC的测试最为严格使用官方标准向量逐条验证。