Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

byteswap_test.c 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. /** @file
  25. *
  26. * Byte-order swapping test functions
  27. *
  28. */
  29. /* Forcibly enable assertions */
  30. #undef NDEBUG
  31. #include <stdint.h>
  32. #include <assert.h>
  33. #include <byteswap.h>
  34. #include <ipxe/test.h>
  35. /* Provide global functions to allow inspection of generated assembly code */
  36. uint16_t test_bswap16 ( uint16_t x ) {
  37. return __bswap_16 ( x );
  38. }
  39. uint32_t test_bswap32 ( uint32_t x ) {
  40. return __bswap_32 ( x );
  41. }
  42. uint64_t test_bswap64 ( uint64_t x ) {
  43. return __bswap_64 ( x );
  44. }
  45. void test_bswap16s ( uint16_t *x ) {
  46. __bswap_16s ( x );
  47. }
  48. void test_bswap32s ( uint32_t *x ) {
  49. __bswap_32s ( x );
  50. }
  51. void test_bswap64s ( uint64_t *x ) {
  52. __bswap_64s ( x );
  53. }
  54. /**
  55. * Perform byte-order swapping
  56. *
  57. */
  58. static void byteswap_test_exec ( void ) {
  59. uint16_t test16;
  60. uint32_t test32;
  61. uint64_t test64;
  62. ok ( test_bswap16 ( 0x1234 ) == 0x3412 );
  63. ok ( test_bswap32 ( 0x12345678UL ) == 0x78563412UL );
  64. ok ( test_bswap64 ( 0x123456789abcdef0ULL ) == 0xf0debc9a78563412ULL );
  65. test16 = 0xabcd;
  66. test_bswap16s ( &test16 );
  67. ok ( test16 == 0xcdab );
  68. test32 = 0xabcdef01UL;
  69. test_bswap32s ( &test32 );
  70. ok ( test32 == 0x01efcdabUL );
  71. test64 = 0xabcdef0123456789ULL;
  72. test_bswap64s ( &test64 );
  73. ok ( test64 == 0x8967452301efcdabULL );
  74. }
  75. /** Byte-order swapping self-test */
  76. struct self_test byteswap_test __self_test = {
  77. .name = "byteswap",
  78. .exec = byteswap_test_exec,
  79. };