test_npl_task.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. #include "test_util.h"
  20. #include "nimble/nimble_npl.h"
  21. #include <pthread.h>
  22. #define TASK0_ARG 55
  23. #define TASK1_ARG 66
  24. static struct ble_npl_task s_task[2];
  25. static int s_task_arg[2] =
  26. {
  27. TASK0_ARG, TASK1_ARG
  28. };
  29. void *task0_run(void *args)
  30. {
  31. int i = 10000;
  32. VerifyOrQuit(args == &s_task_arg[0], "Wrong args passed to task0");
  33. while (i--)
  34. {
  35. }
  36. return NULL;
  37. }
  38. void *task1_run(void *args)
  39. {
  40. int i = 10000;
  41. VerifyOrQuit(args == &s_task_arg[1], "Wrong args passed to task0");
  42. while (i--)
  43. {
  44. }
  45. printf("All tests passed\n");
  46. exit(PASS);
  47. return NULL;
  48. }
  49. /**
  50. * Unit test for initializing a task.
  51. *
  52. * int ble_npl_task_init(struct ble_npl_task *t, const char *name, ble_npl_task_func_t func,
  53. * void *arg, uint8_t prio, ble_npl_time_t sanity_itvl,
  54. * ble_npl_stack_t *stack_bottom, uint16_t stack_size)
  55. *
  56. */
  57. int test_init(void)
  58. {
  59. int err;
  60. err = ble_npl_task_init(NULL,
  61. "Null task",
  62. NULL, NULL, 1, 0, NULL, 0);
  63. VerifyOrQuit(err, "ble_npl_task_init accepted NULL parameters.");
  64. err = ble_npl_task_init(&s_task[0],
  65. "s_task[0]",
  66. task0_run, &s_task_arg[0], 1, 0, NULL, 0);
  67. SuccessOrQuit(err, "ble_npl_task_init failed.");
  68. err = ble_npl_task_init(&s_task[1],
  69. "s_task[1]",
  70. task1_run, &s_task_arg[1], 1, 0, NULL, 0);
  71. return err;
  72. }
  73. int main(void)
  74. {
  75. int ret = PASS;
  76. SuccessOrQuit(test_init(), "Failed: ble_npl_task_init");
  77. pthread_exit(&ret);
  78. return ret;
  79. }