1*cde5b16cSGeorge Liu# phosphor-power-sequencer testing
2*cde5b16cSGeorge Liu
3dd6c3661SShawn McCarney## Overview
4dd6c3661SShawn McCarney
5dd6c3661SShawn McCarneyThe [test](../test) directory contains automated test cases written using the
6dd6c3661SShawn McCarney[GoogleTest](https://github.com/google/googletest) framework. These tests are
7dd6c3661SShawn McCarneyrun during Continuous Integration (CI) testing.
8dd6c3661SShawn McCarney
9dd6c3661SShawn McCarneyThe goal is to write automated test cases for as much application code as
10dd6c3661SShawn McCarneypossible.
11dd6c3661SShawn McCarney
12dd6c3661SShawn McCarney## Test case conventions
13dd6c3661SShawn McCarney
14dd6c3661SShawn McCarneyEach implementation source file should have a corresponding tests file. For
15dd6c3661SShawn McCarneyexample, [rail.cpp](../src/rail.cpp) is tested by
16dd6c3661SShawn McCarney[rail_tests.cpp](../test/rail_tests.cpp).
17dd6c3661SShawn McCarney
18dd6c3661SShawn McCarneyWithin the tests file, there should be a TEST for each public method or global
19dd6c3661SShawn McCarneyscope function. For example, `Rail::isPresent()` is tested by
20dd6c3661SShawn McCarney`TEST(RailTests, IsPresent)`.
21dd6c3661SShawn McCarney
22dd6c3661SShawn McCarney## Mock framework
23dd6c3661SShawn McCarney
24dd6c3661SShawn McCarneyOne of the primary challenges with automated testing is handling external
25dd6c3661SShawn McCarneyinterfaces. The phosphor-power-sequencer application depends on the following
26dd6c3661SShawn McCarneyexternal interfaces:
27dd6c3661SShawn McCarney
28dd6c3661SShawn McCarney- D-Bus
29dd6c3661SShawn McCarney- Journal
30dd6c3661SShawn McCarney- Error logging
31dd6c3661SShawn McCarney- GPIOs
32dd6c3661SShawn McCarney- sysfs files containing PMBus information
33dd6c3661SShawn McCarney- BMC dump
34dd6c3661SShawn McCarney
35dd6c3661SShawn McCarneyThese interfaces are either not available or do not behave properly within the
36dd6c3661SShawn McCarneyCI test environment. Thus, in automated test cases they need to be mocked.
37dd6c3661SShawn McCarney
38dd6c3661SShawn McCarneyThe GoogleTest mock framework is used to implement mocking. This allows the
39dd6c3661SShawn McCarneybehavior of the external interface to be simulated and controlled within the
40dd6c3661SShawn McCarneytest case.
41dd6c3661SShawn McCarney
42dd6c3661SShawn McCarneyThe mock framework typically relies on a class hierarchy of the following form:
43dd6c3661SShawn McCarney
44dd6c3661SShawn McCarney- Abstract base class with virtual methods for external interfaces
45dd6c3661SShawn McCarney  - Concrete sub-class with real implementation of virtual methods that call
46dd6c3661SShawn McCarney    actual external interfaces
47dd6c3661SShawn McCarney  - Mock sub-class that provides mock implementation of virtual methods
48dd6c3661SShawn McCarney
49dd6c3661SShawn McCarneyThe phosphor-power-sequencer application follows this pattern using the
50dd6c3661SShawn McCarneyfollowing classes:
51dd6c3661SShawn McCarney
52dd6c3661SShawn McCarney- [Services](../src/services.hpp)
53dd6c3661SShawn McCarney  - [BMCServices](../src/services.hpp)
54dd6c3661SShawn McCarney  - [MockServices](../test/mock_services.hpp)
55