Home | History | Annotate | Download | only in functional-tests
      1 /*
      2  * Copyright (c) 2015, Intel Corporation
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without modification,
      6  * are permitted provided that the following conditions are met:
      7  *
      8  * 1. Redistributions of source code must retain the above copyright notice, this
      9  * list of conditions and the following disclaimer.
     10  *
     11  * 2. Redistributions in binary form must reproduce the above copyright notice,
     12  * this list of conditions and the following disclaimer in the documentation and/or
     13  * other materials provided with the distribution.
     14  *
     15  * 3. Neither the name of the copyright holder nor the names of its contributors
     16  * may be used to endorse or promote products derived from this software without
     17  * specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
     23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
     26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #include "Test.hpp"
     32 #include "Config.hpp"
     33 #include "StoreLogger.hpp"
     34 #include "ParameterFramework.hpp"
     35 
     36 #include <catch.hpp>
     37 
     38 #include <list>
     39 #include <string>
     40 
     41 #include <cstdio>
     42 
     43 namespace parameterFramework
     44 {
     45 
     46 SCENARIO_METHOD(ParameterFramework, "Default logger", "[log]")
     47 {
     48     WHEN ("No logger is set") {
     49         THEN ("Start should succeed") {
     50             CHECK_NOTHROW(start());
     51         }
     52     }
     53 }
     54 
     55 SCENARIO_METHOD(ParameterFramework, "No Logger", "[log]")
     56 {
     57     WHEN ("A nullptr logger is set") {
     58         setLogger(nullptr);
     59         THEN ("Start should succeed") {
     60             CHECK_NOTHROW(start());
     61         }
     62     }
     63 }
     64 
     65 SCENARIO("Logger should receive info and warnings", "[log]")
     66 {
     67     GIVEN ("A logger that stores logs") {
     68         /* Instantiating logger first to ensure that its lifetime is longer than the pfw's one,
     69          * because the pfw references the logger. */
     70         StoreLogger logger{};
     71         GIVEN ("A parameter framework") {
     72             WarningPF pfw;
     73             GIVEN ("Config files that emit warnings") {
     74                 WHEN ("The record logger is set") {
     75                     pfw.setLogger(&logger);
     76                     THEN ("Start should succeed") {
     77                         REQUIRE_NOTHROW(pfw.start());
     78                         AND_THEN ("The logger should have stored info and warning log") {
     79                             using Logs = StoreLogger::Logs;
     80                             using Level = StoreLogger::Log::Level;
     81                             CHECK(logger.filter(Level::warning) != Logs{});
     82                             CHECK(logger.getLogs() != Logs{});
     83                         }
     84                     }
     85                     AND_WHEN ("A nullptr logger is set") {
     86                         pfw.setLogger(nullptr);
     87                         THEN ("Start should succeed") {
     88                             REQUIRE_NOTHROW(pfw.start());
     89                             AND_THEN ("The record logger should NOT have stored any info or "
     90                                       "warning log") {
     91                                 CHECK(logger.getLogs() == StoreLogger::Logs{});
     92                             }
     93                         }
     94                     }
     95                 }
     96             }
     97         }
     98     }
     99 }
    100 
    101 SCENARIO_METHOD(LazyPF, "Tuning OK", "[properties][remote interface]")
    102 {
    103 }
    104 
    105 SCENARIO_METHOD(LazyPF, "Invalid XML configuration")
    106 {
    107     for (auto &xmlT : Tests<std::string>{{"an unknown tag", "<unknown_tag/>"},
    108                                          {"an unclosed tag", "<unclosed>"}}) {
    109         auto invalidXml = xmlT.payload;
    110         GIVEN ("An invalid xml: containing " + xmlT.title) {
    111             Config::Plugins ps{};
    112             for (auto &&configT : Tests<Config>{
    113                      {"top config", {&Config::plugins, Config::Plugins{{"", {invalidXml}}}}},
    114                      {"structure", {&Config::instances, invalidXml}},
    115                      {"settings", {&Config::domains, invalidXml}}}) {
    116                 WHEN ("Used in the " + configT.title) {
    117                     create(std::move(configT.payload));
    118                     THEN ("Start should fail") {
    119                         CHECK_THROWS_AS(mPf->start(), Exception);
    120                     }
    121                 }
    122             }
    123         }
    124     }
    125 }
    126 
    127 SCENARIO_METHOD(LazyPF, "Plugin OK", "[properties][missing plugin policy]")
    128 {
    129     for (auto &pluginNameT :
    130          Tests<std::string>{{"an non existing plugin", "libdonetexist.so"},
    131                             {"an existing library but invalid (linux) PF plugin", "libc.so.6"}}) {
    132         GIVEN ("An" + pluginNameT.title) {
    133             create({&Config::plugins, Config::Plugins{{"", {pluginNameT.payload}}}});
    134             WHEN ("The missing subsystem policy is left to default") {
    135                 THEN ("Start should fail") {
    136                     CHECK_THROWS_AS(mPf->start(), Exception);
    137                 }
    138             }
    139             WHEN ("The missing subsystem policy is set to failure") {
    140                 mPf->setFailureOnMissingSubsystem(true);
    141                 THEN ("Start should fail") {
    142                     CHECK_THROWS_AS(mPf->start(), Exception);
    143                 }
    144             }
    145             WHEN ("The missing subsystem policy is set to ignore") {
    146                 mPf->setFailureOnMissingSubsystem(false);
    147                 THEN ("Start should success") {
    148                     CHECK_NOTHROW(mPf->start());
    149                 }
    150             }
    151         }
    152     }
    153 }
    154 
    155 SCENARIO_METHOD(LazyPF, "Invalid domains", "[properties]")
    156 {
    157     GIVEN ("An invalid domain file") {
    158         create({&Config::domains, "<Domain name='Invalid'/>"});
    159         THEN ("Start should fail") {
    160             CHECK_THROWS_AS(mPf->start(), Exception);
    161         }
    162         WHEN ("Changing failure setting load policy to ignore") {
    163             mPf->setFailureOnFailedSettingsLoad(false);
    164             THEN ("Start should succeed") {
    165                 CHECK_NOTHROW(mPf->start());
    166             }
    167         }
    168     }
    169 }
    170 
    171 SCENARIO_METHOD(ParameterFramework, "Raw value space")
    172 {
    173     WHEN ("Raw value space is set") {
    174         setRawValueSpace(true);
    175         THEN ("Value space should be raw") {
    176             CHECK(isValueSpaceRaw() == true);
    177         }
    178     }
    179 }
    180 
    181 } // parameterFramework
    182