make_test_files.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/bin/bash
  2. # Copyright 2016 Google Inc. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. if [ "$#" == "0" ] ; then
  16. echo "Usage: make_test_files.sh <output dir>"
  17. exit 1
  18. fi
  19. cd $1
  20. OUTPUT_DIR=`pwd`
  21. TMP=`mktemp -d`
  22. CC="${CC:-cc}"
  23. echo Writing output to $OUTPUT_DIR
  24. echo Working in $TMP
  25. cd $TMP
  26. function publish() {
  27. echo $1
  28. cp $1 $OUTPUT_DIR
  29. }
  30. function make_tmp_obj() {
  31. FILE=$1
  32. CONTENTS="$2"
  33. CFILE=`basename $1`.c
  34. echo "$CONTENTS" > $CFILE
  35. $CC -g -fPIC -o $FILE -c $CFILE
  36. }
  37. function make_obj() {
  38. FILE=$1
  39. CONTENTS="$2"
  40. make_tmp_obj $FILE "$CONTENTS"
  41. publish $FILE
  42. }
  43. function make_ar() {
  44. FILE=$1
  45. shift
  46. ar rcs $FILE "$@"
  47. publish $FILE
  48. }
  49. function make_so() {
  50. FILE=$1
  51. shift
  52. $CC -g -shared -o $FILE "$@"
  53. publish $FILE
  54. }
  55. function make_binary() {
  56. FILE=$1
  57. shift
  58. $CC -o $FILE "$@"
  59. publish $FILE
  60. }
  61. make_obj "01-empty.o" ""
  62. make_obj "02-simple.o" "
  63. #include <stdint.h>
  64. uint64_t bss_a = 0;
  65. uint32_t bss_b = 0;
  66. uint64_t data_a = 1;
  67. uint32_t data_b = 2;
  68. const uint64_t rodata_a = 1;
  69. const uint32_t rodata_b = 2;
  70. uint32_t func1() { return bss_b / 17; }
  71. uint32_t func2() { return data_b / 17; }"
  72. make_tmp_obj "foo.o" "
  73. int foo_x[1000] = {0};
  74. int foo_y = 0;
  75. int foo_func() { return foo_y / 17; }
  76. "
  77. make_tmp_obj "bar.o" "
  78. int bar_x[1000] = {1};
  79. int bar_y = 1;
  80. int bar_z = 0;
  81. int bar_func() { return bar_y / 17; }
  82. "
  83. make_tmp_obj "a_filename_longer_than_sixteen_chars.o" "
  84. int long_filename_x[3] = {1};
  85. int long_filename_y = 2;
  86. "
  87. make_ar "03-simple.a" "foo.o" "bar.o" "a_filename_longer_than_sixteen_chars.o"
  88. make_so "04-simple.so" "foo.o" "bar.o"
  89. make_tmp_obj "main.o" "int main() {}"
  90. make_binary "05-binary.bin" "foo.o" "bar.o" "main.o"
  91. # Make an object like foo.o but with different sizes.
  92. make_tmp_obj "foo2.o" "
  93. int foo_x[500] = {0};
  94. long long foo_y = 0;
  95. int foo_func() { return foo_y / 17 * 37 / 21; }
  96. "
  97. make_ar "06-diff.a" "foo2.o" "bar.o" "a_filename_longer_than_sixteen_chars.o"
  98. cp "05-binary.bin" "07-binary-stripped.bin"
  99. strip "07-binary-stripped.bin"
  100. publish "07-binary-stripped.bin"