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 26# Bundle up individual tests into a single binary. The resulting binary can run 27# individual tests by passing their name (without '.c') as the first argument. 28# 29# Usage: mk-bundle.pl [<directory>] 30 31use strict; 32use warnings; 33 34my $src_dir = @ARGV ? $ARGV[0] : "."; 35 36# Read list of tests 37open my $fh, "<", "$src_dir/Makefile.inc" or die "Cannot open '$src_dir/Makefile.inc': $!"; 38 39print <<HEADER 40/* !checksrc! disable COPYRIGHT all */ 41/* !checksrc! disable INCLUDEDUP all */ 42 43#define CURLTESTS_BUNDLED 44#define CURLTESTS_BUNDLED_TEST_H 45#include "first.h" 46HEADER 47 ; 48 49# TODO: Some of these might be subject for de-duplication or sync. 50my @reused_symbols = ( 51 "ReadThis", 52 "ReadWriteSockets", 53 "Sockets", 54 "Tdata", 55 "WriteThis", 56 "addFd", 57 "checkFdSet", 58 "checkForCompletion", 59 "close_file_descriptors", 60 "curl", # shadow 61 "curlSocketCallback", 62 "curlTimerCallback", 63 "cyclic_add", 64 "easy", # unit 65 "fopen_works", 66 "getMicroSecondTimeout", 67 "geterr", 68 "hash_static", # unit 69 "header_callback", 70 "ioctlcallback", 71 "msgbuff", 72 "mydtor", # unit 73 "num_open", 74 "progress_callback", 75 "read_callback", 76 "readcallback", 77 "recv_pong", 78 "removeFd", 79 "rlim2str", 80 "run_thread", 81 "send_ping", 82 "showem", 83 "store_errmsg", 84 "suburl", 85 "test_failure", # shadow 86 "test_fire", 87 "test_lock", 88 "test_once", 89 "test_parse", # unit 90 "test_rlimit", 91 "test_unlock", 92 "testbuf", 93 "testcase", # unit 94 "testdata", 95 "testfd", 96 "testname", 97 "testpost", 98 "tests", # unit 99 "teststring", 100 "trailers_callback", 101 "transfer_status", 102 "unit_setup", # unit 103 "unit_stop", # unit 104 "updateFdSet", 105 "userdata", 106 "websocket", 107 "websocket_close", 108 "write_callback", 109 "write_cb", 110 "writecb", 111 "xferinfo", 112 ); 113 114# TODO: Some of these may be #undef-ed manually at the end of each source 115my @reused_macros = ( 116 "HEADER_REQUEST", 117 "NUM_HANDLES", 118 "SAFETY_MARGIN", 119 "TEST_HANG_TIMEOUT", 120 ); 121 122my $tlist = ""; 123 124while(my $line = <$fh>) { 125 chomp $line; 126 if($line =~ /([a-z0-9]+)_SOURCES\ =\ ([a-z0-9]+)\.c/) { 127 my $name = $1; 128 my $namu = uc($name); 129 my $src = "$2.c"; 130 131 # Make common symbols unique across test sources 132 foreach my $symb ("test", @reused_symbols) { 133 print "#undef $symb\n"; 134 print "#define $symb ${symb}_$name\n"; 135 } 136 137 print "#define $namu\n"; 138 print "#include \"$src\"\n"; 139 print "#undef $namu\n"; 140 141 # Reset macros re-used by multiple tests 142 foreach my $undef ("test", @reused_macros) { 143 print "#undef $undef\n"; 144 } 145 146 print "\n"; 147 148 $tlist .= " {\"$name\", test_$name},\n"; 149 } 150} 151 152close $fh; 153 154print <<FOOTER 155static const struct onetest s_tests[] = { 156$tlist}; 157 158#undef CURLTESTS_BUNDLED_TEST_H 159 160#include "first.c" 161FOOTER 162 ; 163