~ubuntu-branches/debian/sid/botan/sid

« back to all changes in this revision

Viewing changes to src/tests/main.cpp

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2018-03-01 22:23:25 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20180301222325-7p7vc45gu3hta34d
Tags: 2.4.0-2
* Don't remove .doctrees from the manual if it doesn't exist.
* Don't specify parallel to debhelper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* (C) 2015 Jack Lloyd
 
3
*
 
4
* Botan is released under the Simplified BSD License (see license.txt)
 
5
*/
 
6
 
 
7
#include "../cli/argparse.h"
 
8
#include "test_runner.h"
 
9
#include "tests.h"
 
10
#include <iostream>
 
11
#include <vector>
 
12
#include <string>
 
13
#include <sstream>
 
14
 
 
15
#include <botan/version.h>
 
16
 
 
17
#if defined(BOTAN_HAS_OPENSSL)
 
18
   #include <botan/internal/openssl.h>
 
19
#endif
 
20
 
 
21
namespace {
 
22
 
 
23
std::string help_text(const std::string& spec)
 
24
   {
 
25
   std::ostringstream err;
 
26
 
 
27
   err << "Usage: " << spec << "\n\n"
 
28
       << "Available test suites\n"
 
29
       << "----------------\n";
 
30
 
 
31
   size_t line_len = 0;
 
32
 
 
33
   for(auto const& test : Botan_Tests::Test::registered_tests())
 
34
      {
 
35
      err << test << " ";
 
36
      line_len += test.size() + 1;
 
37
 
 
38
      if(line_len > 64)
 
39
         {
 
40
         err << "\n";
 
41
         line_len = 0;
 
42
         }
 
43
      }
 
44
 
 
45
   if(line_len > 0)
 
46
      {
 
47
      err << "\n";
 
48
      }
 
49
 
 
50
   return err.str();
 
51
   }
 
52
 
 
53
}
 
54
 
 
55
int main(int argc, char* argv[])
 
56
   {
 
57
   std::cerr << Botan::runtime_version_check(BOTAN_VERSION_MAJOR, BOTAN_VERSION_MINOR, BOTAN_VERSION_PATCH);
 
58
 
 
59
   try
 
60
      {
 
61
      const std::string arg_spec =
 
62
         "botan-test --data-dir= --pkcs11-lib= --provider= --log-success "
 
63
         "--verbose --help --run-long-tests --run-online-tests --test-runs=1 --drbg-seed= "
 
64
         "*suites";
 
65
 
 
66
      Botan_CLI::Argument_Parser parser(arg_spec);
 
67
 
 
68
      parser.parse_args(std::vector<std::string>(argv + 1, argv + argc));
 
69
 
 
70
      if(parser.flag_set("help"))
 
71
         {
 
72
         std::cout << help_text(arg_spec);
 
73
         return 0;
 
74
         }
 
75
 
 
76
      const std::string data_dir = parser.get_arg_or("data-dir", "src/tests/data");
 
77
      const std::string pkcs11_lib = parser.get_arg("pkcs11-lib");
 
78
      const std::string provider = parser.get_arg("provider");
 
79
      const std::string drbg_seed = parser.get_arg("drbg-seed");
 
80
 
 
81
      const bool log_success = parser.flag_set("log-success");
 
82
      const bool run_long_tests = parser.flag_set("run-long-tests");
 
83
      const bool run_online_tests = parser.flag_set("run-online-tests");
 
84
      const size_t test_runs = parser.get_arg_sz("test-runs");
 
85
 
 
86
      const std::vector<std::string> suites = parser.get_arg_list("suites");
 
87
 
 
88
#if defined(BOTAN_HAS_OPENSSL)
 
89
      if(provider.empty() || provider == "openssl")
 
90
         {
 
91
         ::ERR_load_crypto_strings();
 
92
         }
 
93
#endif
 
94
 
 
95
      Botan_Tests::Test_Runner tests(std::cout);
 
96
 
 
97
      return tests.run(suites, data_dir, pkcs11_lib, provider,
 
98
                       log_success, run_online_tests, run_long_tests,
 
99
                       drbg_seed, test_runs);
 
100
      }
 
101
   catch(std::exception& e)
 
102
      {
 
103
      std::cerr << "Exiting with error: " << e.what() << std::endl;
 
104
      }
 
105
   catch(...)
 
106
      {
 
107
      std::cerr << "Exiting with unknown exception" << std::endl;
 
108
      }
 
109
   return 2;
 
110
   }