qdf_delayed_work_test.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include "qdf_delayed_work.h"
  19. #include "qdf_delayed_work_test.h"
  20. #include "qdf_trace.h"
  21. #define dwork_delay_ms 1
  22. static void __qdf_dwork_cb(void *context)
  23. {
  24. bool *flag = context;
  25. *flag = true;
  26. }
  27. uint32_t qdf_delayed_work_unit_test(void)
  28. {
  29. struct qdf_delayed_work dwork;
  30. bool work_ran = false;
  31. QDF_STATUS status;
  32. status = qdf_delayed_work_create(&dwork, __qdf_dwork_cb, &work_ran);
  33. QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
  34. QDF_BUG(qdf_delayed_work_start(&dwork, dwork_delay_ms));
  35. while (!work_ran)
  36. schedule();
  37. /* flush to avoid races with the next assert */
  38. qdf_delayed_work_stop_sync(&dwork);
  39. QDF_BUG(!qdf_delayed_work_stop_sync(&dwork));
  40. qdf_delayed_work_destroy(&dwork);
  41. return 0;
  42. }