| 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 <unistd.h> | ||
| 9 | |||
| 10 | #include <sstream> | ||
| 11 | #include <fstream> | ||
| 12 | #include <iostream> | ||
| 13 | |||
| 14 | #include <thread> | ||
| 15 | #include <vector> | ||
| 16 | |||
| 17 | #include "SignalCatcher.h" | ||
| 18 | |||
| 19 | ///Function executed by a thread | ||
| 20 | /** @param[out] b : true on success, false otherwise | ||
| 21 | * @param threadId : id of the current thread | ||
| 22 | */ | ||
| 23 | 2 | void threadFunction(char & b, size_t threadId){ | |
| 24 |
1/1✓ Branch 0 (2→3) taken 2 times.
|
2 | std::stringstream fileName; |
| 25 |
3/3✓ Branch 0 (3→4) taken 2 times.
✓ Branch 2 (4→5) taken 2 times.
✓ Branch 4 (5→6) taken 2 times.
|
2 | fileName << "threadFunction_" << threadId << ".log"; |
| 26 | |||
| 27 |
1/1✓ Branch 0 (6→7) taken 2 times.
|
2 | std::ofstream fs; |
| 28 |
2/2✓ Branch 0 (7→8) taken 1 times.
✓ Branch 2 (8→9) taken 2 times.
|
2 | fs.open(fileName.str()); |
| 29 | |||
| 30 | 2 | bool isSignalRecived(false); | |
| 31 | 2 | size_t delay(10lu); | |
| 32 |
3/4✓ Branch 0 (19→20) taken 6 times.
✗ Branch 1 (19→21) not taken.
✓ Branch 2 (20→11) taken 4 times.
✓ Branch 3 (20→21) taken 2 times.
|
6 | for(size_t i(0lu); i < delay && !isSignalRecived; ++i){ |
| 33 |
5/5✓ Branch 0 (11→12) taken 4 times.
✓ Branch 2 (12→13) taken 4 times.
✓ Branch 4 (13→14) taken 4 times.
✓ Branch 6 (14→15) taken 4 times.
✓ Branch 8 (15→16) taken 4 times.
|
4 | fs << "thread("<<threadId<<") : Waiting for signal : i = " << i << std::endl; |
| 34 |
1/1✓ Branch 0 (16→17) taken 4 times.
|
4 | isSignalRecived = phoenix_isSignalRecived(SIGQUIT); |
| 35 |
1/1✓ Branch 0 (17→18) taken 4 times.
|
4 | usleep(1000000); |
| 36 | } | ||
| 37 |
3/3✓ Branch 0 (21→22) taken 2 times.
✓ Branch 2 (22→23) taken 2 times.
✓ Branch 4 (23→24) taken 2 times.
|
2 | fs << "testSignalCatch : isSignalRecived = " << isSignalRecived << std::endl; |
| 38 |
1/1✓ Branch 0 (24→25) taken 2 times.
|
2 | fs.close(); |
| 39 | 2 | b = isSignalRecived; | |
| 40 | 2 | } | |
| 41 | |||
| 42 | ///Check Signal Catcher | ||
| 43 | /** @return true on success, false otherwise | ||
| 44 | */ | ||
| 45 | 1 | bool testSignalCatch(){ | |
| 46 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | phoenix_addSignalCatcher(SIGQUIT); |
| 47 | |||
| 48 | 1 | size_t nbThread(2lu); | |
| 49 | |||
| 50 | 1 | std::vector<char> vecRes; | |
| 51 |
1/1✓ Branch 0 (4→5) taken 1 times.
|
1 | vecRes.resize(nbThread); |
| 52 | |||
| 53 | 1 | std::vector<std::thread> vecThread; | |
| 54 |
1/1✓ Branch 0 (6→7) taken 1 times.
|
1 | vecThread.resize(nbThread); |
| 55 | |||
| 56 |
2/2✓ Branch 0 (15→8) taken 2 times.
✓ Branch 1 (15→16) taken 1 times.
|
3 | for(size_t i(0lu); i < nbThread; ++i){ |
| 57 |
1/1✓ Branch 0 (10→11) taken 2 times.
|
2 | vecThread[i] = std::thread(threadFunction, std::ref(vecRes[i]), i); |
| 58 | } | ||
| 59 | |||
| 60 |
2/2✓ Branch 0 (20→17) taken 2 times.
✓ Branch 1 (20→21) taken 1 times.
|
3 | for(size_t i(0lu); i < nbThread; ++i){ |
| 61 |
1/1✓ Branch 0 (18→19) taken 2 times.
|
2 | vecThread[i].join(); |
| 62 | } | ||
| 63 | 1 | bool b(true); | |
| 64 |
2/2✓ Branch 0 (24→22) taken 2 times.
✓ Branch 1 (24→25) taken 1 times.
|
3 | for(size_t i(0lu); i < nbThread; ++i){ |
| 65 | 2 | b &= (bool)vecRes[i]; | |
| 66 | } | ||
| 67 | |||
| 68 |
3/3✓ Branch 0 (25→26) taken 1 times.
✓ Branch 2 (26→27) taken 1 times.
✓ Branch 4 (27→28) taken 1 times.
|
1 | std::cout << "testSignalCatch : b = " << b << std::endl; |
| 69 | 1 | return b; | |
| 70 | 1 | } | |
| 71 | |||
| 72 | 1 | int main(int argc, char **argv){ | |
| 73 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | bool b(testSignalCatch()); |
| 74 |
3/3✓ Branch 0 (3→4) taken 1 times.
✓ Branch 2 (4→5) taken 1 times.
✓ Branch 4 (5→6) taken 1 times.
|
1 | std::cout << "final : b = " << b << std::endl; |
| 75 |
1/1✓ Branch 0 (6→7) taken 1 times.
|
1 | std::ofstream fs; |
| 76 |
1/1✓ Branch 0 (7→8) taken 1 times.
|
1 | fs.open("test_phoenix_thread_signal_catcher_thread.log"); |
| 77 |
2/2✓ Branch 0 (8→9) taken 1 times.
✓ Branch 2 (9→10) taken 1 times.
|
1 | fs << b << std::endl; |
| 78 |
1/1✓ Branch 0 (10→11) taken 1 times.
|
1 | fs.close(); |
| 79 | 1 | return b - 1; | |
| 80 | 1 | } | |
| 81 | |||
| 82 | |||
| 83 | |||
| 84 | |||
| 85 |