Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2673)

Unified Diff: base/atomicops_unittest.cc

Issue 1410713009: Add negative test case for CompareAndSwap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed double space Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/atomicops_unittest.cc
diff --git a/base/atomicops_unittest.cc b/base/atomicops_unittest.cc
index 3fd559747226dab196d7f0cd68fc26c4dd9b3e7d..7298609270f883cf8e4245f67fd623dd90efa8a4 100644
--- a/base/atomicops_unittest.cc
+++ b/base/atomicops_unittest.cc
@@ -89,6 +89,13 @@ static void TestCompareAndSwap() {
EXPECT_EQ(1, value);
EXPECT_EQ(0, prev);
+ // Verify that CAS will *not* change "value" if it doesn't match the
+ // expected number. CAS will always return the actual value of the
+ // variable from before any change.
+ AtomicType fail = base::subtle::NoBarrier_CompareAndSwap(&value, 0, 2);
+ EXPECT_EQ(1, value);
+ EXPECT_EQ(1, fail);
+
// Use test value that has non-zero bits in both halves, more for testing
// 64-bit implementation on 32-bit platforms.
const AtomicType k_test_val = (static_cast<uint64_t>(1) <<
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698