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 VM_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 VM_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(FetchAndIncrementSigned) { | 29 VM_UNIT_TEST_CASE(FetchAndIncrementSigned) { |
30 intptr_t v = -42; | 30 intptr_t v = -42; |
31 EXPECT_EQ(static_cast<intptr_t>(-42), | 31 EXPECT_EQ(static_cast<intptr_t>(-42), |
32 AtomicOperations::FetchAndIncrement(&v)); | 32 AtomicOperations::FetchAndIncrement(&v)); |
33 EXPECT_EQ(static_cast<intptr_t>(-41), v); | 33 EXPECT_EQ(static_cast<intptr_t>(-41), v); |
34 } | 34 } |
35 | 35 |
36 | 36 |
37 UNIT_TEST_CASE(FetchAndDecrementSigned) { | 37 VM_UNIT_TEST_CASE(FetchAndDecrementSigned) { |
38 intptr_t v = -42; | 38 intptr_t v = -42; |
39 EXPECT_EQ(static_cast<intptr_t>(-42), | 39 EXPECT_EQ(static_cast<intptr_t>(-42), |
40 AtomicOperations::FetchAndDecrement(&v)); | 40 AtomicOperations::FetchAndDecrement(&v)); |
41 EXPECT_EQ(static_cast<intptr_t>(-43), v); | 41 EXPECT_EQ(static_cast<intptr_t>(-43), v); |
42 } | 42 } |
43 | 43 |
44 | 44 |
45 UNIT_TEST_CASE(IncrementBy) { | 45 VM_UNIT_TEST_CASE(IncrementBy) { |
46 intptr_t v = 42; | 46 intptr_t v = 42; |
47 AtomicOperations::IncrementBy(&v, 100); | 47 AtomicOperations::IncrementBy(&v, 100); |
48 EXPECT_EQ(static_cast<intptr_t>(142), v); | 48 EXPECT_EQ(static_cast<intptr_t>(142), v); |
49 } | 49 } |
50 | 50 |
51 | 51 |
52 UNIT_TEST_CASE(DecrementBy) { | 52 VM_UNIT_TEST_CASE(DecrementBy) { |
53 intptr_t v = 42; | 53 intptr_t v = 42; |
54 AtomicOperations::DecrementBy(&v, 41); | 54 AtomicOperations::DecrementBy(&v, 41); |
55 EXPECT_EQ(static_cast<intptr_t>(1), v); | 55 EXPECT_EQ(static_cast<intptr_t>(1), v); |
56 } | 56 } |
57 | 57 |
58 | 58 |
59 UNIT_TEST_CASE(LoadRelaxed) { | 59 VM_UNIT_TEST_CASE(LoadRelaxed) { |
60 uword v = 42; | 60 uword v = 42; |
61 EXPECT_EQ(static_cast<uword>(42), AtomicOperations::LoadRelaxed(&v)); | 61 EXPECT_EQ(static_cast<uword>(42), AtomicOperations::LoadRelaxed(&v)); |
62 } | 62 } |
63 | 63 |
64 | 64 |
65 TEST_CASE(CompareAndSwapWord) { | 65 TEST_CASE(CompareAndSwapWord) { |
66 uword old_value = 42; | 66 uword old_value = 42; |
67 uword new_value = 100; | 67 uword new_value = 100; |
68 uword result = | 68 uword result = |
69 AtomicOperations::CompareAndSwapWord(&old_value, old_value, new_value); | 69 AtomicOperations::CompareAndSwapWord(&old_value, old_value, new_value); |
70 EXPECT_EQ(static_cast<uword>(42), result); | 70 EXPECT_EQ(static_cast<uword>(42), result); |
71 } | 71 } |
72 | 72 |
73 | 73 |
74 TEST_CASE(CompareAndSwapUint32) { | 74 TEST_CASE(CompareAndSwapUint32) { |
75 uint32_t old_value = 42; | 75 uint32_t old_value = 42; |
76 uint32_t new_value = 100; | 76 uint32_t new_value = 100; |
77 uint32_t result = | 77 uint32_t result = |
78 AtomicOperations::CompareAndSwapUint32(&old_value, old_value, new_value); | 78 AtomicOperations::CompareAndSwapUint32(&old_value, old_value, new_value); |
79 EXPECT_EQ(static_cast<uint32_t>(42), result); | 79 EXPECT_EQ(static_cast<uint32_t>(42), result); |
80 } | 80 } |
81 | 81 |
82 } // namespace dart | 82 } // namespace dart |
OLD | NEW |