• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 11844561993

14 Nov 2024 07:58PM UTC coverage: 91.178% (+0.1%) from 91.072%
11844561993

Pull #4435

github

web-flow
Merge 81dcb29da into e430f157a
Pull Request #4435: Test duration values ​​are now presented in seconds with six digits of precision. Tests without time measurements have been edited.

91856 of 100744 relevant lines covered (91.18%)

9311006.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.3
/src/tests/test_thread_utils.cpp
1
/*
2
* (C) 2019 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "tests.h"
8

9
#if defined(BOTAN_TARGET_OS_HAS_THREADS) && defined(BOTAN_HAS_THREAD_UTILS)
10

11
   #include <botan/internal/thread_pool.h>
12
   #include <chrono>
13

14
namespace Botan_Tests {
15

16
// TODO test Barrier
17
// TODO test Semaphore
18

19
namespace {
20

21
Test::Result thread_pool() {
1✔
22
   Test::Result result("Thread_Pool");
1✔
23
   result.start_timer();
1✔
24

25
   // Using lots of threads since here the works spend most of the time sleeping
26
   Botan::Thread_Pool pool(16);
1✔
27

28
   auto sleep_or_throw = [](size_t x) -> size_t {
101✔
29
      std::this_thread::sleep_for(std::chrono::milliseconds((x * 97) % 127));
100✔
30

31
      if(x % 2 == 0) {
100✔
32
         throw x;  // NOLINT(hicpp-exception-baseclass)
50✔
33
      }
34
      return x;
50✔
35
   };
36

37
   std::vector<std::future<size_t>> futures;
1✔
38
   for(size_t i = 0; i != 100; ++i) {
101✔
39
      auto fut = pool.run(sleep_or_throw, i);
100✔
40
      futures.push_back(std::move(fut));
100✔
41
   }
100✔
42

43
   for(size_t i = 0; i != futures.size(); ++i) {
101✔
44
      if(i % 2 == 0) {
100✔
45
         try {
50✔
46
            futures[i].get();
50✔
47
            result.test_failure("Expected future to throw");
×
48
         } catch(size_t x) {
50✔
49
            result.test_eq("Expected thrown value", x, i);
50✔
50
         }
50✔
51
      } else {
52
         result.test_eq("Expected return value", futures[i].get(), i);
100✔
53
      }
54
   }
55

56
   pool.shutdown();
1✔
57

58
   result.end_timer();
1✔
59
   return result;
1✔
60
}
1✔
61

62
BOTAN_REGISTER_TEST_FN("utils", "thread_pool", thread_pool);
63

64
}  // namespace
65

66
}  // namespace Botan_Tests
67

68
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc