adstraw commented on code in PR #12411: URL: https://github.com/apache/tvm/pull/12411#discussion_r949707780
########## tests/cpp-runtime/hexagon/hexagon_user_dma_tests.cc: ########## @@ -0,0 +1,141 @@ +/* + * 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. + */ + +#include <gtest/gtest.h> + +#include "../src/runtime/hexagon/hexagon_user_dma.h" + +using namespace tvm::runtime; +using namespace tvm::runtime::hexagon; + +class HexagonUserDMATest : public ::testing::Test { + void SetUp() override { + src = malloc(length); + dst = malloc(length); + ASSERT_NE(src, nullptr); + ASSERT_NE(dst, nullptr); + + src_char = static_cast<char*>(src); + dst_char = static_cast<char*>(dst); + for (uint32_t i = 0; i < length; ++i) { + src_char[i] = 1; + dst_char[i] = 0; + } + } + void TearDown() override { + free(src); + free(dst); + } + + public: + int ret{0}; + void* src{nullptr}; + void* dst{nullptr}; + char* src_char{nullptr}; + char* dst_char{nullptr}; + uint32_t length{0x400000}; // 4MB +}; + +TEST_F(HexagonUserDMATest, wait) { + HexagonUserDMA::Get().Wait(0); + HexagonUserDMA::Get().Wait(10); +} + +TEST_F(HexagonUserDMATest, poll) { ASSERT_EQ(HexagonUserDMA::Get().Poll(), 0); } + +TEST_F(HexagonUserDMATest, bad_copy) { + uint64_t bigaddr = 0x100000000; + void* src64 = reinterpret_cast<void*>(bigaddr); + void* dst64 = reinterpret_cast<void*>(bigaddr); + uint32_t biglength = 0x1000000; + ASSERT_NE(HexagonUserDMA::Get().Copy(dst64, src, length), DMA_SUCCESS); + ASSERT_NE(HexagonUserDMA::Get().Copy(dst, src64, length), DMA_SUCCESS); + ASSERT_NE(HexagonUserDMA::Get().Copy(dst, src, biglength), DMA_SUCCESS); +} + +TEST_F(HexagonUserDMATest, sync_dma) { + // kick off 1 DMA + ret = HexagonUserDMA::Get().Copy(dst, src, length); + ASSERT_EQ(ret, DMA_SUCCESS); + + // wait for DMA to complete + HexagonUserDMA::Get().Wait(0); + + // verify + for (uint32_t i = 0; i < length; ++i) { + ASSERT_EQ(src_char[i], dst_char[i]); + } +} + +TEST_F(HexagonUserDMATest, async_dma) { + // kick off 10x duplicate DMAs + for (uint32_t i = 0; i < 10; ++i) { + ret = HexagonUserDMA::Get().Copy(dst, src, length); + ASSERT_EQ(ret, DMA_SUCCESS); + } + + // verify at least 1 DMA in flight + // TODO: re-enable when CI runs on hardware - fails on simulator + // ASSERT_GT(HexagonUserDMA::Get().Poll(), 0); Review Comment: The more I think about it, this check for an "in flight" count greater than 0 does not really add any value. On the simulator, the "in flight" count is always 0 as if DMAs complete automatically so the test fails. On hardware, the "in flight" count should be non-zero but we have other ways to validate the polling mechanism is working correctly. I added `async_dma_poll` test case which has the correct coverage, I think. Let me know what you think @csullivan. -- 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]
