ThreadIdTest.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright 2017-present Facebook, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. // Make sure we include ThreadId.h before anything else.
  17. // There is no ThreadId.cpp file, so this test is the only thing that verifies
  18. // that ThreadId.h compiles by itself when included first.
  19. #include <folly/system/ThreadId.h>
  20. #include <thread>
  21. #include <folly/portability/GTest.h>
  22. TEST(ThreadId, getCurrentID) {
  23. auto thisThreadID = folly::getCurrentThreadID();
  24. uint64_t otherThreadID;
  25. std::thread otherThread{[&] { otherThreadID = folly::getCurrentThreadID(); }};
  26. otherThread.join();
  27. EXPECT_NE(thisThreadID, otherThreadID);
  28. }
  29. TEST(ThreadId, getOSThreadID) {
  30. auto thisThreadID = folly::getOSThreadID();
  31. uint64_t otherThreadID;
  32. std::thread otherThread{[&] { otherThreadID = folly::getOSThreadID(); }};
  33. otherThread.join();
  34. EXPECT_NE(thisThreadID, otherThreadID);
  35. }