diff --git a/catch/unit/event/Unit_hipEvent.cc b/catch/unit/event/Unit_hipEvent.cc index ceeaa54db7..d0b2fd0a1e 100644 --- a/catch/unit/event/Unit_hipEvent.cc +++ b/catch/unit/event/Unit_hipEvent.cc @@ -114,7 +114,8 @@ void test(unsigned testMask, int* C_d, int* C_h, int64_t numElements, hipStream_ if (e == hipSuccess) assert(t == 0.0f); // stop usually ready unless we skipped the synchronization (syncNone) - HIP_ASSERT(hipEventElapsedTime(&t, stop, stop) == expectedStopError); + e = hipEventElapsedTime(&t, stop, stop); + HIP_ASSERT(e == expectedStopError); if (e == hipSuccess) assert(t == 0.0f); e = hipEventElapsedTime(&t, start, stop); diff --git a/catch/unit/event/Unit_hipEventElapsedTime.cc b/catch/unit/event/Unit_hipEventElapsedTime.cc index e2fd695fa9..a3ebad3e88 100644 --- a/catch/unit/event/Unit_hipEventElapsedTime.cc +++ b/catch/unit/event/Unit_hipEventElapsedTime.cc @@ -19,8 +19,19 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/* +Testcase Scenarios : +Unit_hipEventElapsedTime_NullCheck - Test unsuccessful hipEventElapsedTime when either event passed as nullptr +Unit_hipEventElapsedTime_DisableTiming - Test unsuccessful hipEventElapsedTime when events are created with hipEventDisableTiming flag +Unit_hipEventElapsedTime_DifferentDevices - Test unsuccessful hipEventElapsedTime when events are recorded on different devices +Unit_hipEventElapsedTime_NotReady_Negative - Test unsuccessful hipEventElapsedTime when an event has not been completed +Unit_hipEventElapsedTime - Test time elapsed between two recorded events with hipEventElapsedTime api +*/ #include + +#include + #include TEST_CASE("Unit_hipEventElapsedTime_NullCheck") { @@ -51,9 +62,7 @@ TEST_CASE("Unit_hipEventElapsedTime_DifferentDevices") { // create event on dev=0 HIP_CHECK(hipSetDevice(0)); hipEvent_t start; - hipEvent_t start1; HIP_CHECK(hipEventCreate(&start)); - HIP_CHECK(hipEventCreate(&start1)); HIP_CHECK(hipEventRecord(start, nullptr)); HIP_CHECK(hipEventSynchronize(start)); @@ -63,9 +72,6 @@ TEST_CASE("Unit_hipEventElapsedTime_DifferentDevices") { hipEvent_t stop; HIP_CHECK(hipEventCreate(&stop)); - // start1 on device 0 but null stream on device 1 - HIP_ASSERT(hipEventRecord(start1, nullptr) == hipErrorInvalidHandle); - HIP_CHECK(hipEventRecord(stop, nullptr)); HIP_CHECK(hipEventSynchronize(stop)); @@ -74,11 +80,37 @@ TEST_CASE("Unit_hipEventElapsedTime_DifferentDevices") { HIP_ASSERT(hipEventElapsedTime(&tElapsed,start,stop) == hipErrorInvalidHandle); HIP_CHECK(hipEventDestroy(start)); - HIP_CHECK(hipEventDestroy(start1)); HIP_CHECK(hipEventDestroy(stop)); } } + +#if HT_AMD /* Disabled because frequency based wait is timing out on nvidia platforms */ +TEST_CASE("Unit_hipEventElapsedTime_NotReady_Negative") { + hipEvent_t start; + HIP_CHECK(hipEventCreate(&start)); + + hipEvent_t stop; + HIP_CHECK(hipEventCreate(&stop)); + + // Record start event + HIP_CHECK(hipEventRecord(start, nullptr)); + + HipTest::runKernelForDuration(std::chrono::milliseconds(1000)); + + // Record stop event + HIP_CHECK(hipEventRecord(stop, nullptr)); + + // stop event has not been completed + float tElapsed = 1.0f; + HIP_CHECK_ERROR(hipEventQuery(stop), hipErrorNotReady); + HIP_ASSERT(hipEventElapsedTime(&tElapsed,start,stop) == hipErrorNotReady); + + HIP_CHECK(hipEventDestroy(start)); + HIP_CHECK(hipEventDestroy(stop)); +} +#endif // HT_AMD + TEST_CASE("Unit_hipEventElapsedTime") { hipEvent_t start; HIP_CHECK(hipEventCreate(&start)); diff --git a/catch/unit/event/Unit_hipEventRecord.cc b/catch/unit/event/Unit_hipEventRecord.cc index 41c793d23e..7bf5462637 100644 --- a/catch/unit/event/Unit_hipEventRecord.cc +++ b/catch/unit/event/Unit_hipEventRecord.cc @@ -19,8 +19,12 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - -// Test hipEventRecord serialization behavior. +/* +Testcase Scenarios : +Unit_hipEventRecord- Test hipEventRecord serialization behavior +Unit_hipEventRecord_Negative - Test unsuccessful hipEventRecord when event is passed as nullptr + - Test unsuccessful hipEventRecord when event is created/recorded on different devices +*/ #include @@ -117,4 +121,21 @@ TEST_CASE("Unit_hipEventRecord_Negative") { SECTION("Nullptr event") { HIP_CHECK_ERROR(hipEventRecord(nullptr, nullptr), hipErrorInvalidResourceHandle); } + + SECTION("Different devices") { + int devCount = 0; + HIP_CHECK(hipGetDeviceCount(&devCount)); + if (devCount > 1) { + // create event on dev=0 + HIP_CHECK(hipSetDevice(0)); + hipEvent_t start; + HIP_CHECK(hipEventCreate(&start)); + + // start on device 0 but null stream on device 1 + HIP_CHECK(hipSetDevice(1)); + HIP_CHECK_ERROR(hipEventRecord(start, nullptr), hipErrorInvalidHandle) + + HIP_CHECK(hipEventDestroy(start)); + } + } } \ No newline at end of file