[clang-tools-extra] r317194 - Fix clangd test on platforms where get_thread_name does nothing.

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 2 02:48:55 PDT 2017


Author: sammccall
Date: Thu Nov  2 02:48:55 2017
New Revision: 317194

URL: http://llvm.org/viewvc/llvm-project?rev=317194&view=rev
Log:
Fix clangd test on platforms where get_thread_name does nothing.

Modified:
    clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp?rev=317194&r1=317193&r2=317194&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp Thu Nov  2 02:48:55 2017
@@ -12,6 +12,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/Threading.h"
 #include "llvm/Support/YAMLParser.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -88,6 +89,11 @@ TEST(TraceTest, SmokeTest) {
   auto *Root = dyn_cast_or_null<yaml::MappingNode>(Doc->getRoot());
   ASSERT_NE(Root, nullptr) << "Root should be an object";
 
+  // Check whether we expect thread name events on this platform.
+  SmallString<32> ThreadName;
+  llvm::get_thread_name(ThreadName);
+  bool ThreadsHaveNames = !ThreadName.empty();
+
   // We expect in order:
   //   displayTimeUnit: "ns"
   //   traceEvents: [process name, thread name, start span, log, end span]
@@ -103,8 +109,10 @@ TEST(TraceTest, SmokeTest) {
   auto Event = Events->begin();
   ASSERT_NE(Event, Events->end()) << "Expected process name";
   EXPECT_TRUE(VerifyObject(*Event, {{"ph", "M"}, {"name", "process_name"}}));
-  ASSERT_NE(++Event, Events->end()) << "Expected thread name";
-  EXPECT_TRUE(VerifyObject(*Event, {{"ph", "M"}, {"name", "thread_name"}}));
+  if (ThreadsHaveNames) {
+    ASSERT_NE(++Event, Events->end()) << "Expected thread name";
+    EXPECT_TRUE(VerifyObject(*Event, {{"ph", "M"}, {"name", "thread_name"}}));
+  }
   ASSERT_NE(++Event, Events->end()) << "Expected span start";
   EXPECT_TRUE(VerifyObject(*Event, {{"ph", "B"}, {"name", "A"}}));
   ASSERT_NE(++Event, Events->end()) << "Expected log message";




More information about the cfe-commits mailing list