/*
 * Copyright (c) 2023 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
#include <cstdlib>
#include <gtest/gtest.h>
#include <mc/log.h>

// Flush gcov coverage data before quick_exit, since quick_exit does not call
// atexit handlers where gcov normally flushes.
// HAS_GCOV is defined by meson when enable_coverage=true.
#ifdef HAS_GCOV
extern "C" void __gcov_dump(void);
#endif

int main(int argc, char** argv)
{
    testing::InitGoogleTest(&argc, argv);

    // // 初始化日志系统
    // mc::log::Logger::getInstance()
    //     .setAppender<mc::log::ConsoleAppender>()
    //     .setLevel(mc::log::Level::Debug);

    std::cout << "Running devmon tests..." << std::endl;
    std::cout << "Tests will validate device drivers and manager functionality." << std::endl;

    int result = RUN_ALL_TESTS();

#ifdef HAS_GCOV
    __gcov_dump();
#endif

    // 各 TEST 套件的 TearDownTestSuite 已释放 runtime/engine/DBus 等资源。
    // 仍使用 quick_exit:从 main return 会跑全局/静态析构,当前与第三方及 libmcpp
    // 初始化顺序组合下可能在进程退出阶段崩溃,导致 Lua 包装器里 os.execute 得到 nil。
    std::quick_exit(result);
}