Tarantool development patches archive
 help / color / mirror / Atom feed
From: Alexander Turenko <alexander.turenko@tarantool.org>
To: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: tml <tarantool-patches@dev.tarantool.org>
Subject: Re: [Tarantool-patches] [PATCH 7/7] test/unit: add popen test
Date: Wed, 11 Mar 2020 23:22:13 +0300	[thread overview]
Message-ID: <20200311202213.pugz24653u7zlk4f@tkn_work_nb> (raw)
In-Reply-To: <20200302201227.31785-8-gorcunov@gmail.com>

There are two good properties, which can be easily achieved for the
test:

* better fit TAP13 format;
* set a non-zero exit code at fail.

See below (comments 2 and 4) if you're interested or skip if not.

There also two comments around (1 and 3), see them below too.

WBR, Alexander Turenko.

> +static int
> +main_f(va_list ap)
> +{
> +	int rc = 0;
> +
> +	rc = popen_write_exit();
> +	if (rc == 0)
> +		rc = popen_read_exit();
> +	if (rc == 0)
> +		rc = popen_kill();

1. I would run all tests even if some of them fails: this way we can get
   more info what is healthy and what is broken. And it is usual for
   TAP13 tests as I see.

> +
> +	ev_break(loop(), EVBREAK_ALL);
> +	return 0;
> +}

2. Since our unit.[ch] module supports test nesting I would start the
   function from plan() + header() prologue and end it with footer() +
   check_plan() epilogue. See swim.c or uri.c unit tests for example.

   This will make the output almost TAP13 compliant (now it contains
   several plans on one nesting level) and I hope we'll make it fully
   compliant by a change in unit.[ch] and remove most of *.result files
   in test/unit directory.

   I propose also save the check_plan() return value in a global static
   variable like in swim.c unit test to report it in the exit code of
   the process.

> +int
> +main(int argc, char *argv[])
> +{
> +	//say_logger_init(NULL, S_DEBUG, 0, "plain", 0);
> +	memory_init();
> +
> +	fiber_init(fiber_c_invoke);
> +	popen_init();
> +	coio_init();
> +	coio_enable();
> +
> +	if (!loop())
> +		panic("%s", "can't init event loop");
> +
> +	struct fiber *test = fiber_new("coio_stat", main_f);

3. It seems the name was copied from coio.cc and forgotten to change.
   AFAIS, it is usually "main" for such tests.

> +	fiber_wakeup(test);
> +
> +	ev_now_update(loop());
> +	ev_run(loop(), 0);
> +	popen_free();
> +	fiber_free();
> +	memory_free();
> +
> +	return 0;
> +}

4. I would return a return value from check_plan() in main_f() here,
   like in swim.c unit test.

   I think that it is good property to report a non-zero exit code from
   a test if it fails in some way, because this way we may relax
   requirements for a testing harness if we'll need it for some reason.

----

In fact I experimented around this and made the proposed changes. So
I'll share it with you in order to better show what I propose.

I also verified that after small changes in test/unit/unit.[ch] and the
changes below the result file for popen test can be deleted at all.

diff --git a/test/unit/popen.c b/test/unit/popen.c
index 7656ebe73..a40ca514c 100644
--- a/test/unit/popen.c
+++ b/test/unit/popen.c
@@ -16,6 +16,11 @@
 	POPEN_FLAG_SHELL		|	\
 	POPEN_FLAG_RESTORE_SIGNALS)
 
+/**
+ * A real return value of main_f(), see a comment in swim.c.
+ */
+static int test_result = 1;
+
 static int
 wait_exit(struct popen_handle *handle, int *state, int *exit_code)
 {
@@ -30,7 +35,7 @@ wait_exit(struct popen_handle *handle, int *state, int *exit_code)
 	return 0;
 }
 
-static int
+static void
 popen_write_exit(void)
 {
 	struct popen_handle *handle;
@@ -95,10 +100,10 @@ out_kill:
 
 out:
 	footer();
-	return check_plan();
+	check_plan();
 }
 
-static int
+static void
 popen_read_exit(void)
 {
 	struct popen_handle *handle;
@@ -152,10 +157,10 @@ out_kill:
 
 out:
 	footer();
-	return check_plan();
+	check_plan();
 }
 
-static int
+static void
 popen_kill(void)
 {
 	struct popen_handle *handle;
@@ -205,21 +210,24 @@ out_kill:
 
 out:
 	footer();
-	return check_plan();
+	check_plan();
 }
 
 static int
 main_f(va_list ap)
 {
-	int rc = 0;
+	plan(3);
+	header();
 
-	rc = popen_write_exit();
-	if (rc == 0)
-		rc = popen_read_exit();
-	if (rc == 0)
-		rc = popen_kill();
+	popen_write_exit();
+	popen_read_exit();
+	popen_kill();
 
 	ev_break(loop(), EVBREAK_ALL);
+
+	footer();
+	test_result = check_plan();
+
 	return 0;
 }
 
@@ -237,7 +245,7 @@ main(int argc, char *argv[])
 	if (!loop())
 		panic("%s", "can't init event loop");
 
-	struct fiber *test = fiber_new("coio_stat", main_f);
+	struct fiber *test = fiber_new("main", main_f);
 	fiber_wakeup(test);
 
 	ev_now_update(loop());
@@ -246,5 +254,5 @@ main(int argc, char *argv[])
 	fiber_free();
 	memory_free();
 
-	return 0;
+	return test_result;
 }

  reply	other threads:[~2020-03-11 20:22 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-02 20:12 [Tarantool-patches] [PATCH 0/7] popen: various fixes and a test Cyrill Gorcunov
2020-03-02 20:12 ` [Tarantool-patches] [PATCH 1/7] core/say: Export logger fd Cyrill Gorcunov
2020-03-02 20:12 ` [Tarantool-patches] [PATCH 2/7] popen: allow accessing environ variable Cyrill Gorcunov
2020-03-02 20:12 ` [Tarantool-patches] [PATCH 3/7] popen: close_inherited_fds - add support for macos/freebsd Cyrill Gorcunov
2020-03-02 20:12 ` [Tarantool-patches] [PATCH 4/7] popen: log errors if popen creation failed Cyrill Gorcunov
2020-03-02 20:12 ` [Tarantool-patches] [PATCH 5/7] popen: add logging in child process Cyrill Gorcunov
2020-03-02 20:12 ` [Tarantool-patches] [PATCH 6/7] popen: handle setsid os specifics Cyrill Gorcunov
2020-03-03 11:38   ` Alexander Turenko
2020-03-03 11:45     ` Cyrill Gorcunov
2020-03-10 15:49       ` Alexander Turenko
2020-03-10 16:36         ` Alexander Turenko
2020-03-10 16:41           ` Cyrill Gorcunov
2020-03-10 17:12             ` Alexander Turenko
2020-03-10 17:40               ` Cyrill Gorcunov
2020-03-11  7:55               ` [Tarantool-patches] [PATCH v5 6/7] popen: handle sid on macos Cyrill Gorcunov
2020-03-06 14:30   ` [Tarantool-patches] [PATCH v2 6/7] popen: handle setsid os specifics Cyrill Gorcunov
2020-03-10  8:02     ` [Tarantool-patches] [PATCH v3 6/7] popen: use ioctl on macos Cyrill Gorcunov
2020-03-02 20:12 ` [Tarantool-patches] [PATCH 7/7] test/unit: add popen test Cyrill Gorcunov
2020-03-11 20:22   ` Alexander Turenko [this message]
2020-03-12 10:38     ` [Tarantool-patches] [PATCH v5 " Cyrill Gorcunov
2020-03-12 11:58 ` [Tarantool-patches] [PATCH 0/7] popen: various fixes and a test Alexander Turenko
2020-03-12 12:18   ` Cyrill Gorcunov
2020-03-16 15:58 ` Kirill Yukhin

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=20200311202213.pugz24653u7zlk4f@tkn_work_nb \
    --to=alexander.turenko@tarantool.org \
    --cc=gorcunov@gmail.com \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 7/7] test/unit: add 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