Skip to content

Commit

Permalink
Speed up unit test for #9204
Browse files Browse the repository at this point in the history
```
[ RUN      ] EnergyPlusFixture.OutputProcessor_StdoutRecordCount
2005-12-22 02:45
/home/julien/Software/Others/EnergyPlus/tst/EnergyPlus/unit/OutputProcessor.unit.cc:5483: Failure
Expected: (state->dataGlobal->StdOutputRecordCount) > (0), actual: -2147482095 vs 0
/home/julien/Software/Others/EnergyPlus/tst/EnergyPlus/unit/OutputProcessor.unit.cc:5484: Failure
Expected: (state->dataGlobal->StdMeterRecordCount) > (0), actual: -2147483648 vs 0
```
  • Loading branch information
jmarrec committed May 30, 2024
1 parent 4e24dec commit 00a7d05
Showing 1 changed file with 39 additions and 12 deletions.
51 changes: 39 additions & 12 deletions tst/EnergyPlus/unit/OutputProcessor.unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5364,14 +5364,14 @@ namespace OutputProcessor {
ASSERT_TRUE(process_idf(idf_objects));

// Demonstrate that it's not unreasonable to reach the INT_MAX limit at all
// NOTE: the test takes way to long to run
constexpr int numOfTimeStepInHour = 60;
constexpr int hoursInYear = 8760;
constexpr int numOutputVariables = 4200;
constexpr size_t totalRecords =
static_cast<size_t>(numOfTimeStepInHour) * static_cast<size_t>(hoursInYear) * static_cast<size_t>(numOutputVariables);

EXPECT_GT(totalRecords, static_cast<size_t>(INT_MAX));
constexpr auto INT_MAX_AS_SIZE_T = static_cast<size_t>(INT_MAX);
EXPECT_GT(totalRecords, INT_MAX_AS_SIZE_T);

state->dataEnvrn->DSTIndicator = 0;
state->dataEnvrn->HolidayIndex = 0;
Expand Down Expand Up @@ -5409,6 +5409,10 @@ namespace OutputProcessor {
state->dataEnvrn->Year = 2005;
state->dataGlobal->CalendarYear = 2005;

// NOTE: the test takes way to long to run if do call UpdateMeterReporting and UpdateDataandReport
// So I'm going to just scan for a timestamp were we're about to overflow, and fake it
size_t records_written = 0;
bool found_about_to_overflow = false;
for (state->dataEnvrn->Month = 1; state->dataEnvrn->Month <= 12; ++state->dataEnvrn->Month) {
state->dataEnvrn->EndMonthFlag = false;
for (state->dataEnvrn->DayOfMonth = 1; state->dataEnvrn->DayOfMonth <= state->dataWeather->EndDayOfMonth(state->dataEnvrn->Month);
Expand Down Expand Up @@ -5439,23 +5443,46 @@ namespace OutputProcessor {
if (state->dataEnvrn->DayOfMonth == state->dataWeather->EndDayOfMonth(state->dataEnvrn->Month)) {
state->dataEnvrn->EndMonthFlag = true;
}

fmt::print("{:04d}-{:02d}-{:02d} {:02d}:{:02d}\n",
state->dataGlobal->CalendarYear,
state->dataEnvrn->Month,
state->dataEnvrn->DayOfMonth,
state->dataGlobal->HourOfDay,
state->dataGlobal->TimeStep);
UpdateMeterReporting(*state);
UpdateDataandReport(*state, TimeStepType::Zone);
records_written += numOutputVariables;
if (records_written > (INT_MAX_AS_SIZE_T - numOutputVariables)) {
EXPECT_EQ("2005-12-22 02:45",
fmt::format("{:04d}-{:02d}-{:02d} {:02d}:{:02d}",
state->dataGlobal->CalendarYear,
state->dataEnvrn->Month,
state->dataEnvrn->DayOfMonth,
state->dataGlobal->HourOfDay,
state->dataGlobal->TimeStep));
UpdateMeterReporting(*state);
UpdateDataandReport(*state, TimeStepType::Zone);
found_about_to_overflow = true;
break;
}
}
if (found_about_to_overflow) {
break;
}
}
if (found_about_to_overflow) {
break;
}
}
if (found_about_to_overflow) {
break;
}
break;
}
ASSERT_TRUE(found_about_to_overflow);
EXPECT_EQ(numOutputVariables + 1, state->dataGlobal->StdOutputRecordCount);
EXPECT_EQ(1, state->dataGlobal->StdMeterRecordCount);
EXPECT_TRUE(has_eso_output(true));
state->dataGlobal->StdOutputRecordCount = records_written;
state->dataGlobal->StdMeterRecordCount = INT_MAX;

++state->dataGlobal->TimeStep;

UpdateMeterReporting(*state);
UpdateDataandReport(*state, TimeStepType::Zone);
EXPECT_GT(state->dataGlobal->StdOutputRecordCount, 0);
EXPECT_GT(state->dataGlobal->StdMeterRecordCount, 0);
}
} // namespace OutputProcessor

Expand Down

0 comments on commit 00a7d05

Please sign in to comment.