Skip to content

Commit

Permalink
Merge pull request autotest#5016 from nanli1/fix_chardev_get_messsge_…
Browse files Browse the repository at this point in the history
…failed

fix chardev get message failed
  • Loading branch information
Yingshun authored Jul 17, 2023
2 parents 4429b6c + aa73a27 commit 19469e7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,27 @@
device = "hvc0"
target_path = "/dev/hvc"
device_dict = "{'type_name':'${chardev_type}','sources': [{'attrs': {'path': '%s'}}],'target_type':'%s', 'alias': {'name': '%s'},'target_port':'${port}'}"
- serial_target:
target_type = "serial"
target_path = "/dev/ttyS"
device_dict = "{'type_name':'${chardev_type}','sources': [{'attrs': {'path': '%s'}}],'target_type':'%s', 'alias': {'name': '%s'},'target_port':'${port}'}"
- serial:
chardev = "serial"
target_path = "/dev/ttyS"
variants:
- pci_target:
target_type = "pci-serial"
target_model = "pci-serial"
no s390-virtio
target_type = pci-serial
target_model = pci-serial
aarch64:
target_type = system-serial
target_model = pl011
device_dict = "{'type_name':'${chardev_type}','sources': [{'attrs': {'path': '%s'}}],'target_type':'%s', 'target_model':'${target_model}','target_port':'${port}','alias': {'name': '%s'}}"
- isa_target:
target_type = "isa-serial"
target_model = "isa-serial"
target_type = isa-serial
target_model = isa-serial
aarch64:
target_type = system-serial
target_model = pl011
s390x:
target_type = sclp-serial
target_model = sclpconsole
device_dict = "{'type_name':'${chardev_type}','sources': [{'attrs': {'path': '%s'}}],'target_type':'%s', 'target_model':'${target_model}','target_port':'${port}','alias': {'name': '%s'}}"
- channel:
chardev = "channel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# Author: Nan Li <[email protected]>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import time

import aexpect
import os
import platform
Expand Down Expand Up @@ -163,7 +165,7 @@ def add_chardev(source_path):
vmxml.remove_all_device_by_type("channel")
dest_dict = eval(
device_dict % (source_path, target_type, device_alias))
test.log.debug("Add chadev dict is: %s", dest_dict)
test.log.debug("Add chardev dict is: %s", dest_dict)
libvirt_vmxml.modify_vm_device(
vmxml=vmxml, dev_type=chardev, dev_dict=dest_dict)

Expand Down Expand Up @@ -216,23 +218,21 @@ def check_message_from_host():
chardev_port = get_chardev_port(chardev)

vm_session = vm.wait_for_login(timeout=240)
cmd = "cat < %s > %s" % (target_path + chardev_port, guest_out)
cmd = "cat %s > %s &" % (target_path + chardev_port, guest_out)
test.log.debug("Execute cmd:'%s' on guest ", cmd)
vm_session.sendline(cmd)

time.sleep(5)
chardev_base.send_message(vm, "host", send_msg=host_msg,
send_path=pipe_in)
vm_session.close()

vm_session_new = vm.wait_for_login(timeout=240)
status, output = vm_session_new.cmd_status_output(
"grep -E '%s' %s" % (host_msg, guest_out))
"cat %s | grep '%s' " % (guest_out, host_msg))
vm_session_new.close()
vm_session.close()

if status != 0:
test.fail("Check host msg failed.")
if not re.search(host_msg, output):
test.fail("Not get %s in %s" % (host_msg, output))
test.fail("Not get %s in '%s' " % (host_msg, output))
else:
test.log.debug("Check '%s' exist in :%s" % (host_msg, output))

Expand Down
8 changes: 7 additions & 1 deletion provider/chardev/chardev_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import re

from avocado.core import exceptions
from avocado.utils import process


Expand All @@ -28,7 +29,12 @@ def send_message(vm, send_on="host", send_msg="Test message", send_path=""):
if not vm.is_alive():
vm.start()
session = vm.wait_for_login()
session.cmd_status_output("echo %s > %s " % (send_msg, send_path))
cmd = "echo %s > %s " % (send_msg, send_path)
status, stdout = session.cmd_status_output(cmd)
if status != 0:
raise exceptions.TestError("Error happened when executing "
"command:\n'%s', due to:\n'%s'"
% (cmd, stdout))
session.close()


Expand Down

0 comments on commit 19469e7

Please sign in to comment.