summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/build_defs.bzl
blob: 1df761dd060743a6f19ebdc86d56593d710bbe8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"""Defines a rule for syscall test targets."""

load("//tools:defs.bzl", "loopback")

# syscall_test is a macro that will create targets to run the given test target
# on the host (native) and runsc.
def syscall_test(
        test,
        shard_count = 5,
        size = "small",
        use_tmpfs = False,
        add_overlay = False,
        add_uds_tree = False,
        add_hostinet = False,
        tags = None):
    _syscall_test(
        test = test,
        shard_count = shard_count,
        size = size,
        platform = "native",
        use_tmpfs = False,
        add_uds_tree = add_uds_tree,
        tags = tags,
    )

    _syscall_test(
        test = test,
        shard_count = shard_count,
        size = size,
        platform = "kvm",
        use_tmpfs = use_tmpfs,
        add_uds_tree = add_uds_tree,
        tags = tags,
    )

    _syscall_test(
        test = test,
        shard_count = shard_count,
        size = size,
        platform = "ptrace",
        use_tmpfs = use_tmpfs,
        add_uds_tree = add_uds_tree,
        tags = tags,
    )

    if add_overlay:
        _syscall_test(
            test = test,
            shard_count = shard_count,
            size = size,
            platform = "ptrace",
            use_tmpfs = False,  # overlay is adding a writable tmpfs on top of root.
            add_uds_tree = add_uds_tree,
            tags = tags,
            overlay = True,
        )

    if not use_tmpfs:
        # Also test shared gofer access.
        _syscall_test(
            test = test,
            shard_count = shard_count,
            size = size,
            platform = "ptrace",
            use_tmpfs = use_tmpfs,
            add_uds_tree = add_uds_tree,
            tags = tags,
            file_access = "shared",
        )

    if add_hostinet:
        _syscall_test(
            test = test,
            shard_count = shard_count,
            size = size,
            platform = "ptrace",
            use_tmpfs = use_tmpfs,
            network = "host",
            add_uds_tree = add_uds_tree,
            tags = tags,
        )

def _syscall_test(
        test,
        shard_count,
        size,
        platform,
        use_tmpfs,
        tags,
        network = "none",
        file_access = "exclusive",
        overlay = False,
        add_uds_tree = False):
    test_name = test.split(":")[1]

    # Prepend "runsc" to non-native platform names.
    full_platform = platform if platform == "native" else "runsc_" + platform

    name = test_name + "_" + full_platform
    if file_access == "shared":
        name += "_shared"
    if overlay:
        name += "_overlay"
    if network != "none":
        name += "_" + network + "net"

    if tags == None:
        tags = []

    # Add the full_platform and file access in a tag to make it easier to run
    # all the tests on a specific flavor. Use --test_tag_filters=ptrace,file_shared.
    tags += [full_platform, "file_" + file_access]

    # Add tag to prevent the tests from running in a Bazel sandbox.
    # TODO(b/120560048): Make the tests run without this tag.
    tags.append("no-sandbox")

    # TODO(b/112165693): KVM tests are tagged "manual" to until the platform is
    # more stable.
    if platform == "kvm":
        tags += ["manual"]
        tags += ["requires-kvm"]

    args = [
        # Arguments are passed directly to syscall_test_runner binary.
        "--test-name=" + test_name,
        "--platform=" + platform,
        "--network=" + network,
        "--use-tmpfs=" + str(use_tmpfs),
        "--file-access=" + file_access,
        "--overlay=" + str(overlay),
        "--add-uds-tree=" + str(add_uds_tree),
    ]

    sh_test(
        srcs = ["syscall_test_runner.sh"],
        name = name,
        data = [
            ":syscall_test_runner",
            loopback,
            test,
        ],
        args = args,
        size = size,
        tags = tags,
        shard_count = shard_count,
    )

def sh_test(**kwargs):
    """Wraps the standard sh_test."""
    native.sh_test(
        **kwargs
    )