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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

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

95.65
/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

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

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

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

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

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

52
   pool.shutdown();
1✔
53

54
   return result;
1✔
55
}
1✔
56

57
BOTAN_REGISTER_TEST_FN("utils", "thread_pool", thread_pool);
58

59
}
60

61
}
62

63
#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