basic.py 1.1 KB

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