def test_handle_hwpc_report_with_one_rapl_event(state): """ handle a HWPC report with a simple RAPL event The HWPC report contain only one RAPL event and no other groups The handle method must return a PowerReport containing only the RAPL event """ raw_power = 10 socket_id = '1' rapl_event_id = 'RAPL_1' hwpc_report = create_report_root([ create_group_report('rapl', [ create_socket_report( socket_id, [create_core_report('1', rapl_event_id, raw_power)]) ]) ]) validation_report = PowerReport(hwpc_report.timestamp, hwpc_report.sensor, hwpc_report.target, math.ldexp(raw_power, -32), { 'socket': socket_id, 'event': rapl_event_id }) result = RAPLHandler(state)._estimate(hwpc_report) assert [validation_report] == result
def test_pusher_start_handler(self): """ Test the StartHandler of PusherActor """ # Define PusherState fake_database = get_fake_db() fake_socket_interface = get_fake_socket_interface() pusher_state = PusherState(Actor._initial_behaviour, fake_socket_interface, fake_database, mock.Mock()) assert pusher_state.initialized is False # Define StartHandler start_handler = PusherStartHandler() # Test Random message when state is not initialized to_send = [OKMessage(), ErrorMessage("Error"), create_report_root({})] for msg in to_send: start_handler.handle(msg, pusher_state) assert fake_database.method_calls == [] assert fake_socket_interface.method_calls == [] assert pusher_state.initialized is False # Try to initialize the state start_handler.handle(StartMessage(), pusher_state) assert pusher_state.initialized is True
def test_puller_start_handler(self): """ Test the StartHandler of PullerActor """ # Define PullerState fake_database = get_fake_db() fake_socket_interface = get_fake_socket_interface() fake_filter = get_fake_filter() puller_state = PullerState(Mock(), fake_database, fake_filter, HWPCModel(), False, 100) puller_state.actor.receive_control = Mock(return_value=None) assert puller_state.initialized is False # Define StartHandler start_handler = PullerStartHandler(puller_state, 0.1) # Test Random message when state is not initialized to_send = [OKMessage(), ErrorMessage("Error"), create_report_root({})] for msg in to_send: start_handler.handle(msg) assert fake_database.method_calls == [] assert fake_socket_interface.method_calls == [] assert fake_filter.method_calls == [] assert puller_state.initialized is False # Try to initialize the state start_handler.handle(StartMessage()) assert puller_state.initialized is True
def test_handle_hwpc_report_with_two_rapl_event_and_other_groups(state): """ handle a HWPC report with two RAPL events and events from other groups The HWPC report contain two RAPL events and events from a group 'sys' with two cores The handle method must return two PowerReport containing each RAPL event """ socket_id = '1' raw_power_1 = 10 rapl_event_id_1 = 'RAPL_1' raw_power_2 = 20 rapl_event_id_2 = 'RAPL_2' events = {rapl_event_id_1: raw_power_1, rapl_event_id_2: raw_power_2} hwpc_report = create_report_root([ create_group_report('rapl', [ create_socket_report( socket_id, [create_core_report('1', None, None, events=events)]) ]), create_group_report('sys', [ create_socket_report(socket_id, [ create_core_report('1', 'e0', 0), create_core_report('2', 'e0', 0) ]) ]) ]) validation_report_1 = PowerReport(hwpc_report.timestamp, hwpc_report.sensor, hwpc_report.target, math.ldexp(raw_power_1, -32), { 'socket': socket_id, 'event': rapl_event_id_1 }) validation_report_2 = PowerReport(hwpc_report.timestamp, hwpc_report.sensor, hwpc_report.target, math.ldexp(raw_power_2, -32), { 'socket': socket_id, 'event': rapl_event_id_2 }) result = RAPLFormulaHWPCReportHandler(get_fake_pusher())._process_report( hwpc_report, state) assert len(result) == 2 assert validation_report_1 in result assert validation_report_2 in result
def test_pusher_power_handler(self): """ Test the PowerHandler of PusherActor """ # Define PusherState fake_database = get_fake_db() fake_socket_interface = get_fake_socket_interface() pusher_state = PusherState(Actor._initial_behaviour, fake_socket_interface, fake_database, mock.Mock()) assert pusher_state.initialized is False # Define PowerHandler power_handler = PowerHandler() # Test Random message when state is not initialized to_send = [OKMessage(), ErrorMessage("Error"), create_report_root({})] for msg in to_send: power_handler.handle(msg, pusher_state) assert pusher_state.database.method_calls == [] assert pusher_state.initialized is False pusher_state.initialized = True # Test Random message when state is initialized to_send = [OKMessage(), ErrorMessage("Error"), create_report_root({})] for msg in to_send: power_handler.handle(msg, pusher_state) assert pusher_state.database.method_calls == [] # Test with a PowerMessage for _ in range(101): power_handler.handle( PowerReport("10", "test", "test", "test", "test"), pusher_state) assert len(pusher_state.buffer) == 101
def test_handle_hwpc_report_with_two_rapl_event(state): """ handle a HWPC report with two RAPL events The HWPC report contain only two RAPL events and no other groups The handle method must return two PowerReport containing each RAPL event """ socket_id = '1' raw_power_1 = 10 rapl_event_id_1 = 'RAPL_1' raw_power_2 = 20 rapl_event_id_2 = 'RAPL_2' events = {rapl_event_id_1: raw_power_1, rapl_event_id_2: raw_power_2} hwpc_report = create_report_root([ create_group_report('rapl', [ create_socket_report( socket_id, [create_core_report('1', None, None, events=events)]) ]) ]) validation_report_1 = PowerReport(hwpc_report.timestamp, hwpc_report.sensor, hwpc_report.target, math.ldexp(raw_power_1, -32), { 'socket': socket_id, 'event': rapl_event_id_1 }) validation_report_2 = PowerReport(hwpc_report.timestamp, hwpc_report.sensor, hwpc_report.target, math.ldexp(raw_power_2, -32), { 'socket': socket_id, 'event': rapl_event_id_2 }) result = RAPLHandler(state)._estimate(hwpc_report) assert len(result) == 2 assert validation_report_1 in result assert validation_report_2 in result
def gen_hwpc_report(): """ Return a well formated HWPCReport """ cpua0 = create_core_report('1', 'e0', '0') cpub0 = create_core_report('2', 'e0', '1') cpuc0 = create_core_report('3', 'e0', '2') cpud0 = create_core_report('4', 'e0', '3') cpua1 = create_core_report('1', 'e1', '0') cpub1 = create_core_report('2', 'e1', '1') cpuc1 = create_core_report('3', 'e1', '2') cpud1 = create_core_report('4', 'e1', '3') socketa0 = create_socket_report('1', [cpua0, cpub0]) socketb0 = create_socket_report('2', [cpuc0, cpud0]) socketa1 = create_socket_report('1', [cpua1, cpub1]) socketb1 = create_socket_report('2', [cpuc1, cpud1]) groupa = create_group_report('group1', [socketa0, socketb0]) groupb = create_group_report('group2', [socketa1, socketb1]) return create_report_root([groupa, groupb])
def gen_hwpc_report(): """ Return a well formated HWPCReport """ cpua = create_core_report('1', 'e0', '0') cpub = create_core_report('2', 'e0', '1') cpuc = create_core_report('1', 'e0', '2') cpud = create_core_report('2', 'e0', '3') cpue = create_core_report('1', 'e1', '0') cpuf = create_core_report('2', 'e1', '1') cpug = create_core_report('1', 'e1', '2') cpuh = create_core_report('2', 'e1', '3') socketa = create_socket_report('1', [cpua, cpub]) socketb = create_socket_report('2', [cpuc, cpud]) socketc = create_socket_report('1', [cpue, cpuf]) socketd = create_socket_report('2', [cpug, cpuh]) groupa = create_group_report('1', [socketa, socketb]) groupb = create_group_report('2', [socketc, socketd]) return create_report_root([groupa, groupb])
def test_handle_hwpc_report_with_one_rapl_event_and_other_groups(state): """ handle a HWPC report with a simple RAPL event and events from other groups The HWPC report contain one RAPL event and events from a group 'sys' with two cores The handle method must return a PowerReport containing only the RAPL event """ raw_power = 10 socket_id = '1' rapl_event_id = 'RAPL_1' hwpc_report = create_report_root([ create_group_report('rapl', [ create_socket_report( socket_id, [create_core_report('1', rapl_event_id, raw_power)]) ]), create_group_report('sys', [ create_socket_report(socket_id, [ create_core_report('1', 'e0', 0), create_core_report('2', 'e0', 0) ]) ]) ]) validation_report = PowerReport(hwpc_report.timestamp, hwpc_report.sensor, hwpc_report.target, math.ldexp(raw_power, -32), { 'socket': socket_id, 'event': rapl_event_id }) result = RAPLFormulaHWPCReportHandler(get_fake_pusher())._process_report( hwpc_report, state) assert [validation_report] == result
def test_pusher_power_handler(self): """ Test the ReportHandler of PusherActor """ # Define PusherState fake_database = get_fake_db() fake_socket_interface = get_fake_socket_interface() pusher_state = PusherState(Mock(), fake_database, HWPCModel()) pusher_state.actor.socket_interface = fake_socket_interface assert pusher_state.initialized is False # Define PowerHandler power_handler = ReportHandler(pusher_state) # Test Random message when state is not initialized to_send = [OKMessage(), ErrorMessage("Error"), create_report_root({})] for msg in to_send: power_handler.handle_message(msg) assert pusher_state.database.method_calls == [] assert pusher_state.initialized is False pusher_state.initialized = True
def test_without_filter(self): """ Test filter without any filter, raise an error """ hwpc_filter = Filter() with pytest.raises(FilterUselessError) as pytest_wrapped: hwpc_filter.route(create_report_root({})) assert pytest_wrapped.type == FilterUselessError