Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mpers_test.sh 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/sh -efu
  2. #
  3. # Copyright (c) 2015 Elvira Khabirova <lineprinter0@gmail.com>
  4. # Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
  5. # Copyright (c) 2015-2019 The strace developers.
  6. # All rights reserved.
  7. #
  8. # SPDX-License-Identifier: LGPL-2.1-or-later
  9. [ "x${D:-0}" != x1 ] || set -x
  10. mpers_name="$1"; shift
  11. mpers_cc_flags="$1"; shift
  12. size="$(printf %s "$mpers_name" |tr -cd '[0-9]')"
  13. [ "$size" -gt 0 ]
  14. srcdir=${0%/*}
  15. mpers_sh="${srcdir}/mpers.sh"
  16. mpers_dir="mpers-$mpers_name"
  17. mkdir -p "$mpers_dir"
  18. sample="$mpers_dir/sample.c"
  19. cat > "$sample" <<EOF
  20. #include "mpers_type.h"
  21. #include DEF_MPERS_TYPE(sample_struct)
  22. typedef struct {
  23. struct {
  24. void *p;
  25. char sc;
  26. /* unsigned char mpers_filler_1[1]; */
  27. short ss;
  28. unsigned char uc;
  29. /* unsigned char mpers_filler_2[3]; */
  30. int si;
  31. unsigned ui;
  32. long sl;
  33. unsigned short us;
  34. /* unsigned char mpers_filler_3[6]; */
  35. long long sll __attribute__((__aligned__(8)));
  36. unsigned long long ull;
  37. unsigned long ul;
  38. long asl[3][5][7];
  39. char f;
  40. /* unsigned char mpers_end_filler_4[7]; */
  41. } s;
  42. union {
  43. long long sll;
  44. unsigned long long ull;
  45. void *p;
  46. long sl;
  47. unsigned long ul;
  48. int si;
  49. unsigned ui;
  50. short ss[7][9];
  51. unsigned short us[4];
  52. char sc;
  53. unsigned char uc;
  54. } u[3][2];
  55. short f[0];
  56. } sample_struct;
  57. #include MPERS_DEFS
  58. EOF
  59. expected="$mpers_dir/sample.expected"
  60. mpers_ptr_t="uint${size}_t"
  61. cat > "$expected" <<EOF
  62. #include <stdint.h>
  63. #ifndef mpers_ptr_t_is_${mpers_ptr_t}
  64. typedef ${mpers_ptr_t} mpers_ptr_t;
  65. #define mpers_ptr_t_is_${mpers_ptr_t}
  66. #endif
  67. typedef
  68. struct {
  69. struct {
  70. mpers_ptr_t p;
  71. char sc;
  72. unsigned char mpers_filler_1[1];
  73. int16_t ss;
  74. unsigned char uc;
  75. unsigned char mpers_filler_2[3];
  76. int32_t si;
  77. uint32_t ui;
  78. int${size}_t sl;
  79. uint16_t us;
  80. unsigned char mpers_filler_3[6];
  81. int64_t sll;
  82. uint64_t ull;
  83. uint${size}_t ul;
  84. int${size}_t asl[3][5][7];
  85. char f;
  86. unsigned char mpers_end_filler_4[7];
  87. } ATTRIBUTE_PACKED s;
  88. union {
  89. int64_t sll;
  90. uint64_t ull;
  91. mpers_ptr_t p;
  92. int${size}_t sl;
  93. uint${size}_t ul;
  94. int32_t si;
  95. uint32_t ui;
  96. int16_t ss[7][9];
  97. uint16_t us[4];
  98. char sc;
  99. unsigned char uc;
  100. } u[3][2];
  101. int16_t f[0];
  102. } ATTRIBUTE_PACKED ${mpers_name}_sample_struct;
  103. #define MPERS_${mpers_name}_sample_struct ${mpers_name}_sample_struct
  104. EOF
  105. CFLAGS="$CPPFLAGS -I${srcdir} -DMPERS_IS_${mpers_name}" \
  106. CPPFLAGS="$CPPFLAGS -I${srcdir} -DIN_MPERS -DMPERS_IS_${mpers_name}" \
  107. "$mpers_sh" "$mpers_name" "$mpers_cc_flags" "$sample"
  108. cmp "$expected" "$mpers_dir"/sample_struct.h > /dev/null