Skip to content

Commit c3b065c

Browse files
committed
Script: Add serial log to file support
Signed-off-by: Wei Liu <[email protected]>
1 parent 033707c commit c3b065c

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

sh_script/test/conftest.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def __init__(self):
6666
self._threads: Dict[str, threading.Thread] = {}
6767
self._host_procs: Dict[str, subprocess.Popen] = {}
6868
self.ssh = None
69+
self.serial_log_type = "stdio"
6970
# clear dmesg
7071
self.clear_dmesg()
7172
# terminate all tds & socat before test execution
@@ -117,7 +118,7 @@ def start_test_payload(self, bios_img=None, type=None, device=None):
117118
Start migration td
118119
"""
119120
LOG.debug(f"Starting launch test td payload")
120-
arg=f"sudo bash {self.mig_td_script} -q {self.qemu} -m {bios_img} -t {type}"
121+
arg=f"sudo bash {self.mig_td_script} -q {self.qemu} -m {bios_img} -t {type} -l {self.serial_log_type}"
121122

122123
if device == "serial":
123124
arg=arg + " -s"
@@ -138,7 +139,7 @@ def start_mig_td(self, bios_img=None, type=None, no_device=False, device=None):
138139
"""
139140
Start migration td
140141
"""
141-
arg=f"sudo bash {self.mig_td_script} -q {self.qemu} -m {bios_img} -t {type}"
142+
arg=f"sudo bash {self.mig_td_script} -q {self.qemu} -m {bios_img} -t {type} -l {self.serial_log_type}"
142143
if no_device:
143144
arg=arg + " -n"
144145
if device == "serial":
@@ -157,7 +158,7 @@ def start_mig_td(self, bios_img=None, type=None, no_device=False, device=None):
157158

158159
# type has src dst
159160
def start_user_td(self, is_pre_binding=False, type=None, hash=None):
160-
command = f"sudo bash {self.user_td_script} -q {self.qemu} -i {self.guest_img} -k {self.kernel_img} -o {self.user_td_bios_img} -t {type}"
161+
command = f"sudo bash {self.user_td_script} -q {self.qemu} -i {self.guest_img} -k {self.kernel_img} -o {self.user_td_bios_img} -t {type} -l {self.serial_log_type}"
161162
if is_pre_binding:
162163
command += f" -g true -m {hash}"
163164
"""

sh_script/test/mig-td.sh

+25-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ GUEST_CID=18
1111
MIGTD=""
1212
VIRTIO_SERIAL=false
1313
MIGTD_TYPE=""
14+
LOG_TYPE="file"
1415
DEST_IP="127.0.0.1"
1516

1617
usage() {
@@ -21,19 +22,21 @@ Usage: $(basename "$0") [OPTION]...
2122
-t <src|dst> Must set migtd type, src or dst
2223
-s Use virtio serial, default is vsock
2324
-i <dest_ip> IP of destination
25+
-l <stdio|file> Serial log type
2426
-h Show this help
2527
EOM
2628
}
2729

2830
process_args() {
29-
while getopts "i:m:t:q:hsn" option; do
31+
while getopts "i:m:t:q:l:hsn" option; do
3032
case "${option}" in
3133
i) DEST_IP=$OPTARG;;
3234
m) MIGTD=$OPTARG;;
3335
t) MIGTD_TYPE=$OPTARG;;
3436
s) VIRTIO_SERIAL=true;;
3537
n) NO_DEVICE=true;;
3638
q) QEMU_EXEC=$OPTARG;;
39+
l) LOG_TYPE=$OPTARG;;
3740
h) usage
3841
exit 0
3942
;;
@@ -62,6 +65,19 @@ process_args() {
6265
error "Invalid ${MIGTD_TYPE}, must be [src|dst]"
6366
;;
6467
esac
68+
69+
70+
case ${LOG_TYPE} in
71+
"stdio")
72+
echo "LOG_TYPE is set to stdio. Proceeding with standard I/O logging."
73+
;;
74+
"file")
75+
echo "LOG_TYPE is set to file. Proceeding with file logging."
76+
;;
77+
*)
78+
error "Invalid LOG_TYPE '${LOG_TYPE}', must be [stdio|file]"
79+
;;
80+
esac
6581
}
6682

6783
error() {
@@ -82,9 +98,14 @@ QEMU_CMD="${QEMU_EXEC} \
8298
-name migtd-${MIGTD_TYPE},process=migtd-${MIGTD_TYPE},debug-threads=on \
8399
-no-hpet \
84100
-nographic -vga none -nic none \
85-
-serial mon:stdio \
86101
-pidfile /var/run/migtd-${MIGTD_TYPE}.pid"
87102

103+
if [[ ${LOG_TYPE} == stdio ]]; then
104+
QEMU_CMD+=" -serial mon:stdio "
105+
else
106+
QEMU_CMD+=" -serial migtd${MIGTD_TYPE}.log "
107+
fi
108+
88109
QEMU_VERSION=`${QEMU_EXEC} --version | grep -oP 'version \K[^\s]+'`
89110
if [ "$(printf '%s\n' "8.0.0" "${QEMU_VERSION}" | sort -V | head -n1)" == "8.0.0" ]; then
90111
QEMU_CMD+=" -object memory-backend-ram,id=ram1,size=32M,private=on "
@@ -106,6 +127,8 @@ QEMU_CMD="${QEMU_EXEC} \
106127
fi
107128
fi
108129

130+
131+
109132
eval "${QEMU_CMD}"
110133
}
111134

sh_script/test/user-td.sh

+24-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ TELNET_PORT=9088
2020
INCOMING_PORT=6666
2121
PRE_BINDING="false"
2222
SERVTD_HASH=""
23+
LOG_TYPE="file"
2324

2425

2526
usage() {
@@ -36,12 +37,13 @@ Usage: $(basename "$0") [OPTION]...
3637
-t <src|dst> Must set userTD type, src or dst
3738
-g [true|false] Use pre-binding or not, default is "false"
3839
-m [MigTD hash] Hash of MigTD SERVTD_INFO_HASH, shall be provided if "-g" is true
40+
-l [stdio|file] Serial log type
3941
-h Show this help
4042
EOM
4143
}
4244

4345
process_args() {
44-
while getopts "i:k:b:o:p:q:a:r:t:g:m:h" option; do
46+
while getopts "i:k:b:o:p:q:a:r:t:g:m:l:h" option; do
4547
case "${option}" in
4648
i) GUEST_IMG=$OPTARG;;
4749
k) KERNEL=$OPTARG;;
@@ -54,6 +56,7 @@ process_args() {
5456
t) TD_TYPE=$OPTARG;;
5557
g) PRE_BINDING=$OPTARG;;
5658
m) SERVTD_HASH=$OPTARG;;
59+
l) LOG_TYPE=$OPTARG;;
5760
h) usage
5861
exit 0
5962
;;
@@ -127,6 +130,18 @@ process_args() {
127130
;;
128131
esac
129132
fi
133+
134+
case ${LOG_TYPE} in
135+
"stdio")
136+
echo "LOG_TYPE is set to stdio. Proceeding with standard I/O logging."
137+
;;
138+
"file")
139+
echo "LOG_TYPE is set to file. Proceeding with file logging."
140+
;;
141+
*)
142+
error "Invalid LOG_TYPE '${LOG_TYPE}', must be [stdio|file]"
143+
;;
144+
esac
130145
}
131146

132147
error() {
@@ -150,7 +165,14 @@ QEMU_CMD="${QEMU_EXEC} \
150165
-monitor unix:/tmp/qmp-sock-${TD_TYPE},server,nowait \
151166
-monitor telnet:127.0.0.1:${TELNET_PORT},server,nowait \
152167
-device virtio-serial,romfile= \
153-
-device virtconsole,chardev=mux -serial chardev:mux -monitor chardev:mux"
168+
-device virtconsole,chardev=mux -monitor chardev:mux"
169+
170+
if [[ ${LOG_TYPE} == stdio ]]; then
171+
QEMU_CMD+=" -serial chardev:mux "
172+
else
173+
QEMU_CMD+=" -serial usertd${MIGTD_TYPE}.log "
174+
fi
175+
154176
OBJ_SUBCOMMAND=" -object tdx-guest,id=tdx0,sept-ve-disable=on,debug=off"
155177

156178
QEMU_VERSION=`${QEMU_EXEC} --version | grep -oP 'version \K[^\s]+'`

0 commit comments

Comments
 (0)