inet: Increase htontest coverage to run-time evaluation, library

Message ID 87frtfuaas.fsf@oldenburg.str.redhat.com
State Dropped
Headers
Series inet: Increase htontest coverage to run-time evaluation, library |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
redhat-pt-bot/TryBot-32bit success Build for i686
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed

Commit Message

Florian Weimer June 14, 2024, 9:46 a.m. UTC
  And convert the test to <support/test-driver.c>.

Tested on x86_64-linux-gnu and s390x-linux-gnu.

---
 inet/htontest.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)


base-commit: 868ab8923a2ec977faafec97ecafac0c3159c1b2
  

Comments

Andreas Schwab June 14, 2024, 10:17 a.m. UTC | #1
On Jun 14 2024, Florian Weimer wrote:

> +/* Use a volatile function pointer as a compiler barrier, to test the
> +   library implementation, not the compiler intrinsic.  */
> +uint32_t (*volatile htonl_ptr) (uint32_t) = htonl;
> +uint32_t (*volatile ntohl_ptr) (uint32_t) = ntohl;
> +uint16_t (*volatile htons_ptr) (uint16_t) = htons;
> +uint16_t (*volatile ntohs_ptr) (uint16_t) = ntohs;

Perhaps -fno-builtin is already sufficient?
  
Florian Weimer June 14, 2024, 10:29 a.m. UTC | #2
* Andreas Schwab:

> On Jun 14 2024, Florian Weimer wrote:
>
>> +/* Use a volatile function pointer as a compiler barrier, to test the
>> +   library implementation, not the compiler intrinsic.  */
>> +uint32_t (*volatile htonl_ptr) (uint32_t) = htonl;
>> +uint32_t (*volatile ntohl_ptr) (uint32_t) = ntohl;
>> +uint16_t (*volatile htons_ptr) (uint16_t) = htons;
>> +uint16_t (*volatile ntohs_ptr) (uint16_t) = ntohs;
>
> Perhaps -fno-builtin is already sufficient?

Hmm.  There is no compiler builtin yet, which means that (htonl)
etc. are currently sufficient for ensuring that the implementation is
called.  I'd still like to make this change in case one gets added.

Thanks,
Florian
  
Florian Weimer June 17, 2024, 1:27 p.m. UTC | #3
* Florian Weimer:

> * Andreas Schwab:
>
>> On Jun 14 2024, Florian Weimer wrote:
>>
>>> +/* Use a volatile function pointer as a compiler barrier, to test the
>>> +   library implementation, not the compiler intrinsic.  */
>>> +uint32_t (*volatile htonl_ptr) (uint32_t) = htonl;
>>> +uint32_t (*volatile ntohl_ptr) (uint32_t) = ntohl;
>>> +uint16_t (*volatile htons_ptr) (uint16_t) = htons;
>>> +uint16_t (*volatile ntohs_ptr) (uint16_t) = ntohs;
>>
>> Perhaps -fno-builtin is already sufficient?
>
> Hmm.  There is no compiler builtin yet, which means that (htonl)
> etc. are currently sufficient for ensuring that the implementation is
> called.  I'd still like to make this change in case one gets added.

Let's drop this patch.

Thanks,
Florian
  

Patch

diff --git a/inet/htontest.c b/inet/htontest.c
index c7543f04ba..f473603fe1 100644
--- a/inet/htontest.c
+++ b/inet/htontest.c
@@ -37,33 +37,51 @@ 
 # error "Bah, what kind of system do you use?"
 #endif
 
-uint32_t lo = 0x67452301;
-uint16_t foo = 0x1234;
+/* Use volatile to force evaluation at run time.  */
+volatile uint32_t lo = 0x67452301;
+volatile uint16_t foo = 0x1234;
 
-int
-main (void)
+/* Use a volatile function pointer as a compiler barrier, to test the
+   library implementation, not the compiler intrinsic.  */
+uint32_t (*volatile htonl_ptr) (uint32_t) = htonl;
+uint32_t (*volatile ntohl_ptr) (uint32_t) = ntohl;
+uint16_t (*volatile htons_ptr) (uint16_t) = htons;
+uint16_t (*volatile ntohs_ptr) (uint16_t) = ntohs;
+
+static int
+do_test (void)
 {
   int result = 0;
 
   TEST (0x67452301, 0x01234567, htonl);
   TEST (0x67452301, 0x01234567, (htonl));
+  TEST (0x67452301, 0x01234567, htonl_ptr);
   TEST (0x67452301, 0x01234567, ntohl);
   TEST (0x67452301, 0x01234567, (ntohl));
+  TEST (0x67452301, 0x01234567, ntohl_ptr);
 
   TEST (lo, 0x01234567, htonl);
   TEST (lo, 0x01234567, (htonl));
+  TEST (lo, 0x01234567, htonl_ptr);
   TEST (lo, 0x01234567, ntohl);
   TEST (lo, 0x01234567, (ntohl));
+  TEST (lo, 0x01234567, ntohl_ptr);
 
   TEST (0x1234, 0x3412, htons);
   TEST (0x1234, 0x3412, (htons));
+  TEST (0x1234, 0x3412, htons_ptr);
   TEST (0x1234, 0x3412, ntohs);
   TEST (0x1234, 0x3412, (ntohs));
+  TEST (0x1234, 0x3412, ntohs_ptr);
 
   TEST (foo, 0x3412, htons);
   TEST (foo, 0x3412, (htons));
+  TEST (foo, 0x3412, htons_ptr);
   TEST (foo, 0x3412, ntohs);
   TEST (foo, 0x3412, (ntohs));
+  TEST (foo, 0x3412, ntohs_ptr);
 
   return result;
 }
+
+#include <support/test-driver.c>