MCPcopy Create free account
hub / github.com/apache/impala / TestBasic

Function TestBasic

be/src/common/atomic-test.cc:33–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31// intended to test the thread safety.
32template<typename T>
33static void TestBasic() {
34 AtomicInt<T> i1;
35 EXPECT_EQ(i1.Load(), 0);
36 i1.Store(10);
37 EXPECT_EQ(i1.Load(), 10);
38 i1.Add(5);
39 EXPECT_EQ(i1.Load(), 15);
40 i1.Add(-25);
41 EXPECT_EQ(i1.Load(), -10);
42 i1.Store(100);
43 EXPECT_EQ(i1.Load(), 100);
44
45 bool success = i1.CompareAndSwap(100, 50);
46 EXPECT_EQ(i1.Load(), 50);
47 EXPECT_EQ(success, true);
48 success = i1.CompareAndSwap(50, 100);
49 EXPECT_EQ(i1.Load(), 100);
50 EXPECT_EQ(success, true);
51
52 success = i1.CompareAndSwap(-200, 50);
53 EXPECT_EQ(i1.Load(), 100);
54 EXPECT_EQ(success, false);
55 success = i1.CompareAndSwap(50, 200);
56 EXPECT_EQ(i1.Load(), 100);
57 EXPECT_EQ(success, false);
58}
59
60TEST(AtomicTest, Basic) {
61 TestBasic<int32_t>();

Callers

nothing calls this directly

Calls 4

LoadMethod · 0.45
StoreMethod · 0.45
AddMethod · 0.45
CompareAndSwapMethod · 0.45

Tested by

no test coverage detected