1 /*
2 * Copyright (c) 2019 The Linux Foundation. All rights reserved.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include "qdf_delayed_work.h"
20 #include "qdf_delayed_work_test.h"
21 #include "qdf_trace.h"
22
23 #define dwork_delay_ms 1
24
__qdf_dwork_cb(void * context)25 static void __qdf_dwork_cb(void *context)
26 {
27 bool *flag = context;
28
29 *flag = true;
30 }
31
qdf_delayed_work_unit_test(void)32 uint32_t qdf_delayed_work_unit_test(void)
33 {
34 struct qdf_delayed_work dwork;
35 bool work_ran = false;
36 QDF_STATUS status;
37
38 status = qdf_delayed_work_create(&dwork, __qdf_dwork_cb, &work_ran);
39 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
40
41 QDF_BUG(qdf_delayed_work_start(&dwork, dwork_delay_ms));
42
43 while (!work_ran)
44 schedule();
45
46 /* flush to avoid races with the next assert */
47 qdf_delayed_work_stop_sync(&dwork);
48 QDF_BUG(!qdf_delayed_work_stop_sync(&dwork));
49
50 qdf_delayed_work_destroy(&dwork);
51
52 return 0;
53 }
54
55