Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineGautier committed Sep 21, 2023
1 parent 94a8a0e commit 5f17768
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ env:
# - TEST_ARG="make test-dymola PACKAGE=\"Buildings.Utilities\""
# - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.Utilities\""
# - TEST_ARG="make test-optimica PACKAGE=\"Buildings.Utilities\""
- TEST_ARG="make test-dymola PACKAGE=\"Buildings.Templates\""
# - TEST_ARG="make test-dymola PACKAGE=\"Buildings.Templates\""
# - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.Templates\""
# - TEST_ARG="make test-optimica PACKAGE=\"Buildings.Templates\""
- TEST_ARG="make test-templates-optimica"
Expand Down
14 changes: 2 additions & 12 deletions Buildings/Resources/Scripts/travis/templates/ChilledWaterPlants.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,5 @@
# Simulate cases.
results = simulate_cases(combinations, simulator=SIMULATOR, asy=False)

# Report and clean.
df = report_clean(combinations, results)

# Log and exit.
if df.errorcode.abs().sum() != 0:
print(
CRED + 'Some simulations failed: ' + CEND + 'see the file `unitTestsTemplates.log`.\n'
)
sys.exit(1)
else:
print(CGREEN + 'All simulations succeeded.\n' + CEND)
sys.exit(0)
# Report, clean and exit.
report_clean(combinations, results)
14 changes: 2 additions & 12 deletions Buildings/Resources/Scripts/travis/templates/VAVBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,5 @@
# Simulate cases.
results = simulate_cases(combinations, simulator=SIMULATOR, asy=False)

# Report and clean.
df = report_clean(combinations, results)

# Log and exit.
if df.errorcode.abs().sum() != 0:
print(
CRED + 'Some simulations failed: ' + CEND + 'see the file `unitTestsTemplates.log`.\n'
)
sys.exit(1)
else:
print(CGREEN + 'All simulations succeeded.\n' + CEND)
sys.exit(0)
# Report, clean and exit.
report_clean(combinations, results)
14 changes: 2 additions & 12 deletions Buildings/Resources/Scripts/travis/templates/VAVMultiZone.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,5 @@
# Simulate cases.
results = simulate_cases(combinations, simulator=SIMULATOR, asy=False)

# Report and clean.
df = report_clean(combinations, results)

# Log and exit.
if df.errorcode.abs().sum() != 0:
print(
CRED + 'Some simulations failed: ' + CEND + 'see the file `unitTestsTemplates.log`.\n'
)
sys.exit(1)
else:
print(CGREEN + 'All simulations succeeded.\n' + CEND)
sys.exit(0)
# Report, clean and exit.
report_clean(combinations, results)
4 changes: 0 additions & 4 deletions Buildings/Resources/Scripts/travis/templates/checkandrun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ for type in "${!checksum_dirs[@]}"; do
# Launch simulations (typically several thousands).
python "${test_script[$type]}" $SIMULATOR $FRACTION_TEST_COVERAGE
if (( $? != 0 )); then
if [[ -s unitTestsTemplates.log ]]; then
printf "Below is the error log.\n\n"
cat unitTestsTemplates.log
fi
exit 1
fi
else
Expand Down
37 changes: 25 additions & 12 deletions Buildings/Resources/Scripts/travis/templates/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class modifications of the combination (concatenated).


def report_clean(combinations, results):
"""Report and clean after simulations.
"""Report, clean and exit after simulations.
Args:
combinations: list[tuple[str, list[str], str]]: List of combinations.
Expand All @@ -366,14 +366,27 @@ def report_clean(combinations, results):
errorlog=[r[1] for r in results],
)
)

with open('unitTestsTemplates.log', 'w') as FH:
for idx in df[df.errorcode != 0].index:
FH.write(
f'*** Simulation failed for {df.iloc[idx].model} with the error code {df.iloc[idx].errorcode} '
+ 'and the following class modifications and error log.\n\n'
+ ',\n'.join(df.iloc[idx].modif)
+ f'\n\n{df.iloc[idx].errorlog}\n\n'
)

return df
assert len(df) > 0, 'Error when trying to retrieve simulation results as a DataFrame.'

# Log and exit.
if df.errorcode.abs().sum() != 0:
with open('unitTestsTemplates.log', 'w') as FH:
for idx in df[df.errorcode != 0].index:
FH.write(
f'*** Simulation failed for {df.iloc[idx].model} with the error code {df.iloc[idx].errorcode} '
+ 'and the following class modifications and error log.\n\n'
+ ',\n'.join(df.iloc[idx].modif)
+ f'\n\n{df.iloc[idx].errorlog}\n\n'
)

number_failure = df.errorcode.apply(lambda x: 1 if x != 0 else 0).sum()
print(
CRED
+ f'{int(number_failure / len(df) * 100)} % of the simulations failed. '
+ CEND
+ 'See the file `unitTestsTemplates.log`.\n'
)
sys.exit(1)
else:
print(CGREEN + 'All simulations succeeded.\n' + CEND)
sys.exit(0)

0 comments on commit 5f17768

Please sign in to comment.