csullivan commented on code in PR #11145:
URL: https://github.com/apache/tvm/pull/11145#discussion_r861212085


##########
CMakeLists.txt:
##########
@@ -598,6 +598,15 @@ endif()
 target_link_libraries(tvm PRIVATE ${TVM_LINKER_LIBS} 
${TVM_RUNTIME_LINKER_LIBS})
 target_link_libraries(tvm_runtime PRIVATE ${TVM_RUNTIME_LINKER_LIBS})
 
+if(BUILD_FOR_HEXAGON)
+  include(FetchContent)
+  FetchContent_Declare(googletest SOURCE_DIR 
"${USE_HEXAGON_SDK}/utils/googletest/gtest")
+  set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
+  FetchContent_MakeAvailable(googletest)
+  target_link_libraries(tvm_runtime PUBLIC gtest)

Review Comment:
   Thinking we maybe should conditionally do this if a cmake variable is set so 
that we are only linking in gtest to the tvm_runtime when we want to do testing 
in order to avoid tvm_runtime bloat. 



##########
src/runtime/hexagon/tests/run_all_tests.cc:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#if defined(__hexagon__)
+
+#include <gtest/gtest.h>
+#include <tvm/runtime/packed_func.h>
+#include <tvm/runtime/registry.h>
+
+#include <string>
+#include <vector>
+
+#include "../src/support/utils.h"
+
+namespace tvm {
+namespace runtime {
+namespace hexagon {
+
+TVM_REGISTER_GLOBAL("hexagon.run_all_tests").set_body([](TVMArgs args, 
TVMRetValue* rv) {
+  // gtest args are passed into this packed func as a singular string
+  // split gtest args using <space> delimiter and build argument vector
+  std::vector<std::string> parsed_args = tvm::support::Split(args[0], ' ');
+  std::vector<char*> argv;
+
+  // add executable name
+  argv.push_back(const_cast<char*>("hexagon_run_all_tests"));
+
+  // add parsed arguments
+  for (int i = 0; i < parsed_args.size(); ++i) {
+    argv.push_back(const_cast<char*>(parsed_args[i].data()));
+  }
+
+  // end of parsed arguments
+  argv.push_back(nullptr);
+
+  // set argument count
+  int argc = argv.size() - 1;
+
+  // initialize gtest with arguments and run
+  ::testing::InitGoogleTest(&argc, argv.data());
+  *rv = RUN_ALL_TESTS();

Review Comment:
   Neat! looks like gtest supports capturing the stdout to a string that we can 
return in the ret value across the FFI,
   ```
   testing::internal::CaptureStdout();
   // Run tests
   // ...
   std::string output = testing::internal::GetCapturedStdout();
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to