From: Cyrill Gorcunov <gorcunov@gmail.com> To: tml <tarantool-patches@dev.tarantool.org> Subject: [Tarantool-patches] [PATCH v3 5/5] test: Add app/popen test Date: Wed, 11 Dec 2019 12:28:33 +0300 [thread overview] Message-ID: <20191211092833.12212-6-gorcunov@gmail.com> (raw) In-Reply-To: <20191211092833.12212-1-gorcunov@gmail.com> To test basic functionality of popen code. Fixes #4031 Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com> --- test/app/popen.result | 230 ++++++++++++++++++++++++++++++++++++++++ test/app/popen.test.lua | 87 +++++++++++++++ 2 files changed, 317 insertions(+) create mode 100644 test/app/popen.result create mode 100644 test/app/popen.test.lua diff --git a/test/app/popen.result b/test/app/popen.result new file mode 100644 index 000000000..a2573ae8d --- /dev/null +++ b/test/app/popen.result @@ -0,0 +1,230 @@ +-- test-run result file version 2 +fio = require('fio') + | --- + | ... +buffer = require('buffer') + | --- + | ... +ffi = require('ffi') + | --- + | ... + +test_run = require('test_run').new() + | --- + | ... + +buf = buffer.ibuf() + | --- + | ... + +-- +-- Trivial echo output +-- +script = "echo -n 1 2 3 4 5" + | --- + | ... +popen = fio.popen_posix(script, "r") + | --- + | ... +popen:wait() -- wait echo to finish + | --- + | - null + | - 1 + | - 0 + | ... +popen:read() -- read the output + | --- + | - 1 2 3 4 5 + | ... +popen:close() -- release the popen + | --- + | - true + | ... + +-- +-- Test info and force killing of a child process +-- +script = "while [ 1 ]; do sleep 10; done" + | --- + | ... +popen = fio.popen_posix(script, "r") + | --- + | ... +popen:kill() + | --- + | - true + | ... +-- +-- Killing child may be queued and depends on +-- system load, so we may get ESRCH here. +err, reason, exit_code = popen:wait() + | --- + | ... +popen:state() + | --- + | - null + | - 3 + | - 9 + | ... +info = popen:info() + | --- + | ... +info["command"] + | --- + | - sh -c while [ 1 ]; do sleep 10; done + | ... +info["state"] + | --- + | - signaled + | ... +info["flags"] + | --- + | - 61510 + | ... +info["exit_code"] + | --- + | - 9 + | ... +popen:close() + | --- + | - true + | ... + +-- +-- Test info and soft killing of a child process +-- +script = "while [ 1 ]; do sleep 10; done" + | --- + | ... +popen = fio.popen_posix(script, "r") + | --- + | ... +popen:terminate() + | --- + | - true + | ... +-- +-- Killing child may be queued and depends on +-- system load, so we may get ESRCH here. +err, reason, exit_code = popen:wait() + | --- + | ... +popen:state() + | --- + | - null + | - 3 + | - 15 + | ... +info = popen:info() + | --- + | ... +info["command"] + | --- + | - sh -c while [ 1 ]; do sleep 10; done + | ... +info["state"] + | --- + | - signaled + | ... +info["flags"] + | --- + | - 61510 + | ... +info["exit_code"] + | --- + | - 15 + | ... +popen:close() + | --- + | - true + | ... + + +-- +-- Test for stdin/out stream +-- +script="prompt=''; read -n 5 prompt; echo -n $prompt" + | --- + | ... +popen = fio.popen_posix(script, "rw") + | --- + | ... +popen:write("input") + | --- + | - 5 + | ... +popen:read() + | --- + | - input + | ... +popen:close() + | --- + | - true + | ... + +-- +-- Test reading stderr (simply redirect stdout to stderr) +-- +script = "echo -n 1 2 3 4 5 1>&2" + | --- + | ... +popen = fio.popen_posix(script, "rw") + | --- + | ... +popen:wait() + | --- + | - null + | - 1 + | - 0 + | ... +size = 128 + | --- + | ... +dst = buf:reserve(size) + | --- + | ... +res, err = popen:read2({buf = dst, size = size, nil, flags = {stderr = true}}) + | --- + | ... +res = buf:alloc(res) + | --- + | ... +ffi.string(buf.rpos, buf:size()) + | --- + | - 1 2 3 4 5 + | ... +buf:recycle() + | --- + | ... +popen:close() + | --- + | - true + | ... + +-- +-- Test timeouts: just wait for 10 microseconds +-- to elapse, then write data and re-read for sure. +-- +script = "prompt=''; read -n 5 prompt && echo -n $prompt;" + | --- + | ... +popen = fio.popen_posix(script, "rw") + | --- + | ... +popen:read(nil, nil, {timeout = 10, flags = {stdout = true}}) + | --- + | - null + | - null + | ... +popen:write("input") + | --- + | - 5 + | ... +popen:read() + | --- + | - input + | ... +popen:close() + | --- + | - true + | ... diff --git a/test/app/popen.test.lua b/test/app/popen.test.lua new file mode 100644 index 000000000..a6dbbb5ae --- /dev/null +++ b/test/app/popen.test.lua @@ -0,0 +1,87 @@ +fio = require('fio') +buffer = require('buffer') +ffi = require('ffi') + +test_run = require('test_run').new() + +buf = buffer.ibuf() + +-- +-- Trivial echo output +-- +script = "echo -n 1 2 3 4 5" +popen = fio.popen_posix(script, "r") +popen:wait() -- wait echo to finish +popen:read() -- read the output +popen:close() -- release the popen + +-- +-- Test info and force killing of a child process +-- +script = "while [ 1 ]; do sleep 10; done" +popen = fio.popen_posix(script, "r") +popen:kill() +-- +-- Killing child may be queued and depends on +-- system load, so we may get ESRCH here. +err, reason, exit_code = popen:wait() +popen:state() +info = popen:info() +info["command"] +info["state"] +info["flags"] +info["exit_code"] +popen:close() + +-- +-- Test info and soft killing of a child process +-- +script = "while [ 1 ]; do sleep 10; done" +popen = fio.popen_posix(script, "r") +popen:terminate() +-- +-- Killing child may be queued and depends on +-- system load, so we may get ESRCH here. +err, reason, exit_code = popen:wait() +popen:state() +info = popen:info() +info["command"] +info["state"] +info["flags"] +info["exit_code"] +popen:close() + + +-- +-- Test for stdin/out stream +-- +script="prompt=''; read -n 5 prompt; echo -n $prompt" +popen = fio.popen_posix(script, "rw") +popen:write("input") +popen:read() +popen:close() + +-- +-- Test reading stderr (simply redirect stdout to stderr) +-- +script = "echo -n 1 2 3 4 5 1>&2" +popen = fio.popen_posix(script, "rw") +popen:wait() +size = 128 +dst = buf:reserve(size) +res, err = popen:read2({buf = dst, size = size, nil, flags = {stderr = true}}) +res = buf:alloc(res) +ffi.string(buf.rpos, buf:size()) +buf:recycle() +popen:close() + +-- +-- Test timeouts: just wait for 10 microseconds +-- to elapse, then write data and re-read for sure. +-- +script = "prompt=''; read -n 5 prompt && echo -n $prompt;" +popen = fio.popen_posix(script, "rw") +popen:read(nil, nil, {timeout = 10, flags = {stdout = true}}) +popen:write("input") +popen:read() +popen:close() -- 2.20.1
prev parent reply other threads:[~2019-12-11 9:29 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-12-11 9:28 [Tarantool-patches] [PATCH v3 0/5] popen: Add ability to run external process Cyrill Gorcunov 2019-12-11 9:28 ` [Tarantool-patches] [PATCH v3 1/5] popen: Introduce a backend engine Cyrill Gorcunov 2019-12-11 9:28 ` [Tarantool-patches] [PATCH v3 2/5] lua/fio: Add lbox_fio_push_error as a separate helper Cyrill Gorcunov 2019-12-11 9:28 ` [Tarantool-patches] [PATCH v3 3/5] popen/fio: Merge popen engine into fio internal module Cyrill Gorcunov 2019-12-11 9:28 ` [Tarantool-patches] [PATCH v3 4/5] popen/fio: Add ability to run external programs Cyrill Gorcunov 2019-12-11 9:28 ` Cyrill Gorcunov [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20191211092833.12212-6-gorcunov@gmail.com \ --to=gorcunov@gmail.com \ --cc=tarantool-patches@dev.tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v3 5/5] test: Add app/popen test' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox