2018-03-24 08:44:30 +01:00
|
|
|
#include "git-compat-util.h"
|
|
|
|
#include "test-tool.h"
|
2019-02-22 23:25:01 +01:00
|
|
|
#include "trace2.h"
|
2019-04-18 15:16:49 +02:00
|
|
|
#include "parse-options.h"
|
|
|
|
|
|
|
|
static const char * const test_tool_usage[] = {
|
|
|
|
"test-tool [-C <directory>] <command [<arguments>...]]",
|
|
|
|
NULL
|
|
|
|
};
|
2018-03-24 08:44:30 +01:00
|
|
|
|
|
|
|
struct test_cmd {
|
|
|
|
const char *name;
|
|
|
|
int (*fn)(int argc, const char **argv);
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct test_cmd cmds[] = {
|
2020-03-02 21:01:59 +01:00
|
|
|
{ "advise", cmd__advise_if_enabled },
|
2021-04-01 03:32:11 +02:00
|
|
|
{ "bitmap", cmd__bitmap },
|
2020-03-30 02:31:24 +02:00
|
|
|
{ "bloom", cmd__bloom },
|
2018-03-24 08:44:31 +01:00
|
|
|
{ "chmtime", cmd__chmtime },
|
2018-03-24 08:44:34 +01:00
|
|
|
{ "config", cmd__config },
|
2020-09-11 19:49:18 +02:00
|
|
|
{ "crontab", cmd__crontab },
|
wrapper: add a helper to generate numbers from a CSPRNG
There are many situations in which having access to a cryptographically
secure pseudorandom number generator (CSPRNG) is helpful. In the
future, we'll encounter one of these when dealing with temporary files.
To make this possible, let's add a function which reads from a system
CSPRNG and returns some bytes.
We know that all systems will have such an interface. A CSPRNG is
required for a secure TLS or SSH implementation and a Git implementation
which provided neither would be of little practical use. In addition,
POSIX is set to standardize getentropy(2) in the next version, so in the
(potentially distant) future we can rely on that.
For systems which lack one of the other interfaces, we provide the
ability to use OpenSSL's CSPRNG. OpenSSL is highly portable and
functions on practically every known OS, and we know it will have access
to some source of cryptographically secure randomness. We also provide
support for the arc4random in libbsd for folks who would prefer to use
that.
Because this is a security sensitive interface, we take some
precautions. We either succeed by filling the buffer completely as we
requested, or we fail. We don't return partial data because the caller
will almost never find that to be a useful behavior.
Specify a makefile knob which users can use to specify one or more
suitable CSPRNGs, and turn the multiple string options into a set of
defines, since we cannot match on strings in the preprocessor. We allow
multiple options to make the job of handling this in autoconf easier.
The order of options is important here. On systems with arc4random,
which is most of the BSDs, we use that, since, except on MirBSD and
macOS, it uses ChaCha20, which is extremely fast, and sits entirely in
userspace, avoiding a system call. We then prefer getrandom over
getentropy, because the former has been available longer on Linux, and
then OpenSSL. Finally, if none of those are available, we use
/dev/urandom, because most Unix-like operating systems provide that API.
We prefer options that don't involve device files when possible because
those work in some restricted environments where device files may not be
available.
Set the configuration variables appropriately for Linux and the BSDs,
including macOS, as well as Windows and NonStop. We specifically only
consider versions which receive publicly available security support
here. For the same reason, we don't specify getrandom(2) on Linux,
because CentOS 7 doesn't support it in glibc (although its kernel does)
and we don't want to resort to making syscalls.
Finally, add a test helper to allow this to be tested by hand and in
tests. We don't add any tests, since invoking the CSPRNG is not likely
to produce interesting, reproducible results.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-01-17 22:56:16 +01:00
|
|
|
{ "csprng", cmd__csprng },
|
2018-03-24 08:44:35 +01:00
|
|
|
{ "ctype", cmd__ctype },
|
2018-03-24 08:44:36 +01:00
|
|
|
{ "date", cmd__date },
|
2018-03-24 08:44:37 +01:00
|
|
|
{ "delta", cmd__delta },
|
2019-07-11 01:58:57 +02:00
|
|
|
{ "dir-iterator", cmd__dir_iterator },
|
2018-03-24 08:44:38 +01:00
|
|
|
{ "drop-caches", cmd__drop_caches },
|
2018-03-24 08:44:39 +01:00
|
|
|
{ "dump-cache-tree", cmd__dump_cache_tree },
|
2018-09-09 19:36:30 +02:00
|
|
|
{ "dump-fsmonitor", cmd__dump_fsmonitor },
|
2018-03-24 08:44:40 +01:00
|
|
|
{ "dump-split-index", cmd__dump_split_index },
|
2018-09-09 19:36:27 +02:00
|
|
|
{ "dump-untracked-cache", cmd__dump_untracked_cache },
|
2018-03-24 08:44:41 +01:00
|
|
|
{ "example-decorate", cmd__example_decorate },
|
2020-10-29 21:32:13 +01:00
|
|
|
{ "fast-rebase", cmd__fast_rebase },
|
2022-03-25 19:03:03 +01:00
|
|
|
{ "fsmonitor-client", cmd__fsmonitor_client },
|
2018-03-24 08:44:42 +01:00
|
|
|
{ "genrandom", cmd__genrandom },
|
tests: teach the test-tool to generate NUL bytes and use it
In cc95bc2025 (t5562: replace /dev/zero with a pipe from
generate_zero_bytes, 2019-02-09), we replaced usage of /dev/zero (which
is not available on NonStop, apparently) by a Perl script snippet to
generate NUL bytes.
Sadly, it does not seem to work on NonStop, as t5562 reportedly hangs.
Worse, this also hangs in the Ubuntu 16.04 agents of the CI builds on
Azure Pipelines: for some reason, the Perl script snippet that is run
via `generate_zero_bytes` in t5562's 'CONTENT_LENGTH overflow ssite_t'
test case tries to write out an infinite amount of NUL bytes unless a
broken pipe is encountered, that snippet never encounters the broken
pipe, and keeps going until the build times out.
Oddly enough, this does not reproduce on the Windows and macOS agents,
nor in a local Ubuntu 18.04.
This developer tried for a day to figure out the exact circumstances
under which this hang happens, to no avail, the details remain a
mystery.
In the end, though, what counts is that this here change incidentally
fixes that hang (maybe also on NonStop?). Even more positively, it gets
rid of yet another unnecessary Perl invocation.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-02-14 22:33:12 +01:00
|
|
|
{ "genzeros", cmd__genzeros },
|
2021-07-30 18:18:14 +02:00
|
|
|
{ "getcwd", cmd__getcwd },
|
2018-03-24 08:44:43 +01:00
|
|
|
{ "hashmap", cmd__hashmap },
|
2018-11-14 05:09:34 +01:00
|
|
|
{ "hash-speed", cmd__hash_speed },
|
2022-05-26 23:47:20 +02:00
|
|
|
{ "hexdump", cmd__hexdump },
|
2018-03-24 08:44:44 +01:00
|
|
|
{ "index-version", cmd__index_version },
|
2018-07-13 18:54:08 +02:00
|
|
|
{ "json-writer", cmd__json_writer },
|
2018-03-24 08:44:33 +01:00
|
|
|
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
|
2018-03-24 08:44:45 +01:00
|
|
|
{ "match-trees", cmd__match_trees },
|
2018-03-24 08:44:46 +01:00
|
|
|
{ "mergesort", cmd__mergesort },
|
2018-03-24 08:44:47 +01:00
|
|
|
{ "mktemp", cmd__mktemp },
|
2020-03-30 16:04:03 +02:00
|
|
|
{ "oid-array", cmd__oid_array },
|
2019-06-15 12:06:59 +02:00
|
|
|
{ "oidmap", cmd__oidmap },
|
2021-07-08 01:10:19 +02:00
|
|
|
{ "oidtree", cmd__oidtree },
|
2018-03-24 08:44:48 +01:00
|
|
|
{ "online-cpus", cmd__online_cpus },
|
2022-05-21 01:17:46 +02:00
|
|
|
{ "pack-mtimes", cmd__pack_mtimes },
|
2018-09-09 19:36:29 +02:00
|
|
|
{ "parse-options", cmd__parse_options },
|
2019-12-31 11:15:12 +01:00
|
|
|
{ "parse-pathspec-file", cmd__parse_pathspec_file },
|
2021-06-17 19:13:26 +02:00
|
|
|
{ "partial-clone", cmd__partial_clone },
|
2018-03-24 08:44:49 +01:00
|
|
|
{ "path-utils", cmd__path_utils },
|
grep/pcre2: better support invalid UTF-8 haystacks
Improve the support for invalid UTF-8 haystacks given a non-ASCII
needle when using the PCREv2 backend.
This is a more complete fix for a bug I started to fix in
870eea8166 (grep: do not enter PCRE2_UTF mode on fixed matching,
2019-07-26), now that PCREv2 has the PCRE2_MATCH_INVALID_UTF mode we
can make use of it.
This fixes the sort of case described in 8a5999838e (grep: stess test
PCRE v2 on invalid UTF-8 data, 2019-07-26), i.e.:
- The subject string is non-ASCII (e.g. "ævar")
- We're under a is_utf8_locale(), e.g. "en_US.UTF-8", not "C"
- We are using --ignore-case, or we're a non-fixed pattern
If those conditions were satisfied and we matched found non-valid
UTF-8 data PCREv2 might bark on it, in practice this only happened
under the JIT backend (turned on by default on most platforms).
Ultimately this fixes a "regression" in b65abcafc7 ("grep: use PCRE v2
for optimized fixed-string search", 2019-07-01), I'm putting that in
scare-quotes because before then we wouldn't properly support these
complex case-folding, locale etc. cases either, it just broke in
different ways.
There was a bug related to this the PCRE2_NO_START_OPTIMIZE flag fixed
in PCREv2 10.36. It can be worked around by setting the
PCRE2_NO_START_OPTIMIZE flag. Let's do that in those cases, and add
tests for the bug.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-01-24 18:28:13 +01:00
|
|
|
{ "pcre2-config", cmd__pcre2_config },
|
2018-09-09 19:36:28 +02:00
|
|
|
{ "pkt-line", cmd__pkt_line },
|
2018-03-24 08:44:50 +01:00
|
|
|
{ "prio-queue", cmd__prio_queue },
|
2021-10-07 22:25:00 +02:00
|
|
|
{ "proc-receive", cmd__proc_receive },
|
Test the progress display
'progress.c' has seen a few fixes recently [1], and, unfortunately,
some of those fixes required further fixes [2]. It seems it's time to
have a few tests focusing on the subtleties of the progress display.
Add the 'test-tool progress' subcommand to help testing the progress
display, reading instructions from standard input and turning them
into calls to the display_progress() and display_throughput()
functions with the given parameters.
The progress display is, however, critically dependent on timing,
because it's only updated once every second or, if the toal is known
in advance, every 1%, and there is the throughput rate as well. These
make the progress display far too undeterministic for testing as-is.
To address this, add a few testing-specific variables and functions to
'progress.c', allowing the the new test helper to:
- Disable the triggered-every-second SIGALRM and set the
'progress_update' flag explicitly based in the input instructions.
This way the progress line will be updated deterministically when
the test wants it to be updated.
- Specify the time elapsed since start_progress() to make the
throughput rate calculations deterministic.
Add the new test script 't0500-progress-display.sh' to check a few
simple cases with and without throughput, and that a shorter progress
line properly covers up the previously displayed line in different
situations.
[1] See commits 545dc345eb (progress: break too long progress bar
lines, 2019-04-12) and 9f1fd84e15 (progress: clear previous
progress update dynamically, 2019-04-12).
[2] 1aed1a5f25 (progress: avoid empty line when breaking the progress
line, 2019-05-19)
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-09-16 22:54:12 +02:00
|
|
|
{ "progress", cmd__progress },
|
2018-07-20 18:33:15 +02:00
|
|
|
{ "reach", cmd__reach },
|
2018-03-24 08:44:51 +01:00
|
|
|
{ "read-cache", cmd__read_cache },
|
2019-11-12 17:58:20 +01:00
|
|
|
{ "read-graph", cmd__read_graph },
|
2018-07-12 21:39:23 +02:00
|
|
|
{ "read-midx", cmd__read_midx },
|
2018-03-24 08:44:52 +01:00
|
|
|
{ "ref-store", cmd__ref_store },
|
2021-10-07 22:25:00 +02:00
|
|
|
{ "reftable", cmd__reftable },
|
2021-10-07 22:25:15 +02:00
|
|
|
{ "dump-reftable", cmd__dump_reftable },
|
2018-03-24 08:44:53 +01:00
|
|
|
{ "regex", cmd__regex },
|
2018-07-12 00:42:42 +02:00
|
|
|
{ "repository", cmd__repository },
|
2018-03-24 08:44:54 +01:00
|
|
|
{ "revision-walking", cmd__revision_walking },
|
2018-03-24 08:44:55 +01:00
|
|
|
{ "run-command", cmd__run_command },
|
2018-03-24 08:44:56 +01:00
|
|
|
{ "scrap-cache-tree", cmd__scrap_cache_tree },
|
2019-04-18 15:16:51 +02:00
|
|
|
{ "serve-v2", cmd__serve_v2 },
|
2018-03-24 08:44:32 +01:00
|
|
|
{ "sha1", cmd__sha1 },
|
2018-11-14 05:09:36 +01:00
|
|
|
{ "sha256", cmd__sha256 },
|
2018-03-24 08:44:58 +01:00
|
|
|
{ "sigchain", cmd__sigchain },
|
2021-03-22 11:29:48 +01:00
|
|
|
{ "simple-ipc", cmd__simple_ipc },
|
2018-03-24 08:44:59 +01:00
|
|
|
{ "strcmp-offset", cmd__strcmp_offset },
|
2018-03-24 08:45:00 +01:00
|
|
|
{ "string-list", cmd__string_list },
|
2018-03-24 08:45:01 +01:00
|
|
|
{ "submodule-config", cmd__submodule_config },
|
2018-10-25 18:18:13 +02:00
|
|
|
{ "submodule-nested-repo-config", cmd__submodule_nested_repo_config },
|
2018-03-24 08:45:02 +01:00
|
|
|
{ "subprocess", cmd__subprocess },
|
2019-02-22 23:25:10 +01:00
|
|
|
{ "trace2", cmd__trace2 },
|
2021-04-08 17:04:21 +02:00
|
|
|
{ "userdiff", cmd__userdiff },
|
2018-03-24 08:45:03 +01:00
|
|
|
{ "urlmatch-normalization", cmd__urlmatch_normalization },
|
2019-01-29 15:19:27 +01:00
|
|
|
{ "xml-encode", cmd__xml_encode },
|
2018-03-24 08:45:04 +01:00
|
|
|
{ "wildmatch", cmd__wildmatch },
|
2018-09-11 22:06:01 +02:00
|
|
|
#ifdef GIT_WINDOWS_NATIVE
|
|
|
|
{ "windows-named-pipe", cmd__windows_named_pipe },
|
|
|
|
#endif
|
2018-03-24 08:45:05 +01:00
|
|
|
{ "write-cache", cmd__write_cache },
|
2018-03-24 08:44:30 +01:00
|
|
|
};
|
|
|
|
|
2018-10-17 11:25:07 +02:00
|
|
|
static NORETURN void die_usage(void)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
fprintf(stderr, "usage: test-tool <toolname> [args]\n");
|
|
|
|
for (i = 0; i < ARRAY_SIZE(cmds); i++)
|
|
|
|
fprintf(stderr, " %s\n", cmds[i].name);
|
|
|
|
exit(128);
|
|
|
|
}
|
|
|
|
|
2018-03-24 08:44:30 +01:00
|
|
|
int cmd_main(int argc, const char **argv)
|
|
|
|
{
|
|
|
|
int i;
|
2019-04-18 15:16:49 +02:00
|
|
|
const char *working_directory = NULL;
|
|
|
|
struct option options[] = {
|
|
|
|
OPT_STRING('C', NULL, &working_directory, "directory",
|
|
|
|
"change the working directory"),
|
|
|
|
OPT_END()
|
|
|
|
};
|
2018-03-24 08:44:30 +01:00
|
|
|
|
2018-05-02 11:38:28 +02:00
|
|
|
BUG_exit_code = 99;
|
2019-04-18 15:16:49 +02:00
|
|
|
argc = parse_options(argc, argv, NULL, options, test_tool_usage,
|
|
|
|
PARSE_OPT_STOP_AT_NON_OPTION |
|
|
|
|
PARSE_OPT_KEEP_ARGV0);
|
|
|
|
|
2018-03-24 08:44:30 +01:00
|
|
|
if (argc < 2)
|
2018-10-17 11:25:07 +02:00
|
|
|
die_usage();
|
2018-03-24 08:44:30 +01:00
|
|
|
|
2019-04-18 15:16:49 +02:00
|
|
|
if (working_directory && chdir(working_directory) < 0)
|
|
|
|
die("Could not cd to '%s'", working_directory);
|
|
|
|
|
2018-03-24 08:44:30 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(cmds); i++) {
|
|
|
|
if (!strcmp(cmds[i].name, argv[1])) {
|
|
|
|
argv++;
|
|
|
|
argc--;
|
2019-02-22 23:25:01 +01:00
|
|
|
trace2_cmd_name(cmds[i].name);
|
|
|
|
trace2_cmd_list_config();
|
2020-03-20 22:06:15 +01:00
|
|
|
trace2_cmd_list_env_vars();
|
2018-03-24 08:44:30 +01:00
|
|
|
return cmds[i].fn(argc, argv);
|
|
|
|
}
|
|
|
|
}
|
2018-10-17 11:25:07 +02:00
|
|
|
error("there is no tool named '%s'", argv[1]);
|
|
|
|
die_usage();
|
2018-03-24 08:44:30 +01:00
|
|
|
}
|