From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (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 C3CC74696C2 for ; Thu, 28 Nov 2019 23:46:24 +0300 (MSK) Received: by mail-lj1-f174.google.com with SMTP id n21so29672980ljg.12 for ; Thu, 28 Nov 2019 12:46:24 -0800 (PST) From: Cyrill Gorcunov Date: Thu, 28 Nov 2019 23:45:12 +0300 Message-Id: <20191128204512.19732-6-gorcunov@gmail.com> In-Reply-To: <20191128204512.19732-1-gorcunov@gmail.com> References: <20191128204512.19732-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 5/5] test: Add app/popen test List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tml To test basic functionality of popen code. Fixes #4031 Signed-off-by: Cyrill Gorcunov --- test/app/popen.result | 105 ++++++++++++++++++++++++++++++++++++++++ test/app/popen.test.lua | 39 +++++++++++++++ 2 files changed, 144 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..1a27b1b0c --- /dev/null +++ b/test/app/popen.result @@ -0,0 +1,105 @@ +-- test-run result file version 2 +fio = require('fio') + | --- + | ... +test_run = require('test_run').new() + | --- + | ... + +local err, reason, exit_code + | --- + | ... + +-- +-- Trivial echo output +-- +script="echo -n 1 2 3 4 5" + | --- + | ... +popen = fio.popen(script, "r") + | --- + | ... +popen:wait() + | --- + | - null + | - 1 + | - 0 + | ... +popen:read() + | --- + | - 1 2 3 4 5 + | ... +popen:close() + | --- + | - true + | - null + | ... + +-- +-- Test info and killing of a child process +-- +script="while [ 1 ]; do sleep 10; done" + | --- + | ... +popen = fio.popen(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:status() + | --- + | - null + | - 2 + | - 9 + | ... +info = popen:info() + | --- + | ... +info["state"] + | --- + | - exited + | ... +info["flags"] + | --- + | - 834 + | ... +info["exit_code"] + | --- + | - 9 + | ... +popen:close() + | --- + | - true + | - null + | ... + +-- +-- Test for stdin/out stream +-- +script="prompt=''; read -n 5 prompt; echo -n $prompt" + | --- + | ... +popen = fio.popen(script, "rw") + | --- + | ... +popen:write("input") + | --- + | - 5 + | ... +popen:read() + | --- + | - input + | ... +popen:close() + | --- + | - true + | - null + | ... diff --git a/test/app/popen.test.lua b/test/app/popen.test.lua new file mode 100644 index 000000000..46c49cb18 --- /dev/null +++ b/test/app/popen.test.lua @@ -0,0 +1,39 @@ +fio = require('fio') +test_run = require('test_run').new() + +local err, reason, exit_code + +-- +-- Trivial echo output +-- +script="echo -n 1 2 3 4 5" +popen = fio.popen(script, "r") +popen:wait() +popen:read() +popen:close() + +-- +-- Test info and killing of a child process +-- +script="while [ 1 ]; do sleep 10; done" +popen = fio.popen(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:status() +info = popen:info() +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(script, "rw") +popen:write("input") +popen:read() +popen:close() -- 2.20.1