[svn-commits] rmudgett: branch rmudgett/ao2_red_black r371661 - in /team/rmudgett/ao2_red_b...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Aug 25 00:50:57 CDT 2012


Author: rmudgett
Date: Sat Aug 25 00:50:54 2012
New Revision: 371661

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=371661
Log:
* Ultimately fail integrity check if rbtree colors are not right.

* Check the contianer integrity more often during unit tests.

Modified:
    team/rmudgett/ao2_red_black/main/astobj2.c
    team/rmudgett/ao2_red_black/tests/test_astobj2.c

Modified: team/rmudgett/ao2_red_black/main/astobj2.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/ao2_red_black/main/astobj2.c?view=diff&rev=371661&r1=371660&r2=371661
==============================================================================
--- team/rmudgett/ao2_red_black/main/astobj2.c (original)
+++ team/rmudgett/ao2_red_black/main/astobj2.c Sat Aug 25 00:50:54 2012
@@ -3632,8 +3632,6 @@
 		}
 	}
 	child->is_red = 0;
-
-	/*! \todo BUGBUG rb_delete_fixup() not written */
 }
 
 /*!
@@ -4606,10 +4604,13 @@
  */
 static int rb_ao2_integrity(struct ao2_container_rbtree *self)
 {
+	int res;
 	int count_node;
 	int count_obj;
 	void *obj_last;
 	struct rbtree_node *node;
+
+	res = 0;
 
 	count_node = 0;
 	count_obj = 0;
@@ -4634,6 +4635,7 @@
 		if (self->root->is_red) {
 			/* Violation rbtree property 2. */
 			ast_log(LOG_ERROR, "Tree root is red!\n");
+			res = -1;
 		}
 		node = self->root;
 		do {
@@ -4654,10 +4656,12 @@
 					if (node->left->is_red) {
 						/* Violation rbtree property 4. */
 						ast_log(LOG_ERROR, "Tree node is red and its left child is red!\n");
+						res = -1;
 					}
 					if (node->right->is_red) {
 						/* Violation rbtree property 4. */
 						ast_log(LOG_ERROR, "Tree node is red and its right child is red!\n");
+						res = -1;
 					}
 				} else if (node->left || node->right) {
 					/*
@@ -4665,6 +4669,7 @@
 					 * Violation rbtree property 5 if the child is black.
 					 */
 					ast_log(LOG_ERROR, "Tree node is red and it only has one child!\n");
+					res = -1;
 				}
 			} else {
 				/*
@@ -4677,11 +4682,13 @@
 						/* Violation rbtree property 5. */
 						ast_log(LOG_ERROR,
 							"Tree node is black and the left child's color doesn't match the right child!\n");
+						res = -1;
 					}
 				} else if ((node->left && !node->left->is_red)
 					|| (node->right && !node->right->is_red)) {
 					/* Violation rbtree property 5. */
 					ast_log(LOG_ERROR, "Tree node is black and its only child is black!\n");
+					res = -1;
 				}
 			}
 
@@ -4725,7 +4732,7 @@
 		return -1;
 	}
 
-	return 0;
+	return res;
 }
 #endif	/* defined(AST_DEVMODE) */
 

Modified: team/rmudgett/ao2_red_black/tests/test_astobj2.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/ao2_red_black/tests/test_astobj2.c?view=diff&rev=371661&r1=371660&r2=371661
==============================================================================
--- team/rmudgett/ao2_red_black/tests/test_astobj2.c (original)
+++ team/rmudgett/ao2_red_black/tests/test_astobj2.c Sat Aug 25 00:50:54 2012
@@ -478,26 +478,26 @@
 	}
 
 	/* Create objects and link into container */
-	destructor_count = lim;
 	for (num = 0; num < lim; ++num) {
 		if (!(obj = ao2_t_alloc(sizeof(struct test_obj), test_obj_destructor, "making zombies"))) {
 			ast_test_status_update(test, "ao2_alloc failed.\n");
 			res = AST_TEST_FAIL;
 			goto cleanup;
 		}
+		++destructor_count;
 		obj->destructor_count = &destructor_count;
 		obj->i = num;
 		ao2_link(c1, obj);
 		ao2_t_ref(obj, -1, "test");
+		if (ao2_container_check(c1, 0)) {
+			ast_test_status_update(test, "container integrity check failed linking obj num:%d\n", num);
+			res = AST_TEST_FAIL;
+			goto cleanup;
+		}
 		if (ao2_container_count(c1) != num + 1) {
 			ast_test_status_update(test, "container did not link correctly\n");
 			res = AST_TEST_FAIL;
 		}
-	}
-	if (ao2_container_check(c1, 0)) {
-		ast_test_status_update(test, "container integrity check failed\n");
-		res = AST_TEST_FAIL;
-		goto cleanup;
 	}
 
 	ast_test_status_update(test, "%s container created: buckets: %d, items: %d\n",
@@ -1164,6 +1164,11 @@
 		obj->i = vector[idx];
 		ao2_link(container, obj);
 		ao2_t_ref(obj, -1, "test");
+		if (ao2_container_check(container, 0)) {
+			ast_test_status_update(test, "%s: Container integrity check failed linking vector[%d]:%d\n",
+				prefix, idx, vector[idx]);
+			return -1;
+		}
 
 		if (ao2_container_count(container) != idx + 1) {
 			ast_test_status_update(test,
@@ -1171,10 +1176,6 @@
 				prefix, idx + 1, ao2_container_count(container));
 			return -1;
 		}
-	}
-	if (ao2_container_check(container, 0)) {
-		ast_test_status_update(test, "%s: Container integrity check failed\n", prefix);
-		return -1;
 	}
 
 	return 0;
@@ -1236,6 +1237,15 @@
 		} else {
 			ao2_t_ref(obj, -1, "test");
 		}
+
+		if (ao2_container_check(container, 0)) {
+			ast_test_status_update(test, "%s: Container integrity check failed linking num:%d dup:%d\n",
+				prefix, number, count);
+			if (obj_dup) {
+				ao2_t_ref(obj_dup, -1, "test");
+			}
+			return -1;
+		}
 	}
 
 	/* Add the duplicate object. */
@@ -1243,7 +1253,8 @@
 	ao2_t_ref(obj_dup, -1, "test");
 
 	if (ao2_container_check(container, 0)) {
-		ast_test_status_update(test, "%s: Container integrity check failed\n", prefix);
+		ast_test_status_update(test, "%s: Container integrity check failed linking obj_dup\n",
+			prefix);
 		return -1;
 	}
 




More information about the svn-commits mailing list