Discussion:
openpty: Skip test if no pty is available
(too old to reply)
Guido Günther
2017-01-19 18:14:54 UTC
Permalink
Raw Message
In chroots for package builds there may be no ptys or they might not be
accessible. This both manifests as ENOENT on Linux. Skip tests in this
case.
---
gnulib/tests/test-openpty.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/gnulib/tests/test-openpty.c b/gnulib/tests/test-openpty.c
index 2858d50..603c5f2 100644
--- a/gnulib/tests/test-openpty.c
+++ b/gnulib/tests/test-openpty.c
@@ -25,6 +25,7 @@
SIGNATURE_CHECK (openpty, int, (int *, int *, char *, struct termios const *,
struct winsize const *));

+#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <termios.h>
@@ -43,8 +44,12 @@ main ()
int res = openpty (&master, &slave, NULL, NULL, NULL);
if (res != 0)
{
- fprintf (stderr, "openpty returned %d\n", res);
- return 1;
+ if (errno != ENOENT) {
+ fprintf (stderr, "openpty returned %d: %s\n", res, strerror(errno));
+ return 1;
+ } else {
+ return 77;
+ }
}
}
Guido Günther
2017-02-09 14:11:13 UTC
Permalink
Raw Message
Post by Guido Günther
In chroots for package builds there may be no ptys or they might not be
accessible. This both manifests as ENOENT on Linux. Skip tests in this
case.
---
Any chance this gets applied?
Cheers,
-- Guido
Post by Guido Günther
gnulib/tests/test-openpty.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/gnulib/tests/test-openpty.c b/gnulib/tests/test-openpty.c
index 2858d50..603c5f2 100644
--- a/gnulib/tests/test-openpty.c
+++ b/gnulib/tests/test-openpty.c
@@ -25,6 +25,7 @@
SIGNATURE_CHECK (openpty, int, (int *, int *, char *, struct termios const *,
struct winsize const *));
+#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <termios.h>
@@ -43,8 +44,12 @@ main ()
int res = openpty (&master, &slave, NULL, NULL, NULL);
if (res != 0)
{
- fprintf (stderr, "openpty returned %d\n", res);
- return 1;
+ if (errno != ENOENT) {
+ fprintf (stderr, "openpty returned %d: %s\n", res, strerror(errno));
+ return 1;
+ } else {
+ return 77;
+ }
}
}
Bruno Haible
2017-02-11 18:07:38 UTC
Permalink
Raw Message
Hi,
Post by Guido Günther
In chroots for package builds there may be no ptys or they might not be
accessible. This both manifests as ENOENT on Linux. Skip tests in this
case.
I'm not a fan of this patch, because it reduces the value of the test:
It would only test whether the openpty() function could open a pty or
maybe could not open a pty. Pretty worthless. If a future change to
the implementation would break the openpty() function, the unit test would
no longer notice it.

Can you search for alternatives?

One possibility is that you find how to identify such "chroot environments".
Are there some environment variables which signal it? Are there some system
calls (not related to ptys) that would give a hint?

Another possibility is that, for those packages which you intend to test in a
chroot environment, you omit the test, i.e. use gnulib-tool with argument
--avoid=openpty-tests. I would find this better than to destroy the value of
the test for everyone.

Bruno
Guido Günther
2017-02-11 19:31:40 UTC
Permalink
Raw Message
Hi Bruno,
Post by Bruno Haible
Hi,
Post by Guido Günther
In chroots for package builds there may be no ptys or they might not be
accessible. This both manifests as ENOENT on Linux. Skip tests in this
case.
It would only test whether the openpty() function could open a pty or
maybe could not open a pty. Pretty worthless. If a future change to
the implementation would break the openpty() function, the unit test would
no longer notice it.
Can you search for alternatives?
One possibility is that you find how to identify such "chroot environments".
Are there some environment variables which signal it? Are there some system
calls (not related to ptys) that would give a hint?
Another possibility is that, for those packages which you intend to test in a
chroot environment, you omit the test, i.e. use gnulib-tool with argument
--avoid=openpty-tests. I would find this better than to destroy the value of
the test for everyone.
Thanks for having a look. Let's drop these then and I'll skip them
during the build.
Cheers,
-- Guido

Loading...