Skip to content

Commit

Permalink
build: Create a dejagnu bazel rule and add the fg-scan test suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaqx0r committed Feb 6, 2024
1 parent d63def6 commit 4253f75
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 0 deletions.
2 changes: 2 additions & 0 deletions input/filtergen/t/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package(default_visibility = ["//:__subpackages__"])

cc_binary(
name = "scan",
testonly = True,
Expand Down
Empty file added testsuite/BUILD
Empty file.
57 changes: 57 additions & 0 deletions testsuite/dejagnu.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Dejagnu test runner."""

def _dejagnu_test_impl(ctx):
"""Implementation of dejagnu test suite."""
executable_path = "{name}_/{name}".format(name = ctx.label.name)
executable = ctx.actions.declare_file(executable_path)

tool = ctx.label.name
srcdir = ctx.files.srcs[0].dirname

content = _runtest(tool = tool, srcdir = srcdir)
ctx.actions.write(
output = executable,
content = content,
)

# gather runfiles
runfiles = ctx.runfiles(files = ctx.files.srcs + ctx.files.data + ctx.files.tool_exec + ctx.files.deps)

return [
DefaultInfo(
runfiles = runfiles,
executable = executable,
),
]

dejagnu_test = rule(
implementation = _dejagnu_test_impl,
attrs = {
"srcs": attr.label_list(
allow_files = [".exp"],
doc = "Main test file for dejagnu runtests.",
),
"deps": attr.label_list(allow_files = True),
"data": attr.label_list(
allow_files = True,
),
"tool_exec": attr.label(),
},
test = True,
)

def _runtest(tool, srcdir):
"""Generates the runtest wrapper script."""
return DEJAGNU_TEST_RUNNER_TEMPLATE.format(tool = tool, srcdir = srcdir)

DEJAGNU_TEST_RUNNER_TEMPLATE = """
set -o errexit
cleanup () {{
mv $TEST_UNDECLARED_OUTPUTS_DIR/{tool}.xml $XML_OUTPUT_FILE
}}
trap cleanup EXIT
/bin/runtest --xml --status -all --debug -v -v --tool {tool} --srcdir {srcdir} --outdir $TEST_UNDECLARED_OUTPUTS_DIR
"""
15 changes: 15 additions & 0 deletions testsuite/fg-scan.dg/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("//testsuite:dejagnu.bzl", "dejagnu_test")

dejagnu_test(
name = "fg-scan",
srcs = glob(["**/*.exp"]),
data = glob(
[
"**/*.in",
"include*.d/**",
],
exclude_directories = 0,
) + ["include"],
tool_exec = "//input/filtergen/t:scan",
deps = ["//testsuite/lib:fg-scan-dg"],
)
4 changes: 4 additions & 0 deletions testsuite/filtergen/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
filegroup(
name = "filtergen",
srcs = glob(["*.filter"]),
)
13 changes: 13 additions & 0 deletions testsuite/lib/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package(
default_visibility = ["//:__subpackages__"],
)

filegroup(
name = "filtergen-dg",
srcs = ["filtergen-dg.exp"],
)

filegroup(
name = "fg-scan-dg",
srcs = ["fg-scan-dg.exp"],
)

0 comments on commit 4253f75

Please sign in to comment.