|
27 | 27 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 | 28 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
|
30 | | -# pylint: disable=redefined-outer-name,unused-argument,unused-import,no-self-use |
| 30 | +# pylint: disable=redefined-outer-name,unused-argument,unused-import |
31 | 31 | import time |
32 | 32 | from datetime import datetime |
| 33 | +from multiprocessing import active_children |
33 | 34 |
|
34 | 35 | import pymongo |
35 | 36 | import pytest |
36 | 37 |
|
37 | | -from powerapi.test_utils.db.mongo import MONGO_URI, MONGO_DATABASE_NAME, MONGO_INPUT_COLLECTION_NAME, \ |
38 | | - MONGO_OUTPUT_COLLECTION_NAME |
| 38 | +from tests.utils.db.mongo import MONGO_URI, MONGO_DATABASE_NAME, MONGO_INPUT_COLLECTION_NAME, \ |
| 39 | + MONGO_OUTPUT_COLLECTION_NAME, gen_base_db_test, clean_base_db_test |
39 | 40 |
|
40 | 41 | from smartwatts.__main__ import run_smartwatts |
41 | 42 |
|
|
44 | 45 | SENSOR_NAME = 'cpu' |
45 | 46 |
|
46 | 47 |
|
47 | | -@pytest.fixture |
48 | | -def formula_config(): |
49 | | - """ |
50 | | - Return a formula config |
51 | | - :return: The formula config |
52 | | - """ |
53 | | - return {'verbose': 0, |
54 | | - 'stream': False, |
55 | | - 'input': {'puller_mongodb': {'type': 'mongodb', |
56 | | - 'model': 'HWPCReport', |
57 | | - 'uri': MONGO_URI, |
58 | | - 'db': MONGO_DATABASE_NAME, |
59 | | - 'collection': MONGO_INPUT_COLLECTION_NAME}}, |
60 | | - 'output': {'power_pusher': {'type': 'mongodb', |
61 | | - 'model': 'PowerReport', |
62 | | - 'uri': MONGO_URI, |
63 | | - 'db': MONGO_DATABASE_NAME, |
64 | | - 'collection': MONGO_OUTPUT_COLLECTION_NAME}, |
65 | | - 'formula_pusher': {'type': 'mongodb', |
66 | | - 'model': 'FormulaReport', |
67 | | - 'uri': MONGO_URI, |
68 | | - 'db': MONGO_DATABASE_NAME, |
69 | | - 'collection': 'test_result_formula'}}, |
70 | | - 'disable-cpu-formula': False, |
71 | | - 'disable-dram-formula': True, |
72 | | - 'cpu-rapl-ref-event': 'RAPL_ENERGY_PKG', |
73 | | - 'cpu-tdp': 125, |
74 | | - 'cpu-base-clock': 100, |
75 | | - 'cpu-frequency-min': 4, |
76 | | - 'cpu-frequency-base': 19, |
77 | | - 'cpu-frequency-max': 42, |
78 | | - 'cpu-error-threshold': 2.0, |
79 | | - 'sensor-report-sampling-interval': 1000, |
80 | | - 'learn-min-samples-required': 10, |
81 | | - 'learn-history-window-size': 60, |
82 | | - 'real-time-mode': False} |
83 | | - |
84 | | - |
85 | | -@pytest.fixture |
86 | | -def formula_config_real_time_enabled(formula_config): |
87 | | - """ |
88 | | - Return a formula config with real time mode = True |
89 | | - :return: The formula config |
90 | | - """ |
91 | | - formula_config['real-time-mode'] = True |
92 | | - return formula_config |
93 | | - |
94 | | - |
95 | 48 | def check_db(): |
96 | 49 | """ |
97 | 50 | Check that the output database has the generated reports |
@@ -126,11 +79,77 @@ def check_db_real_time(): |
126 | 79 | assert c_output.count_documents(query) == 1 |
127 | 80 |
|
128 | 81 |
|
129 | | -class AbstractAcceptationTest(): |
| 82 | +class AbstractAcceptationTest: |
130 | 83 | """ |
131 | | - Basic acceptation tests for Smartwatts Formula |
| 84 | + Basic acceptation tests for SmartWatts Formula |
132 | 85 | """ |
133 | 86 |
|
| 87 | + @pytest.fixture |
| 88 | + def shutdown_system(self): |
| 89 | + """ |
| 90 | + Shutdown the actor system, i.e., all actors are killed |
| 91 | + """ |
| 92 | + yield None |
| 93 | + active = active_children() |
| 94 | + for child in active: |
| 95 | + child.kill() |
| 96 | + |
| 97 | + @pytest.fixture |
| 98 | + def mongo_database(self, mongodb_content): |
| 99 | + """ |
| 100 | + connect to a local mongo database (localhost:27017) and store data contained in the list influxdb_content |
| 101 | + after test end, delete the data |
| 102 | + """ |
| 103 | + gen_base_db_test(MONGO_URI, mongodb_content) |
| 104 | + yield None |
| 105 | + clean_base_db_test(MONGO_URI) |
| 106 | + |
| 107 | + @pytest.fixture |
| 108 | + def formula_config(self): |
| 109 | + """ |
| 110 | + Return a formula config |
| 111 | + :return: The formula config |
| 112 | + """ |
| 113 | + return {'verbose': 0, |
| 114 | + 'stream': False, |
| 115 | + 'input': {'puller_mongodb': {'type': 'mongodb', |
| 116 | + 'model': 'HWPCReport', |
| 117 | + 'uri': MONGO_URI, |
| 118 | + 'db': MONGO_DATABASE_NAME, |
| 119 | + 'collection': MONGO_INPUT_COLLECTION_NAME}}, |
| 120 | + 'output': {'power_pusher': {'type': 'mongodb', |
| 121 | + 'model': 'PowerReport', |
| 122 | + 'uri': MONGO_URI, |
| 123 | + 'db': MONGO_DATABASE_NAME, |
| 124 | + 'collection': MONGO_OUTPUT_COLLECTION_NAME}, |
| 125 | + 'formula_pusher': {'type': 'mongodb', |
| 126 | + 'model': 'FormulaReport', |
| 127 | + 'uri': MONGO_URI, |
| 128 | + 'db': MONGO_DATABASE_NAME, |
| 129 | + 'collection': 'test_result_formula'}}, |
| 130 | + 'disable-cpu-formula': False, |
| 131 | + 'disable-dram-formula': True, |
| 132 | + 'cpu-rapl-ref-event': 'RAPL_ENERGY_PKG', |
| 133 | + 'cpu-tdp': 125, |
| 134 | + 'cpu-base-clock': 100, |
| 135 | + 'cpu-frequency-min': 4, |
| 136 | + 'cpu-frequency-base': 19, |
| 137 | + 'cpu-frequency-max': 42, |
| 138 | + 'cpu-error-threshold': 2.0, |
| 139 | + 'sensor-report-sampling-interval': 1000, |
| 140 | + 'learn-min-samples-required': 10, |
| 141 | + 'learn-history-window-size': 60, |
| 142 | + 'real-time-mode': False} |
| 143 | + |
| 144 | + @pytest.fixture |
| 145 | + def formula_config_real_time_enabled(self, formula_config): |
| 146 | + """ |
| 147 | + Return a formula config with real time mode = True |
| 148 | + :return: The formula config |
| 149 | + """ |
| 150 | + formula_config['real-time-mode'] = True |
| 151 | + return formula_config |
| 152 | + |
134 | 153 | def test_normal_behaviour(self, mongo_database, formula_config, shutdown_system): |
135 | 154 | """ |
136 | 155 | Test that the formula generate the expected Power reports |
|
0 commit comments