data(benchmark): 全量重生成 5544 题(M5 扩量收尾 + 清理旧 so-* case + 中间报告)
- 工作树落到 5544 题终态:新增 tros-*/ros2-node + arm-linux 全类目 case 新增 ~17572 文件(8166 py / 4873 md / 3124 yaml / 1166 c / 40 cpp / 66 cmake) - 清理旧 Stack Overflow 源 case:so-embedded-linux/so-gpio/so-spi/so-i2c 整目录移除(148 个 so-embedded-linux case 全删,工作树删除 ~1958 文件) - 清理生成时中间报告:_generation_stats.json / _report.json / _validation_report.json - held_out 标记更新 - 生成器三处修复见前两提交(py_resource_leak 空块 / cache_flush_remover 断 C / syn-arm 模板缺引号) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
55c43d233d
commit
52e629d64b
@ -1,22 +0,0 @@
|
||||
{
|
||||
"total_seeds": 247,
|
||||
"transformed": 247,
|
||||
"passed": 234,
|
||||
"rejected": 13,
|
||||
"mutations_generated": 156,
|
||||
"rejections": [
|
||||
"syn-arm-004: Tagged 'gpio_init_order' but missing GPIO ops",
|
||||
"syn-arm-039: Tagged 'gpio_init_order' but missing GPIO ops",
|
||||
"syn-arm-040: Tagged 'gpio_init_order' but missing GPIO ops",
|
||||
"syn-arm-041: Tagged 'gpio_init_order' but missing GPIO ops",
|
||||
"syn-arm-042: Tagged 'gpio_init_order' but missing GPIO ops",
|
||||
"syn-arm-043: Tagged 'gpio_init_order' but missing GPIO ops",
|
||||
"syn-arm-044: Tagged 'gpio_init_order' but missing GPIO ops",
|
||||
"syn-arm-045: Tagged 'gpio_init_order' but missing GPIO ops",
|
||||
"syn-arm-046: Tagged 'gpio_init_order' but missing GPIO ops",
|
||||
"syn-arm-047: Tagged 'gpio_init_order' but missing GPIO ops",
|
||||
"syn-arm-048: Tagged 'gpio_init_order' but missing GPIO ops",
|
||||
"syn-arm-099: Tagged 'gpio_init_order' but missing GPIO ops",
|
||||
"syn-arm-100: Tagged 'volatile' but not found in reference code"
|
||||
]
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@ -1,42 +0,0 @@
|
||||
{
|
||||
"total_cases": 784,
|
||||
"by_capability": {
|
||||
"hw-config": 6,
|
||||
"compile-deploy": 3,
|
||||
"debug-diag": 162,
|
||||
"code-gen": 435,
|
||||
"ros2-node": 88,
|
||||
"model-deploy": 90
|
||||
},
|
||||
"by_difficulty": {
|
||||
"easy": 595,
|
||||
"medium": 189
|
||||
},
|
||||
"by_platform": {
|
||||
"arm64-linux": 782,
|
||||
"rdk-x5": 2
|
||||
},
|
||||
"by_source": {
|
||||
"synthetic": 215,
|
||||
"mutation:isr_block_injector": 24,
|
||||
"mutation:null_check_remover": 33,
|
||||
"mutation:volatile_remover": 64,
|
||||
"mutation:lock_remover": 15,
|
||||
"mutation:cache_flush_remover": 2,
|
||||
"mutation:init_order_shuffler": 1,
|
||||
"man-pages": 41,
|
||||
"stackoverflow": 307,
|
||||
"rdk_native": 2,
|
||||
"ros2-answers": 22,
|
||||
"mutation:py_missing_shutdown": 4,
|
||||
"mutation:py_exception_swallow": 8,
|
||||
"mutation:py_qos_mismatch": 2,
|
||||
"mutation:py_quantization_error": 4,
|
||||
"oe-docs": 21,
|
||||
"github:D-Robotics/rdk_model_zoo": 19
|
||||
},
|
||||
"by_visibility": {
|
||||
"public": 627,
|
||||
"draft": 157
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L3 HIL Behavior Checks for ldd3-alloc-pages-free-order.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
Verifies deployed program behavior on RDK board via DGAgent SSH.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def ssh_exec(board_id, command, timeout=10):
|
||||
"""Execute command on board via DGAgent dg_ssh_exec tool."""
|
||||
result = subprocess.run(
|
||||
["pi", "tool", "dg_ssh_exec",
|
||||
"--board", board_id, "--command", command,
|
||||
"--timeout", str(timeout)],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
return result.stdout, result.stderr, result.returncode
|
||||
|
||||
|
||||
def check_binary_exists(board_id, remote_path):
|
||||
"""Check if deployed binary exists."""
|
||||
stdout, _, _ = ssh_exec(board_id, f"test -f {remote_path} && echo EXISTS")
|
||||
return "EXISTS" in stdout
|
||||
|
||||
|
||||
def check_program_runs(board_id, remote_path):
|
||||
"""Check program starts without crash."""
|
||||
stdout, stderr, rc = ssh_exec(board_id, f"timeout 5 {remote_path} 2>&1 | head -5")
|
||||
return rc is not None
|
||||
|
||||
|
||||
def run_all_checks(board_id="rdk-x5", remote_path="/opt/ebd_harness/ldd3-alloc-pages-free-order"):
|
||||
"""Run all L3 behavior checks."""
|
||||
results = []
|
||||
results.append({"check": "binary_exists", "pass": check_binary_exists(board_id, remote_path)})
|
||||
results.append({"check": "program_runs", "pass": check_program_runs(board_id, remote_path)})
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
board = sys.argv[1] if len(sys.argv) > 1 else "rdk-x5"
|
||||
results = run_all_checks(board_id=board)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L0 Static Analysis Checks for ldd3-alloc-pages-free-order.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
def check_memory_leak(source_file):
|
||||
"""Check that malloc/free are balanced."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
allocs = content.count("malloc(") + content.count("calloc(") + content.count("realloc(")
|
||||
frees = content.count("free(")
|
||||
if allocs > frees:
|
||||
return {"check": "memory_leak", "pass": False,
|
||||
"detail": f"Allocated {allocs} times but only freed {frees} times"}
|
||||
return {"check": "memory_leak", "pass": True}
|
||||
|
||||
def check_resource_cleanup(source_file):
|
||||
"""Check that all opened resources are closed."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
opens = content.count("open(") + content.count("fopen(")
|
||||
closes = content.count("close(") + content.count("fclose(")
|
||||
if opens > closes:
|
||||
return {"check": "resource_cleanup", "pass": False,
|
||||
"detail": f"Opened {opens} resources but only closed {closes}"}
|
||||
return {"check": "resource_cleanup", "pass": True}
|
||||
|
||||
def run_all_checks(source_file):
|
||||
"""Run all L0 checks."""
|
||||
results = []
|
||||
results.append(check_memory_leak(source_file))
|
||||
results.append(check_resource_cleanup(source_file))
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
source = sys.argv[1] if len(sys.argv) > 1 else "reference/main.c"
|
||||
results = run_all_checks(source)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,25 @@
|
||||
id: ldd3-alloc-pages-free-order
|
||||
capability: code-gen
|
||||
difficulty: medium
|
||||
platform: arm64-linux
|
||||
build_system: makefile
|
||||
implicit_knowledge:
|
||||
- __free_pages
|
||||
- alloc_pages
|
||||
- memory_leak
|
||||
- resource_management
|
||||
paired_case: null
|
||||
embed_gap_metric: false
|
||||
eval_layers:
|
||||
l0_static: true
|
||||
l1_compile: true
|
||||
l2_simulate: false
|
||||
l3_hil: true
|
||||
l4_mutation: false
|
||||
max_iterations: 10
|
||||
max_tool_calls_per_iteration: 30
|
||||
timeout_seconds: 600
|
||||
source: ldd3
|
||||
source_url: https://lwn.net/Kernel/LDD3/
|
||||
visibility: public
|
||||
line: arm-linux
|
||||
@ -0,0 +1,26 @@
|
||||
# alloc_pages: 按阶分配多页与 __free_pages
|
||||
|
||||
## 目标
|
||||
|
||||
用 alloc_pages(GFP_KERNEL, order) 分配 2^order 页,read 返回页数,write 改变 order 重新分配(先释放旧的)。卸载 __free_pages(page, order)。展示页分配器资源管理。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后 write order=2 分配 4 页,read 返回 4;改 write order=0 释放旧 4 页分配 1 页,read 返回 1;rmmod __free_pages 无泄漏无 'bad page' 警告。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 动态分配的内存必须在所有退出路径上释放
|
||||
- 所有打开的文件描述符/资源必须在所有退出路径上正确关闭
|
||||
@ -0,0 +1,21 @@
|
||||
# alloc_pages: 按阶分配多页与 __free_pages
|
||||
|
||||
## 目标
|
||||
|
||||
用 alloc_pages(GFP_KERNEL, order) 分配 2^order 页,read 返回页数,write 改变 order 重新分配(先释放旧的)。卸载 __free_pages(page, order)。展示页分配器资源管理。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后 write order=2 分配 4 页,read 返回 4;改 write order=0 释放旧 4 页分配 1 页,read 返回 1;rmmod __free_pages 无泄漏无 'bad page' 警告。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
@ -0,0 +1,64 @@
|
||||
/* ldd3-alloc-pages-free-order: 按阶页分配 */
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/gfp.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
struct apctx { struct page *pg; unsigned int order; struct cdev cdev; };
|
||||
static struct apctx ap;
|
||||
static dev_t devno;
|
||||
|
||||
static void ap_release(struct apctx *d)
|
||||
{
|
||||
if (d->pg) { __free_pages(d->pg, d->order); d->pg = NULL; }
|
||||
}
|
||||
|
||||
static ssize_t ap_write(struct file *f, const char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
unsigned int order;
|
||||
struct page *np;
|
||||
(void)f; (void)o;
|
||||
if (c < sizeof(unsigned int)) return -EINVAL;
|
||||
if (get_user(order, (unsigned int __user *)u)) return -EFAULT;
|
||||
if (order > 6) return -EINVAL;
|
||||
np = alloc_pages(GFP_KERNEL, order);
|
||||
if (!np) return -ENOMEM;
|
||||
ap_release(&ap);
|
||||
ap.pg = np; ap.order = order;
|
||||
return sizeof(unsigned int);
|
||||
}
|
||||
|
||||
static ssize_t ap_read(struct file *f, char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
unsigned long npg;
|
||||
(void)f; (void)o;
|
||||
if (c < sizeof(unsigned long)) return -EINVAL;
|
||||
npg = ap.pg ? (1UL << ap.order) : 0;
|
||||
return put_user(npg, (unsigned long __user *)u) ? -EFAULT : sizeof(unsigned long);
|
||||
}
|
||||
|
||||
static int ap_open(struct inode *i, struct file *f) { (void)i; (void)f; return 0; }
|
||||
static const struct file_operations apfops = {
|
||||
.owner = THIS_MODULE, .open = ap_open, .read = ap_read, .write = ap_write,
|
||||
};
|
||||
|
||||
static int __init ap_init(void)
|
||||
{
|
||||
int err = alloc_chrdev_region(&devno, 0, 1, "scullallocpg");
|
||||
if (err) return err;
|
||||
cdev_init(&ap.cdev, &apfops);
|
||||
ap.cdev.owner = THIS_MODULE;
|
||||
err = cdev_add(&ap.cdev, devno, 1);
|
||||
if (err) unregister_chrdev_region(devno, 1);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void __exit ap_exit(void) { ap_release(&ap); cdev_del(&ap.cdev); unregister_chrdev_region(devno, 1); }
|
||||
|
||||
module_init(ap_init);
|
||||
module_exit(ap_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("LDD3");
|
||||
MODULE_DESCRIPTION("scull alloc pages order");
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L3 HIL Behavior Checks for ldd3-allow-signal-deny-sigio.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
Verifies deployed program behavior on RDK board via DGAgent SSH.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def ssh_exec(board_id, command, timeout=10):
|
||||
"""Execute command on board via DGAgent dg_ssh_exec tool."""
|
||||
result = subprocess.run(
|
||||
["pi", "tool", "dg_ssh_exec",
|
||||
"--board", board_id, "--command", command,
|
||||
"--timeout", str(timeout)],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
return result.stdout, result.stderr, result.returncode
|
||||
|
||||
|
||||
def check_binary_exists(board_id, remote_path):
|
||||
"""Check if deployed binary exists."""
|
||||
stdout, _, _ = ssh_exec(board_id, f"test -f {remote_path} && echo EXISTS")
|
||||
return "EXISTS" in stdout
|
||||
|
||||
|
||||
def check_program_runs(board_id, remote_path):
|
||||
"""Check program starts without crash."""
|
||||
stdout, stderr, rc = ssh_exec(board_id, f"timeout 5 {remote_path} 2>&1 | head -5")
|
||||
return rc is not None
|
||||
|
||||
|
||||
def run_all_checks(board_id="rdk-x5", remote_path="/opt/ebd_harness/ldd3-allow-signal-deny-sigio"):
|
||||
"""Run all L3 behavior checks."""
|
||||
results = []
|
||||
results.append({"check": "binary_exists", "pass": check_binary_exists(board_id, remote_path)})
|
||||
results.append({"check": "program_runs", "pass": check_program_runs(board_id, remote_path)})
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
board = sys.argv[1] if len(sys.argv) > 1 else "rdk-x5"
|
||||
results = run_all_checks(board_id=board)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L0 Static Analysis Checks for ldd3-allow-signal-deny-sigio.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
def check_resource_cleanup(source_file):
|
||||
"""Check that all opened resources are closed."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
opens = content.count("open(") + content.count("fopen(")
|
||||
closes = content.count("close(") + content.count("fclose(")
|
||||
if opens > closes:
|
||||
return {"check": "resource_cleanup", "pass": False,
|
||||
"detail": f"Opened {opens} resources but only closed {closes}"}
|
||||
return {"check": "resource_cleanup", "pass": True}
|
||||
|
||||
def check_signal_safety(source_file):
|
||||
"""Check that signal handler only uses async-signal-safe functions."""
|
||||
import re
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
handler_match = re.search(r'void\s+\w*[Ss]ignal\w*\s*\([^)]*\)\s*\{([^}]*)\}', content)
|
||||
if not handler_match:
|
||||
return {"check": "signal_safety", "pass": True, "detail": "No signal handler found"}
|
||||
handler_body = handler_match.group(1)
|
||||
unsafe = ["printf", "malloc", "free", "fopen", "sleep", "usleep", "fread", "fwrite"]
|
||||
found = [f for f in unsafe if f + "(" in handler_body]
|
||||
if found:
|
||||
return {"check": "signal_safety", "pass": False,
|
||||
"detail": f"Unsafe calls in signal handler: {found}"}
|
||||
return {"check": "signal_safety", "pass": True}
|
||||
|
||||
def run_all_checks(source_file):
|
||||
"""Run all L0 checks."""
|
||||
results = []
|
||||
results.append(check_resource_cleanup(source_file))
|
||||
results.append(check_signal_safety(source_file))
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
source = sys.argv[1] if len(sys.argv) > 1 else "reference/main.c"
|
||||
results = run_all_checks(source)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,25 @@
|
||||
id: ldd3-allow-signal-deny-sigio
|
||||
capability: code-gen
|
||||
difficulty: hard
|
||||
platform: arm64-linux
|
||||
build_system: makefile
|
||||
implicit_knowledge:
|
||||
- allow_signal
|
||||
- kthread_stop
|
||||
- resource_management
|
||||
- signal_safety
|
||||
paired_case: null
|
||||
embed_gap_metric: false
|
||||
eval_layers:
|
||||
l0_static: true
|
||||
l1_compile: true
|
||||
l2_simulate: false
|
||||
l3_hil: true
|
||||
l4_mutation: false
|
||||
max_iterations: 10
|
||||
max_tool_calls_per_iteration: 30
|
||||
timeout_seconds: 600
|
||||
source: ldd3
|
||||
source_url: https://lwn.net/Kernel/LDD3/
|
||||
visibility: public
|
||||
line: arm-linux
|
||||
@ -0,0 +1,26 @@
|
||||
# allow_signal/deny_signal: 内核线程信号控制
|
||||
|
||||
## 目标
|
||||
|
||||
内核线程用 allow_signal(SIGKILL) 允许接收致命信号,wait 循环中 signal_pending 退出;卸载前 deny_signal 复位。展示内核线程的 signal_safety 与资源管理。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod 启动内核线程并 allow_signal;发 SIGKILL 给该线程后线程退出等待循环;rmmod deny_signal 复位并 kthread_stop;无悬挂线程。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 所有打开的文件描述符/资源必须在所有退出路径上正确关闭
|
||||
- 信号处理函数中只能调用异步信号安全函数(async-signal-safe)
|
||||
@ -0,0 +1,21 @@
|
||||
# allow_signal/deny_signal: 内核线程信号控制
|
||||
|
||||
## 目标
|
||||
|
||||
内核线程用 allow_signal(SIGKILL) 允许接收致命信号,wait 循环中 signal_pending 退出;卸载前 deny_signal 复位。展示内核线程的 signal_safety 与资源管理。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod 启动内核线程并 allow_signal;发 SIGKILL 给该线程后线程退出等待循环;rmmod deny_signal 复位并 kthread_stop;无悬挂线程。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
@ -0,0 +1,71 @@
|
||||
/* ldd3-allow-signal-deny-sigio: 内核线程信号控制 */
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/kthread.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/sched/signal.h>
|
||||
#include <linux/signal.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/atomic.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
static struct task_struct *kthr;
|
||||
static atomic_t running = ATOMIC_INIT(0);
|
||||
static struct cdev ascdev;
|
||||
static dev_t devno;
|
||||
|
||||
static int as_thread(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
allow_signal(SIGKILL);
|
||||
while (!kthread_should_stop()) {
|
||||
atomic_set(&running, 1);
|
||||
if (signal_pending(current))
|
||||
break;
|
||||
set_current_state(TASK_INTERRUPTIBLE);
|
||||
schedule_timeout(msecs_to_jiffies(100));
|
||||
}
|
||||
atomic_set(&running, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t a_read(struct file *f, char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
int v;
|
||||
(void)f; (void)o;
|
||||
if (c < sizeof(int)) return -EINVAL;
|
||||
v = atomic_read(&running);
|
||||
return put_user(v, (int __user *)u) ? -EFAULT : sizeof(int);
|
||||
}
|
||||
|
||||
static int a_open(struct inode *i, struct file *f) { (void)i; (void)f; return 0; }
|
||||
static const struct file_operations afops = {
|
||||
.owner = THIS_MODULE, .open = a_open, .read = a_read,
|
||||
};
|
||||
|
||||
static int __init a_init(void)
|
||||
{
|
||||
int err = alloc_chrdev_region(&devno, 0, 1, "scullallowsig");
|
||||
if (err) return err;
|
||||
kthr = kthread_run(as_thread, NULL, "ldd3_allow_sig");
|
||||
if (IS_ERR(kthr)) { kthr = NULL; unregister_chrdev_region(devno, 1); return PTR_ERR(kthr); }
|
||||
cdev_init(&ascdev, &afops);
|
||||
ascdev.owner = THIS_MODULE;
|
||||
err = cdev_add(&ascdev, devno, 1);
|
||||
if (err) { kthread_stop(kthr); unregister_chrdev_region(devno, 1); }
|
||||
return err;
|
||||
}
|
||||
|
||||
static void __exit a_exit(void)
|
||||
{
|
||||
if (kthr) kthread_stop(kthr);
|
||||
cdev_del(&ascdev);
|
||||
unregister_chrdev_region(devno, 1);
|
||||
}
|
||||
|
||||
module_init(a_init);
|
||||
module_exit(a_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("LDD3");
|
||||
MODULE_DESCRIPTION("scull allow signal deny sigio");
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L3 HIL Behavior Checks for ldd3-atomic-dec-if-positive.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
Verifies deployed program behavior on RDK board via DGAgent SSH.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def ssh_exec(board_id, command, timeout=10):
|
||||
"""Execute command on board via DGAgent dg_ssh_exec tool."""
|
||||
result = subprocess.run(
|
||||
["pi", "tool", "dg_ssh_exec",
|
||||
"--board", board_id, "--command", command,
|
||||
"--timeout", str(timeout)],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
return result.stdout, result.stderr, result.returncode
|
||||
|
||||
|
||||
def check_binary_exists(board_id, remote_path):
|
||||
"""Check if deployed binary exists."""
|
||||
stdout, _, _ = ssh_exec(board_id, f"test -f {remote_path} && echo EXISTS")
|
||||
return "EXISTS" in stdout
|
||||
|
||||
|
||||
def check_program_runs(board_id, remote_path):
|
||||
"""Check program starts without crash."""
|
||||
stdout, stderr, rc = ssh_exec(board_id, f"timeout 5 {remote_path} 2>&1 | head -5")
|
||||
return rc is not None
|
||||
|
||||
|
||||
def run_all_checks(board_id="rdk-x5", remote_path="/opt/ebd_harness/ldd3-atomic-dec-if-positive"):
|
||||
"""Run all L3 behavior checks."""
|
||||
results = []
|
||||
results.append({"check": "binary_exists", "pass": check_binary_exists(board_id, remote_path)})
|
||||
results.append({"check": "program_runs", "pass": check_program_runs(board_id, remote_path)})
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
board = sys.argv[1] if len(sys.argv) > 1 else "rdk-x5"
|
||||
results = run_all_checks(board_id=board)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L0 Static Analysis Checks for ldd3-atomic-dec-if-positive.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
def check_lock_order(source_file):
|
||||
"""Check that mutex lock/unlock are balanced."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
locks = content.count("pthread_mutex_lock(") + content.count("std::lock_guard")
|
||||
unlocks = content.count("pthread_mutex_unlock(") + content.count("}")
|
||||
if locks == 0:
|
||||
return {"check": "lock_order", "pass": True}
|
||||
# lock_guard auto-unlocks, so just check existence of unlock pattern
|
||||
has_unlock = "unlock" in content or "lock_guard" in content or "unique_lock" in content
|
||||
if not has_unlock:
|
||||
return {"check": "lock_order", "pass": False,
|
||||
"detail": "Mutex locked but never unlocked"}
|
||||
return {"check": "lock_order", "pass": True}
|
||||
|
||||
def check_resource_cleanup(source_file):
|
||||
"""Check that all opened resources are closed."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
opens = content.count("open(") + content.count("fopen(")
|
||||
closes = content.count("close(") + content.count("fclose(")
|
||||
if opens > closes:
|
||||
return {"check": "resource_cleanup", "pass": False,
|
||||
"detail": f"Opened {opens} resources but only closed {closes}"}
|
||||
return {"check": "resource_cleanup", "pass": True}
|
||||
|
||||
def run_all_checks(source_file):
|
||||
"""Run all L0 checks."""
|
||||
results = []
|
||||
results.append(check_lock_order(source_file))
|
||||
results.append(check_resource_cleanup(source_file))
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
source = sys.argv[1] if len(sys.argv) > 1 else "reference/main.c"
|
||||
results = run_all_checks(source)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,25 @@
|
||||
id: ldd3-atomic-dec-if-positive
|
||||
capability: code-gen
|
||||
difficulty: medium
|
||||
platform: arm64-linux
|
||||
build_system: makefile
|
||||
implicit_knowledge:
|
||||
- atomic_dec_if_positive
|
||||
- lock_ordering
|
||||
- quota_management
|
||||
- resource_management
|
||||
paired_case: null
|
||||
embed_gap_metric: false
|
||||
eval_layers:
|
||||
l0_static: true
|
||||
l1_compile: true
|
||||
l2_simulate: false
|
||||
l3_hil: true
|
||||
l4_mutation: false
|
||||
max_iterations: 10
|
||||
max_tool_calls_per_iteration: 30
|
||||
timeout_seconds: 600
|
||||
source: ldd3
|
||||
source_url: https://lwn.net/Kernel/LDD3/
|
||||
visibility: public
|
||||
line: arm-linux
|
||||
@ -0,0 +1,26 @@
|
||||
# atomic_dec_if_positive: 不下溢的递减
|
||||
|
||||
## 目标
|
||||
|
||||
用 atomic_dec_if_positive 原子地递减且保证不为负(用于资源配额/令牌),返回值>=0 表示成功取得一个,返回负值表示已耗尽。展示资源配额的原子管理。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后 read 多次取令牌,前 N 次返回 0(成功),第 N+1 次返回 -1(耗尽);令牌总数等于配额,不下溢为负;rmmod 无告警。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 多个 mutex 必须保持一致的获取顺序,避免死锁
|
||||
- 所有打开的文件描述符/资源必须在所有退出路径上正确关闭
|
||||
@ -0,0 +1,21 @@
|
||||
# atomic_dec_if_positive: 不下溢的递减
|
||||
|
||||
## 目标
|
||||
|
||||
用 atomic_dec_if_positive 原子地递减且保证不为负(用于资源配额/令牌),返回值>=0 表示成功取得一个,返回负值表示已耗尽。展示资源配额的原子管理。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后 read 多次取令牌,前 N 次返回 0(成功),第 N+1 次返回 -1(耗尽);令牌总数等于配额,不下溢为负;rmmod 无告警。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
@ -0,0 +1,52 @@
|
||||
/* ldd3-atomic-dec-if-positive: 配额原子递减 */
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/atomic.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
#define QUOTA 5
|
||||
static atomic_t tokens = ATOMIC_INIT(QUOTA);
|
||||
static struct cdev tcdev;
|
||||
static dev_t devno;
|
||||
|
||||
static ssize_t t_read(struct file *f, char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
int v;
|
||||
(void)f; (void)o;
|
||||
if (c < sizeof(int)) return -EINVAL;
|
||||
v = atomic_dec_if_positive(&tokens); /* 不会下溢为负 */
|
||||
return put_user(v, (int __user *)u) ? -EFAULT : sizeof(int);
|
||||
}
|
||||
|
||||
static ssize_t t_write(struct file *f, const char __user *u, size_t cnt, loff_t *o)
|
||||
{
|
||||
(void)f; (void)u; (void)o;
|
||||
atomic_set(&tokens, QUOTA); /* 复位配额 */
|
||||
return cnt;
|
||||
}
|
||||
|
||||
static int t_open(struct inode *i, struct file *f) { (void)i; (void)f; return 0; }
|
||||
static const struct file_operations tfops = {
|
||||
.owner = THIS_MODULE, .open = t_open, .read = t_read, .write = t_write,
|
||||
};
|
||||
|
||||
static int __init t_init(void)
|
||||
{
|
||||
int err = alloc_chrdev_region(&devno, 0, 1, "scullquota");
|
||||
if (err) return err;
|
||||
cdev_init(&tcdev, &tfops);
|
||||
tcdev.owner = THIS_MODULE;
|
||||
err = cdev_add(&tcdev, devno, 1);
|
||||
if (err) unregister_chrdev_region(devno, 1);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void __exit t_exit(void) { cdev_del(&tcdev); unregister_chrdev_region(devno, 1); }
|
||||
|
||||
module_init(t_init);
|
||||
module_exit(t_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("LDD3");
|
||||
MODULE_DESCRIPTION("scull atomic dec if positive quota");
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L3 HIL Behavior Checks for ldd3-atomic-notifier-chain.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
Verifies deployed program behavior on RDK board via DGAgent SSH.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def ssh_exec(board_id, command, timeout=10):
|
||||
"""Execute command on board via DGAgent dg_ssh_exec tool."""
|
||||
result = subprocess.run(
|
||||
["pi", "tool", "dg_ssh_exec",
|
||||
"--board", board_id, "--command", command,
|
||||
"--timeout", str(timeout)],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
return result.stdout, result.stderr, result.returncode
|
||||
|
||||
|
||||
def check_binary_exists(board_id, remote_path):
|
||||
"""Check if deployed binary exists."""
|
||||
stdout, _, _ = ssh_exec(board_id, f"test -f {remote_path} && echo EXISTS")
|
||||
return "EXISTS" in stdout
|
||||
|
||||
|
||||
def check_program_runs(board_id, remote_path):
|
||||
"""Check program starts without crash."""
|
||||
stdout, stderr, rc = ssh_exec(board_id, f"timeout 5 {remote_path} 2>&1 | head -5")
|
||||
return rc is not None
|
||||
|
||||
|
||||
def run_all_checks(board_id="rdk-x5", remote_path="/opt/ebd_harness/ldd3-atomic-notifier-chain"):
|
||||
"""Run all L3 behavior checks."""
|
||||
results = []
|
||||
results.append({"check": "binary_exists", "pass": check_binary_exists(board_id, remote_path)})
|
||||
results.append({"check": "program_runs", "pass": check_program_runs(board_id, remote_path)})
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
board = sys.argv[1] if len(sys.argv) > 1 else "rdk-x5"
|
||||
results = run_all_checks(board_id=board)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L0 Static Analysis Checks for ldd3-atomic-notifier-chain.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
def check_lock_order(source_file):
|
||||
"""Check that mutex lock/unlock are balanced."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
locks = content.count("pthread_mutex_lock(") + content.count("std::lock_guard")
|
||||
unlocks = content.count("pthread_mutex_unlock(") + content.count("}")
|
||||
if locks == 0:
|
||||
return {"check": "lock_order", "pass": True}
|
||||
# lock_guard auto-unlocks, so just check existence of unlock pattern
|
||||
has_unlock = "unlock" in content or "lock_guard" in content or "unique_lock" in content
|
||||
if not has_unlock:
|
||||
return {"check": "lock_order", "pass": False,
|
||||
"detail": "Mutex locked but never unlocked"}
|
||||
return {"check": "lock_order", "pass": True}
|
||||
|
||||
def check_resource_cleanup(source_file):
|
||||
"""Check that all opened resources are closed."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
opens = content.count("open(") + content.count("fopen(")
|
||||
closes = content.count("close(") + content.count("fclose(")
|
||||
if opens > closes:
|
||||
return {"check": "resource_cleanup", "pass": False,
|
||||
"detail": f"Opened {opens} resources but only closed {closes}"}
|
||||
return {"check": "resource_cleanup", "pass": True}
|
||||
|
||||
def run_all_checks(source_file):
|
||||
"""Run all L0 checks."""
|
||||
results = []
|
||||
results.append(check_lock_order(source_file))
|
||||
results.append(check_resource_cleanup(source_file))
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
source = sys.argv[1] if len(sys.argv) > 1 else "reference/main.c"
|
||||
results = run_all_checks(source)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,25 @@
|
||||
id: ldd3-atomic-notifier-chain
|
||||
capability: code-gen
|
||||
difficulty: medium
|
||||
platform: arm64-linux
|
||||
build_system: makefile
|
||||
implicit_knowledge:
|
||||
- atomic_notifier_register
|
||||
- lock_ordering
|
||||
- notifier_call
|
||||
- resource_management
|
||||
paired_case: null
|
||||
embed_gap_metric: false
|
||||
eval_layers:
|
||||
l0_static: true
|
||||
l1_compile: true
|
||||
l2_simulate: false
|
||||
l3_hil: true
|
||||
l4_mutation: false
|
||||
max_iterations: 10
|
||||
max_tool_calls_per_iteration: 30
|
||||
timeout_seconds: 600
|
||||
source: ldd3
|
||||
source_url: https://lwn.net/Kernel/LDD3/
|
||||
visibility: public
|
||||
line: arm-linux
|
||||
@ -0,0 +1,26 @@
|
||||
# atomic_notifier: 原子通知链 register/unregister 配对
|
||||
|
||||
## 目标
|
||||
|
||||
用 atomic_notifier_chain_register 注册一个原子通知块(可在任意上下文调用,不可睡眠),write 触发 atomic_notifier_call;卸载 atomic_notifier_chain_unregister。展示通知链资源管理与配对。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后 write 触发通知,notifier 回调中 atomic_inc;read 返回触发次数;卸载 unregister 后无悬挂 notifier;回调中无可睡眠调用(原子上下文)。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 多个 mutex 必须保持一致的获取顺序,避免死锁
|
||||
- 所有打开的文件描述符/资源必须在所有退出路径上正确关闭
|
||||
@ -0,0 +1,21 @@
|
||||
# atomic_notifier: 原子通知链 register/unregister 配对
|
||||
|
||||
## 目标
|
||||
|
||||
用 atomic_notifier_chain_register 注册一个原子通知块(可在任意上下文调用,不可睡眠),write 触发 atomic_notifier_call;卸载 atomic_notifier_chain_unregister。展示通知链资源管理与配对。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后 write 触发通知,notifier 回调中 atomic_inc;read 返回触发次数;卸载 unregister 后无悬挂 notifier;回调中无可睡眠调用(原子上下文)。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
@ -0,0 +1,71 @@
|
||||
/* ldd3-atomic-notifier-chain: 原子通知链配对 */
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/notifier.h>
|
||||
#include <linux/atomic.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
static ATOMIC_NOTIFIER_HEAD(chain);
|
||||
static atomic_t fired = ATOMIC_INIT(0);
|
||||
static atomic_t reads = ATOMIC_INIT(0);
|
||||
static struct notifier_block nb;
|
||||
static dev_t devno;
|
||||
static struct cdev ncdev;
|
||||
|
||||
static int nb_fn(struct notifier_block *b, unsigned long val, void *v)
|
||||
{
|
||||
(void)b; (void)val; (void)v;
|
||||
atomic_inc(&fired);
|
||||
return NOTIFY_OK;
|
||||
}
|
||||
|
||||
static ssize_t n_write(struct file *f, const char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
(void)f; (void)u; (void)o;
|
||||
atomic_notifier_call(&chain, 0, NULL);
|
||||
return c;
|
||||
}
|
||||
|
||||
static ssize_t n_read(struct file *f, char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
int v;
|
||||
(void)f; (void)o;
|
||||
if (c < sizeof(int)) return -EINVAL;
|
||||
atomic_inc(&reads);
|
||||
v = atomic_read(&fired);
|
||||
return put_user(v, (int __user *)u) ? -EFAULT : sizeof(int);
|
||||
}
|
||||
|
||||
static int n_open(struct inode *i, struct file *f) { (void)i; (void)f; return 0; }
|
||||
static const struct file_operations nfops = {
|
||||
.owner = THIS_MODULE, .open = n_open, .read = n_read, .write = n_write,
|
||||
};
|
||||
|
||||
static int __init n_init(void)
|
||||
{
|
||||
int err = alloc_chrdev_region(&devno, 0, 1, "scullanotify");
|
||||
if (err) return err;
|
||||
nb.notifier_call = nb_fn;
|
||||
nb.priority = 0;
|
||||
atomic_notifier_chain_register(&chain, &nb);
|
||||
cdev_init(&ncdev, &nfops);
|
||||
ncdev.owner = THIS_MODULE;
|
||||
err = cdev_add(&ncdev, devno, 1);
|
||||
if (err) { atomic_notifier_chain_unregister(&chain, &nb); unregister_chrdev_region(devno, 1); }
|
||||
return err;
|
||||
}
|
||||
|
||||
static void __exit n_exit(void)
|
||||
{
|
||||
atomic_notifier_chain_unregister(&chain, &nb);
|
||||
cdev_del(&ncdev);
|
||||
unregister_chrdev_region(devno, 1);
|
||||
}
|
||||
|
||||
module_init(n_init);
|
||||
module_exit(n_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("LDD3");
|
||||
MODULE_DESCRIPTION("scull atomic notifier chain");
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L3 HIL Behavior Checks for ldd3-atomic-xchg-state-machine.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
Verifies deployed program behavior on RDK board via DGAgent SSH.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def ssh_exec(board_id, command, timeout=10):
|
||||
"""Execute command on board via DGAgent dg_ssh_exec tool."""
|
||||
result = subprocess.run(
|
||||
["pi", "tool", "dg_ssh_exec",
|
||||
"--board", board_id, "--command", command,
|
||||
"--timeout", str(timeout)],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
return result.stdout, result.stderr, result.returncode
|
||||
|
||||
|
||||
def check_binary_exists(board_id, remote_path):
|
||||
"""Check if deployed binary exists."""
|
||||
stdout, _, _ = ssh_exec(board_id, f"test -f {remote_path} && echo EXISTS")
|
||||
return "EXISTS" in stdout
|
||||
|
||||
|
||||
def check_program_runs(board_id, remote_path):
|
||||
"""Check program starts without crash."""
|
||||
stdout, stderr, rc = ssh_exec(board_id, f"timeout 5 {remote_path} 2>&1 | head -5")
|
||||
return rc is not None
|
||||
|
||||
|
||||
def run_all_checks(board_id="rdk-x5", remote_path="/opt/ebd_harness/ldd3-atomic-xchg-state-machine"):
|
||||
"""Run all L3 behavior checks."""
|
||||
results = []
|
||||
results.append({"check": "binary_exists", "pass": check_binary_exists(board_id, remote_path)})
|
||||
results.append({"check": "program_runs", "pass": check_program_runs(board_id, remote_path)})
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
board = sys.argv[1] if len(sys.argv) > 1 else "rdk-x5"
|
||||
results = run_all_checks(board_id=board)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L0 Static Analysis Checks for ldd3-atomic-xchg-state-machine.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
def check_lock_order(source_file):
|
||||
"""Check that mutex lock/unlock are balanced."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
locks = content.count("pthread_mutex_lock(") + content.count("std::lock_guard")
|
||||
unlocks = content.count("pthread_mutex_unlock(") + content.count("}")
|
||||
if locks == 0:
|
||||
return {"check": "lock_order", "pass": True}
|
||||
# lock_guard auto-unlocks, so just check existence of unlock pattern
|
||||
has_unlock = "unlock" in content or "lock_guard" in content or "unique_lock" in content
|
||||
if not has_unlock:
|
||||
return {"check": "lock_order", "pass": False,
|
||||
"detail": "Mutex locked but never unlocked"}
|
||||
return {"check": "lock_order", "pass": True}
|
||||
|
||||
def check_resource_cleanup(source_file):
|
||||
"""Check that all opened resources are closed."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
opens = content.count("open(") + content.count("fopen(")
|
||||
closes = content.count("close(") + content.count("fclose(")
|
||||
if opens > closes:
|
||||
return {"check": "resource_cleanup", "pass": False,
|
||||
"detail": f"Opened {opens} resources but only closed {closes}"}
|
||||
return {"check": "resource_cleanup", "pass": True}
|
||||
|
||||
def run_all_checks(source_file):
|
||||
"""Run all L0 checks."""
|
||||
results = []
|
||||
results.append(check_lock_order(source_file))
|
||||
results.append(check_resource_cleanup(source_file))
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
source = sys.argv[1] if len(sys.argv) > 1 else "reference/main.c"
|
||||
results = run_all_checks(source)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,25 @@
|
||||
id: ldd3-atomic-xchg-state-machine
|
||||
capability: code-gen
|
||||
difficulty: medium
|
||||
platform: arm64-linux
|
||||
build_system: makefile
|
||||
implicit_knowledge:
|
||||
- atomic_xchg
|
||||
- lock_ordering
|
||||
- resource_management
|
||||
- state_machine_atomic
|
||||
paired_case: null
|
||||
embed_gap_metric: false
|
||||
eval_layers:
|
||||
l0_static: true
|
||||
l1_compile: true
|
||||
l2_simulate: false
|
||||
l3_hil: true
|
||||
l4_mutation: false
|
||||
max_iterations: 10
|
||||
max_tool_calls_per_iteration: 30
|
||||
timeout_seconds: 600
|
||||
source: ldd3
|
||||
source_url: https://lwn.net/Kernel/LDD3/
|
||||
visibility: public
|
||||
line: arm-linux
|
||||
@ -0,0 +1,26 @@
|
||||
# atomic xchg: 原子状态机切换
|
||||
|
||||
## 目标
|
||||
|
||||
用 atomic_xchg 原子地切换设备状态(IDLE/RUNNING/STOP),保证状态转换原子无竞争。展示 lock_ordering 的无锁状态机管理。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后 ioctl start 把状态从 IDLE 切到 RUNNING;xchg 保证同一时刻只有一个 start 成功;stop 切回 IDLE;非法转换返回 -EBUSY;rmmod 无告警。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 多个 mutex 必须保持一致的获取顺序,避免死锁
|
||||
- 所有打开的文件描述符/资源必须在所有退出路径上正确关闭
|
||||
@ -0,0 +1,21 @@
|
||||
# atomic xchg: 原子状态机切换
|
||||
|
||||
## 目标
|
||||
|
||||
用 atomic_xchg 原子地切换设备状态(IDLE/RUNNING/STOP),保证状态转换原子无竞争。展示 lock_ordering 的无锁状态机管理。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后 ioctl start 把状态从 IDLE 切到 RUNNING;xchg 保证同一时刻只有一个 start 成功;stop 切回 IDLE;非法转换返回 -EBUSY;rmmod 无告警。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
@ -0,0 +1,65 @@
|
||||
/* ldd3-atomic-xchg-state-machine: 原子状态机 */
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/atomic.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/ioctl.h>
|
||||
|
||||
enum { ST_IDLE = 0, ST_RUN = 1, ST_STOP = 2 };
|
||||
#define SM_IOC_MAGIC 'M'
|
||||
#define SM_START _IO(SM_IOC_MAGIC, 0)
|
||||
#define SM_STOP _IO(SM_IOC_MAGIC, 1)
|
||||
|
||||
static atomic_t state = ATOMIC_INIT(ST_IDLE);
|
||||
static struct cdev smcdev;
|
||||
static dev_t devno;
|
||||
|
||||
static long sm_ioctl(struct file *f, unsigned int cmd, unsigned long a)
|
||||
{
|
||||
int old;
|
||||
(void)f; (void)a;
|
||||
if (cmd == SM_START) {
|
||||
old = atomic_xchg(&state, ST_RUN);
|
||||
return (old == ST_IDLE) ? 0 : -EBUSY; /* 非 IDLE 不能 start */
|
||||
}
|
||||
if (cmd == SM_STOP) {
|
||||
old = atomic_xchg(&state, ST_IDLE);
|
||||
return (old == ST_RUN) ? 0 : -EINVAL;
|
||||
}
|
||||
return -ENOTTY;
|
||||
}
|
||||
|
||||
static ssize_t sm_read(struct file *f, char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
int v;
|
||||
(void)f; (void)o;
|
||||
if (c < sizeof(int)) return -EINVAL;
|
||||
v = atomic_read(&state);
|
||||
return put_user(v, (int __user *)u) ? -EFAULT : sizeof(int);
|
||||
}
|
||||
|
||||
static int sm_open(struct inode *i, struct file *f) { (void)i; (void)f; return 0; }
|
||||
static const struct file_operations smfops = {
|
||||
.owner = THIS_MODULE, .open = sm_open, .read = sm_read, .unlocked_ioctl = sm_ioctl,
|
||||
};
|
||||
|
||||
static int __init sm_init(void)
|
||||
{
|
||||
int err = alloc_chrdev_region(&devno, 0, 1, "scullsmxchg");
|
||||
if (err) return err;
|
||||
cdev_init(&smcdev, &smfops);
|
||||
smcdev.owner = THIS_MODULE;
|
||||
err = cdev_add(&smcdev, devno, 1);
|
||||
if (err) unregister_chrdev_region(devno, 1);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void __exit sm_exit(void) { cdev_del(&smcdev); unregister_chrdev_region(devno, 1); }
|
||||
|
||||
module_init(sm_init);
|
||||
module_exit(sm_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("LDD3");
|
||||
MODULE_DESCRIPTION("scull atomic xchg state machine");
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L3 HIL Behavior Checks for ldd3-blocking-notifier-sleepable.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
Verifies deployed program behavior on RDK board via DGAgent SSH.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def ssh_exec(board_id, command, timeout=10):
|
||||
"""Execute command on board via DGAgent dg_ssh_exec tool."""
|
||||
result = subprocess.run(
|
||||
["pi", "tool", "dg_ssh_exec",
|
||||
"--board", board_id, "--command", command,
|
||||
"--timeout", str(timeout)],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
return result.stdout, result.stderr, result.returncode
|
||||
|
||||
|
||||
def check_binary_exists(board_id, remote_path):
|
||||
"""Check if deployed binary exists."""
|
||||
stdout, _, _ = ssh_exec(board_id, f"test -f {remote_path} && echo EXISTS")
|
||||
return "EXISTS" in stdout
|
||||
|
||||
|
||||
def check_program_runs(board_id, remote_path):
|
||||
"""Check program starts without crash."""
|
||||
stdout, stderr, rc = ssh_exec(board_id, f"timeout 5 {remote_path} 2>&1 | head -5")
|
||||
return rc is not None
|
||||
|
||||
|
||||
def run_all_checks(board_id="rdk-x5", remote_path="/opt/ebd_harness/ldd3-blocking-notifier-sleepable"):
|
||||
"""Run all L3 behavior checks."""
|
||||
results = []
|
||||
results.append({"check": "binary_exists", "pass": check_binary_exists(board_id, remote_path)})
|
||||
results.append({"check": "program_runs", "pass": check_program_runs(board_id, remote_path)})
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
board = sys.argv[1] if len(sys.argv) > 1 else "rdk-x5"
|
||||
results = run_all_checks(board_id=board)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L0 Static Analysis Checks for ldd3-blocking-notifier-sleepable.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
def check_lock_order(source_file):
|
||||
"""Check that mutex lock/unlock are balanced."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
locks = content.count("pthread_mutex_lock(") + content.count("std::lock_guard")
|
||||
unlocks = content.count("pthread_mutex_unlock(") + content.count("}")
|
||||
if locks == 0:
|
||||
return {"check": "lock_order", "pass": True}
|
||||
# lock_guard auto-unlocks, so just check existence of unlock pattern
|
||||
has_unlock = "unlock" in content or "lock_guard" in content or "unique_lock" in content
|
||||
if not has_unlock:
|
||||
return {"check": "lock_order", "pass": False,
|
||||
"detail": "Mutex locked but never unlocked"}
|
||||
return {"check": "lock_order", "pass": True}
|
||||
|
||||
def check_resource_cleanup(source_file):
|
||||
"""Check that all opened resources are closed."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
opens = content.count("open(") + content.count("fopen(")
|
||||
closes = content.count("close(") + content.count("fclose(")
|
||||
if opens > closes:
|
||||
return {"check": "resource_cleanup", "pass": False,
|
||||
"detail": f"Opened {opens} resources but only closed {closes}"}
|
||||
return {"check": "resource_cleanup", "pass": True}
|
||||
|
||||
def run_all_checks(source_file):
|
||||
"""Run all L0 checks."""
|
||||
results = []
|
||||
results.append(check_lock_order(source_file))
|
||||
results.append(check_resource_cleanup(source_file))
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
source = sys.argv[1] if len(sys.argv) > 1 else "reference/main.c"
|
||||
results = run_all_checks(source)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,25 @@
|
||||
id: ldd3-blocking-notifier-sleepable
|
||||
capability: code-gen
|
||||
difficulty: medium
|
||||
platform: arm64-linux
|
||||
build_system: makefile
|
||||
implicit_knowledge:
|
||||
- blocking_notifier_register
|
||||
- lock_ordering
|
||||
- resource_management
|
||||
- sleepable_callback
|
||||
paired_case: null
|
||||
embed_gap_metric: false
|
||||
eval_layers:
|
||||
l0_static: true
|
||||
l1_compile: true
|
||||
l2_simulate: false
|
||||
l3_hil: true
|
||||
l4_mutation: false
|
||||
max_iterations: 10
|
||||
max_tool_calls_per_iteration: 30
|
||||
timeout_seconds: 600
|
||||
source: ldd3
|
||||
source_url: https://lwn.net/Kernel/LDD3/
|
||||
visibility: public
|
||||
line: arm-linux
|
||||
@ -0,0 +1,26 @@
|
||||
# blocking_notifier: 可睡眠通知链(进程上下文)
|
||||
|
||||
## 目标
|
||||
|
||||
用 blocking_notifier_chain_register 注册可睡眠通知块(其内部用 rwsem,回调可睡眠);write 触发 blocking_notifier_call。展示可睡眠通知链的资源管理,与原子链区分上下文。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后 write 触发回调(回调内可调用 kmalloc GFP_KERNEL 等可睡眠函数);read 返回触发次数;卸载 blocking_notifier_chain_unregister 无悬挂。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 多个 mutex 必须保持一致的获取顺序,避免死锁
|
||||
- 所有打开的文件描述符/资源必须在所有退出路径上正确关闭
|
||||
@ -0,0 +1,21 @@
|
||||
# blocking_notifier: 可睡眠通知链(进程上下文)
|
||||
|
||||
## 目标
|
||||
|
||||
用 blocking_notifier_chain_register 注册可睡眠通知块(其内部用 rwsem,回调可睡眠);write 触发 blocking_notifier_call。展示可睡眠通知链的资源管理,与原子链区分上下文。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后 write 触发回调(回调内可调用 kmalloc GFP_KERNEL 等可睡眠函数);read 返回触发次数;卸载 blocking_notifier_chain_unregister 无悬挂。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
@ -0,0 +1,73 @@
|
||||
/* ldd3-blocking-notifier-sleepable: 可睡眠通知链 */
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/notifier.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/atomic.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
static BLOCKING_NOTIFIER_HEAD(bchain);
|
||||
static atomic_t fired = ATOMIC_INIT(0);
|
||||
static struct notifier_block bnb;
|
||||
static dev_t devno;
|
||||
static struct cdev bcdev;
|
||||
|
||||
static int bnb_fn(struct notifier_block *b, unsigned long val, void *v)
|
||||
{
|
||||
void *p;
|
||||
(void)b; (void)val; (void)v;
|
||||
p = kmalloc(16, GFP_KERNEL); /* 回调在进程上下文, 可睡眠分配 */
|
||||
kfree(p);
|
||||
atomic_inc(&fired);
|
||||
return NOTIFY_OK;
|
||||
}
|
||||
|
||||
static ssize_t b_write(struct file *f, const char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
(void)f; (void)u; (void)o;
|
||||
blocking_notifier_call(&bchain, 0, NULL);
|
||||
return c;
|
||||
}
|
||||
|
||||
static ssize_t b_read(struct file *f, char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
int v;
|
||||
(void)f; (void)o;
|
||||
if (c < sizeof(int)) return -EINVAL;
|
||||
v = atomic_read(&fired);
|
||||
return put_user(v, (int __user *)u) ? -EFAULT : sizeof(int);
|
||||
}
|
||||
|
||||
static int b_open(struct inode *i, struct file *f) { (void)i; (void)f; return 0; }
|
||||
static const struct file_operations bfops = {
|
||||
.owner = THIS_MODULE, .open = b_open, .read = b_read, .write = b_write,
|
||||
};
|
||||
|
||||
static int __init b_init(void)
|
||||
{
|
||||
int err = alloc_chrdev_region(&devno, 0, 1, "scullbnotify");
|
||||
if (err) return err;
|
||||
bnb.notifier_call = bnb_fn;
|
||||
bnb.priority = 0;
|
||||
blocking_notifier_chain_register(&bchain, &bnb);
|
||||
cdev_init(&bcdev, &bfops);
|
||||
bcdev.owner = THIS_MODULE;
|
||||
err = cdev_add(&bcdev, devno, 1);
|
||||
if (err) { blocking_notifier_chain_unregister(&bchain, &bnb); unregister_chrdev_region(devno, 1); }
|
||||
return err;
|
||||
}
|
||||
|
||||
static void __exit b_exit(void)
|
||||
{
|
||||
blocking_notifier_chain_unregister(&bchain, &bnb);
|
||||
cdev_del(&bcdev);
|
||||
unregister_chrdev_region(devno, 1);
|
||||
}
|
||||
|
||||
module_init(b_init);
|
||||
module_exit(b_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("LDD3");
|
||||
MODULE_DESCRIPTION("scull blocking notifier sleepable");
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L3 HIL Behavior Checks for ldd3-bounded-counter-limit.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
Verifies deployed program behavior on RDK board via DGAgent SSH.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def ssh_exec(board_id, command, timeout=10):
|
||||
"""Execute command on board via DGAgent dg_ssh_exec tool."""
|
||||
result = subprocess.run(
|
||||
["pi", "tool", "dg_ssh_exec",
|
||||
"--board", board_id, "--command", command,
|
||||
"--timeout", str(timeout)],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
return result.stdout, result.stderr, result.returncode
|
||||
|
||||
|
||||
def check_binary_exists(board_id, remote_path):
|
||||
"""Check if deployed binary exists."""
|
||||
stdout, _, _ = ssh_exec(board_id, f"test -f {remote_path} && echo EXISTS")
|
||||
return "EXISTS" in stdout
|
||||
|
||||
|
||||
def check_program_runs(board_id, remote_path):
|
||||
"""Check program starts without crash."""
|
||||
stdout, stderr, rc = ssh_exec(board_id, f"timeout 5 {remote_path} 2>&1 | head -5")
|
||||
return rc is not None
|
||||
|
||||
|
||||
def run_all_checks(board_id="rdk-x5", remote_path="/opt/ebd_harness/ldd3-bounded-counter-limit"):
|
||||
"""Run all L3 behavior checks."""
|
||||
results = []
|
||||
results.append({"check": "binary_exists", "pass": check_binary_exists(board_id, remote_path)})
|
||||
results.append({"check": "program_runs", "pass": check_program_runs(board_id, remote_path)})
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
board = sys.argv[1] if len(sys.argv) > 1 else "rdk-x5"
|
||||
results = run_all_checks(board_id=board)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L0 Static Analysis Checks for ldd3-bounded-counter-limit.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
def check_lock_order(source_file):
|
||||
"""Check that mutex lock/unlock are balanced."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
locks = content.count("pthread_mutex_lock(") + content.count("std::lock_guard")
|
||||
unlocks = content.count("pthread_mutex_unlock(") + content.count("}")
|
||||
if locks == 0:
|
||||
return {"check": "lock_order", "pass": True}
|
||||
# lock_guard auto-unlocks, so just check existence of unlock pattern
|
||||
has_unlock = "unlock" in content or "lock_guard" in content or "unique_lock" in content
|
||||
if not has_unlock:
|
||||
return {"check": "lock_order", "pass": False,
|
||||
"detail": "Mutex locked but never unlocked"}
|
||||
return {"check": "lock_order", "pass": True}
|
||||
|
||||
def check_resource_cleanup(source_file):
|
||||
"""Check that all opened resources are closed."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
opens = content.count("open(") + content.count("fopen(")
|
||||
closes = content.count("close(") + content.count("fclose(")
|
||||
if opens > closes:
|
||||
return {"check": "resource_cleanup", "pass": False,
|
||||
"detail": f"Opened {opens} resources but only closed {closes}"}
|
||||
return {"check": "resource_cleanup", "pass": True}
|
||||
|
||||
def run_all_checks(source_file):
|
||||
"""Run all L0 checks."""
|
||||
results = []
|
||||
results.append(check_lock_order(source_file))
|
||||
results.append(check_resource_cleanup(source_file))
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
source = sys.argv[1] if len(sys.argv) > 1 else "reference/main.c"
|
||||
results = run_all_checks(source)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,25 @@
|
||||
id: ldd3-bounded-counter-limit
|
||||
capability: code-gen
|
||||
difficulty: easy
|
||||
platform: arm64-linux
|
||||
build_system: makefile
|
||||
implicit_knowledge:
|
||||
- bounded_counter
|
||||
- lock_ordering
|
||||
- resource_management
|
||||
- spinlock_pairing
|
||||
paired_case: null
|
||||
embed_gap_metric: false
|
||||
eval_layers:
|
||||
l0_static: true
|
||||
l1_compile: true
|
||||
l2_simulate: false
|
||||
l3_hil: true
|
||||
l4_mutation: false
|
||||
max_iterations: 10
|
||||
max_tool_calls_per_iteration: 30
|
||||
timeout_seconds: 600
|
||||
source: ldd3
|
||||
source_url: https://lwn.net/Kernel/LDD3/
|
||||
visibility: public
|
||||
line: arm-linux
|
||||
@ -0,0 +1,26 @@
|
||||
# 有界计数器: 上限内累加 + 自旋锁
|
||||
|
||||
## 目标
|
||||
|
||||
维护一个有最大上限的计数器,write 在自旋锁内累加但不超过 MAX,超限返回 -ENOSPC;read 返回当前值。展示 lock_ordering 下的资源配额管理。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后前 MAX(100) 次 write 各 +1 返回成功;第 101 次 write 返回 -1 且 errno=ENOSPC(值停在 100);read 始终返回 <=100;并发写不超过上限;rmmod 无告警。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 多个 mutex 必须保持一致的获取顺序,避免死锁
|
||||
- 所有打开的文件描述符/资源必须在所有退出路径上正确关闭
|
||||
@ -0,0 +1,21 @@
|
||||
# 有界计数器: 上限内累加 + 自旋锁
|
||||
|
||||
## 目标
|
||||
|
||||
维护一个有最大上限的计数器,write 在自旋锁内累加但不超过 MAX,超限返回 -ENOSPC;read 返回当前值。展示 lock_ordering 下的资源配额管理。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后前 MAX(100) 次 write 各 +1 返回成功;第 101 次 write 返回 -1 且 errno=ENOSPC(值停在 100);read 始终返回 <=100;并发写不超过上限;rmmod 无告警。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
@ -0,0 +1,57 @@
|
||||
/* ldd3-bounded-counter-limit: 有界计数器 */
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
#define MAXC 100
|
||||
struct bc { spinlock_t lock; int val; struct cdev cdev; };
|
||||
static struct bc bc;
|
||||
static dev_t devno;
|
||||
|
||||
static ssize_t b_write(struct file *f, const char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
int ret;
|
||||
(void)f; (void)u; (void)o;
|
||||
spin_lock(&bc.lock);
|
||||
if (bc.val >= MAXC) ret = -ENOSPC;
|
||||
else { bc.val++; ret = sizeof(int); }
|
||||
spin_unlock(&bc.lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t b_read(struct file *f, char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
int v;
|
||||
(void)f; (void)o;
|
||||
if (c < sizeof(int)) return -EINVAL;
|
||||
spin_lock(&bc.lock); v = bc.val; spin_unlock(&bc.lock);
|
||||
return put_user(v, (int __user *)u) ? -EFAULT : sizeof(int);
|
||||
}
|
||||
|
||||
static int b_open(struct inode *i, struct file *f) { (void)i; (void)f; return 0; }
|
||||
static const struct file_operations bfops = {
|
||||
.owner = THIS_MODULE, .open = b_open, .read = b_read, .write = b_write,
|
||||
};
|
||||
|
||||
static int __init b_init(void)
|
||||
{
|
||||
int err = alloc_chrdev_region(&devno, 0, 1, "scullbounded");
|
||||
if (err) return err;
|
||||
spin_lock_init(&bc.lock);
|
||||
cdev_init(&bc.cdev, &bfops);
|
||||
bc.cdev.owner = THIS_MODULE;
|
||||
err = cdev_add(&bc.cdev, devno, 1);
|
||||
if (err) unregister_chrdev_region(devno, 1);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void __exit b_exit(void) { cdev_del(&bc.cdev); unregister_chrdev_region(devno, 1); }
|
||||
|
||||
module_init(b_init);
|
||||
module_exit(b_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("LDD3");
|
||||
MODULE_DESCRIPTION("scull bounded counter limit");
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L3 HIL Behavior Checks for ldd3-cache-flush-dcache-dma.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
Verifies deployed program behavior on RDK board via DGAgent SSH.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def ssh_exec(board_id, command, timeout=10):
|
||||
"""Execute command on board via DGAgent dg_ssh_exec tool."""
|
||||
result = subprocess.run(
|
||||
["pi", "tool", "dg_ssh_exec",
|
||||
"--board", board_id, "--command", command,
|
||||
"--timeout", str(timeout)],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
return result.stdout, result.stderr, result.returncode
|
||||
|
||||
|
||||
def check_binary_exists(board_id, remote_path):
|
||||
"""Check if deployed binary exists."""
|
||||
stdout, _, _ = ssh_exec(board_id, f"test -f {remote_path} && echo EXISTS")
|
||||
return "EXISTS" in stdout
|
||||
|
||||
|
||||
def check_program_runs(board_id, remote_path):
|
||||
"""Check program starts without crash."""
|
||||
stdout, stderr, rc = ssh_exec(board_id, f"timeout 5 {remote_path} 2>&1 | head -5")
|
||||
return rc is not None
|
||||
|
||||
|
||||
def run_all_checks(board_id="rdk-x5", remote_path="/opt/ebd_harness/ldd3-cache-flush-dcache-dma"):
|
||||
"""Run all L3 behavior checks."""
|
||||
results = []
|
||||
results.append({"check": "binary_exists", "pass": check_binary_exists(board_id, remote_path)})
|
||||
results.append({"check": "program_runs", "pass": check_program_runs(board_id, remote_path)})
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
board = sys.argv[1] if len(sys.argv) > 1 else "rdk-x5"
|
||||
results = run_all_checks(board_id=board)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L0 Static Analysis Checks for ldd3-cache-flush-dcache-dma.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
def check_cache_flush(source_file):
|
||||
"""Check that DMA operations include cache flush/invalidate."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
has_dma = "dma" in content.lower() or "DMA" in content
|
||||
has_flush = any(x in content for x in ["__builtin___clear_cache", "cacheflush",
|
||||
"dcache_clean", "CLFLUSH", "cache_flush"])
|
||||
if has_dma and not has_flush:
|
||||
return {"check": "cache_coherence", "pass": False,
|
||||
"detail": "DMA operation without cache flush/invalidate"}
|
||||
return {"check": "cache_coherence", "pass": True}
|
||||
|
||||
def check_dma_alignment(source_file):
|
||||
"""Check that DMA buffers are properly aligned."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
has_dma = "dma" in content.lower()
|
||||
has_align = any(x in content for x in ["posix_memalign", "aligned_alloc",
|
||||
"__attribute__((aligned", "memalign"])
|
||||
if has_dma and "alloc" in content and not has_align:
|
||||
return {"check": "dma_alignment", "pass": False,
|
||||
"detail": "DMA buffer allocated without alignment"}
|
||||
return {"check": "dma_alignment", "pass": True}
|
||||
|
||||
def check_resource_cleanup(source_file):
|
||||
"""Check that all opened resources are closed."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
opens = content.count("open(") + content.count("fopen(")
|
||||
closes = content.count("close(") + content.count("fclose(")
|
||||
if opens > closes:
|
||||
return {"check": "resource_cleanup", "pass": False,
|
||||
"detail": f"Opened {opens} resources but only closed {closes}"}
|
||||
return {"check": "resource_cleanup", "pass": True}
|
||||
|
||||
def run_all_checks(source_file):
|
||||
"""Run all L0 checks."""
|
||||
results = []
|
||||
results.append(check_cache_flush(source_file))
|
||||
results.append(check_dma_alignment(source_file))
|
||||
results.append(check_resource_cleanup(source_file))
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
source = sys.argv[1] if len(sys.argv) > 1 else "reference/main.c"
|
||||
results = run_all_checks(source)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,26 @@
|
||||
id: ldd3-cache-flush-dcache-dma
|
||||
capability: code-gen
|
||||
difficulty: hard
|
||||
platform: arm64-linux
|
||||
build_system: makefile
|
||||
implicit_knowledge:
|
||||
- cache_coherence
|
||||
- dma_alignment
|
||||
- flush_dcache_page
|
||||
- memory_mapping
|
||||
- resource_management
|
||||
paired_case: null
|
||||
embed_gap_metric: false
|
||||
eval_layers:
|
||||
l0_static: true
|
||||
l1_compile: true
|
||||
l2_simulate: false
|
||||
l3_hil: true
|
||||
l4_mutation: false
|
||||
max_iterations: 10
|
||||
max_tool_calls_per_iteration: 30
|
||||
timeout_seconds: 600
|
||||
source: ldd3
|
||||
source_url: https://lwn.net/Kernel/LDD3/
|
||||
visibility: private
|
||||
line: arm-linux
|
||||
@ -0,0 +1,28 @@
|
||||
# cache flush: flush_dcache_page 维护 DMA 一致
|
||||
|
||||
## 目标
|
||||
|
||||
在用户页参与 DMA 前/后用 flush_dcache_page 维护 cache 一致(非一致 IOMMU 架构),确保设备与 CPU 看到相同数据。展示 cache_coherence 维护与资源管理。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后 write 触发 flush_dcache_page,read 数据与设备一致;cache 与内存同步无 stale;rmmod 无告警(演示 cache 维护,板上需具体平台)。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- DMA 传输前后必须执行 cache flush/invalidate 操作
|
||||
- DMA 缓冲区必须按 cache line 对齐(通常 32 或 64 字节)
|
||||
- mmap 映射的内存必须在所有退出路径上 munmap
|
||||
- 所有打开的文件描述符/资源必须在所有退出路径上正确关闭
|
||||
@ -0,0 +1,21 @@
|
||||
# cache flush: flush_dcache_page 维护 DMA 一致
|
||||
|
||||
## 目标
|
||||
|
||||
在用户页参与 DMA 前/后用 flush_dcache_page 维护 cache 一致(非一致 IOMMU 架构),确保设备与 CPU 看到相同数据。展示 cache_coherence 维护与资源管理。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后 write 触发 flush_dcache_page,read 数据与设备一致;cache 与内存同步无 stale;rmmod 无告警(演示 cache 维护,板上需具体平台)。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
@ -0,0 +1,58 @@
|
||||
/* ldd3-cache-flush-dcache-dma: DMA 前后 cache flush */
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/pagemap.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
#define PGADDR (unsigned long)0 /* 占位: 真实应取自用户 mmap 页 */
|
||||
struct fc { struct page *pg; char buf[64]; size_t len; struct cdev cdev; };
|
||||
static struct fc fc;
|
||||
static dev_t devno;
|
||||
|
||||
static ssize_t f_write(struct file *filp, const char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
(void)filp; (void)o;
|
||||
if (c > sizeof(fc.buf)) c = sizeof(fc.buf);
|
||||
if (copy_from_user(fc.buf, u, c)) return -EFAULT;
|
||||
fc.len = c;
|
||||
if (fc.pg) flush_dcache_page(fc.pg); /* CPU 写后刷 cache 供设备读 */
|
||||
return c;
|
||||
}
|
||||
|
||||
static ssize_t f_read(struct file *filp, char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
ssize_t r;
|
||||
(void)filp; (void)o;
|
||||
if (fc.pg) flush_dcache_page(fc.pg); /* 设备写后刷 cache 供 CPU 读 */
|
||||
c = min(c, fc.len);
|
||||
r = copy_to_user(u, fc.buf, c) ? -EFAULT : (ssize_t)c;
|
||||
return r;
|
||||
}
|
||||
|
||||
static int f_open(struct inode *i, struct file *filp) { (void)i; (void)filp; return 0; }
|
||||
static const struct file_operations ffops = {
|
||||
.owner = THIS_MODULE, .open = f_open, .read = f_read, .write = f_write,
|
||||
};
|
||||
|
||||
static int __init f_init(void)
|
||||
{
|
||||
int err = alloc_chrdev_region(&devno, 0, 1, "scullcacheflush");
|
||||
if (err) return err;
|
||||
fc.pg = NULL;
|
||||
cdev_init(&fc.cdev, &ffops);
|
||||
fc.cdev.owner = THIS_MODULE;
|
||||
err = cdev_add(&fc.cdev, devno, 1);
|
||||
if (err) unregister_chrdev_region(devno, 1);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void __exit f_exit(void) { cdev_del(&fc.cdev); unregister_chrdev_region(devno, 1); }
|
||||
|
||||
module_init(f_init);
|
||||
module_exit(f_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("LDD3");
|
||||
MODULE_DESCRIPTION("scull cache flush dcache dma");
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L3 HIL Behavior Checks for ldd3-circular-buffer-lockless.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
Verifies deployed program behavior on RDK board via DGAgent SSH.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def ssh_exec(board_id, command, timeout=10):
|
||||
"""Execute command on board via DGAgent dg_ssh_exec tool."""
|
||||
result = subprocess.run(
|
||||
["pi", "tool", "dg_ssh_exec",
|
||||
"--board", board_id, "--command", command,
|
||||
"--timeout", str(timeout)],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
return result.stdout, result.stderr, result.returncode
|
||||
|
||||
|
||||
def check_binary_exists(board_id, remote_path):
|
||||
"""Check if deployed binary exists."""
|
||||
stdout, _, _ = ssh_exec(board_id, f"test -f {remote_path} && echo EXISTS")
|
||||
return "EXISTS" in stdout
|
||||
|
||||
|
||||
def check_program_runs(board_id, remote_path):
|
||||
"""Check program starts without crash."""
|
||||
stdout, stderr, rc = ssh_exec(board_id, f"timeout 5 {remote_path} 2>&1 | head -5")
|
||||
return rc is not None
|
||||
|
||||
|
||||
def run_all_checks(board_id="rdk-x5", remote_path="/opt/ebd_harness/ldd3-circular-buffer-lockless"):
|
||||
"""Run all L3 behavior checks."""
|
||||
results = []
|
||||
results.append({"check": "binary_exists", "pass": check_binary_exists(board_id, remote_path)})
|
||||
results.append({"check": "program_runs", "pass": check_program_runs(board_id, remote_path)})
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
board = sys.argv[1] if len(sys.argv) > 1 else "rdk-x5"
|
||||
results = run_all_checks(board_id=board)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L0 Static Analysis Checks for ldd3-circular-buffer-lockless.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
def check_lock_order(source_file):
|
||||
"""Check that mutex lock/unlock are balanced."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
locks = content.count("pthread_mutex_lock(") + content.count("std::lock_guard")
|
||||
unlocks = content.count("pthread_mutex_unlock(") + content.count("}")
|
||||
if locks == 0:
|
||||
return {"check": "lock_order", "pass": True}
|
||||
# lock_guard auto-unlocks, so just check existence of unlock pattern
|
||||
has_unlock = "unlock" in content or "lock_guard" in content or "unique_lock" in content
|
||||
if not has_unlock:
|
||||
return {"check": "lock_order", "pass": False,
|
||||
"detail": "Mutex locked but never unlocked"}
|
||||
return {"check": "lock_order", "pass": True}
|
||||
|
||||
def check_volatile(source_file):
|
||||
"""Check that shared variables use volatile."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
# Look for signal handler shared variable pattern
|
||||
if "signal_handler" in content or "signal(" in content:
|
||||
if "volatile" not in content:
|
||||
return {"check": "volatile_on_shared_var", "pass": False,
|
||||
"detail": "Signal handler shared variable must use volatile"}
|
||||
return {"check": "volatile_on_shared_var", "pass": True}
|
||||
|
||||
def run_all_checks(source_file):
|
||||
"""Run all L0 checks."""
|
||||
results = []
|
||||
results.append(check_lock_order(source_file))
|
||||
results.append(check_volatile(source_file))
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
source = sys.argv[1] if len(sys.argv) > 1 else "reference/main.c"
|
||||
results = run_all_checks(source)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,25 @@
|
||||
id: ldd3-circular-buffer-lockless
|
||||
capability: code-gen
|
||||
difficulty: hard
|
||||
platform: arm64-linux
|
||||
build_system: makefile
|
||||
implicit_knowledge:
|
||||
- lock_ordering
|
||||
- smp_wmb_rmb_pairing
|
||||
- spsc_ring
|
||||
- volatile
|
||||
paired_case: null
|
||||
embed_gap_metric: false
|
||||
eval_layers:
|
||||
l0_static: true
|
||||
l1_compile: true
|
||||
l2_simulate: false
|
||||
l3_hil: true
|
||||
l4_mutation: false
|
||||
max_iterations: 10
|
||||
max_tool_calls_per_iteration: 30
|
||||
timeout_seconds: 600
|
||||
source: ldd3
|
||||
source_url: https://lwn.net/Kernel/LDD3/
|
||||
visibility: public
|
||||
line: arm-linux
|
||||
@ -0,0 +1,26 @@
|
||||
# 无锁环形缓冲: 单生产单消费 + 内存屏障
|
||||
|
||||
## 目标
|
||||
|
||||
实现 SPSC(单生产单消费)环形缓冲:生产者写后 smp_wmb 再推进 head,消费者 smp_rmb 读 head 后再读数据。无锁无竞争,展示 volatile 屏障与 lock_ordering 的高性能范式。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后一个生产者 write 入队 N 字节,一个消费者 read 出队相同字节;无锁下数据不撕裂(head/tail 单方向更新);缓冲满 write 丢弃多余;rmmod 无告警。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 多个 mutex 必须保持一致的获取顺序,避免死锁
|
||||
- 共享变量(如信号处理函数中使用的标志位)必须使用 volatile 关键字
|
||||
@ -0,0 +1,21 @@
|
||||
# 无锁环形缓冲: 单生产单消费 + 内存屏障
|
||||
|
||||
## 目标
|
||||
|
||||
实现 SPSC(单生产单消费)环形缓冲:生产者写后 smp_wmb 再推进 head,消费者 smp_rmb 读 head 后再读数据。无锁无竞争,展示 volatile 屏障与 lock_ordering 的高性能范式。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后一个生产者 write 入队 N 字节,一个消费者 read 出队相同字节;无锁下数据不撕裂(head/tail 单方向更新);缓冲满 write 丢弃多余;rmmod 无告警。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
@ -0,0 +1,81 @@
|
||||
/* ldd3-circular-buffer-lockless: SPSC 无锁环形 */
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/atomic.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
#define RING 256
|
||||
struct ringbuf {
|
||||
char data[RING];
|
||||
unsigned int head; /* 生产者写 */
|
||||
unsigned int tail; /* 消费者写 */
|
||||
struct cdev cdev;
|
||||
};
|
||||
static struct ringbuf rb;
|
||||
static dev_t devno;
|
||||
|
||||
static ssize_t rb_write(struct file *f, const char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
unsigned int h, t, i, n = 0;
|
||||
char tmp[RING];
|
||||
(void)f; (void)o;
|
||||
if (c > RING) c = RING;
|
||||
if (copy_from_user(tmp, u, c)) return -EFAULT;
|
||||
t = smp_load_acquire(&rb.tail); /* 读消费者位置 */
|
||||
h = rb.head;
|
||||
for (i = 0; i < c; i++) {
|
||||
unsigned int next = (h + 1) % RING;
|
||||
if (next == t) break; /* 满 */
|
||||
rb.data[h] = tmp[i];
|
||||
h = next;
|
||||
n++;
|
||||
}
|
||||
smp_store_release(&rb.head, h); /* 发布: 数据先于 head */
|
||||
return n;
|
||||
}
|
||||
|
||||
static ssize_t rb_read(struct file *f, char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
unsigned int h, tl, i, n = 0;
|
||||
char tmp[RING];
|
||||
(void)f; (void)o;
|
||||
if (c > RING) c = RING;
|
||||
h = smp_load_acquire(&rb.head); /* 读生产者位置 */
|
||||
tl = rb.tail;
|
||||
for (i = 0; i < c; i++) {
|
||||
if (tl == h) break; /* 空 */
|
||||
tmp[i] = rb.data[tl];
|
||||
tl = (tl + 1) % RING;
|
||||
n++;
|
||||
}
|
||||
smp_store_release(&rb.tail, tl);
|
||||
if (n == 0) return 0;
|
||||
if (copy_to_user(u, tmp, n)) return -EFAULT;
|
||||
return n;
|
||||
}
|
||||
|
||||
static int rb_open(struct inode *i, struct file *f) { (void)i; (void)f; return 0; }
|
||||
static const struct file_operations rbfops = {
|
||||
.owner = THIS_MODULE, .open = rb_open, .read = rb_read, .write = rb_write,
|
||||
};
|
||||
|
||||
static int __init rb_init(void)
|
||||
{
|
||||
int err = alloc_chrdev_region(&devno, 0, 1, "sculllockless");
|
||||
if (err) return err;
|
||||
cdev_init(&rb.cdev, &rbfops);
|
||||
rb.cdev.owner = THIS_MODULE;
|
||||
err = cdev_add(&rb.cdev, devno, 1);
|
||||
if (err) unregister_chrdev_region(devno, 1);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void __exit rb_exit(void) { cdev_del(&rb.cdev); unregister_chrdev_region(devno, 1); }
|
||||
|
||||
module_init(rb_init);
|
||||
module_exit(rb_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("LDD3");
|
||||
MODULE_DESCRIPTION("scull circular buffer lockless");
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L3 HIL Behavior Checks for ldd3-cmpxchg-lockfree-update.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
Verifies deployed program behavior on RDK board via DGAgent SSH.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def ssh_exec(board_id, command, timeout=10):
|
||||
"""Execute command on board via DGAgent dg_ssh_exec tool."""
|
||||
result = subprocess.run(
|
||||
["pi", "tool", "dg_ssh_exec",
|
||||
"--board", board_id, "--command", command,
|
||||
"--timeout", str(timeout)],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
return result.stdout, result.stderr, result.returncode
|
||||
|
||||
|
||||
def check_binary_exists(board_id, remote_path):
|
||||
"""Check if deployed binary exists."""
|
||||
stdout, _, _ = ssh_exec(board_id, f"test -f {remote_path} && echo EXISTS")
|
||||
return "EXISTS" in stdout
|
||||
|
||||
|
||||
def check_program_runs(board_id, remote_path):
|
||||
"""Check program starts without crash."""
|
||||
stdout, stderr, rc = ssh_exec(board_id, f"timeout 5 {remote_path} 2>&1 | head -5")
|
||||
return rc is not None
|
||||
|
||||
|
||||
def run_all_checks(board_id="rdk-x5", remote_path="/opt/ebd_harness/ldd3-cmpxchg-lockfree-update"):
|
||||
"""Run all L3 behavior checks."""
|
||||
results = []
|
||||
results.append({"check": "binary_exists", "pass": check_binary_exists(board_id, remote_path)})
|
||||
results.append({"check": "program_runs", "pass": check_program_runs(board_id, remote_path)})
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
board = sys.argv[1] if len(sys.argv) > 1 else "rdk-x5"
|
||||
results = run_all_checks(board_id=board)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L0 Static Analysis Checks for ldd3-cmpxchg-lockfree-update.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
def check_lock_order(source_file):
|
||||
"""Check that mutex lock/unlock are balanced."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
locks = content.count("pthread_mutex_lock(") + content.count("std::lock_guard")
|
||||
unlocks = content.count("pthread_mutex_unlock(") + content.count("}")
|
||||
if locks == 0:
|
||||
return {"check": "lock_order", "pass": True}
|
||||
# lock_guard auto-unlocks, so just check existence of unlock pattern
|
||||
has_unlock = "unlock" in content or "lock_guard" in content or "unique_lock" in content
|
||||
if not has_unlock:
|
||||
return {"check": "lock_order", "pass": False,
|
||||
"detail": "Mutex locked but never unlocked"}
|
||||
return {"check": "lock_order", "pass": True}
|
||||
|
||||
def check_resource_cleanup(source_file):
|
||||
"""Check that all opened resources are closed."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
opens = content.count("open(") + content.count("fopen(")
|
||||
closes = content.count("close(") + content.count("fclose(")
|
||||
if opens > closes:
|
||||
return {"check": "resource_cleanup", "pass": False,
|
||||
"detail": f"Opened {opens} resources but only closed {closes}"}
|
||||
return {"check": "resource_cleanup", "pass": True}
|
||||
|
||||
def run_all_checks(source_file):
|
||||
"""Run all L0 checks."""
|
||||
results = []
|
||||
results.append(check_lock_order(source_file))
|
||||
results.append(check_resource_cleanup(source_file))
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
source = sys.argv[1] if len(sys.argv) > 1 else "reference/main.c"
|
||||
results = run_all_checks(source)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,25 @@
|
||||
id: ldd3-cmpxchg-lockfree-update
|
||||
capability: code-gen
|
||||
difficulty: hard
|
||||
platform: arm64-linux
|
||||
build_system: makefile
|
||||
implicit_knowledge:
|
||||
- cmpxchg
|
||||
- lock_ordering
|
||||
- lockfree_cas_loop
|
||||
- resource_management
|
||||
paired_case: null
|
||||
embed_gap_metric: false
|
||||
eval_layers:
|
||||
l0_static: true
|
||||
l1_compile: true
|
||||
l2_simulate: false
|
||||
l3_hil: true
|
||||
l4_mutation: false
|
||||
max_iterations: 10
|
||||
max_tool_calls_per_iteration: 30
|
||||
timeout_seconds: 600
|
||||
source: ldd3
|
||||
source_url: https://lwn.net/Kernel/LDD3/
|
||||
visibility: public
|
||||
line: arm-linux
|
||||
@ -0,0 +1,26 @@
|
||||
# cmpxchg: 无锁原子比较交换
|
||||
|
||||
## 目标
|
||||
|
||||
用 cmpxchg 实现无锁的 'compare and swap' 更新循环:读旧值,计算新值,cmpxchg 失败则重试。展示 lock_ordering 的无锁原子更新范式。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后并发 write 用 cmpxchg 累加共享值,read 返回的值等于总写入次数(无丢失更新);无锁无死锁;rmmod 无告警。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 多个 mutex 必须保持一致的获取顺序,避免死锁
|
||||
- 所有打开的文件描述符/资源必须在所有退出路径上正确关闭
|
||||
@ -0,0 +1,21 @@
|
||||
# cmpxchg: 无锁原子比较交换
|
||||
|
||||
## 目标
|
||||
|
||||
用 cmpxchg 实现无锁的 'compare and swap' 更新循环:读旧值,计算新值,cmpxchg 失败则重试。展示 lock_ordering 的无锁原子更新范式。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后并发 write 用 cmpxchg 累加共享值,read 返回的值等于总写入次数(无丢失更新);无锁无死锁;rmmod 无告警。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
@ -0,0 +1,56 @@
|
||||
/* ldd3-cmpxchg-lockfree-update: 无锁 cmpxchg 更新 */
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/atomic.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
static atomic_t acc = ATOMIC_INIT(0);
|
||||
static struct cdev ccdev;
|
||||
static dev_t devno;
|
||||
|
||||
static ssize_t c_write(struct file *f, const char __user *u, size_t cnt, loff_t *o)
|
||||
{
|
||||
int old, new;
|
||||
int inc = 1;
|
||||
(void)f; (void)u; (void)o;
|
||||
do {
|
||||
old = atomic_read(&acc);
|
||||
new = old + inc;
|
||||
} while (atomic_cmpxchg(&acc, old, new) != old);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
static ssize_t c_read(struct file *f, char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
int v;
|
||||
(void)f; (void)o;
|
||||
if (c < sizeof(int)) return -EINVAL;
|
||||
v = atomic_read(&acc);
|
||||
return put_user(v, (int __user *)u) ? -EFAULT : sizeof(int);
|
||||
}
|
||||
|
||||
static int c_open(struct inode *i, struct file *f) { (void)i; (void)f; return 0; }
|
||||
static const struct file_operations cfops = {
|
||||
.owner = THIS_MODULE, .open = c_open, .read = c_read, .write = c_write,
|
||||
};
|
||||
|
||||
static int __init c_init(void)
|
||||
{
|
||||
int err = alloc_chrdev_region(&devno, 0, 1, "scullcmpxchg");
|
||||
if (err) return err;
|
||||
cdev_init(&ccdev, &cfops);
|
||||
ccdev.owner = THIS_MODULE;
|
||||
err = cdev_add(&ccdev, devno, 1);
|
||||
if (err) unregister_chrdev_region(devno, 1);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void __exit c_exit(void) { cdev_del(&ccdev); unregister_chrdev_region(devno, 1); }
|
||||
|
||||
module_init(c_init);
|
||||
module_exit(c_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("LDD3");
|
||||
MODULE_DESCRIPTION("scull cmpxchg lockfree update");
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L3 HIL Behavior Checks for ldd3-completion-timeout-wait.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
Verifies deployed program behavior on RDK board via DGAgent SSH.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def ssh_exec(board_id, command, timeout=10):
|
||||
"""Execute command on board via DGAgent dg_ssh_exec tool."""
|
||||
result = subprocess.run(
|
||||
["pi", "tool", "dg_ssh_exec",
|
||||
"--board", board_id, "--command", command,
|
||||
"--timeout", str(timeout)],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
return result.stdout, result.stderr, result.returncode
|
||||
|
||||
|
||||
def check_binary_exists(board_id, remote_path):
|
||||
"""Check if deployed binary exists."""
|
||||
stdout, _, _ = ssh_exec(board_id, f"test -f {remote_path} && echo EXISTS")
|
||||
return "EXISTS" in stdout
|
||||
|
||||
|
||||
def check_program_runs(board_id, remote_path):
|
||||
"""Check program starts without crash."""
|
||||
stdout, stderr, rc = ssh_exec(board_id, f"timeout 5 {remote_path} 2>&1 | head -5")
|
||||
return rc is not None
|
||||
|
||||
|
||||
def run_all_checks(board_id="rdk-x5", remote_path="/opt/ebd_harness/ldd3-completion-timeout-wait"):
|
||||
"""Run all L3 behavior checks."""
|
||||
results = []
|
||||
results.append({"check": "binary_exists", "pass": check_binary_exists(board_id, remote_path)})
|
||||
results.append({"check": "program_runs", "pass": check_program_runs(board_id, remote_path)})
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
board = sys.argv[1] if len(sys.argv) > 1 else "rdk-x5"
|
||||
results = run_all_checks(board_id=board)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L0 Static Analysis Checks for ldd3-completion-timeout-wait.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
def check_resource_cleanup(source_file):
|
||||
"""Check that all opened resources are closed."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
opens = content.count("open(") + content.count("fopen(")
|
||||
closes = content.count("close(") + content.count("fclose(")
|
||||
if opens > closes:
|
||||
return {"check": "resource_cleanup", "pass": False,
|
||||
"detail": f"Opened {opens} resources but only closed {closes}"}
|
||||
return {"check": "resource_cleanup", "pass": True}
|
||||
|
||||
def check_signal_safety(source_file):
|
||||
"""Check that signal handler only uses async-signal-safe functions."""
|
||||
import re
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
handler_match = re.search(r'void\s+\w*[Ss]ignal\w*\s*\([^)]*\)\s*\{([^}]*)\}', content)
|
||||
if not handler_match:
|
||||
return {"check": "signal_safety", "pass": True, "detail": "No signal handler found"}
|
||||
handler_body = handler_match.group(1)
|
||||
unsafe = ["printf", "malloc", "free", "fopen", "sleep", "usleep", "fread", "fwrite"]
|
||||
found = [f for f in unsafe if f + "(" in handler_body]
|
||||
if found:
|
||||
return {"check": "signal_safety", "pass": False,
|
||||
"detail": f"Unsafe calls in signal handler: {found}"}
|
||||
return {"check": "signal_safety", "pass": True}
|
||||
|
||||
def run_all_checks(source_file):
|
||||
"""Run all L0 checks."""
|
||||
results = []
|
||||
results.append(check_resource_cleanup(source_file))
|
||||
results.append(check_signal_safety(source_file))
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
source = sys.argv[1] if len(sys.argv) > 1 else "reference/main.c"
|
||||
results = run_all_checks(source)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,25 @@
|
||||
id: ldd3-completion-timeout-wait
|
||||
capability: code-gen
|
||||
difficulty: medium
|
||||
platform: arm64-linux
|
||||
build_system: makefile
|
||||
implicit_knowledge:
|
||||
- complete_producer
|
||||
- resource_management
|
||||
- signal_safety
|
||||
- wait_for_completion_timeout
|
||||
paired_case: null
|
||||
embed_gap_metric: false
|
||||
eval_layers:
|
||||
l0_static: true
|
||||
l1_compile: true
|
||||
l2_simulate: false
|
||||
l3_hil: true
|
||||
l4_mutation: false
|
||||
max_iterations: 10
|
||||
max_tool_calls_per_iteration: 30
|
||||
timeout_seconds: 600
|
||||
source: ldd3
|
||||
source_url: https://lwn.net/Kernel/LDD3/
|
||||
visibility: public
|
||||
line: arm-linux
|
||||
@ -0,0 +1,26 @@
|
||||
# completion: wait_for_completion_timeout 带超时等待
|
||||
|
||||
## 目标
|
||||
|
||||
producer write 路径 complete,consumer read 用 wait_for_completion_timeout 限时等待(超时返回 0 不死等);超时计数器可观测。展示资源(完成量)配对与 signal_safety。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后先 read 阻塞,另一终端 write 后 read 立即返回;5 秒不 write 则 read 因超时返回 0;以 O_NONBLOCK 打开无 complete 时 read 立即返回 EAGAIN;无悬挂完成量泄漏。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 所有打开的文件描述符/资源必须在所有退出路径上正确关闭
|
||||
- 信号处理函数中只能调用异步信号安全函数(async-signal-safe)
|
||||
@ -0,0 +1,21 @@
|
||||
# completion: wait_for_completion_timeout 带超时等待
|
||||
|
||||
## 目标
|
||||
|
||||
producer write 路径 complete,consumer read 用 wait_for_completion_timeout 限时等待(超时返回 0 不死等);超时计数器可观测。展示资源(完成量)配对与 signal_safety。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后先 read 阻塞,另一终端 write 后 read 立即返回;5 秒不 write 则 read 因超时返回 0;以 O_NONBLOCK 打开无 complete 时 read 立即返回 EAGAIN;无悬挂完成量泄漏。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
@ -0,0 +1,63 @@
|
||||
/* ldd3-completion-timeout-wait: 带超时完成量 */
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/completion.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
struct cctx { struct completion done; int ready; unsigned long timeouts; struct cdev cdev; };
|
||||
static struct cctx cd;
|
||||
static dev_t devno;
|
||||
|
||||
static ssize_t c_read(struct file *f, char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
int v;
|
||||
(void)u; (void)c; (void)o;
|
||||
if (f->f_flags & O_NONBLOCK) {
|
||||
if (!cd.ready) return -EAGAIN;
|
||||
return 0;
|
||||
}
|
||||
if (!wait_for_completion_timeout(&cd.done, msecs_to_jiffies(5000))) {
|
||||
cd.timeouts++;
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
v = cd.ready;
|
||||
return 0;
|
||||
(void)v;
|
||||
}
|
||||
|
||||
static ssize_t c_write(struct file *f, const char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
(void)f; (void)u; (void)o;
|
||||
cd.ready = 1;
|
||||
complete(&cd.done);
|
||||
return c;
|
||||
}
|
||||
|
||||
static int c_open(struct inode *i, struct file *f) { (void)i; (void)f; return 0; }
|
||||
static const struct file_operations cfops = {
|
||||
.owner = THIS_MODULE, .open = c_open, .read = c_read, .write = c_write,
|
||||
};
|
||||
|
||||
static int __init c_init(void)
|
||||
{
|
||||
int err = alloc_chrdev_region(&devno, 0, 1, "scullcompto");
|
||||
if (err) return err;
|
||||
init_completion(&cd.done);
|
||||
cdev_init(&cd.cdev, &cfops);
|
||||
cd.cdev.owner = THIS_MODULE;
|
||||
err = cdev_add(&cd.cdev, devno, 1);
|
||||
if (err) unregister_chrdev_region(devno, 1);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void __exit c_exit(void) { cdev_del(&cd.cdev); unregister_chrdev_region(devno, 1); }
|
||||
|
||||
module_init(c_init);
|
||||
module_exit(c_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("LDD3");
|
||||
MODULE_DESCRIPTION("scull completion timeout wait");
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L3 HIL Behavior Checks for ldd3-cpu-notifier-hotplug.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
Verifies deployed program behavior on RDK board via DGAgent SSH.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def ssh_exec(board_id, command, timeout=10):
|
||||
"""Execute command on board via DGAgent dg_ssh_exec tool."""
|
||||
result = subprocess.run(
|
||||
["pi", "tool", "dg_ssh_exec",
|
||||
"--board", board_id, "--command", command,
|
||||
"--timeout", str(timeout)],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
return result.stdout, result.stderr, result.returncode
|
||||
|
||||
|
||||
def check_binary_exists(board_id, remote_path):
|
||||
"""Check if deployed binary exists."""
|
||||
stdout, _, _ = ssh_exec(board_id, f"test -f {remote_path} && echo EXISTS")
|
||||
return "EXISTS" in stdout
|
||||
|
||||
|
||||
def check_program_runs(board_id, remote_path):
|
||||
"""Check program starts without crash."""
|
||||
stdout, stderr, rc = ssh_exec(board_id, f"timeout 5 {remote_path} 2>&1 | head -5")
|
||||
return rc is not None
|
||||
|
||||
|
||||
def run_all_checks(board_id="rdk-x5", remote_path="/opt/ebd_harness/ldd3-cpu-notifier-hotplug"):
|
||||
"""Run all L3 behavior checks."""
|
||||
results = []
|
||||
results.append({"check": "binary_exists", "pass": check_binary_exists(board_id, remote_path)})
|
||||
results.append({"check": "program_runs", "pass": check_program_runs(board_id, remote_path)})
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
board = sys.argv[1] if len(sys.argv) > 1 else "rdk-x5"
|
||||
results = run_all_checks(board_id=board)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L0 Static Analysis Checks for ldd3-cpu-notifier-hotplug.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
def check_lock_order(source_file):
|
||||
"""Check that mutex lock/unlock are balanced."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
locks = content.count("pthread_mutex_lock(") + content.count("std::lock_guard")
|
||||
unlocks = content.count("pthread_mutex_unlock(") + content.count("}")
|
||||
if locks == 0:
|
||||
return {"check": "lock_order", "pass": True}
|
||||
# lock_guard auto-unlocks, so just check existence of unlock pattern
|
||||
has_unlock = "unlock" in content or "lock_guard" in content or "unique_lock" in content
|
||||
if not has_unlock:
|
||||
return {"check": "lock_order", "pass": False,
|
||||
"detail": "Mutex locked but never unlocked"}
|
||||
return {"check": "lock_order", "pass": True}
|
||||
|
||||
def check_resource_cleanup(source_file):
|
||||
"""Check that all opened resources are closed."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
opens = content.count("open(") + content.count("fopen(")
|
||||
closes = content.count("close(") + content.count("fclose(")
|
||||
if opens > closes:
|
||||
return {"check": "resource_cleanup", "pass": False,
|
||||
"detail": f"Opened {opens} resources but only closed {closes}"}
|
||||
return {"check": "resource_cleanup", "pass": True}
|
||||
|
||||
def run_all_checks(source_file):
|
||||
"""Run all L0 checks."""
|
||||
results = []
|
||||
results.append(check_lock_order(source_file))
|
||||
results.append(check_resource_cleanup(source_file))
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
source = sys.argv[1] if len(sys.argv) > 1 else "reference/main.c"
|
||||
results = run_all_checks(source)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,25 @@
|
||||
id: ldd3-cpu-notifier-hotplug
|
||||
capability: code-gen
|
||||
difficulty: hard
|
||||
platform: arm64-linux
|
||||
build_system: makefile
|
||||
implicit_knowledge:
|
||||
- cpuhp_remove_state
|
||||
- cpuhp_setup_state
|
||||
- lock_ordering
|
||||
- resource_management
|
||||
paired_case: null
|
||||
embed_gap_metric: false
|
||||
eval_layers:
|
||||
l0_static: true
|
||||
l1_compile: true
|
||||
l2_simulate: false
|
||||
l3_hil: true
|
||||
l4_mutation: false
|
||||
max_iterations: 10
|
||||
max_tool_calls_per_iteration: 30
|
||||
timeout_seconds: 600
|
||||
source: ldd3
|
||||
source_url: https://lwn.net/Kernel/LDD3/
|
||||
visibility: public
|
||||
line: arm-linux
|
||||
@ -0,0 +1,26 @@
|
||||
# cpu hotplug: cpuhp 注册/注销状态
|
||||
|
||||
## 目标
|
||||
|
||||
用 cpuhp_setup_state 注册一个 hotplug 回调(在线/离线时被调),卸载 cpuhp_remove_state 清理。展示 CPU 热插拔资源管理与配对。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod 注册成功,dmesg 报 'cpu hp setup';CPU 上线时回调被调用计数;rmmod cpuhp_remove_state 注销,无悬挂状态。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 多个 mutex 必须保持一致的获取顺序,避免死锁
|
||||
- 所有打开的文件描述符/资源必须在所有退出路径上正确关闭
|
||||
@ -0,0 +1,21 @@
|
||||
# cpu hotplug: cpuhp 注册/注销状态
|
||||
|
||||
## 目标
|
||||
|
||||
用 cpuhp_setup_state 注册一个 hotplug 回调(在线/离线时被调),卸载 cpuhp_remove_state 清理。展示 CPU 热插拔资源管理与配对。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod 注册成功,dmesg 报 'cpu hp setup';CPU 上线时回调被调用计数;rmmod cpuhp_remove_state 注销,无悬挂状态。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
@ -0,0 +1,68 @@
|
||||
/* ldd3-cpu-notifier-hotplug: CPU 热插拔回调 */
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/cpuhotplug.h>
|
||||
#include <linux/atomic.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
static enum cpuhp_state hp_state;
|
||||
static atomic_t online = ATOMIC_INIT(0);
|
||||
static struct cdev hcdev;
|
||||
static dev_t devno;
|
||||
|
||||
static int hp_up(unsigned int cpu)
|
||||
{
|
||||
atomic_inc(&online);
|
||||
pr_info("ldd3hp: cpu %u online\n", cpu);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hp_down(unsigned int cpu)
|
||||
{
|
||||
atomic_dec(&online);
|
||||
pr_info("ldd3hp: cpu %u offline\n", cpu);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t h_read(struct file *f, char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
int v;
|
||||
(void)f; (void)o;
|
||||
if (c < sizeof(int)) return -EINVAL;
|
||||
v = atomic_read(&online);
|
||||
return put_user(v, (int __user *)u) ? -EFAULT : sizeof(int);
|
||||
}
|
||||
|
||||
static int h_open(struct inode *i, struct file *f) { (void)i; (void)f; return 0; }
|
||||
static const struct file_operations hfops = {
|
||||
.owner = THIS_MODULE, .open = h_open, .read = h_read,
|
||||
};
|
||||
|
||||
static int __init h_init(void)
|
||||
{
|
||||
int err = alloc_chrdev_region(&devno, 0, 1, "scullhp");
|
||||
if (err) return err;
|
||||
err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "ldd3/hp", hp_up, hp_down);
|
||||
if (err < 0) { unregister_chrdev_region(devno, 1); return err; }
|
||||
hp_state = err;
|
||||
cdev_init(&hcdev, &hfops);
|
||||
hcdev.owner = THIS_MODULE;
|
||||
err = cdev_add(&hcdev, devno, 1);
|
||||
if (err) { cpuhp_remove_state(hp_state); unregister_chrdev_region(devno, 1); }
|
||||
return err;
|
||||
}
|
||||
|
||||
static void __exit h_exit(void)
|
||||
{
|
||||
cpuhp_remove_state(hp_state);
|
||||
cdev_del(&hcdev);
|
||||
unregister_chrdev_region(devno, 1);
|
||||
}
|
||||
|
||||
module_init(h_init);
|
||||
module_exit(h_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("LDD3");
|
||||
MODULE_DESCRIPTION("scull cpu hotplug notifier");
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L3 HIL Behavior Checks for ldd3-debugfs-blob-readonly.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
Verifies deployed program behavior on RDK board via DGAgent SSH.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def ssh_exec(board_id, command, timeout=10):
|
||||
"""Execute command on board via DGAgent dg_ssh_exec tool."""
|
||||
result = subprocess.run(
|
||||
["pi", "tool", "dg_ssh_exec",
|
||||
"--board", board_id, "--command", command,
|
||||
"--timeout", str(timeout)],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
return result.stdout, result.stderr, result.returncode
|
||||
|
||||
|
||||
def check_binary_exists(board_id, remote_path):
|
||||
"""Check if deployed binary exists."""
|
||||
stdout, _, _ = ssh_exec(board_id, f"test -f {remote_path} && echo EXISTS")
|
||||
return "EXISTS" in stdout
|
||||
|
||||
|
||||
def check_program_runs(board_id, remote_path):
|
||||
"""Check program starts without crash."""
|
||||
stdout, stderr, rc = ssh_exec(board_id, f"timeout 5 {remote_path} 2>&1 | head -5")
|
||||
return rc is not None
|
||||
|
||||
|
||||
def run_all_checks(board_id="rdk-x5", remote_path="/opt/ebd_harness/ldd3-debugfs-blob-readonly"):
|
||||
"""Run all L3 behavior checks."""
|
||||
results = []
|
||||
results.append({"check": "binary_exists", "pass": check_binary_exists(board_id, remote_path)})
|
||||
results.append({"check": "program_runs", "pass": check_program_runs(board_id, remote_path)})
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
board = sys.argv[1] if len(sys.argv) > 1 else "rdk-x5"
|
||||
results = run_all_checks(board_id=board)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L0 Static Analysis Checks for ldd3-debugfs-blob-readonly.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
def check_memory_leak(source_file):
|
||||
"""Check that malloc/free are balanced."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
allocs = content.count("malloc(") + content.count("calloc(") + content.count("realloc(")
|
||||
frees = content.count("free(")
|
||||
if allocs > frees:
|
||||
return {"check": "memory_leak", "pass": False,
|
||||
"detail": f"Allocated {allocs} times but only freed {frees} times"}
|
||||
return {"check": "memory_leak", "pass": True}
|
||||
|
||||
def check_resource_cleanup(source_file):
|
||||
"""Check that all opened resources are closed."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
opens = content.count("open(") + content.count("fopen(")
|
||||
closes = content.count("close(") + content.count("fclose(")
|
||||
if opens > closes:
|
||||
return {"check": "resource_cleanup", "pass": False,
|
||||
"detail": f"Opened {opens} resources but only closed {closes}"}
|
||||
return {"check": "resource_cleanup", "pass": True}
|
||||
|
||||
def run_all_checks(source_file):
|
||||
"""Run all L0 checks."""
|
||||
results = []
|
||||
results.append(check_memory_leak(source_file))
|
||||
results.append(check_resource_cleanup(source_file))
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
source = sys.argv[1] if len(sys.argv) > 1 else "reference/main.c"
|
||||
results = run_all_checks(source)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,25 @@
|
||||
id: ldd3-debugfs-blob-readonly
|
||||
capability: code-gen
|
||||
difficulty: easy
|
||||
platform: arm64-linux
|
||||
build_system: makefile
|
||||
implicit_knowledge:
|
||||
- debugfs_create_blob
|
||||
- debugfs_remove_recursive
|
||||
- memory_leak
|
||||
- resource_management
|
||||
paired_case: null
|
||||
embed_gap_metric: false
|
||||
eval_layers:
|
||||
l0_static: true
|
||||
l1_compile: true
|
||||
l2_simulate: false
|
||||
l3_hil: true
|
||||
l4_mutation: false
|
||||
max_iterations: 10
|
||||
max_tool_calls_per_iteration: 30
|
||||
timeout_seconds: 600
|
||||
source: ldd3
|
||||
source_url: https://lwn.net/Kernel/LDD3/
|
||||
visibility: private
|
||||
line: arm-linux
|
||||
@ -0,0 +1,26 @@
|
||||
# debugfs blob: 二进制只读快照
|
||||
|
||||
## 目标
|
||||
|
||||
用 debugfs_create_blob 暴露一段固定二进制(如版本/校验和)为只读,cat 输出其内容。展示 debugfs 二进制资源管理。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod 后 'cat /sys/kernel/debug/scullblob/snap' 输出固定二进制串;多次 cat 输出一致;rmmod 调 debugfs_remove_recursive,debugfs 目录消失。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 动态分配的内存必须在所有退出路径上释放
|
||||
- 所有打开的文件描述符/资源必须在所有退出路径上正确关闭
|
||||
@ -0,0 +1,21 @@
|
||||
# debugfs blob: 二进制只读快照
|
||||
|
||||
## 目标
|
||||
|
||||
用 debugfs_create_blob 暴露一段固定二进制(如版本/校验和)为只读,cat 输出其内容。展示 debugfs 二进制资源管理。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod 后 'cat /sys/kernel/debug/scullblob/snap' 输出固定二进制串;多次 cat 输出一致;rmmod 调 debugfs_remove_recursive,debugfs 目录消失。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
@ -0,0 +1,27 @@
|
||||
/* ldd3-debugfs-blob-readonly: debugfs 二进制只读 */
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/debugfs.h>
|
||||
|
||||
static const char snap_data[] = "LDD3-BLOB-v1\0checksum-deadbeef";
|
||||
static struct debugfs_blob_wrapper blob = {
|
||||
.data = (void *)snap_data,
|
||||
.size = sizeof(snap_data),
|
||||
};
|
||||
static struct dentry *root;
|
||||
|
||||
static int __init bl_init(void)
|
||||
{
|
||||
root = debugfs_create_dir("scullblob", NULL);
|
||||
if (!root) return -ENOMEM;
|
||||
debugfs_create_blob("snap", 0444, root, &blob);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit bl_exit(void) { debugfs_remove_recursive(root); }
|
||||
|
||||
module_init(bl_init);
|
||||
module_exit(bl_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("LDD3");
|
||||
MODULE_DESCRIPTION("debugfs blob readonly");
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L3 HIL Behavior Checks for ldd3-delayed-work-cancel-sync.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
Verifies deployed program behavior on RDK board via DGAgent SSH.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def ssh_exec(board_id, command, timeout=10):
|
||||
"""Execute command on board via DGAgent dg_ssh_exec tool."""
|
||||
result = subprocess.run(
|
||||
["pi", "tool", "dg_ssh_exec",
|
||||
"--board", board_id, "--command", command,
|
||||
"--timeout", str(timeout)],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
return result.stdout, result.stderr, result.returncode
|
||||
|
||||
|
||||
def check_binary_exists(board_id, remote_path):
|
||||
"""Check if deployed binary exists."""
|
||||
stdout, _, _ = ssh_exec(board_id, f"test -f {remote_path} && echo EXISTS")
|
||||
return "EXISTS" in stdout
|
||||
|
||||
|
||||
def check_program_runs(board_id, remote_path):
|
||||
"""Check program starts without crash."""
|
||||
stdout, stderr, rc = ssh_exec(board_id, f"timeout 5 {remote_path} 2>&1 | head -5")
|
||||
return rc is not None
|
||||
|
||||
|
||||
def run_all_checks(board_id="rdk-x5", remote_path="/opt/ebd_harness/ldd3-delayed-work-cancel-sync"):
|
||||
"""Run all L3 behavior checks."""
|
||||
results = []
|
||||
results.append({"check": "binary_exists", "pass": check_binary_exists(board_id, remote_path)})
|
||||
results.append({"check": "program_runs", "pass": check_program_runs(board_id, remote_path)})
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
board = sys.argv[1] if len(sys.argv) > 1 else "rdk-x5"
|
||||
results = run_all_checks(board_id=board)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L0 Static Analysis Checks for ldd3-delayed-work-cancel-sync.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
def check_lock_order(source_file):
|
||||
"""Check that mutex lock/unlock are balanced."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
locks = content.count("pthread_mutex_lock(") + content.count("std::lock_guard")
|
||||
unlocks = content.count("pthread_mutex_unlock(") + content.count("}")
|
||||
if locks == 0:
|
||||
return {"check": "lock_order", "pass": True}
|
||||
# lock_guard auto-unlocks, so just check existence of unlock pattern
|
||||
has_unlock = "unlock" in content or "lock_guard" in content or "unique_lock" in content
|
||||
if not has_unlock:
|
||||
return {"check": "lock_order", "pass": False,
|
||||
"detail": "Mutex locked but never unlocked"}
|
||||
return {"check": "lock_order", "pass": True}
|
||||
|
||||
def check_resource_cleanup(source_file):
|
||||
"""Check that all opened resources are closed."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
opens = content.count("open(") + content.count("fopen(")
|
||||
closes = content.count("close(") + content.count("fclose(")
|
||||
if opens > closes:
|
||||
return {"check": "resource_cleanup", "pass": False,
|
||||
"detail": f"Opened {opens} resources but only closed {closes}"}
|
||||
return {"check": "resource_cleanup", "pass": True}
|
||||
|
||||
def run_all_checks(source_file):
|
||||
"""Run all L0 checks."""
|
||||
results = []
|
||||
results.append(check_lock_order(source_file))
|
||||
results.append(check_resource_cleanup(source_file))
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
source = sys.argv[1] if len(sys.argv) > 1 else "reference/main.c"
|
||||
results = run_all_checks(source)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,25 @@
|
||||
id: ldd3-delayed-work-cancel-sync
|
||||
capability: code-gen
|
||||
difficulty: hard
|
||||
platform: arm64-linux
|
||||
build_system: makefile
|
||||
implicit_knowledge:
|
||||
- cancel_delayed_work_sync
|
||||
- lock_ordering
|
||||
- resource_management
|
||||
- schedule_delayed_work
|
||||
paired_case: null
|
||||
embed_gap_metric: false
|
||||
eval_layers:
|
||||
l0_static: true
|
||||
l1_compile: true
|
||||
l2_simulate: false
|
||||
l3_hil: true
|
||||
l4_mutation: false
|
||||
max_iterations: 10
|
||||
max_tool_calls_per_iteration: 30
|
||||
timeout_seconds: 600
|
||||
source: ldd3
|
||||
source_url: https://lwn.net/Kernel/LDD3/
|
||||
visibility: private
|
||||
line: arm-linux
|
||||
@ -0,0 +1,26 @@
|
||||
# delayed_work: 延迟工作与 cancel_delayed_work_sync 卸载
|
||||
|
||||
## 目标
|
||||
|
||||
write 用 schedule_delayed_work 投递延迟 work,处理函数(进程上下文)打印 payload;卸载前 cancel_delayed_work_sync 确保 pending 定时器与正在运行的回调都完成,防止 use-after-free。展示延迟工作资源管理。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后每次 write 在约 1 秒后 dmesg 出现 'delayed work payload N';rmmod 时 cancel_delayed_work_sync 等待,无 WARNING/use-after-free;快速连续 write 不丢失(payload 单调递增)。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 多个 mutex 必须保持一致的获取顺序,避免死锁
|
||||
- 所有打开的文件描述符/资源必须在所有退出路径上正确关闭
|
||||
@ -0,0 +1,21 @@
|
||||
# delayed_work: 延迟工作与 cancel_delayed_work_sync 卸载
|
||||
|
||||
## 目标
|
||||
|
||||
write 用 schedule_delayed_work 投递延迟 work,处理函数(进程上下文)打印 payload;卸载前 cancel_delayed_work_sync 确保 pending 定时器与正在运行的回调都完成,防止 use-after-free。展示延迟工作资源管理。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后每次 write 在约 1 秒后 dmesg 出现 'delayed work payload N';rmmod 时 cancel_delayed_work_sync 等待,无 WARNING/use-after-free;快速连续 write 不丢失(payload 单调递增)。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
@ -0,0 +1,60 @@
|
||||
/* ldd3-delayed-work-cancel-sync: 延迟工作 + 卸载同步 */
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include <linux/atomic.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
struct wctx { struct delayed_work dw; unsigned long payload; struct cdev cdev; };
|
||||
static struct wctx *wd;
|
||||
static dev_t devno;
|
||||
|
||||
static void dw_handler(struct work_struct *w)
|
||||
{
|
||||
struct wctx *d = container_of(w, struct wctx, dw.work);
|
||||
pr_info("ldd3dw: delayed work payload %lu\n", d->payload);
|
||||
}
|
||||
|
||||
static ssize_t dw_write(struct file *f, const char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
struct wctx *d = f->private_data;
|
||||
(void)f; (void)u; (void)o;
|
||||
d->payload++;
|
||||
schedule_delayed_work(&d->dw, msecs_to_jiffies(1000));
|
||||
return c;
|
||||
}
|
||||
|
||||
static int dw_open(struct inode *i, struct file *f) { (void)i; f->private_data = wd; return 0; }
|
||||
static const struct file_operations dwfops = {
|
||||
.owner = THIS_MODULE, .open = dw_open, .write = dw_write,
|
||||
};
|
||||
|
||||
static int __init dw_init(void)
|
||||
{
|
||||
int err = alloc_chrdev_region(&devno, 0, 1, "sculldw");
|
||||
if (err) return err;
|
||||
wd = kzalloc(sizeof(*wd), GFP_KERNEL);
|
||||
if (!wd) { unregister_chrdev_region(devno, 1); return -ENOMEM; }
|
||||
INIT_DELAYED_WORK(&wd->dw, dw_handler);
|
||||
cdev_init(&wd->cdev, &dwfops);
|
||||
wd->cdev.owner = THIS_MODULE;
|
||||
err = cdev_add(&wd->cdev, devno, 1);
|
||||
if (err) { kfree(wd); unregister_chrdev_region(devno, 1); }
|
||||
return err;
|
||||
}
|
||||
|
||||
static void __exit dw_exit(void)
|
||||
{
|
||||
cancel_delayed_work_sync(&wd->dw);
|
||||
cdev_del(&wd->cdev);
|
||||
kfree(wd);
|
||||
unregister_chrdev_region(devno, 1);
|
||||
}
|
||||
|
||||
module_init(dw_init);
|
||||
module_exit(dw_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("LDD3");
|
||||
MODULE_DESCRIPTION("scull delayed work cancel sync");
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L3 HIL Behavior Checks for ldd3-disable-irq-enable-pair.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
Verifies deployed program behavior on RDK board via DGAgent SSH.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def ssh_exec(board_id, command, timeout=10):
|
||||
"""Execute command on board via DGAgent dg_ssh_exec tool."""
|
||||
result = subprocess.run(
|
||||
["pi", "tool", "dg_ssh_exec",
|
||||
"--board", board_id, "--command", command,
|
||||
"--timeout", str(timeout)],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
return result.stdout, result.stderr, result.returncode
|
||||
|
||||
|
||||
def check_binary_exists(board_id, remote_path):
|
||||
"""Check if deployed binary exists."""
|
||||
stdout, _, _ = ssh_exec(board_id, f"test -f {remote_path} && echo EXISTS")
|
||||
return "EXISTS" in stdout
|
||||
|
||||
|
||||
def check_program_runs(board_id, remote_path):
|
||||
"""Check program starts without crash."""
|
||||
stdout, stderr, rc = ssh_exec(board_id, f"timeout 5 {remote_path} 2>&1 | head -5")
|
||||
return rc is not None
|
||||
|
||||
|
||||
def run_all_checks(board_id="rdk-x5", remote_path="/opt/ebd_harness/ldd3-disable-irq-enable-pair"):
|
||||
"""Run all L3 behavior checks."""
|
||||
results = []
|
||||
results.append({"check": "binary_exists", "pass": check_binary_exists(board_id, remote_path)})
|
||||
results.append({"check": "program_runs", "pass": check_program_runs(board_id, remote_path)})
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
board = sys.argv[1] if len(sys.argv) > 1 else "rdk-x5"
|
||||
results = run_all_checks(board_id=board)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L0 Static Analysis Checks for ldd3-disable-irq-enable-pair.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
def check_lock_order(source_file):
|
||||
"""Check that mutex lock/unlock are balanced."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
locks = content.count("pthread_mutex_lock(") + content.count("std::lock_guard")
|
||||
unlocks = content.count("pthread_mutex_unlock(") + content.count("}")
|
||||
if locks == 0:
|
||||
return {"check": "lock_order", "pass": True}
|
||||
# lock_guard auto-unlocks, so just check existence of unlock pattern
|
||||
has_unlock = "unlock" in content or "lock_guard" in content or "unique_lock" in content
|
||||
if not has_unlock:
|
||||
return {"check": "lock_order", "pass": False,
|
||||
"detail": "Mutex locked but never unlocked"}
|
||||
return {"check": "lock_order", "pass": True}
|
||||
|
||||
def check_resource_cleanup(source_file):
|
||||
"""Check that all opened resources are closed."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
opens = content.count("open(") + content.count("fopen(")
|
||||
closes = content.count("close(") + content.count("fclose(")
|
||||
if opens > closes:
|
||||
return {"check": "resource_cleanup", "pass": False,
|
||||
"detail": f"Opened {opens} resources but only closed {closes}"}
|
||||
return {"check": "resource_cleanup", "pass": True}
|
||||
|
||||
def run_all_checks(source_file):
|
||||
"""Run all L0 checks."""
|
||||
results = []
|
||||
results.append(check_lock_order(source_file))
|
||||
results.append(check_resource_cleanup(source_file))
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
source = sys.argv[1] if len(sys.argv) > 1 else "reference/main.c"
|
||||
results = run_all_checks(source)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,25 @@
|
||||
id: ldd3-disable-irq-enable-pair
|
||||
capability: code-gen
|
||||
difficulty: medium
|
||||
platform: arm64-linux
|
||||
build_system: makefile
|
||||
implicit_knowledge:
|
||||
- disable_irq
|
||||
- enable_irq
|
||||
- lock_ordering
|
||||
- resource_management
|
||||
paired_case: null
|
||||
embed_gap_metric: false
|
||||
eval_layers:
|
||||
l0_static: true
|
||||
l1_compile: true
|
||||
l2_simulate: false
|
||||
l3_hil: true
|
||||
l4_mutation: false
|
||||
max_iterations: 10
|
||||
max_tool_calls_per_iteration: 30
|
||||
timeout_seconds: 600
|
||||
source: ldd3
|
||||
source_url: https://lwn.net/Kernel/LDD3/
|
||||
visibility: public
|
||||
line: arm-linux
|
||||
@ -0,0 +1,26 @@
|
||||
# disable_irq/enable_irq: 临时屏蔽本线中断
|
||||
|
||||
## 目标
|
||||
|
||||
用 disable_irq_nosync/enable_irq 临时屏蔽某 IRQ 线(等待其 handler 完成或保护临界区),严格配对(enable 平衡 disable)。展示中断线级资源管理与配对计数。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后 ioctl disable 屏蔽本 IRQ,期间该中断不触发计数;ioctl enable 恢复;disable/enable 计数严格平衡;rmmod 无 'enable_irq unbalanced' 告警(板上 not_in_v0)。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 多个 mutex 必须保持一致的获取顺序,避免死锁
|
||||
- 所有打开的文件描述符/资源必须在所有退出路径上正确关闭
|
||||
@ -0,0 +1,21 @@
|
||||
# disable_irq/enable_irq: 临时屏蔽本线中断
|
||||
|
||||
## 目标
|
||||
|
||||
用 disable_irq_nosync/enable_irq 临时屏蔽某 IRQ 线(等待其 handler 完成或保护临界区),严格配对(enable 平衡 disable)。展示中断线级资源管理与配对计数。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod+mknod 后 ioctl disable 屏蔽本 IRQ,期间该中断不触发计数;ioctl enable 恢复;disable/enable 计数严格平衡;rmmod 无 'enable_irq unbalanced' 告警(板上 not_in_v0)。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
@ -0,0 +1,68 @@
|
||||
/* ldd3-disable-irq-enable-pair: 中断线屏蔽配对 */
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/atomic.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/ioctl.h>
|
||||
|
||||
#define DIRQ 0
|
||||
#define DE_IOC_MAGIC 'Y'
|
||||
#define DE_DIS _IO(DE_IOC_MAGIC, 0)
|
||||
#define DE_ENA _IO(DE_IOC_MAGIC, 1)
|
||||
|
||||
static atomic_t depth = ATOMIC_INIT(0);
|
||||
static struct cdev dcdev;
|
||||
static dev_t devno;
|
||||
|
||||
static ssize_t d_ioctl(struct file *f, unsigned int cmd, unsigned long a)
|
||||
{
|
||||
(void)f; (void)a;
|
||||
if (cmd == DE_DIS) { disable_irq_nosync(DIRQ); atomic_inc(&depth); return 0; }
|
||||
if (cmd == DE_ENA) {
|
||||
if (atomic_dec_if_positive(&depth) >= 0) enable_irq(DIRQ);
|
||||
else atomic_inc(&depth);
|
||||
return 0;
|
||||
}
|
||||
return -ENOTTY;
|
||||
}
|
||||
|
||||
static int d_open(struct inode *i, struct file *f) { (void)i; (void)f; return 0; }
|
||||
static ssize_t d_read(struct file *f, char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
int v;
|
||||
(void)f; (void)o;
|
||||
if (c < sizeof(int)) return -EINVAL;
|
||||
v = atomic_read(&depth);
|
||||
return put_user(v, (int __user *)u) ? -EFAULT : sizeof(int);
|
||||
}
|
||||
|
||||
static const struct file_operations dfops = {
|
||||
.owner = THIS_MODULE, .open = d_open, .read = d_read, .unlocked_ioctl = d_ioctl,
|
||||
};
|
||||
|
||||
static int __init d_init(void)
|
||||
{
|
||||
int err = alloc_chrdev_region(&devno, 0, 1, "sculldisirq");
|
||||
if (err) return err;
|
||||
cdev_init(&dcdev, &dfops);
|
||||
dcdev.owner = THIS_MODULE;
|
||||
err = cdev_add(&dcdev, devno, 1);
|
||||
if (err) unregister_chrdev_region(devno, 1);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void __exit d_exit(void)
|
||||
{
|
||||
while (atomic_dec_if_positive(&depth) >= 0) enable_irq(DIRQ);
|
||||
cdev_del(&dcdev);
|
||||
unregister_chrdev_region(devno, 1);
|
||||
}
|
||||
|
||||
module_init(d_init);
|
||||
module_exit(d_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("LDD3");
|
||||
MODULE_DESCRIPTION("scull disable enable irq pair");
|
||||
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L3 HIL Behavior Checks for ldd3-dma-map-single-streaming.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
Verifies deployed program behavior on RDK board via DGAgent SSH.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def ssh_exec(board_id, command, timeout=10):
|
||||
"""Execute command on board via DGAgent dg_ssh_exec tool."""
|
||||
result = subprocess.run(
|
||||
["pi", "tool", "dg_ssh_exec",
|
||||
"--board", board_id, "--command", command,
|
||||
"--timeout", str(timeout)],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
return result.stdout, result.stderr, result.returncode
|
||||
|
||||
|
||||
def check_binary_exists(board_id, remote_path):
|
||||
"""Check if deployed binary exists."""
|
||||
stdout, _, _ = ssh_exec(board_id, f"test -f {remote_path} && echo EXISTS")
|
||||
return "EXISTS" in stdout
|
||||
|
||||
|
||||
def check_program_runs(board_id, remote_path):
|
||||
"""Check program starts without crash."""
|
||||
stdout, stderr, rc = ssh_exec(board_id, f"timeout 5 {remote_path} 2>&1 | head -5")
|
||||
return rc is not None
|
||||
|
||||
|
||||
def run_all_checks(board_id="rdk-x5", remote_path="/opt/ebd_harness/ldd3-dma-map-single-streaming"):
|
||||
"""Run all L3 behavior checks."""
|
||||
results = []
|
||||
results.append({"check": "binary_exists", "pass": check_binary_exists(board_id, remote_path)})
|
||||
results.append({"check": "program_runs", "pass": check_program_runs(board_id, remote_path)})
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
board = sys.argv[1] if len(sys.argv) > 1 else "rdk-x5"
|
||||
results = run_all_checks(board_id=board)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
"""L0 Static Analysis Checks for ldd3-dma-map-single-streaming.
|
||||
|
||||
Auto-generated by ebd_harness case_generator.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
def check_cache_flush(source_file):
|
||||
"""Check that DMA operations include cache flush/invalidate."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
has_dma = "dma" in content.lower() or "DMA" in content
|
||||
has_flush = any(x in content for x in ["__builtin___clear_cache", "cacheflush",
|
||||
"dcache_clean", "CLFLUSH", "cache_flush"])
|
||||
if has_dma and not has_flush:
|
||||
return {"check": "cache_coherence", "pass": False,
|
||||
"detail": "DMA operation without cache flush/invalidate"}
|
||||
return {"check": "cache_coherence", "pass": True}
|
||||
|
||||
def check_dma_alignment(source_file):
|
||||
"""Check that DMA buffers are properly aligned."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
has_dma = "dma" in content.lower()
|
||||
has_align = any(x in content for x in ["posix_memalign", "aligned_alloc",
|
||||
"__attribute__((aligned", "memalign"])
|
||||
if has_dma and "alloc" in content and not has_align:
|
||||
return {"check": "dma_alignment", "pass": False,
|
||||
"detail": "DMA buffer allocated without alignment"}
|
||||
return {"check": "dma_alignment", "pass": True}
|
||||
|
||||
def check_resource_cleanup(source_file):
|
||||
"""Check that all opened resources are closed."""
|
||||
with open(source_file) as f:
|
||||
content = f.read()
|
||||
opens = content.count("open(") + content.count("fopen(")
|
||||
closes = content.count("close(") + content.count("fclose(")
|
||||
if opens > closes:
|
||||
return {"check": "resource_cleanup", "pass": False,
|
||||
"detail": f"Opened {opens} resources but only closed {closes}"}
|
||||
return {"check": "resource_cleanup", "pass": True}
|
||||
|
||||
def run_all_checks(source_file):
|
||||
"""Run all L0 checks."""
|
||||
results = []
|
||||
results.append(check_cache_flush(source_file))
|
||||
results.append(check_dma_alignment(source_file))
|
||||
results.append(check_resource_cleanup(source_file))
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
source = sys.argv[1] if len(sys.argv) > 1 else "reference/main.c"
|
||||
results = run_all_checks(source)
|
||||
all_pass = True
|
||||
for r in results:
|
||||
status = "PASS" if r["pass"] else "FAIL"
|
||||
print(f" [{status}] {r['check']}")
|
||||
if not r["pass"]:
|
||||
all_pass = False
|
||||
sys.exit(0 if all_pass else 1)
|
||||
@ -0,0 +1,26 @@
|
||||
id: ldd3-dma-map-single-streaming
|
||||
capability: code-gen
|
||||
difficulty: hard
|
||||
platform: arm64-linux
|
||||
build_system: makefile
|
||||
implicit_knowledge:
|
||||
- cache_coherence
|
||||
- dma_alignment
|
||||
- dma_map_single
|
||||
- dma_unmap_pairing
|
||||
- resource_management
|
||||
paired_case: null
|
||||
embed_gap_metric: false
|
||||
eval_layers:
|
||||
l0_static: true
|
||||
l1_compile: true
|
||||
l2_simulate: false
|
||||
l3_hil: true
|
||||
l4_mutation: false
|
||||
max_iterations: 10
|
||||
max_tool_calls_per_iteration: 30
|
||||
timeout_seconds: 600
|
||||
source: ldd3
|
||||
source_url: https://lwn.net/Kernel/LDD3/
|
||||
visibility: public
|
||||
line: arm-linux
|
||||
@ -0,0 +1,27 @@
|
||||
# DMA streaming: dma_map_single/unmap 配对
|
||||
|
||||
## 目标
|
||||
|
||||
用 kmalloc 分配发送缓冲,dma_map_single 取 bus 地址供设备 DMA,dma_unmap_single 在使用完毕后解除映射。强调 dma_alignment 与 map/unmap 严格配对、cache 一致由 sync 维护。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod 后 dmesg 报告 map 的 cpu/bus 地址且 bus 按 dma_alignment 对齐;write 后 map、read 前 unmap,数据一致;rmmod 无未 unmap 的 dma 映射泄漏(需 DMA 设备,板上 not_in_v0)。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- DMA 传输前后必须执行 cache flush/invalidate 操作
|
||||
- DMA 缓冲区必须按 cache line 对齐(通常 32 或 64 字节)
|
||||
- 所有打开的文件描述符/资源必须在所有退出路径上正确关闭
|
||||
@ -0,0 +1,21 @@
|
||||
# DMA streaming: dma_map_single/unmap 配对
|
||||
|
||||
## 目标
|
||||
|
||||
用 kmalloc 分配发送缓冲,dma_map_single 取 bus 地址供设备 DMA,dma_unmap_single 在使用完毕后解除映射。强调 dma_alignment 与 map/unmap 严格配对、cache 一致由 sync 维护。
|
||||
|
||||
## 平台
|
||||
|
||||
ARM aarch64 Linux 环境(Ubuntu 22.04)
|
||||
|
||||
## 构建要求
|
||||
|
||||
使用 makefile 构建系统。
|
||||
|
||||
## 期望行为
|
||||
|
||||
insmod 后 dmesg 报告 map 的 cpu/bus 地址且 bus 按 dma_alignment 对齐;write 后 map、read 前 unmap,数据一致;rmmod 无未 unmap 的 dma 映射泄漏(需 DMA 设备,板上 not_in_v0)。
|
||||
|
||||
## 输出
|
||||
|
||||
提供完整的源代码和构建文件。
|
||||
@ -0,0 +1,75 @@
|
||||
/* ldd3-dma-map-single-streaming: streaming DMA 映射配对 */
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/dma-mapping.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
#define DMASZ 4096
|
||||
struct dctx {
|
||||
void *cpu;
|
||||
dma_addr_t bus;
|
||||
int mapped;
|
||||
size_t len;
|
||||
struct cdev cdev;
|
||||
};
|
||||
static struct dctx dc;
|
||||
static dev_t devno;
|
||||
|
||||
static ssize_t d_write(struct file *f, const char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
(void)f; (void)o;
|
||||
if (c > DMASZ) c = DMASZ;
|
||||
if (dc.mapped) dma_unmap_single(NULL, dc.bus, dc.len, DMA_TO_DEVICE);
|
||||
if (copy_from_user(dc.cpu, u, c)) return -EFAULT;
|
||||
dc.len = c;
|
||||
dc.bus = dma_map_single(NULL, dc.cpu, dc.len, DMA_TO_DEVICE);
|
||||
dc.mapped = 1;
|
||||
return c;
|
||||
}
|
||||
|
||||
static ssize_t d_read(struct file *f, char __user *u, size_t c, loff_t *o)
|
||||
{
|
||||
ssize_t r;
|
||||
(void)f; (void)o;
|
||||
if (!dc.mapped) return 0;
|
||||
dma_unmap_single(NULL, dc.bus, dc.len, DMA_FROM_DEVICE);
|
||||
dc.mapped = 0;
|
||||
c = min(c, dc.len);
|
||||
r = copy_to_user(u, dc.cpu, c) ? -EFAULT : (ssize_t)c;
|
||||
return r;
|
||||
}
|
||||
|
||||
static int d_open(struct inode *i, struct file *f) { (void)i; (void)f; return 0; }
|
||||
static const struct file_operations dfops = {
|
||||
.owner = THIS_MODULE, .open = d_open, .read = d_read, .write = d_write,
|
||||
};
|
||||
|
||||
static int __init d_init(void)
|
||||
{
|
||||
int err = alloc_chrdev_region(&devno, 0, 1, "sculldmasing");
|
||||
if (err) return err;
|
||||
dc.cpu = kmalloc(DMASZ, GFP_KERNEL | GFP_DMA);
|
||||
if (!dc.cpu) { unregister_chrdev_region(devno, 1); return -ENOMEM; }
|
||||
cdev_init(&dc.cdev, &dfops);
|
||||
dc.cdev.owner = THIS_MODULE;
|
||||
err = cdev_add(&dc.cdev, devno, 1);
|
||||
if (err) { kfree(dc.cpu); unregister_chrdev_region(devno, 1); }
|
||||
return err;
|
||||
}
|
||||
|
||||
static void __exit d_exit(void)
|
||||
{
|
||||
if (dc.mapped) dma_unmap_single(NULL, dc.bus, dc.len, DMA_BIDIRECTIONAL);
|
||||
kfree(dc.cpu);
|
||||
cdev_del(&dc.cdev);
|
||||
unregister_chrdev_region(devno, 1);
|
||||
}
|
||||
|
||||
module_init(d_init);
|
||||
module_exit(d_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("LDD3");
|
||||
MODULE_DESCRIPTION("scull dma map single streaming");
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user