Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hexagon] Add support for on-device unit testing using gtest #11145

Merged
merged 20 commits into from
May 3, 2022

Conversation

adstraw
Copy link
Contributor

@adstraw adstraw commented Apr 27, 2022

Adds Hexagon on-device unit testing support by linking the tvm runtime with gtest. Also moves HexagonBuffer unit tests from their original home as part of the cpptest executable to their new home as a Hexagon on-device unit test. This is a Hexagon specific and proof-of-concept implementation for this discussion topic.

cc @mehrdadh

@mehrdadh
Copy link
Member

mehrdadh commented Apr 28, 2022

Is there a reason that you put test files under src/runtime/hexagon/tests/ instead of tests/cpp/...?

@adstraw adstraw force-pushed the straw-link-gtest-to-tvm-runtime branch from edb2fc9 to 39c2275 Compare April 28, 2022 18:04
CMakeLists.txt Show resolved Hide resolved

// initialize gtest with arguments and run
::testing::InitGoogleTest(&argc, argv.data());
*rv = RUN_ALL_TESTS();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it looks like stdout redirection is one of the disabled features in the Hexagon SDK gtest version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How so? in that case can we target a generic gtest and then modify to support for Hexagon as we have discussed potentially doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that one must set GTEST_HAS_STREAM_REDIRECTION=0 when compiling gtest for Hexagon which disables the CaptureStdout function. I believe this would be true even if we used a "stock" gtest version as opposed to the gtest version in the Hexagon SDK.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Darn. @kparzysz-quic any idea why this is disabled for Hexagon? Is there an alternative for us to capture stdout on Hexagon?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. What happens if we set GTEST_HAS_STREAM_REDIRECTION=1?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GTest stream redirection relies on dup2(), which does not exist under QuRT.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adstraw
Copy link
Contributor Author

adstraw commented Apr 29, 2022

Is there a reason that you put test files under src/runtime/hexagon/tests/ instead of tests/cpp/...?

Short answer: We need a separate directory from which to include runtime tests.

Long answer ...

All files in tests/cpp/... are recursively globbed and added to the cpptest executable. This forces all code tested by cpptest to have an x86 implementation. For runtime code, it may or may not be possible to have an x86 implementation.

The HexagonBuffer class, for example, was able to have both a Hexagon (VTMC allocation via the SDK) and x86 (malloc) implementation and hence was testable using cpptest on x86. However, this added some complication to the build system which is removed in this PR along with the x86 implementation for HexagonBuffer. HexagonBuffer is now implemented and tested on Hexagon.

Other Hexagon classes e.g. for thread management coming soon to TVM will not be so easily implemented on x86 which is part of the motivation for this PR.

@csullivan
Copy link
Contributor

I think @areusch may argue this is a reasonable example of why we should have test files co-located with source implementations. That said, for now we could consider changing the cpptest globbing to exclude the runtime subdirectory with the assumption that runtime specific tests will need to be globbed by a tvm_runtime compatible gtest impl.

@adstraw adstraw marked this pull request as ready for review May 2, 2022 15:43
@adstraw
Copy link
Contributor Author

adstraw commented May 2, 2022

@kparzysz-quic please review

@adstraw
Copy link
Contributor Author

adstraw commented May 2, 2022

for now we could consider changing the cpptest globbing to exclude the runtime subdirectory with the assumption that runtime specific tests will need to be globbed by a tvm_runtime compatible gtest impl.

I don't mind the current src/runtime/hexagon/tests file location for Hexagon tests but I am also open to changing it based on feedback from @areusch @mehrdadh @csullivan. Let me know what you think.

@areusch
Copy link
Contributor

areusch commented May 2, 2022

@adstraw until such a future time as we colocate all the tests with the source files, i think it'd be great to keep them underneath tests/ so we don't vary too much impl-to-impl. i'm okay with creating further directories underneath tests/cpptest as needed for this.

@github-actions github-actions bot requested a review from mehrdadh May 2, 2022 23:22
@adstraw
Copy link
Contributor Author

adstraw commented May 2, 2022

Given that cpptest recursively globs all files under tests/cpp I decided to make a new folder named tests/cpp-runtime with subdirectory for Hexagon. I am hoping this will satisfy the concerns about test location.

@csullivan csullivan merged commit 0fb155c into apache:main May 3, 2022
Comment on lines +119 to +128
if(BUILD_FOR_HEXAGON OR USE_HEXAGON_RPC)
# Common sources for TVM runtime with Hexagon support
file_glob_append(RUNTIME_HEXAGON_SRCS
"${TVMRT_SOURCE_DIR}/hexagon/*.cc"
)
else()
file_glob_append(RUNTIME_HEXAGON_SRCS
"${TVMRT_SOURCE_DIR}/hexagon/hexagon_module.cc"
)
endif()
Copy link
Contributor

@kparzysz-quic kparzysz-quic May 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part disables Hexagon runtime when building for x86. Please revert this.

Nevermind. It was an error on my side. Sorry for the noise.

@adstraw adstraw deleted the straw-link-gtest-to-tvm-runtime branch May 10, 2022 15:42
shtinsa pushed a commit to Deelvin/tvm that referenced this pull request May 17, 2022
…11145)

* link gtest to tvm runtime

* first test running!

* HexagonBuffer tests running in sim

* move to new tests directory

* use USE_HEXAGON_SDK

* add python frontend for Hexagon unit tests

* clean up after rebase

* isolate cmake changes to Hexagon

* add gtest init with arguments

* add hexagon sources only if building for Hexagon; remove workaround

* format & lint

* fix Hexagon build error

* remove x86 implementation and win32 code

* check if hexagon gtest path exists before linking

* make USE_HEXAGON_GTEST an optional cmake param

* turn on Hexagon gtest in Hexagon CI

* Hexagon unit tests should fail if run without proper gtest linkage

* add tvm option; move Hexagon tests to test/cpp-runtime/hexagon

* add libinfo

* trigger ci
SebastianBoblest pushed a commit to SebastianBoblest/tvm that referenced this pull request May 27, 2022
…11145)

* link gtest to tvm runtime

* first test running!

* HexagonBuffer tests running in sim

* move to new tests directory

* use USE_HEXAGON_SDK

* add python frontend for Hexagon unit tests

* clean up after rebase

* isolate cmake changes to Hexagon

* add gtest init with arguments

* add hexagon sources only if building for Hexagon; remove workaround

* format & lint

* fix Hexagon build error

* remove x86 implementation and win32 code

* check if hexagon gtest path exists before linking

* make USE_HEXAGON_GTEST an optional cmake param

* turn on Hexagon gtest in Hexagon CI

* Hexagon unit tests should fail if run without proper gtest linkage

* add tvm option; move Hexagon tests to test/cpp-runtime/hexagon

* add libinfo

* trigger ci
juda pushed a commit to juda/tvm that referenced this pull request Jun 21, 2022
…11145)

* link gtest to tvm runtime

* first test running!

* HexagonBuffer tests running in sim

* move to new tests directory

* use USE_HEXAGON_SDK

* add python frontend for Hexagon unit tests

* clean up after rebase

* isolate cmake changes to Hexagon

* add gtest init with arguments

* add hexagon sources only if building for Hexagon; remove workaround

* format & lint

* fix Hexagon build error

* remove x86 implementation and win32 code

* check if hexagon gtest path exists before linking

* make USE_HEXAGON_GTEST an optional cmake param

* turn on Hexagon gtest in Hexagon CI

* Hexagon unit tests should fail if run without proper gtest linkage

* add tvm option; move Hexagon tests to test/cpp-runtime/hexagon

* add libinfo

* trigger ci
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants