test_skel.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Copyright 2018, Google Inc. All rights reserved.
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions are
  5. * met:
  6. *
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above
  10. * copyright notice, this list of conditions and the following disclaimer
  11. * in the documentation and/or other materials provided with the
  12. * distribution.
  13. * * Neither the name of Google Inc. nor the names of its
  14. * contributors may be used to endorse or promote products derived from
  15. * this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. /*
  30. * Make sure it's defined before including anything else. A number of syscalls
  31. * are GNU extensions and rely on being exported by glibc.
  32. */
  33. #ifndef _GNU_SOURCE
  34. #define _GNU_SOURCE
  35. #endif
  36. /*
  37. * Make sure the assert checks aren't removed as all the unittests are based
  38. * on them.
  39. */
  40. #undef NDEBUG
  41. #include <assert.h>
  42. #include <fcntl.h>
  43. #include <sched.h>
  44. #include <stdint.h>
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <sys/mman.h>
  48. #include <sys/prctl.h>
  49. #include <sys/stat.h>
  50. #include <sys/vfs.h>
  51. #include <sys/wait.h>
  52. #include <linux/capability.h>
  53. #include "linux_syscall_support.h"
  54. void assert_buffers_eq_len(const void *buf1, const void *buf2, size_t len) {
  55. const uint8_t *u8_1 = (const uint8_t *)buf1;
  56. const uint8_t *u8_2 = (const uint8_t *)buf2;
  57. size_t i;
  58. for (i = 0; i < len; ++i) {
  59. if (u8_1[i] != u8_2[i])
  60. printf("offset %zu: %02x != %02x\n", i, u8_1[i], u8_2[i]);
  61. }
  62. }
  63. #define assert_buffers_eq(obj1, obj2) assert_buffers_eq_len(obj1, obj2, sizeof(*obj1))