| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | |||
| 2 | /*************************************** | ||
| 3 | Auteur : Pierre Aubert | ||
| 4 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 5 | Licence : CeCILL-C | ||
| 6 | ****************************************/ | ||
| 7 | |||
| 8 | #include <iostream> | ||
| 9 | #include <fstream> | ||
| 10 | #include "phoenix_assert.h" | ||
| 11 | #include "phoenix_check.h" | ||
| 12 | #include "lauchParallelThread.h" | ||
| 13 | |||
| 14 | ///Process a list of files | ||
| 15 | /** @param listFile : list of the files to be processed | ||
| 16 | * @param scal : scalar value | ||
| 17 | */ | ||
| 18 | 10 | void processFiles(const std::vector<std::string> & listFile, float scal){ | |
| 19 |
2/2✓ Branch 0 (25→3) taken 64 times.
✓ Branch 1 (25→26) taken 10 times.
|
148 | for(std::vector<std::string>::const_iterator it(listFile.begin()); it != listFile.end(); ++it){ |
| 20 | 64 | float res(0.0f); | |
| 21 |
2/2✓ Branch 0 (5→4) taken 498523 times.
✓ Branch 1 (5→6) taken 64 times.
|
498587 | for(long unsigned int i(1lu); i < 10000lu; ++i){ |
| 22 | 498523 | res += 1.0f/(((float)i)*((float)i)) - scal/((float)i); | |
| 23 | } | ||
| 24 |
1/1✓ Branch 0 (6→7) taken 64 times.
|
64 | std::ofstream fs; |
| 25 |
1/1✓ Branch 0 (10→11) taken 64 times.
|
64 | fs.open(it->c_str()); |
| 26 | |||
| 27 |
2/2✓ Branch 0 (11→12) taken 64 times.
✓ Branch 2 (12→13) taken 64 times.
|
64 | fs << res << std::endl; |
| 28 |
1/1✓ Branch 0 (13→14) taken 64 times.
|
64 | fs.close(); |
| 29 | 64 | } | |
| 30 | 10 | } | |
| 31 | |||
| 32 | ///Test the lauchParallelThread function | ||
| 33 | 1 | void testLauchParallelThread(){ | |
| 34 | 1 | std::vector<std::string> listFile; | |
| 35 |
2/2✓ Branch 0 (5→6) taken 1 times.
✓ Branch 2 (6→7) taken 1 times.
|
2 | listFile.push_back("file1.txt"); |
| 36 |
2/2✓ Branch 0 (11→12) taken 1 times.
✓ Branch 2 (12→13) taken 1 times.
|
2 | listFile.push_back("file2.txt"); |
| 37 |
2/2✓ Branch 0 (17→18) taken 1 times.
✓ Branch 2 (18→19) taken 1 times.
|
2 | listFile.push_back("file3.txt"); |
| 38 |
2/2✓ Branch 0 (23→24) taken 1 times.
✓ Branch 2 (24→25) taken 1 times.
|
2 | listFile.push_back("file4.txt"); |
| 39 |
2/2✓ Branch 0 (29→30) taken 1 times.
✓ Branch 2 (30→31) taken 1 times.
|
2 | listFile.push_back("file5.txt"); |
| 40 |
2/2✓ Branch 0 (35→36) taken 1 times.
✓ Branch 2 (36→37) taken 1 times.
|
2 | listFile.push_back("file6.txt"); |
| 41 |
2/2✓ Branch 0 (41→42) taken 1 times.
✓ Branch 2 (42→43) taken 1 times.
|
2 | listFile.push_back("file7.txt"); |
| 42 |
2/2✓ Branch 0 (47→48) taken 1 times.
✓ Branch 2 (48→49) taken 1 times.
|
2 | listFile.push_back("file8.txt"); |
| 43 |
2/2✓ Branch 0 (53→54) taken 1 times.
✓ Branch 2 (54→55) taken 1 times.
|
2 | listFile.push_back("file9.txt"); |
| 44 |
2/2✓ Branch 0 (59→60) taken 1 times.
✓ Branch 2 (60→61) taken 1 times.
|
2 | listFile.push_back("file10.txt"); |
| 45 |
2/2✓ Branch 0 (65→66) taken 1 times.
✓ Branch 2 (66→67) taken 1 times.
|
2 | listFile.push_back("file11.txt"); |
| 46 |
2/2✓ Branch 0 (71→72) taken 1 times.
✓ Branch 2 (72→73) taken 1 times.
|
2 | listFile.push_back("file12.txt"); |
| 47 |
2/2✓ Branch 0 (77→78) taken 1 times.
✓ Branch 2 (78→79) taken 1 times.
|
2 | listFile.push_back("file13.txt"); |
| 48 |
2/2✓ Branch 0 (83→84) taken 1 times.
✓ Branch 2 (84→85) taken 1 times.
|
2 | listFile.push_back("file14.txt"); |
| 49 |
2/2✓ Branch 0 (89→90) taken 1 times.
✓ Branch 2 (90→91) taken 1 times.
|
2 | listFile.push_back("file15.txt"); |
| 50 |
2/2✓ Branch 0 (95→96) taken 1 times.
✓ Branch 2 (96→97) taken 1 times.
|
1 | listFile.push_back("file16.txt"); |
| 51 | |||
| 52 | 1 | float scal(1.0f); | |
| 53 |
2/2✓ Branch 0 (102→100) taken 5 times.
✓ Branch 1 (102→103) taken 1 times.
|
6 | for(size_t i(0lu); i < 5lu; ++i){ |
| 54 |
1/1✓ Branch 0 (100→101) taken 5 times.
|
5 | lauchParallelThread(listFile, i, processFiles, scal); |
| 55 | } | ||
| 56 | 1 | } | |
| 57 | |||
| 58 | ///Process a list of files | ||
| 59 | /** @param fs : log output to be used | ||
| 60 | * @param listFile : list of the files to be processed | ||
| 61 | * @param scal : scalar value | ||
| 62 | */ | ||
| 63 | 20 | void processFilesLog(std::ofstream & fs, const std::vector<PPath> & listFile, float scal){ | |
| 64 |
2/2✓ Branch 0 (30→3) taken 128 times.
✓ Branch 1 (30→31) taken 20 times.
|
296 | for(std::vector<PPath>::const_iterator it(listFile.begin()); it != listFile.end(); ++it){ |
| 65 | 128 | float res(0.0f); | |
| 66 |
2/2✓ Branch 0 (5→4) taken 1017348 times.
✓ Branch 1 (5→6) taken 128 times.
|
1017476 | for(long unsigned int i(1lu); i < 10000lu; ++i){ |
| 67 | 1017348 | res += 1.0f/(((float)i)*((float)i)) - scal/((float)i); | |
| 68 | } | ||
| 69 |
1/1✓ Branch 0 (6→7) taken 128 times.
|
128 | std::ofstream fsOut; |
| 70 |
1/1✓ Branch 0 (9→10) taken 128 times.
|
128 | fsOut.open(*it); |
| 71 | |||
| 72 |
2/2✓ Branch 0 (10→11) taken 128 times.
✓ Branch 2 (11→12) taken 128 times.
|
128 | fsOut << res << std::endl; |
| 73 |
4/4✓ Branch 0 (12→13) taken 128 times.
✓ Branch 2 (15→16) taken 128 times.
✓ Branch 4 (16→17) taken 128 times.
✓ Branch 6 (17→18) taken 128 times.
|
256 | fs << "processFilesLog : process file '"<<(*it)<<"'" << std::endl; |
| 74 |
1/1✓ Branch 0 (18→19) taken 128 times.
|
128 | fsOut.close(); |
| 75 | 128 | } | |
| 76 | 20 | } | |
| 77 | |||
| 78 | ///Check the function lauchParallelThreadLogList with files | ||
| 79 | /** @param logFileName : name of the log file to be used | ||
| 80 | * @param expectedOk : true if we expect the function to work | ||
| 81 | * @return true on success, false otherwise | ||
| 82 | */ | ||
| 83 | 3 | bool testLauchParallelThreadLogListFile(const PPath & logFileName, bool expectedOk){ | |
| 84 | 3 | std::vector<PPath> listFile; | |
| 85 |
3/3✓ Branch 0 (3→4) taken 3 times.
✓ Branch 2 (4→5) taken 3 times.
✓ Branch 4 (5→6) taken 3 times.
|
3 | listFile.push_back(PPath("file1.txt")); |
| 86 |
3/3✓ Branch 0 (8→9) taken 3 times.
✓ Branch 2 (9→10) taken 3 times.
✓ Branch 4 (10→11) taken 3 times.
|
3 | listFile.push_back(PPath("file2.txt")); |
| 87 |
3/3✓ Branch 0 (13→14) taken 3 times.
✓ Branch 2 (14→15) taken 3 times.
✓ Branch 4 (15→16) taken 3 times.
|
3 | listFile.push_back(PPath("file3.txt")); |
| 88 |
3/3✓ Branch 0 (18→19) taken 3 times.
✓ Branch 2 (19→20) taken 3 times.
✓ Branch 4 (20→21) taken 3 times.
|
3 | listFile.push_back(PPath("file4.txt")); |
| 89 |
3/3✓ Branch 0 (23→24) taken 3 times.
✓ Branch 2 (24→25) taken 3 times.
✓ Branch 4 (25→26) taken 3 times.
|
3 | listFile.push_back(PPath("file5.txt")); |
| 90 |
3/3✓ Branch 0 (28→29) taken 3 times.
✓ Branch 2 (29→30) taken 3 times.
✓ Branch 4 (30→31) taken 3 times.
|
3 | listFile.push_back(PPath("file6.txt")); |
| 91 |
3/3✓ Branch 0 (33→34) taken 3 times.
✓ Branch 2 (34→35) taken 3 times.
✓ Branch 4 (35→36) taken 3 times.
|
3 | listFile.push_back(PPath("file7.txt")); |
| 92 |
3/3✓ Branch 0 (38→39) taken 3 times.
✓ Branch 2 (39→40) taken 3 times.
✓ Branch 4 (40→41) taken 3 times.
|
3 | listFile.push_back(PPath("file8.txt")); |
| 93 |
3/3✓ Branch 0 (43→44) taken 3 times.
✓ Branch 2 (44→45) taken 3 times.
✓ Branch 4 (45→46) taken 3 times.
|
3 | listFile.push_back(PPath("file9.txt")); |
| 94 |
3/3✓ Branch 0 (48→49) taken 3 times.
✓ Branch 2 (49→50) taken 3 times.
✓ Branch 4 (50→51) taken 3 times.
|
3 | listFile.push_back(PPath("file10.txt")); |
| 95 |
3/3✓ Branch 0 (53→54) taken 3 times.
✓ Branch 2 (54→55) taken 3 times.
✓ Branch 4 (55→56) taken 3 times.
|
3 | listFile.push_back(PPath("file11.txt")); |
| 96 |
3/3✓ Branch 0 (58→59) taken 3 times.
✓ Branch 2 (59→60) taken 3 times.
✓ Branch 4 (60→61) taken 3 times.
|
3 | listFile.push_back(PPath("file12.txt")); |
| 97 |
3/3✓ Branch 0 (63→64) taken 3 times.
✓ Branch 2 (64→65) taken 3 times.
✓ Branch 4 (65→66) taken 3 times.
|
3 | listFile.push_back(PPath("file13.txt")); |
| 98 |
3/3✓ Branch 0 (68→69) taken 3 times.
✓ Branch 2 (69→70) taken 3 times.
✓ Branch 4 (70→71) taken 3 times.
|
3 | listFile.push_back(PPath("file14.txt")); |
| 99 |
3/3✓ Branch 0 (73→74) taken 3 times.
✓ Branch 2 (74→75) taken 3 times.
✓ Branch 4 (75→76) taken 3 times.
|
3 | listFile.push_back(PPath("file15.txt")); |
| 100 |
3/3✓ Branch 0 (78→79) taken 3 times.
✓ Branch 2 (79→80) taken 3 times.
✓ Branch 4 (80→81) taken 3 times.
|
3 | listFile.push_back(PPath("file16.txt")); |
| 101 | |||
| 102 | 3 | bool b(true); | |
| 103 | 3 | float scal(1.0f); | |
| 104 |
2/2✓ Branch 0 (86→84) taken 15 times.
✓ Branch 1 (86→87) taken 3 times.
|
18 | for(size_t i(0lu); i < 5lu; ++i){ |
| 105 |
1/1✓ Branch 0 (84→85) taken 15 times.
|
15 | b &= lauchParallelThreadLog(listFile, logFileName, i, processFilesLog, scal); |
| 106 | } | ||
| 107 | 3 | bool isSuccess(b == expectedOk); | |
| 108 | // phoenix_functionOk("testLauchParallelThreadLogListFile("+logFileName+")", isSuccess); | ||
| 109 | 3 | return isSuccess; | |
| 110 | 3 | } | |
| 111 | |||
| 112 | ///Write some log | ||
| 113 | /** @param fs : log output to be used | ||
| 114 | * @param scal : scalar value | ||
| 115 | */ | ||
| 116 | 20 | void processFilesLogOnly(std::ofstream & fs, float scal){ | |
| 117 | 20 | float res(0.0f); | |
| 118 |
2/2✓ Branch 0 (10→3) taken 1980 times.
✓ Branch 1 (10→11) taken 20 times.
|
2000 | for(long unsigned int i(1lu); i < 100lu; ++i){ |
| 119 | 1980 | res += 1.0f/(((float)i)*((float)i)) - scal/((float)i); | |
| 120 | 1980 | fs << "processFilesLogOnly : res["<<i<<"] '"<<res<<"'" << std::endl; | |
| 121 | } | ||
| 122 | 20 | } | |
| 123 | |||
| 124 | ///Check the function lauchParallelThreadLogList with log only | ||
| 125 | /** @param logFileName : name of the log file to be used | ||
| 126 | * @param expectedOk : true if we expect the function to work | ||
| 127 | * @return true on success, false otherwise | ||
| 128 | */ | ||
| 129 | 3 | bool testLauchParallelThreadLogOnlyLog(const PPath & logFileName, bool expectedOk){ | |
| 130 | 3 | bool b(true); | |
| 131 | 3 | float scal(1.0f); | |
| 132 |
2/2✓ Branch 0 (5→3) taken 15 times.
✓ Branch 1 (5→6) taken 3 times.
|
18 | for(size_t i(0lu); i < 5lu; ++i){ |
| 133 |
1/1✓ Branch 0 (3→4) taken 15 times.
|
15 | b &= lauchParallelThreadLog(logFileName, i, processFilesLogOnly, scal); |
| 134 | } | ||
| 135 | 3 | bool isSuccess(b == expectedOk); | |
| 136 | // phoenix_functionOk("testLauchParallelThreadLogOnlyLog("+logFileName+")", isSuccess); | ||
| 137 | 3 | return isSuccess; | |
| 138 | } | ||
| 139 | |||
| 140 | 1 | int main(int argc, char** argv){ | |
| 141 | 1 | testLauchParallelThread(); | |
| 142 |
7/7✓ Branch 0 (5→6) taken 1 times.
✓ Branch 2 (8→9) taken 1 times.
✓ Branch 4 (11→12) taken 1 times.
✓ Branch 6 (12→13) taken 1 times.
✓ Branch 8 (13→14) taken 1 times.
✓ Branch 10 (14→15) taken 1 times.
✓ Branch 12 (15→16) taken 1 times.
|
6 | phoenix_assert(testLauchParallelThreadLogListFile(PPath("basic_log_file.txt"), true)); |
| 143 |
7/7✓ Branch 0 (26→27) taken 1 times.
✓ Branch 2 (29→30) taken 1 times.
✓ Branch 4 (32→33) taken 1 times.
✓ Branch 6 (33→34) taken 1 times.
✓ Branch 8 (34→35) taken 1 times.
✓ Branch 10 (35→36) taken 1 times.
✓ Branch 12 (36→37) taken 1 times.
|
6 | phoenix_assert(testLauchParallelThreadLogListFile(PPath("basic_log_file"), true)); |
| 144 |
7/7✓ Branch 0 (47→48) taken 1 times.
✓ Branch 2 (50→51) taken 1 times.
✓ Branch 4 (53→54) taken 1 times.
✓ Branch 6 (54→55) taken 1 times.
✓ Branch 8 (55→56) taken 1 times.
✓ Branch 10 (56→57) taken 1 times.
✓ Branch 12 (57→58) taken 1 times.
|
6 | phoenix_assert(testLauchParallelThreadLogListFile(PPath("some/inexisting/logFile.txt"), false)); |
| 145 | |||
| 146 |
7/7✓ Branch 0 (68→69) taken 1 times.
✓ Branch 2 (71→72) taken 1 times.
✓ Branch 4 (74→75) taken 1 times.
✓ Branch 6 (75→76) taken 1 times.
✓ Branch 8 (76→77) taken 1 times.
✓ Branch 10 (77→78) taken 1 times.
✓ Branch 12 (78→79) taken 1 times.
|
6 | phoenix_assert(testLauchParallelThreadLogOnlyLog(PPath("only_log_file.txt"), true)); |
| 147 |
7/7✓ Branch 0 (89→90) taken 1 times.
✓ Branch 2 (92→93) taken 1 times.
✓ Branch 4 (95→96) taken 1 times.
✓ Branch 6 (96→97) taken 1 times.
✓ Branch 8 (97→98) taken 1 times.
✓ Branch 10 (98→99) taken 1 times.
✓ Branch 12 (99→100) taken 1 times.
|
6 | phoenix_assert(testLauchParallelThreadLogOnlyLog(PPath("only_log_file"), true)); |
| 148 |
7/7✓ Branch 0 (110→111) taken 1 times.
✓ Branch 2 (113→114) taken 1 times.
✓ Branch 4 (116→117) taken 1 times.
✓ Branch 6 (117→118) taken 1 times.
✓ Branch 8 (118→119) taken 1 times.
✓ Branch 10 (119→120) taken 1 times.
✓ Branch 12 (120→121) taken 1 times.
|
5 | phoenix_assert(testLauchParallelThreadLogOnlyLog(PPath("some/inexisting/logFile.txt"), false)); |
| 149 | 1 | return 0; | |
| 150 | } | ||
| 151 | |||
| 152 | |||
| 153 |