Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Net-Ping tests fail on Android 8.1 (Oreo) because getprotobyname etc. aren't implemented #16967

Closed
p5pRT opened this issue Apr 18, 2019 · 9 comments

Comments

@p5pRT
Copy link

p5pRT commented Apr 18, 2019

Migrated from rt.perl.org#134043 (status was 'pending release')

Searchable as RT134043$

@p5pRT
Copy link
Author

p5pRT commented Apr 18, 2019

From rich@hyphen-dash-hyphen.info

Related to the efforts in RT#133787 to build Perl on Android 8.1
(Oreo) under the Termux app environment, Net-Ping tests fail under
"make test" because getprotobyname & co have not been implemented in
the Bionic libraries. (Empty stubs in [1].) Besides causing test
failures during build, presumably a lot of real network-related code
would also fail.

The common test behaviour is the failure to get (tcp|udp) protocol by name, e.g.

  $ ./perl -T -Ilib dist/Net-Ping/t/010_pingecho.t
  1..2
  ok 1 - use Net​::Ping;
  Can't get tcp protocol by name at dist/Net-Ping/t/010_pingecho.t line 17.
  # Looks like your test exited with 255 just after 1.

For reference, the cross-compiled version of Perl that ships with
Termux also appears broken in this regard on Android​:

  $ perl -MNet​::Ping -e 'my $p = Net​::Ping->new();'
  Can't get tcp protocol by name at -e line 1.

Some other interpreter projects/builds [2,3] have worked around this
situation by re-implementing the missing functionality. Is this
something that could feasibly be done for the perl interpreter?

[1] https://android.googlesource.com/platform/bionic/+/master/libc/bionic/netdb.cpp
[2] termux/termux-packages#2387
[3] https://github.com/ageneau/ecl-android/blob/master/patches/ecl/0001-Fix-socket-implementation-on-android-getprotobyname-.patch

@p5pRT
Copy link
Author

p5pRT commented May 19, 2019

From rich@hyphen-dash-hyphen.info

On Thu, Apr 18, 2019 at 1​:09 AM Richard Leach (via RT)
<perlbug-followup@​perl.org> wrote​:

Related to the efforts in RT#133787 to build Perl on Android 8.1
(Oreo) under the Termux app environment, Net-Ping tests fail under
"make test" because getprotobyname & co have not been implemented in
the Bionic libraries.

Not ruling out providing an implementation of the missing functions,
but while looking into this further, I noticed that​:
* Various Net​::Ping tests skip if d_getpbyname is undefined, but not
all tests needing getprotobyname do this. One of the attached patches
adds additional skips.
* The Android hints file has probes for the stub functions, but these
no longer work due to the functions having stopped emitting warnings
at some point. This results in Configure therefore believing that the
stub functions are defined. The other attached patch restores stub
detection based upon the function return values.

Please could these patches be applied once blead is unfrozen?

Thanks,
Richard

@p5pRT
Copy link
Author

p5pRT commented May 19, 2019

From rich@hyphen-dash-hyphen.info

0001-Tests-for-Android-stub-funtion-updated-for-Oreo-beha.patch
From 5a29b8b50f858abe8c259f8b52dd5c8ab9e1a1a4 Mon Sep 17 00:00:00 2001
From: Richard Leach <rich+perl@hyphen-dash-hyphen.info>
Date: Sun, 19 May 2019 03:27:56 +0000
Subject: [PATCH] Tests for Android stub functions updated for Oreo

---
 hints/linux-android.sh | 56 +++++++++++++++++++++++++++++++++++-------
 1 file changed, 47 insertions(+), 9 deletions(-)

diff --git a/hints/linux-android.sh b/hints/linux-android.sh
index 6a59cb726e..b0b404da50 100644
--- a/hints/linux-android.sh
+++ b/hints/linux-android.sh
@@ -41,27 +41,37 @@ i_locale='undef'
 # https://code.google.com/p/android-source-browsing/source/browse/libc/netbsd/net/getservent_r.c?repo=platform--bionic&r=ca6fe7bebe3cc6ed7e2db5a3ede2de0fcddf411d#95
 d_getservent_r='undef'

-# Bionic defines several stubs that just warn and return NULL
+# Bionic defines several stubs that warn (in older releases) and return NULL
 # https://gitorious.org/0xdroid/bionic/blobs/70b2ef0ec89a9c9d4c2d4bcab728a0e72bafb18e/libc/bionic/stubs.c
 # https://android.googlesource.com/platform/bionic/+/master/libc/bionic/stubs.cpp

-# If they warn with 'FIX' or 'Android', assume they are the stubs
-# we want to avoid.
+# These tests originally looked for 'FIX' or 'Android' warnings, as they
+# indicated stubs to avoid. At some point, Android stopped emitting
+# those warnings; the tests were adapted to check function return values
+# and hopefully now detect stubs on both older and newer Androids.

 # These are all stubs as well, but the core doesn't use them:
 # getusershell setusershell endusershell

 # This script UU/archname.cbu will get 'called-back' by Configure.
 $cat > UU/archname.cbu <<'EOCBU'
-# egrep pattern to detect a stub warning on Android.
+# original egrep pattern to detect a stub warning on Android.
 # Right now we're checking for:
 # Android 2.x: FIX ME! implement FUNC
 # Android 4.x: FUNC is not implemented on Android
+# Android 8.x: <no warnings; tests now printf a compatible warning>
 android_stub='FIX|Android'

 $cat > try.c << 'EOM'
 #include <netdb.h>
-int main() { (void) getnetbyname("foo"); return(0); }
+#include <stdio.h>
+int main() {
+  struct netent* test = getnetbyname("loopback");
+  if (test == NULL) {
+    printf("getnetbyname is still a stub function on Android");
+  }
+  return(0);
+}
 EOM
 $cc $ccflags try.c -o try
 android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
@@ -71,7 +81,14 @@ fi

 $cat > try.c << 'EOM'
 #include <netdb.h>
-int main() { (void) getnetbyaddr((uint32_t)1, AF_INET); return(0); }
+#include <stdio.h>
+int main() {
+  struct netent* test = getnetbyaddr(127, AF_INET);
+  if (test == NULL) {
+    printf("getnetbyaddr is still a stub function on Android");
+  }
+  return(0);
+}
 EOM
 $cc $ccflags try.c -o try
 android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
@@ -93,7 +110,14 @@ fi

 $cat > try.c << 'EOM'
 #include <netdb.h>
-int main() { (void) getprotobyname("foo"); return(0); }
+#include <stdio.h>
+int main() {
+  struct protoent* test = getprotobyname("tcp");
+  if (test == NULL) {
+    printf("getprotobyname is still a stub function on Android");
+  }
+  return(0);
+}
 EOM
 $cc $ccflags try.c -o try
 android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
@@ -103,7 +127,14 @@ fi

 $cat > try.c << 'EOM'
 #include <netdb.h>
-int main() { (void) getprotobynumber(1); return(0); }
+#include <stdio.h>
+int main() {
+  struct protoent* test = getprotobynumber(1);
+  if (test == NULL) {
+    printf("getprotobynumber is still a stub function on Android");
+  }
+  return(0);
+}
 EOM
 $cc $ccflags try.c -o try
 android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
@@ -124,7 +155,14 @@ fi

 $cat > try.c << 'EOM'
 #include <unistd.h>
-int main() { (void) ttyname(STDIN_FILENO); return(0); }
+#include <stdio.h>
+int main() {
+  char *tty = ttyname(STDIN_FILENO);
+  if (tty == NULL) {
+    printf("ttyname is still a stub function on Android");
+  }
+  return(0);
+}
 EOM
 $cc $ccflags try.c -o try
 android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
--
2.21.0

@p5pRT
Copy link
Author

p5pRT commented May 19, 2019

From rich@hyphen-dash-hyphen.info

0001-Additional-Net-Ping-tests-skip-if-d_getpbyname-is-un.patch
From 54d7c3d032f828008a3ea3d49d869cf6cdd62300 Mon Sep 17 00:00:00 2001
From: Richard Leach <rich+perl@hyphen-dash-hyphen.info>
Date: Sun, 19 May 2019 03:34:38 +0000
Subject: [PATCH] Additional Net-Ping tests skip if d_getpbyname is undef

---
 dist/Net-Ping/t/001_new.t      | 5 +++++
 dist/Net-Ping/t/010_pingecho.t | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/dist/Net-Ping/t/001_new.t b/dist/Net-Ping/t/001_new.t
index 6b097d70a8..46965b7b05 100644
--- a/dist/Net-Ping/t/001_new.t
+++ b/dist/Net-Ping/t/001_new.t
@@ -1,11 +1,16 @@
 use warnings;
 use strict;
+use Config;

 BEGIN {
   unless (my $port = getservbyname('echo', 'tcp')) {
     print "1..0 \# Skip: no echo port\n";
     exit;
   }
+  unless ($Config{d_getpbyname}) {
+    print "1..0 \# Skip: no getprotobyname\n";
+    exit;
+  }
 }

 use Test::More qw(no_plan);
diff --git a/dist/Net-Ping/t/010_pingecho.t b/dist/Net-Ping/t/010_pingecho.t
index 90a934a0b1..e8a6bb093e 100644
--- a/dist/Net-Ping/t/010_pingecho.t
+++ b/dist/Net-Ping/t/010_pingecho.t
@@ -1,11 +1,16 @@
 use warnings;
 use strict;
+use Config;

 BEGIN {
   unless (my $port = getservbyname('echo', 'tcp')) {
     print "1..0 \# Skip: no echo port\n";
     exit;
   }
+  unless ($Config{d_getpbyname}) {
+    print "1..0 \# Skip: no getprotobyname\n";
+    exit;
+  }
 }

 use Test::More tests => 2;
--
2.21.0

@p5pRT
Copy link
Author

p5pRT commented Jun 23, 2019

From rich@hyphen-dash-hyphen.info

On Sun, May 19, 2019 at 3​:41 AM Richard Leach
<rich@​hyphen-dash-hyphen.info> wrote​:

Please could these patches be applied once blead is unfrozen?

Hi,

Not sure if that last email was one that got dropped, or if it's just
waiting on tuits.

Thanks,
Richard

@p5pRT
Copy link
Author

p5pRT commented Jun 25, 2019

From @khwilliamson

On 6/23/19 5​:14 PM, Richard Leach wrote​:

On Sun, May 19, 2019 at 3​:41 AM Richard Leach
<rich@​hyphen-dash-hyphen.info> wrote​:

Please could these patches be applied once blead is unfrozen?

Hi,

Not sure if that last email was one that got dropped, or if it's just
waiting on tuits.

Thanks,
Richard

Now applied as
f1d63d3
3167cd9

You suggested in the ticket that maybe an implementation of the library
could be done if not present. If you still think that, patches welcome.
  Otherwise, I doubt it will get done.

@p5pRT
Copy link
Author

p5pRT commented Jun 25, 2019

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jun 25, 2019

From rich@hyphen-dash-hyphen.info

On Tue, Jun 25, 2019 at 7​:53 PM Karl Williamson <public@​khwilliamson.com> wrote​:

Now applied as
f1d63d3
3167cd9

Thanks!

You suggested in the ticket that maybe an implementation of the library
could be done if not present. If you still think that, patches welcome.
Otherwise, I doubt it will get done.

Having since learned that other builds get by fine without, I'm
leaning towards not doing so, unless anyone suggests a compelling case
for doing so.

Regards,
Richard

@p5pRT
Copy link
Author

p5pRT commented Jun 25, 2019

@khwilliamson - Status changed from 'open' to 'pending release'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant