tst-bswap.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Copyright (C) 2000-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #include <byteswap.h>
  15. #include <stdio.h>
  16. extern unsigned long long int wash (unsigned long long int a);
  17. int
  18. do_test (void)
  19. {
  20. int result = 0;
  21. /* Test the functions with constant arguments. */
  22. if (bswap_16 (0x1234) != 0x3412)
  23. {
  24. puts ("bswap_16 (constant) flunked");
  25. result = 1;
  26. }
  27. if (bswap_32 (0x12345678) != 0x78563412)
  28. {
  29. puts ("bswap_32 (constant) flunked");
  30. result = 1;
  31. }
  32. if (bswap_64 (0x1234567890abcdefULL) != 0xefcdab9078563412ULL)
  33. {
  34. puts ("bswap_64 (constant) flunked");
  35. result = 1;
  36. }
  37. /* Test the functions with non-constant arguments. */
  38. if (bswap_16 (wash (0x1234)) != 0x3412)
  39. {
  40. puts ("bswap_16 (non-constant) flunked");
  41. result = 1;
  42. }
  43. if (bswap_32 (wash (0x12345678)) != 0x78563412)
  44. {
  45. puts ("bswap_32 (non-constant) flunked");
  46. result = 1;
  47. }
  48. if (bswap_64 (wash (0x1234567890abcdefULL)) != 0xefcdab9078563412ULL)
  49. {
  50. puts ("bswap_64 (non-constant) flunked");
  51. result = 1;
  52. }
  53. return result;
  54. }
  55. unsigned long long int
  56. wash (unsigned long long int a)
  57. {
  58. /* Do nothing. This function simply exists to avoid that the compiler
  59. regards the argument to the bswap_*() functions as constant. */
  60. return a + 0;
  61. }
  62. #include <support/test-driver.c>