Skip to content

Commit

Permalink
๐Ÿงช test: Add testcase for BPiF3-Bianbu
Browse files Browse the repository at this point in the history
  • Loading branch information
wychlw committed Sep 19, 2024
1 parent bac6612 commit bb0d4cf
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 66 deletions.
4 changes: 2 additions & 2 deletions apps/boards/boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from abc import ABC, abstractmethod
from tester import Tty
from tester import PyTty


class Boards(ABC):
Expand All @@ -25,7 +25,7 @@ def power_cycle(self, *args, **kwargs):
"""

@abstractmethod
def get_console(self, *args, **kwargs) -> Tty:
def get_console(self, *args, **kwargs) -> PyTty:
"""
Get the console of the board.
"""
10 changes: 5 additions & 5 deletions apps/boards/bpif3.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def flash(self, shell: Exec, img: str, dsk="/dev/sda"):
"""
Flash the board with given image.
"""
self.sdwirec.to_ts()
# self.sdwirec.to_ts()
sleep(0.5)
shell.assert_script_sudo(
f"dd if={img} of={dsk} status=progress", 600)
shell.assert_script_sudo("sync")
shell.script_sudo(
f"dd if={img} of={dsk} status=progress bs=4M ", 600)
shell.script_sudo("sync")
sleep(0.5)
self.sdwirec.to_dut()
# self.sdwirec.to_dut()
sleep(0.5)

def power_cycle(self):
Expand Down
13 changes: 9 additions & 4 deletions apps/bpif3_armbian.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ def default_proc():

local_shell = Shell("/bin/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)
e.script_run("uname -a")

e.script_run("uname -a")


e.script_run("uname -a")


board = BPiF3("id = 0\n", "/dev/ttyUSB0", 115200)

# url = "/Armbian-bpi-SpacemiT_24.5.0-trunk_Bananapif3_mantic_legacy_6.1.15_xfce_desktop.img.xz" # ๅบฆ็›˜๏ผŒdummy
url = "https://mirrors.tuna.tsinghua.edu.cn/armbian-releases/bananapif3/archive/Armbian_24.8.1_Bananapif3_noble_legacy_6.1.15_minimal.img.xz"
work_dir = "/home/lw/Work/plct/boards/bpif3/armbian"
img = wget_image(url, work_dir)
Expand All @@ -44,7 +48,7 @@ def default_proc():

info("Begin flashing board...")

board.flash(e, img, "/dev/mmcblk0")
board.flash(e, img, "/dev/sda")

info("Flash board ended...")

Expand All @@ -61,6 +65,7 @@ def default_proc():

system = Armbian(e)

system.setup()
system.loggin()

asciicast = e.exit()
Expand Down
86 changes: 86 additions & 0 deletions apps/bpif3_bianbu.py
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()
23 changes: 10 additions & 13 deletions apps/system/armbian.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
from time import sleep
from tester import Exec


def slp(t=0.5):
"""
Sleep for t second.
"""
sleep(t)

from system.system import slp

class Armbian:
"""
Expand All @@ -35,9 +29,9 @@ def wit(self, wait: str, timeout: int = 600):
self.tty.wait_serial(wait, timeout)
slp()

def loggin(self):
def setup(self):
"""
Loggin to the board.
Setup the armbian.
"""

# init settings
Expand Down Expand Up @@ -82,13 +76,16 @@ def loggin(self):
self.wit("#?")
self.wln("1")

# Loggin
def loggin(self):
"""
Login to the board.
"""
self.wit("root@")

def get_info(self):
"""
Get system information.
"""
self.tty.assert_script_run("uname -a")
self.tty.assert_script_run("cat /etc/os-release")
self.tty.assert_script_run("cat /proc/cpuinfo")
self.tty.script_run("uname -a")
self.tty.script_run("cat /etc/os-release")
self.tty.script_run("cat /proc/cpuinfo")
49 changes: 49 additions & 0 deletions apps/system/generic.py
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")
37 changes: 37 additions & 0 deletions apps/system/system.py
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.
"""
Loading

0 comments on commit bb0d4cf

Please sign in to comment.