MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / main

Function main

smallthinker/tests/test-arg-parser.cpp:12–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include <cassert>
11
12int main(void) {
13 common_params params;
14
15 printf("test-arg-parser: make sure there is no duplicated arguments in any examples\n\n");
16 for (int ex = 0; ex < LLAMA_EXAMPLE_COUNT; ex++) {
17 try {
18 auto ctx_arg = common_params_parser_init(params, (enum llama_example)ex);
19 std::unordered_set<std::string> seen_args;
20 std::unordered_set<std::string> seen_env_vars;
21 for (const auto & opt : ctx_arg.options) {
22 // check for args duplications
23 for (const auto & arg : opt.args) {
24 if (seen_args.find(arg) == seen_args.end()) {
25 seen_args.insert(arg);
26 } else {
27 fprintf(stderr, "test-arg-parser: found different handlers for the same argument: %s", arg);
28 exit(1);
29 }
30 }
31 // check for env var duplications
32 if (opt.env) {
33 if (seen_env_vars.find(opt.env) == seen_env_vars.end()) {
34 seen_env_vars.insert(opt.env);
35 } else {
36 fprintf(stderr, "test-arg-parser: found different handlers for the same env var: %s", opt.env);
37 exit(1);
38 }
39 }
40 }
41 } catch (std::exception & e) {
42 printf("%s\n", e.what());
43 assert(false);
44 }
45 }
46
47 auto list_str_to_char = [](std::vector<std::string> & argv) -> std::vector<char *> {
48 std::vector<char *> res;
49 for (auto & arg : argv) {
50 res.push_back(const_cast<char *>(arg.data()));
51 }
52 return res;
53 };
54
55 std::vector<std::string> argv;
56
57 printf("test-arg-parser: test invalid usage\n\n");
58
59 // missing value
60 argv = {"binary_name", "-m"};
61 assert(false == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_COMMON));
62
63 // wrong value (int)
64 argv = {"binary_name", "-ngl", "hello"};
65 assert(false == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_COMMON));
66
67 // wrong value (enum)
68 argv = {"binary_name", "-sm", "hello"};
69 assert(false == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_COMMON));

Callers

nothing calls this directly

Calls 13

printfFunction · 0.85
fprintfFunction · 0.85
common_params_parseFunction · 0.85
common_has_curlFunction · 0.85
findMethod · 0.80
endMethod · 0.45
insertMethod · 0.45
whatMethod · 0.45
push_backMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected