Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

byteswap_test.c 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. FILE_LICENCE ( GPL2_OR_LATER );
  20. /** @file
  21. *
  22. * Byte-order swapping test functions
  23. *
  24. */
  25. /* Forcibly enable assertions */
  26. #undef NDEBUG
  27. #include <stdint.h>
  28. #include <assert.h>
  29. #include <byteswap.h>
  30. #include <ipxe/test.h>
  31. /* Provide global functions to allow inspection of generated assembly code */
  32. uint16_t test_bswap16 ( uint16_t x ) {
  33. return __bswap_16 ( x );
  34. }
  35. uint32_t test_bswap32 ( uint32_t x ) {
  36. return __bswap_32 ( x );
  37. }
  38. uint64_t test_bswap64 ( uint64_t x ) {
  39. return __bswap_64 ( x );
  40. }
  41. void test_bswap16s ( uint16_t *x ) {
  42. __bswap_16s ( x );
  43. }
  44. void test_bswap32s ( uint32_t *x ) {
  45. __bswap_32s ( x );
  46. }
  47. void test_bswap64s ( uint64_t *x ) {
  48. __bswap_64s ( x );
  49. }
  50. /**
  51. * Perform byte-order swapping
  52. *
  53. */
  54. static void byteswap_test_exec ( void ) {
  55. uint16_t test16;
  56. uint32_t test32;
  57. uint64_t test64;
  58. ok ( test_bswap16 ( 0x1234 ) == 0x3412 );
  59. ok ( test_bswap32 ( 0x12345678UL ) == 0x78563412UL );
  60. ok ( test_bswap64 ( 0x123456789abcdef0ULL ) == 0xf0debc9a78563412ULL );
  61. test16 = 0xabcd;
  62. test_bswap16s ( &test16 );
  63. ok ( test16 == 0xcdab );
  64. test32 = 0xabcdef01UL;
  65. test_bswap32s ( &test32 );
  66. ok ( test32 == 0x01efcdabUL );
  67. test64 = 0xabcdef0123456789ULL;
  68. test_bswap64s ( &test64 );
  69. ok ( test64 == 0x8967452301efcdabULL );
  70. }
  71. /** Byte-order swapping self-test */
  72. struct self_test byteswap_test __self_test = {
  73. .name = "byteswap",
  74. .exec = byteswap_test_exec,
  75. };