Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thir820 committed Aug 10, 2024
1 parent 6b8f9ee commit 6a52e06
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 64 deletions.
2 changes: 1 addition & 1 deletion images/user
Submodule user updated from 2167ee to 5ec0ce
38 changes: 28 additions & 10 deletions robot_tests/images.robot
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
*** Settings ***
Library lib/Fakeroot.py
Library lib/CommManager.py mode=Process
Test Timeout 45m
Test Timeout 1h

*** Test Cases ***

Expand All @@ -22,7 +22,7 @@ Build Image amd64/qemu/jammy/elbe

Build Image amd64/qemu/jammy/kernel_src
[Tags] amd64 qemu elbe jammy
[Timeout] 90m
[Timeout] 2h
Test Systemd Image amd64/qemu/jammy/kernel_src

Build Image amd64/qemu/jammy/kiwi
Expand Down Expand Up @@ -89,28 +89,44 @@ Build Image arm64/nxp/rdb2/systemd

Build Image arm64/nxp/rdb2/kernel_src
[Tags] arm64 rdb2 hardware elbe ebcl
[Timeout] 2h
Test Hardware Image arm64/nxp/rdb2/kernel_src



*** Keywords ***
Run Make
[Arguments] ${path} ${target} ${max_time}=
[Timeout] ${max_time}
${result}= Execute source /build/venv/bin/activate; cd ${path}; make ${target}
RETURN ${result}

Build Image
[Arguments] ${path} ${image}=image.raw
[Arguments] ${path} ${image}=image.raw ${max_time}=1h
[Timeout] ${max_time}
${full_path}= Evaluate '/workspace/images/' + $path
${results_folder}= Evaluate $full_path + '/build'
# TODO: enable clean to build everything from scratch
# Run bash -c "source /build/venv/bin/activate; cd ${full_path}; make clean"
Run bash -c "source /build/venv/bin/activate; cd ${full_path}; make image"
${result}= Run file ${results_folder}/image.raw
${file_info}= Evaluate $result[0]
Run Make ${full_path} clean 2m
Run Make ${full_path} image ${max_time}
Sleep 10s # Give some processing time to other processes.
Wait For Line Containing Image was written to
${file_info}= Execute cd ${results_folder}; file ${image}
Should Not Contain ${file_info} No such file
Clear Lines # Clear the output queue
Sleep 1s

Test That Make Does Not Rebuild
[Arguments] ${path}
[Timeout] 1m
${full_path}= Evaluate '/workspace/images/' + $path
${output}= Run Make ${full_path} image
Should Contain ${output} Nothing to be done for 'image'

Run Image
[Arguments] ${path} ${image}=image.raw
[Timeout] 2m
${full_path}= Evaluate '/workspace/images/' + $path
Send Message cd ${full_path}
Send Message make qemu
Send Message source /build/venv/bin/activate; cd ${full_path}; make qemu
${success}= Login To Vm
Should Be True ${success}

Expand All @@ -124,6 +140,7 @@ Test Systemd Image
[Arguments] ${path} ${image}=image.raw
Connect
Build Image ${path} ${image}
Test That Make Does Not Rebuild ${path}
Run Image ${path} ${image}
Shutdown Systemd Image
Disconnect
Expand All @@ -132,3 +149,4 @@ Test Hardware Image
[Arguments] ${path} ${image}=image.raw
Connect
Build Image ${path} ${image}
Test That Make Does Not Rebuild ${path}
20 changes: 19 additions & 1 deletion robot_tests/lib/CommManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ def execute(self, message, timeout: int = -1) -> Optional[str]:

logging.info('Executing %s (ter: %s)...', message, ter)

logging.info('Clearing old output...')

self.clear_lines()
time.sleep(0.2)

logging.info('Running command %s...', message)

self.send_message(message + "; echo " + ter)

buf = ""
Expand All @@ -192,7 +199,7 @@ def execute(self, message, timeout: int = -1) -> Optional[str]:
if not line:
continue

if line == ter:
if ter in line:
logging.info('Line %s matches terminator...', line)
return buf

Expand All @@ -203,6 +210,11 @@ def login_to_vm(self, user: str = 'root', password: str = 'linux',
""" Login to VM. """
logging.info("Waiting for login prompt...")

time.sleep(1) # Give other processes and thread some time do work
self.clear_lines() # Delete all the output bevor trying to login

self.send_keys('\n') # Press return to show the login prompt

m = self.wait_for_regex(".*login:.*", timeout=30)
if not m:
logging.info("Trying to get login prompt by pressing enter...")
Expand Down Expand Up @@ -232,3 +244,9 @@ def login_to_vm(self, user: str = 'root', password: str = 'linux',
return True

return False

def clear_lines(self):
"""
Clear all the output lines.
"""
self.interface.clear_lines()
6 changes: 6 additions & 0 deletions robot_tests/lib/interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,9 @@ def next_line(self, timeout: int = 1) -> Optional[str]:
if line:
self.lines += line
return line

@abstractmethod
def clear_lines(self):
"""
Clear all the output lines.
"""
18 changes: 12 additions & 6 deletions robot_tests/lib/interfaces/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from queue import Queue, Empty
from subprocess import PIPE, Popen
from threading import Thread
from time import sleep
from typing import Optional

from . import CommunicationInterface
Expand Down Expand Up @@ -63,12 +64,9 @@ def _process_command(self) -> list[str]:
def connect(self):
""" Open shell process. """
if self.process:
rc = self.process.poll()
if not rc:
logging.info('Using existing shell session.')
return
else:
logging.info('Old shell session ended with returncode %d.', rc)
logging.info(
'Old shell session found. Closing old shell session...')
self.disconnect()

logging.info('Running shell %s...', self.shell)

Expand Down Expand Up @@ -160,3 +158,11 @@ def read_line(self, timeout: int = 1) -> Optional[str]:

def create_session(self):
""" Nothing to do. """

def clear_lines(self):
""" Clear the output queue. """
# Give the threads some time to read all the output,
sleep(0.5)
# then clear the output queue.
with self.queue.mutex:
self.queue.queue.clear()
Loading

0 comments on commit 6a52e06

Please sign in to comment.