Path: blob/main/contrib/kyua/drivers/debug_test.cpp
39478 views
// Copyright 2011 The Kyua Authors.1// All rights reserved.2//3// Redistribution and use in source and binary forms, with or without4// modification, are permitted provided that the following conditions are5// met:6//7// * Redistributions of source code must retain the above copyright8// notice, this list of conditions and the following disclaimer.9// * Redistributions in binary form must reproduce the above copyright10// notice, this list of conditions and the following disclaimer in the11// documentation and/or other materials provided with the distribution.12// * Neither the name of Google Inc. nor the names of its contributors13// may be used to endorse or promote products derived from this software14// without specific prior written permission.15//16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2728#include "drivers/debug_test.hpp"2930#include <stdexcept>31#include <utility>3233#include "engine/filters.hpp"34#include "engine/kyuafile.hpp"35#include "engine/scanner.hpp"36#include "engine/scheduler.hpp"37#include "model/test_case.hpp"38#include "model/test_program.hpp"39#include "model/test_result.hpp"40#include "utils/defs.hpp"41#include "utils/format/macros.hpp"42#include "utils/fs/auto_cleaners.hpp"43#include "utils/optional.ipp"4445namespace config = utils::config;46namespace fs = utils::fs;47namespace scheduler = engine::scheduler;4849using utils::optional;505152/// Executes the operation.53///54/// \param kyuafile_path The path to the Kyuafile to be loaded.55/// \param build_root If not none, path to the built test programs.56/// \param filter The test case filter to locate the test to debug.57/// \param user_config The end-user configuration properties.58/// \param stdout_path The name of the file into which to store the test case59/// stdout.60/// \param stderr_path The name of the file into which to store the test case61/// stderr.62///63/// \returns A structure with all results computed by this driver.64drivers::debug_test::result65drivers::debug_test::drive(engine::debugger_ptr debugger,66const fs::path& kyuafile_path,67const optional< fs::path > build_root,68const engine::test_filter& filter,69const config::tree& user_config,70const fs::path& stdout_path,71const fs::path& stderr_path)72{73scheduler::scheduler_handle handle = scheduler::setup();7475const engine::kyuafile kyuafile = engine::kyuafile::load(76kyuafile_path, build_root, user_config, handle);77std::set< engine::test_filter > filters;78filters.insert(filter);7980engine::scanner scanner(kyuafile.test_programs(), filters);81optional< engine::scan_result > match;82while (!match && !scanner.done()) {83match = scanner.yield();84}85if (!match) {86throw std::runtime_error(F("Unknown test case '%s'") % filter.str());87} else if (!scanner.done()) {88throw std::runtime_error(F("The filter '%s' matches more than one test "89"case") % filter.str());90}91INV(match && scanner.done());92const model::test_program_ptr test_program = match.get().first;93const std::string& test_case_name = match.get().second;9495const model::test_case test_case = test_program->find(test_case_name);96if (debugger)97test_case.attach_debugger(debugger);9899scheduler::result_handle_ptr result_handle = handle.debug_test(100test_program, test_case_name, user_config,101stdout_path, stderr_path);102const scheduler::test_result_handle* test_result_handle =103dynamic_cast< const scheduler::test_result_handle* >(104result_handle.get());105const model::test_result test_result = test_result_handle->test_result();106result_handle->cleanup();107108handle.check_interrupt();109handle.cleanup();110111return result(engine::test_filter(112test_program->relative_path(), test_case_name), test_result);113}114115116