6
6
7
7
#include " fixtures.h"
8
8
#include " uur/known_failure.h"
9
+ using namespace std ::chrono_literals;
9
10
10
11
/* Using urEventReferenceTest to be able to release the event during the test */
11
- using urEventSetCallbackTest = uur::event::urEventReferenceTest;
12
+ struct urEventSetCallbackTest : uur::event::urEventReferenceTest {
13
+ std::mutex m;
14
+ std::condition_variable cv;
15
+ int flag = 0 ;
16
+
17
+ void WaitForFlag (int Target = 1 ) {
18
+ std::unique_lock lk (m);
19
+ cv.wait_for (lk, 1000ms, [&] { return flag == Target; });
20
+ }
21
+
22
+ void SetFlag () {
23
+ flag++;
24
+ cv.notify_one ();
25
+ }
26
+ };
12
27
13
28
/* *
14
29
* Checks that the callback function is called.
@@ -22,19 +37,19 @@ TEST_P(urEventSetCallbackTest, Success) {
22
37
[[maybe_unused]] ur_execution_info_t execStatus,
23
38
void *pUserData) {
24
39
25
- auto status = reinterpret_cast <bool *>(pUserData);
26
- *status = true ;
40
+ auto that = reinterpret_cast <urEventSetCallbackTest *>(pUserData);
41
+ that-> SetFlag () ;
27
42
}
28
43
};
29
44
30
- bool didRun = false ;
31
45
ASSERT_SUCCESS (
32
46
urEventSetCallback (event, ur_execution_info_t ::UR_EXECUTION_INFO_COMPLETE,
33
- Callback::callback, &didRun ));
47
+ Callback::callback, this ));
34
48
35
49
ASSERT_SUCCESS (urEventWait (1 , &event));
36
50
ASSERT_SUCCESS (urEventRelease (event));
37
- ASSERT_TRUE (didRun);
51
+ WaitForFlag ();
52
+ ASSERT_EQ (flag, 1 );
38
53
}
39
54
40
55
/* *
@@ -45,6 +60,7 @@ TEST_P(urEventSetCallbackTest, ValidateParameters) {
45
60
uur::LevelZeroV2{}, uur::NativeCPU{});
46
61
47
62
struct CallbackParameters {
63
+ urEventSetCallbackTest *test;
48
64
ur_event_handle_t event;
49
65
ur_execution_info_t execStatus;
50
66
};
@@ -56,17 +72,19 @@ TEST_P(urEventSetCallbackTest, ValidateParameters) {
56
72
auto parameters = reinterpret_cast <CallbackParameters *>(pUserData);
57
73
parameters->event = hEvent;
58
74
parameters->execStatus = execStatus;
75
+ parameters->test ->SetFlag ();
59
76
}
60
77
};
61
78
62
- CallbackParameters parameters{};
79
+ CallbackParameters parameters{this , nullptr , UR_EXECUTION_INFO_QUEUED };
63
80
64
81
ASSERT_SUCCESS (
65
82
urEventSetCallback (event, ur_execution_info_t ::UR_EXECUTION_INFO_COMPLETE,
66
83
Callback::callback, ¶meters));
67
84
68
85
ASSERT_SUCCESS (urEventWait (1 , &event));
69
86
ASSERT_SUCCESS (urEventRelease (event));
87
+ WaitForFlag ();
70
88
ASSERT_EQ (event, parameters.event );
71
89
ASSERT_EQ (ur_execution_info_t ::UR_EXECUTION_INFO_COMPLETE,
72
90
parameters.execStatus );
@@ -80,6 +98,7 @@ TEST_P(urEventSetCallbackTest, AllStates) {
80
98
uur::LevelZeroV2{}, uur::NativeCPU{});
81
99
82
100
struct CallbackStatus {
101
+ urEventSetCallbackTest *test = nullptr ;
83
102
bool submitted = false ;
84
103
bool running = false ;
85
104
bool complete = false ;
@@ -107,10 +126,12 @@ TEST_P(urEventSetCallbackTest, AllStates) {
107
126
FAIL () << " Invalid execution info enumeration" ;
108
127
}
109
128
}
129
+
130
+ status->test ->SetFlag ();
110
131
}
111
132
};
112
133
113
- CallbackStatus status{};
134
+ CallbackStatus status{this };
114
135
115
136
ASSERT_SUCCESS (urEventSetCallback (
116
137
event, ur_execution_info_t ::UR_EXECUTION_INFO_SUBMITTED,
@@ -124,6 +145,7 @@ TEST_P(urEventSetCallbackTest, AllStates) {
124
145
125
146
ASSERT_SUCCESS (urEventWait (1 , &event));
126
147
ASSERT_SUCCESS (urEventRelease (event));
148
+ WaitForFlag (3 );
127
149
128
150
ASSERT_TRUE (status.submitted );
129
151
ASSERT_TRUE (status.running );
@@ -145,19 +167,18 @@ TEST_P(urEventSetCallbackTest, EventAlreadyCompleted) {
145
167
[[maybe_unused]] ur_execution_info_t execStatus,
146
168
void *pUserData) {
147
169
148
- auto status = reinterpret_cast <bool *>(pUserData);
149
- *status = true ;
170
+ auto that = reinterpret_cast <urEventSetCallbackTest *>(pUserData);
171
+ that-> SetFlag () ;
150
172
}
151
173
};
152
174
153
- bool didRun = false ;
154
-
155
175
ASSERT_SUCCESS (
156
176
urEventSetCallback (event, ur_execution_info_t ::UR_EXECUTION_INFO_COMPLETE,
157
- Callback::callback, &didRun ));
177
+ Callback::callback, this ));
158
178
159
179
ASSERT_SUCCESS (urEventRelease (event));
160
- ASSERT_TRUE (didRun);
180
+ WaitForFlag ();
181
+ ASSERT_EQ (flag, 1 );
161
182
}
162
183
163
184
UUR_INSTANTIATE_DEVICE_TEST_SUITE (urEventSetCallbackTest);
0 commit comments