2
0

mk-bundle.pl 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) Viktor Szakats
  10. #
  11. # This software is licensed as described in the file COPYING, which
  12. # you should have received as part of this distribution. The terms
  13. # are also available at https://curl.se/docs/copyright.html.
  14. #
  15. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. # copies of the Software, and permit persons to whom the Software is
  17. # furnished to do so, under the terms of the COPYING file.
  18. #
  19. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. # KIND, either express or implied.
  21. #
  22. # SPDX-License-Identifier: curl
  23. #
  24. ###########################################################################
  25. # Bundle up individual tests into a single binary. The resulting binary can run
  26. # individual tests by passing their name (without '.c') as the first argument.
  27. #
  28. # Usage: mk-bundle.pl [<directory>]
  29. use strict;
  30. use warnings;
  31. my $src_dir = @ARGV ? $ARGV[0] : ".";
  32. # Read list of tests
  33. open my $fh, "<", "$src_dir/Makefile.inc" or die "Cannot open '$src_dir/Makefile.inc': $!";
  34. print <<HEADER
  35. /* !checksrc! disable COPYRIGHT all */
  36. /* !checksrc! disable INCLUDEDUP all */
  37. #define CURLTESTS_BUNDLED
  38. #define CURLTESTS_BUNDLED_TEST_H
  39. #include "first.h"
  40. HEADER
  41. ;
  42. # TODO: Some of these might be subject for de-duplication or sync.
  43. my @reused_symbols = (
  44. "ReadThis",
  45. "ReadWriteSockets",
  46. "Sockets",
  47. "Tdata",
  48. "WriteThis",
  49. "addFd",
  50. "checkFdSet",
  51. "checkForCompletion",
  52. "close_file_descriptors",
  53. "curl", # shadow
  54. "curlSocketCallback",
  55. "curlTimerCallback",
  56. "cyclic_add",
  57. "easy", # unit
  58. "fopen_works",
  59. "getMicroSecondTimeout",
  60. "geterr",
  61. "hash_static", # unit
  62. "header_callback",
  63. "ioctlcallback",
  64. "msgbuff",
  65. "mydtor", # unit
  66. "num_open",
  67. "progress_callback",
  68. "read_callback",
  69. "readcallback",
  70. "recv_pong",
  71. "removeFd",
  72. "rlim2str",
  73. "run_thread",
  74. "send_ping",
  75. "showem",
  76. "store_errmsg",
  77. "suburl",
  78. "test_failure", # shadow
  79. "test_fire",
  80. "test_lock",
  81. "test_once",
  82. "test_parse", # unit
  83. "test_rlimit",
  84. "test_unlock",
  85. "testbuf",
  86. "testcase", # unit
  87. "testdata",
  88. "testfd",
  89. "testname",
  90. "testpost",
  91. "tests", # unit
  92. "teststring",
  93. "trailers_callback",
  94. "transfer_status",
  95. "unit_setup", # unit
  96. "unit_stop", # unit
  97. "updateFdSet",
  98. "userdata",
  99. "websocket",
  100. "websocket_close",
  101. "write_callback",
  102. "write_cb",
  103. "writecb",
  104. "xferinfo",
  105. );
  106. # TODO: Some of these may be #undef-ed manually at the end of each source
  107. my @reused_macros = (
  108. "HEADER_REQUEST",
  109. "NUM_HANDLES",
  110. "SAFETY_MARGIN",
  111. "TEST_HANG_TIMEOUT",
  112. );
  113. my $tlist = "";
  114. while(my $line = <$fh>) {
  115. chomp $line;
  116. if($line =~ /([a-z0-9]+)_SOURCES\ =\ ([a-z0-9]+)\.c/) {
  117. my $name = $1;
  118. my $namu = uc($name);
  119. my $src = "$2.c";
  120. # Make common symbols unique across test sources
  121. foreach my $symb ("test", @reused_symbols) {
  122. print "#undef $symb\n";
  123. print "#define $symb ${symb}_$name\n";
  124. }
  125. print "#define $namu\n";
  126. print "#include \"$src\"\n";
  127. print "#undef $namu\n";
  128. # Reset macros re-used by multiple tests
  129. foreach my $undef ("test", @reused_macros) {
  130. print "#undef $undef\n";
  131. }
  132. print "\n";
  133. $tlist .= " {\"$name\", test_$name},\n";
  134. }
  135. }
  136. close $fh;
  137. print <<FOOTER
  138. static const struct onetest s_tests[] = {
  139. $tlist};
  140. #undef CURLTESTS_BUNDLED_TEST_H
  141. #include "first.c"
  142. FOOTER
  143. ;