diff options
author | Eduardo Habkost <ehabkost@redhat.com> | 2013-02-04 16:27:45 -0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2013-02-04 14:38:33 -0600 |
commit | e3f9fe2d404ca10153e95499ece111c077b6690a (patch) | |
tree | 1e7c9447e310d8ec6d1002f25dce0f25444b0ceb /tests/Makefile | |
parent | ff057ccb07f07ee8f34ae4104f7ba8c2dcbc3f9a (diff) | |
download | qemu-e3f9fe2d404ca10153e95499ece111c077b6690a.zip qemu-e3f9fe2d404ca10153e95499ece111c077b6690a.tar.gz qemu-e3f9fe2d404ca10153e95499ece111c077b6690a.tar.bz2 |
cutils: unsigned int parsing functions
There are lots of duplicate parsing code using strto*() in QEMU, and
most of that code is broken in one way or another. Even the visitors
code have duplicate integer parsing code[1]. This introduces functions
to help parsing unsigned int values: parse_uint() and parse_uint_full().
Parsing functions for signed ints and floats will be submitted later.
parse_uint_full() has all the checks made by opts_type_uint64() at
opts-visitor.c:
- Check for NULL (returns -EINVAL)
- Check for negative numbers (returns -EINVAL)
- Check for empty string (returns -EINVAL)
- Check for overflow or other errno values set by strtoll() (returns
-errno)
- Check for end of string (reject invalid characters after number)
(returns -EINVAL)
parse_uint() does everything above except checking for the end of the
string, so callers can continue parsing the remainder of string after
the number.
Unit tests included.
[1] string-input-visitor.c:parse_int() could use the same parsing code
used by opts-visitor.c:opts_type_int(), instead of duplicating that
logic.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'tests/Makefile')
-rw-r--r-- | tests/Makefile | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/tests/Makefile b/tests/Makefile index 83145f5..a2d62b8 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -52,6 +52,8 @@ check-unit-y += tests/test-x86-cpuid$(EXESUF) gcov-files-test-x86-cpuid-y = check-unit-y += tests/test-xbzrle$(EXESUF) gcov-files-test-xbzrle-y = xbzrle.c +check-unit-y += tests/test-cutils$(EXESUF) +gcov-files-test-cutils-y += util/cutils.c check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh @@ -101,6 +103,7 @@ tests/test-iov$(EXESUF): tests/test-iov.o libqemuutil.a tests/test-hbitmap$(EXESUF): tests/test-hbitmap.o libqemuutil.a libqemustub.a tests/test-x86-cpuid$(EXESUF): tests/test-x86-cpuid.o tests/test-xbzrle$(EXESUF): tests/test-xbzrle.o xbzrle.o page_cache.o libqemuutil.a +tests/test-cutils$(EXESUF): tests/test-cutils.o util/cutils.o tests/test-qapi-types.c tests/test-qapi-types.h :\ $(SRC_PATH)/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-types.py |