-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
๐งช test: Add testcase for BPiF3-Bianbu
- Loading branch information
Showing
9 changed files
with
250 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
""" | ||
Gives a configuration, | ||
runs a default procedure, | ||
generates a default log. | ||
""" | ||
|
||
from boards.bpif3 import BPiF3 | ||
from system.generic import Generic | ||
from utils.maintain_img import * | ||
from utils.utils import swap_tty | ||
|
||
from tester import * | ||
|
||
|
||
def default_proc(): | ||
""" | ||
Default procedure for testing. | ||
""" | ||
|
||
local_shell = Shell("bash") | ||
local_shell = Tee(local_shell, "run.log") | ||
local_shell.write(b"uname -a\n") | ||
local_shell.read() | ||
|
||
asciicast = Asciicast(local_shell) | ||
asciicast.begin() | ||
|
||
e = Exec(asciicast) | ||
|
||
board = BPiF3("id = 0\n", "/dev/ttyUSB0", 115200) | ||
|
||
url = "https://archive.spacemit.com/image/k1/version/bianbu/v2.0rc1/bianbu-24.04-desktop-k1-v2.0rc1-release-20240909135447.img.zip" | ||
work_dir = "/home/lw/Work/plct/boards/bpif3/bianbu" | ||
img = wget_image(url, work_dir) | ||
if img is None: | ||
print("Download failed.") | ||
return | ||
img = extract_image(img) | ||
if img is None: | ||
print("Extract failed.") | ||
return | ||
info(f"Image is ready at {img}") | ||
|
||
info("Begin flashing board...") | ||
|
||
board.flash(e, img, "/dev/mmcblk0") | ||
|
||
info("Flash board ended...") | ||
|
||
console = board.get_console() | ||
console = Tee(console, "con.log") | ||
|
||
asciicast = e.exit() | ||
local_shell = swap_tty(asciicast, console) | ||
e = Exec(asciicast) | ||
|
||
board.power_cycle() | ||
|
||
info(f"Begin system test...") | ||
|
||
system = Generic("root", "bianbu", e) | ||
|
||
system.setup() | ||
system.loggin() | ||
|
||
asciicast = e.exit() | ||
logger = PyTty("wrap=true\nsimple_recorder=true\n", asciicast) | ||
logger.begin() | ||
e = Exec(logger) | ||
system.tty = e | ||
|
||
system.get_info() | ||
|
||
logger = e.exit() | ||
info_log = logger.end() | ||
asciicast = logger.exit() | ||
res = asciicast.end() | ||
|
||
with open("res.cast", "w") as f: | ||
f.write(res) | ||
|
||
with open("info.log", "w") as f: | ||
f.write(info_log) | ||
|
||
if __name__ == "__main__": | ||
default_proc() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
Generic means this system is out of box, no need to do anything. | ||
""" | ||
|
||
from time import sleep | ||
from tester import Exec | ||
|
||
from system.system import slp | ||
|
||
class Generic: | ||
""" | ||
System class for Generic Linux | ||
""" | ||
|
||
def __init__(self, username, password, tty) -> None: | ||
self.username = username | ||
self.password = password | ||
self.tty = tty | ||
|
||
def setup(self): | ||
""" | ||
Setup the system. | ||
""" | ||
pass | ||
|
||
def loggin(self): | ||
""" | ||
Loggin to the system. | ||
""" | ||
self.tty.wait_serial("login:", 600) | ||
slp() | ||
self.tty.writeln(self.username) | ||
slp() | ||
slp(10) # Some system would gives you "ๅฏ็ " instead of "Password"... Just sleep for a while. | ||
slp() | ||
self.tty.writeln(self.password) | ||
slp() | ||
self.tty.wait_serial(self.username) | ||
slp() | ||
|
||
def get_info(self): | ||
""" | ||
Get system information. | ||
""" | ||
self.tty.script_run("uname -a") | ||
slp() | ||
self.tty.script_run("cat /etc/os-release") | ||
slp() | ||
self.tty.script_run("cat /proc/cpuinfo") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
This module contains the abstract class for all systems. | ||
""" | ||
|
||
from abc import ABC, abstractmethod | ||
from time import sleep | ||
from tester import Exec | ||
|
||
|
||
def slp(t=0.5): | ||
""" | ||
Sleep for t second. | ||
""" | ||
sleep(t) | ||
|
||
class Systems(ABC): | ||
""" | ||
Abstract class for all systems. | ||
This is mainly an interface definition, instead of a base class. | ||
""" | ||
@abstractmethod | ||
def loggin(self): | ||
""" | ||
Loggin to the board. | ||
""" | ||
|
||
@abstractmethod | ||
def setup(self, *args, **kwargs): | ||
""" | ||
some system may need initial setup. | ||
""" | ||
|
||
@abstractmethod | ||
def get_info(self): | ||
""" | ||
Get system information. | ||
""" |
Oops, something went wrong.