[PATCH 2/3] lib: fwts_framework: minor tidy up of code

Colin King colin.king at canonical.com
Fri Jun 28 00:04:10 UTC 2013


From: Colin Ian King <colin.king at canonical.com>

Re-format the code and use more white space in for statements.
Use bool types where possible.  Use size_t where necessary.

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/lib/src/fwts_framework.c | 46 ++++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
index add9eec..6727d5a 100644
--- a/src/lib/src/fwts_framework.c
+++ b/src/lib/src/fwts_framework.c
@@ -31,11 +31,11 @@
 /* Suffix ".log", ".xml", etc gets automatically appended */
 #define RESULTS_LOG	"results"
 
-#define FWTS_FLAG_RUN_ALL		\
+#define FWTS_FLAG_RUN_ALL			\
 	(FWTS_FLAG_BATCH |			\
 	 FWTS_FLAG_INTERACTIVE |		\
-	 FWTS_FLAG_BATCH_EXPERIMENTAL |	\
-	 FWTS_FLAG_INTERACTIVE_EXPERIMENTAL |\
+	 FWTS_FLAG_BATCH_EXPERIMENTAL |		\
+	 FWTS_FLAG_INTERACTIVE_EXPERIMENTAL |	\
 	 FWTS_FLAG_POWER_STATES |		\
 	 FWTS_FLAG_UTILS |			\
 	 FWTS_FLAG_UNSAFE)
@@ -113,7 +113,8 @@ static int fwts_framework_compare_priority(void *data1, void *data2)
  *    be reported to stderr because the logging engine
  *    is not set up yet.
  */
-void fwts_framework_test_add(const char *name,
+void fwts_framework_test_add(
+	const char *name,
 	fwts_framework_ops *ops,
 	const fwts_priority priority,
 	const fwts_framework_flags flags)
@@ -133,7 +134,9 @@ void fwts_framework_test_add(const char *name,
 	}
 
 	/* Total up minor tests in this test */
-	for (ops->total_tests = 0; ops->minor_tests[ops->total_tests].test_func != NULL; ops->total_tests++)
+	for (ops->total_tests = 0; 
+	     ops->minor_tests[ops->total_tests].test_func != NULL;
+	     ops->total_tests++)
 		;
 
 	new_test->name = name;
@@ -146,11 +149,8 @@ void fwts_framework_test_add(const char *name,
 
 	/* Add any options and handler, if they exists */
 	if (ops->options && ops->options_handler) {
-		int ret;
-
-		ret = fwts_args_add_options(ops->options, ops->options_handler,
-			ops->options_check);
-		if (ret == FWTS_ERROR) {
+		if (fwts_args_add_options(ops->options, ops->options_handler,
+			ops->options_check) == FWTS_ERROR) {
 			fprintf(stderr, "FATAL: Could not allocate memory "
 				"for getopt options handler.");
 			exit(EXIT_FAILURE);
@@ -178,8 +178,8 @@ static void fwts_framework_show_tests_brief(void)
 {
 	fwts_list sorted;
 	fwts_list_link *item;
-	int n = 0;
-	int width = fwts_tty_width(fileno(stderr), 80);
+	size_t n = 0;
+	size_t width = (size_t)fwts_tty_width(fileno(stderr), 80);
 
 	fwts_list_init(&sorted);
 
@@ -191,7 +191,7 @@ static void fwts_framework_show_tests_brief(void)
 
 	fwts_list_foreach(item, &sorted) {
 		fwts_framework_test *test = fwts_list_data(fwts_framework_test*, item);
-		int len = strlen(test->name) + 1;
+		size_t len = strlen(test->name) + 1;
 		if ((n + len) > width)  {
 			fprintf(stderr, "\n");
 			n = 0;
@@ -208,12 +208,12 @@ static void fwts_framework_show_tests_brief(void)
  *  fwts_framework_show_tests()
  *	dump out registered tests.
  */
-static void fwts_framework_show_tests(fwts_framework *fw, bool full)
+static void fwts_framework_show_tests(fwts_framework *fw, const bool full)
 {
 	fwts_list_link *item;
 	fwts_list sorted;
 	int i;
-	int need_nl = 0;
+	bool need_nl = false;
 	int total = 0;
 
 	typedef struct {
@@ -233,7 +233,7 @@ static void fwts_framework_show_tests(fwts_framework *fw, bool full)
 	};
 
 	/* Dump out tests registered under all categories */
-	for (i=0; categories[i].title != NULL; i++) {
+	for (i = 0; categories[i].title != NULL; i++) {
 		fwts_framework_test *test;
 
 		/* If no category flags are set, or category matches user requested
@@ -251,7 +251,7 @@ static void fwts_framework_show_tests(fwts_framework *fw, bool full)
 			if (fwts_list_len(&sorted) > 0) {
 				if (need_nl)
 					printf("\n");
-				need_nl = 1;
+				need_nl = true;
 				printf("%s%s:\n", categories[i].title,
 					categories[i].flag & FWTS_FLAG_UTILS ? "" : " tests");
 
@@ -262,7 +262,7 @@ static void fwts_framework_show_tests(fwts_framework *fw, bool full)
 						printf(" %-15.15s (%d test%s):\n",
 							test->name, test->ops->total_tests,
 							test->ops->total_tests > 1 ? "s" : "");
-						for (j=0; j<test->ops->total_tests;j++)
+						for (j = 0; j < test->ops->total_tests; j++)
 							printf("  %s\n", test->ops->minor_tests[j].name);
 						total += test->ops->total_tests;
 					}
@@ -302,7 +302,7 @@ static void fwts_framework_strtrunc(char *dest, const char *src, size_t max)
  */
 static void fwts_framework_format_results(char *buffer, int buflen, fwts_results const *results, bool include_zero_results)
 {
-	int n = 0;
+	size_t n = 0;
 
 	if (buflen)
 		*buffer = 0;
@@ -800,7 +800,7 @@ static void fwts_framework_syntax(char * const *argv)
 
 	/* Tag on copyright info */
 	printf("\n");
-	for (i=0; fwts_copyright[i]; i++)
+	for (i = 0; fwts_copyright[i]; i++)
 		printf("%s\n", fwts_copyright[i]);
 }
 
@@ -830,7 +830,7 @@ static void fwts_framework_heading_info(
 
 	fwts_log_info(fw, "Results generated by fwts: Version %s (%s).", FWTS_VERSION, FWTS_DATE);
 	fwts_log_nl(fw);
-	for (i=0; fwts_copyright[i]; i++)
+	for (i = 0; fwts_copyright[i]; i++)
 		fwts_log_info(fw, "%s", fwts_copyright[i]);
 	fwts_log_nl(fw);
 
@@ -1225,7 +1225,7 @@ int fwts_framework_args(const int argc, char **argv)
 		goto tidy_close;
 	}
 
-	for (i=1; i<argc; i++)
+	for (i = 1; i < argc; i++)
 		if (!strcmp(argv[i], "-")) {
 			fwts_framework_strdup(&fw->results_logname, "stdout");
 			fw->flags = (fw->flags &
@@ -1282,7 +1282,7 @@ int fwts_framework_args(const int argc, char **argv)
 	}
 
 	/* Collect up tests to run */
-	for (i=optind; i < argc; i++) {
+	for (i = optind; i < argc; i++) {
 		fwts_framework_test *test;
 
 		if (*argv[i] == '-')
-- 
1.8.3.1




More information about the fwts-devel mailing list