1 // Copyright 2017 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "absl/base/config.h"
16
17 #include <cstdint>
18
19 #include "gtest/gtest.h"
20 #include "absl/synchronization/internal/thread_pool.h"
21
22 namespace {
23
TEST(ConfigTest,Endianness)24 TEST(ConfigTest, Endianness) {
25 union {
26 uint32_t value;
27 uint8_t data[sizeof(uint32_t)];
28 } number;
29 number.data[0] = 0x00;
30 number.data[1] = 0x01;
31 number.data[2] = 0x02;
32 number.data[3] = 0x03;
33 #if defined(ABSL_IS_LITTLE_ENDIAN) && defined(ABSL_IS_BIG_ENDIAN)
34 #error Both ABSL_IS_LITTLE_ENDIAN and ABSL_IS_BIG_ENDIAN are defined
35 #elif defined(ABSL_IS_LITTLE_ENDIAN)
36 EXPECT_EQ(UINT32_C(0x03020100), number.value);
37 #elif defined(ABSL_IS_BIG_ENDIAN)
38 EXPECT_EQ(UINT32_C(0x00010203), number.value);
39 #else
40 #error Unknown endianness
41 #endif
42 }
43
44 #if defined(ABSL_HAVE_THREAD_LOCAL)
TEST(ConfigTest,ThreadLocal)45 TEST(ConfigTest, ThreadLocal) {
46 static thread_local int mine_mine_mine = 16;
47 EXPECT_EQ(16, mine_mine_mine);
48 {
49 absl::synchronization_internal::ThreadPool pool(1);
50 pool.Schedule([&] {
51 EXPECT_EQ(16, mine_mine_mine);
52 mine_mine_mine = 32;
53 EXPECT_EQ(32, mine_mine_mine);
54 });
55 }
56 EXPECT_EQ(16, mine_mine_mine);
57 }
58 #endif
59
60 } // namespace
61