From 74610ed912c33d6d1387d6548a084400b86fa750 Mon Sep 17 00:00:00 2001 From: Neal Kruis Date: Fri, 22 Dec 2023 14:04:29 -0700 Subject: [PATCH 01/15] Use cross-platform file io and modern formatting. --- src/HPWH.cc | 33 +++++++++-------- src/HPWH.hh | 4 +-- test/Rheem2020Build50.txt | 24 ++++++------- test/main.cc | 29 +++++++-------- test/ref/DHW_YRLY.csv | 70 ++++++++++++++++++------------------- test/testCompressorFcts.cc | 2 +- test/testEnergyBalance.cc | 2 +- test/testHeatingLogics.cc | 2 +- test/testMaxSetpoint.cc | 2 +- test/testPerformanceMaps.cc | 2 +- test/testResistanceFcts.cc | 2 +- test/testScaleHPWH.cc | 2 +- test/testSizingFractions.cc | 2 +- 13 files changed, 88 insertions(+), 88 deletions(-) diff --git a/src/HPWH.cc b/src/HPWH.cc index b615ffeb..3d4e8d63 100644 --- a/src/HPWH.cc +++ b/src/HPWH.cc @@ -40,6 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "HPWH.hh" #include +#include #include #include @@ -1113,64 +1114,62 @@ void HPWH::printTankTemps() } // public members to write to CSV file -int HPWH::WriteCSVHeading(FILE* outFILE, const char* preamble, int nTCouples, int options) const +int HPWH::WriteCSVHeading(std::ofstream& outFILE, const char* preamble, int nTCouples, int options) const { bool doIP = (options & CSVOPT_IPUNITS) != 0; - fprintf(outFILE, "%s", preamble); + outFILE << preamble; - fprintf(outFILE, "%s", "DRstatus"); + outFILE << "DRstatus"; for (int iHS = 0; iHS < getNumHeatSources(); iHS++) { - fprintf(outFILE, ",h_src%dIn (Wh),h_src%dOut (Wh)", iHS + 1, iHS + 1); + outFILE << fmt::format(",h_src{}In (Wh),h_src{}Out (Wh)", iHS + 1, iHS + 1); } for (int iTC = 0; iTC < nTCouples; iTC++) { - fprintf(outFILE, ",tcouple%d (%s)", iTC + 1, doIP ? "F" : "C"); + outFILE << fmt::format(",tcouple{} ({})", iTC + 1, doIP ? "F" : "C"); } - fprintf(outFILE, ",toutlet (%s)", doIP ? "F" : "C"); - - fprintf(outFILE, "\n"); + outFILE << fmt::format(",toutlet ({})", doIP ? "F" : "C") << std::endl; return 0; } -int HPWH::WriteCSVRow(FILE* outFILE, const char* preamble, int nTCouples, int options) const +int HPWH::WriteCSVRow(std::ofstream& outFILE, const char* preamble, int nTCouples, int options) const { bool doIP = (options & CSVOPT_IPUNITS) != 0; - fprintf(outFILE, "%s", preamble); + outFILE << preamble; + + outFILE << prevDRstatus; - fprintf(outFILE, "%i", prevDRstatus); for (int iHS = 0; iHS < getNumHeatSources(); iHS++) { - fprintf(outFILE, - ",%0.2f,%0.2f", + outFILE << fmt::format(",{:0.2f},{:0.2f}", getNthHeatSourceEnergyInput(iHS, UNITS_KWH) * 1000., getNthHeatSourceEnergyOutput(iHS, UNITS_KWH) * 1000.); } for (int iTC = 0; iTC < nTCouples; iTC++) { - fprintf(outFILE, ",%0.2f", getNthSimTcouple(iTC + 1, nTCouples, doIP ? UNITS_F : UNITS_C)); + outFILE << fmt::format(",{:0.2f}", getNthSimTcouple(iTC + 1, nTCouples, doIP ? UNITS_F : UNITS_C)); } if (options & HPWH::CSVOPT_IS_DRAWING) { - fprintf(outFILE, ",%0.2f", doIP ? C_TO_F(outletTemp_C) : outletTemp_C); + outFILE << fmt::format(",{:0.2f}", doIP ? C_TO_F(outletTemp_C) : outletTemp_C); } else { - fprintf(outFILE, ","); + outFILE << ","; } - fprintf(outFILE, "\n"); + outFILE << std::endl; return 0; } diff --git a/src/HPWH.hh b/src/HPWH.hh index ccdae473..e83f2b9f 100644 --- a/src/HPWH.hh +++ b/src/HPWH.hh @@ -584,11 +584,11 @@ class HPWH /**< this prints out all the node temps, kind of nicely formatted does not use verbosity, as it is public and expected to be called only when needed */ - int WriteCSVHeading(FILE* outFILE, + int WriteCSVHeading(std::ofstream& outFILE, const char* preamble = "", int nTCouples = 6, int options = CSVOPT_NONE) const; - int WriteCSVRow(FILE* outFILE, + int WriteCSVRow(std::ofstream& outFILE, const char* preamble = "", int nTCouples = 6, int options = CSVOPT_NONE) const; diff --git a/test/Rheem2020Build50.txt b/test/Rheem2020Build50.txt index 90c08559..79f34034 100644 --- a/test/Rheem2020Build50.txt +++ b/test/Rheem2020Build50.txt @@ -1,8 +1,8 @@ verbosity silent -numNodes 12 +numNodes 12 setpoint 127 F -volume 45.1 gal -UA 8.55 kJperHrC +volume 45.1 gal +UA 8.55 kJperHrC depressTemp false mixOnDraw true @@ -29,7 +29,7 @@ heatsource 2 copT1quad 0.0 heatsource 2 copT2const 8.45936 heatsource 2 copT2lin -0.04539 heatsource 2 copT2quad 0.0 -heatsource 2 minT 37F +heatsource 2 minT 37 F heatsource 2 maxT 120 F heatsource 2 hysteresis 1 F heatsource 2 coilConfig wrapped @@ -41,10 +41,10 @@ heatsource 0 condensity 0 0 0 0 0 0 0 0 1 0 0 0 heatsource 0 nTemps 2 heatsource 0 T1 50 F heatsource 0 T2 67 F -heatsource 0 inPowT1const 4500 +heatsource 0 inPowT1const 4500 heatsource 0 inPowT1lin 0.0 heatsource 0 inPowT1quad 0.0 -heatsource 0 inPowT2const 4500 +heatsource 0 inPowT2const 4500 heatsource 0 inPowT2lin 0.0 heatsource 0 inPowT2quad 0.0 heatsource 0 copT1const 1.0 @@ -64,10 +64,10 @@ heatsource 1 condensity 1 0 0 0 0 0 0 0 0 0 0 0 heatsource 1 nTemps 2 heatsource 1 T1 47 F heatsource 1 T2 67 F -heatsource 1 inPowT1const 4500 +heatsource 1 inPowT1const 4500 heatsource 1 inPowT1lin 0.0 heatsource 1 inPowT1quad 0.0 -heatsource 1 inPowT2const 4500 +heatsource 1 inPowT2const 4500 heatsource 1 inPowT2lin 0.0 heatsource 1 inPowT2quad 0.0 heatsource 1 copT1const 1.0 @@ -79,12 +79,12 @@ heatsource 1 copT2quad 0.0 heatsource 1 hysteresis 4 F heatsource 1 coilConfig submerged -heatsource 0 onlogic topSixth 20.4167 F +heatsource 0 onlogic topSixth 20.4167 F -heatsource 2 onlogic bottomThird 30 F -heatsource 2 onlogic standby 9 F +heatsource 2 onlogic bottomThird 30 F +heatsource 2 onlogic standby 9 F -heatsource 1 offlogic bottomTwelfthMaxTemp 100 F +heatsource 1 offlogic bottomTwelfthMaxTemp 100 F heatsource 1 backupSource 2 heatsource 2 backupSource 1 diff --git a/test/main.cc b/test/main.cc index 057a4c0b..9a69b580 100644 --- a/test/main.cc +++ b/test/main.cc @@ -15,6 +15,8 @@ #include #include #include // std::max +#include +#include #define MAX_DIR_LENGTH 255 @@ -63,8 +65,8 @@ int main(int argc, char* argv[]) bool HPWH_doTempDepress; int doInvMix, doCondu; - FILE* outputFile = NULL; - FILE* yearOutFile = NULL; + std::ofstream outputFile; + std::ofstream yearOutFile; ifstream controlFile; string strPreamble; @@ -329,8 +331,8 @@ int main(int argc, char* argv[]) if (minutesToRun > 500000.) { fileToOpen = outputDirectory + "/DHW_YRLY.csv"; - - if (fopen_s(&yearOutFile, fileToOpen.c_str(), "a+") != 0) + yearOutFile.open(fileToOpen.c_str(), std::ifstream::app); + if (!yearOutFile.is_open()) { cout << "Could not open output file " << fileToOpen << "\n"; exit(1); @@ -339,8 +341,8 @@ int main(int argc, char* argv[]) else { fileToOpen = outputDirectory + "/" + input3 + "_" + input1 + "_" + input2 + ".csv"; - - if (fopen_s(&outputFile, fileToOpen.c_str(), "w+") != 0) + outputFile.open(fileToOpen.c_str(), std::ifstream::out); + if (!outputFile.is_open()) { cout << "Could not open output file " << fileToOpen << "\n"; exit(1); @@ -499,26 +501,25 @@ int main(int argc, char* argv[]) if (minutesToRun > 500000.) { firstCol = input3 + "," + input1 + "," + input2; - fprintf(yearOutFile, "%s", firstCol.c_str()); + yearOutFile << firstCol; double totalIn = 0, totalOut = 0; for (int iHS = 0; iHS < 3; iHS++) { - fprintf(yearOutFile, ",%0.0f,%0.0f", cumHeatIn[iHS], cumHeatOut[iHS]); + yearOutFile << fmt::format(",{:0.0f},{:0.0f}", cumHeatIn[iHS], cumHeatOut[iHS]); totalIn += cumHeatIn[iHS]; totalOut += cumHeatOut[iHS]; } - fprintf(yearOutFile, ",%0.0f,%0.0f", totalIn, totalOut); + yearOutFile << fmt::format(",{:0.0f},{:0.0f}", totalIn, totalOut); for (int iHS = 0; iHS < 3; iHS++) { - fprintf(yearOutFile, ",%0.2f", cumHeatOut[iHS] / cumHeatIn[iHS]); + yearOutFile << fmt::format(",{:0.2f}", cumHeatOut[iHS] / cumHeatIn[iHS]); } - fprintf(yearOutFile, ",%0.2f", totalOut / totalIn); - fprintf(yearOutFile, "\n"); - fclose(yearOutFile); + yearOutFile << fmt::format(",{:0.2f}", totalOut / totalIn) << std::endl; + yearOutFile.close(); } else { - fclose(outputFile); + yearOutFile.close(); } controlFile.close(); diff --git a/test/ref/DHW_YRLY.csv b/test/ref/DHW_YRLY.csv index 1fd19101..0a9136fa 100644 --- a/test/ref/DHW_YRLY.csv +++ b/test/ref/DHW_YRLY.csv @@ -1,43 +1,43 @@ testCA_3BR_CTZ15,Preset,AOSmithHPTU80,6449,6449,4426,4426,589134,2249404,600009,2260279,1.00,1.00,3.82,3.77 -testCA_3BR_CTZ15,Preset,Sanden80,962244,3211029,0,0,0,0,962244,3211029,3.34,-nan(ind),-nan(ind),3.34 -testCA_3BR_CTZ15,Preset,GE502014,55875,55875,0,0,565517,2071441,621392,2127316,1.00,-nan(ind),3.66,3.42 -testCA_3BR_CTZ15,Preset,Rheem2020Prem40,43073,43073,0,0,537835,2245943,580908,2289016,1.00,-nan(ind),4.18,3.94 -testCA_3BR_CTZ15,Preset,Rheem2020Prem50,21934,21934,0,0,533295,2224941,555229,2246875,1.00,-nan(ind),4.17,4.05 -testCA_3BR_CTZ15,Preset,Rheem2020Build50,18422,18422,0,0,616009,2241746,634431,2260168,1.00,-nan(ind),3.64,3.56 -testCA_3BR_CTZ15,Preset,RheemPlugInDedicated50,686585,2277144,0,0,0,0,686585,2277144,3.32,-nan(ind),-nan(ind),3.32 -testCA_3BR_CTZ15,Preset,RheemPlugInShared40,557168,2339586,0,0,0,0,557168,2339586,4.20,-nan(ind),-nan(ind),4.20 -testCA_3BR_CTZ15,Preset,RheemPlugInShared50,550351,2305883,0,0,0,0,550351,2305883,4.19,-nan(ind),-nan(ind),4.19 -testCA_3BR_CTZ15,Preset,AOSmithCAHP120,0,0,2475,2475,677748,2365264,680223,2367738,-nan(ind),1.00,3.49,3.48 -testCA_3BR_CTZ15,Preset,AWHSTier3Generic80,17550,17550,0,0,695306,2264199,712856,2281749,1.00,-nan(ind),3.26,3.20 +testCA_3BR_CTZ15,Preset,Sanden80,962244,3211029,0,0,0,0,962244,3211029,3.34,-nan,-nan,3.34 +testCA_3BR_CTZ15,Preset,GE502014,55875,55875,0,0,565517,2071441,621392,2127316,1.00,-nan,3.66,3.42 +testCA_3BR_CTZ15,Preset,Rheem2020Prem40,43073,43073,0,0,537835,2245943,580908,2289016,1.00,-nan,4.18,3.94 +testCA_3BR_CTZ15,Preset,Rheem2020Prem50,21934,21934,0,0,533295,2224941,555229,2246875,1.00,-nan,4.17,4.05 +testCA_3BR_CTZ15,Preset,Rheem2020Build50,18422,18422,0,0,616009,2241746,634431,2260168,1.00,-nan,3.64,3.56 +testCA_3BR_CTZ15,Preset,RheemPlugInDedicated50,686585,2277144,0,0,0,0,686585,2277144,3.32,-nan,-nan,3.32 +testCA_3BR_CTZ15,Preset,RheemPlugInShared40,557168,2339586,0,0,0,0,557168,2339586,4.20,-nan,-nan,4.20 +testCA_3BR_CTZ15,Preset,RheemPlugInShared50,550351,2305883,0,0,0,0,550351,2305883,4.19,-nan,-nan,4.19 +testCA_3BR_CTZ15,Preset,AOSmithCAHP120,0,0,2475,2475,677748,2365264,680223,2367738,-nan,1.00,3.49,3.48 +testCA_3BR_CTZ15,Preset,AWHSTier3Generic80,17550,17550,0,0,695306,2264199,712856,2281749,1.00,-nan,3.26,3.20 testCA_3BR_CTZ16,Preset,AOSmithHPTU80,6088,6088,1179534,1179534,690914,2297398,1876536,3483020,1.00,1.00,3.33,1.86 -testCA_3BR_CTZ16,Preset,Sanden80,1354799,4328117,0,0,0,0,1354799,4328117,3.19,-nan(ind),-nan(ind),3.19 +testCA_3BR_CTZ16,Preset,Sanden80,1354799,4328117,0,0,0,0,1354799,4328117,3.19,-nan,-nan,3.19 testCA_3BR_CTZ16,Preset,GE502014,130275,130275,353792,353792,898211,2756543,1382279,3240610,1.00,1.00,3.07,2.34 testCA_3BR_CTZ16,Preset,Rheem2020Prem40,132342,132342,278799,278799,844628,3058799,1255769,3469941,1.00,1.00,3.62,2.76 testCA_3BR_CTZ16,Preset,Rheem2020Prem50,89483,89483,279666,279666,842085,3042790,1211235,3411939,1.00,1.00,3.61,2.82 testCA_3BR_CTZ16,Preset,Rheem2020Build50,73993,73993,281985,281985,931391,3066657,1287370,3422636,1.00,1.00,3.29,2.66 -testCA_3BR_CTZ16,Preset,RheemPlugInDedicated50,1075466,3298078,0,0,0,0,1075466,3298078,3.07,-nan(ind),-nan(ind),3.07 -testCA_3BR_CTZ16,Preset,RheemPlugInShared40,902116,3357097,0,0,0,0,902116,3357097,3.72,-nan(ind),-nan(ind),3.72 -testCA_3BR_CTZ16,Preset,RheemPlugInShared50,905228,3337523,0,0,0,0,905228,3337523,3.69,-nan(ind),-nan(ind),3.69 -testCA_3BR_CTZ16,Preset,AOSmithCAHP120,0,0,1691018,1691018,540738,1798679,2231756,3489697,-nan(ind),1.00,3.33,1.56 +testCA_3BR_CTZ16,Preset,RheemPlugInDedicated50,1075466,3298078,0,0,0,0,1075466,3298078,3.07,-nan,-nan,3.07 +testCA_3BR_CTZ16,Preset,RheemPlugInShared40,902116,3357097,0,0,0,0,902116,3357097,3.72,-nan,-nan,3.72 +testCA_3BR_CTZ16,Preset,RheemPlugInShared50,905228,3337523,0,0,0,0,905228,3337523,3.69,-nan,-nan,3.69 +testCA_3BR_CTZ16,Preset,AOSmithCAHP120,0,0,1691018,1691018,540738,1798679,2231756,3489697,-nan,1.00,3.33,1.56 testCA_3BR_CTZ16,Preset,AWHSTier3Generic80,41850,41850,1063562,1063562,852285,2430196,1957697,3535608,1.00,1.00,2.85,1.81 -testCA_36Unit_CTZ12,Preset,QAHV_N136TAU_HPB_SP,25579199,96336852,0,0,0,0,25579199,96336852,3.77,-nan(ind),-nan(ind),3.77 -testCA_36Unit_CTZ12,Preset,ColmacCxV_5_SP,29810230,93675724,0,0,0,0,29810230,93675724,3.14,-nan(ind),-nan(ind),3.14 -testCA_36Unit_CTZ12,Preset,ColmacCxA_10_SP,29863357,97002089,0,0,0,0,29863357,97002089,3.25,-nan(ind),-nan(ind),3.25 -testCA_36Unit_CTZ12,Preset,ColmacCxA_15_SP,37099048,97207160,0,0,0,0,37099048,97207160,2.62,-nan(ind),-nan(ind),2.62 -testCA_36Unit_CTZ12,Preset,ColmacCxA_20_SP,32819045,97554042,0,0,0,0,32819045,97554042,2.97,-nan(ind),-nan(ind),2.97 -testCA_36Unit_CTZ12,Preset,ColmacCxA_25_SP,34181024,97826810,0,0,0,0,34181024,97826810,2.86,-nan(ind),-nan(ind),2.86 -testCA_36Unit_CTZ12,Preset,ColmacCxA_30_SP,34200636,98139446,0,0,0,0,34200636,98139446,2.87,-nan(ind),-nan(ind),2.87 -testCA_36Unit_CTZ12,Preset,NyleC60A_SP,30073563,94790929,0,0,0,0,30073563,94790929,3.15,-nan(ind),-nan(ind),3.15 -testCA_36Unit_CTZ12,Preset,NyleC90A_SP,29066682,96788017,0,0,0,0,29066682,96788017,3.33,-nan(ind),-nan(ind),3.33 -testCA_36Unit_CTZ12,Preset,NyleC185A_SP,29660784,97554366,0,0,0,0,29660784,97554366,3.29,-nan(ind),-nan(ind),3.29 -testCA_36Unit_CTZ12,Preset,NyleC250A_SP,25595635,97547619,0,0,0,0,25595635,97547619,3.81,-nan(ind),-nan(ind),3.81 -testCA_36Unit_CTZ12,Preset,ColmacCxV_5_MP,31681534,87668021,0,0,0,0,31681534,87668021,2.77,-nan(ind),-nan(ind),2.77 -testCA_36Unit_CTZ12,Preset,ColmacCxA_15_MP,44752575,95899338,0,0,0,0,44752575,95899338,2.14,-nan(ind),-nan(ind),2.14 -testCA_36Unit_CTZ12,Preset,ColmacCxA_20_MP,37878323,97052064,0,0,0,0,37878323,97052064,2.56,-nan(ind),-nan(ind),2.56 -testCA_36Unit_CTZ12,Preset,NyleC60A_MP,40596680,89031773,0,0,0,0,40596680,89031773,2.19,-nan(ind),-nan(ind),2.19 -testCA_36Unit_CTZ12,Preset,NyleC185A_MP,42450434,97449918,0,0,0,0,42450434,97449918,2.30,-nan(ind),-nan(ind),2.30 -testCA_36Unit_CTZ12,Preset,NyleC250A_MP,34266642,97496299,0,0,0,0,34266642,97496299,2.85,-nan(ind),-nan(ind),2.85 -testCA_36Unit_CTZ12,Preset,RheemHPHD60,25796227,87357476,0,0,0,0,25796227,87357476,3.39,-nan(ind),-nan(ind),3.39 -testCA_36Unit_CTZ12,Preset,RheemHPHD135,34754223,95520122,0,0,0,0,34754223,95520122,2.75,-nan(ind),-nan(ind),2.75 -testCA_36Unit_CTZ12,Preset,TamScalable_SP,1000,1000,0,0,43439261,110163246,43440261,110164246,1.00,-nan(ind),2.54,2.54 +testCA_36Unit_CTZ12,Preset,QAHV_N136TAU_HPB_SP,25579199,96336852,0,0,0,0,25579199,96336852,3.77,-nan,-nan,3.77 +testCA_36Unit_CTZ12,Preset,ColmacCxV_5_SP,29810230,93675724,0,0,0,0,29810230,93675724,3.14,-nan,-nan,3.14 +testCA_36Unit_CTZ12,Preset,ColmacCxA_10_SP,29863357,97002089,0,0,0,0,29863357,97002089,3.25,-nan,-nan,3.25 +testCA_36Unit_CTZ12,Preset,ColmacCxA_15_SP,37099048,97207160,0,0,0,0,37099048,97207160,2.62,-nan,-nan,2.62 +testCA_36Unit_CTZ12,Preset,ColmacCxA_20_SP,32819045,97554042,0,0,0,0,32819045,97554042,2.97,-nan,-nan,2.97 +testCA_36Unit_CTZ12,Preset,ColmacCxA_25_SP,34181024,97826810,0,0,0,0,34181024,97826810,2.86,-nan,-nan,2.86 +testCA_36Unit_CTZ12,Preset,ColmacCxA_30_SP,34200636,98139446,0,0,0,0,34200636,98139446,2.87,-nan,-nan,2.87 +testCA_36Unit_CTZ12,Preset,NyleC60A_SP,30073563,94790929,0,0,0,0,30073563,94790929,3.15,-nan,-nan,3.15 +testCA_36Unit_CTZ12,Preset,NyleC90A_SP,29066682,96788017,0,0,0,0,29066682,96788017,3.33,-nan,-nan,3.33 +testCA_36Unit_CTZ12,Preset,NyleC185A_SP,29660784,97554366,0,0,0,0,29660784,97554366,3.29,-nan,-nan,3.29 +testCA_36Unit_CTZ12,Preset,NyleC250A_SP,25595635,97547619,0,0,0,0,25595635,97547619,3.81,-nan,-nan,3.81 +testCA_36Unit_CTZ12,Preset,ColmacCxV_5_MP,31681534,87668021,0,0,0,0,31681534,87668021,2.77,-nan,-nan,2.77 +testCA_36Unit_CTZ12,Preset,ColmacCxA_15_MP,44752575,95899338,0,0,0,0,44752575,95899338,2.14,-nan,-nan,2.14 +testCA_36Unit_CTZ12,Preset,ColmacCxA_20_MP,37878323,97052064,0,0,0,0,37878323,97052064,2.56,-nan,-nan,2.56 +testCA_36Unit_CTZ12,Preset,NyleC60A_MP,40596680,89031773,0,0,0,0,40596680,89031773,2.19,-nan,-nan,2.19 +testCA_36Unit_CTZ12,Preset,NyleC185A_MP,42450434,97449918,0,0,0,0,42450434,97449918,2.30,-nan,-nan,2.30 +testCA_36Unit_CTZ12,Preset,NyleC250A_MP,34266642,97496299,0,0,0,0,34266642,97496299,2.85,-nan,-nan,2.85 +testCA_36Unit_CTZ12,Preset,RheemHPHD60,25796227,87357476,0,0,0,0,25796227,87357476,3.39,-nan,-nan,3.39 +testCA_36Unit_CTZ12,Preset,RheemHPHD135,34754223,95520122,0,0,0,0,34754223,95520122,2.75,-nan,-nan,2.75 +testCA_36Unit_CTZ12,Preset,TamScalable_SP,1000,1000,0,0,43439261,110163246,43440261,110164246,1.00,-nan,2.54,2.54 testCA_36Unit_CTZ12,Preset,Scalable_MP,500,500,779200,779200,51100212,104284026,51879912,105063726,1.00,1.00,2.04,2.03 diff --git a/test/testCompressorFcts.cc b/test/testCompressorFcts.cc index c3aff1e1..622bb763 100644 --- a/test/testCompressorFcts.cc +++ b/test/testCompressorFcts.cc @@ -56,7 +56,7 @@ void testGetMinOperatingTemp(string input, double expected) ASSERTTRUE(hpwh.getMinOperatingTemp(HPWH::UNITS_F) == expected); } -int main(int, char*) +int main(int, char**) { const int length = 14; diff --git a/test/testEnergyBalance.cc b/test/testEnergyBalance.cc index 0ddc1669..9dfd7c4d 100644 --- a/test/testEnergyBalance.cc +++ b/test/testEnergyBalance.cc @@ -72,7 +72,7 @@ void testEnergyBalanceSolar() } } -int main(int, char*) +int main(int, char**) { testEnergyBalanceAOSmithHPTS50(); testEnergyBalanceSolar(); diff --git a/test/testHeatingLogics.cc b/test/testHeatingLogics.cc index 2603675f..f5a0cf4f 100644 --- a/test/testHeatingLogics.cc +++ b/test/testHeatingLogics.cc @@ -51,7 +51,7 @@ const std::vector noHighShuttOffVectIntegrated = {"AOSmithHPTU80", "restankRealistic", "StorageTank"}; -int main(int, char*) +int main(int, char**) { double tempsForSetSoC[5][3] = { {49, 99, 125}, {65, 110, 129}, {32, 120, 121}, {32, 33, 121}, {80, 81, 132.5}}; diff --git a/test/testMaxSetpoint.cc b/test/testMaxSetpoint.cc index 2ec8c138..17361657 100644 --- a/test/testMaxSetpoint.cc +++ b/test/testMaxSetpoint.cc @@ -27,7 +27,7 @@ void testSetTankTemps(); const double REMaxShouldBe = 100.; -int main(int, char*) +int main(int, char**) { testMaxSetpointResistanceTank(); testScalableCompressor(); diff --git a/test/testPerformanceMaps.cc b/test/testPerformanceMaps.cc index 67f642fb..f88ced4a 100644 --- a/test/testPerformanceMaps.cc +++ b/test/testPerformanceMaps.cc @@ -650,7 +650,7 @@ void testSanden() ASSERTTRUE(outputBTUH == HPWH::HPWH_ABORT); } -int main(int, char*) +int main(int, char**) { testSanden(); // check can still work with HPWH::getCapacity() as expected diff --git a/test/testResistanceFcts.cc b/test/testResistanceFcts.cc index 480a32d6..980a3c93 100644 --- a/test/testResistanceFcts.cc +++ b/test/testResistanceFcts.cc @@ -250,7 +250,7 @@ void testCommercialTankInit() #undef INITGEN #undef R_TO_RSI -int main(int, char*) +int main(int, char**) { testSetResistanceCapacityErrorChecks(); // Check the resistance reset throws errors when // expected. diff --git a/test/testScaleHPWH.cc b/test/testScaleHPWH.cc index f199c633..49d58eb6 100644 --- a/test/testScaleHPWH.cc +++ b/test/testScaleHPWH.cc @@ -544,7 +544,7 @@ void testStorageTankErrors() ASSERTTRUE(hpwh.setScaleHPWHCapacityCOP(1., 1.) == HPWH::HPWH_ABORT); } -int main(int, char*) +int main(int, char**) { testSetMPCompressorOutputCapacity(); diff --git a/test/testSizingFractions.cc b/test/testSizingFractions.cc index 9a3664d6..2053922b 100644 --- a/test/testSizingFractions.cc +++ b/test/testSizingFractions.cc @@ -26,7 +26,7 @@ void testResTankSizingFract(); void testStoTankSizingFract(); void testGetCompressorMinRuntime(); -int main(int, char*) +int main(int, char**) { testScalableSizingFract(); testSandenSizingFract(); From abec7ed732aaadbe285ec0bb07be836cc7fb984e Mon Sep 17 00:00:00 2001 From: Neal Kruis Date: Fri, 22 Dec 2023 14:06:49 -0700 Subject: [PATCH 02/15] Update .gitignore. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 9d449f14..6ebbaa7e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ *.o *.x *.png +.idea +.vscode .Rproj.user *TestToolOutput.csv !Documentation/** From 81d7873a464260bb31ca025a73f740bd15c1ec4d Mon Sep 17 00:00:00 2001 From: Neal Kruis Date: Fri, 22 Dec 2023 14:10:23 -0700 Subject: [PATCH 03/15] Format CMakeLists.txt files. --- CMakeLists.txt | 36 +-- src/CMakeLists.txt | 36 +-- test/CMakeLists.txt | 617 ++++++++++++++++++++++---------------------- 3 files changed, 345 insertions(+), 344 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a3efe2e0..37039809 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,32 +4,32 @@ cmake_minimum_required(VERSION 3.5) enable_testing() -set (CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") +set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") # Set a default build type if none was specified -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "Setting build type to 'Release' as none was specified.") - set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) - # Set the possible values of build type for cmake-gui - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" - "MinSizeRel" "RelWithDebInfo") -endif() - -if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wshadow") -elseif(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") -endif() +if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to 'Release' as none was specified.") + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" + "MinSizeRel" "RelWithDebInfo") +endif () + +if (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wshadow") +elseif (MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") +endif () find_package(Git QUIET) if (HPWHSIM_ABRIDGED) - add_compile_definitions( HPWH_ABRIDGED) -endif() + add_compile_definitions(HPWH_ABRIDGED) +endif () add_subdirectory(vendor) add_subdirectory(src) if (NOT HPWHSIM_OMIT_TESTTOOL) - add_subdirectory(test) -endif() + add_subdirectory(test) +endif () diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0be9497d..62a95fc3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,33 +1,33 @@ # Set HPWHsim Version add_custom_target(${PROJECT_NAME}_version_header - DEPENDS ${PROJECT_SOURCE_DIR}/src/HPWHversion.in.hh - COMMAND ${CMAKE_COMMAND} - ARGS -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR} - -DPROJECT_BINARY_DIR=${PROJECT_BINARY_DIR} - -DPROJECT_NAME=${PROJECT_NAME} - -DGIT_EXECUTABLE=${GIT_EXECUTABLE} - -P "${PROJECT_SOURCE_DIR}/cmake/git-version.cmake" -) + DEPENDS ${PROJECT_SOURCE_DIR}/src/HPWHversion.in.hh + COMMAND ${CMAKE_COMMAND} + ARGS -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR} + -DPROJECT_BINARY_DIR=${PROJECT_BINARY_DIR} + -DPROJECT_NAME=${PROJECT_NAME} + -DGIT_EXECUTABLE=${GIT_EXECUTABLE} + -P "${PROJECT_SOURCE_DIR}/cmake/git-version.cmake" + ) set_target_properties(${PROJECT_NAME}_version_header PROPERTIES FOLDER Dependencies/HPWHsim) set(headers - HPWHversion.in.hh - HPWH.hh -) + HPWHversion.in.hh + HPWH.hh + ) set(source - HPWHversion.cc - HPWH.cc - HPWHHeatSources.cc - HPWHHeatingLogics.cc - HPWHpresets.cc -) + HPWHversion.cc + HPWH.cc + HPWHHeatSources.cc + HPWHHeatingLogics.cc + HPWHpresets.cc + ) add_library(libHPWHsim ${source} ${headers}) target_include_directories(libHPWHsim PUBLIC ${PROJECT_BINARY_DIR}/src ${PROJECT_SOURCE_DIR}/src) -target_link_libraries( libHPWHsim PUBLIC btwxt) +target_link_libraries(libHPWHsim PUBLIC btwxt) add_dependencies(libHPWHsim ${PROJECT_NAME}_version_header) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b87a097e..61f4d023 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,7 @@ # Build test tool include_directories("${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}/src") -add_executable(testTool main.cc ) +add_executable(testTool main.cc) add_executable(testTankSizeFixed testTankSizeFixed.cc) add_executable(testScaleHPWH testScaleHPWH.cc) add_executable(testMaxSetpoint testMaxSetpoint.cc) @@ -14,9 +14,10 @@ add_executable(testHeatingLogics testHeatingLogics.cc) add_executable(testEnergyBalance testEnergyBalance.cc) set(libs - libHPWHsim - btwxt -) + libHPWHsim + btwxt + ) + target_link_libraries(testTool ${libs}) target_link_libraries(testTankSizeFixed ${libs}) target_link_libraries(testScaleHPWH ${libs}) @@ -37,15 +38,15 @@ add_custom_target(results_directory ALL COMMAND ${CMAKE_COMMAND} -E make_directo add_test(NAME "Ready.Output.Files" COMMAND ${CMAKE_COMMAND} -E remove "${CMAKE_CURRENT_BINARY_DIR}/output/DHW_YRLY.csv") # Run Unit tests -add_test(NAME "testScaleHPWH" COMMAND $ ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) -add_test(NAME "testMaxSetpoint" COMMAND $ ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) -add_test(NAME "testSizingFractions" COMMAND $ ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) -add_test(NAME "testResistanceFcts" COMMAND $ ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) -add_test(NAME "testCompressorFcts" COMMAND $ ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) -add_test(NAME "testPerformanceMaps" COMMAND $ ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) -add_test(NAME "testStateOfChargeFcts" COMMAND $ ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) -add_test(NAME "testHeatingLogics" COMMAND $ ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) -add_test(NAME "testEnergyBalance" COMMAND $ ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +add_test(NAME "testScaleHPWH" COMMAND $ ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +add_test(NAME "testMaxSetpoint" COMMAND $ ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +add_test(NAME "testSizingFractions" COMMAND $ ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +add_test(NAME "testResistanceFcts" COMMAND $ ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +add_test(NAME "testCompressorFcts" COMMAND $ ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +add_test(NAME "testPerformanceMaps" COMMAND $ ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +add_test(NAME "testStateOfChargeFcts" COMMAND $ ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +add_test(NAME "testHeatingLogics" COMMAND $ ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +add_test(NAME "testEnergyBalance" COMMAND $ ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) #add_test(NAME "testREGoesTo99C.AOSmithCAHP120" COMMAND $ "Preset" "AOSmithCAHP120" "testREGoesTo99C" #"${CMAKE_CURRENT_BINARY_DIR}/output" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) @@ -54,351 +55,351 @@ add_test(NAME "testEnergyBalance" COMMAND $ ${te # Run model tests and unit tests on models set(testNames - test30 - test50 - test70 - test95 - testLockout - testSandenCombi - testDr_LO - testDr_TOO - testDr_TOT - testDr_TOO2 - testDR_TOTLOR -) + test30 + test50 + test70 + test95 + testLockout + testSandenCombi + testDr_LO + testDr_TOO + testDr_TOT + testDr_TOO2 + testDR_TOTLOR + ) set(modelNames -# StorageTank - AOSmithHPTS50 - AOSmithPHPT60 - AOSmithHPTU80 - Sanden80 - RheemHB50 - Stiebel220e - GE502014 - Rheem2020Prem40 - Rheem2020Prem50 - Rheem2020Build50 -# RheemPlugInDedicated50 -) + # StorageTank + AOSmithHPTS50 + AOSmithPHPT60 + AOSmithHPTU80 + Sanden80 + RheemHB50 + Stiebel220e + GE502014 + Rheem2020Prem40 + Rheem2020Prem50 + Rheem2020Build50 + # RheemPlugInDedicated50 + ) set(lockoutTestModels - AOSmithPHPT60 - AOSmithHPTU80 - RheemHB50 - Stiebel220e - GE502014 -) - -set(yearTestsModels - AOSmithHPTU80 - Sanden80 - GE502014 - Rheem2020Prem40 - Rheem2020Prem50 - Rheem2020Build50 - RheemPlugInDedicated50 - RheemPlugInShared40 - RheemPlugInShared50 - AOSmithCAHP120 - AWHSTier3Generic80 -) -set(yearTests - testCA_3BR_CTZ15 - testCA_3BR_CTZ16 -) - -set(maxTempModels - AOSmithHPTU80 - Rheem2020Build50 - RheemHB50 - Stiebel220e - GE502014 - TamScalable_SP - AOSmithCAHP120 -) + AOSmithPHPT60 + AOSmithHPTU80 + RheemHB50 + Stiebel220e + GE502014 + ) + +set(yearTestsModels + AOSmithHPTU80 + Sanden80 + GE502014 + Rheem2020Prem40 + Rheem2020Prem50 + Rheem2020Build50 + RheemPlugInDedicated50 + RheemPlugInShared40 + RheemPlugInShared50 + AOSmithCAHP120 + AWHSTier3Generic80 + ) +set(yearTests + testCA_3BR_CTZ15 + testCA_3BR_CTZ16 + ) + +set(maxTempModels + AOSmithHPTU80 + Rheem2020Build50 + RheemHB50 + Stiebel220e + GE502014 + TamScalable_SP + AOSmithCAHP120 + ) set(maxTempTests - testREGoesTo93C - testREGoesTo93CCold -) + testREGoesTo93C + testREGoesTo93CCold + ) set(largeCompressorTests - testLargeComp45 - testLargeComp60 - testLargeCompHot -) + testLargeComp45 + testLargeComp60 + testLargeCompHot + ) set(largeCompressorNames - QAHV_N136TAU_HPB_SP - - AOSmithCAHP120 - ColmacCxV_5_SP - ColmacCxA_10_SP - ColmacCxA_15_SP - ColmacCxA_20_SP - ColmacCxA_25_SP - ColmacCxA_30_SP - - ColmacCxV_5_MP - ColmacCxA_20_MP - RheemHPHD60 - RheemHPHD135 - - NyleC25A_SP - NyleC90A_SP - NyleC185A_SP - NyleC250A_SP - NyleC90A_C_SP - NyleC185A_C_SP - NyleC250A_C_SP - - NyleC90A_MP - NyleC250A_MP - - NyleC90A_C_MP - NyleC250A_C_MP - - TamScalable_SP_Half - #Scalable_MP -) - -set(yearLargeTestsModels - QAHV_N136TAU_HPB_SP - - ColmacCxV_5_SP - ColmacCxA_10_SP - ColmacCxA_15_SP - ColmacCxA_20_SP - ColmacCxA_25_SP - ColmacCxA_30_SP - NyleC60A_SP - NyleC90A_SP - NyleC185A_SP - NyleC250A_SP - - ColmacCxV_5_MP - ColmacCxA_15_MP - ColmacCxA_20_MP - - NyleC60A_MP - NyleC185A_MP - NyleC250A_MP - - RheemHPHD60 - RheemHPHD135 - TamScalable_SP - Scalable_MP -) + QAHV_N136TAU_HPB_SP + + AOSmithCAHP120 + ColmacCxV_5_SP + ColmacCxA_10_SP + ColmacCxA_15_SP + ColmacCxA_20_SP + ColmacCxA_25_SP + ColmacCxA_30_SP + + ColmacCxV_5_MP + ColmacCxA_20_MP + RheemHPHD60 + RheemHPHD135 + + NyleC25A_SP + NyleC90A_SP + NyleC185A_SP + NyleC250A_SP + NyleC90A_C_SP + NyleC185A_C_SP + NyleC250A_C_SP + + NyleC90A_MP + NyleC250A_MP + + NyleC90A_C_MP + NyleC250A_C_MP + + TamScalable_SP_Half + #Scalable_MP + ) + +set(yearLargeTestsModels + QAHV_N136TAU_HPB_SP + + ColmacCxV_5_SP + ColmacCxA_10_SP + ColmacCxA_15_SP + ColmacCxA_20_SP + ColmacCxA_25_SP + ColmacCxA_30_SP + NyleC60A_SP + NyleC90A_SP + NyleC185A_SP + NyleC250A_SP + + ColmacCxV_5_MP + ColmacCxA_15_MP + ColmacCxA_20_MP + + NyleC60A_MP + NyleC185A_MP + NyleC250A_MP + + RheemHPHD60 + RheemHPHD135 + TamScalable_SP + Scalable_MP + ) set(heatExchangeModelNames - AquaThermAire -) + AquaThermAire + ) set(heatExchangeTests - villara_24hr67 -) -set(yearLargeTests - testCA_36Unit_CTZ12 -) + villara_24hr67 + ) +set(yearLargeTests + testCA_36Unit_CTZ12 + ) set(stateOfChargeTests - testSoC70 - testSoCLockout - testSoCHighEnteringWater - testSoCSetpointChange -) + testSoC70 + testSoCLockout + testSoCHighEnteringWater + testSoCSetpointChange + ) set(stateOfChargeCompressorNames - Sanden120 - NyleC25A_SP -) + Sanden120 + NyleC25A_SP + ) list(APPEND extendedModelNames ${modelNames} ${heatExchangeModelNames}) list(REMOVE_DUPLICATES extendedModelNames) # Unit tests -function( add_TankSizeFixed_test ) - set(options) - set(oneValueArgs MODEL_NAME) - set(multValueArgs) - cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) +function(add_TankSizeFixed_test) + set(options) + set(oneValueArgs MODEL_NAME) + set(multValueArgs) + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - set(testArgs "${ARG_MODEL_NAME}") + set(testArgs "${ARG_MODEL_NAME}") - set(TEST_TITLE "TankSizeFixed.${ARG_MODEL_NAME}") + set(TEST_TITLE "TankSizeFixed.${ARG_MODEL_NAME}") - add_test(NAME "${TEST_TITLE}" COMMAND $ ${testArgs} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + add_test(NAME "${TEST_TITLE}" COMMAND $ ${testArgs} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) endfunction() -foreach(model ${extendedModelNames}) - add_TankSizeFixed_test( MODEL_NAME "${model}") -endforeach(model) -foreach(model ${largeCompressorNames}) - add_TankSizeFixed_test( MODEL_NAME "${model}") -endforeach(model) +foreach (model ${extendedModelNames}) + add_TankSizeFixed_test(MODEL_NAME "${model}") +endforeach (model) +foreach (model ${largeCompressorNames}) + add_TankSizeFixed_test(MODEL_NAME "${model}") +endforeach (model) #Tests for successful runs -function( add_model_test ) - set(options) - set(oneValueArgs INP_SOURCE MODEL_NAME TEST_NAME) - set(multValueArgs) - cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) - - set(testToolArgs "${ARG_INP_SOURCE}" "${ARG_MODEL_NAME}" "${ARG_TEST_NAME}" "${CMAKE_CURRENT_BINARY_DIR}/output") - - if(${ARG_TEST_NAME} STREQUAL "testLockout") - if( ${ARG_MODEL_NAME} STREQUAL "AOSmithPHPT60" ) - set(airTemp "48") - elseif( ${ARG_MODEL_NAME} STREQUAL "AOSmithHPTU80" ) - set(airTemp "45") - elseif( ${ARG_MODEL_NAME} STREQUAL "RheemHB50" ) - set(airTemp "43") - elseif( ${ARG_MODEL_NAME} STREQUAL "Stiebel220e" ) - set(airTemp "35") - elseif( ${ARG_MODEL_NAME} STREQUAL "GE502014" ) - set(airTemp "40") - else() - return() - endif() - set(testToolArgs ${testToolArgs} ${airTemp}) - endif() - - set(TEST_TITLE "ModelTest.${ARG_TEST_NAME}.${ARG_MODEL_NAME}.${ARG_INP_SOURCE}") - - add_test(NAME "${TEST_TITLE}" COMMAND $ ${testToolArgs} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - ) +function(add_model_test) + set(options) + set(oneValueArgs INP_SOURCE MODEL_NAME TEST_NAME) + set(multValueArgs) + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + set(testToolArgs "${ARG_INP_SOURCE}" "${ARG_MODEL_NAME}" "${ARG_TEST_NAME}" "${CMAKE_CURRENT_BINARY_DIR}/output") + + if (${ARG_TEST_NAME} STREQUAL "testLockout") + if (${ARG_MODEL_NAME} STREQUAL "AOSmithPHPT60") + set(airTemp "48") + elseif (${ARG_MODEL_NAME} STREQUAL "AOSmithHPTU80") + set(airTemp "45") + elseif (${ARG_MODEL_NAME} STREQUAL "RheemHB50") + set(airTemp "43") + elseif (${ARG_MODEL_NAME} STREQUAL "Stiebel220e") + set(airTemp "35") + elseif (${ARG_MODEL_NAME} STREQUAL "GE502014") + set(airTemp "40") + else () + return() + endif () + set(testToolArgs ${testToolArgs} ${airTemp}) + endif () + + set(TEST_TITLE "ModelTest.${ARG_TEST_NAME}.${ARG_MODEL_NAME}.${ARG_INP_SOURCE}") + + add_test(NAME "${TEST_TITLE}" COMMAND $ ${testToolArgs} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) endfunction() -foreach(test ${testNames}) - foreach(model ${modelNames}) - add_model_test( TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") - add_model_test( TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "File") - endforeach(model) -endforeach(test) +foreach (test ${testNames}) + foreach (model ${modelNames}) + add_model_test(TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") + add_model_test(TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "File") + endforeach (model) +endforeach (test) #Test(s) specifically for heat-exchange models -foreach(test ${heatExchangeTests}) - foreach(model ${heatExchangeModelNames}) - add_model_test( TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") - add_model_test( TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "File") - endforeach(model) -endforeach(test) - -#Test models follow control logic with max temperatures. -foreach(test ${maxTempTests}) - foreach(model ${maxTempModels}) - add_model_test( TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") - endforeach(model) -endforeach(test) +foreach (test ${heatExchangeTests}) + foreach (model ${heatExchangeModelNames}) + add_model_test(TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") + add_model_test(TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "File") + endforeach (model) +endforeach (test) + +#Test models follow control logic with max temperatures. +foreach (test ${maxTempTests}) + foreach (model ${maxTempModels}) + add_model_test(TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") + endforeach (model) +endforeach (test) #Add large compressor tests to the list -foreach(test ${largeCompressorTests}) - foreach(model ${largeCompressorNames}) - add_model_test( TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") - #No files for these yet - #add_model_test( TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "File") - endforeach(model) -endforeach(test) +foreach (test ${largeCompressorTests}) + foreach (model ${largeCompressorNames}) + add_model_test(TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") + #No files for these yet + #add_model_test( TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "File") + endforeach (model) +endforeach (test) #Add State of Charge tests to the list -foreach(test ${stateOfChargeTests}) - foreach(model ${stateOfChargeCompressorNames}) - add_model_test( TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") - #No files for these yet - #add_model_test( TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "File") - endforeach(model) -endforeach(test) +foreach (test ${stateOfChargeTests}) + foreach (model ${stateOfChargeCompressorNames}) + add_model_test(TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") + #No files for these yet + #add_model_test( TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "File") + endforeach (model) +endforeach (test) #Add small compressor yearly tests to the list -foreach(test ${yearTests}) - foreach(model ${yearTestsModels}) - add_model_test( TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") - endforeach(model) -endforeach(test) +foreach (test ${yearTests}) + foreach (model ${yearTestsModels}) + add_model_test(TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") + endforeach (model) +endforeach (test) #Add LARGE compressor yearly tests to the list -foreach(test ${yearLargeTests}) - foreach(model ${yearLargeTestsModels}) - add_model_test( TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") - endforeach(model) -endforeach(test) +foreach (test ${yearLargeTests}) + foreach (model ${yearLargeTestsModels}) + add_model_test(TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") + endforeach (model) +endforeach (test) # Tests for differences between File and Preset versions -function( add_file_test ) - set(options) - set(oneValueArgs MODEL_NAME TEST_NAME) - set(multValueArgs) - cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) - - if ((${ARG_TEST_NAME} STREQUAL "testLockout") AND (NOT ${ARG_MODEL_NAME} IN_LIST lockoutTestModels)) - return() - endif() - - set(TEST_TITLE "FileTest.${ARG_TEST_NAME}.${ARG_MODEL_NAME}") - - add_test(NAME "${TEST_TITLE}" COMMAND ${CMAKE_COMMAND} -E compare_files "${CMAKE_CURRENT_BINARY_DIR}/output/${ARG_TEST_NAME}_File_${ARG_MODEL_NAME}.csv" "${CMAKE_CURRENT_BINARY_DIR}/output/${ARG_TEST_NAME}_Preset_${ARG_MODEL_NAME}.csv" - ) - set_property(TEST "${TEST_TITLE}" APPEND PROPERTY DEPENDS "ModelTest.${ARG_TEST_NAME}.${ARG_MODEL_NAME}.File") - set_property(TEST "${TEST_TITLE}" APPEND PROPERTY DEPENDS "ModelTest.${ARG_TEST_NAME}.${ARG_MODEL_NAME}.Preset") +function(add_file_test) + set(options) + set(oneValueArgs MODEL_NAME TEST_NAME) + set(multValueArgs) + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if ((${ARG_TEST_NAME} STREQUAL "testLockout") AND (NOT ${ARG_MODEL_NAME} IN_LIST lockoutTestModels)) + return() + endif () + + set(TEST_TITLE "FileTest.${ARG_TEST_NAME}.${ARG_MODEL_NAME}") + + add_test(NAME "${TEST_TITLE}" COMMAND ${CMAKE_COMMAND} -E compare_files "${CMAKE_CURRENT_BINARY_DIR}/output/${ARG_TEST_NAME}_File_${ARG_MODEL_NAME}.csv" "${CMAKE_CURRENT_BINARY_DIR}/output/${ARG_TEST_NAME}_Preset_${ARG_MODEL_NAME}.csv" + ) + set_property(TEST "${TEST_TITLE}" APPEND PROPERTY DEPENDS "ModelTest.${ARG_TEST_NAME}.${ARG_MODEL_NAME}.File") + set_property(TEST "${TEST_TITLE}" APPEND PROPERTY DEPENDS "ModelTest.${ARG_TEST_NAME}.${ARG_MODEL_NAME}.Preset") endfunction() -foreach(test ${testNames}) - foreach(model ${modelNames}) - add_file_test( TEST_NAME "${test}" MODEL_NAME "${model}") - endforeach(model) -endforeach(test) +foreach (test ${testNames}) + foreach (model ${modelNames}) + add_file_test(TEST_NAME "${test}" MODEL_NAME "${model}") + endforeach (model) +endforeach (test) #Test(s) specifically for heat-exchange models -foreach(test ${heatExchangeTests}) - foreach(model ${heatExchangeModelNames}) - add_file_test( TEST_NAME "${test}" MODEL_NAME "${model}") - endforeach(model) -endforeach(test) +foreach (test ${heatExchangeTests}) + foreach (model ${heatExchangeModelNames}) + add_file_test(TEST_NAME "${test}" MODEL_NAME "${model}") + endforeach (model) +endforeach (test) # Tests for regression differences against reference results -function( add_regression_test ) - set(options) - set(oneValueArgs INP_SOURCE MODEL_NAME TEST_NAME) - set(multValueArgs) - cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) - - if ((${ARG_TEST_NAME} STREQUAL "testLockout") AND (NOT ${ARG_MODEL_NAME} IN_LIST lockoutTestModels)) - return() - endif() - - set(TEST_TITLE "RegressionTest.${ARG_TEST_NAME}.${ARG_MODEL_NAME}.${ARG_INP_SOURCE}") - - add_test(NAME "${TEST_TITLE}" COMMAND ${CMAKE_COMMAND} -E compare_files "${CMAKE_CURRENT_BINARY_DIR}/output/${ARG_TEST_NAME}_${ARG_INP_SOURCE}_${ARG_MODEL_NAME}.csv" "${CMAKE_CURRENT_SOURCE_DIR}/ref/${ARG_TEST_NAME}_${ARG_INP_SOURCE}_${ARG_MODEL_NAME}.csv" - ) - set_property(TEST "${TEST_TITLE}" APPEND PROPERTY DEPENDS "ModelTest.${ARG_TEST_NAME}.${ARG_MODEL_NAME}.File") - set_property(TEST "${TEST_TITLE}" APPEND PROPERTY DEPENDS "ModelTest.${ARG_TEST_NAME}.${ARG_MODEL_NAME}.Preset") +function(add_regression_test) + set(options) + set(oneValueArgs INP_SOURCE MODEL_NAME TEST_NAME) + set(multValueArgs) + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if ((${ARG_TEST_NAME} STREQUAL "testLockout") AND (NOT ${ARG_MODEL_NAME} IN_LIST lockoutTestModels)) + return() + endif () + + set(TEST_TITLE "RegressionTest.${ARG_TEST_NAME}.${ARG_MODEL_NAME}.${ARG_INP_SOURCE}") + + add_test(NAME "${TEST_TITLE}" COMMAND ${CMAKE_COMMAND} -E compare_files "${CMAKE_CURRENT_BINARY_DIR}/output/${ARG_TEST_NAME}_${ARG_INP_SOURCE}_${ARG_MODEL_NAME}.csv" "${CMAKE_CURRENT_SOURCE_DIR}/ref/${ARG_TEST_NAME}_${ARG_INP_SOURCE}_${ARG_MODEL_NAME}.csv" + ) + set_property(TEST "${TEST_TITLE}" APPEND PROPERTY DEPENDS "ModelTest.${ARG_TEST_NAME}.${ARG_MODEL_NAME}.File") + set_property(TEST "${TEST_TITLE}" APPEND PROPERTY DEPENDS "ModelTest.${ARG_TEST_NAME}.${ARG_MODEL_NAME}.Preset") endfunction() -foreach(test ${testNames}) - foreach(model ${modelNames}) - add_regression_test( TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") - add_regression_test( TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "File") - endforeach(model) -endforeach(test) +foreach (test ${testNames}) + foreach (model ${modelNames}) + add_regression_test(TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") + add_regression_test(TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "File") + endforeach (model) +endforeach (test) #Add max temp tests to the regression list -foreach(test ${maxTempTests}) - foreach(model ${maxTempModels}) - add_regression_test( TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") - endforeach(model) -endforeach(test) +foreach (test ${maxTempTests}) + foreach (model ${maxTempModels}) + add_regression_test(TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") + endforeach (model) +endforeach (test) #Add large compressor tests to the regression list -foreach(test ${largeCompressorTests}) - foreach(model ${largeCompressorNames}) - add_regression_test( TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") - endforeach(model) -endforeach(test) +foreach (test ${largeCompressorTests}) + foreach (model ${largeCompressorNames}) + add_regression_test(TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") + endforeach (model) +endforeach (test) #Add State of Charge tests to the list -foreach(test ${stateOfChargeTests}) - foreach(model ${stateOfChargeCompressorNames}) - add_regression_test( TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") - endforeach(model) -endforeach(test) - -#Add regression test for yearly file -add_test(NAME "RegressionTest.YearRuns" COMMAND ${CMAKE_COMMAND} -E compare_files "${CMAKE_CURRENT_BINARY_DIR}/output/DHW_YRLY.csv" "${CMAKE_CURRENT_SOURCE_DIR}/ref/DHW_YRLY.csv") \ No newline at end of file +foreach (test ${stateOfChargeTests}) + foreach (model ${stateOfChargeCompressorNames}) + add_regression_test(TEST_NAME "${test}" MODEL_NAME "${model}" INP_SOURCE "Preset") + endforeach (model) +endforeach (test) + +#Add regression test for yearly file +add_test(NAME "RegressionTest.YearRuns" COMMAND ${CMAKE_COMMAND} -E compare_files "${CMAKE_CURRENT_BINARY_DIR}/output/DHW_YRLY.csv" "${CMAKE_CURRENT_SOURCE_DIR}/ref/DHW_YRLY.csv") From 101f85ad4b4c113896931f4b26ee0eda9ad9cdc6 Mon Sep 17 00:00:00 2001 From: Neal Kruis Date: Fri, 22 Dec 2023 15:18:37 -0700 Subject: [PATCH 04/15] Clean up clang warnings and fix formatting. --- .../{CI_with_Cmake.yml => build-and-test.yml} | 0 src/HPWH.cc | 35 ++++++++++--------- src/HPWH.hh | 8 +++-- src/HPWHHeatSources.cc | 20 +++++------ src/HPWHversion.cc | 2 +- 5 files changed, 34 insertions(+), 31 deletions(-) rename .github/workflows/{CI_with_Cmake.yml => build-and-test.yml} (100%) diff --git a/.github/workflows/CI_with_Cmake.yml b/.github/workflows/build-and-test.yml similarity index 100% rename from .github/workflows/CI_with_Cmake.yml rename to .github/workflows/build-and-test.yml diff --git a/src/HPWH.cc b/src/HPWH.cc index 3d4e8d63..597a49a0 100644 --- a/src/HPWH.cc +++ b/src/HPWH.cc @@ -322,7 +322,7 @@ void HPWH::setMinutesPerStep(const double minutesPerStep_in) }; // public HPWH functions -HPWH::HPWH() : messageCallback(NULL), messageCallbackContextPtr(NULL), hpwhVerbosity(VRB_silent) +HPWH::HPWH() : hpwhVerbosity(VRB_silent), messageCallback(NULL), messageCallbackContextPtr(NULL) { setAllDefaults(); }; @@ -1114,14 +1114,17 @@ void HPWH::printTankTemps() } // public members to write to CSV file -int HPWH::WriteCSVHeading(std::ofstream& outFILE, const char* preamble, int nTCouples, int options) const +int HPWH::WriteCSVHeading(std::ofstream& outFILE, + const char* preamble, + int nTCouples, + int options) const { bool doIP = (options & CSVOPT_IPUNITS) != 0; outFILE << preamble; - outFILE << "DRstatus"; + outFILE << "DRstatus"; for (int iHS = 0; iHS < getNumHeatSources(); iHS++) { @@ -1138,7 +1141,10 @@ int HPWH::WriteCSVHeading(std::ofstream& outFILE, const char* preamble, int nTCo return 0; } -int HPWH::WriteCSVRow(std::ofstream& outFILE, const char* preamble, int nTCouples, int options) const +int HPWH::WriteCSVRow(std::ofstream& outFILE, + const char* preamble, + int nTCouples, + int options) const { bool doIP = (options & CSVOPT_IPUNITS) != 0; @@ -1147,17 +1153,17 @@ int HPWH::WriteCSVRow(std::ofstream& outFILE, const char* preamble, int nTCouple outFILE << prevDRstatus; - for (int iHS = 0; iHS < getNumHeatSources(); iHS++) { outFILE << fmt::format(",{:0.2f},{:0.2f}", - getNthHeatSourceEnergyInput(iHS, UNITS_KWH) * 1000., - getNthHeatSourceEnergyOutput(iHS, UNITS_KWH) * 1000.); + getNthHeatSourceEnergyInput(iHS, UNITS_KWH) * 1000., + getNthHeatSourceEnergyOutput(iHS, UNITS_KWH) * 1000.); } for (int iTC = 0; iTC < nTCouples; iTC++) { - outFILE << fmt::format(",{:0.2f}", getNthSimTcouple(iTC + 1, nTCouples, doIP ? UNITS_F : UNITS_C)); + outFILE << fmt::format(",{:0.2f}", + getNthSimTcouple(iTC + 1, nTCouples, doIP ? UNITS_F : UNITS_C)); } if (options & HPWH::CSVOPT_IS_DRAWING) @@ -1247,15 +1253,12 @@ double HPWH::getMaxCompressorSetpoint(UNITS units /*=UNITS_C*/) const } double returnVal = heatSources[compressorIndex].maxSetpoint_C; - if (units == UNITS_C) - { - returnVal = returnVal; - } - else if (units == UNITS_F) + + if (units == UNITS_F) { returnVal = C_TO_F(returnVal); } - else + else if (units != UNITS_C) { if (hpwhVerbosity >= VRB_reluctant) { @@ -4771,9 +4774,8 @@ int HPWH::HPWHinit_file(string configFile) } else { - for (auto n : nodeNums) + for ([[maybe_unused]] auto n : nodeNums) { - n += 0; // used to get rid of unused variable compiler warning weights.push_back(1.0); } } @@ -5203,6 +5205,7 @@ int HPWH::HPWHinit_file(string configFile) string var = match[1].str(); nTemps = std::stoi(match[2].str()); string coeff = match[3].str(); + int coeff_num; if (coeff == "const") { diff --git a/src/HPWH.hh b/src/HPWH.hh index e83f2b9f..ab9a0983 100644 --- a/src/HPWH.hh +++ b/src/HPWH.hh @@ -324,11 +324,13 @@ class HPWH std::function c, bool isHTS) : description(desc) + , compare(c) , decisionPoint(decisionPoint_in) , hpwh(hpwh_in) - , compare(c) , isEnteringWaterHighTempShutoff(isHTS) {}; + virtual ~HeatingLogic() = default; + /**< checks that the input is all valid. */ virtual const bool isValid() = 0; /**< gets the value for comparing the tank value to, i.e. the target SoC */ @@ -362,8 +364,8 @@ class HPWH double mains_C = 18.333, std::function c = std::less()) : HeatingLogic(desc, decisionPoint, hpwh, c, false) - , hysteresisFraction(hF) , tempMinUseful_C(tM_C) + , hysteresisFraction(hF) , useCostantMains(constMains) , constantMains_C(mains_C) {}; const bool isValid(); @@ -394,7 +396,7 @@ class HPWH bool a = false, std::function c = std::less(), bool isHTS = false) - : HeatingLogic(desc, decisionPoint, hpwh, c, isHTS), nodeWeights(n), isAbsolute(a) {}; + : HeatingLogic(desc, decisionPoint, hpwh, c, isHTS), isAbsolute(a), nodeWeights(n) {}; const bool isValid(); diff --git a/src/HPWHHeatSources.cc b/src/HPWHHeatSources.cc index e193e7f7..d555318a 100644 --- a/src/HPWHHeatSources.cc +++ b/src/HPWHHeatSources.cc @@ -19,21 +19,21 @@ HPWH::HeatSource::HeatSource(HPWH* parentInput) , backupHeatSource(NULL) , companionHeatSource(NULL) , followedByHeatSource(NULL) + , useBtwxtGrid(false) + , standbyLogic(NULL) + , maxOut_at_LowT {100, -273.15} + , secondaryHeatExchanger {0., 0., 0.} , minT(-273.15) , maxT(100) + , maxSetpoint_C(100.) , hysteresis_dC(0) , airflowFreedom(1.0) - , maxSetpoint_C(100.) - , typeOfHeatSource(TYPE_none) - , extrapolationMethod(EXTRAP_LINEAR) - , maxOut_at_LowT {100, -273.15} - , standbyLogic(NULL) - , isMultipass(true) - , mpFlowRate_LPS(0.) , externalInletHeight(-1) , externalOutletHeight(-1) - , useBtwxtGrid(false) - , secondaryHeatExchanger {0., 0., 0.} + , mpFlowRate_LPS(0.) + , typeOfHeatSource(TYPE_none) + , isMultipass(true) + , extrapolationMethod(EXTRAP_LINEAR) { } @@ -802,10 +802,8 @@ void HPWH::HeatSource::getCapacityMP(double externalT_C, else { // Get bounding performance map points for interpolation/extrapolation - bool extrapolate = false; if (externalT_F > perfMap[0].T_F) { - extrapolate = true; if (extrapolationMethod == EXTRAP_NEAREST) { externalT_F = perfMap[0].T_F; diff --git a/src/HPWHversion.cc b/src/HPWHversion.cc index 50d30efc..7e03d765 100644 --- a/src/HPWHversion.cc +++ b/src/HPWHversion.cc @@ -2,7 +2,7 @@ * Version control */ -#include "HPWHVersion.hh" +#include "HPWHversion.hh" #include "HPWH.hh" // ugh, this should be in the header From dfc4cff16409a33d76abf8dae48cf213ad04df74 Mon Sep 17 00:00:00 2001 From: Neal Kruis Date: Fri, 22 Dec 2023 15:19:36 -0700 Subject: [PATCH 05/15] Update GitHub Actions workflow. --- .github/workflows/build-and-test.yml | 128 ++++++++++++++++++--------- 1 file changed, 85 insertions(+), 43 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index da469032..904c11a0 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -1,49 +1,91 @@ -# Started cmake workflow: https://github.com/actions/starter-workflows/pull/47/files +name: Build and Test -name: Cmake CI +on: push -# Controls when the action will run. -# Triggers the workflow on push or pull request events -on: [push, pull_request] - -env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) - BUILD_TYPE: Release - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ${{ matrix.os }} + build-and-test: strategy: + fail-fast: false matrix: - os: [windows-latest] - - # Steps represent a sequence of tasks that will be executed as part of the job + include: + - os: ubuntu + os_ver: "22.04" + config: Release + coverage: false + cc: gcc-11 + cxx: g++-11 + - os: ubuntu + os_ver: "20.04" + config: Release + coverage: false + cc: gcc-10 + cxx: g++-10 + - os: windows + os_ver: "2022" + config: Release + coverage: false + cc: cl + cxx: cl + - os: macos + os_ver: "12" + config: Release + coverage: false + cc: clang + cxx: clang++ + - os: macos + os_ver: "11" + config: Release + coverage: false + cc: clang + cxx: clang++ + - os: ubuntu + os_ver: "20.04" + config: Debug + coverage: true + cc: gcc-10 + cxx: g++-10 + defaults: + run: + shell: bash + name: ${{ matrix.os }}-${{ matrix.os_ver }} ${{ matrix.cxx }} ${{ matrix.config }} coverage=${{ matrix.coverage }} + env: + CC: ${{ matrix.cc }} + CXX: ${{ matrix.cxx }} + runs-on: ${{ matrix.os }}-${{ matrix.os_ver }} steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v1 - - # Sets up the build directory and cmake - - name: Create Build Environment - run: cmake -E make_directory ${{runner.workspace}}/build - - - name: Configure CMake - shell: bash - working-directory: ${{runner.workspace}}/build - # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 - run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE - - - name: Build - working-directory: ${{runner.workspace}}/build - shell: bash - # Execute the build. You can specify a specific target with "--target " - run: cmake --build . --config $BUILD_TYPE - - - name: Test - working-directory: ${{runner.workspace}}/build - shell: bash - # Execute tests defined by the CMake configuration. - # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest -C $BUILD_TYPE + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set Project Name + run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV + - name: Create Build Directory + run: cmake -E make_directory ${{github.workspace}}/build + # - name: Set coverage variables + # id: cov + # run: | + # if ${{matrix.coverage}}; then + # echo "COVERAGE=ON" >> $GITHUB_OUTPUT + # echo "STATIC_LIB=OFF" >> $GITHUB_OUTPUT + # else + # echo "COVERAGE=OFF" >> $GITHUB_OUTPUT + # echo "STATIC_LIB=ON" >> $GITHUB_OUTPUT + # fi + - name: Configure CMake + run: cmake -S . -B build -DCMAKE_BUILD_TYPE="${{ matrix.config }}" -D${{ env.REPOSITORY_NAME }}_BUILD_TESTING="ON" -D${{ env.REPOSITORY_NAME }}_STATIC_LIB="${{ steps.cov.outputs.STATIC_LIB }}" -D${{ env.REPOSITORY_NAME }}_COVERAGE="${{ steps.cov.outputs.COVERAGE }}" + - name: Build + run: cmake --build build --config ${{ matrix.config }} + - name: Test + run: ctest -C ${{ matrix.config }} --output-on-failure + working-directory: build +# - name: Code Coverage Analysis +# if: "matrix.coverage" +# run: make gcov +# working-directory: build +# - name: Upload Code Coverage Report +# if: "matrix.coverage" +# uses: codecov/codecov-action@v3 +# with: +# flags: integration +# functionalities: "gcov" +# move_coverage_to_trash: true \ No newline at end of file From ea6c9f0f9b84e60de2b526aa0d58131650b95ada Mon Sep 17 00:00:00 2001 From: Neal Kruis Date: Fri, 22 Dec 2023 16:23:09 -0700 Subject: [PATCH 06/15] Update compiler flags and clean up higher level warnings. --- CMakeLists.txt | 46 +++++++++++----- cmake/compiler-flags.cmake | 107 +++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 35 ++++++++++-- src/HPWH.cc | 11 ++-- src/HPWH.hh | 38 ++++++------- src/HPWHHeatingLogics.cc | 26 ++++----- test/CMakeLists.txt | 9 ++-- 7 files changed, 214 insertions(+), 58 deletions(-) create mode 100644 cmake/compiler-flags.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 37039809..c9089133 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,7 @@ -project(HPWHsim) - -cmake_minimum_required(VERSION 3.5) - -enable_testing() - -set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") +cmake_policy(SET CMP0091 NEW) +project(HPWHsim LANGUAGES CXX) +cmake_minimum_required(VERSION 3.7) +cmake_policy(SET CMP0079 NEW) # target_link_libraries() allows use with targets in other directories. # Set a default build type if none was specified if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) @@ -15,13 +12,31 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) "MinSizeRel" "RelWithDebInfo") endif () -if (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wshadow") -elseif (MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") +find_package(Git QUIET) + +set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") + +include(CMakeDependentOption) + +cmake_dependent_option(${PROJECT_NAME}_BUILD_TESTING "Build ${PROJECT_NAME} testing targets" ON "${PROJECT_NAME}_IS_TOP_LEVEL" OFF) +#option(${PROJECT_NAME}_COVERAGE "Add ${PROJECT_NAME} coverage reports" OFF) +#cmake_dependent_option(${PROJECT_NAME}_BUILD_EXAMPLES "Build ${PROJECT_NAME} examples" ON "${PROJECT_NAME}_IS_TOP_LEVEL" OFF) +cmake_dependent_option(${PROJECT_NAME}_WARNINGS_AS_ERRORS "Treat warnings in ${PROJECT_NAME} as errors" ON "${PROJECT_NAME}_IS_TOP_LEVEL" OFF) + +if (NOT ${PROJECT_NAME}_STATIC_LIB) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) endif () -find_package(Git QUIET) +include(compiler-flags) + +# Set up testing/coverage +if (${PROJECT_NAME}_BUILD_TESTING) + enable_testing() + # if (${PROJECT_NAME}_COVERAGE) + # set(ENABLE_COVERAGE ON CACHE BOOL "" FORCE) + # find_package(codecov) + # endif () +endif () if (HPWHSIM_ABRIDGED) add_compile_definitions(HPWH_ABRIDGED) @@ -30,6 +45,9 @@ endif () add_subdirectory(vendor) add_subdirectory(src) -if (NOT HPWHSIM_OMIT_TESTTOOL) +if (${PROJECT_NAME}_BUILD_TESTING) add_subdirectory(test) -endif () + # if (${PROJECT_NAME}_COVERAGE) + # coverage_evaluate() + # endif () +endif () \ No newline at end of file diff --git a/cmake/compiler-flags.cmake b/cmake/compiler-flags.cmake new file mode 100644 index 00000000..aaf975e8 --- /dev/null +++ b/cmake/compiler-flags.cmake @@ -0,0 +1,107 @@ +# '*' indicates CMake default option +# '+' indicates default compiler behavior +add_library(${PROJECT_NAME}_common_interface INTERFACE) + +#==================# +# Compiler options # +#==================# + +target_compile_options(${PROJECT_NAME}_common_interface INTERFACE + $<$: # Visual C++ (VS 2013) + /GR + /nologo + /W4 + $<$: + /WX # Turn warnings into errors + > + $<$: + /GS- # Disable buffer overrun checks for performance in release mode + > + > + # GCC And Clang + $<$: + -pthread + -pipe # Faster compiler processing + $<$: # Adds flag only to C++ + -pedantic # Turn on warnings about constructs/situations that may be non-portable or outside of the standard + > + -Wall # Turn on warnings + -Wextra # Turn on warnings + $<$: + -Werror # Turn warnings into errors + > + $<$: + -fno-stack-protector # Produces debugging information specifically for gdb + > + $<$: + $<$: + -ffloat-store # Improve debug run solution stability + -fsignaling-nans # Disable optimizations that may have concealed NaN behavior + > + > + # -finline-limit=2000 # More aggressive inlining This is causing unit test failures on Ubuntu 14.04 + > + ) + +#======================# +# Compiler definitions # +#======================# + +target_compile_definitions(${PROJECT_NAME}_common_interface INTERFACE + # GCC + $<$: + $<$: + _GLIBCXX_DEBUG # Standard container debug mode (bounds checking, ...) + > + > + ) + +#==================# +# Linker options # +#==================# + +target_link_options(${PROJECT_NAME}_common_interface INTERFACE + $<$: + -pthread + > + + ) + +# This macro will encapsulate the CMAKE_CXX flags that should only be set for executables +macro(SET_CXX_FLAGS) + # Remove unwanted CMake defaults from global flags + if (MSVC) + # See https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/Platform/Windows-MSVC.cmake + set(CMAKE_CXX_FLAGS + /EHsc #*Specifies the model of exception handling (sc options). + /DWIN32 #*Windows Platform (regardless of architecture) + /D_WINDOWS #* + ) + set(CMAKE_CXX_FLAGS_RELEASE + /O2 #*Creates fast code (Og+Oi+Ot+Oy+Ob2+GF+Gy). + # /Ob2 #*Controls inline expansion (level 2). (part of O2) + /DNDEBUG #*Enables or disables compilation of assertions + ) + set(CMAKE_CXX_FLAGS_DEBUG + /Ob0 #*Controls inline expansion (level 0 -- disabled). + /Od #*Disables optimization. + /Zi #*Generates complete debugging information. + /RTC1 #*Enables run-time error checking. + ) + else () # GCC or Clang or AppleClang + # See https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/Compiler/GNU.cmake + set(CMAKE_CXX_FLAGS "") + set(CMAKE_CXX_FLAGS_RELEASE + -O3 #*Maximum optimization (see https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize-Options). + -DNDEBUG #*Enables or disables compilation of assertions + ) + set(CMAKE_CXX_FLAGS_DEBUG + -g #*Produce debugging information in the operating system’s native format. + ) + endif () + + # Convert lists to space-separated strings + list(JOIN CMAKE_CXX_FLAGS " " CMAKE_CXX_FLAGS) + list(JOIN CMAKE_CXX_FLAGS_RELEASE " " CMAKE_CXX_FLAGS_RELEASE) + list(JOIN CMAKE_CXX_FLAGS_DEBUG " " CMAKE_CXX_FLAGS_DEBUG) +endmacro() \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 62a95fc3..067f826a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,22 +16,49 @@ set(headers HPWH.hh ) -set(source +set(sources HPWHversion.cc HPWH.cc HPWHHeatSources.cc HPWHHeatingLogics.cc HPWHpresets.cc ) -add_library(libHPWHsim ${source} ${headers}) + +set(library_sources + ${sources} + ${headers} + ) + +option(${PROJECT_NAME}_STATIC_LIB "Make ${PROJECT_NAME} a static library" ON) + +if (${PROJECT_NAME}_STATIC_LIB) + add_library(libHPWHsim STATIC ${library_sources}) # TODO: Change name to ${PROJECT_NAME} + set_target_properties(libHPWHsim PROPERTIES COMPILE_FLAGS "-D${PROJECT_NAME}_STATIC_DEFINE") +else () + set(CMAKE_MACOSX_RPATH 1) + add_library(libHPWHsim SHARED ${library_sources}) +endif () target_include_directories(libHPWHsim PUBLIC ${PROJECT_BINARY_DIR}/src ${PROJECT_SOURCE_DIR}/src) -target_link_libraries(libHPWHsim PUBLIC btwxt) +target_link_libraries(libHPWHsim PRIVATE ${PROJECT_NAME}_common_interface PUBLIC btwxt) +target_compile_features(libHPWHsim PRIVATE cxx_std_17) + add_dependencies(libHPWHsim ${PROJECT_NAME}_version_header) set_target_properties(libHPWHsim PROPERTIES OUTPUT_NAME HPWHsim) set_target_properties(libHPWHsim PROPERTIES PDB_NAME libHPWHsim) -target_compile_features(libHPWHsim PUBLIC cxx_std_17) + +# If MSVC_RUNTIME_LIBRARY is not by a parent project use the default. +# It's not clear why this is needed, since documentation indicates it +# should be happening with the CMP0091 policy set to NEW. +get_target_property(RTL libHPWHsim MSVC_RUNTIME_LIBRARY) +if ("${RTL}" STREQUAL "RTL-NOTFOUND") + set_target_properties(libHPWHsim PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") +endif () + +#if (${PROJECT_NAME}_COVERAGE) +# add_coverage(${PROJECT_NAME}) +#endif() diff --git a/src/HPWH.cc b/src/HPWH.cc index 597a49a0..8a9a9071 100644 --- a/src/HPWH.cc +++ b/src/HPWH.cc @@ -4433,7 +4433,7 @@ int HPWH::HPWHinit_file(string configFile) } // some variables that will be handy - int heatsource, sourceNum, nTemps, tempInt; + std::size_t heatsource, sourceNum, nTemps, tempInt; std::size_t num_nodes = 0, numHeatSources = 0; bool hasInitialTankTemp = false; double initalTankT_C = F_TO_C(120.); @@ -4652,7 +4652,7 @@ int HPWH::HPWHinit_file(string configFile) { line_ss >> numHeatSources; heatSources.reserve(numHeatSources); - for (int i = 0; i < numHeatSources; i++) + for (std::size_t i = 0; i < numHeatSources; i++) { heatSources.emplace_back(this); } @@ -5151,7 +5151,7 @@ int HPWH::HPWHinit_file(string configFile) std::smatch match; std::regex_match(token, match, std::regex("T(\\d+)")); nTemps = std::stoi(match[1].str()); - int maxTemps = (int)heatSources[heatsource].perfMap.size(); + std::size_t maxTemps = heatSources[heatsource].perfMap.size(); if (maxTemps < nTemps) { @@ -5206,6 +5206,8 @@ int HPWH::HPWHinit_file(string configFile) nTemps = std::stoi(match[2].str()); string coeff = match[3].str(); + /* + // TODO: Currently relies on the coefficients being defined in the correct order int coeff_num; if (coeff == "const") { @@ -5219,8 +5221,9 @@ int HPWH::HPWHinit_file(string configFile) { coeff_num = 2; } + */ - int maxTemps = (int)heatSources[heatsource].perfMap.size(); + std::size_t maxTemps = heatSources[heatsource].perfMap.size(); if (maxTemps < nTemps) { diff --git a/src/HPWH.hh b/src/HPWH.hh index ab9a0983..8b4fcbcb 100644 --- a/src/HPWH.hh +++ b/src/HPWH.hh @@ -332,15 +332,15 @@ class HPWH virtual ~HeatingLogic() = default; /**< checks that the input is all valid. */ - virtual const bool isValid() = 0; + virtual bool isValid() = 0; /**< gets the value for comparing the tank value to, i.e. the target SoC */ - virtual const double getComparisonValue() = 0; + virtual double getComparisonValue() = 0; /**< gets the calculated value from the tank, i.e. SoC or tank average of node weights*/ - virtual const double getTankValue() = 0; + virtual double getTankValue() = 0; /**< function to calculate where the average node for a logic set is. */ - virtual const double nodeWeightAvgFract() = 0; + virtual double nodeWeightAvgFract() = 0; /**< gets the fraction of a node that has to be heated up to met the turnoff condition*/ - virtual const double getFractToMeetComparisonExternal() = 0; + virtual double getFractToMeetComparisonExternal() = 0; virtual int setDecisionPoint(double value) = 0; double getDecisionPoint() { return decisionPoint; } @@ -368,14 +368,14 @@ class HPWH , hysteresisFraction(hF) , useCostantMains(constMains) , constantMains_C(mains_C) {}; - const bool isValid(); - - const double getComparisonValue(); - const double getTankValue(); - const double nodeWeightAvgFract(); - const double getFractToMeetComparisonExternal(); - const double getMainsT_C(); - const double getTempMinUseful_C(); + bool isValid(); + + double getComparisonValue(); + double getTankValue(); + double nodeWeightAvgFract(); + double getFractToMeetComparisonExternal(); + double getMainsT_C(); + double getTempMinUseful_C(); int setDecisionPoint(double value); int setConstantMainsTemperature(double mains_C); @@ -398,18 +398,18 @@ class HPWH bool isHTS = false) : HeatingLogic(desc, decisionPoint, hpwh, c, isHTS), isAbsolute(a), nodeWeights(n) {}; - const bool isValid(); + bool isValid(); - const double getComparisonValue(); - const double getTankValue(); - const double nodeWeightAvgFract(); - const double getFractToMeetComparisonExternal(); + double getComparisonValue(); + double getTankValue(); + double nodeWeightAvgFract(); + double getFractToMeetComparisonExternal(); int setDecisionPoint(double value); int setDecisionPoint(double value, bool absolute); private: - const bool areNodeWeightsValid(); + bool areNodeWeightsValid(); bool isAbsolute; std::vector nodeWeights; diff --git a/src/HPWHHeatingLogics.cc b/src/HPWHHeatingLogics.cc index e2f1838d..65e43227 100644 --- a/src/HPWHHeatingLogics.cc +++ b/src/HPWHHeatingLogics.cc @@ -5,7 +5,7 @@ File of the presets heating logics available HPWHsim #include "HPWH.hh" /* State of Charge Based Logic*/ -const bool HPWH::SoCBasedHeatingLogic::isValid() +bool HPWH::SoCBasedHeatingLogic::isValid() { bool isValid = true; if (decisionPoint < 0) @@ -15,12 +15,12 @@ const bool HPWH::SoCBasedHeatingLogic::isValid() return isValid; } -const double HPWH::SoCBasedHeatingLogic::getComparisonValue() +double HPWH::SoCBasedHeatingLogic::getComparisonValue() { return decisionPoint + hysteresisFraction; } -const double HPWH::SoCBasedHeatingLogic::getTankValue() +double HPWH::SoCBasedHeatingLogic::getTankValue() { double soCFraction; if (hpwh->member_inletT_C == HPWH_ABORT && !useCostantMains) @@ -34,7 +34,7 @@ const double HPWH::SoCBasedHeatingLogic::getTankValue() return soCFraction; } -const double HPWH::SoCBasedHeatingLogic::getMainsT_C() +double HPWH::SoCBasedHeatingLogic::getMainsT_C() { if (useCostantMains) { @@ -46,7 +46,7 @@ const double HPWH::SoCBasedHeatingLogic::getMainsT_C() } } -const double HPWH::SoCBasedHeatingLogic::getTempMinUseful_C() { return tempMinUseful_C; } +double HPWH::SoCBasedHeatingLogic::getTempMinUseful_C() { return tempMinUseful_C; } int HPWH::SoCBasedHeatingLogic::setDecisionPoint(double value) { @@ -61,9 +61,9 @@ int HPWH::SoCBasedHeatingLogic::setConstantMainsTemperature(double mains_C) return 0; } -const double HPWH::SoCBasedHeatingLogic::nodeWeightAvgFract() { return getComparisonValue(); } +double HPWH::SoCBasedHeatingLogic::nodeWeightAvgFract() { return getComparisonValue(); } -const double HPWH::SoCBasedHeatingLogic::getFractToMeetComparisonExternal() +double HPWH::SoCBasedHeatingLogic::getFractToMeetComparisonExternal() { double deltaSoCFraction = (getComparisonValue() + HPWH::TOL_MINVALUE) - getTankValue(); @@ -141,7 +141,7 @@ const double HPWH::SoCBasedHeatingLogic::getFractToMeetComparisonExternal() } /* Temperature Based Heating Logic*/ -const bool HPWH::TempBasedHeatingLogic::isValid() +bool HPWH::TempBasedHeatingLogic::isValid() { bool isValid = true; if (!areNodeWeightsValid()) @@ -151,7 +151,7 @@ const bool HPWH::TempBasedHeatingLogic::isValid() return isValid; } -const bool HPWH::TempBasedHeatingLogic::areNodeWeightsValid() +bool HPWH::TempBasedHeatingLogic::areNodeWeightsValid() { for (auto nodeWeight : nodeWeights) { @@ -163,7 +163,7 @@ const bool HPWH::TempBasedHeatingLogic::areNodeWeightsValid() return true; } -const double HPWH::TempBasedHeatingLogic::getComparisonValue() +double HPWH::TempBasedHeatingLogic::getComparisonValue() { double value = decisionPoint; if (isAbsolute) @@ -176,7 +176,7 @@ const double HPWH::TempBasedHeatingLogic::getComparisonValue() } } -const double HPWH::TempBasedHeatingLogic::getTankValue() { return hpwh->tankAvg_C(nodeWeights); } +double HPWH::TempBasedHeatingLogic::getTankValue() { return hpwh->tankAvg_C(nodeWeights); } int HPWH::TempBasedHeatingLogic::setDecisionPoint(double value) { @@ -189,7 +189,7 @@ int HPWH::TempBasedHeatingLogic::setDecisionPoint(double value, bool absolute) return setDecisionPoint(value); } -const double HPWH::TempBasedHeatingLogic::nodeWeightAvgFract() +double HPWH::TempBasedHeatingLogic::nodeWeightAvgFract() { double logicNode; double calcNodes = 0, totWeight = 0; @@ -218,7 +218,7 @@ const double HPWH::TempBasedHeatingLogic::nodeWeightAvgFract() return logicNode / static_cast(LOGIC_NODE_SIZE); } -const double HPWH::TempBasedHeatingLogic::getFractToMeetComparisonExternal() +double HPWH::TempBasedHeatingLogic::getFractToMeetComparisonExternal() { double fracTemp; double diff; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 61f4d023..82a314f6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,11 @@ # Build test tool +SET_CXX_FLAGS() + include_directories("${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}/src") add_executable(testTool main.cc) + +# TODO: Migrate to googletest framework add_executable(testTankSizeFixed testTankSizeFixed.cc) add_executable(testScaleHPWH testScaleHPWH.cc) add_executable(testMaxSetpoint testMaxSetpoint.cc) @@ -13,10 +17,7 @@ add_executable(testStateOfChargeFcts testStateOfChargeFcts.cc) add_executable(testHeatingLogics testHeatingLogics.cc) add_executable(testEnergyBalance testEnergyBalance.cc) -set(libs - libHPWHsim - btwxt - ) +set(libs libHPWHsim) target_link_libraries(testTool ${libs}) target_link_libraries(testTankSizeFixed ${libs}) From 2660b4d783345e648551232f7f05a7bdf84a903d Mon Sep 17 00:00:00 2001 From: Neal Kruis Date: Fri, 22 Dec 2023 16:34:09 -0700 Subject: [PATCH 07/15] Address warnings on linux/windows. --- src/HPWH.cc | 4 ++-- src/HPWH.hh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/HPWH.cc b/src/HPWH.cc index 8a9a9071..574b2155 100644 --- a/src/HPWH.cc +++ b/src/HPWH.cc @@ -5105,7 +5105,7 @@ int HPWH::HPWHinit_file(string configFile) line_ss >> tempInt; if (tempInt < num_nodes && tempInt >= 0) { - heatSources[heatsource].externalInletHeight = tempInt; + heatSources[heatsource].externalInletHeight = static_cast(tempInt); } else { @@ -5121,7 +5121,7 @@ int HPWH::HPWHinit_file(string configFile) line_ss >> tempInt; if (tempInt < num_nodes && tempInt >= 0) { - heatSources[heatsource].externalOutletHeight = tempInt; + heatSources[heatsource].externalOutletHeight = static_cast(tempInt); } else { diff --git a/src/HPWH.hh b/src/HPWH.hh index 8b4fcbcb..3210b909 100644 --- a/src/HPWH.hh +++ b/src/HPWH.hh @@ -16,7 +16,7 @@ namespace Btwxt { class RegularGridInterpolator; -}; +} // #define HPWH_ABRIDGED /**< If HPWH_ABRIDGED is defined, then some function definitions will be From eaba2a96aace57acf1fbe9f639c4b156a4527cfd Mon Sep 17 00:00:00 2001 From: Neal Kruis Date: Tue, 26 Dec 2023 10:09:46 -0700 Subject: [PATCH 08/15] Fix CI CMake configuration. --- .github/workflows/build-and-test.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 904c11a0..ed6f07d1 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -61,16 +61,16 @@ jobs: run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV - name: Create Build Directory run: cmake -E make_directory ${{github.workspace}}/build - # - name: Set coverage variables - # id: cov - # run: | - # if ${{matrix.coverage}}; then - # echo "COVERAGE=ON" >> $GITHUB_OUTPUT - # echo "STATIC_LIB=OFF" >> $GITHUB_OUTPUT - # else - # echo "COVERAGE=OFF" >> $GITHUB_OUTPUT - # echo "STATIC_LIB=ON" >> $GITHUB_OUTPUT - # fi + - name: Set coverage variables + id: cov + run: | + if ${{matrix.coverage}}; then + echo "COVERAGE=ON" >> $GITHUB_OUTPUT + echo "STATIC_LIB=OFF" >> $GITHUB_OUTPUT + else + echo "COVERAGE=OFF" >> $GITHUB_OUTPUT + echo "STATIC_LIB=ON" >> $GITHUB_OUTPUT + fi - name: Configure CMake run: cmake -S . -B build -DCMAKE_BUILD_TYPE="${{ matrix.config }}" -D${{ env.REPOSITORY_NAME }}_BUILD_TESTING="ON" -D${{ env.REPOSITORY_NAME }}_STATIC_LIB="${{ steps.cov.outputs.STATIC_LIB }}" -D${{ env.REPOSITORY_NAME }}_COVERAGE="${{ steps.cov.outputs.COVERAGE }}" - name: Build From ad3a009a8bb36d2a3da49d1a1c886320dcb58927 Mon Sep 17 00:00:00 2001 From: Neal Kruis Date: Tue, 26 Dec 2023 10:10:15 -0700 Subject: [PATCH 09/15] Clean up gcc warnings. --- src/HPWH.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/HPWH.cc b/src/HPWH.cc index 574b2155..b4f01f79 100644 --- a/src/HPWH.cc +++ b/src/HPWH.cc @@ -5103,7 +5103,7 @@ int HPWH::HPWHinit_file(string configFile) else if (token == "externalInlet") { line_ss >> tempInt; - if (tempInt < num_nodes && tempInt >= 0) + if (tempInt < num_nodes) { heatSources[heatsource].externalInletHeight = static_cast(tempInt); } @@ -5119,7 +5119,7 @@ int HPWH::HPWHinit_file(string configFile) else if (token == "externalOutlet") { line_ss >> tempInt; - if (tempInt < num_nodes && tempInt >= 0) + if (tempInt < num_nodes) { heatSources[heatsource].externalOutletHeight = static_cast(tempInt); } From 763d5c6b9640a9204563216946eab114d68163f9 Mon Sep 17 00:00:00 2001 From: Neal Kruis Date: Tue, 26 Dec 2023 10:18:37 -0700 Subject: [PATCH 10/15] Clean up more gcc warnings. --- src/HPWH.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/HPWH.cc b/src/HPWH.cc index b4f01f79..99aa83c8 100644 --- a/src/HPWH.cc +++ b/src/HPWH.cc @@ -319,13 +319,13 @@ void HPWH::setMinutesPerStep(const double minutesPerStep_in) minutesPerStep = minutesPerStep_in; secondsPerStep = sec_per_min * minutesPerStep; hoursPerStep = minutesPerStep / min_per_hr; -}; +} // public HPWH functions HPWH::HPWH() : hpwhVerbosity(VRB_silent), messageCallback(NULL), messageCallbackContextPtr(NULL) { setAllDefaults(); -}; +} void HPWH::setAllDefaults() { From b640728acd357584a3cc08bb44f139442f23f23b Mon Sep 17 00:00:00 2001 From: Neal Kruis Date: Wed, 27 Dec 2023 10:18:45 -0700 Subject: [PATCH 11/15] Fix GCC debug compiler flag. --- cmake/compiler-flags.cmake | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/cmake/compiler-flags.cmake b/cmake/compiler-flags.cmake index aaf975e8..57b73140 100644 --- a/cmake/compiler-flags.cmake +++ b/cmake/compiler-flags.cmake @@ -43,19 +43,6 @@ target_compile_options(${PROJECT_NAME}_common_interface INTERFACE > ) -#======================# -# Compiler definitions # -#======================# - -target_compile_definitions(${PROJECT_NAME}_common_interface INTERFACE - # GCC - $<$: - $<$: - _GLIBCXX_DEBUG # Standard container debug mode (bounds checking, ...) - > - > - ) - #==================# # Linker options # #==================# @@ -67,8 +54,7 @@ target_link_options(${PROJECT_NAME}_common_interface INTERFACE ) -# This macro will encapsulate the CMAKE_CXX flags that should only be set for executables -macro(SET_CXX_FLAGS) +if (${PROJECT_NAME}_IS_TOP_LEVEL) # Remove unwanted CMake defaults from global flags if (MSVC) # See https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/Platform/Windows-MSVC.cmake @@ -98,10 +84,15 @@ macro(SET_CXX_FLAGS) set(CMAKE_CXX_FLAGS_DEBUG -g #*Produce debugging information in the operating system’s native format. ) + if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} + -D_GLIBCXX_DEBUG # Standard container debug mode (bounds checking, etc.) + ) + endif () endif () # Convert lists to space-separated strings list(JOIN CMAKE_CXX_FLAGS " " CMAKE_CXX_FLAGS) list(JOIN CMAKE_CXX_FLAGS_RELEASE " " CMAKE_CXX_FLAGS_RELEASE) list(JOIN CMAKE_CXX_FLAGS_DEBUG " " CMAKE_CXX_FLAGS_DEBUG) -endmacro() \ No newline at end of file +endif () \ No newline at end of file From 11abf0b47c107c6eb81207c3b2a0a319ef072e03 Mon Sep 17 00:00:00 2001 From: Neal Kruis Date: Wed, 27 Dec 2023 10:20:24 -0700 Subject: [PATCH 12/15] Make MacOS 11 experimental for now. --- .github/workflows/build-and-test.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index ed6f07d1..4ec5b8ca 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -14,36 +14,42 @@ jobs: coverage: false cc: gcc-11 cxx: g++-11 + experimental: false - os: ubuntu os_ver: "20.04" config: Release coverage: false cc: gcc-10 cxx: g++-10 + experimental: false - os: windows os_ver: "2022" config: Release coverage: false cc: cl cxx: cl + experimental: false - os: macos os_ver: "12" config: Release coverage: false cc: clang cxx: clang++ + experimental: false - os: macos os_ver: "11" config: Release coverage: false cc: clang cxx: clang++ + experimental: true - os: ubuntu os_ver: "20.04" config: Debug coverage: true cc: gcc-10 cxx: g++-10 + experimental: false defaults: run: shell: bash @@ -52,6 +58,7 @@ jobs: CC: ${{ matrix.cc }} CXX: ${{ matrix.cxx }} runs-on: ${{ matrix.os }}-${{ matrix.os_ver }} + continue-on-error: ${{ matrix.experimental }} steps: - name: Checkout uses: actions/checkout@v3 From 54723ad9ba7f8238ad2342d883ed47896dde52c0 Mon Sep 17 00:00:00 2001 From: Neal Kruis Date: Wed, 27 Dec 2023 10:21:00 -0700 Subject: [PATCH 13/15] CMake cleanup. --- src/CMakeLists.txt | 3 +++ test/CMakeLists.txt | 32 +++++++++++++++----------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 067f826a..c78fc16b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,6 +44,9 @@ target_include_directories(libHPWHsim PUBLIC ${PROJECT_BINARY_DIR}/src ${PROJECT target_link_libraries(libHPWHsim PRIVATE ${PROJECT_NAME}_common_interface PUBLIC btwxt) target_compile_features(libHPWHsim PRIVATE cxx_std_17) +include(GenerateExportHeader) +generate_export_header(libHPWHsim) + add_dependencies(libHPWHsim ${PROJECT_NAME}_version_header) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 82a314f6..8023f63b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,8 +1,4 @@ # Build test tool -SET_CXX_FLAGS() - -include_directories("${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}/src") - add_executable(testTool main.cc) # TODO: Migrate to googletest framework @@ -17,19 +13,21 @@ add_executable(testStateOfChargeFcts testStateOfChargeFcts.cc) add_executable(testHeatingLogics testHeatingLogics.cc) add_executable(testEnergyBalance testEnergyBalance.cc) -set(libs libHPWHsim) - -target_link_libraries(testTool ${libs}) -target_link_libraries(testTankSizeFixed ${libs}) -target_link_libraries(testScaleHPWH ${libs}) -target_link_libraries(testMaxSetpoint ${libs}) -target_link_libraries(testSizingFractions ${libs}) -target_link_libraries(testResistanceFcts ${libs}) -target_link_libraries(testCompressorFcts ${libs}) -target_link_libraries(testPerformanceMaps ${libs}) -target_link_libraries(testStateOfChargeFcts ${libs}) -target_link_libraries(testHeatingLogics ${libs}) -target_link_libraries(testEnergyBalance ${libs}) +set(libs libHPWHsim ${PROJECT_NAME}_common_interface) + +target_link_libraries(testTool PRIVATE ${libs}) +target_link_libraries(testTankSizeFixed PRIVATE ${libs}) +target_link_libraries(testScaleHPWH PRIVATE ${libs}) +target_link_libraries(testMaxSetpoint PRIVATE ${libs}) +target_link_libraries(testSizingFractions PRIVATE ${libs}) +target_link_libraries(testResistanceFcts PRIVATE ${libs}) +target_link_libraries(testCompressorFcts PRIVATE ${libs}) +target_link_libraries(testPerformanceMaps PRIVATE ${libs}) +target_link_libraries(testStateOfChargeFcts PRIVATE ${libs}) +target_link_libraries(testHeatingLogics PRIVATE ${libs}) +target_link_libraries(testEnergyBalance PRIVATE ${libs}) + +target_compile_features(testTool PRIVATE cxx_std_17) # Add output directory for test results add_custom_target(results_directory ALL COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/output") From 4690c6dc0a90a88da2f5317ecd94c9a023259efd Mon Sep 17 00:00:00 2001 From: Neal Kruis Date: Wed, 27 Dec 2023 10:21:21 -0700 Subject: [PATCH 14/15] Fix gcc warnings. --- src/HPWH.hh | 6 +++--- test/testMaxSetpoint.cc | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/HPWH.hh b/src/HPWH.hh index 3210b909..3a4a564a 100644 --- a/src/HPWH.hh +++ b/src/HPWH.hh @@ -1350,9 +1350,9 @@ class HPWH::HeatSource /** some compressors have a resistance element for defrost*/ struct resistanceElementDefrost { - double inputPwr_kW; - double constTempLift_dF; - double onBelowT_F; + double inputPwr_kW {0.0}; + double constTempLift_dF {0.0}; + double onBelowT_F {-999}; }; resistanceElementDefrost resDefrost; diff --git a/test/testMaxSetpoint.cc b/test/testMaxSetpoint.cc index 17361657..18074c6c 100644 --- a/test/testMaxSetpoint.cc +++ b/test/testMaxSetpoint.cc @@ -276,7 +276,7 @@ void testSetTankTemps() ASSERTTRUE(relcmpd(newTemps[8], 67.6, 0.1)); // // test 4 - int nSet = 24; + std::size_t nSet = 24; setTemps.resize(nSet); double Ti = 20., Tf = 66.; for (std::size_t i = 0; i < nSet; ++i) From e7a89c828b04f830487c68f0785274a351709d41 Mon Sep 17 00:00:00 2001 From: Neal Kruis Date: Wed, 27 Dec 2023 10:44:57 -0700 Subject: [PATCH 15/15] Enable code coverage. --- .codecov.yml | 6 + .github/workflows/build-and-test.yml | 22 +- CMakeLists.txt | 16 +- cmake/FindGcov.cmake | 158 ++++++++++++ cmake/FindLcov.cmake | 357 +++++++++++++++++++++++++++ cmake/Findcodecov.cmake | 258 +++++++++++++++++++ cmake/llvm-cov-wrapper | 56 +++++ src/CMakeLists.txt | 6 +- 8 files changed, 857 insertions(+), 22 deletions(-) create mode 100644 .codecov.yml create mode 100755 cmake/FindGcov.cmake create mode 100755 cmake/FindLcov.cmake create mode 100755 cmake/Findcodecov.cmake create mode 100755 cmake/llvm-cov-wrapper diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 00000000..51689dba --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,6 @@ +coverage: + precision: 2 + round: nearest + range: "0...100" + ignore: + - "vendor/**/*" \ No newline at end of file diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 4ec5b8ca..ceb27bb4 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -85,14 +85,14 @@ jobs: - name: Test run: ctest -C ${{ matrix.config }} --output-on-failure working-directory: build -# - name: Code Coverage Analysis -# if: "matrix.coverage" -# run: make gcov -# working-directory: build -# - name: Upload Code Coverage Report -# if: "matrix.coverage" -# uses: codecov/codecov-action@v3 -# with: -# flags: integration -# functionalities: "gcov" -# move_coverage_to_trash: true \ No newline at end of file + - name: Code Coverage Analysis + if: "matrix.coverage" + run: make gcov + working-directory: build + - name: Upload Code Coverage Report + if: "matrix.coverage" + uses: codecov/codecov-action@v3 + with: + flags: integration + functionalities: "gcov" + move_coverage_to_trash: true \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index c9089133..49f3fa63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") include(CMakeDependentOption) cmake_dependent_option(${PROJECT_NAME}_BUILD_TESTING "Build ${PROJECT_NAME} testing targets" ON "${PROJECT_NAME}_IS_TOP_LEVEL" OFF) -#option(${PROJECT_NAME}_COVERAGE "Add ${PROJECT_NAME} coverage reports" OFF) +option(${PROJECT_NAME}_COVERAGE "Add ${PROJECT_NAME} coverage reports" OFF) #cmake_dependent_option(${PROJECT_NAME}_BUILD_EXAMPLES "Build ${PROJECT_NAME} examples" ON "${PROJECT_NAME}_IS_TOP_LEVEL" OFF) cmake_dependent_option(${PROJECT_NAME}_WARNINGS_AS_ERRORS "Treat warnings in ${PROJECT_NAME} as errors" ON "${PROJECT_NAME}_IS_TOP_LEVEL" OFF) @@ -32,10 +32,10 @@ include(compiler-flags) # Set up testing/coverage if (${PROJECT_NAME}_BUILD_TESTING) enable_testing() - # if (${PROJECT_NAME}_COVERAGE) - # set(ENABLE_COVERAGE ON CACHE BOOL "" FORCE) - # find_package(codecov) - # endif () + if (${PROJECT_NAME}_COVERAGE) + set(ENABLE_COVERAGE ON CACHE BOOL " " FORCE) + find_package(codecov) + endif () endif () if (HPWHSIM_ABRIDGED) @@ -47,7 +47,7 @@ add_subdirectory(src) if (${PROJECT_NAME}_BUILD_TESTING) add_subdirectory(test) - # if (${PROJECT_NAME}_COVERAGE) - # coverage_evaluate() - # endif () + if (${PROJECT_NAME}_COVERAGE) + coverage_evaluate() + endif () endif () \ No newline at end of file diff --git a/cmake/FindGcov.cmake b/cmake/FindGcov.cmake new file mode 100755 index 00000000..638dc738 --- /dev/null +++ b/cmake/FindGcov.cmake @@ -0,0 +1,158 @@ +# This file is part of CMake-codecov. +# +# Copyright (c) +# 2015-2017 RWTH Aachen University, Federal Republic of Germany +# +# See the LICENSE file in the package base directory for details +# +# Written by Alexander Haase, alexander.haase@rwth-aachen.de +# + + +# include required Modules +include(FindPackageHandleStandardArgs) + + +# Search for gcov binary. +set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET}) +set(CMAKE_REQUIRED_QUIET ${codecov_FIND_QUIETLY}) + +get_property(ENABLED_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES) +foreach (LANG ${ENABLED_LANGUAGES}) + # Gcov evaluation is dependent on the used compiler. Check gcov support for + # each compiler that is used. If gcov binary was already found for this + # compiler, do not try to find it again. + if (NOT GCOV_${CMAKE_${LANG}_COMPILER_ID}_BIN) + get_filename_component(COMPILER_PATH "${CMAKE_${LANG}_COMPILER}" PATH) + + if ("${CMAKE_${LANG}_COMPILER_ID}" STREQUAL "GNU") + # Some distributions like OSX (homebrew) ship gcov with the compiler + # version appended as gcov-x. To find this binary we'll build the + # suggested binary name with the compiler version. + string(REGEX MATCH "^[0-9]+" GCC_VERSION + "${CMAKE_${LANG}_COMPILER_VERSION}") + + find_program(GCOV_BIN NAMES gcov-${GCC_VERSION} gcov + HINTS ${COMPILER_PATH}) + + elseif ("${CMAKE_${LANG}_COMPILER_ID}" MATCHES "^(Apple)?Clang$") + # Some distributions like Debian ship llvm-cov with the compiler + # version appended as llvm-cov-x.y. To find this binary we'll build + # the suggested binary name with the compiler version. + string(REGEX MATCH "^[0-9]+.[0-9]+" LLVM_VERSION + "${CMAKE_${LANG}_COMPILER_VERSION}") + + # llvm-cov prior version 3.5 seems to be not working with coverage + # evaluation tools, but these versions are compatible with the gcc + # gcov tool. + if(LLVM_VERSION VERSION_GREATER 3.4) + find_program(LLVM_COV_BIN NAMES "llvm-cov-${LLVM_VERSION}" + "llvm-cov" HINTS ${COMPILER_PATH}) + mark_as_advanced(LLVM_COV_BIN) + + if (LLVM_COV_BIN) + find_program(LLVM_COV_WRAPPER "llvm-cov-wrapper" PATHS + ${CMAKE_MODULE_PATH}) + if (LLVM_COV_WRAPPER) + set(GCOV_BIN "${LLVM_COV_WRAPPER}" CACHE FILEPATH "") + + # set additional parameters + set(GCOV_${CMAKE_${LANG}_COMPILER_ID}_ENV + "LLVM_COV_BIN=${LLVM_COV_BIN}" CACHE STRING + "Environment variables for llvm-cov-wrapper.") + mark_as_advanced(GCOV_${CMAKE_${LANG}_COMPILER_ID}_ENV) + endif () + endif () + endif () + + if (NOT GCOV_BIN) + # Fall back to gcov binary if llvm-cov was not found or is + # incompatible. This is the default on OSX, but may crash on + # recent Linux versions. + find_program(GCOV_BIN gcov HINTS ${COMPILER_PATH}) + endif () + endif () + + + if (GCOV_BIN) + set(GCOV_${CMAKE_${LANG}_COMPILER_ID}_BIN "${GCOV_BIN}" CACHE STRING + "${LANG} gcov binary.") + + if (NOT CMAKE_REQUIRED_QUIET) + message("-- Found gcov evaluation for " + "${CMAKE_${LANG}_COMPILER_ID}: ${GCOV_BIN}") + endif() + + unset(GCOV_BIN CACHE) + endif () + endif () +endforeach () + + + + +# Add a new global target for all gcov targets. This target could be used to +# generate the gcov files for the whole project instead of calling -gcov +# for each target. +if (NOT TARGET gcov) + add_custom_target(gcov) +endif (NOT TARGET gcov) + + + +# This function will add gcov evaluation for target . Only sources of +# this target will be evaluated and no dependencies will be added. It will call +# Gcov on any source file of once and store the gcov file in the same +# directory. +function (add_gcov_target TNAME) + get_target_property(TBIN_DIR ${TNAME} BINARY_DIR) + set(TDIR ${TBIN_DIR}/CMakeFiles/${TNAME}.dir) + + # We don't have to check, if the target has support for coverage, thus this + # will be checked by add_coverage_target in Findcoverage.cmake. Instead we + # have to determine which gcov binary to use. + get_target_property(TSOURCES ${TNAME} SOURCES) + set(SOURCES "") + set(TCOMPILER "") + foreach (FILE ${TSOURCES}) + codecov_path_of_source(${FILE} FILE) + if (NOT "${FILE}" STREQUAL "") + codecov_lang_of_source(${FILE} LANG) + if (NOT "${LANG}" STREQUAL "") + list(APPEND SOURCES "${FILE}") + set(TCOMPILER ${CMAKE_${LANG}_COMPILER_ID}) + endif () + endif () + endforeach () + + # If no gcov binary was found, coverage data can't be evaluated. + if (NOT GCOV_${TCOMPILER}_BIN) + message(WARNING "No coverage evaluation binary found for ${TCOMPILER}.") + return() + endif () + + set(GCOV_BIN "${GCOV_${TCOMPILER}_BIN}") + set(GCOV_ENV "${GCOV_${TCOMPILER}_ENV}") + + + set(BUFFER "") + foreach(FILE ${SOURCES}) + get_filename_component(FILE_PATH "${TDIR}/${FILE}" PATH) + + # call gcov + add_custom_command(OUTPUT ${TDIR}/${FILE}.gcov + COMMAND ${GCOV_ENV} ${GCOV_BIN} ${TDIR}/${FILE}.gcno > /dev/null + DEPENDS ${TNAME} ${TDIR}/${FILE}.gcno + WORKING_DIRECTORY ${FILE_PATH} + ) + + list(APPEND BUFFER ${TDIR}/${FILE}.gcov) + endforeach() + + + # add target for gcov evaluation of + add_custom_target(${TNAME}-gcov DEPENDS ${BUFFER}) + + # add evaluation target to the global gcov target. + add_dependencies(gcov ${TNAME}-gcov) +endfunction (add_gcov_target) diff --git a/cmake/FindLcov.cmake b/cmake/FindLcov.cmake new file mode 100755 index 00000000..bd98f36a --- /dev/null +++ b/cmake/FindLcov.cmake @@ -0,0 +1,357 @@ +# This file is part of CMake-codecov. +# +# Copyright (c) +# 2015-2017 RWTH Aachen University, Federal Republic of Germany +# +# See the LICENSE file in the package base directory for details +# +# Written by Alexander Haase, alexander.haase@rwth-aachen.de +# + + +# configuration +set(LCOV_DATA_PATH "${CMAKE_BINARY_DIR}/lcov/data") +set(LCOV_DATA_PATH_INIT "${LCOV_DATA_PATH}/init") +set(LCOV_DATA_PATH_CAPTURE "${LCOV_DATA_PATH}/capture") +set(LCOV_HTML_PATH "${CMAKE_BINARY_DIR}/lcov/html") + + + + +# Search for Gcov which is used by Lcov. +find_package(Gcov) + + + + +# This function will add lcov evaluation for target . Only sources of +# this target will be evaluated and no dependencies will be added. It will call +# geninfo on any source file of once and store the info file in the same +# directory. +# +# Note: This function is only a wrapper to define this function always, even if +# coverage is not supported by the compiler or disabled. This function must +# be defined here, because the module will be exited, if there is no coverage +# support by the compiler or it is disabled by the user. +function (add_lcov_target TNAME) + if (LCOV_FOUND) + # capture initial coverage data + lcov_capture_initial_tgt(${TNAME}) + + # capture coverage data after execution + lcov_capture_tgt(${TNAME}) + endif () +endfunction (add_lcov_target) + + + + +# include required Modules +include(FindPackageHandleStandardArgs) + +# Search for required lcov binaries. +find_program(LCOV_BIN lcov) +find_program(GENINFO_BIN geninfo) +find_program(GENHTML_BIN genhtml) +find_package_handle_standard_args(lcov + REQUIRED_VARS LCOV_BIN GENINFO_BIN GENHTML_BIN + ) + +# enable genhtml C++ demangeling, if c++filt is found. +set(GENHTML_CPPFILT_FLAG "") +find_program(CPPFILT_BIN c++filt) +if (NOT CPPFILT_BIN STREQUAL "") + set(GENHTML_CPPFILT_FLAG "--demangle-cpp") +endif (NOT CPPFILT_BIN STREQUAL "") + +# enable no-external flag for lcov, if available. +if (GENINFO_BIN AND NOT DEFINED GENINFO_EXTERN_FLAG) + set(FLAG "") + execute_process(COMMAND ${GENINFO_BIN} --help OUTPUT_VARIABLE GENINFO_HELP) + string(REGEX MATCH "external" GENINFO_RES "${GENINFO_HELP}") + if (GENINFO_RES) + set(FLAG "--no-external") + endif () + + set(GENINFO_EXTERN_FLAG "${FLAG}" + CACHE STRING "Geninfo flag to exclude system sources.") +endif () + +# If Lcov was not found, exit module now. +if (NOT LCOV_FOUND) + return() +endif (NOT LCOV_FOUND) + + + + +# Create directories to be used. +file(MAKE_DIRECTORY ${LCOV_DATA_PATH_INIT}) +file(MAKE_DIRECTORY ${LCOV_DATA_PATH_CAPTURE}) + +set(LCOV_REMOVE_PATTERNS "") + +# This function will merge lcov files to a single target file. Additional lcov +# flags may be set with setting LCOV_EXTRA_FLAGS before calling this function. +function (lcov_merge_files OUTFILE ...) + # Remove ${OUTFILE} from ${ARGV} and generate lcov parameters with files. + list(REMOVE_AT ARGV 0) + + # Generate merged file. + string(REPLACE "${CMAKE_BINARY_DIR}/" "" FILE_REL "${OUTFILE}") + add_custom_command(OUTPUT "${OUTFILE}.raw" + COMMAND cat ${ARGV} > ${OUTFILE}.raw + DEPENDS ${ARGV} + COMMENT "Generating ${FILE_REL}" + ) + + add_custom_command(OUTPUT "${OUTFILE}" + COMMAND ${LCOV_BIN} --quiet -a ${OUTFILE}.raw --output-file ${OUTFILE} + --base-directory ${PROJECT_SOURCE_DIR} ${LCOV_EXTRA_FLAGS} + COMMAND ${LCOV_BIN} --quiet -r ${OUTFILE} ${LCOV_REMOVE_PATTERNS} + --output-file ${OUTFILE} ${LCOV_EXTRA_FLAGS} + DEPENDS ${OUTFILE}.raw + COMMENT "Post-processing ${FILE_REL}" + ) +endfunction () + + + + +# Add a new global target to generate initial coverage reports for all targets. +# This target will be used to generate the global initial info file, which is +# used to gather even empty report data. +if (NOT TARGET lcov-capture-init) + add_custom_target(lcov-capture-init) + set(LCOV_CAPTURE_INIT_FILES "" CACHE INTERNAL "") +endif (NOT TARGET lcov-capture-init) + + +# This function will add initial capture of coverage data for target , +# which is needed to get also data for objects, which were not loaded at +# execution time. It will call geninfo for every source file of once and +# store the info file in the same directory. +function (lcov_capture_initial_tgt TNAME) + # We don't have to check, if the target has support for coverage, thus this + # will be checked by add_coverage_target in Findcoverage.cmake. Instead we + # have to determine which gcov binary to use. + get_target_property(TSOURCES ${TNAME} SOURCES) + set(SOURCES "") + set(TCOMPILER "") + foreach (FILE ${TSOURCES}) + codecov_path_of_source(${FILE} FILE) + if (NOT "${FILE}" STREQUAL "") + codecov_lang_of_source(${FILE} LANG) + if (NOT "${LANG}" STREQUAL "") + list(APPEND SOURCES "${FILE}") + set(TCOMPILER ${CMAKE_${LANG}_COMPILER_ID}) + endif () + endif () + endforeach () + + # If no gcov binary was found, coverage data can't be evaluated. + if (NOT GCOV_${TCOMPILER}_BIN) + message(WARNING "No coverage evaluation binary found for ${TCOMPILER}.") + return() + endif () + + set(GCOV_BIN "${GCOV_${TCOMPILER}_BIN}") + set(GCOV_ENV "${GCOV_${TCOMPILER}_ENV}") + + + get_target_property(TBIN_DIR ${TNAME} BINARY_DIR) + set(TDIR ${TBIN_DIR}/CMakeFiles/${TNAME}.dir) + + set(GENINFO_FILES "") + foreach(FILE ${SOURCES}) + # generate empty coverage files + set(OUTFILE "${TDIR}/${FILE}.info.init") + list(APPEND GENINFO_FILES ${OUTFILE}) + + add_custom_command(OUTPUT ${OUTFILE} COMMAND ${GCOV_ENV} ${GENINFO_BIN} + --quiet --base-directory ${PROJECT_SOURCE_DIR} --initial + --gcov-tool ${GCOV_BIN} --output-filename ${OUTFILE} + ${GENINFO_EXTERN_FLAG} ${TDIR}/${FILE}.gcno + DEPENDS ${TNAME} + COMMENT "Capturing initial coverage data for ${FILE}" + ) + endforeach() + + # Concatenate all files generated by geninfo to a single file per target. + set(OUTFILE "${LCOV_DATA_PATH_INIT}/${TNAME}.info") + set(LCOV_EXTRA_FLAGS "--initial") + lcov_merge_files("${OUTFILE}" ${GENINFO_FILES}) + add_custom_target(${TNAME}-capture-init ALL DEPENDS ${OUTFILE}) + + # add geninfo file generation to global lcov-geninfo target + add_dependencies(lcov-capture-init ${TNAME}-capture-init) + set(LCOV_CAPTURE_INIT_FILES "${LCOV_CAPTURE_INIT_FILES}" + "${OUTFILE}" CACHE INTERNAL "" + ) +endfunction (lcov_capture_initial_tgt) + + +# This function will generate the global info file for all targets. It has to be +# called after all other CMake functions in the root CMakeLists.txt file, to get +# a full list of all targets that generate coverage data. +function (lcov_capture_initial) + # Skip this function (and do not create the following targets), if there are + # no input files. + if ("${LCOV_CAPTURE_INIT_FILES}" STREQUAL "") + return() + endif () + + # Add a new target to merge the files of all targets. + set(OUTFILE "${LCOV_DATA_PATH_INIT}/all_targets.info") + lcov_merge_files("${OUTFILE}" ${LCOV_CAPTURE_INIT_FILES}) + add_custom_target(lcov-geninfo-init ALL DEPENDS ${OUTFILE} + lcov-capture-init + ) +endfunction (lcov_capture_initial) + + + + +# Add a new global target to generate coverage reports for all targets. This +# target will be used to generate the global info file. +if (NOT TARGET lcov-capture) + add_custom_target(lcov-capture) + set(LCOV_CAPTURE_FILES "" CACHE INTERNAL "") +endif (NOT TARGET lcov-capture) + + +# This function will add capture of coverage data for target , which is +# needed to get also data for objects, which were not loaded at execution time. +# It will call geninfo for every source file of once and store the info +# file in the same directory. +function (lcov_capture_tgt TNAME) + # We don't have to check, if the target has support for coverage, thus this + # will be checked by add_coverage_target in Findcoverage.cmake. Instead we + # have to determine which gcov binary to use. + get_target_property(TSOURCES ${TNAME} SOURCES) + set(SOURCES "") + set(TCOMPILER "") + foreach (FILE ${TSOURCES}) + codecov_path_of_source(${FILE} FILE) + if (NOT "${FILE}" STREQUAL "") + codecov_lang_of_source(${FILE} LANG) + if (NOT "${LANG}" STREQUAL "") + list(APPEND SOURCES "${FILE}") + set(TCOMPILER ${CMAKE_${LANG}_COMPILER_ID}) + endif () + endif () + endforeach () + + # If no gcov binary was found, coverage data can't be evaluated. + if (NOT GCOV_${TCOMPILER}_BIN) + message(WARNING "No coverage evaluation binary found for ${TCOMPILER}.") + return() + endif () + + set(GCOV_BIN "${GCOV_${TCOMPILER}_BIN}") + set(GCOV_ENV "${GCOV_${TCOMPILER}_ENV}") + + get_target_property(TBIN_DIR ${TNAME} BINARY_DIR) + set(TDIR ${TBIN_DIR}/CMakeFiles/${TNAME}.dir) + + set(GENINFO_FILES "") + foreach(FILE ${SOURCES}) + # Generate coverage files. If no .gcda file was generated during + # execution, the empty coverage file will be used instead. + set(OUTFILE "${TDIR}/${FILE}.info") + list(APPEND GENINFO_FILES ${OUTFILE}) + + add_custom_command(OUTPUT ${OUTFILE} + COMMAND test -f "${TDIR}/${FILE}.gcda" + && ${GCOV_ENV} ${GENINFO_BIN} --quiet --base-directory + ${PROJECT_SOURCE_DIR} --gcov-tool ${GCOV_BIN} + --output-filename ${OUTFILE} ${GENINFO_EXTERN_FLAG} + ${TDIR}/${FILE}.gcda + || cp ${OUTFILE}.init ${OUTFILE} + DEPENDS ${TNAME} ${TNAME}-capture-init + COMMENT "Capturing coverage data for ${FILE}" + ) + endforeach() + + # Concatenate all files generated by geninfo to a single file per target. + set(OUTFILE "${LCOV_DATA_PATH_CAPTURE}/${TNAME}.info") + lcov_merge_files("${OUTFILE}" ${GENINFO_FILES}) + add_custom_target(${TNAME}-geninfo DEPENDS ${OUTFILE}) + + # add geninfo file generation to global lcov-capture target + add_dependencies(lcov-capture ${TNAME}-geninfo) + set(LCOV_CAPTURE_FILES "${LCOV_CAPTURE_FILES}" "${OUTFILE}" CACHE INTERNAL + "" + ) + + # Add target for generating html output for this target only. + file(MAKE_DIRECTORY ${LCOV_HTML_PATH}/${TNAME}) + add_custom_target(${TNAME}-genhtml + COMMAND ${GENHTML_BIN} --quiet --sort --prefix ${PROJECT_SOURCE_DIR} + --baseline-file ${LCOV_DATA_PATH_INIT}/${TNAME}.info + --output-directory ${LCOV_HTML_PATH}/${TNAME} + --title "${CMAKE_PROJECT_NAME} - target ${TNAME}" + ${GENHTML_CPPFILT_FLAG} ${OUTFILE} + DEPENDS ${TNAME}-geninfo ${TNAME}-capture-init + ) +endfunction (lcov_capture_tgt) + + +# This function will generate the global info file for all targets. It has to be +# called after all other CMake functions in the root CMakeLists.txt file, to get +# a full list of all targets that generate coverage data. +function (lcov_capture) + # Skip this function (and do not create the following targets), if there are + # no input files. + if ("${LCOV_CAPTURE_FILES}" STREQUAL "") + return() + endif () + + # Add a new target to merge the files of all targets. + set(OUTFILE "${LCOV_DATA_PATH_CAPTURE}/all_targets.info") + lcov_merge_files("${OUTFILE}" ${LCOV_CAPTURE_FILES}) + add_custom_target(lcov-geninfo DEPENDS ${OUTFILE} lcov-capture) + + # Add a new global target for all lcov targets. This target could be used to + # generate the lcov html output for the whole project instead of calling + # -geninfo and -genhtml for each target. It will also be + # used to generate a html site for all project data together instead of one + # for each target. + if (NOT TARGET lcov) + file(MAKE_DIRECTORY ${LCOV_HTML_PATH}/all_targets) + add_custom_target(lcov + COMMAND ${GENHTML_BIN} --quiet --sort + --baseline-file ${LCOV_DATA_PATH_INIT}/all_targets.info + --output-directory ${LCOV_HTML_PATH}/all_targets + --title "${CMAKE_PROJECT_NAME}" --prefix "${PROJECT_SOURCE_DIR}" + ${GENHTML_CPPFILT_FLAG} ${OUTFILE} + DEPENDS lcov-geninfo-init lcov-geninfo + ) + endif () +endfunction (lcov_capture) + + + + +# Add a new global target to generate the lcov html report for the whole project +# instead of calling -genhtml for each target (to create an own report +# for each target). Instead of the lcov target it does not require geninfo for +# all targets, so you have to call -geninfo to generate the info files +# the targets you'd like to have in your report or lcov-geninfo for generating +# info files for all targets before calling lcov-genhtml. +file(MAKE_DIRECTORY ${LCOV_HTML_PATH}/selected_targets) +if (NOT TARGET lcov-genhtml) + add_custom_target(lcov-genhtml + COMMAND ${GENHTML_BIN} + --quiet + --output-directory ${LCOV_HTML_PATH}/selected_targets + --title \"${CMAKE_PROJECT_NAME} - targets `find + ${LCOV_DATA_PATH_CAPTURE} -name \"*.info\" ! -name + \"all_targets.info\" -exec basename {} .info \\\;`\" + --prefix ${PROJECT_SOURCE_DIR} + --sort + ${GENHTML_CPPFILT_FLAG} + `find ${LCOV_DATA_PATH_CAPTURE} -name \"*.info\" ! -name + \"all_targets.info\"` + ) +endif (NOT TARGET lcov-genhtml) diff --git a/cmake/Findcodecov.cmake b/cmake/Findcodecov.cmake new file mode 100755 index 00000000..5ed9acc3 --- /dev/null +++ b/cmake/Findcodecov.cmake @@ -0,0 +1,258 @@ +# This file is part of CMake-codecov. +# +# Copyright (c) +# 2015-2017 RWTH Aachen University, Federal Republic of Germany +# +# See the LICENSE file in the package base directory for details +# +# Written by Alexander Haase, alexander.haase@rwth-aachen.de +# + + +# Add an option to choose, if coverage should be enabled or not. If enabled +# marked targets will be build with coverage support and appropriate targets +# will be added. If disabled coverage will be ignored for *ALL* targets. +option(ENABLE_COVERAGE "Enable coverage build." OFF) + +set(COVERAGE_FLAG_CANDIDATES + # gcc and clang + "-O0 -g -fprofile-arcs -ftest-coverage" + + # gcc and clang fallback + "-O0 -g --coverage" + ) + + +# Add coverage support for target ${TNAME} and register target for coverage +# evaluation. If coverage is disabled or not supported, this function will +# simply do nothing. +# +# Note: This function is only a wrapper to define this function always, even if +# coverage is not supported by the compiler or disabled. This function must +# be defined here, because the module will be exited, if there is no coverage +# support by the compiler or it is disabled by the user. +function (add_coverage TNAME) + # only add coverage for target, if coverage is support and enabled. + if (ENABLE_COVERAGE) + foreach (TNAME ${ARGV}) + add_coverage_target(${TNAME}) + endforeach () + endif () +endfunction (add_coverage) + + +# Add global target to gather coverage information after all targets have been +# added. Other evaluation functions could be added here, after checks for the +# specific module have been passed. +# +# Note: This function is only a wrapper to define this function always, even if +# coverage is not supported by the compiler or disabled. This function must +# be defined here, because the module will be exited, if there is no coverage +# support by the compiler or it is disabled by the user. +function (coverage_evaluate) + # add lcov evaluation + if (LCOV_FOUND) + lcov_capture_initial() + lcov_capture() + endif (LCOV_FOUND) +endfunction () + + +# Exit this module, if coverage is disabled. add_coverage is defined before this +# return, so this module can be exited now safely without breaking any build- +# scripts. +if (NOT ENABLE_COVERAGE) + return() +endif () + + + + +# Find the required flags foreach language. +set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET}) +set(CMAKE_REQUIRED_QUIET ${codecov_FIND_QUIETLY}) + +get_property(ENABLED_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES) +foreach (LANG ${ENABLED_LANGUAGES}) + # Coverage flags are not dependent on language, but the used compiler. So + # instead of searching flags foreach language, search flags foreach compiler + # used. + set(COMPILER ${CMAKE_${LANG}_COMPILER_ID}) + if (NOT COVERAGE_${COMPILER}_FLAGS) + foreach (FLAG ${COVERAGE_FLAG_CANDIDATES}) + if(NOT CMAKE_REQUIRED_QUIET) + message(STATUS "Try ${COMPILER} code coverage flag = [${FLAG}]") + endif() + + set(CMAKE_REQUIRED_FLAGS "${FLAG}") + unset(COVERAGE_FLAG_DETECTED CACHE) + + if (${LANG} STREQUAL "C") + include(CheckCCompilerFlag) + check_c_compiler_flag("${FLAG}" COVERAGE_FLAG_DETECTED) + + elseif (${LANG} STREQUAL "CXX") + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag("${FLAG}" COVERAGE_FLAG_DETECTED) + + elseif (${LANG} STREQUAL "Fortran") + # CheckFortranCompilerFlag was introduced in CMake 3.x. To be + # compatible with older Cmake versions, we will check if this + # module is present before we use it. Otherwise we will define + # Fortran coverage support as not available. + include(CheckFortranCompilerFlag OPTIONAL + RESULT_VARIABLE INCLUDED) + if (INCLUDED) + check_fortran_compiler_flag("${FLAG}" + COVERAGE_FLAG_DETECTED) + elseif (NOT CMAKE_REQUIRED_QUIET) + message("-- Performing Test COVERAGE_FLAG_DETECTED") + message("-- Performing Test COVERAGE_FLAG_DETECTED - Failed" + " (Check not supported)") + endif () + endif() + + if (COVERAGE_FLAG_DETECTED) + set(COVERAGE_${COMPILER}_FLAGS "${FLAG}" + CACHE STRING "${COMPILER} flags for code coverage.") + mark_as_advanced(COVERAGE_${COMPILER}_FLAGS) + break() + else () + message(WARNING "Code coverage is not available for ${COMPILER}" + " compiler. Targets using this compiler will be " + "compiled without it.") + endif () + endforeach () + endif () +endforeach () + +set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE}) + + + + +# Helper function to get the language of a source file. +function (codecov_lang_of_source FILE RETURN_VAR) + get_filename_component(FILE_EXT "${FILE}" EXT) + string(TOLOWER "${FILE_EXT}" FILE_EXT) + string(SUBSTRING "${FILE_EXT}" 1 -1 FILE_EXT) + + get_property(ENABLED_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES) + foreach (LANG ${ENABLED_LANGUAGES}) + list(FIND CMAKE_${LANG}_SOURCE_FILE_EXTENSIONS "${FILE_EXT}" TEMP) + if (NOT ${TEMP} EQUAL -1) + set(${RETURN_VAR} "${LANG}" PARENT_SCOPE) + return() + endif () + endforeach() + + set(${RETURN_VAR} "" PARENT_SCOPE) +endfunction () + + +# Helper function to get the relative path of the source file destination path. +# This path is needed by FindGcov and FindLcov cmake files to locate the +# captured data. +function (codecov_path_of_source FILE RETURN_VAR) + string(REGEX MATCH "TARGET_OBJECTS:([^ >]+)" _source ${FILE}) + + # If expression was found, SOURCEFILE is a generator-expression for an + # object library. Currently we found no way to call this function automatic + # for the referenced target, so it must be called in the directoryso of the + # object library definition. + if (NOT "${_source}" STREQUAL "") + set(${RETURN_VAR} "" PARENT_SCOPE) + return() + endif () + + + string(REPLACE "${CMAKE_CURRENT_BINARY_DIR}/" "" FILE "${FILE}") + if(IS_ABSOLUTE ${FILE}) + file(RELATIVE_PATH FILE ${CMAKE_CURRENT_SOURCE_DIR} ${FILE}) + endif() + + # get the right path for file + string(REPLACE ".." "__" PATH "${FILE}") + + set(${RETURN_VAR} "${PATH}" PARENT_SCOPE) +endfunction() + + + + +# Add coverage support for target ${TNAME} and register target for coverage +# evaluation. +function(add_coverage_target TNAME) + # Check if all sources for target use the same compiler. If a target uses + # e.g. C and Fortran mixed and uses different compilers (e.g. clang and + # gfortran) this can trigger huge problems, because different compilers may + # use different implementations for code coverage. + get_target_property(TSOURCES ${TNAME} SOURCES) + set(TARGET_COMPILER "") + set(ADDITIONAL_FILES "") + foreach (FILE ${TSOURCES}) + # If expression was found, FILE is a generator-expression for an object + # library. Object libraries will be ignored. + string(REGEX MATCH "TARGET_OBJECTS:([^ >]+)" _file ${FILE}) + if ("${_file}" STREQUAL "") + codecov_lang_of_source(${FILE} LANG) + if (LANG) + list(APPEND TARGET_COMPILER ${CMAKE_${LANG}_COMPILER_ID}) + + list(APPEND ADDITIONAL_FILES "${FILE}.gcno") + list(APPEND ADDITIONAL_FILES "${FILE}.gcda") + endif () + endif () + endforeach () + + list(REMOVE_DUPLICATES TARGET_COMPILER) + list(LENGTH TARGET_COMPILER NUM_COMPILERS) + + if (NUM_COMPILERS GREATER 1) + message(WARNING "Can't use code coverage for target ${TNAME}, because " + "it will be compiled by incompatible compilers. Target will be " + "compiled without code coverage.") + return() + + elseif (NUM_COMPILERS EQUAL 0) + message(WARNING "Can't use code coverage for target ${TNAME}, because " + "it uses an unknown compiler. Target will be compiled without " + "code coverage.") + return() + + elseif (NOT DEFINED "COVERAGE_${TARGET_COMPILER}_FLAGS") + # A warning has been printed before, so just return if flags for this + # compiler aren't available. + return() + endif() + + + # enable coverage for target + set_property(TARGET ${TNAME} APPEND_STRING + PROPERTY COMPILE_FLAGS " ${COVERAGE_${TARGET_COMPILER}_FLAGS}") + set_property(TARGET ${TNAME} APPEND_STRING + PROPERTY LINK_FLAGS " ${COVERAGE_${TARGET_COMPILER}_FLAGS}") + + + # Add gcov files generated by compiler to clean target. + set(CLEAN_FILES "") + foreach (FILE ${ADDITIONAL_FILES}) + codecov_path_of_source(${FILE} FILE) + list(APPEND CLEAN_FILES "CMakeFiles/${TNAME}.dir/${FILE}") + endforeach() + + set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES + "${CLEAN_FILES}") + + + add_gcov_target(${TNAME}) + add_lcov_target(${TNAME}) +endfunction(add_coverage_target) + + + + +# Include modules for parsing the collected data and output it in a readable +# format (like gcov and lcov). +find_package(Gcov) +find_package(Lcov) diff --git a/cmake/llvm-cov-wrapper b/cmake/llvm-cov-wrapper new file mode 100755 index 00000000..453f52d1 --- /dev/null +++ b/cmake/llvm-cov-wrapper @@ -0,0 +1,56 @@ +#!/bin/sh + +# This file is part of CMake-codecov. +# +# Copyright (c) +# 2015-2017 RWTH Aachen University, Federal Republic of Germany +# +# See the LICENSE file in the package base directory for details +# +# Written by Alexander Haase, alexander.haase@rwth-aachen.de +# + +if [ -z "$LLVM_COV_BIN" ] +then + echo "LLVM_COV_BIN not set!" >& 2 + exit 1 +fi + + +# Get LLVM version to find out. +LLVM_VERSION=$($LLVM_COV_BIN -version | grep -i "LLVM version" \ + | sed "s/^\([A-Za-z ]*\)\([0-9]*\).\([0-9]*\).*$/\2.\3/g") + +if [ "$1" = "-v" ] +then + echo "llvm-cov-wrapper $LLVM_VERSION" + exit 0 +fi + + +if [ -n "$LLVM_VERSION" ] +then + MAJOR=$(echo $LLVM_VERSION | cut -d'.' -f1) + MINOR=$(echo $LLVM_VERSION | cut -d'.' -f2) + + if [ $MAJOR -eq 3 ] && [ $MINOR -le 4 ] + then + if [ -f "$1" ] + then + filename=$(basename "$1") + extension="${filename##*.}" + + case "$extension" in + "gcno") exec $LLVM_COV_BIN --gcno="$1" ;; + "gcda") exec $LLVM_COV_BIN --gcda="$1" ;; + esac + fi + fi + + if [ $MAJOR -eq 3 ] && [ $MINOR -le 5 ] + then + exec $LLVM_COV_BIN $@ + fi +fi + +exec $LLVM_COV_BIN gcov $@ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c78fc16b..a988f7ff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,7 +61,7 @@ if ("${RTL}" STREQUAL "RTL-NOTFOUND") set_target_properties(libHPWHsim PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") endif () -#if (${PROJECT_NAME}_COVERAGE) -# add_coverage(${PROJECT_NAME}) -#endif() +if (${PROJECT_NAME}_COVERAGE) + add_coverage(libHPWHsim) +endif ()