[PATCH 5/8] KVM: selftests: Add vsprintf() to KVM selftests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add string formatting support to the guest by adding a local version
of vsprintf with no dependencies on LIBC.

There were some minor fix-ups needed to get it compiling in selftests:
 - isdigit() was added as a local helper.
 - boot.h was switch for test_util.h.
 - printf and sprintf were removed.  Support for printing will go
   through the ucall framework.

Signed-off-by: Aaron Lewis <aaronlewis@xxxxxxxxxx>
---
 tools/testing/selftests/kvm/Makefile          |  1 +
 .../testing/selftests/kvm/include/test_util.h |  2 ++
 tools/testing/selftests/kvm/lib/printf.c      | 33 ++++---------------
 3 files changed, 9 insertions(+), 27 deletions(-)

diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index cda631f10526..ce577b564616 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -23,6 +23,7 @@ LIBKVM += lib/guest_modes.c
 LIBKVM += lib/io.c
 LIBKVM += lib/kvm_util.c
 LIBKVM += lib/memstress.c
+LIBKVM += lib/printf.c
 LIBKVM += lib/rbtree.c
 LIBKVM += lib/sparsebit.c
 LIBKVM += lib/test_util.c
diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h
index 80d6416f3012..261852598a4a 100644
--- a/tools/testing/selftests/kvm/include/test_util.h
+++ b/tools/testing/selftests/kvm/include/test_util.h
@@ -177,4 +177,6 @@ static inline uint32_t atoi_non_negative(const char *name, const char *num_str)
 	return num;
 }
 
+int vsprintf(char *buf, const char *fmt, va_list args);
+
 #endif /* SELFTEST_KVM_TEST_UTIL_H */
diff --git a/tools/testing/selftests/kvm/lib/printf.c b/tools/testing/selftests/kvm/lib/printf.c
index 1237beeb9540..d356e55cbc28 100644
--- a/tools/testing/selftests/kvm/lib/printf.c
+++ b/tools/testing/selftests/kvm/lib/printf.c
@@ -13,7 +13,12 @@
  *
  */
 
-#include "boot.h"
+#include "test_util.h"
+
+int isdigit(int ch)
+{
+	return (ch >= '0') && (ch <= '9');
+}
 
 static int skip_atoi(const char **s)
 {
@@ -279,29 +284,3 @@ int vsprintf(char *buf, const char *fmt, va_list args)
 	*str = '\0';
 	return str - buf;
 }
-
-int sprintf(char *buf, const char *fmt, ...)
-{
-	va_list args;
-	int i;
-
-	va_start(args, fmt);
-	i = vsprintf(buf, fmt, args);
-	va_end(args);
-	return i;
-}
-
-int printf(const char *fmt, ...)
-{
-	char printf_buf[1024];
-	va_list args;
-	int printed;
-
-	va_start(args, fmt);
-	printed = vsprintf(printf_buf, fmt, args);
-	va_end(args);
-
-	puts(printf_buf);
-
-	return printed;
-}
-- 
2.40.0.rc0.216.gc4246ad0f0-goog




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux