GCC Code Coverage Report


Directory: include/tts/
File: include/tts/engine/shard.hpp
Date: 2026-10-14 16:28:14
Exec Total Coverage
Lines: 17 17 100.0%
Functions: 3 3 100.0%
Branches: 18 19 94.7%

Line Branch Exec Source
1 //======================================================================================================================
2 //! @file
3 /*
4 TTS - Tiny Test System
5 Copyright : TTS Contributors & Maintainers
6 SPDX-License-Identifier: BSL-1.0
7 */
8 //======================================================================================================================
9 #pragma once
10
11 #include <tts/tools/options.hpp>
12 #include <tts/tools/preprocessor.hpp>
13
14 namespace tts::_
15 {
16 // Splits the suite in `total` round-robin shards (test at registration index k belongs to
17 // shard k % total), so a slow binary can be spread across parallel CI workers without
18 // splitting source files. See --shard in doc/cli.hpp.
19 struct shard_spec
20 {
21 bool active = false;
22 unsigned int index = 0;
23 unsigned int total = 1;
24
25 387 bool selects(std::size_t position) const
26 {
27
4/4
✓ Branch 0 taken 102 times.
✓ Branch 1 taken 285 times.
✓ Branch 2 taken 34 times.
✓ Branch 3 taken 68 times.
387 return !active || (position % total == index);
28 }
29
30 102 std::size_t count(std::size_t suite_size) const
31 {
32
2/2
✓ Branch 0 taken 99 times.
✓ Branch 1 taken 3 times.
102 if(!active) return suite_size;
33
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(suite_size <= index) return 0;
34 3 return (suite_size - index - 1) / total + 1;
35 }
36 };
37
38 // Parses --shard=i/n. `ok` is set to false if the flag is present but malformed or out of
39 // range (n == 0 or i >= n); the returned shard_spec is then meaningless and must be ignored.
40 TTS_DISABLE_WARNING_PUSH
41 TTS_DISABLE_WARNING_CRT_SECURE
42 108 inline shard_spec parse_shard(bool& ok)
43 {
44 108 ok = true;
45
1/1
✓ Branch 2 taken 108 times.
108 ::tts::text raw = ::tts::arguments().value<::tts::text>("--shard");
46
2/2
✓ Branch 1 taken 101 times.
✓ Branch 2 taken 7 times.
108 if(raw.is_empty()) return {};
47
48 7 unsigned int i = 0;
49 7 unsigned int n = 0;
50
8/8
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 5 times.
✓ Branch 8 taken 2 times.
7 if(sscanf(raw.data(), "%u/%u", &i, &n) != 2 || n == 0 || i >= n)
51 {
52 5 ok = false;
53 5 return {};
54 }
55
56 2 return {true, i, n};
57 108 }
58 TTS_DISABLE_WARNING_POP
59 }
60