/tests/misc/od-float.sh

https://gitlab.com/oyvholm/coreutils · Shell · 72 lines · 29 code · 12 blank · 31 comment · 1 complexity · ba034101a6850586f2ca10413a5294d7 MD5 · raw file

  1. #!/bin/sh
  2. # Test od on floating-point values.
  3. # Copyright (C) 2010-2016 Free Software Foundation, Inc.
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  15. print_ver_ od
  16. export LC_ALL=C
  17. # Test for a bug in coreutils up through 8.7: od was losing
  18. # information when asked to parse floating-point values. The numeric
  19. # tests are valid only on Intel-like hosts, but that should be good
  20. # enough to detect regressions, as they are designed to succeed on
  21. # non-Intel-like hosts. Also, test for another bug in coreutils 8.7
  22. # on x86: sometimes there was no space between the columns.
  23. set x $(echo aaaabaaa | tr ab '\376\377' | od -t fF) ||
  24. fail=1
  25. case "$*" in
  26. *0-*) fail=1;;
  27. esac
  28. case $3,$4 in
  29. -1.694740e+38,-1.694740e+38) fail=1;;
  30. esac
  31. set x $(echo aaaaaaaabaaaaaaa | tr ab '\376\377' | od -t fD) ||
  32. fail=1
  33. case "$*" in
  34. *0-*) fail=1;;
  35. esac
  36. case $3,$4 in
  37. -5.314010372517808e+303,-5.314010372517808e+303) fail=1;;
  38. esac
  39. set x $(echo aaaaaaaaaaaaaaaabaaaaaaaaaaaaaaa | tr ab '\376\377' | od -t fL) ||
  40. fail=1
  41. case "$*" in
  42. *0-*) fail=1;;
  43. esac
  44. case $3,$4 in
  45. -1.023442870282055988e+4855,-1.023442870282055988e+4855) fail=1;;
  46. esac
  47. # Ensure od doesn't crash as it did on glibc <= 2.5:
  48. # https://sourceware.org/bugzilla/show_bug.cgi?id=4586
  49. set x $(printf 00000000ff000000 | tr 0f '\000\377' | od -t fL) || fail=1
  50. # With coreutils <= 8.7 we used to print "nan" for the above invalid value.
  51. # However since v8.7-22-ga71c22f we deferred to the system printf routines
  52. # through the use of the ftoastr module. So the following check would only
  53. # be valid on x86_64 if we again handle the conversion internally or
  54. # if this glibc bug is resolved:
  55. # https://sourceware.org/bugzilla/show_bug.cgi?id=17661
  56. #case "$*" in
  57. #*nan*) ;;
  58. #*) fail=1;;
  59. #esac
  60. Exit $fail