public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH] Use SELF_CHECK in all unit tests
Date: Fri,  7 Apr 2023 15:04:08 -0600	[thread overview]
Message-ID: <20230407210408.3411936-1-tom@tromey.com> (raw)

I noticed a few unit tests are using gdb_assert.  I think this was an
older style, before SELF_CHECK was added.  This patch switches them
over.
---
 gdb/unittests/filtered_iterator-selftests.c | 20 +++----
 gdb/unittests/intrusive_list-selftests.c    | 60 ++++++++++-----------
 2 files changed, 40 insertions(+), 40 deletions(-)

diff --git a/gdb/unittests/filtered_iterator-selftests.c b/gdb/unittests/filtered_iterator-selftests.c
index 6e93a09627a..2558bb4291b 100644
--- a/gdb/unittests/filtered_iterator-selftests.c
+++ b/gdb/unittests/filtered_iterator-selftests.c
@@ -59,7 +59,7 @@ struct int_array_iterator
     /* If they are both not past-the-end, make sure they iterate on the
        same array (we shouldn't compare iterators that iterate on different
        things).  */
-    gdb_assert (m_array == other.m_array);
+    SELF_CHECK (m_array == other.m_array);
 
     /* They are equal if they have the same current index.  */
     return m_cur_idx == other.m_cur_idx;
@@ -73,7 +73,7 @@ struct int_array_iterator
   void operator++ ()
   {
     /* Make sure nothing tries to increment a past the end iterator. */
-    gdb_assert (m_cur_idx < m_size);
+    SELF_CHECK (m_cur_idx < m_size);
 
     m_cur_idx++;
 
@@ -85,7 +85,7 @@ struct int_array_iterator
   int operator* () const
   {
     /* Make sure nothing tries to dereference a past the end iterator.  */
-    gdb_assert (m_cur_idx < m_size);
+    SELF_CHECK (m_cur_idx < m_size);
 
     return m_array[m_cur_idx];
   }
@@ -123,7 +123,7 @@ test_filtered_iterator ()
   for (; iter != end; ++iter)
     even_ints.push_back (*iter);
 
-  gdb_assert (even_ints == expected_even_ints);
+  SELF_CHECK (even_ints == expected_even_ints);
 }
 
 /* Test operator== and operator!=. */
@@ -139,18 +139,18 @@ test_filtered_iterator_eq ()
     iter2(array, ARRAY_SIZE (array));
 
   /* They start equal.  */
-  gdb_assert (iter1 == iter2);
-  gdb_assert (!(iter1 != iter2));
+  SELF_CHECK (iter1 == iter2);
+  SELF_CHECK (!(iter1 != iter2));
 
   /* Advance 1, now they aren't equal (despite pointing to equal values).  */
   ++iter1;
-  gdb_assert (!(iter1 == iter2));
-  gdb_assert (iter1 != iter2);
+  SELF_CHECK (!(iter1 == iter2));
+  SELF_CHECK (iter1 != iter2);
 
   /* Advance 2, now they are equal again.  */
   ++iter2;
-  gdb_assert (iter1 == iter2);
-  gdb_assert (!(iter1 != iter2));
+  SELF_CHECK (iter1 == iter2);
+  SELF_CHECK (!(iter1 != iter2));
 }
 
 } /* namespace selftests */
diff --git a/gdb/unittests/intrusive_list-selftests.c b/gdb/unittests/intrusive_list-selftests.c
index fe47177d51f..1f85b326683 100644
--- a/gdb/unittests/intrusive_list-selftests.c
+++ b/gdb/unittests/intrusive_list-selftests.c
@@ -87,13 +87,13 @@ struct intrusive_list_test
       {
 	const item_type &item = *it;
 
-	gdb_assert (i < expected.size ());
-	gdb_assert (&item == expected[i]);
+	SELF_CHECK (i < expected.size ());
+	SELF_CHECK (&item == expected[i]);
 
 	++i;
       }
 
-    gdb_assert (i == expected.size ());
+    SELF_CHECK (i == expected.size ());
 
     for (typename ListType::reverse_iterator it = list.rbegin ();
 	 it != list.rend ();
@@ -103,11 +103,11 @@ struct intrusive_list_test
 
 	--i;
 
-	gdb_assert (i >= 0);
-	gdb_assert (&item == expected[i]);
+	SELF_CHECK (i >= 0);
+	SELF_CHECK (&item == expected[i]);
       }
 
-    gdb_assert (i == 0);
+    SELF_CHECK (i == 0);
   }
 
   static void
@@ -384,10 +384,10 @@ struct intrusive_list_test
     list.push_back (b);
     list.push_back (c);
 
-    gdb_assert (&list.front () == &a);
-    gdb_assert (&clist.front () == &a);
-    gdb_assert (&list.back () == &c);
-    gdb_assert (&clist.back () == &c);
+    SELF_CHECK (&list.front () == &a);
+    SELF_CHECK (&clist.front () == &a);
+    SELF_CHECK (&list.back () == &c);
+    SELF_CHECK (&clist.back () == &c);
   }
 
   static void
@@ -701,14 +701,14 @@ struct intrusive_list_test
 
     expected = {};
     verify_items (list, expected);
-    gdb_assert (disposer_calls == 3);
-    gdb_assert (disposer_seen.find (&a) != disposer_seen.end ());
-    gdb_assert (disposer_seen.find (&b) != disposer_seen.end ());
-    gdb_assert (disposer_seen.find (&c) != disposer_seen.end ());
+    SELF_CHECK (disposer_calls == 3);
+    SELF_CHECK (disposer_seen.find (&a) != disposer_seen.end ());
+    SELF_CHECK (disposer_seen.find (&b) != disposer_seen.end ());
+    SELF_CHECK (disposer_seen.find (&c) != disposer_seen.end ());
 
     /* Verify idempotency.  */
     list.clear_and_dispose (disposer);
-    gdb_assert (disposer_calls == 3);
+    SELF_CHECK (disposer_calls == 3);
   }
 
   static void
@@ -717,11 +717,11 @@ struct intrusive_list_test
     item_type a ("a");
     ListType list;
 
-    gdb_assert (list.empty ());
+    SELF_CHECK (list.empty ());
     list.push_back (a);
-    gdb_assert (!list.empty ());
+    SELF_CHECK (!list.empty ());
     list.erase (list.iterator_to (a));
-    gdb_assert (list.empty ());
+    SELF_CHECK (list.empty ());
   }
 
   static void
@@ -735,12 +735,12 @@ struct intrusive_list_test
     list.push_back (b);
     list.push_back (c);
 
-    gdb_assert (&*list.begin () == &a);
-    gdb_assert (&*list.cbegin () == &a);
-    gdb_assert (&*clist.begin () == &a);
-    gdb_assert (&*list.rbegin () == &c);
-    gdb_assert (&*list.crbegin () == &c);
-    gdb_assert (&*clist.rbegin () == &c);
+    SELF_CHECK (&*list.begin () == &a);
+    SELF_CHECK (&*list.cbegin () == &a);
+    SELF_CHECK (&*clist.begin () == &a);
+    SELF_CHECK (&*list.rbegin () == &c);
+    SELF_CHECK (&*list.crbegin () == &c);
+    SELF_CHECK (&*clist.rbegin () == &c);
 
     /* At least check that they compile.  */
     list.end ();
@@ -782,22 +782,22 @@ test_node_is_linked ()
     item_with_base a ("a");
     item_with_base_list list;
 
-    gdb_assert (!a.is_linked ());
+    SELF_CHECK (!a.is_linked ());
     list.push_back (a);
-    gdb_assert (a.is_linked ());
+    SELF_CHECK (a.is_linked ());
     list.pop_back ();
-    gdb_assert (!a.is_linked ());
+    SELF_CHECK (!a.is_linked ());
   }
 
   {
     item_with_member a ("a");
     item_with_member_list list;
 
-    gdb_assert (!a.node.is_linked ());
+    SELF_CHECK (!a.node.is_linked ());
     list.push_back (a);
-    gdb_assert (a.node.is_linked ());
+    SELF_CHECK (a.node.is_linked ());
     list.pop_back ();
-    gdb_assert (!a.node.is_linked ());
+    SELF_CHECK (!a.node.is_linked ());
   }
 }
 
-- 
2.39.2


             reply	other threads:[~2023-04-07 21:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-07 21:04 Tom Tromey [this message]
2023-04-11 14:09 ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230407210408.3411936-1-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).