• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef MOCK_FFRT_API_CPP_TASK_H
16 #define MOCK_FFRT_API_CPP_TASK_H
17 
18 #include <string>
19 #include <vector>
20 #include <functional>
21 #include "c/task.h"
22 
23 namespace ffrt {
24 
25 class task_attr : public ffrt_task_attr_t {
26 public:
27 #if __has_builtin(__builtin_FUNCTION)
28 
29     task_attr(const char *func = __builtin_FUNCTION())
30     {}
31 #else
32 
33     task_attr()
34     {}
35 #endif
36 
~task_attr()37     ~task_attr()
38     {}
39 
40     task_attr(const task_attr &) = delete;
41 
42     task_attr &operator=(const task_attr &) = delete;
43 
name(const char * name)44     inline task_attr &name(const char *name)
45     {
46         return *this;
47     }
48 
name()49     inline const char *name() const
50     {
51         return nullptr;
52     }
53 
qos(qos qos_)54     inline task_attr &qos(qos qos_)
55     {
56         return *this;
57     }
58 
qos()59     inline int qos() const
60     {
61         return 0;
62     }
63 
delay(uint64_t delay_us)64     inline task_attr &delay(uint64_t delay_us)
65     {
66         return *this;
67     }
68 
delay()69     inline uint64_t delay() const
70     {
71         return 0;
72     }
73 
priority(ffrt_queue_priority_t prio)74     inline task_attr &priority(ffrt_queue_priority_t prio)
75     {
76         return *this;
77     }
78 
priority()79     inline ffrt_queue_priority_t priority() const
80     {
81         return {};
82     }
83 
stack_size(uint64_t size)84     inline task_attr &stack_size(uint64_t size)
85     {
86         return *this;
87     }
88 
stack_size()89     inline uint64_t stack_size() const
90     {
91         return 0;
92     }
93 
timeout(uint64_t timeout_us)94     inline task_attr &timeout(uint64_t timeout_us)
95     {
96         return *this;
97     }
98 
timeout()99     inline uint64_t timeout() const
100     {
101         return 0;
102     }
103 };
104 
105 class task_handle {
106 public:
task_handle()107     task_handle()
108     {}
109 
task_handle(ffrt_task_handle_t p)110     task_handle(ffrt_task_handle_t p)
111     {}
112 
~task_handle()113     ~task_handle()
114     {}
115 
116     task_handle(task_handle const &) = delete;
117 
118     task_handle &operator=(task_handle const &) = delete;
119 
task_handle(task_handle && h)120     task_handle(task_handle &&h)
121     {}
122 
get_id()123     inline uint64_t get_id() const
124     {
125         return 0;
126     }
127 
128     inline task_handle &operator=(task_handle &&h)
129     {
130         return *this;
131     }
132 
133     inline operator void *() const
134     {
135         return nullptr;
136     }
137 private:
138     [[maybe_unused]] ffrt_task_handle_t p = nullptr;
139 };
140 
141 struct dependence : ffrt_dependence_t {
142 
dependencedependence143     dependence(const void *d)
144     {}
145 
dependencedependence146     dependence(const task_handle &h)
147     {}
148 
dependencedependence149     dependence(const dependence &other)
150     {}
151 
dependencedependence152     dependence(dependence &&other)
153     {}
154 
155     dependence &operator=(const dependence &other)
156     {
157         return *this;
158     }
159 
160     dependence &operator=(dependence &&other)
161     {
162         return *this;
163     }
164 
~dependencedependence165     ~dependence()
166     {}
167 };
168 
169 template <class T>
170 struct function {
171     ffrt_function_header_t header;
172     T closure;
173 };
174 
175 template <class T>
exec_function_wrapper(void * t)176 void exec_function_wrapper(void *t)
177 {}
178 
179 template <class T>
destroy_function_wrapper(void * t)180 void destroy_function_wrapper(void *t)
181 {}
182 
183 template <class T>
184 inline ffrt_function_header_t *create_function_wrapper(T &&func, ffrt_function_kind_t kind = ffrt_function_kind_general)
185 {
186     return nullptr;
187 }
188 
189 static inline void submit(std::function<void()> &&func, const task_attr &attr = {})
190 {}
191 
192 static inline void submit(
193     std::function<void()> &&func, std::initializer_list<dependence> in_deps, const task_attr &attr = {})
194 {}
195 
196 static inline void submit(std::function<void()> &&func, std::initializer_list<dependence> in_deps,
197     std::initializer_list<dependence> out_deps, const task_attr &attr = {})
198 {}
199 
200 static inline void submit(
201     std::function<void()> &&func, const std::vector<dependence> &in_deps, const task_attr &attr = {})
202 {}
203 
204 static inline void submit(std::function<void()> &&func, const std::vector<dependence> &in_deps,
205     const std::vector<dependence> &out_deps, const task_attr &attr = {})
206 {}
207 
208 static inline void submit(const std::function<void()> &func, const task_attr &attr = {})
209 {}
210 
211 static inline void submit(
212     const std::function<void()> &func, std::initializer_list<dependence> in_deps, const task_attr &attr = {})
213 {}
214 
215 static inline void submit(const std::function<void()> &func, std::initializer_list<dependence> in_deps,
216     std::initializer_list<dependence> out_deps, const task_attr &attr = {})
217 {}
218 
219 static inline void submit(
220     const std::function<void()> &func, const std::vector<dependence> &in_deps, const task_attr &attr = {})
221 {}
222 
223 static inline void submit(const std::function<void()> &func, const std::vector<dependence> &in_deps,
224     const std::vector<dependence> &out_deps, const task_attr &attr = {})
225 {}
226 
227 static inline task_handle submit_h(std::function<void()> &&func, const task_attr &attr = {})
228 {
229     return {};
230 }
231 
232 static inline task_handle submit_h(
233     std::function<void()> &&func, std::initializer_list<dependence> in_deps, const task_attr &attr = {})
234 {
235     return {};
236 }
237 
238 static inline task_handle submit_h(std::function<void()> &&func, std::initializer_list<dependence> in_deps,
239     std::initializer_list<dependence> out_deps, const task_attr &attr = {})
240 {
241     return {};
242 }
243 
244 static inline task_handle submit_h(
245     std::function<void()> &&func, const std::vector<dependence> &in_deps, const task_attr &attr = {})
246 {
247     return {};
248 }
249 
250 static inline task_handle submit_h(std::function<void()> &&func, const std::vector<dependence> &in_deps,
251     const std::vector<dependence> &out_deps, const task_attr &attr = {})
252 {
253     return {};
254 }
255 
256 static inline task_handle submit_h(const std::function<void()> &func, const task_attr &attr = {})
257 {
258     return {};
259 }
260 
261 static inline task_handle submit_h(
262     const std::function<void()> &func, std::initializer_list<dependence> in_deps, const task_attr &attr = {})
263 {
264     return {};
265 }
266 
267 static inline task_handle submit_h(const std::function<void()> &func, std::initializer_list<dependence> in_deps,
268     std::initializer_list<dependence> out_deps, const task_attr &attr = {})
269 {
270     return {};
271 }
272 
273 static inline task_handle submit_h(
274     const std::function<void()> &func, const std::vector<dependence> &in_deps, const task_attr &attr = {})
275 {
276     return {};
277 }
278 
279 static inline task_handle submit_h(const std::function<void()> &func, const std::vector<dependence> &in_deps,
280     const std::vector<dependence> &out_deps, const task_attr &attr = {})
281 {
282     return {};
283 }
284 
wait()285 static inline void wait()
286 {}
287 
wait(std::initializer_list<dependence> deps)288 static inline void wait(std::initializer_list<dependence> deps)
289 {}
290 
wait(const std::vector<dependence> & deps)291 static inline void wait(const std::vector<dependence> &deps)
292 {}
293 
set_worker_stack_size(qos qos_,size_t stack_size)294 static inline ffrt_error_t set_worker_stack_size(qos qos_, size_t stack_size)
295 {
296     return {};
297 }
298 
299 namespace this_task {
300 
update_qos(qos qos_)301 static inline int update_qos(qos qos_)
302 {
303     return 0;
304 }
305 
get_id()306 static inline uint64_t get_id()
307 {
308     return 0;
309 }
310 }  // namespace this_task
311 }  // namespace ffrt
312 
313 #endif