diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2021-06-04 10:47:01 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-06-09 12:20:05 +0200 |
commit | 6eb6998a2ba3eb314916df80bf42590e63bbfd3d (patch) | |
tree | 47084b1ae534ec642842ab030f95aca0913d7d37 /test/strategy.py | |
parent | 848c4c61c5b469910df2471c659b005f9f4538b9 (diff) | |
download | barebox-6eb6998a2ba3eb314916df80bf42590e63bbfd3d.tar.gz |
test: add first sample tests
The test can be run manually with e.g.
labgrid-pytest --lg-env test/arm/qemu_virt64_defconfig.yaml test/py
Acked-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20210604084704.17410-11-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'test/strategy.py')
-rw-r--r-- | test/strategy.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/strategy.py b/test/strategy.py new file mode 100644 index 0000000000..1fe1b7d818 --- /dev/null +++ b/test/strategy.py @@ -0,0 +1,53 @@ +import enum + +import attr + +from labgrid import target_factory, step +from labgrid.strategy import Strategy, StrategyError + +class Status(enum.Enum): + unknown = 0 + off = 1 + barebox = 2 + +@target_factory.reg_driver +@attr.s(eq=False) +class BareboxTestStrategy(Strategy): + """BareboxTestStrategy - Strategy to switch to barebox""" + bindings = { + "power": "PowerProtocol", + "console": "ConsoleProtocol", + "barebox": "BareboxDriver", + } + + status = attr.ib(default=Status.unknown) + + def __attrs_post_init__(self): + super().__attrs_post_init__() + + @step(args=['status']) + def transition(self, status, *, step): + if not isinstance(status, Status): + status = Status[status] + if status == Status.unknown: + raise StrategyError("can not transition to {}".format(status)) + elif status == self.status: + step.skip("nothing to do") + return # nothing to do + elif status == Status.off: + self.target.deactivate(self.console) + self.target.activate(self.power) + self.power.off() + elif status == Status.barebox: + self.transition(Status.off) # pylint: disable=missing-kwoa + self.target.activate(self.console) + # cycle power + self.power.cycle() + # interrupt barebox + self.target.activate(self.barebox) + else: + raise StrategyError( + "no transition found from {} to {}". + format(self.status, status) + ) + self.status = status |