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