Skip to content

Commit

Permalink
#810 a few modifications
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitri Baron <[email protected]>
  • Loading branch information
barondim committed Jan 31, 2025
1 parent 4bd5380 commit 06209b7
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 80 deletions.
5 changes: 4 additions & 1 deletion cmake/TestMain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#

if(${USE_ZIP} STREQUAL "YES")
execute_process(COMMAND zip -j res/${TEST_NAME}.zip res/TestIIDM_${TEST_NAME}.iidm res/config_${TEST_NAME}.json)
# clean-up : delete the zip archive and the previous unzipped files
execute_process(COMMAND rm -f res/${TEST_NAME}.zip res/TestIIDM_${TEST_NAME}.iidm res/config_${TEST_NAME}.json)

execute_process(COMMAND zip -j res/${TEST_NAME}.zip res/res_to_zip/TestIIDM_${TEST_NAME}.iidm res/res_to_zip/config_${TEST_NAME}.json)
set(_command ${EXE} --network=TestIIDM_${TEST_NAME}.iidm --config=config_${TEST_NAME}.json --input-archive=res/${TEST_NAME}.zip)
else()
set(_command ${EXE} --network=res/TestIIDM_${TEST_NAME}.iidm --config=res/config_${TEST_NAME}.json)
Expand Down
5 changes: 4 additions & 1 deletion cmake/TestMainNSA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#

if(${USE_ZIP} STREQUAL "YES")
execute_process(COMMAND zip -j res/${TEST_NAME}.zip res/TestIIDM_${TEST_NAME}.iidm res/config_${TEST_NAME}.json res/contingencies_${TEST_NAME}.json)
# clean-up : delete the zip archive and the previous unzipped files
execute_process(COMMAND rm -f res/${TEST_NAME}.zip res/TestIIDM_${TEST_NAME}.iidm res/config_${TEST_NAME}.json res/contingencies_${TEST_NAME}.json)

execute_process(COMMAND zip -j res/${TEST_NAME}.zip res/res_to_zip/TestIIDM_${TEST_NAME}.iidm res/res_to_zip/config_${TEST_NAME}.json res/res_to_zip/contingencies_${TEST_NAME}.json)
set(_dfl_cmd ${EXE} --network=TestIIDM_${TEST_NAME}.iidm --config=config_${TEST_NAME}.json --contingencies=contingencies_${TEST_NAME}.json --input-archive=res/${TEST_NAME}.zip --nsa)
else()
set(_dfl_cmd ${EXE} --network=res/TestIIDM_${TEST_NAME}.iidm --config=res/config_${TEST_NAME}.json --contingencies=res/contingencies_${TEST_NAME}.json --nsa)
Expand Down
5 changes: 4 additions & 1 deletion cmake/TestMainSA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#

if(${USE_ZIP} STREQUAL "YES")
execute_process(COMMAND zip -j res/${TEST_NAME}.zip res/TestIIDM_${TEST_NAME}.iidm res/config_${TEST_NAME}.json res/contingencies_${TEST_NAME}.json)
# clean-up : delete the zip archive and the previous unzipped files
execute_process(COMMAND rm -f res/${TEST_NAME}.zip res/TestIIDM_${TEST_NAME}.iidm res/config_${TEST_NAME}.json res/contingencies_${TEST_NAME}.json)

execute_process(COMMAND zip -j res/${TEST_NAME}.zip res/res_to_zip/TestIIDM_${TEST_NAME}.iidm res/res_to_zip/config_${TEST_NAME}.json res/res_to_zip/contingencies_${TEST_NAME}.json)
set(_dfl_cmd ${EXE} --network=TestIIDM_${TEST_NAME}.iidm --config=config_${TEST_NAME}.json --contingencies=contingencies_${TEST_NAME}.json --input-archive=res/${TEST_NAME}.zip)
else ()
set(_dfl_cmd ${EXE} --network=res/TestIIDM_${TEST_NAME}.iidm --config=res/config_${TEST_NAME}.json --contingencies=res/contingencies_${TEST_NAME}.json)
Expand Down
2 changes: 2 additions & 0 deletions etc/Dictionaries/DFLError_en_GB.dic
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ ConnexityError = slack node of id %1% not present in main conn
NetworkHasNoRegulatingGenerator = network file %1% has no generator regulating voltage in the main connex component
SlackNodeNotFound = no slack node found for network '%1%'
FailToOpenLogFile = failed to open %1% log file
FileNotFound = file %1 not found
LibZipError = zip error for file %1 : %2
82 changes: 37 additions & 45 deletions scripts/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ def get_argparser():
except KeyError:
pass

results_root = os.path.realpath(os.path.join(options.root, "resultsTestsTmp", options.testdir))
reference_root = os.path.realpath(os.path.join(options.root, "reference", options.testdir))

if options.output_zip:
zip_archive_parent_directory = os.path.join(options.root, "resultsTestsTmp", options.testdir)
zip_archive_path = os.path.join(zip_archive_parent_directory, options.output_zip)
unzipped_archive_path = zip_archive_parent_directory
zip_archive_path = os.path.join(results_root, options.output_zip)
try:
with zipfile.ZipFile(zip_archive_path, "r") as zip_ref:
zip_ref.extractall(unzipped_archive_path)
zip_ref.extractall(results_root)
except FileNotFoundError:
print("[ERROR] " + zip_archive_path + " is missing")
nb_differences += 1
Expand All @@ -73,72 +74,63 @@ def get_argparser():
is_constraints_generated = (buildType == "Debug" or (buildType == "Release" and "CONSTRAINTS" in chosen_outputs))
is_lost_equipement_generated = (buildType == "Debug" or (buildType == "Release" and "LOSTEQ" in chosen_outputs))

results_root = os.path.realpath(os.path.join(options.root, "resultsTestsTmp", options.testdir))
reference_root = os.path.realpath(os.path.join(options.root, "reference", options.testdir))

outputiidm_result_paths = list()
outputiidm_result_paths.append(os.path.realpath(os.path.join(results_root, "outputs/finalState/outputIIDM.xml")))
outputiidm_result_path = os.path.realpath(os.path.join(results_root, "outputs/finalState/outputIIDM.xml"))
outputiidm_reference_path = os.path.realpath(os.path.join(reference_root, "outputIIDM.xml"))

if not os.path.exists(outputiidm_reference_path):
print("Reference path " + outputiidm_reference_path + " does not exist : not checked")
else:
for outputiidm_result_path in outputiidm_result_paths:
if options.verbose:
print("comparing " + outputiidm_result_path + " and " + outputiidm_reference_path)
if options.verbose:
print("comparing " + outputiidm_result_path + " and " + outputiidm_reference_path)

(nb_differences_local, msg) = iidmDiff.OutputIIDMCloseEnough(outputiidm_result_path, outputiidm_reference_path)
if nb_differences_local > 0:
print("[ERROR] " + outputiidm_result_path + ": " + msg)
elif options.verbose:
print("No difference")
nb_differences += nb_differences_local
(nb_differences_local, msg) = iidmDiff.OutputIIDMCloseEnough(outputiidm_result_path, outputiidm_reference_path)
if nb_differences_local > 0:
print("[ERROR] " + outputiidm_result_path + ": " + msg)
elif options.verbose:
print("No difference")
nb_differences += nb_differences_local

# dyd and par
nb_differences += compare_dyd_and_par_files(results_root, reference_root, options.verbose)

if is_constraints_generated:
#constraints
constraints_result_paths = list()
constraints_result_paths.append(os.path.realpath(os.path.join(results_root, "outputs/constraints/constraints.xml")))
constraints_result_path = os.path.realpath(os.path.join(results_root, "outputs/constraints/constraints.xml"))
constraints_reference_path = os.path.realpath(os.path.join(reference_root, "constraints.xml"))

if not os.path.exists(constraints_reference_path):
print("Reference path " + constraints_reference_path + " does not exist : not checked")
else:
for constraints_result_path in constraints_result_paths:
if options.verbose:
print("comparing " + constraints_result_path + " and " + constraints_reference_path)

(nb_differences_local, msg) = constraintsDiff.output_constraints_close_enough(constraints_result_path, constraints_reference_path)
if nb_differences_local > 0:
print("[ERROR] constraints file " + constraints_result_path + " different from reference file " + constraints_reference_path)
print(msg)
elif options.verbose:
print("No difference")
nb_differences += nb_differences_local
if options.verbose:
print("comparing " + constraints_result_path + " and " + constraints_reference_path)

(nb_differences_local, msg) = constraintsDiff.output_constraints_close_enough(constraints_result_path, constraints_reference_path)
if nb_differences_local > 0:
print("[ERROR] constraints file " + constraints_result_path + " different from reference file " + constraints_reference_path)
print(msg)
elif options.verbose:
print("No difference")
nb_differences += nb_differences_local

if is_lost_equipement_generated:
#lost equipments
lost_equipments_result_paths = list()
lost_equipments_result_paths.append(os.path.realpath(os.path.join(results_root, "outputs/lostEquipments/lostEquipments.xml")))
lost_equipments_result_path = os.path.realpath(os.path.join(results_root, "outputs/lostEquipments/lostEquipments.xml"))
lost_equipments_reference_path = os.path.realpath(os.path.join(reference_root, "lostEquipments.xml"))

if not os.path.exists(lost_equipments_reference_path):
print("Reference path " + lost_equipments_reference_path + " does not exist : not checked")
else:
for lost_equipments_result_path in lost_equipments_result_paths:
if options.verbose:
print("comparing " + lost_equipments_result_path + " and " + lost_equipments_reference_path)

# compare line per line with universal newline, stop at first diff
with open(lost_equipments_result_path) as f1, open(lost_equipments_reference_path) as f2:
identical = all(l1 == l2 for l1, l2 in zip_longest(f1, f2))
if identical:
print("No difference")
else:
print("[ERROR] lost equipments file " + lost_equipments_result_path + " different from reference file " + lost_equipments_reference_path)
nb_differences += 1
if options.verbose:
print("comparing " + lost_equipments_result_path + " and " + lost_equipments_reference_path)

# compare line per line with universal newline, stop at first diff
with open(lost_equipments_result_path) as f1, open(lost_equipments_reference_path) as f2:
identical = all(l1 == l2 for l1, l2 in zip_longest(f1, f2))
if identical:
print("No difference")
else:
print("[ERROR] lost equipments file " + lost_equipments_result_path + " different from reference file " + lost_equipments_reference_path)
nb_differences += 1
else:
raise UnknownBuildType(buildType)

Expand Down
20 changes: 9 additions & 11 deletions scripts/diffContingencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,6 @@ def compare_file(options, contingency_folder, chosen_outputs):

if buildType == "Debug" or buildType == "Release" or buildType == "Coverage":

if options.output_zip:
zip_archive_parent_directory = os.path.join(options.root, "resultsTestsTmp", options.testdir)
zip_archive_path = os.path.join(zip_archive_parent_directory, options.output_zip)
unzipped_archive_path = zip_archive_parent_directory
try:
with zipfile.ZipFile(zip_archive_path, "r") as zip_ref:
zip_ref.extractall(unzipped_archive_path)
except FileNotFoundError:
print("[ERROR] " + zip_archive_path + " is missing")
nb_differences += 1

if buildType == "Debug" or (buildType == "Release" and "STEADYSTATE" in chosen_outputs) or buildType == "Coverage":
# output IIDM
result_path = full_path(
Expand Down Expand Up @@ -158,6 +147,15 @@ def full_path(a, *paths):
results_root = full_path(options.root, "resultsTestsTmp", options.testdir)
reference_root = full_path(options.root, "reference", options.testdir)

if options.output_zip:
zip_archive_path = os.path.join(results_root, options.output_zip)
try:
with zipfile.ZipFile(zip_archive_path, "r") as zip_ref:
zip_ref.extractall(results_root)
except FileNotFoundError:
print("[ERROR] " + zip_archive_path + " is missing")
total_diffs += 1

print(results_root)
for folder in os.listdir(results_root):
if os.path.isdir(os.path.join(results_root, folder)):
Expand Down
19 changes: 0 additions & 19 deletions sources/Common/include/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,11 @@
* @brief Options header file
*/

namespace zip {
class ZipFile;
}

/// @brief Namespace for dynaflow launcher components
namespace dfl {
/// @brief Namespace for common components to dynawo-launcher
namespace common {

namespace po = boost::program_options;

/**
* @brief Manager for input programm options
*
Expand Down Expand Up @@ -94,19 +88,6 @@ class Options {
*/
Request parse(int argc, char* argv[]);

/**
* @brief Check whether all required files are present in the specified archive
*
* This method checks if the zip archive contains all files required for execution, such as the network file,
* configuration file, and optionally the contingencies file.
*
* @param vm A variables map containing the input arguments passed to Dynaflow-launcher. It is used to determine if the optional contingencies file is required.
* @param archive A shared pointer to the zip archive to be checked.
*
* @returns true if one or more required files are missing, false otherwise
*/
bool areRequiredFilesMissing(const po::variables_map& vm, const boost::shared_ptr<zip::ZipFile>& archive) const;

/**
* @brief Retrieves description of options
*
Expand Down
24 changes: 22 additions & 2 deletions sources/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <libzip/ZipFileFactory.h>
#include <libzip/ZipInputStream.h>
#include <libzip/ZipOutputStream.h>
#include <libzip/ZipException.h>

#include <chrono>
#include <cstdlib>
Expand Down Expand Up @@ -156,7 +157,7 @@ void dumpZipArchive(std::unordered_map<std::string, std::string> &mapOutputFiles

boost::shared_ptr<zip::ZipFile> archive = zip::ZipFileFactory::newInstance();
const std::string archivePath = createAbsolutePath("outputs.zip", outputPath.generic_string());
if (!runtimeConfig.contingenciesFilePath.empty())
if (!runtimeConfig.contingenciesFilePath.empty() && boost::filesystem::exists(archivePath))
archive = zip::ZipInputStream::read(archivePath);
for (const std::pair<std::string, std::string> &outputFile : mapOutputFilesData) {
archive->addEntry(outputFile.first, outputFile.second);
Expand Down Expand Up @@ -204,7 +205,26 @@ int main(int argc, char *argv[]) {
boost::filesystem::path contingencyPath(runtimeConfig.contingenciesFilePath);
if (!runtimeConfig.zipArchivePath.empty()) {
if (mpiContext.isRootProc()) {
boost::shared_ptr<zip::ZipFile> archive = zip::ZipInputStream::read(runtimeConfig.zipArchivePath);
boost::shared_ptr<zip::ZipFile> archive;
try {
try {
archive = zip::ZipInputStream::read(runtimeConfig.zipArchivePath);
} catch (const zip::ZipException& e) {
switch (e.getErrorCode()) {
case zip::Error::Code::LIBARCHIVE_INTERNAL_ERROR:
throw Error(LibZipError, runtimeConfig.zipArchivePath, e.what());
case zip::Error::Code::FILE_NOT_FOUND:
throw Error(FileNotFound, e.what());
default:
// other libzip errors
throw;
}
}
} catch (std::exception& e) {
std::cerr << "Initialization failed: " << e.what() << std::endl;
return EXIT_FAILURE;
}

std::string archiveParentPath = boost::filesystem::path(runtimeConfig.zipArchivePath).parent_path().string();
for (std::map<std::string, boost::shared_ptr<zip::ZipEntry>>::const_iterator archiveIt = archive->getEntries().begin();
archiveIt != archive->getEntries().end(); ++archiveIt) {
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 06209b7

Please sign in to comment.