From 2a4a827312e69b0378ecc85ed583a37c4fe52788 Mon Sep 17 00:00:00 2001
From: Anders Roxell <anders.roxell@linaro.org>
Date: Wed, 7 Mar 2018 13:36:08 +0100
Subject: [PATCH] selftests/size: rework to use printf

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
 tools/testing/selftests/size/Makefile   |  2 +-
 tools/testing/selftests/size/get_size.c | 46 ++++++++++++---------------------
 2 files changed, 17 insertions(+), 31 deletions(-)

diff --git a/tools/testing/selftests/size/Makefile b/tools/testing/selftests/size/Makefile
index 4685b3e421fc..73932e0e7cd0 100644
--- a/tools/testing/selftests/size/Makefile
+++ b/tools/testing/selftests/size/Makefile
@@ -1,4 +1,4 @@
-CFLAGS := -static -ffreestanding -nostartfiles -s
+CFLAGS := -static -ffreestanding -s
 
 TEST_GEN_PROGS := get_size
 
diff --git a/tools/testing/selftests/size/get_size.c b/tools/testing/selftests/size/get_size.c
index 1280b09266f0..d3010cefe699 100644
--- a/tools/testing/selftests/size/get_size.c
+++ b/tools/testing/selftests/size/get_size.c
@@ -26,13 +26,6 @@
 #include <stdio.h>
 #include "../kselftest.h"
 
-#define STDOUT_FILENO 1
-
-static int print(const char *s)
-{
-	return write(STDOUT_FILENO, s, __builtin_strlen(s));
-}
-
 static inline char *num_to_str(unsigned long num, char *buf, int len)
 {
 	unsigned int digit;
@@ -49,30 +42,23 @@ static inline char *num_to_str(unsigned long num, char *buf, int len)
 	return buf;
 }
 
-static int print_num(unsigned long num)
-{
-	char num_buf[30];
-
-	return print(num_to_str(num, num_buf, sizeof(num_buf)));
-}
-
 static int print_k_value(const char *s, unsigned long num, unsigned long units)
 {
 	unsigned long long temp;
 	int ccode;
 
-	print(s);
+	printf(s);
 
 	temp = num;
 	temp = (temp * units)/1024;
 	num = temp;
-	ccode = print_num(num);
-	print("\n");
+	ccode = printf("%d", num);
+	printf("\n");
 	return ccode;
 }
 
 /* this program has no main(), as startup libraries are not used */
-void _start(void)
+int main(void)
 {
 	int ccode;
 	struct sysinfo info;
@@ -80,28 +66,28 @@ void _start(void)
 	static const char *test_name = " get runtime memory use\n";
 
 	ksft_print_header();
-	print("# Testing system size.\n");
+	printf("# Testing system size.\n");
 
 	ccode = sysinfo(&info);
 	if (ccode < 0) {
-		print("not ok 1");
-		print(test_name);
-		print(" ---\n reason: \"could not get sysinfo\"\n ...\n");
-		_exit(ccode);
+		printf("not ok 1");
+		printf(test_name);
+		printf(" ---\n reason: \"could not get sysinfo\"\n ...\n");
+		return 1;
 	}
-	print("ok 1");
-	print(test_name);
+	printf("ok 1");
+	printf(test_name);
 
 	/* ignore cache complexities for now */
 	used = info.totalram - info.freeram - info.bufferram;
-	print("# System runtime memory report (units in Kilobytes):\n");
-	print(" ---\n");
+	printf("# System runtime memory report (units in Kilobytes):\n");
+	printf(" ---\n");
 	print_k_value(" Total:  ", info.totalram, info.mem_unit);
 	print_k_value(" Free:   ", info.freeram, info.mem_unit);
 	print_k_value(" Buffer: ", info.bufferram, info.mem_unit);
 	print_k_value(" In use: ", used, info.mem_unit);
-	print(" ...\n");
-	print("1..1\n");
+	printf(" ...\n");
+	printf("1..1\n");
 
-	_exit(0);
+	return 0;
 }
-- 
2.11.0

