252 lines
8.8 KiB
Plaintext
252 lines
8.8 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-03-14T10:01:29.820846Z",
|
||
"start_time": "2026-03-14T10:01:28.106163Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"print(\"你好,世界!\")\n",
|
||
"name = input(\"请输入你的名字:\")\n",
|
||
"print(f\"欢迎你,{name}!\")"
|
||
],
|
||
"id": "eea196e830ee8847",
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"你好,世界!\n",
|
||
"欢迎你,!\n"
|
||
]
|
||
}
|
||
],
|
||
"execution_count": 2
|
||
},
|
||
{
|
||
"metadata": {
|
||
"ExecuteTime": {
|
||
"end_time": "2026-03-18T04:26:12.758229Z",
|
||
"start_time": "2026-03-18T04:26:12.018248Z"
|
||
}
|
||
},
|
||
"cell_type": "code",
|
||
"source": [
|
||
"\n",
|
||
"#!/usr/bin/env python3\n",
|
||
"\"\"\"\n",
|
||
"批量生成常用测试波形\n",
|
||
"直接运行此脚本,一次性生成多个测试文件\n",
|
||
"\"\"\"\n",
|
||
"\n",
|
||
"import subprocess\n",
|
||
"import os\n",
|
||
"import sys\n",
|
||
"import time\n",
|
||
"from pathlib import Path\n",
|
||
"\n",
|
||
"# ========== 配置区 ==========\n",
|
||
"SCRIPT_NAME = \"da4008_gen_transaction.py\" # 波形生成脚本文件名\n",
|
||
"OUTPUT_DIR = \"./wave\" # 输出目录\n",
|
||
"# ============================\n",
|
||
"\n",
|
||
"# 确保输出目录存在\n",
|
||
"os.makedirs(OUTPUT_DIR, exist_ok=True)\n",
|
||
"\n",
|
||
"# 检查波形生成脚本是否存在\n",
|
||
"if not Path(SCRIPT_NAME).is_file():\n",
|
||
" print(f\"错误:找不到脚本文件 {SCRIPT_NAME}\")\n",
|
||
" print(\"请确保该脚本与批量生成脚本在同一目录下,或修改 SCRIPT_NAME 变量。\")\n",
|
||
" sys.exit(1)\n",
|
||
"\n",
|
||
"# 测试用例定义(使用结构化参数,便于增删改)\n",
|
||
"test_cases = [\n",
|
||
" {\n",
|
||
" \"name\": \"1000Hz正弦波\",\n",
|
||
" \"params\": {\n",
|
||
" \"--type\": \"sine\",\n",
|
||
" \"--start_addr\": 0x0,\n",
|
||
" \"--length\": 262081,\n",
|
||
" \"--freq\": \"1e9\",\n",
|
||
" \"--cycles\": 1,\n",
|
||
" \"--lvds_addr\": \"0x0\",\n",
|
||
" \"--output\": f\"{OUTPUT_DIR}/lvdswave_262144_sine_1GHz.txt\"\n",
|
||
" }\n",
|
||
" },\n",
|
||
"\n",
|
||
" {\n",
|
||
" \"name\": \"测试用例3:方波\",\n",
|
||
" \"params\": {\n",
|
||
" \"--type\": \"pulse\",\n",
|
||
" \"--start_addr\": 0x0,\n",
|
||
" \"--length\": 10024,\n",
|
||
" \"--freq\": \"500e6\",\n",
|
||
" \"--duty\": 0.5,\n",
|
||
" \"--cycles\": 1,\n",
|
||
" \"--lvds_addr\": \"0x0\",\n",
|
||
" \"--output\": f\"{OUTPUT_DIR}/pulse_500m_10024.txt\"\n",
|
||
" }\n",
|
||
" },\n",
|
||
" {\n",
|
||
" \"name\": \"测试用例4:三角波\",\n",
|
||
" \"params\": {\n",
|
||
" \"--type\": \"triangle\",\n",
|
||
" \"--start_addr\": 0,\n",
|
||
" \"--length\": 12024,\n",
|
||
" \"--step\": 16,\n",
|
||
" \"--duration\": 10,\n",
|
||
" \"--cycles\": 3,\n",
|
||
" \"--lvds_addr\": \"0x0\",\n",
|
||
" \"--output\": f\"{OUTPUT_DIR}/triangle_12024.txt\"\n",
|
||
" }\n",
|
||
" },\n",
|
||
" {\n",
|
||
" \"name\": \"测试用例5:Flattop波形\",\n",
|
||
" \"params\": {\n",
|
||
" \"--type\": \"flattop\",\n",
|
||
" \"--start_addr\": 0,\n",
|
||
" \"--rise_samples\": 0x100,\n",
|
||
" \"--hold_cycles\": 5000,\n",
|
||
" \"--fall_samples\": 0x100,\n",
|
||
" \"--hold_value\": 255,\n",
|
||
" \"--cycles\": 1,\n",
|
||
" \"--lvds_addr\": \"0x0\",\n",
|
||
" \"--output\": f\"{OUTPUT_DIR}/flattop_hold5000.txt\"\n",
|
||
" }\n",
|
||
" }\n",
|
||
"\n",
|
||
"]\n",
|
||
"\n",
|
||
"def build_command(params):\n",
|
||
" \"\"\"将参数字典转换为命令行列表(避免shell注入)\"\"\"\n",
|
||
" cmd = [sys.executable, SCRIPT_NAME]\n",
|
||
" for key, value in params.items():\n",
|
||
" cmd.append(key)\n",
|
||
" cmd.append(str(value))\n",
|
||
" return cmd\n",
|
||
"\n",
|
||
"def run_test_case(case):\n",
|
||
" \"\"\"执行单个测试用例,返回成功标志和输出信息\"\"\"\n",
|
||
" name = case[\"name\"]\n",
|
||
" cmd = build_command(case[\"params\"])\n",
|
||
" cmd_str = \" \".join(cmd)\n",
|
||
"\n",
|
||
" print(f\"\\n▶ {name}\")\n",
|
||
" print(f\"命令: {cmd_str}\")\n",
|
||
"\n",
|
||
" try:\n",
|
||
" # 使用列表形式调用,安全且无shell=True\n",
|
||
" result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)\n",
|
||
" if result.returncode == 0:\n",
|
||
" print(\"✅ 成功\")\n",
|
||
" return True, result.stdout\n",
|
||
" else:\n",
|
||
" print(\"❌ 失败\")\n",
|
||
" print(f\"返回码: {result.returncode}\")\n",
|
||
" if result.stderr:\n",
|
||
" print(\"错误输出:\")\n",
|
||
" print(result.stderr)\n",
|
||
" return False, result.stderr\n",
|
||
" except subprocess.TimeoutExpired:\n",
|
||
" print(\"❌ 超时(超过30秒)\")\n",
|
||
" return False, \"执行超时\"\n",
|
||
" except Exception as e:\n",
|
||
" print(f\"❌ 异常: {e}\")\n",
|
||
" return False, str(e)\n",
|
||
"\n",
|
||
"def main():\n",
|
||
" print(\"开始批量生成测试文件...\")\n",
|
||
" print(f\"输出目录: {OUTPUT_DIR}\")\n",
|
||
" print(\"=\" * 60)\n",
|
||
"\n",
|
||
" start_time = time.time()\n",
|
||
" success_count = 0\n",
|
||
" fail_count = 0\n",
|
||
"\n",
|
||
" for i, case in enumerate(test_cases, 1):\n",
|
||
" print(f\"\\n[{i}/{len(test_cases)}] 正在生成...\")\n",
|
||
" success, _ = run_test_case(case)\n",
|
||
" if success:\n",
|
||
" success_count += 1\n",
|
||
" else:\n",
|
||
" fail_count += 1\n",
|
||
"\n",
|
||
" elapsed = time.time() - start_time\n",
|
||
" print(\"\\n\" + \"=\" * 60)\n",
|
||
" print(f\"批量生成完成!\")\n",
|
||
" print(f\"成功: {success_count}, 失败: {fail_count}, 耗时: {elapsed:.2f} 秒\")\n",
|
||
" print(f\"文件保存在 {OUTPUT_DIR} 目录下\")\n",
|
||
"\n",
|
||
"if __name__ == \"__main__\":\n",
|
||
" main()"
|
||
],
|
||
"id": "33083ea8b8420b7e",
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"开始批量生成测试文件...\n",
|
||
"输出目录: ./wave\n",
|
||
"============================================================\n",
|
||
"\n",
|
||
"[1/4] 正在生成...\n",
|
||
"\n",
|
||
"▶ 1000Hz正弦波\n",
|
||
"命令: D:\\yangshenbo\\workspace\\Document\\python_project\\da4008_case_gen\\.venv\\Scripts\\python.exe da4008_gen_transaction.py --type sine --start_addr 0 --length 262081 --freq 1e9 --cycles 1 --lvds_addr 0x0 --output ./wave/lvdswave_262144_sine_1GHz.txt\n",
|
||
"✅ 成功\n",
|
||
"\n",
|
||
"[2/4] 正在生成...\n",
|
||
"\n",
|
||
"▶ 测试用例3:方波\n",
|
||
"命令: D:\\yangshenbo\\workspace\\Document\\python_project\\da4008_case_gen\\.venv\\Scripts\\python.exe da4008_gen_transaction.py --type pulse --start_addr 0 --length 10024 --freq 500e6 --duty 0.5 --cycles 1 --lvds_addr 0x0 --output ./wave/pulse_500m_10024.txt\n",
|
||
"✅ 成功\n",
|
||
"\n",
|
||
"[3/4] 正在生成...\n",
|
||
"\n",
|
||
"▶ 测试用例4:三角波\n",
|
||
"命令: D:\\yangshenbo\\workspace\\Document\\python_project\\da4008_case_gen\\.venv\\Scripts\\python.exe da4008_gen_transaction.py --type triangle --start_addr 0 --length 12024 --step 16 --duration 10 --cycles 3 --lvds_addr 0x0 --output ./wave/triangle_12024.txt\n",
|
||
"✅ 成功\n",
|
||
"\n",
|
||
"[4/4] 正在生成...\n",
|
||
"\n",
|
||
"▶ 测试用例5:Flattop波形\n",
|
||
"命令: D:\\yangshenbo\\workspace\\Document\\python_project\\da4008_case_gen\\.venv\\Scripts\\python.exe da4008_gen_transaction.py --type flattop --start_addr 0 --rise_samples 256 --hold_cycles 5000 --fall_samples 256 --hold_value 255 --cycles 1 --lvds_addr 0x0 --output ./wave/flattop_hold5000.txt\n",
|
||
"✅ 成功\n",
|
||
"\n",
|
||
"============================================================\n",
|
||
"批量生成完成!\n",
|
||
"成功: 4, 失败: 0, 耗时: 0.73 秒\n",
|
||
"文件保存在 ./wave 目录下\n"
|
||
]
|
||
}
|
||
],
|
||
"execution_count": 94
|
||
}
|
||
],
|
||
"metadata": {
|
||
"kernelspec": {
|
||
"display_name": "Python 3",
|
||
"language": "python",
|
||
"name": "python3"
|
||
},
|
||
"language_info": {
|
||
"codemirror_mode": {
|
||
"name": "ipython",
|
||
"version": 2
|
||
},
|
||
"file_extension": ".py",
|
||
"mimetype": "text/x-python",
|
||
"name": "python",
|
||
"nbconvert_exporter": "python",
|
||
"pygments_lexer": "ipython2",
|
||
"version": "2.7.6"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 5
|
||
}
|