GCC Code Coverage Report


Directory: ./
File: program/main_split.cpp
Date: 2025-03-14 11:49:29
Exec Total Coverage
Lines: 53 76 69.7%
Branches: 77 165 46.7%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #include "PPath.h"
8 #include "OptionParser.h"
9
10 #include "phoenix_clock_mock.h"
11
12 ///Create the OptionParser of this program
13 /** @return OptionParser of this program
14 */
15 2 OptionParser createOptionParser(){
16
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 OptionParser parser(true, __PROGRAM_VERSION__);
17
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 parser.setExampleLongOption("phoenix_clock_mock_split --input=file.clockmock --output=split.clockmock");
18
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 parser.setExampleShortOption("phoenix_clock_mock_split -i file2.clockmock file2.clockmock -o split.clockmock");
19
20
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
2 parser.addOption("input", "i", OptionType::FILENAME, true, "List of input mock to be split");
21
22
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 PPath defaultOutputFile("./split.clockmock");
23
5/5
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
2 parser.addOption("output", "o", defaultOutputFile, "Name of the output split mock file");
24
25 2 size_t defaultOffset(0lu), defaultSizePart(1lu), defaultNbPart(0lu);
26
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
2 parser.addOption("offset", "f", defaultOffset, "Offset of the first message to be extracted in a split mock");
27
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
2 parser.addOption("sizepart", "s", defaultSizePart, "Size of each split part (number of messages in each part to be split)");
28
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
2 parser.addOption("nbpart", "n", defaultNbPart, "Number of output mock to be created (0 means automatic by respect to --offset and --sizepart)");
29 4 return parser;
30 2 }
31
32 ///Make the output file name
33 /** @param baseFileName : base name of the file
34 * @param indexFile : index of hte file
35 * @param extentionFile : extention of the file
36 * @return corresponding output file
37 */
38 4 PPath phoenix_mockMakeOutputFile(const PPath & baseFileName, size_t indexFile, const PPath & extentionFile){
39
1/1
✓ Branch 1 taken 4 times.
4 PPath extention(extentionFile);
40
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if(extention == ""){
41 extention = PPath("clockmock");
42 }
43
9/9
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 13 taken 4 times.
✓ Branch 16 taken 4 times.
✓ Branch 19 taken 4 times.
✓ Branch 22 taken 4 times.
✓ Branch 25 taken 4 times.
8 return PPath(baseFileName + PString("_") + PString::toString(indexFile) + PString(".") + extention);
44 4 }
45
46 ///Merge mock files
47 /** @param vecInputFile : vector of input files to be merged
48 * @param outputFile : output file name to be saved
49 * @param offsetPart : offset of the first message to be extracted in a split mock
50 * @param sizePart : size of each split part (number of messages in each part to be split)
51 * @param nbPart : number of output mock to be created (0 means automatic by respect to --offset and --sizepart)
52 * @return true on success, false otherwise
53 */
54 2 bool splitMock(const std::vector<PPath> & vecInputFile, const PPath & outputFile,
55 size_t offsetPart, size_t sizePart, size_t nbPart)
56 {
57
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 if(sizePart == 0lu && nbPart == 0lu){
58 std::cerr << "Error sizePart cannot be 0 id nbPart == 0, aborting split" << std::endl;
59 return false;
60 }
61
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
4 PPath outputExtension(outputFile.getExtension()), baseOutputFile(outputFile.eraseExtension());
62 2 bool b(true);
63
5/6
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 2 times.
4 for(std::vector<PPath>::const_iterator itFile(vecInputFile.begin()); itFile != vecInputFile.end() && b; ++itFile){
64 2 VecTime vecTmpFile;
65
3/3
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
2 if(data_load(*itFile, vecTmpFile)){
66 1 size_t nbTimeIn(vecTmpFile.size());
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(sizePart == 0lu){
68 if(offsetPart <= nbTimeIn){
69 sizePart = (nbTimeIn - offsetPart)/nbPart;
70 if(sizePart == 0lu){
71 std::cerr << "splitMock : cannot split nbTimeIn = " << nbTimeIn << ", into nbPart = "<<nbPart<<" of size sizePart = "<<sizePart<<" and offset offsetPart = " << offsetPart << std::endl;
72 b = false;
73 }else{
74 for(size_t i(0lu); i < nbPart; ++i){
75 VecTime vecMessage;
76 splitVecTime(vecMessage, vecTmpFile, offsetPart + i*sizePart, sizePart);
77 b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, i, outputExtension), vecMessage);
78 }
79 }
80 }else{
81 VecTime vecMessage;
82 // splitVecTime(vecMessage, vecTmpFile, offsetPart, sizePart);
83 b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, 0lu, outputExtension), vecMessage);
84 }
85
86
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 }else if(nbPart == 0lu){
87
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if((sizePart + offsetPart) <= nbTimeIn){
88 1 nbPart = (nbTimeIn-offsetPart)/sizePart;
89
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for(size_t i(0lu); i < nbPart; ++i){
90 4 VecTime vecMessage;
91
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 splitVecTime(vecMessage, vecTmpFile, offsetPart + i*sizePart, sizePart);
92
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, i, outputExtension), vecMessage);
93 4 }
94 }else{
95 VecTime vecMessage;
96 // splitVecTime(vecMessage, vecTmpFile, offsetPart, sizePart);
97 b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, 0lu, outputExtension), vecMessage);
98 }
99 }else{
100 if((sizePart*nbPart + offsetPart) <= nbTimeIn){
101 for(size_t i(0lu); i < nbPart; ++i){
102 VecTime vecMessage;
103 splitVecTime(vecMessage, vecTmpFile, offsetPart + i*sizePart, sizePart);
104 b &= data_save(phoenix_mockMakeOutputFile(baseOutputFile, i, outputExtension), vecMessage);
105 }
106 }else{
107 std::cerr << "splitMock : cannot split nbTimeIn = " << nbTimeIn << ", into nbPart = "<<nbPart<<" of size sizePart = "<<sizePart<<" and offset offsetPart = " << offsetPart << std::endl;
108 b = false;
109 }
110 }
111 }else{
112 1 b = false;
113 }
114 2 }
115 2 return b;
116 2 }
117
118 2 int main(int argc, char** argv){
119
1/1
✓ Branch 1 taken 2 times.
2 OptionParser parser = createOptionParser();
120
1/1
✓ Branch 1 taken 2 times.
2 parser.parseArgument(argc, argv);
121
122
1/1
✓ Branch 1 taken 2 times.
2 const OptionMode & defaultMode = parser.getDefaultMode();
123 2 std::vector<PPath> vecInputFile;
124
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 PPath outputFile("");
125
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 defaultMode.getValue(vecInputFile, "input");
126
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 defaultMode.getValue(outputFile, "output");
127
128 2 size_t offsetPart(0lu), sizePart(1lu), nbPart(0lu);
129
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 defaultMode.getValue(offsetPart, "offset");
130
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 defaultMode.getValue(sizePart, "sizepart");
131
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 defaultMode.getValue(nbPart, "nbpart");
132
133
1/1
✓ Branch 1 taken 2 times.
2 return splitMock(vecInputFile, outputFile, offsetPart, sizePart, nbPart) - 1;
134 2 }
135
136
137