trace2: create new combined trace facility
[git] / t / helper / test-tool.c
1 #include "git-compat-util.h"
2 #include "test-tool.h"
3 #include "trace2.h"
4
5 struct test_cmd {
6         const char *name;
7         int (*fn)(int argc, const char **argv);
8 };
9
10 static 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         { "urlmatch-normalization", cmd__urlmatch_normalization },
56         { "xml-encode", cmd__xml_encode },
57         { "wildmatch", cmd__wildmatch },
58 #ifdef GIT_WINDOWS_NATIVE
59         { "windows-named-pipe", cmd__windows_named_pipe },
60 #endif
61         { "write-cache", cmd__write_cache },
62 };
63
64 static NORETURN void die_usage(void)
65 {
66         size_t i;
67
68         fprintf(stderr, "usage: test-tool <toolname> [args]\n");
69         for (i = 0; i < ARRAY_SIZE(cmds); i++)
70                 fprintf(stderr, "  %s\n", cmds[i].name);
71         exit(128);
72 }
73
74 int cmd_main(int argc, const char **argv)
75 {
76         int i;
77
78         BUG_exit_code = 99;
79         if (argc < 2)
80                 die_usage();
81
82         for (i = 0; i < ARRAY_SIZE(cmds); i++) {
83                 if (!strcmp(cmds[i].name, argv[1])) {
84                         argv++;
85                         argc--;
86                         trace2_cmd_name(cmds[i].name);
87                         trace2_cmd_list_config();
88                         return cmds[i].fn(argc, argv);
89                 }
90         }
91         error("there is no tool named '%s'", argv[1]);
92         die_usage();
93 }