config_test.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include "absl/base/config.h"
  15. #include <cstdint>
  16. #include "gtest/gtest.h"
  17. #include "absl/synchronization/internal/thread_pool.h"
  18. namespace {
  19. TEST(ConfigTest, Endianness) {
  20. union {
  21. uint32_t value;
  22. uint8_t data[sizeof(uint32_t)];
  23. } number;
  24. number.data[0] = 0x00;
  25. number.data[1] = 0x01;
  26. number.data[2] = 0x02;
  27. number.data[3] = 0x03;
  28. #if defined(ABSL_IS_LITTLE_ENDIAN) && defined(ABSL_IS_BIG_ENDIAN)
  29. #error Both ABSL_IS_LITTLE_ENDIAN and ABSL_IS_BIG_ENDIAN are defined
  30. #elif defined(ABSL_IS_LITTLE_ENDIAN)
  31. EXPECT_EQ(UINT32_C(0x03020100), number.value);
  32. #elif defined(ABSL_IS_BIG_ENDIAN)
  33. EXPECT_EQ(UINT32_C(0x00010203), number.value);
  34. #else
  35. #error Unknown endianness
  36. #endif
  37. }
  38. #if defined(ABSL_HAVE_THREAD_LOCAL)
  39. TEST(ConfigTest, ThreadLocal) {
  40. static thread_local int mine_mine_mine = 16;
  41. EXPECT_EQ(16, mine_mine_mine);
  42. {
  43. absl::synchronization_internal::ThreadPool pool(1);
  44. pool.Schedule([&] {
  45. EXPECT_EQ(16, mine_mine_mine);
  46. mine_mine_mine = 32;
  47. EXPECT_EQ(32, mine_mine_mine);
  48. });
  49. }
  50. EXPECT_EQ(16, mine_mine_mine);
  51. }
  52. #endif
  53. } // namespace