1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 *     Copyright 2016 Couchbase, Inc
4 *
5 *   Licensed under the Apache License, Version 2.0 (the "License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 */
17
18/*
19 * Main function & globals for the ep_unit_test target.
20 */
21
22#include "programs/engine_testapp/mock_server.h"
23
24#include <getopt.h>
25#include <gmock/gmock.h>
26#include <logger/logger.h>
27
28#include "configuration.h"
29#include "ep_time.h"
30#include "hash_table.h"
31#include "logger.h"
32
33/* static storage for environment variable set by putenv(). */
34static char allow_no_stats_env[] = "ALLOW_NO_STATS_UPDATE=yeah";
35
36
37int main(int argc, char **argv) {
38    bool log_to_stderr = false;
39    // Parse command-line options.
40    int cmd;
41    bool invalid_argument = false;
42    while (!invalid_argument &&
43           (cmd = getopt(argc, argv, "v")) != EOF) {
44        switch (cmd) {
45        case 'v':
46            log_to_stderr = true;
47            break;
48        default:
49            std::cerr << "Usage: " << argv[0] << " [-v] [gtest_options...]" << std::endl
50                      << std::endl
51                      << "  -v Verbose - Print verbose output to stderr."
52                      << std::endl << std::endl;
53            invalid_argument = true;
54            break;
55        }
56    }
57
58    putenv(allow_no_stats_env);
59
60    cb::logger::createBlackholeLogger();
61    mock_init_alloc_hooks();
62    init_mock_server(log_to_stderr);
63
64    get_mock_server_api()->log->set_level(EXTENSION_LOG_DEBUG);
65    Logger::setLoggerAPI(get_mock_server_api()->log);
66
67    // Need to initialize ep_real_time and friends.
68    initialize_time_functions(get_mock_server_api()->core);
69
70    ::testing::InitGoogleMock(&argc, argv);
71    return RUN_ALL_TESTS();
72}
73