summaryrefslogtreecommitdiffstats
path: root/test/physical.cpp
Commit message (Collapse)AuthorAgeFilesLines
* test: physical: Cover trigger:timer branch in setInitialState()Andrew Jeffery2019-04-081-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The test causes execution to take the following path in setInitialState(), previously outlined in 264d909d3dc9 ("test: Add tests for Physical class") as being missed: auto trigger = led.getTrigger(); if (trigger == "timer") { // LED is blinking. Get the delay_on and delay_off and compute // DutyCycle. sfsfs values are in strings. Need to convert 'em over to // integer. auto delayOn = led.getDelayOn(); auto delayOff = led.getDelayOff(); // Calculate frequency and then percentage ON frequency = delayOn + delayOff; auto factor = frequency / 100; auto dutyOn = delayOn / factor; // Update. this->dutyOn(dutyOn); } This brings the line coverage to 96.6% (function coverage remains unchanged by this patch). Change-Id: Ie311186f6275d3fdd31de5698c7c14bb335128e1 Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
* test: physical: Introduce LED mocksAndrew Jeffery2019-04-081-5/+70
| | | | | | | | | | | | This removes the dependency on touching the filesystem entirely. All methods are now mocked into an ignored state when called by the NiceMock template class. The filesystem is only touched by the SysfsLed tests, though we still need to provide a temporary path to its constructor in the decended mock class to ensure we're isolated if something does manage to get written. Change-Id: I3955a6e0fb5c3c42887da847239d381ef151fa3e Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
* sysfs: Integrate class into Physical and testsAndrew Jeffery2019-04-081-7/+12
| | | | | Change-Id: I7d5ad19df5ef1258a4e669ea3243b7411f371d9c Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
* test: Add tests for Physical classAndrew Jeffery2019-03-181-0/+37
The additions to configure expose a new `check-code-coverage` make target when `--enable-code-coverage` is passed to `./configure`. Assuming gcov/lcov are installed, `make check-code-coverage` will run the test suite and generate an HTML line/function/branch coverage report that enables measurement of the effectiveness of the test suite. The tests themselves are trivial (integration) tests that get us to 78.8% line coverage and 93.3% function coverage over physical.hpp and physical.cpp. However, as we don't have the read() and write() functions under our control - and as they're implemented to return empty strings when the target files do not exist - this high level of coverage is more by luck than design. To demonstrate, under the current test arrangement, we can never enter this branch of setInitialState(): auto trigger = read<std::string>(blinkCtrl); if (trigger == "timer") { // LED is blinking. Get the delay_on and delay_off and compute // DutyCycle. sfsfs values are in strings. Need to convert 'em over to // integer. auto delayOn = std::stoi(read<std::string>(delayOnCtrl)); auto delayOff = std::stoi(read<std::string>(delayOffCtrl)); // Calculate frequency and then percentage ON frequency = delayOn + delayOff; auto factor = frequency / 100; auto dutyOn = delayOn / factor; // Update. this->dutyOn(dutyOn); } For similar reasons, we also fail to enter: auto brightness = read<std::string>(brightCtrl); if (brightness == std::string(ASSERT)) { // LED is in Solid ON sdbusplus::xyz::openbmc_project::Led::server ::Physical::state( Action::On); } To test both of these paths we need to make changes to isolate functionality so we can manipulate the read() call to return the necessary strings at the appropriate times, but that is for a future change. Change-Id: I0df2ab2d992ccad514cddb7f7fc6d080aa74f27d Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
OpenPOWER on IntegriCloud