libstdc++: Improve tests for std::atomic_flag
authorJonathan Wakely <jwakely@redhat.com>
Fri, 12 Jun 2020 09:33:37 +0000 (10:33 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 12 Jun 2020 09:43:06 +0000 (10:43 +0100)
The tests for clear() and test_and_set() didn't cover all cases.

* testsuite/29_atomics/atomic_flag/clear/1.cc: Also test clear()
when the value is currently set.
* testsuite/29_atomics/atomic_flag/test_and_set/explicit.cc:
Actually check the return value.
* testsuite/29_atomics/atomic_flag/test_and_set/implicit.cc:
Likewise.

libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.cc
libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/explicit.cc
libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/implicit.cc

index 30d9075e372bed517bdaea08a00ad17d37b9fcc7..ed5d11a529233f521ffa62dec268e02c0dd705dc 100644 (file)
@@ -25,9 +25,9 @@ int main()
 {
   std::atomic_flag f = ATOMIC_FLAG_INIT;
 
-  f.clear(); // set to false
+  f.clear();                           // set to false
+  VERIFY( false == f.test_and_set() ); // return true
+  VERIFY( true == f.test_and_set() );  // return true
+  f.clear();                           // set to false
   VERIFY( false == f.test_and_set() ); // return previous false, set to true
-  VERIFY( true == f.test_and_set() ); // return true
-
-  return 0;
 }
index 5d6dbcc98a2fea61794aff8832614cdaba219575..1934854d7f7db8794935da2bfb5b9cefe17f45e9 100644 (file)
 // <http://www.gnu.org/licenses/>.
 
 #include <atomic>
+#include <testsuite_hooks.h>
 
 int main()
 {
   using namespace std;
   atomic_flag af = ATOMIC_FLAG_INIT;
 
-  if (!af.test_and_set(memory_order_acquire))
-    af.clear(memory_order_release);
-
-  return 0;
+  VERIFY( ! af.test_and_set(memory_order_acquire) );
+  VERIFY( af.test_and_set(memory_order_acquire) );
 }
index 8e1284cd29999e9b7f99043051d3e2c38c7759d7..1934854d7f7db8794935da2bfb5b9cefe17f45e9 100644 (file)
 // <http://www.gnu.org/licenses/>.
 
 #include <atomic>
+#include <testsuite_hooks.h>
 
 int main()
 {
   using namespace std;
   atomic_flag af = ATOMIC_FLAG_INIT;
 
-  if (!af.test_and_set())
-    af.clear();
-
-  return 0;
+  VERIFY( ! af.test_and_set(memory_order_acquire) );
+  VERIFY( af.test_and_set(memory_order_acquire) );
 }