1#include "git-compat-util.h"
2#include "test-tool.h"
3#include "trace2.h"
4
5struct test_cmd {
6 const char *name;
7 int (*fn)(int argc, const char **argv);
8};
9
10static struct test_cmd cmds[] = {
11 { "chmtime", cmd__chmtime },
12 { "config", cmd__config },
13 { "ctype", cmd__ctype },
14 { "date", cmd__date },
15 { "delta", cmd__delta },
16 { "drop-caches", cmd__drop_caches },
17 { "dump-cache-tree", cmd__dump_cache_tree },
18 { "dump-fsmonitor", cmd__dump_fsmonitor },
19 { "dump-split-index", cmd__dump_split_index },
20 { "dump-untracked-cache", cmd__dump_untracked_cache },
21 { "example-decorate", cmd__example_decorate },
22 { "genrandom", cmd__genrandom },
23 { "genzeros", cmd__genzeros },
24 { "hashmap", cmd__hashmap },
25 { "hash-speed", cmd__hash_speed },
26 { "index-version", cmd__index_version },
27 { "json-writer", cmd__json_writer },
28 { "lazy-init-name-hash", cmd__lazy_init_name_hash },
29 { "match-trees", cmd__match_trees },
30 { "mergesort", cmd__mergesort },
31 { "mktemp", cmd__mktemp },
32 { "online-cpus", cmd__online_cpus },
33 { "parse-options", cmd__parse_options },
34 { "path-utils", cmd__path_utils },
35 { "pkt-line", cmd__pkt_line },
36 { "prio-queue", cmd__prio_queue },
37 { "reach", cmd__reach },
38 { "read-cache", cmd__read_cache },
39 { "read-midx", cmd__read_midx },
40 { "ref-store", cmd__ref_store },
41 { "regex", cmd__regex },
42 { "repository", cmd__repository },
43 { "revision-walking", cmd__revision_walking },
44 { "run-command", cmd__run_command },
45 { "scrap-cache-tree", cmd__scrap_cache_tree },
46 { "sha1", cmd__sha1 },
47 { "sha1-array", cmd__sha1_array },
48 { "sha256", cmd__sha256 },
49 { "sigchain", cmd__sigchain },
50 { "strcmp-offset", cmd__strcmp_offset },
51 { "string-list", cmd__string_list },
52 { "submodule-config", cmd__submodule_config },
53 { "submodule-nested-repo-config", cmd__submodule_nested_repo_config },
54 { "subprocess", cmd__subprocess },
55 { "trace2", cmd__trace2 },
56 { "urlmatch-normalization", cmd__urlmatch_normalization },
57 { "xml-encode", cmd__xml_encode },
58 { "wildmatch", cmd__wildmatch },
59#ifdef GIT_WINDOWS_NATIVE
60 { "windows-named-pipe", cmd__windows_named_pipe },
61#endif
62 { "write-cache", cmd__write_cache },
63};
64
65static NORETURN void die_usage(void)
66{
67 size_t i;
68
69 fprintf(stderr, "usage: test-tool <toolname> [args]\n");
70 for (i = 0; i < ARRAY_SIZE(cmds); i++)
71 fprintf(stderr, " %s\n", cmds[i].name);
72 exit(128);
73}
74
75int cmd_main(int argc, const char **argv)
76{
77 int i;
78
79 BUG_exit_code = 99;
80 if (argc < 2)
81 die_usage();
82
83 for (i = 0; i < ARRAY_SIZE(cmds); i++) {
84 if (!strcmp(cmds[i].name, argv[1])) {
85 argv++;
86 argc--;
87 trace2_cmd_name(cmds[i].name);
88 trace2_cmd_list_config();
89 return cmds[i].fn(argc, argv);
90 }
91 }
92 error("there is no tool named '%s'", argv[1]);
93 die_usage();
94}