Tarantool development patches archive
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: tml <tarantool-patches@dev.tarantool.org>
Subject: [Tarantool-patches] [PATCH v6 4/4] popen/test: Add base test cases
Date: Tue, 17 Dec 2019 15:54:20 +0300	[thread overview]
Message-ID: <20191217125420.20881-5-gorcunov@gmail.com> (raw)
In-Reply-To: <20191217125420.20881-1-gorcunov@gmail.com>

Fixes #4031

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 test/app/popen.result   | 234 ++++++++++++++++++++++++++++++++++++++++
 test/app/popen.test.lua |  91 ++++++++++++++++
 2 files changed, 325 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..dd60f4833
--- /dev/null
+++ b/test/app/popen.result
@@ -0,0 +1,234 @@
+-- test-run result file version 2
+-- Test popen engine
+--
+-- vim: ts=4 sw=4 et
+
+buffer = require('buffer')
+ | ---
+ | ...
+popen = require('popen')
+ | ---
+ | ...
+ffi = require('ffi')
+ | ---
+ | ...
+
+test_run = require('test_run').new()
+ | ---
+ | ...
+
+buf = buffer.ibuf()
+ | ---
+ | ...
+
+--
+-- Trivial echo output
+--
+script = "echo -n 1 2 3 4 5"
+ | ---
+ | ...
+ph = popen.posix(script, "r")
+ | ---
+ | ...
+ph:wait()   -- wait echo to finish
+ | ---
+ | - null
+ | - 2
+ | - 0
+ | ...
+ph:read()   -- read the output
+ | ---
+ | - 1 2 3 4 5
+ | ...
+ph:close()  -- release the popen
+ | ---
+ | - true
+ | ...
+
+--
+-- Test info and force killing of a child process
+--
+script = "while [ 1 ]; do sleep 10; done"
+ | ---
+ | ...
+ph = popen.posix(script, "r")
+ | ---
+ | ...
+ph:kill()
+ | ---
+ | - true
+ | ...
+--
+-- Killing child may be queued and depends on
+-- system load, so we may get ESRCH here.
+err, reason, exit_code = ph:wait()
+ | ---
+ | ...
+ph:state()
+ | ---
+ | - null
+ | - 3
+ | - 9
+ | ...
+info = ph:info()
+ | ---
+ | ...
+info["command"]
+ | ---
+ | - sh -c while [ 1 ]; do sleep 10; done
+ | ...
+info["state"]
+ | ---
+ | - signaled
+ | ...
+info["flags"]
+ | ---
+ | - 61510
+ | ...
+info["exit_code"]
+ | ---
+ | - 9
+ | ...
+ph:close()
+ | ---
+ | - true
+ | ...
+
+--
+-- Test info and soft killing of a child process
+--
+script = "while [ 1 ]; do sleep 10; done"
+ | ---
+ | ...
+ph = popen.posix(script, "r")
+ | ---
+ | ...
+ph:terminate()
+ | ---
+ | - true
+ | ...
+--
+-- Killing child may be queued and depends on
+-- system load, so we may get ESRCH here.
+err, reason, exit_code = ph:wait()
+ | ---
+ | ...
+ph:state()
+ | ---
+ | - null
+ | - 3
+ | - 15
+ | ...
+info = ph:info()
+ | ---
+ | ...
+info["command"]
+ | ---
+ | - sh -c while [ 1 ]; do sleep 10; done
+ | ...
+info["state"]
+ | ---
+ | - signaled
+ | ...
+info["flags"]
+ | ---
+ | - 61510
+ | ...
+info["exit_code"]
+ | ---
+ | - 15
+ | ...
+ph:close()
+ | ---
+ | - true
+ | ...
+
+--
+-- Test for stdin/out stream
+--
+script="prompt=''; read -n 5 prompt; echo -n $prompt"
+ | ---
+ | ...
+ph = popen.posix(script, "rw")
+ | ---
+ | ...
+ph:write("input")
+ | ---
+ | - true
+ | ...
+ph:read()
+ | ---
+ | - input
+ | ...
+ph:close()
+ | ---
+ | - true
+ | ...
+
+--
+-- Test reading stderr (simply redirect stdout to stderr)
+--
+script = "echo -n 1 2 3 4 5 1>&2"
+ | ---
+ | ...
+ph = popen.posix(script, "rw")
+ | ---
+ | ...
+ph:wait()
+ | ---
+ | - null
+ | - 2
+ | - 0
+ | ...
+size = 128
+ | ---
+ | ...
+dst = buf:reserve(size)
+ | ---
+ | ...
+res, err = ph: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()
+ | ---
+ | ...
+ph:close()
+ | ---
+ | - true
+ | ...
+
+--
+-- Test timeouts: just wait for 0.1 second
+-- to elapse, then write data and re-read
+-- for sure.
+--
+script = "prompt=''; read -n 5 prompt && echo -n $prompt;"
+ | ---
+ | ...
+ph = popen.posix(script, "rw")
+ | ---
+ | ...
+ph:read(nil, 0.1)
+ | ---
+ | - null
+ | - 'popen: Resource temporarily unavailable'
+ | ...
+ph:write("input")
+ | ---
+ | - true
+ | ...
+ph:read()
+ | ---
+ | - input
+ | ...
+ph:close()
+ | ---
+ | - true
+ | ...
diff --git a/test/app/popen.test.lua b/test/app/popen.test.lua
new file mode 100644
index 000000000..87b9dbdc8
--- /dev/null
+++ b/test/app/popen.test.lua
@@ -0,0 +1,91 @@
+-- Test popen engine
+--
+-- vim: ts=4 sw=4 et
+
+buffer = require('buffer')
+popen = require('popen')
+ffi = require('ffi')
+
+test_run = require('test_run').new()
+
+buf = buffer.ibuf()
+
+--
+-- Trivial echo output
+--
+script = "echo -n 1 2 3 4 5"
+ph = popen.posix(script, "r")
+ph:wait()   -- wait echo to finish
+ph:read()   -- read the output
+ph:close()  -- release the popen
+
+--
+-- Test info and force killing of a child process
+--
+script = "while [ 1 ]; do sleep 10; done"
+ph = popen.posix(script, "r")
+ph:kill()
+--
+-- Killing child may be queued and depends on
+-- system load, so we may get ESRCH here.
+err, reason, exit_code = ph:wait()
+ph:state()
+info = ph:info()
+info["command"]
+info["state"]
+info["flags"]
+info["exit_code"]
+ph:close()
+
+--
+-- Test info and soft killing of a child process
+--
+script = "while [ 1 ]; do sleep 10; done"
+ph = popen.posix(script, "r")
+ph:terminate()
+--
+-- Killing child may be queued and depends on
+-- system load, so we may get ESRCH here.
+err, reason, exit_code = ph:wait()
+ph:state()
+info = ph:info()
+info["command"]
+info["state"]
+info["flags"]
+info["exit_code"]
+ph:close()
+
+--
+-- Test for stdin/out stream
+--
+script="prompt=''; read -n 5 prompt; echo -n $prompt"
+ph = popen.posix(script, "rw")
+ph:write("input")
+ph:read()
+ph:close()
+
+--
+-- Test reading stderr (simply redirect stdout to stderr)
+--
+script = "echo -n 1 2 3 4 5 1>&2"
+ph = popen.posix(script, "rw")
+ph:wait()
+size = 128
+dst = buf:reserve(size)
+res, err = ph:read2({buf = dst, size = size, nil, flags = {stderr = true}})
+res = buf:alloc(res)
+ffi.string(buf.rpos, buf:size())
+buf:recycle()
+ph:close()
+
+--
+-- Test timeouts: just wait for 0.1 second
+-- to elapse, then write data and re-read
+-- for sure.
+--
+script = "prompt=''; read -n 5 prompt && echo -n $prompt;"
+ph = popen.posix(script, "rw")
+ph:read(nil, 0.1)
+ph:write("input")
+ph:read()
+ph:close()
-- 
2.20.1

      parent reply	other threads:[~2019-12-17 12:55 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-17 12:54 [Tarantool-patches] [PATCH v6 0/4] popen: Add ability to run external process Cyrill Gorcunov
2019-12-17 12:54 ` [Tarantool-patches] [PATCH v6 1/4] coio: Export helpers and provide coio_read_fd_timeout Cyrill Gorcunov
2019-12-20  7:48   ` Konstantin Osipov
2019-12-20 14:50     ` Cyrill Gorcunov
2019-12-17 12:54 ` [Tarantool-patches] [PATCH v6 2/4] popen: Introduce a backend engine Cyrill Gorcunov
2019-12-20  8:11   ` Konstantin Osipov
2019-12-20 11:52     ` Cyrill Gorcunov
2019-12-20 12:04       ` Konstantin Osipov
2019-12-20 12:10         ` Cyrill Gorcunov
2019-12-20 12:11     ` Alexander Turenko
2019-12-26  7:14   ` Konstantin Osipov
2019-12-26  7:19     ` Cyrill Gorcunov
2020-01-09 11:23     ` Cyrill Gorcunov
2019-12-17 12:54 ` [Tarantool-patches] [PATCH v6 3/4] popen/lua: Add popen module Cyrill Gorcunov
2019-12-20 15:41   ` Maxim Melentiev
2019-12-17 12:54 ` 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=20191217125420.20881-5-gorcunov@gmail.com \
    --to=gorcunov@gmail.com \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v6 4/4] popen/test: Add base test cases' \
    /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