changeset 21299:5be9ee567034

lib-test: Change test_fatal_func_t to take unsigned int stage as parameter. It could never be -1, so this makes it clearer. It also removes annoying casts when comparing stage to e.g. N_ELEMENTS().
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 12 Dec 2016 15:21:13 +0200
parents e99464c82e52
children 3f4770a7b27c
files src/lib-test/test-common.c src/lib-test/test-common.h src/lib/test-array.c src/lib/test-data-stack.c src/lib/test-lib.c src/lib/test-lib.h src/lib/test-mempool-alloconly.c src/lib/test-printf-format-fix.c
diffstat 8 files changed, 15 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-test/test-common.c	Mon Dec 12 15:17:23 2016 +0200
+++ b/src/lib-test/test-common.c	Mon Dec 12 15:21:13 2016 +0200
@@ -258,7 +258,7 @@
 
 static void run_one_fatal(test_fatal_func_t *fatal_function)
 {
-	static int index = 0;
+	static unsigned int index = 0;
 	for (;;) {
 		volatile int jumped = setjmp(fatal_jmpbuf);
 		if (jumped == 0) {
--- a/src/lib-test/test-common.h	Mon Dec 12 15:17:23 2016 +0200
+++ b/src/lib-test/test-common.h	Mon Dec 12 15:21:13 2016 +0200
@@ -72,7 +72,7 @@
    is increased by 1. The idea is that each stage would be running an
    individual test that is supposed to crash. The function is called until
    FATAL_TEST_FINISHED or FATAL_TEST_ABORT is returned. */
-typedef enum fatal_test_state test_fatal_func_t(int stage);
+typedef enum fatal_test_state test_fatal_func_t(unsigned int stage);
 
 struct named_fatal {
 	const char *name;
@@ -83,7 +83,7 @@
 int test_run_named_with_fatals(const char *match, struct named_test tests[],
 			       struct named_fatal fatals[]);
 
-#define FATAL_DECL(x) enum fatal_test_state x(int);
+#define FATAL_DECL(x) enum fatal_test_state x(unsigned int);
 #define FATAL_NAMELESS(x) x, /* Were you to want to use the X trick but not name the tests */
 #define FATAL_NAMED(x) { .name = #x , .func = x },
 
--- a/src/lib/test-array.c	Mon Dec 12 15:17:23 2016 +0200
+++ b/src/lib/test-array.c	Mon Dec 12 15:21:13 2016 +0200
@@ -238,7 +238,7 @@
 	test_array_swap();
 }
 
-enum fatal_test_state fatal_array(int stage)
+enum fatal_test_state fatal_array(unsigned int stage)
 {
 	double tmpd[2] = { 42., -42. };
 	short tmps[8] = {1,2,3,4,5,6,7,8};
@@ -276,7 +276,7 @@
 	test_end();
 	/* Forces the compiler to check the value of useless_ptr, so that it
 	   must call array_idx (which is marked as pure, and gcc was desperate
-	   to optimise out. Of course, gcc is unaware stage is never -1.*/
-	return (useless_ptr != NULL && stage == -1)
+	   to optimise out. Of course, gcc is unaware stage is never UINT_MAX.*/
+	return (useless_ptr != NULL && stage == UINT_MAX)
 		? FATAL_TEST_FAILURE : FATAL_TEST_FINISHED;
 }
--- a/src/lib/test-data-stack.c	Mon Dec 12 15:17:23 2016 +0200
+++ b/src/lib/test-data-stack.c	Mon Dec 12 15:21:13 2016 +0200
@@ -145,7 +145,7 @@
 	test_ds_recursive(20, 80);
 }
 
-enum fatal_test_state fatal_data_stack(int stage)
+enum fatal_test_state fatal_data_stack(unsigned int stage)
 {
 #ifdef DEBUG
 	/* If we abort, then we'll be left with a dangling t_push()
--- a/src/lib/test-lib.c	Mon Dec 12 15:17:23 2016 +0200
+++ b/src/lib/test-lib.c	Mon Dec 12 15:21:13 2016 +0200
@@ -63,7 +63,7 @@
 		test_wildcard_match,
 		NULL
 	};
-	static enum fatal_test_state (*fatal_functions[])(int) = {
+	static enum fatal_test_state (*fatal_functions[])(unsigned int) = {
 		fatal_array,
 		fatal_data_stack,
 		fatal_mempool,
--- a/src/lib/test-lib.h	Mon Dec 12 15:17:23 2016 +0200
+++ b/src/lib/test-lib.h	Mon Dec 12 15:21:13 2016 +0200
@@ -6,7 +6,7 @@
 
 void test_aqueue(void);
 void test_array(void);
-enum fatal_test_state fatal_array(int);
+enum fatal_test_state fatal_array(unsigned int);
 void test_base32(void);
 void test_base64(void);
 void test_bits(void);
@@ -14,7 +14,7 @@
 void test_buffer(void);
 void test_crc32(void);
 void test_data_stack(void);
-enum fatal_test_state fatal_data_stack(int);
+enum fatal_test_state fatal_data_stack(unsigned int);
 void test_failures(void);
 void test_guid(void);
 void test_hash(void);
@@ -39,7 +39,7 @@
 void test_llist(void);
 void test_log_throttle(void);
 void test_mempool_alloconly(void);
-enum fatal_test_state fatal_mempool(int);
+enum fatal_test_state fatal_mempool(unsigned int);
 void test_pkcs5_pbkdf2(void);
 void test_net(void);
 void test_numpack(void);
@@ -48,7 +48,7 @@
 void test_ostream_file(void);
 void test_primes(void);
 void test_printf_format_fix(void);
-enum fatal_test_state fatal_printf_format_fix(int);
+enum fatal_test_state fatal_printf_format_fix(unsigned int);
 void test_priorityq(void);
 void test_seq_range_array(void);
 void test_str(void);
--- a/src/lib/test-mempool-alloconly.c	Mon Dec 12 15:17:23 2016 +0200
+++ b/src/lib/test-mempool-alloconly.c	Mon Dec 12 15:21:13 2016 +0200
@@ -53,7 +53,7 @@
 	test_end();
 }
 
-enum fatal_test_state fatal_mempool(int stage)
+enum fatal_test_state fatal_mempool(unsigned int stage)
 {
 	static pool_t pool;
 
--- a/src/lib/test-printf-format-fix.c	Mon Dec 12 15:17:23 2016 +0200
+++ b/src/lib/test-printf-format-fix.c	Mon Dec 12 15:21:13 2016 +0200
@@ -95,7 +95,7 @@
 }
 
 /* Want to test the panics too? go for it! */
-enum fatal_test_state fatal_printf_format_fix(int stage)
+enum fatal_test_state fatal_printf_format_fix(unsigned int stage)
 {
 	static const char *fatals[] = {
 		"no no no %n's",
@@ -104,7 +104,7 @@
 		"definitely can't have a tailing %",
 	};
 
-	if((unsigned int)stage >= N_ELEMENTS(fatals)) {
+	if(stage >= N_ELEMENTS(fatals)) {
 		test_end();
 		return FATAL_TEST_FINISHED;
 	}