[PATCH] Changed assert to ASSERT

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Katerina Barone-Adesi kat.obsc at gmail.com
Fri Mar 1 18:43:33 UTC 2013


Rationale: zecke pointed out that the tests should unconditionally
assert, regardless of debug settings.
---
 include/osmocom/core/utils.h     |   7 +++
 tests/lapd/lapd_test.c           |   8 +--
 tests/loggingrb/loggingrb_test.c |   3 +-
 tests/strrb/strrb_test.c         | 126 +++++++++++++++++++--------------------
 4 files changed, 72 insertions(+), 72 deletions(-)

diff --git a/include/osmocom/core/utils.h b/include/osmocom/core/utils.h
index 03861d7..4790386 100644
--- a/include/osmocom/core/utils.h
+++ b/include/osmocom/core/utils.h
@@ -51,6 +51,13 @@ do {								\
 	rem -= ret;						\
 } while (0)
 
+#define ASSERT(exp)    \
+	if (!(exp)) { \
+		printf("Assert failed %s %s:%d\n", #exp, __FILE__, __LINE__); \
+		abort(); \
+	}
+
+
 /*! @} */
 
 #endif
diff --git a/tests/lapd/lapd_test.c b/tests/lapd/lapd_test.c
index acd3cad..65206ed 100644
--- a/tests/lapd/lapd_test.c
+++ b/tests/lapd/lapd_test.c
@@ -21,6 +21,7 @@
 
 #include <osmocom/core/application.h>
 #include <osmocom/core/logging.h>
+#include <osmocom/core/utils.h>
 #include <osmocom/gsm/lapdm.h>
 #include <osmocom/gsm/rsl.h>
 
@@ -34,13 +35,6 @@
 		abort(); \
 	}
 
-#define ASSERT(exp)    \
-	if (!(exp)) { \
-		printf("Assert failed %s %s:%d\n", #exp, __FILE__, __LINE__); \
-		abort(); \
-	}
-
-
 static struct log_info info = {};
 
 struct lapdm_polling_state {
diff --git a/tests/loggingrb/loggingrb_test.c b/tests/loggingrb/loggingrb_test.c
index 1ab5212..7c08a7f 100644
--- a/tests/loggingrb/loggingrb_test.c
+++ b/tests/loggingrb/loggingrb_test.c
@@ -18,7 +18,6 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  */
-#include <assert.h>
 
 #include <osmocom/core/logging.h>
 #include <osmocom/core/utils.h>
@@ -77,7 +76,7 @@ int main(int argc, char **argv)
 	DEBUGP(DMM, "You should not see this\n");
 	fprintf(stderr, ringbuffer_get_nth(ringbuf_target->tgt_rbvty.rb, 0));
 	fprintf(stderr, ringbuffer_get_nth(ringbuf_target->tgt_rbvty.rb, 1));
-	assert(!ringbuffer_get_nth(ringbuf_target->tgt_rbvty.rb, 2));
+	ASSERT(!ringbuffer_get_nth(ringbuf_target->tgt_rbvty.rb, 2));
 
 	return 0;
 }
diff --git a/tests/strrb/strrb_test.c b/tests/strrb/strrb_test.c
index abe649f..6dcf8e0 100644
--- a/tests/strrb/strrb_test.c
+++ b/tests/strrb/strrb_test.c
@@ -18,12 +18,12 @@
  */
 
 #include <stdio.h>
-#include <assert.h>
 #include <string.h>
 
 #include <osmocom/core/strrb.h>
 #include <osmocom/core/talloc.h>
 #include <osmocom/core/logging.h>
+#include <osmocom/core/utils.h>
 
 struct osmo_strrb *rb0, *rb1, *rb2, *rb3, *rb4, *rb5;
 
@@ -77,98 +77,98 @@ void free_rbs(void)
 
 void test_offset_valid(void)
 {
-	assert(_osmo_strrb_is_bufindex_valid(rb1, 0));
-	assert(!_osmo_strrb_is_bufindex_valid(rb1, 1));
-	assert(!_osmo_strrb_is_bufindex_valid(rb1, 2));
+	ASSERT(_osmo_strrb_is_bufindex_valid(rb1, 0));
+	ASSERT(!_osmo_strrb_is_bufindex_valid(rb1, 1));
+	ASSERT(!_osmo_strrb_is_bufindex_valid(rb1, 2));
 
-	assert(!_osmo_strrb_is_bufindex_valid(rb3, 0));
-	assert(_osmo_strrb_is_bufindex_valid(rb3, 1));
-	assert(_osmo_strrb_is_bufindex_valid(rb3, 2));
+	ASSERT(!_osmo_strrb_is_bufindex_valid(rb3, 0));
+	ASSERT(_osmo_strrb_is_bufindex_valid(rb3, 1));
+	ASSERT(_osmo_strrb_is_bufindex_valid(rb3, 2));
 
-	assert(_osmo_strrb_is_bufindex_valid(rb4, 0));
-	assert(!_osmo_strrb_is_bufindex_valid(rb4, 1));
-	assert(_osmo_strrb_is_bufindex_valid(rb4, 2));
+	ASSERT(_osmo_strrb_is_bufindex_valid(rb4, 0));
+	ASSERT(!_osmo_strrb_is_bufindex_valid(rb4, 1));
+	ASSERT(_osmo_strrb_is_bufindex_valid(rb4, 2));
 
-	assert(_osmo_strrb_is_bufindex_valid(rb5, 0));
-	assert(_osmo_strrb_is_bufindex_valid(rb5, 1));
-	assert(!_osmo_strrb_is_bufindex_valid(rb5, 2));
+	ASSERT(_osmo_strrb_is_bufindex_valid(rb5, 0));
+	ASSERT(_osmo_strrb_is_bufindex_valid(rb5, 1));
+	ASSERT(!_osmo_strrb_is_bufindex_valid(rb5, 2));
 }
 
 void test_elems(void)
 {
-	assert(osmo_strrb_elements(rb0) == 0);
-	assert(osmo_strrb_elements(rb1) == 1);
-	assert(osmo_strrb_elements(rb2) == 2);
-	assert(osmo_strrb_elements(rb3) == 2);
+	ASSERT(osmo_strrb_elements(rb0) == 0);
+	ASSERT(osmo_strrb_elements(rb1) == 1);
+	ASSERT(osmo_strrb_elements(rb2) == 2);
+	ASSERT(osmo_strrb_elements(rb3) == 2);
 }
 
 void test_getn(void)
 {
-	assert(!osmo_strrb_get_nth(rb0, 0));
-	assert(!strcmp(STR0, osmo_strrb_get_nth(rb2, 0)));
-	assert(!strcmp(STR1, osmo_strrb_get_nth(rb2, 1)));
-	assert(!strcmp(STR1, osmo_strrb_get_nth(rb3, 0)));
-	assert(!strcmp(STR2, osmo_strrb_get_nth(rb3, 1)));
-	assert(!osmo_strrb_get_nth(rb3, 2));
+	ASSERT(!osmo_strrb_get_nth(rb0, 0));
+	ASSERT(!strcmp(STR0, osmo_strrb_get_nth(rb2, 0)));
+	ASSERT(!strcmp(STR1, osmo_strrb_get_nth(rb2, 1)));
+	ASSERT(!strcmp(STR1, osmo_strrb_get_nth(rb3, 0)));
+	ASSERT(!strcmp(STR2, osmo_strrb_get_nth(rb3, 1)));
+	ASSERT(!osmo_strrb_get_nth(rb3, 2));
 }
 
 void test_getn_wrap(void)
 {
-	assert(!strcmp(STR2, osmo_strrb_get_nth(rb4, 0)));
-	assert(!strcmp(STR3, osmo_strrb_get_nth(rb4, 1)));
+	ASSERT(!strcmp(STR2, osmo_strrb_get_nth(rb4, 0)));
+	ASSERT(!strcmp(STR3, osmo_strrb_get_nth(rb4, 1)));
 
-	assert(!strcmp(STR3, osmo_strrb_get_nth(rb5, 0)));
-	assert(!strcmp(STR4, osmo_strrb_get_nth(rb5, 1)));
+	ASSERT(!strcmp(STR3, osmo_strrb_get_nth(rb5, 0)));
+	ASSERT(!strcmp(STR4, osmo_strrb_get_nth(rb5, 1)));
 }
 
 void test_add(void)
 {
 	struct osmo_strrb *rb = osmo_strrb_create(NULL, 4);
-	assert(rb->start == 0);
-	assert(rb->end == 0);
+	ASSERT(rb->start == 0);
+	ASSERT(rb->end == 0);
 
 	osmo_strrb_add(rb, "a");
 	osmo_strrb_add(rb, "b");
 	osmo_strrb_add(rb, "c");
-	assert(rb->start == 0);
-	assert(rb->end == 3);
-	assert(osmo_strrb_elements(rb) == 3);
+	ASSERT(rb->start == 0);
+	ASSERT(rb->end == 3);
+	ASSERT(osmo_strrb_elements(rb) == 3);
 
 	osmo_strrb_add(rb, "d");
-	assert(rb->start == 1);
-	assert(rb->end == 0);
-	assert(osmo_strrb_elements(rb) == 3);
-	assert(!strcmp("b", osmo_strrb_get_nth(rb, 0)));
-	assert(!strcmp("c", osmo_strrb_get_nth(rb, 1)));
-	assert(!strcmp("d", osmo_strrb_get_nth(rb, 2)));
+	ASSERT(rb->start == 1);
+	ASSERT(rb->end == 0);
+	ASSERT(osmo_strrb_elements(rb) == 3);
+	ASSERT(!strcmp("b", osmo_strrb_get_nth(rb, 0)));
+	ASSERT(!strcmp("c", osmo_strrb_get_nth(rb, 1)));
+	ASSERT(!strcmp("d", osmo_strrb_get_nth(rb, 2)));
 
 	osmo_strrb_add(rb, "e");
-	assert(rb->start == 2);
-	assert(rb->end == 1);
-	assert(!strcmp("c", osmo_strrb_get_nth(rb, 0)));
-	assert(!strcmp("d", osmo_strrb_get_nth(rb, 1)));
-	assert(!strcmp("e", osmo_strrb_get_nth(rb, 2)));
+	ASSERT(rb->start == 2);
+	ASSERT(rb->end == 1);
+	ASSERT(!strcmp("c", osmo_strrb_get_nth(rb, 0)));
+	ASSERT(!strcmp("d", osmo_strrb_get_nth(rb, 1)));
+	ASSERT(!strcmp("e", osmo_strrb_get_nth(rb, 2)));
 
 	osmo_strrb_add(rb, "f");
-	assert(rb->start == 3);
-	assert(rb->end == 2);
-	assert(!strcmp("d", osmo_strrb_get_nth(rb, 0)));
-	assert(!strcmp("e", osmo_strrb_get_nth(rb, 1)));
-	assert(!strcmp("f", osmo_strrb_get_nth(rb, 2)));
+	ASSERT(rb->start == 3);
+	ASSERT(rb->end == 2);
+	ASSERT(!strcmp("d", osmo_strrb_get_nth(rb, 0)));
+	ASSERT(!strcmp("e", osmo_strrb_get_nth(rb, 1)));
+	ASSERT(!strcmp("f", osmo_strrb_get_nth(rb, 2)));
 
 	osmo_strrb_add(rb, "g");
-	assert(rb->start == 0);
-	assert(rb->end == 3);
-	assert(!strcmp("e", osmo_strrb_get_nth(rb, 0)));
-	assert(!strcmp("f", osmo_strrb_get_nth(rb, 1)));
-	assert(!strcmp("g", osmo_strrb_get_nth(rb, 2)));
+	ASSERT(rb->start == 0);
+	ASSERT(rb->end == 3);
+	ASSERT(!strcmp("e", osmo_strrb_get_nth(rb, 0)));
+	ASSERT(!strcmp("f", osmo_strrb_get_nth(rb, 1)));
+	ASSERT(!strcmp("g", osmo_strrb_get_nth(rb, 2)));
 
 	osmo_strrb_add(rb, "h");
-	assert(rb->start == 1);
-	assert(rb->end == 0);
-	assert(!strcmp("f", osmo_strrb_get_nth(rb, 0)));
-	assert(!strcmp("g", osmo_strrb_get_nth(rb, 1)));
-	assert(!strcmp("h", osmo_strrb_get_nth(rb, 2)));
+	ASSERT(rb->start == 1);
+	ASSERT(rb->end == 0);
+	ASSERT(!strcmp("f", osmo_strrb_get_nth(rb, 0)));
+	ASSERT(!strcmp("g", osmo_strrb_get_nth(rb, 1)));
+	ASSERT(!strcmp("h", osmo_strrb_get_nth(rb, 2)));
 
 	talloc_free(rb);
 }
@@ -184,8 +184,8 @@ void test_long_msg(void)
 	tests1 = malloc(test_size);
 	tests2 = malloc(test_size);
 	/* Be certain allocating memory worked before continuing */
-	assert(tests1);
-	assert(tests2);
+	ASSERT(tests1);
+	ASSERT(tests2);
 
 	for (i = 0; i < RB_MAX_MESSAGE_SIZE; i += 2) {
 		tests1[i] = 'a';
@@ -201,9 +201,9 @@ void test_long_msg(void)
 	free(tests1);
 
 	rb_content = osmo_strrb_get_nth(rb, 0);
-	assert(!strncmp(tests2, rb_content, RB_MAX_MESSAGE_SIZE - 1));
-	assert(!rb_content[RB_MAX_MESSAGE_SIZE - 1]);
-	assert(strlen(rb_content) == RB_MAX_MESSAGE_SIZE - 1);
+	ASSERT(!strncmp(tests2, rb_content, RB_MAX_MESSAGE_SIZE - 1));
+	ASSERT(!rb_content[RB_MAX_MESSAGE_SIZE - 1]);
+	ASSERT(strlen(rb_content) == RB_MAX_MESSAGE_SIZE - 1);
 
 	free(tests2);
 	talloc_free(rb);
-- 
1.8.1.2





More information about the OpenBSC mailing list