From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 2ACB84696C4 for ; Tue, 17 Dec 2019 15:55:10 +0300 (MSK) Received: by mail-lj1-f177.google.com with SMTP id a13so10787399ljm.10 for ; Tue, 17 Dec 2019 04:55:10 -0800 (PST) From: Cyrill Gorcunov Date: Tue, 17 Dec 2019 15:54:20 +0300 Message-Id: <20191217125420.20881-5-gorcunov@gmail.com> In-Reply-To: <20191217125420.20881-1-gorcunov@gmail.com> References: <20191217125420.20881-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v6 4/4] popen/test: Add base test cases List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tml Fixes #4031 Signed-off-by: Cyrill Gorcunov --- 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