| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "platform/utils.h" | 6 #include "platform/utils.h" |
| 7 #include "vm/atomic.h" | 7 #include "vm/atomic.h" |
| 8 #include "vm/globals.h" | 8 #include "vm/globals.h" |
| 9 #include "vm/unit_test.h" | 9 #include "vm/unit_test.h" |
| 10 | 10 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 UNIT_TEST_CASE(FetchAndIncrement) { | 13 UNIT_TEST_CASE(FetchAndIncrement) { |
| 14 uintptr_t v = 42; | 14 uintptr_t v = 42; |
| 15 EXPECT_EQ(static_cast<uintptr_t>(42), | 15 EXPECT_EQ(static_cast<uintptr_t>(42), |
| 16 AtomicOperations::FetchAndIncrement(&v)); | 16 AtomicOperations::FetchAndIncrement(&v)); |
| 17 EXPECT_EQ(static_cast<uintptr_t>(43), v); | 17 EXPECT_EQ(static_cast<uintptr_t>(43), v); |
| 18 } | 18 } |
| 19 | 19 |
| 20 | 20 |
| 21 UNIT_TEST_CASE(FetchAndDecrement) { | 21 UNIT_TEST_CASE(FetchAndDecrement) { |
| 22 uintptr_t v = 42; | 22 uintptr_t v = 42; |
| 23 EXPECT_EQ(static_cast<uintptr_t>(42), | 23 EXPECT_EQ(static_cast<uintptr_t>(42), |
| 24 AtomicOperations::FetchAndDecrement(&v)); | 24 AtomicOperations::FetchAndDecrement(&v)); |
| 25 EXPECT_EQ(static_cast<uintptr_t>(41), v); | 25 EXPECT_EQ(static_cast<uintptr_t>(41), v); |
| 26 } | 26 } |
| 27 | 27 |
| 28 | 28 |
| 29 UNIT_TEST_CASE(FetchAndIncrementBy) { |
| 30 intptr_t v = 42; |
| 31 EXPECT_EQ(static_cast<uintptr_t>(42), |
| 32 AtomicOperations::FetchAndIncrementBy(&v, 100)); |
| 33 EXPECT_EQ(static_cast<intptr_t>(142), v); |
| 34 } |
| 35 |
| 36 |
| 37 UNIT_TEST_CASE(FetchAndDecrementBy) { |
| 38 intptr_t v = 42; |
| 39 EXPECT_EQ(static_cast<uintptr_t>(42), |
| 40 AtomicOperations::FetchAndDecrementBy(&v, 41)); |
| 41 EXPECT_EQ(static_cast<intptr_t>(1), v); |
| 42 } |
| 43 |
| 44 |
| 29 UNIT_TEST_CASE(LoadRelaxed) { | 45 UNIT_TEST_CASE(LoadRelaxed) { |
| 30 uword v = 42; | 46 uword v = 42; |
| 31 EXPECT_EQ(static_cast<uword>(42), AtomicOperations::LoadRelaxed(&v)); | 47 EXPECT_EQ(static_cast<uword>(42), AtomicOperations::LoadRelaxed(&v)); |
| 32 } | 48 } |
| 33 | 49 |
| 34 | 50 |
| 35 TEST_CASE(CompareAndSwapWord) { | 51 TEST_CASE(CompareAndSwapWord) { |
| 36 uword old_value = 42; | 52 uword old_value = 42; |
| 37 uword new_value = 100; | 53 uword new_value = 100; |
| 38 uword result = AtomicOperations::CompareAndSwapWord( | 54 uword result = AtomicOperations::CompareAndSwapWord( |
| 39 &old_value, old_value, new_value); | 55 &old_value, old_value, new_value); |
| 40 EXPECT_EQ(static_cast<uword>(42), result); | 56 EXPECT_EQ(static_cast<uword>(42), result); |
| 41 } | 57 } |
| 42 | 58 |
| 43 | 59 |
| 44 TEST_CASE(CompareAndSwapUint32) { | 60 TEST_CASE(CompareAndSwapUint32) { |
| 45 uint32_t old_value = 42; | 61 uint32_t old_value = 42; |
| 46 uint32_t new_value = 100; | 62 uint32_t new_value = 100; |
| 47 uint32_t result = AtomicOperations::CompareAndSwapUint32( | 63 uint32_t result = AtomicOperations::CompareAndSwapUint32( |
| 48 &old_value, old_value, new_value); | 64 &old_value, old_value, new_value); |
| 49 EXPECT_EQ(static_cast<uint32_t>(42), result); | 65 EXPECT_EQ(static_cast<uint32_t>(42), result); |
| 50 } | 66 } |
| 51 | 67 |
| 52 } // namespace dart | 68 } // namespace dart |
| OLD | NEW |