Skip to content

Commit

Permalink
libpressio version 0.25.1
Browse files Browse the repository at this point in the history
Bug Fixes:

+ Modify the external metrics module to compile with C++11 on CentOS.
  Previously, it used move constructors on stringstreams that were not
  present on CentOS.
+ Used compat headers on some missing functions in the test cases
  • Loading branch information
robertu94 committed Dec 12, 2019
1 parent 72b8f9a commit 54b65fd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(libpressio VERSION "0.25.0" LANGUAGES CXX C)
project(libpressio VERSION "0.25.1" LANGUAGES CXX C)

#correct was to set a default build type
# https://blog.kitware.com/cmake-and-the-default-build-type/
Expand Down
2 changes: 1 addition & 1 deletion COPYRIGHT.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Copyright © 2019 , UChicago Argonne, LLC
All Rights Reserved
[libpressio, Version 0.25.0]
[libpressio, Version 0.25.1]
Robert Underwood
Argonne National Laboratory

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile-CentOS
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RUN git clone https://github.com/LLNL/zfp /src/zfp && \
rm -rf build && \
mkdir build && \
cd build && \
cmake3 .. -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_TESTS=ON -DLIBPRESSIO_HAS_MAGICK=OFF -DLIBPRESSIO_HAS_MGARD=ON -DBUILD_PYTHON_WRAPPER=ON -G Ninja && \
cmake3 .. -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_TESTS=ON -DLIBPRESSIO_HAS_MAGICK=OFF -DLIBPRESSIO_HAS_MGARD=ON -DBUILD_PYTHON_WRAPPER=ON -DLIBPRESSIO_CXX_VERSION=11 -G Ninja && \
cmake3 --build . && \
CTEST_OUTPUT_ON_FAILURE=1 ctest3 . && \
ninja-build install
Expand Down
29 changes: 16 additions & 13 deletions src/plugins/metrics/external.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace {
format_error=4
};
struct extern_proc_results {
std::stringstream stdout_stream; //stdout from the command
std::stringstream stderr_stream; //stdin from the command
std::string proc_stdout; //stdout from the command
std::string proc_stderr; //stdin from the command
int return_code = 0; //the return code from the external process
int error_code = success; //used to report errors with run_command
};
Expand Down Expand Up @@ -86,24 +86,26 @@ namespace {

int status = 0;
char buffer[2048];
std::ostringstream stdout_stream;
std::ostringstream stderr_stream;
do {
//read the stdout[0]
int nread;
while((nread = read(stdout_pipe_fd[0], buffer, 2048)) > 0) {
results.stdout_stream.write(buffer, nread);
stdout_stream.write(buffer, nread);
}

//read the stderr[0]
while((nread = read(stderr_pipe_fd[0], buffer, 2048)) > 0) {
results.stderr_stream.write(buffer, nread);
stderr_stream.write(buffer, nread);
}

//wait for the child to complete
waitpid(child, &status, 0);
} while (not WIFEXITED(status));

results.stdout_stream.seekg(0);
results.stderr_stream.seekg(0);
results.proc_stdout = stdout_stream.str();
results.proc_stderr = stderr_stream.str();
results.return_code = WEXITSTATUS(status);
}

Expand Down Expand Up @@ -146,9 +148,9 @@ class external_metric_plugin : public libpressio_metrics_plugin {


//returns the version number parsed, starts at 1, zero means error
size_t api_version_number(extern_proc_results& results) {
size_t api_version_number(std::istringstream& stdout_stream) {
std::string version_line;
std::getline(results.stdout_stream, version_line);
std::getline(stdout_stream, version_line);
auto eq_pos = version_line.find('=') + 1;
if(version_line.substr(0, eq_pos) == "external:api") {
//report error
Expand All @@ -159,10 +161,11 @@ class external_metric_plugin : public libpressio_metrics_plugin {

void parse_result(extern_proc_results& results) {
try{
size_t api_version = api_version_number(results);
std::istringstream stdout_stream(results.proc_stdout);
size_t api_version = api_version_number(stdout_stream);
switch(api_version) {
case 1:
parse_v1(results);
parse_v1(stdout_stream, results);
return;
default:
(void)0;
Expand All @@ -175,17 +178,17 @@ class external_metric_plugin : public libpressio_metrics_plugin {
this->results.set("external:stderr", "");
}

void parse_v1(extern_proc_results& input) {
void parse_v1(std::istringstream& stdout_stream, extern_proc_results& input) {
results.clear();

for (std::string line; std::getline(input.stdout_stream, line); ) {
for (std::string line; std::getline(stdout_stream, line); ) {
auto equal_pos = line.find('=');
std::string name = "external:results:" + line.substr(0, equal_pos);
std::string value_s = line.substr(equal_pos + 1);
double value = std::stod(value_s);
results.set(name, value);
}
results.set("external:stderr", input.stderr_stream.str());
results.set("external:stderr", input.proc_stderr);
results.set("external:return_code", input.return_code);
results.set("external:error_code", input.return_code);
}
Expand Down
5 changes: 3 additions & 2 deletions test/test_register_compressor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "libpressio_ext/cpp/options.h"
#include "libpressio_ext/cpp/pressio.h"
#include "libpressio_ext/compressors/sz.h"
#include "libpressio_ext/compat/std_compat.h"

namespace {
struct log_fn{
Expand Down Expand Up @@ -108,13 +109,13 @@ class log_transform : public libpressio_compressor_plugin {
pressio_compressor compressor;
};

static pressio_register X(compressor_plugins(), "log", [](){ return std::make_unique<log_transform>();});
static pressio_register X(compressor_plugins(), "log", [](){ return compat::make_unique<log_transform>();});

TEST(ExternalPlugin, TestLogCompressor) {
pressio library;

auto sz_compressor = library.get_compressor("sz");
auto log_compressor = std::make_unique<log_transform>(std::move(sz_compressor));
auto log_compressor = compat::make_unique<log_transform>(std::move(sz_compressor));
auto options = log_compressor->get_options();
options.set("sz:error_bound_mode", ABS);
options.set("sz:abs_err_bound", 0.5);
Expand Down

0 comments on commit 54b65fd

Please sign in to comment.