aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2021-03-24 14:33:33 +0000
committerPeter Maydell <peter.maydell@linaro.org>2021-03-24 14:33:33 +0000
commitf0b6a6a1a94cfbba87db98dd2edbc29b30e54f76 (patch)
tree5631bf62f53662da23378aaf78514795d2f1b966 /tests
parent01874b15d36e3f9a3506c47941a92ccf8d8bed98 (diff)
parenta9eb2df27f117bbac9f370bf8cb79532005f19c2 (diff)
Merge remote-tracking branch 'remotes/stsquad/tags/pull-6.0-rc0-fixed-240321-1' into staging
Various fixes for 6.0: - include kernel-doc API reference for plugins - fix semihosting SYS_HEAPINFO - various tweaks to improve CI runtime - more stroz fixes - fix iotest CI regressions # gpg: Signature made Wed 24 Mar 2021 14:28:24 GMT # gpg: using RSA key 6685AE99E75167BCAFC8DF35FBD0DB095A9E2A44 # gpg: Good signature from "Alex Bennée (Master Work Key) <alex.bennee@linaro.org>" [full] # Primary key fingerprint: 6685 AE99 E751 67BC AFC8 DF35 FBD0 DB09 5A9E 2A44 * remotes/stsquad/tags/pull-6.0-rc0-fixed-240321-1: (22 commits) gitlab: default to not building the documentation iotests: iothreads need ioeventfd iotests: test m68k with the virt machine iotests: Revert "iotests: use -ccw on s390x for 040, 139, and 182" blockdev: with -drive if=virtio, use generic virtio-blk m68k: add the virtio devices aliases qdev: define list of archs with virtio-pci or virtio-ccw gitlab: extend timeouts for CFI builds utils: Work around mingw strto*l bug with 0x utils: Tighter tests for qemu_strtosz cirrus.yml: Update the FreeBSD task to version 12.2 configure: Don't use the __atomic_*_16 functions for testing 128-bit support gitlab-ci.yml: Merge the trace-backend testing into other jobs tests/tcg: add HeapInfo checking to semihosting test linux-user/riscv: initialise the TaskState heap/stack info semihosting/arm-compat-semi: don't use SET_ARG to report SYS_HEAPINFO semihosting/arm-compat-semi: unify GET/SET_ARG helpers semihosting: move semihosting tests to multiarch tools/virtiofsd: include --socket-group in help docs/devel: expand style section of memory management ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests')
-rwxr-xr-xtests/qemu-iotests/0402
-rwxr-xr-xtests/qemu-iotests/05112
-rw-r--r--tests/qemu-iotests/051.out2
-rw-r--r--tests/qemu-iotests/051.pc.out2
-rwxr-xr-xtests/qemu-iotests/0684
-rwxr-xr-xtests/qemu-iotests/0933
-rwxr-xr-xtests/qemu-iotests/1273
-rwxr-xr-xtests/qemu-iotests/1399
-rwxr-xr-xtests/qemu-iotests/18213
-rwxr-xr-xtests/qemu-iotests/2384
-rwxr-xr-xtests/qemu-iotests/24010
-rwxr-xr-xtests/qemu-iotests/2566
-rwxr-xr-xtests/qemu-iotests/2574
-rwxr-xr-xtests/qemu-iotests/3074
-rw-r--r--tests/qemu-iotests/common.rc13
-rw-r--r--tests/qemu-iotests/iotests.py10
-rw-r--r--tests/qemu-iotests/testenv.py1
-rw-r--r--tests/tcg/Makefile.target3
-rw-r--r--tests/tcg/aarch64/Makefile.target18
-rw-r--r--tests/tcg/aarch64/semicall.h18
-rw-r--r--tests/tcg/arm/Makefile.target22
-rw-r--r--tests/tcg/arm/semicall.h15
-rw-r--r--tests/tcg/arm/semihosting.c26
-rw-r--r--tests/tcg/multiarch/Makefile.target31
-rw-r--r--tests/tcg/multiarch/arm-compat-semi/semiconsole.c (renamed from tests/tcg/arm/semiconsole.c)2
-rw-r--r--tests/tcg/multiarch/arm-compat-semi/semihosting.c82
-rw-r--r--tests/tcg/riscv64/semicall.h22
-rw-r--r--tests/unit/test-cutils.c171
28 files changed, 377 insertions, 135 deletions
diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040
index 336ff7c4f2..ba7cb34ce8 100755
--- a/tests/qemu-iotests/040
+++ b/tests/qemu-iotests/040
@@ -89,7 +89,7 @@ class TestSingleDrive(ImageCommitTestCase):
qemu_io('-f', 'raw', '-c', 'write -P 0xab 0 524288', backing_img)
qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xef 524288 524288', mid_img)
self.vm = iotests.VM().add_drive(test_img, "node-name=top,backing.node-name=mid,backing.backing.node-name=base", interface="none")
- self.vm.add_device(iotests.get_virtio_scsi_device())
+ self.vm.add_device('virtio-scsi')
self.vm.add_device("scsi-hd,id=scsi0,drive=drive0")
self.vm.launch()
self.has_quit = False
diff --git a/tests/qemu-iotests/051 b/tests/qemu-iotests/051
index f92161d8ef..333cc81818 100755
--- a/tests/qemu-iotests/051
+++ b/tests/qemu-iotests/051
@@ -119,17 +119,7 @@ echo
echo === Device without drive ===
echo
-case "$QEMU_DEFAULT_MACHINE" in
- s390-ccw-virtio)
- virtio_scsi=virtio-scsi-ccw
- ;;
- *)
- virtio_scsi=virtio-scsi-pci
- ;;
-esac
-
-run_qemu -device $virtio_scsi -device scsi-hd |
- sed -e "s/$virtio_scsi/VIRTIO_SCSI/"
+run_qemu -device virtio-scsi -device scsi-hd
echo
echo === Overriding backing file ===
diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out
index de4771bcb3..437053c839 100644
--- a/tests/qemu-iotests/051.out
+++ b/tests/qemu-iotests/051.out
@@ -72,7 +72,7 @@ QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=foo#12: Invalid node name
=== Device without drive ===
-Testing: -device VIRTIO_SCSI -device scsi-hd
+Testing: -device virtio-scsi -device scsi-hd
QEMU X.Y.Z monitor - type 'help' for more information
(qemu) QEMU_PROG: -device scsi-hd: drive property not set
diff --git a/tests/qemu-iotests/051.pc.out b/tests/qemu-iotests/051.pc.out
index a28e3fc124..e95bd42b8d 100644
--- a/tests/qemu-iotests/051.pc.out
+++ b/tests/qemu-iotests/051.pc.out
@@ -72,7 +72,7 @@ QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=foo#12: Invalid node-name: 'fo
=== Device without drive ===
-Testing: -device VIRTIO_SCSI -device scsi-hd
+Testing: -device virtio-scsi -device scsi-hd
QEMU X.Y.Z monitor - type 'help' for more information
(qemu) QEMU_PROG: -device scsi-hd: drive property not set
diff --git a/tests/qemu-iotests/068 b/tests/qemu-iotests/068
index 03e03508a6..54e49c8ffa 100755
--- a/tests/qemu-iotests/068
+++ b/tests/qemu-iotests/068
@@ -49,11 +49,9 @@ IMG_SIZE=128K
case "$QEMU_DEFAULT_MACHINE" in
s390-ccw-virtio)
platform_parm="-no-shutdown"
- hba=virtio-scsi-ccw
;;
*)
platform_parm=""
- hba=virtio-scsi-pci
;;
esac
@@ -61,7 +59,7 @@ _qemu()
{
$QEMU $platform_parm -nographic -monitor stdio -serial none \
-drive if=none,id=drive0,file="$TEST_IMG",format="$IMGFMT" \
- -device $hba,id=hba0 \
+ -device virtio-scsi,id=hba0 \
-device scsi-hd,drive=drive0 \
"$@" |\
_filter_qemu | _filter_hmp
diff --git a/tests/qemu-iotests/093 b/tests/qemu-iotests/093
index 7745cb04b6..93274dc8cb 100755
--- a/tests/qemu-iotests/093
+++ b/tests/qemu-iotests/093
@@ -371,8 +371,7 @@ class ThrottleTestGroupNames(iotests.QMPTestCase):
class ThrottleTestRemovableMedia(iotests.QMPTestCase):
def setUp(self):
self.vm = iotests.VM()
- self.vm.add_device("{},id=virtio-scsi".format(
- iotests.get_virtio_scsi_device()))
+ self.vm.add_device("{},id=virtio-scsi".format('virtio-scsi'))
self.vm.launch()
def tearDown(self):
diff --git a/tests/qemu-iotests/127 b/tests/qemu-iotests/127
index 98e8e82a82..32edc3b068 100755
--- a/tests/qemu-iotests/127
+++ b/tests/qemu-iotests/127
@@ -44,7 +44,8 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
_supported_fmt qcow2
_supported_proto file fuse
-_require_devices virtio-scsi scsi-hd
+_require_devices scsi-hd
+_require_one_device_of virtio-scsi-pci virtio-scsi-ccw
IMG_SIZE=64K
diff --git a/tests/qemu-iotests/139 b/tests/qemu-iotests/139
index e79b3c21fd..178b1ee230 100755
--- a/tests/qemu-iotests/139
+++ b/tests/qemu-iotests/139
@@ -26,18 +26,13 @@ import time
base_img = os.path.join(iotests.test_dir, 'base.img')
new_img = os.path.join(iotests.test_dir, 'new.img')
-if iotests.qemu_default_machine == 's390-ccw-virtio':
- default_virtio_blk = 'virtio-blk-ccw'
-else:
- default_virtio_blk = 'virtio-blk-pci'
class TestBlockdevDel(iotests.QMPTestCase):
def setUp(self):
iotests.qemu_img('create', '-f', iotests.imgfmt, base_img, '1M')
self.vm = iotests.VM()
- self.vm.add_device("{},id=virtio-scsi".format(
- iotests.get_virtio_scsi_device()))
+ self.vm.add_device("{},id=virtio-scsi".format('virtio-scsi'))
self.vm.launch()
def tearDown(self):
@@ -93,7 +88,7 @@ class TestBlockdevDel(iotests.QMPTestCase):
self.checkBlockDriverState(node, expect_error)
# Add a device model
- def addDeviceModel(self, device, backend, driver = default_virtio_blk):
+ def addDeviceModel(self, device, backend, driver = 'virtio-blk'):
result = self.vm.qmp('device_add', id = device,
driver = driver, drive = backend)
self.assert_qmp(result, 'return', {})
diff --git a/tests/qemu-iotests/182 b/tests/qemu-iotests/182
index 55a0384c08..fcd1d796eb 100755
--- a/tests/qemu-iotests/182
+++ b/tests/qemu-iotests/182
@@ -46,26 +46,17 @@ _supported_proto file
size=32M
-case "$QEMU_DEFAULT_MACHINE" in
- s390-ccw-virtio)
- virtioblk=virtio-blk-ccw
- ;;
- *)
- virtioblk=virtio-blk-pci
- ;;
-esac
-
_make_test_img $size
echo "Starting QEMU"
_launch_qemu -drive file=$TEST_IMG,if=none,id=drive0,file.locking=on \
- -device $virtioblk,drive=drive0
+ -device virtio-blk,drive=drive0
echo
echo "Starting a second QEMU using the same image should fail"
echo 'quit' | $QEMU -nographic -monitor stdio \
-drive file=$TEST_IMG,if=none,id=drive0,file.locking=on \
- -device $virtioblk,drive=drive0 2>&1 | _filter_testdir 2>&1 |
+ -device virtio-blk,drive=drive0 2>&1 | _filter_testdir 2>&1 |
_filter_qemu |
sed -e '/falling back to POSIX file/d' \
-e '/locks can be lost unexpectedly/d'
diff --git a/tests/qemu-iotests/238 b/tests/qemu-iotests/238
index 8a10af57f1..38bd3744e6 100755
--- a/tests/qemu-iotests/238
+++ b/tests/qemu-iotests/238
@@ -26,14 +26,12 @@ from iotests import log
iotests.script_initialize()
-virtio_scsi_device = iotests.get_virtio_scsi_device()
-
vm = iotests.VM()
vm.launch()
log(vm.qmp('blockdev-add', node_name='hd0', driver='null-co', read_zeroes=True))
log(vm.qmp('object-add', qom_type='iothread', id='iothread0'))
-log(vm.qmp('device_add', id='scsi0', driver=virtio_scsi_device, iothread='iothread0'))
+log(vm.qmp('device_add', id='scsi0', driver='virtio-scsi', iothread='iothread0'))
log(vm.qmp('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0'))
log(vm.qmp('block_set_io_throttle', id='scsi-hd0', bps=0, bps_rd=0, bps_wr=0,
iops=1000, iops_rd=0, iops_wr=0, conv_keys=False))
diff --git a/tests/qemu-iotests/240 b/tests/qemu-iotests/240
index ab077f4ceb..9b281e1dc0 100755
--- a/tests/qemu-iotests/240
+++ b/tests/qemu-iotests/240
@@ -42,7 +42,7 @@ class TestCase(iotests.QMPTestCase):
iotests.log('==Unplug a SCSI disk and then plug it again==')
self.vm.qmp_log('blockdev-add', driver='null-co', read_zeroes=True, node_name='hd0')
self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
- self.vm.qmp_log('device_add', id='scsi0', driver=iotests.get_virtio_scsi_device(), iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
+ self.vm.qmp_log('device_add', id='scsi0', driver='virtio-scsi', iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
self.vm.qmp_log('device_del', id='scsi-hd0')
self.vm.event_wait('DEVICE_DELETED')
@@ -55,7 +55,7 @@ class TestCase(iotests.QMPTestCase):
iotests.log('==Attach two SCSI disks using the same block device and the same iothread==')
self.vm.qmp_log('blockdev-add', driver='null-co', read_zeroes=True, node_name='hd0', read_only=True)
self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
- self.vm.qmp_log('device_add', id='scsi0', driver=iotests.get_virtio_scsi_device(), iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
+ self.vm.qmp_log('device_add', id='scsi0', driver='virtio-scsi', iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
self.vm.qmp_log('device_add', id='scsi-hd1', driver='scsi-hd', drive='hd0')
@@ -73,8 +73,8 @@ class TestCase(iotests.QMPTestCase):
self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
self.vm.qmp_log('object-add', qom_type='iothread', id="iothread1")
- self.vm.qmp_log('device_add', id='scsi0', driver=iotests.get_virtio_scsi_device(), iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
- self.vm.qmp_log('device_add', id='scsi1', driver=iotests.get_virtio_scsi_device(), iothread='iothread1', filters=[iotests.filter_qmp_virtio_scsi])
+ self.vm.qmp_log('device_add', id='scsi0', driver='virtio-scsi', iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
+ self.vm.qmp_log('device_add', id='scsi1', driver='virtio-scsi', iothread='iothread1', filters=[iotests.filter_qmp_virtio_scsi])
self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0', bus="scsi0.0")
self.vm.qmp_log('device_add', id='scsi-hd1', driver='scsi-hd', drive='hd0', bus="scsi1.0")
@@ -99,7 +99,7 @@ class TestCase(iotests.QMPTestCase):
self.vm.qmp_log('nbd-server-add', device='hd0')
self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
- self.vm.qmp_log('device_add', id='scsi0', driver=iotests.get_virtio_scsi_device(), iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
+ self.vm.qmp_log('device_add', id='scsi0', driver='virtio-scsi', iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
if __name__ == '__main__':
diff --git a/tests/qemu-iotests/256 b/tests/qemu-iotests/256
index 8d82a1dd86..13666813bd 100755
--- a/tests/qemu-iotests/256
+++ b/tests/qemu-iotests/256
@@ -24,6 +24,8 @@ import os
import iotests
from iotests import log
+iotests._verify_virtio_scsi_pci_or_ccw()
+
iotests.script_initialize(supported_fmts=['qcow2'])
size = 64 * 1024 * 1024
@@ -61,8 +63,8 @@ with iotests.FilePath('img0') as img0_path, \
log('--- Preparing images & VM ---\n')
vm.add_object('iothread,id=iothread0')
vm.add_object('iothread,id=iothread1')
- vm.add_device('virtio-scsi-pci,id=scsi0,iothread=iothread0')
- vm.add_device('virtio-scsi-pci,id=scsi1,iothread=iothread1')
+ vm.add_device('virtio-scsi,id=scsi0,iothread=iothread0')
+ vm.add_device('virtio-scsi,id=scsi1,iothread=iothread1')
iotests.qemu_img_create('-f', iotests.imgfmt, img0_path, str(size))
iotests.qemu_img_create('-f', iotests.imgfmt, img1_path, str(size))
vm.add_drive(img0_path, interface='none')
diff --git a/tests/qemu-iotests/257 b/tests/qemu-iotests/257
index 7cd2520829..c72c82a171 100755
--- a/tests/qemu-iotests/257
+++ b/tests/qemu-iotests/257
@@ -292,7 +292,7 @@ def test_bitmap_sync(bsync_mode, msync_mode='bitmap', failure=None):
log('--- Preparing image & VM ---\n')
drive0 = Drive(img_path, vm=vm)
drive0.img_create(iotests.imgfmt, SIZE)
- vm.add_device("{},id=scsi0".format(iotests.get_virtio_scsi_device()))
+ vm.add_device("{},id=scsi0".format('virtio-scsi'))
vm.launch()
file_config = {
@@ -449,7 +449,7 @@ def test_backup_api():
log('--- Preparing image & VM ---\n')
drive0 = Drive(img_path, vm=vm)
drive0.img_create(iotests.imgfmt, SIZE)
- vm.add_device("{},id=scsi0".format(iotests.get_virtio_scsi_device()))
+ vm.add_device("{},id=scsi0".format('virtio-scsi'))
vm.launch()
file_config = {
diff --git a/tests/qemu-iotests/307 b/tests/qemu-iotests/307
index 9008974346..c7685347bc 100755
--- a/tests/qemu-iotests/307
+++ b/tests/qemu-iotests/307
@@ -40,13 +40,11 @@ with iotests.FilePath('image') as img, \
iotests.log('=== Launch VM ===')
- virtio_scsi_device = iotests.get_virtio_scsi_device()
-
vm.add_object('iothread,id=iothread0')
vm.add_blockdev(f'file,filename={img},node-name=file')
vm.add_blockdev(f'{iotests.imgfmt},file=file,node-name=fmt')
vm.add_blockdev('raw,file=file,node-name=ro,read-only=on')
- vm.add_device(f'id=scsi0,driver={virtio_scsi_device},iothread=iothread0')
+ vm.add_device(f'id=scsi0,driver=virtio-scsi,iothread=iothread0')
vm.launch()
vm.qmp_log('nbd-server-start',
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
index 65cdba5723..7f49c9716d 100644
--- a/tests/qemu-iotests/common.rc
+++ b/tests/qemu-iotests/common.rc
@@ -977,5 +977,18 @@ _require_devices()
done
}
+_require_one_device_of()
+{
+ available=$($QEMU -M none -device help | \
+ grep ^name | sed -e 's/^name "//' -e 's/".*$//')
+ for device
+ do
+ if echo "$available" | grep -q "$device" ; then
+ return
+ fi
+ done
+ _notrun "$* not available"
+}
+
# make sure this script returns success
true
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 90d0b62523..5af0182895 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -234,11 +234,6 @@ def qemu_io_silent_check(*args):
stderr=subprocess.STDOUT)
return exitcode == 0
-def get_virtio_scsi_device():
- if qemu_default_machine == 's390-ccw-virtio':
- return 'virtio-scsi-ccw'
- return 'virtio-scsi-pci'
-
class QemuIoInteractive:
def __init__(self, *args):
self.args = qemu_io_args_no_fmt + list(args)
@@ -1151,6 +1146,11 @@ def _verify_virtio_blk() -> None:
if 'virtio-blk' not in out:
notrun('Missing virtio-blk in QEMU binary')
+def _verify_virtio_scsi_pci_or_ccw() -> None:
+ out = qemu_pipe('-M', 'none', '-device', 'help')
+ if 'virtio-scsi-pci' not in out and 'virtio-scsi-ccw' not in out:
+ notrun('Missing virtio-scsi-pci or virtio-scsi-ccw in QEMU binary')
+
def supports_quorum():
return 'quorum' in qemu_img_pipe('--help')
diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py
index 1fbec854c1..6d27712617 100644
--- a/tests/qemu-iotests/testenv.py
+++ b/tests/qemu-iotests/testenv.py
@@ -208,6 +208,7 @@ class TestEnv(ContextManager['TestEnv']):
('arm', 'virt'),
('aarch64', 'virt'),
('avr', 'mega2560'),
+ ('m68k', 'virt'),
('rx', 'gdbsim-r5f562n8'),
('tricore', 'tricore_testboard')
)
diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target
index 24d75a5801..cab8c6b3a2 100644
--- a/tests/tcg/Makefile.target
+++ b/tests/tcg/Makefile.target
@@ -32,6 +32,9 @@
all:
-include ../../../config-host.mak
-include ../config-$(TARGET).mak
+ifeq ($(CONFIG_USER_ONLY),y)
+-include $(SRC_PATH)/default-configs/targets/$(TARGET).mak
+endif
# for including , in command strings
COMMA := ,
diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target
index bf53ad0087..56e48f4b34 100644
--- a/tests/tcg/aarch64/Makefile.target
+++ b/tests/tcg/aarch64/Makefile.target
@@ -41,24 +41,6 @@ AARCH64_TESTS += mte-1 mte-2 mte-3 mte-4
mte-%: CFLAGS += -march=armv8.5-a+memtag
endif
-# Semihosting smoke test for linux-user
-AARCH64_TESTS += semihosting
-run-semihosting: semihosting
- $(call run-test,$<,$(QEMU) $< 2> $<.err, "$< on $(TARGET_NAME)")
-
-run-plugin-semihosting-with-%:
- $(call run-test, $@, $(QEMU) $(QEMU_OPTS) \
- -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@) \
- $(call strip-plugin,$<) 2> $<.err, \
- "$< on $(TARGET_NAME) with $*")
-
-AARCH64_TESTS += semiconsole
-run-semiconsole: semiconsole
- $(call skip-test, $<, "MANUAL ONLY")
-
-run-plugin-semiconsole-with-%:
- $(call skip-test, $<, "MANUAL ONLY")
-
ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_SVE),)
# System Registers Tests
AARCH64_TESTS += sysregs
diff --git a/tests/tcg/aarch64/semicall.h b/tests/tcg/aarch64/semicall.h
new file mode 100644
index 0000000000..8a3fce35c5
--- /dev/null
+++ b/tests/tcg/aarch64/semicall.h
@@ -0,0 +1,18 @@
+/*
+ * Semihosting Tests - AArch64 helper
+ *
+ * Copyright (c) 2019
+ * Written by Alex Bennée <alex.bennee@linaro.org>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+uintptr_t __semi_call(uintptr_t type, uintptr_t arg0)
+{
+ register uintptr_t t asm("x0") = type;
+ register uintptr_t a0 asm("x1") = arg0;
+ asm("hlt 0xf000"
+ : "=r" (t)
+ : "r" (t), "r" (a0));
+ return t;
+}
diff --git a/tests/tcg/arm/Makefile.target b/tests/tcg/arm/Makefile.target
index ec95156562..5ab59ed6ce 100644
--- a/tests/tcg/arm/Makefile.target
+++ b/tests/tcg/arm/Makefile.target
@@ -29,37 +29,31 @@ run-fcvt: fcvt
$(call run-test,fcvt,$(QEMU) $<,"$< on $(TARGET_NAME)")
$(call diff-out,fcvt,$(ARM_SRC)/fcvt.ref)
+ifeq ($(CONFIG_ARM_COMPATIBLE_SEMIHOSTING),y)
+
# Semihosting smoke test for linux-user
-ARM_TESTS += semihosting
semihosting: CFLAGS += -mthumb
-run-semihosting: semihosting
- $(call run-test,$<,$(QEMU) $< 2> $<.err, "$< on $(TARGET_NAME)")
ARM_TESTS += semihosting-arm
-semihosting-arm: CFLAGS += -marm
+semihosting-arm: CFLAGS += -marm -I$(SRC_PATH)/tests/tcg/$(TARGET_NAME)
semihosting-arm: semihosting.c
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
run-semihosting-arm: semihosting-arm
$(call run-test,$<,$(QEMU) $< 2> $<.err, "$< on $(TARGET_NAME)")
-run-plugin-semihosting-with-%:
+run-plugin-semihosting-arm-with-%:
$(call run-test, $@, $(QEMU) $(QEMU_OPTS) \
-plugin $(PLUGIN_LIB)/$(call extract-plugin,$@) \
$(call strip-plugin,$<) 2> $<.err, \
"$< on $(TARGET_NAME) with $*")
-ARM_TESTS += semiconsole semiconsole-arm
+ARM_TESTS += semiconsole-arm
semiconsole: CFLAGS += -mthumb
-run-semiconsole: semiconsole
- $(call skip-test, $<, "MANUAL ONLY")
-run-plugin-semiconsole-with-%:
- $(call skip-test, $<, "MANUAL ONLY")
-
-semiconsole-arm: CFLAGS += -marm
-semiconsole-arm: semiconsole.c
+semiconsole-arm: CFLAGS += -marm -I$(SRC_PATH)/tests/tcg/$(TARGET_NAME)
+semiconsole-arm: semihosting.c
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
run-semiconsole-arm: semiconsole-arm
@@ -68,6 +62,8 @@ run-semiconsole-arm: semiconsole-arm
run-plugin-semiconsole-arm-with-%:
$(call skip-test, $<, "MANUAL ONLY")
+endif
+
ARM_TESTS += commpage
TESTS += $(ARM_TESTS)
diff --git a/tests/tcg/arm/semicall.h b/tests/tcg/arm/semicall.h
index d4f6818192..ad8ac51310 100644
--- a/tests/tcg/arm/semicall.h
+++ b/tests/tcg/arm/semicall.h
@@ -1,5 +1,5 @@
/*
- * Semihosting Tests
+ * Semihosting Tests - ARM Helper
*
* Copyright (c) 2019
* Written by Alex Bennée <alex.bennee@linaro.org>
@@ -7,13 +7,8 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
-#define SYS_WRITE0 0x04
-#define SYS_READC 0x07
-#define SYS_REPORTEXC 0x18
-
uintptr_t __semi_call(uintptr_t type, uintptr_t arg0)
{
-#if defined(__arm__)
register uintptr_t t asm("r0") = type;
register uintptr_t a0 asm("r1") = arg0;
#ifdef __thumb__
@@ -23,13 +18,5 @@ uintptr_t __semi_call(uintptr_t type, uintptr_t arg0)
#endif
asm(SVC : "=r" (t)
: "r" (t), "r" (a0));
-#else
- register uintptr_t t asm("x0") = type;
- register uintptr_t a0 asm("x1") = arg0;
- asm("hlt 0xf000"
- : "=r" (t)
- : "r" (t), "r" (a0));
-#endif
-
return t;
}
diff --git a/tests/tcg/arm/semihosting.c b/tests/tcg/arm/semihosting.c
deleted file mode 100644
index 33faac9916..0000000000
--- a/tests/tcg/arm/semihosting.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * linux-user semihosting checks
- *
- * Copyright (c) 2019
- * Written by Alex Bennée <alex.bennee@linaro.org>
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
-
-#include <stdint.h>
-#include "semicall.h"
-
-int main(int argc, char *argv[argc])
-{
-#if defined(__arm__)
- uintptr_t exit_code = 0x20026;
-#else
- uintptr_t exit_block[2] = {0x20026, 0};
- uintptr_t exit_code = (uintptr_t) &exit_block;
-#endif
-
- __semi_call(SYS_WRITE0, (uintptr_t) "Hello World");
- __semi_call(SYS_REPORTEXC, exit_code);
- /* if we get here we failed */
- return -1;
-}
diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Makefile.target
index abbdb2e126..a3a751723d 100644
--- a/tests/tcg/multiarch/Makefile.target
+++ b/tests/tcg/multiarch/Makefile.target
@@ -69,6 +69,37 @@ run-gdbstub-%:
endif
EXTRA_RUNS += run-gdbstub-sha1 run-gdbstub-qxfer-auxv-read
+# ARM Compatible Semi Hosting Tests
+#
+# Despite having ARM in the name we actually have several
+# architectures that implement it. We gate the tests on the feature
+# appearing in config.
+#
+ifeq ($(CONFIG_ARM_COMPATIBLE_SEMIHOSTING),y)
+VPATH += $(MULTIARCH_SRC)/arm-compat-semi
+
+# Add -I path back to TARGET_NAME for semicall.h
+semihosting: CFLAGS+=-I$(SRC_PATH)/tests/tcg/$(TARGET_NAME)
+
+run-semihosting: semihosting
+ $(call run-test,$<,$(QEMU) $< 2> $<.err, "$< on $(TARGET_NAME)")
+
+run-plugin-semihosting-with-%:
+ $(call run-test, $@, $(QEMU) $(QEMU_OPTS) \
+ -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@) \
+ $(call strip-plugin,$<) 2> $<.err, \
+ "$< on $(TARGET_NAME) with $*")
+
+semiconsole: CFLAGS+=-I$(SRC_PATH)/tests/tcg/$(TARGET_NAME)
+
+run-semiconsole: semiconsole
+ $(call skip-test, $<, "MANUAL ONLY")
+
+run-plugin-semiconsole-with-%:
+ $(call skip-test, $<, "MANUAL ONLY")
+
+TESTS += semihosting semiconsole
+endif
# Update TESTS
TESTS += $(MULTIARCH_TESTS)
diff --git a/tests/tcg/arm/semiconsole.c b/tests/tcg/multiarch/arm-compat-semi/semiconsole.c
index 6ef0bd2450..1d82efc589 100644
--- a/tests/tcg/arm/semiconsole.c
+++ b/tests/tcg/multiarch/arm-compat-semi/semiconsole.c
@@ -7,6 +7,8 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
+#define SYS_READC 0x07
+
#include <stdio.h>
#include <stdint.h>
#include "semicall.h"
diff --git a/tests/tcg/multiarch/arm-compat-semi/semihosting.c b/tests/tcg/multiarch/arm-compat-semi/semihosting.c
new file mode 100644
index 0000000000..8627eee3cf
--- /dev/null
+++ b/tests/tcg/multiarch/arm-compat-semi/semihosting.c
@@ -0,0 +1,82 @@
+/*
+ * linux-user semihosting checks
+ *
+ * Copyright (c) 2019
+ * Written by Alex Bennée <alex.bennee@linaro.org>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define SYS_WRITE0 0x04
+#define SYS_HEAPINFO 0x16
+#define SYS_REPORTEXC 0x18
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "semicall.h"
+
+int main(int argc, char *argv[argc])
+{
+#if UINTPTR_MAX == UINT32_MAX
+ uintptr_t exit_code = 0x20026;
+#else
+ uintptr_t exit_block[2] = {0x20026, 0};
+ uintptr_t exit_code = (uintptr_t) &exit_block;
+#endif
+ struct {
+ void *heap_base;
+ void *heap_limit;
+ void *stack_base;
+ void *stack_limit;
+ } info;
+ void *ptr_to_info = (void *) &info;
+
+ __semi_call(SYS_WRITE0, (uintptr_t) "Checking HeapInfo\n");
+
+ memset(&info, 0, sizeof(info));
+ __semi_call(SYS_HEAPINFO, (uintptr_t) &ptr_to_info);
+
+ if (info.heap_base == NULL || info.heap_limit == NULL) {
+ printf("null heap: %p -> %p\n", info.heap_base, info.heap_limit);
+ exit(1);
+ }
+
+ /* Error if heap base is above limit */
+ if ((uintptr_t) info.heap_base >= (uintptr_t) info.heap_limit) {
+ printf("heap base %p >= heap_limit %p\n",
+ info.heap_base, info.heap_limit);
+ exit(2);
+ }
+
+ if (info.stack_base == NULL || info.stack_limit) {
+ printf("null stack: %p -> %p\n", info.stack_base, info.stack_limit);
+ exit(3);
+ }
+
+ /* check our local variables are indeed inside the reported stack */
+ if (ptr_to_info > info.stack_base) {
+ printf("info appears to be above stack: %p > %p\n", ptr_to_info,
+ info.stack_base);
+ exit(4);
+ } else if (ptr_to_info < info.stack_limit) {
+ printf("info appears to be outside stack: %p < %p\n", ptr_to_info,
+ info.stack_limit);
+ exit(5);
+ }
+
+ if (ptr_to_info > info.heap_base && ptr_to_info < info.heap_limit) {
+ printf("info appears to be inside the heap: %p in %p:%p\n",
+ ptr_to_info, info.heap_base, info.heap_limit);
+ exit(6);
+ }
+
+ printf("heap: %p -> %p\n", info.heap_base, info.heap_limit);
+ printf("stack: %p -> %p\n", info.stack_base, info.stack_limit);
+
+ __semi_call(SYS_WRITE0, (uintptr_t) "Passed HeapInfo checks");
+ __semi_call(SYS_REPORTEXC, exit_code);
+ /* if we get here we failed */
+ return -1;
+}
diff --git a/tests/tcg/riscv64/semicall.h b/tests/tcg/riscv64/semicall.h
new file mode 100644
index 0000000000..f8c88f32dc
--- /dev/null
+++ b/tests/tcg/riscv64/semicall.h
@@ -0,0 +1,22 @@
+/*
+ * Semihosting Tests - RiscV64 Helper
+ *
+ * Copyright (c) 2021
+ * Written by Alex Bennée <alex.bennee@linaro.org>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+uintptr_t __semi_call(uintptr_t type, uintptr_t arg0)
+{
+ register uintptr_t t asm("a0") = type;
+ register uintptr_t a0 asm("a1") = arg0;
+ asm(".option norvc\n\t"
+ ".balign 16\n\t"
+ "slli zero, zero, 0x1f\n\t"
+ "ebreak\n\t"
+ "srai zero, zero, 0x7\n\t"
+ : "=r" (t)
+ : "r" (t), "r" (a0));
+ return t;
+}
diff --git a/tests/unit/test-cutils.c b/tests/unit/test-cutils.c
index e025b54c05..98671f1ac3 100644
--- a/tests/unit/test-cutils.c
+++ b/tests/unit/test-cutils.c
@@ -378,6 +378,15 @@ static void test_qemu_strtoi_hex(void)
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 0x123);
g_assert(endptr == str + strlen(str));
+
+ str = "0x";
+ res = 999;
+ endptr = &f;
+ err = qemu_strtoi(str, &endptr, 16, &res);
+
+ g_assert_cmpint(err, ==, 0);
+ g_assert_cmpint(res, ==, 0);
+ g_assert(endptr == str + 1);
}
static void test_qemu_strtoi_max(void)
@@ -669,6 +678,15 @@ static void test_qemu_strtoui_hex(void)
g_assert_cmpint(err, ==, 0);
g_assert_cmphex(res, ==, 0x123);
g_assert(endptr == str + strlen(str));
+
+ str = "0x";
+ res = 999;
+ endptr = &f;
+ err = qemu_strtoui(str, &endptr, 16, &res);
+
+ g_assert_cmpint(err, ==, 0);
+ g_assert_cmphex(res, ==, 0);
+ g_assert(endptr == str + 1);
}
static void test_qemu_strtoui_max(void)
@@ -955,6 +973,15 @@ static void test_qemu_strtol_hex(void)
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 0x123);
g_assert(endptr == str + strlen(str));
+
+ str = "0x";
+ res = 999;
+ endptr = &f;
+ err = qemu_strtol(str, &endptr, 16, &res);
+
+ g_assert_cmpint(err, ==, 0);
+ g_assert_cmpint(res, ==, 0);
+ g_assert(endptr == str + 1);
}
static void test_qemu_strtol_max(void)
@@ -1244,6 +1271,15 @@ static void test_qemu_strtoul_hex(void)
g_assert_cmpint(err, ==, 0);
g_assert_cmphex(res, ==, 0x123);
g_assert(endptr == str + strlen(str));
+
+ str = "0x";
+ res = 999;
+ endptr = &f;
+ err = qemu_strtoul(str, &endptr, 16, &res);
+
+ g_assert_cmpint(err, ==, 0);
+ g_assert_cmphex(res, ==, 0);
+ g_assert(endptr == str + 1);
}
static void test_qemu_strtoul_max(void)
@@ -1528,6 +1564,15 @@ static void test_qemu_strtoi64_hex(void)
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 0x123);
g_assert(endptr == str + strlen(str));
+
+ str = "0x";
+ endptr = &f;
+ res = 999;
+ err = qemu_strtoi64(str, &endptr, 16, &res);
+
+ g_assert_cmpint(err, ==, 0);
+ g_assert_cmpint(res, ==, 0);
+ g_assert(endptr == str + 1);
}
static void test_qemu_strtoi64_max(void)
@@ -1815,6 +1860,15 @@ static void test_qemu_strtou64_hex(void)
g_assert_cmpint(err, ==, 0);
g_assert_cmphex(res, ==, 0x123);
g_assert(endptr == str + strlen(str));
+
+ str = "0x";
+ endptr = &f;
+ res = 999;
+ err = qemu_strtou64(str, &endptr, 16, &res);
+
+ g_assert_cmpint(err, ==, 0);
+ g_assert_cmphex(res, ==, 0);
+ g_assert(endptr == str + 1);
}
static void test_qemu_strtou64_max(void)
@@ -1952,9 +2006,11 @@ static void test_qemu_strtosz_simple(void)
const char *str;
const char *endptr;
int err;
- uint64_t res = 0xbaadf00d;
+ uint64_t res;
str = "0";
+ endptr = str;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 0);
@@ -1962,6 +2018,8 @@ static void test_qemu_strtosz_simple(void)
/* Leading 0 gives decimal results, not octal */
str = "08";
+ endptr = str;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 8);
@@ -1969,46 +2027,61 @@ static void test_qemu_strtosz_simple(void)
/* Leading space is ignored */
str = " 12345";
+ endptr = str;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 12345);
g_assert(endptr == str + 6);
+ res = 0xbaadf00d;
err = qemu_strtosz(str, NULL, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 12345);
str = "9007199254740991"; /* 2^53-1 */
+ endptr = str;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 0x1fffffffffffff);
g_assert(endptr == str + 16);
str = "9007199254740992"; /* 2^53 */
+ endptr = str;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 0x20000000000000);
g_assert(endptr == str + 16);
str = "9007199254740993"; /* 2^53+1 */
+ endptr = str;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 0x20000000000001);
g_assert(endptr == str + 16);
str = "18446744073709549568"; /* 0xfffffffffffff800 (53 msbs set) */
+ endptr = str;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 0xfffffffffffff800);
g_assert(endptr == str + 20);
str = "18446744073709550591"; /* 0xfffffffffffffbff */
+ endptr = str;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 0xfffffffffffffbff);
g_assert(endptr == str + 20);
str = "18446744073709551615"; /* 0xffffffffffffffff */
+ endptr = str;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 0xffffffffffffffff);
@@ -2020,21 +2093,27 @@ static void test_qemu_strtosz_hex(void)
const char *str;
const char *endptr;
int err;
- uint64_t res = 0xbaadf00d;
+ uint64_t res;
str = "0x0";
+ endptr = str;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 0);
g_assert(endptr == str + 3);
str = "0xab";
+ endptr = str;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 171);
g_assert(endptr == str + 4);
str = "0xae";
+ endptr = str;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 174);
@@ -2053,44 +2132,60 @@ static void test_qemu_strtosz_units(void)
const char *e = "1E";
int err;
const char *endptr;
- uint64_t res = 0xbaadf00d;
+ uint64_t res;
/* default is M */
+ endptr = NULL;
+ res = 0xbaadf00d;
err = qemu_strtosz_MiB(none, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, MiB);
g_assert(endptr == none + 1);
+ endptr = NULL;
+ res = 0xbaadf00d;
err = qemu_strtosz(b, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 1);
g_assert(endptr == b + 2);
+ endptr = NULL;
+ res = 0xbaadf00d;
err = qemu_strtosz(k, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, KiB);
g_assert(endptr == k + 2);
+ endptr = NULL;
+ res = 0xbaadf00d;
err = qemu_strtosz(m, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, MiB);
g_assert(endptr == m + 2);
+ endptr = NULL;
+ res = 0xbaadf00d;
err = qemu_strtosz(g, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, GiB);
g_assert(endptr == g + 2);
+ endptr = NULL;
+ res = 0xbaadf00d;
err = qemu_strtosz(t, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, TiB);
g_assert(endptr == t + 2);
+ endptr = NULL;
+ res = 0xbaadf00d;
err = qemu_strtosz(p, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, PiB);
g_assert(endptr == p + 2);
+ endptr = NULL;
+ res = 0xbaadf00d;
err = qemu_strtosz(e, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, EiB);
@@ -2102,9 +2197,11 @@ static void test_qemu_strtosz_float(void)
const char *str;
int err;
const char *endptr;
- uint64_t res = 0xbaadf00d;
+ uint64_t res;
str = "0.5E";
+ endptr = str;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, EiB / 2);
@@ -2112,6 +2209,8 @@ static void test_qemu_strtosz_float(void)
/* For convenience, a fraction of 0 is tolerated even on bytes */
str = "1.0B";
+ endptr = str;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 1);
@@ -2119,6 +2218,8 @@ static void test_qemu_strtosz_float(void)
/* An empty fraction is tolerated */
str = "1.k";
+ endptr = str;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 1024);
@@ -2126,6 +2227,8 @@ static void test_qemu_strtosz_float(void)
/* For convenience, we permit values that are not byte-exact */
str = "12.345M";
+ endptr = str;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, (uint64_t) (12.345 * MiB + 0.5));
@@ -2140,67 +2243,91 @@ static void test_qemu_strtosz_invalid(void)
uint64_t res = 0xbaadf00d;
str = "";
+ endptr = NULL;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, -EINVAL);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
g_assert(endptr == str);
str = " \t ";
+ endptr = NULL;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, -EINVAL);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
g_assert(endptr == str);
str = "crap";
+ endptr = NULL;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, -EINVAL);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
g_assert(endptr == str);
str = "inf";
+ endptr = NULL;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, -EINVAL);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
g_assert(endptr == str);
str = "NaN";
+ endptr = NULL;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, -EINVAL);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
g_assert(endptr == str);
/* Fractional values require scale larger than bytes */
str = "1.1B";
+ endptr = NULL;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, -EINVAL);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
g_assert(endptr == str);
str = "1.1";
+ endptr = NULL;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, -EINVAL);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
g_assert(endptr == str);
/* No floating point exponents */
str = "1.5e1k";
+ endptr = NULL;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, -EINVAL);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
g_assert(endptr == str);
str = "1.5E+0k";
+ endptr = NULL;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, -EINVAL);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
g_assert(endptr == str);
/* No hex fractions */
str = "0x1.8k";
+ endptr = NULL;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, -EINVAL);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
g_assert(endptr == str);
/* No negative values */
str = "-0";
+ endptr = NULL;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, -EINVAL);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
g_assert(endptr == str);
str = "-1";
+ endptr = NULL;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, -EINVAL);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
g_assert(endptr == str);
}
@@ -2209,48 +2336,72 @@ static void test_qemu_strtosz_trailing(void)
const char *str;
const char *endptr;
int err;
- uint64_t res = 0xbaadf00d;
+ uint64_t res;
str = "123xxx";
+ endptr = NULL;
+ res = 0xbaadf00d;
err = qemu_strtosz_MiB(str, &endptr, &res);
+ g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 123 * MiB);
g_assert(endptr == str + 3);
+ res = 0xbaadf00d;
err = qemu_strtosz(str, NULL, &res);
g_assert_cmpint(err, ==, -EINVAL);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
str = "1kiB";
+ endptr = NULL;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 1024);
g_assert(endptr == str + 2);
+ res = 0xbaadf00d;
err = qemu_strtosz(str, NULL, &res);
g_assert_cmpint(err, ==, -EINVAL);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
str = "0x";
+ endptr = NULL;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
+ g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 0);
g_assert(endptr == str + 1);
+ res = 0xbaadf00d;
err = qemu_strtosz(str, NULL, &res);
g_assert_cmpint(err, ==, -EINVAL);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
str = "0.NaN";
+ endptr = NULL;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
+ g_assert_cmpint(res, ==, 0);
g_assert(endptr == str + 2);
+ res = 0xbaadf00d;
err = qemu_strtosz(str, NULL, &res);
g_assert_cmpint(err, ==, -EINVAL);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
str = "123-45";
+ endptr = NULL;
+ res = 0xbaadf00d;
err = qemu_strtosz(str, &endptr, &res);
+ g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 123);
g_assert(endptr == str + 3);
+ res = 0xbaadf00d;
err = qemu_strtosz(str, NULL, &res);
g_assert_cmpint(err, ==, -EINVAL);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
}
static void test_qemu_strtosz_erange(void)
@@ -2261,13 +2412,17 @@ static void test_qemu_strtosz_erange(void)
uint64_t res = 0xbaadf00d;
str = "18446744073709551616"; /* 2^64; see strtosz_simple for 2^64-1 */
+ endptr = NULL;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, -ERANGE);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
g_assert(endptr == str + 20);
str = "20E";
+ endptr = NULL;
err = qemu_strtosz(str, &endptr, &res);
g_assert_cmpint(err, ==, -ERANGE);
+ g_assert_cmpint(res, ==, 0xbaadf00d);
g_assert(endptr == str + 3);
}
@@ -2276,15 +2431,19 @@ static void test_qemu_strtosz_metric(void)
const char *str;
int err;
const char *endptr;
- uint64_t res = 0xbaadf00d;
+ uint64_t res;
str = "12345k";
+ endptr = str;
+ res = 0xbaadf00d;
err = qemu_strtosz_metric(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 12345000);
g_assert(endptr == str + 6);
str = "12.345M";
+ endptr = str;
+ res = 0xbaadf00d;
err = qemu_strtosz_metric(str, &endptr, &res);
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 12345000);