util_task_test.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright 2011-2016 Blender Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "testing/testing.h"
  17. #include "util/util_task.h"
  18. CCL_NAMESPACE_BEGIN
  19. namespace {
  20. void task_run()
  21. {
  22. }
  23. } // namespace
  24. TEST(util_task, basic)
  25. {
  26. TaskScheduler::init(0);
  27. TaskPool pool;
  28. for (int i = 0; i < 100; ++i) {
  29. pool.push(function_bind(task_run));
  30. }
  31. TaskPool::Summary summary;
  32. pool.wait_work(&summary);
  33. TaskScheduler::exit();
  34. EXPECT_EQ(summary.num_tasks_handled, 100);
  35. }
  36. TEST(util_task, multiple_times)
  37. {
  38. for (int N = 0; N < 1000; ++N) {
  39. TaskScheduler::init(0);
  40. TaskPool pool;
  41. for (int i = 0; i < 100; ++i) {
  42. pool.push(function_bind(task_run));
  43. }
  44. TaskPool::Summary summary;
  45. pool.wait_work(&summary);
  46. TaskScheduler::exit();
  47. EXPECT_EQ(summary.num_tasks_handled, 100);
  48. }
  49. }
  50. CCL_NAMESPACE_END