我想在qemu上运行单元测试.我创建了一个自定义规则,它使用规则中指定的参数调用qemu.其中一个参数是elf文件(规则属性"target"),qemu将其用作内核.
当我使用以下命令调用我的自定义规则时,elf文件("kernel.elf")不会被编译:
bazel build //test:custom_rule
Run Code Online (Sandbox Code Playgroud)
即使bazel query 'deps(//test:custom_rule)'将目标":kernel.elf"列为依赖项,也会发生这种情况.
此外,我有自定义规则的另一个问题.当我手动构建":kernel.elf"并调用自定义规则后,qemu告诉我,它无法加载内核文件.在shell中手动调用qemu命令确实有效,所以我猜问题不在于"kernel.elf"文件中.
有人对我的问题有答案吗?
提前致谢!
def _impl(ctx):
qemu = ctx.attr.qemu
machine = ctx.attr.machine
cpu = ctx.attr.cpu
target = ctx.file.target.path
output = ctx.outputs.out
# The command may only access files declared in inputs.
ctx.actions.run_shell(
arguments = [qemu, machine, cpu, target],
outputs=[output],
command="$1 -M $2 -cpu $3 -nographic -monitor null
-serial null -semihosting -kernel $4 > %s" % (output.path))
run_tests = rule(
implementation=_impl,
attrs = {"qemu" : attr.string(),
"machine" : attr.string(),
"cpu" : attr.string(),
"target" : attr.label(allow_files=True, single_file=True,
mandatory=True)},
outputs={"out": "run_tests.log"}
)
Run Code Online (Sandbox Code Playgroud)
load("//make:run_tests.bzl", "run_tests")
run_tests(
name = "custom_rule",
qemu = "qemu-system-arm",
machine = "xilinx-zynq-a9",
cpu = "cortex-a9",
target = ":kernel.elf"
)
cc_binary(
name = "kernel.elf",
srcs = glob(["*.cc"]),
deps = ["//src:portos",
"@unity//:unity"],
copts = ["-Isrc",
"-Iexternal/unity/src",
"-Iexternal/unity/extras/fixture/src"]
)
Run Code Online (Sandbox Code Playgroud)
问题可能是需要为操作指定输入,请参阅 https://docs.bazel.build/versions/master/skylark/lib/actions.html#run_shell.inputs
你也可能需要让qemu成为一个标签,并将其作为动作的输入(如果这是qemu需要的文件,那么也是机器)
例如:
def _impl(ctx):
qemu = ctx.attr.qemu
machine = ctx.attr.machine
cpu = ctx.attr.cpu
target = ctx.file.target.path
output = ctx.outputs.out
# The command may only access files declared in inputs.
ctx.actions.run_shell(
inputs = [qemu, target],
outputs=[output],
arguments = [qemu, machine, cpu, target],
command="$1 -M $2 -cpu $3 -nographic -monitor null
-serial null -semihosting -kernel $4 > %s" % (output.path))
run_tests = rule(
implementation=_impl,
attrs = {
"qemu" : attr.label(allow_files=True, single_file=True,
mandatory=True),
"machine" : attr.string(),
"cpu" : attr.string(),
"target" : attr.label(allow_files=True, single_file=True,
mandatory=True)
},
outputs={"out": "run_tests.log"}
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
510 次 |
| 最近记录: |