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