1 // Copyright 2011 The Kyua Authors. 2 // All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions are 6 // met: 7 // 8 // * Redistributions of source code must retain the above copyright 9 // notice, this list of conditions and the following disclaimer. 10 // * Redistributions in binary form must reproduce the above copyright 11 // notice, this list of conditions and the following disclaimer in the 12 // documentation and/or other materials provided with the distribution. 13 // * Neither the name of Google Inc. nor the names of its contributors 14 // may be used to endorse or promote products derived from this software 15 // without specific prior written permission. 16 // 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29 #include "drivers/scan_results.hpp" 30 31 #include "engine/filters.hpp" 32 #include "model/context.hpp" 33 #include "model/test_case.hpp" 34 #include "model/test_program.hpp" 35 #include "store/read_backend.hpp" 36 #include "store/read_transaction.hpp" 37 #include "utils/defs.hpp" 38 39 namespace fs = utils::fs; 40 41 42 /// Pure abstract destructor. 43 drivers::scan_results::base_hooks::~base_hooks(void) 44 { 45 } 46 47 48 /// Callback executed before any operation is performed. 49 void 50 drivers::scan_results::base_hooks::begin(void) 51 { 52 } 53 54 55 /// Callback executed after all operations are performed. 56 void 57 drivers::scan_results::base_hooks::end(const result& /* r */) 58 { 59 } 60 61 62 /// Executes the operation. 63 /// 64 /// \param store_path The path to the database store. 65 /// \param raw_filters The test case filters as provided by the user. 66 /// \param hooks The hooks for this execution. 67 /// 68 /// \returns A structure with all results computed by this driver. 69 drivers::scan_results::result 70 drivers::scan_results::drive(const fs::path& store_path, 71 const std::set< engine::test_filter >& raw_filters, 72 base_hooks& hooks) 73 { 74 engine::filters_state filters(raw_filters); 75 76 store::read_backend db = store::read_backend::open_ro(store_path); 77 store::read_transaction tx = db.start_read(); 78 79 hooks.begin(); 80 81 const model::context context = tx.get_context(); 82 hooks.got_context(context); 83 84 store::results_iterator iter = tx.get_results(); 85 while (iter) { 86 // TODO(jmmv): We should be filtering at the test case level for 87 // efficiency, but that means we would need to execute more than one 88 // query on the database and our current interfaces don't support that. 89 // 90 // Reuse engine::filters_state for the time being because it is simpler 91 // and we get tracking of unmatched filters "for free". 92 const model::test_program_ptr test_program = iter.test_program(); 93 if (filters.match_test_program(test_program->relative_path())) { 94 const model::test_case& test_case = test_program->find( 95 iter.test_case_name()); 96 if (filters.match_test_case(test_program->relative_path(), 97 test_case.name())) { 98 hooks.got_result(iter); 99 } 100 } 101 ++iter; 102 } 103 104 result r(filters.unused()); 105 hooks.end(r); 106 return r; 107 } 108