def test_create_named_drivers(self, tmpdir): p = tmpdir.join("config.yaml") p.write(""" targets: test1: resources: - AndroidFastboot: name: "fastboot" match: {} - RawSerialPort: name: "serial_a" port: "/dev/ttyUSB0" speed: 115200 - cls: RawSerialPort name: "serial_b" port: "/dev/ttyUSB0" speed: 115200 drivers: - FakeConsoleDriver: name: "serial_a" - FakeConsoleDriver: name: "serial_b" """) e = Environment(str(p)) t = e.get_target("test1")
def test_create_multi_drivers(self, tmpdir): p = tmpdir.join("config.yaml") p.write(""" targets: test1: resources: - RawSerialPort: name: "serial_a" port: "/dev/ttyUSB0" speed: 115200 - RawSerialPort: name: "serial_b" port: "/dev/ttyUSB0" speed: 115200 drivers: - SerialDriver: name: "serial_a" bindings: port: "serial_a" - SerialDriver: name: "serial_b" bindings: port: "serial_b" """) e = Environment(str(p)) t = e.get_target("test1") r_a = t.get_resource(RawSerialPort, name="serial_a") r_b = t.get_resource(RawSerialPort, name="serial_b") assert r_a is not r_b d_a = t.get_driver(ConsoleProtocol, name="serial_a", activate=False) d_b = t.get_driver(ConsoleProtocol, name="serial_b", activate=False) assert d_a is not d_b assert d_a.port is r_a assert d_b.port is r_b
def test_get_target(self, tmpdir): p = tmpdir.join("config.yaml") p.write(""" targets: test1: drivers: {} test2: role: foo resources: {} """) e = Environment(str(p)) assert (e.get_target("test1")) assert (e.get_target("test2"))
def test_usbserialport_warning(self, tmpdir): p = tmpdir.join("config.yaml") p.write(""" targets: test1: resources: - USBSerialPort: port: /dev/ttyS0 drivers: - SerialDriver: {} """) e = Environment(str(p)) with pytest.warns(UserWarning): t = e.get_target("test1")
def test_create_named_resources(self, tmpdir): p = tmpdir.join("config.yaml") p.write(""" targets: test1: resources: - AndroidFastboot: name: "fastboot" match: {} - RawSerialPort: port: "/dev/ttyUSB0" speed: 115200 """) e = Environment(str(p)) t = e.get_target("test1")
def test_usbserialport_no_warning(self, tmpdir): p = tmpdir.join("config.yaml") p.write(""" targets: test1: resources: - USBSerialPort: {} drivers: - SerialDriver: {} """) e = Environment(str(p)) with pytest.warns(None) as record: t = e.get_target("test1") for i in record.list: assert i.category != 'UserWarning'
def docker_env(tmp_path_factory): """Create Environment instance from the given inline YAML file.""" p = tmp_path_factory.mktemp("docker") / "config.yaml" # Note: The SSHDriver part at bottom is only used by the test that # will run if a docker daemon is present, not by # test_driver_without_daemon. p.write_text( """ targets: main: resources: - DockerDaemon: docker_daemon_url: "unix:///var/run/docker.sock" drivers: - DockerDriver: image_uri: "rastasheep/ubuntu-sshd:16.04" container_name: "ubuntu-lg-example" host_config: {"network_mode": "bridge"} network_services: [ {"port": 22, "username": "******", "password": "******"}] - DockerStrategy: {} - SSHDriver: keyfile: "" """ ) return Environment(str(p))
def test_env_imports_yaml(self, tmpdir): import sys i = tmpdir.join("myimport.py") i.write( """ class Test: pass """ ) p = tmpdir.join("config.yaml") p.write( """ targets: main: drivers: {} imports: - {} """.format("{}",str(i)) ) e = Environment(str(p)) assert (isinstance(e, Environment)) assert "myimport" in sys.modules import myimport t = myimport.Test() assert (isinstance(t, myimport.Test))
def test_instance_invalid_yaml(self, tmpdir): p = tmpdir.join("config.yaml") p.write(""" I a(m) no yaml: - keks cookie """) with pytest.raises(InvalidConfigError): e = Environment(str(p))
def test_instance(self, tmpdir): p = tmpdir.join("config.yaml") p.write(""" targets: test1: drivers: {} test2: role: foo resources: {} """) e = Environment(str(p)) assert (isinstance(e, Environment))
def qemu_env(tmpdir): p = tmpdir.join("config.yaml") p.write(""" targets: main: role: foo images: kernel: "test.zImage" dtb: test.dtb" tools: qemu: "qemu-system-arm" paths: rootfs: "test/path" """) return Environment(str(p))
def target(): return Environment( os.path.join(os.path.dirname(__file__), "config.yaml") ).get_target("lm3s6965evb-flat")
from labgrid import Environment from labgrid.protocol import ConsoleProtocol env = Environment('example-env.yaml') cp = t.get_driver(ConsoleProtocol)
def target(): return Environment(os.path.join(os.path.dirname(__file__), "config.yaml")).get_target("sim-ltp")
def test_noconfig_instance(self): with pytest.raises(NoConfigFoundError): e = Environment()
import sys from labgrid import Environment, StepReporter from labgrid.protocol import CommandProtocol from labgrid.strategy import BareboxStrategy from labgrid.strategy.bareboxstrategy import Status # enable debug logging import logging logging.basicConfig( level=logging.DEBUG, format='%(levelname)7s: %(message)s', stream=sys.stderr, ) # show labgrid steps on the console StepReporter() def run_once(target): s = target.get_driver(BareboxStrategy) s.status = Status.unknown # force a power-cycle s.transition('barebox') cmd = target.get_active_driver(CommandProtocol) cmd.run_check('test -e /dev/nand0') target.deactivate(cmd) env = Environment(sys.argv[1]) target = env.get_target('main') while True: run_once(target)
from labgrid import Environment from labgrid.driver import ShellDriver from labgrid.strategy import ShellStrategy env = Environment('milliways.yaml') t = env.get_target('main') strat = t.get_driver(ShellStrategy) # power cycle the device strat.transition("off") strat.transition("shell") # get_driver() automatically activates sh = t.get_driver(ShellDriver) # Run command in shell and print the output stdout, stderr, returncode = sh.run("cat /proc/cpuinfo") for line in stdout: print(line)