summaryrefslogtreecommitdiffstats
path: root/eval
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2022-03-04 13:38:36 +0000
committerHåvard Pettersen <havardpe@oath.com>2022-03-05 15:00:58 +0000
commit2681bcd99a024d0e94c2cddd08b7636818773a73 (patch)
treefe8466205ba79ea6b7ab89008247070f88cd918f /eval
parentbeed3becc8ec1abe88aea8aa88e6e703fb67dc3c (diff)
gc old process code
also added read_line function to new Process code
Diffstat (limited to 'eval')
-rw-r--r--eval/src/tests/apps/analyze_onnx_model/analyze_onnx_model_test.cpp2
-rw-r--r--eval/src/tests/apps/eval_expr/eval_expr_test.cpp3
-rw-r--r--eval/src/vespa/eval/eval/test/test_io.cpp79
-rw-r--r--eval/src/vespa/eval/eval/test/test_io.h30
4 files changed, 14 insertions, 100 deletions
diff --git a/eval/src/tests/apps/analyze_onnx_model/analyze_onnx_model_test.cpp b/eval/src/tests/apps/analyze_onnx_model/analyze_onnx_model_test.cpp
index 72ef0346ea3..dc4527dd5c8 100644
--- a/eval/src/tests/apps/analyze_onnx_model/analyze_onnx_model_test.cpp
+++ b/eval/src/tests/apps/analyze_onnx_model/analyze_onnx_model_test.cpp
@@ -97,4 +97,4 @@ TEST_F("test error: symbolic size mismatch", ServerCmd(probe_cmd, ServerCmd::cap
//-----------------------------------------------------------------------------
-TEST_MAIN_WITH_PROCESS_PROXY() { TEST_RUN_ALL(); }
+TEST_MAIN() { TEST_RUN_ALL(); }
diff --git a/eval/src/tests/apps/eval_expr/eval_expr_test.cpp b/eval/src/tests/apps/eval_expr/eval_expr_test.cpp
index fd103829618..d7979c6dbea 100644
--- a/eval/src/tests/apps/eval_expr/eval_expr_test.cpp
+++ b/eval/src/tests/apps/eval_expr/eval_expr_test.cpp
@@ -4,7 +4,6 @@
#include <vespa/vespalib/testkit/time_bomb.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/data/slime/slime.h>
-#include <vespa/vespalib/util/child_process.h>
#include <vespa/vespalib/data/input.h>
#include <vespa/vespalib/data/output.h>
#include <vespa/vespalib/data/simple_buffer.h>
@@ -168,4 +167,4 @@ TEST_F("require that type issues produces error", Server()) {
//-----------------------------------------------------------------------------
-TEST_MAIN_WITH_PROCESS_PROXY() { TEST_RUN_ALL(); }
+TEST_MAIN() { TEST_RUN_ALL(); }
diff --git a/eval/src/vespa/eval/eval/test/test_io.cpp b/eval/src/vespa/eval/eval/test/test_io.cpp
index 044b6779431..5512ecf0c1c 100644
--- a/eval/src/vespa/eval/eval/test/test_io.cpp
+++ b/eval/src/vespa/eval/eval/test/test_io.cpp
@@ -66,59 +66,6 @@ StdOut::commit(size_t bytes)
//-----------------------------------------------------------------------------
-ChildIn::ChildIn(ChildProcess &child)
- : _child(child),
- _output()
-{
-}
-
-WritableMemory
-ChildIn::reserve(size_t bytes)
-{
- return _output.reserve(bytes);
-}
-
-Output &
-ChildIn::commit(size_t bytes)
-{
- _output.commit(bytes);
- Memory buf = _output.obtain();
- REQUIRE(_child.write(buf.data, buf.size));
- _output.evict(buf.size);
- return *this;
-}
-
-//-----------------------------------------------------------------------------
-
-ChildOut::ChildOut(ChildProcess &child)
- : _child(child),
- _input()
-{
- REQUIRE(_child.running());
- REQUIRE(!_child.failed());
-}
-
-Memory
-ChildOut::obtain()
-{
- if ((_input.get().size == 0) && !_child.eof()) {
- WritableMemory buf = _input.reserve(4_Ki);
- uint32_t res = _child.read(buf.data, buf.size);
- REQUIRE((res > 0) || _child.eof());
- _input.commit(res);
- }
- return _input.obtain();
-}
-
-Input &
-ChildOut::evict(size_t bytes)
-{
- _input.evict(bytes);
- return *this;
-}
-
-//-----------------------------------------------------------------------------
-
void
ServerCmd::maybe_close()
{
@@ -132,10 +79,8 @@ void
ServerCmd::maybe_exit()
{
if (!_exited) {
- read_until_eof(_child_stdout);
- assert(_child.wait());
- assert(!_child.running());
- _exit_code = _child.getExitCode();
+ read_until_eof(_child);
+ _exit_code = _child.join();
_exited = true;
}
}
@@ -156,9 +101,7 @@ ServerCmd::dump_message(const char *prefix, const Slime &slime)
}
ServerCmd::ServerCmd(vespalib::string cmd)
- : _child(cmd.c_str()),
- _child_stdin(_child),
- _child_stdout(_child),
+ : _child(cmd),
_basename(fs::path(cmd).filename()),
_closed(false),
_exited(false),
@@ -167,9 +110,7 @@ ServerCmd::ServerCmd(vespalib::string cmd)
}
ServerCmd::ServerCmd(vespalib::string cmd, capture_stderr_tag)
- : _child(cmd.c_str(), ChildProcess::capture_stderr_tag()),
- _child_stdin(_child),
- _child_stdout(_child),
+ : _child(cmd, true),
_basename(fs::path(cmd).filename()),
_closed(false),
_exited(false),
@@ -187,9 +128,9 @@ Slime
ServerCmd::invoke(const Slime &req)
{
dump_message("request --> ", req);
- write_compact(req, _child_stdin);
+ write_compact(req, _child);
Slime reply;
- REQUIRE(JsonFormat::decode(_child_stdout, reply));
+ REQUIRE(JsonFormat::decode(_child, reply));
dump_message("reply <-- ", reply);
return reply;
}
@@ -199,12 +140,12 @@ ServerCmd::write_then_read_all(const vespalib::string &input)
{
vespalib::string result;
dump_string("input --> ", input);
- memcpy(_child_stdin.reserve(input.size()).data, input.data(), input.size());
- _child_stdin.commit(input.size());
+ memcpy(_child.reserve(input.size()).data, input.data(), input.size());
+ _child.commit(input.size());
maybe_close();
- for (auto mem = _child_stdout.obtain(); mem.size > 0; mem = _child_stdout.obtain()) {
+ for (auto mem = _child.obtain(); mem.size > 0; mem = _child.obtain()) {
result.append(mem.data, mem.size);
- _child_stdout.evict(mem.size);
+ _child.evict(mem.size);
}
dump_string("output <-- ", result);
return result;
diff --git a/eval/src/vespa/eval/eval/test/test_io.h b/eval/src/vespa/eval/eval/test/test_io.h
index 62fd6588780..26fe260c857 100644
--- a/eval/src/vespa/eval/eval/test/test_io.h
+++ b/eval/src/vespa/eval/eval/test/test_io.h
@@ -9,7 +9,7 @@
#include <vespa/vespalib/data/simple_buffer.h>
#include <vespa/vespalib/data/slime/slime.h>
#include <vespa/vespalib/util/size_literals.h>
-#include <vespa/vespalib/util/child_process.h>
+#include <vespa/vespalib/process/process.h>
#include <functional>
namespace vespalib::eval::test {
@@ -40,38 +40,12 @@ public:
};
/**
- * Output adapter used to write to stdin of a child process.
- **/
-class ChildIn : public Output {
- ChildProcess &_child;
- SimpleBuffer _output;
-public:
- ChildIn(ChildProcess &child);
- WritableMemory reserve(size_t bytes) override;
- Output &commit(size_t bytes) override;
-};
-
-/**
- * Input adapter used to read from stdout of a child process.
- **/
-class ChildOut : public Input {
- ChildProcess &_child;
- SimpleBuffer _input;
-public:
- ChildOut(ChildProcess &child);
- Memory obtain() override;
- Input &evict(size_t bytes) override;
-};
-
-/**
* A command run as a child process that acts as a server reading json
* from stdin and writing json to stdout.
**/
class ServerCmd {
private:
- ChildProcess _child;
- ChildIn _child_stdin;
- ChildOut _child_stdout;
+ Process _child;
vespalib::string _basename;
bool _closed;
bool _exited;