blob: 844ee36200647c90b68079712cad89014422d620 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#define BOOST_TEST_ALTERNATIVE_INIT_API
25
26#include "Globals.h"
27#include "TensorLibrary.h"
28#include "Utils.h"
29#include "ValidationProgramOptions.h"
30#include "ValidationUserConfiguration.h"
31
32#include "arm_compute/runtime/Scheduler.h"
33
34#include "boost_wrapper.h"
35
36#include <iostream>
37#include <memory>
38#include <random>
39
40using namespace arm_compute::test;
41using namespace arm_compute::test::validation;
42
43namespace arm_compute
44{
45namespace test
46{
47ValidationUserConfiguration user_config;
48std::unique_ptr<TensorLibrary> library;
49} // namespace test
50} // namespace arm_compute
51
52struct GlobalFixture
53{
54 GlobalFixture()
55 {
56 if(user_config.seed.is_set())
57 {
58 library = cpp14::make_unique<TensorLibrary>(user_config.path.get(), user_config.seed);
59 }
60 else
61 {
62 library = cpp14::make_unique<TensorLibrary>(user_config.path.get());
63 }
64
65 BOOST_TEST_MESSAGE("Seed: " << library->seed());
66 }
67};
68
69BOOST_GLOBAL_FIXTURE(GlobalFixture);
70
71bool init_unit_test()
72{
73 boost::unit_test::framework::master_test_suite().p_name.value = "Compute Library Validation Tests";
74
75 ValidationProgramOptions options;
76
77 int &argc = boost::unit_test::framework::master_test_suite().argc;
78 char **argv = boost::unit_test::framework::master_test_suite().argv;
79
80 try
81 {
82 options.parse_commandline(argc, argv);
83
84 if(options.wants_help())
85 {
86 std::cout << "Usage: " << argv[0] << " [options] PATH\n";
87 std::cout << options.get_help() << "\n";
88 return false;
89 }
90
91 user_config = ValidationUserConfiguration(options);
92 }
93 catch(const boost::program_options::required_option &err)
94 {
95 std::cerr << "Error: " << err.what() << "\n";
96 std::cout << "\nUsage: " << argv[0] << " [options] PATH\n";
97 std::cout << options.get_help() << "\n";
98 return false;
99 }
100
101 std::cout << "Using " << user_config.threads << " CPU " << (user_config.threads == 1 ? "thread" : "threads") << "\n";
102 arm_compute::Scheduler::get().set_num_threads(user_config.threads);
103 return true;
104}