thread_tc.cpp 954 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2006-2019, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-09-03 liukang the first version
  9. */
  10. #include <rtthread.h>
  11. #include "utest.h"
  12. #include <thread>
  13. static void test_thread(void)
  14. {
  15. int count = 0;
  16. auto func = [&]() mutable
  17. {
  18. for (int i = 0; i < 100; ++i)
  19. {
  20. ++count;
  21. }
  22. };
  23. std::thread t1(func);
  24. t1.join();
  25. if (count != 100)
  26. {
  27. uassert_false(1);
  28. }
  29. std::thread t2(func);
  30. t2.join();
  31. if (count != 200)
  32. {
  33. uassert_false(1);
  34. }
  35. uassert_true(1);
  36. }
  37. static rt_err_t utest_tc_init(void)
  38. {
  39. return RT_EOK;
  40. }
  41. static rt_err_t utest_tc_cleanup(void)
  42. {
  43. return RT_EOK;
  44. }
  45. static void testcase(void)
  46. {
  47. UTEST_UNIT_RUN(test_thread);
  48. }
  49. UTEST_TC_EXPORT(testcase, "testcases.cpp11.thread_tc", utest_tc_init, utest_tc_cleanup, 10);