Add basic pledge/unveil sandbox on OpenBSD
[tinc] / test / integration / basic.py
1 #!/usr/bin/env python3
2
3 """Check that basic functionality works (tincd can be started and stopped)."""
4
5 from testlib.test import Test
6 from testlib.proc import Tinc
7 from testlib.feature import SANDBOX_LEVEL
8 from testlib.log import log
9 from testlib.script import Script
10 from testlib import check
11
12
13 def init(ctx: Test) -> Tinc:
14     """Initialize new test nodes."""
15     node = ctx.node()
16     node.add_script(Script.TINC_UP)
17     stdin = f"""
18         init {node}
19         set Address localhost
20         set Port 0
21         set DeviceType dummy
22         set Sandbox {SANDBOX_LEVEL}
23     """
24     node.cmd(stdin=stdin)
25     return node
26
27
28 def test(ctx: Test, *flags: str) -> None:
29     """Run tests with flags."""
30     log.info("init new node")
31     node = init(ctx)
32
33     log.info('starting tincd with flags "%s"', " ".join(flags))
34     tincd = node.tincd(*flags)
35
36     log.info("waiting for tinc-up script")
37     node[Script.TINC_UP].wait()
38
39     log.info("stopping tincd")
40     node.cmd("stop")
41
42     log.info("checking tincd exit code")
43     check.equals(0, tincd.wait())
44
45
46 with Test("foreground mode") as context:
47     test(context, "-D")
48
49 with Test("background mode") as context:
50     test(context)