def test_measure_rapl_device_all_domains(_mocked_perf_counter, fs_pkg_dram_one_socket, one_gpu_api): domains = [RaplPackageDomain(0), RaplDramDomain(0), NvidiaGPUDomain(0)] correct_trace = CorrectTrace(domains, [fs_pkg_dram_one_socket, one_gpu_api], TIMESTAMP_TRACE) # test rapl = RaplDevice() rapl.configure(domains=[RaplPackageDomain(0), RaplDramDomain(0)]) nvidia = NvidiaGPUDevice() nvidia.configure(domains=[NvidiaGPUDomain(0)]) meter = EnergyMeter([rapl, nvidia]) correct_trace.add_new_sample('foo') # test meter.start(tag="foo") correct_trace.add_new_sample('bar') # test meter.record(tag="bar") correct_trace.add_new_sample('') # test meter.stop() for sample1, sample2 in zip(correct_trace, meter): # test assert_sample_are_equals(sample1, sample2) # test
def test_create_devices_to_monitor_gpu0_and_package_0_machine_with_two_gpu_and_package_dram_api_create_one_nvidia_gpu_device_and_rapl_device_configured_for_package( two_gpu_api, fs_pkg_dram_one_socket): devices = EnergyDeviceFactory.create_devices( [RaplPackageDomain(0), NvidiaGPUDomain(0)]) assert len(devices) == 2 assert isinstance(devices[1], NvidiaGPUDevice) assert devices[1].get_configured_domains() == [NvidiaGPUDomain(0)] assert isinstance(devices[0], RaplDevice) assert devices[0].get_configured_domains() == [RaplPackageDomain(0)]
def test_get_package_dram_energy_with_pkg_dram_rapl_api_two_sockets_return_correct_value(fs_pkg_dram_two_socket): """ Create a RaplDevice instance on a machine with package and dram rapl api with on two socket configure it to monitor package and dram domains use the `get_energy` method and check if: - the returned list contains 4 elements - these elements are the power consumption of the package and dram on socket 0 and socket 1 """ device = RaplDevice() device.configure([RaplPackageDomain(0), RaplDramDomain(0), RaplPackageDomain(1), RaplDramDomain(1)]) assert device.get_energy() == [fs_pkg_dram_two_socket.domains_current_energy['package_0'], fs_pkg_dram_two_socket.domains_current_energy['dram_0'], fs_pkg_dram_two_socket.domains_current_energy['package_1'], fs_pkg_dram_two_socket.domains_current_energy['dram_1']]
def test_create_devices_with_rapl_package_and_dram_domains_return_one_correctly_configured_rapl_device( fs_pkg_dram_one_socket): domains = [RaplPackageDomain(0), RaplDramDomain(0)] devices = EnergyDeviceFactory.create_devices(domains) assert len(devices) == 1 assert isinstance(devices[0], RaplDevice) assert devices[0].get_configured_domains() == domains
def test_create_devices_with_default_values_on_machine_with_one_gpu_and_package_api_create_one_nvidia_gpu_device_and_rapl_device_configured_for_package( one_gpu_api, fs_pkg_one_socket): devices = EnergyDeviceFactory.create_devices() assert len(devices) == 2 assert isinstance(devices[1], NvidiaGPUDevice) assert devices[1].get_configured_domains() == [NvidiaGPUDomain(0)] assert isinstance(devices[0], RaplDevice) assert devices[0].get_configured_domains() == [RaplPackageDomain(0)]
def test_create_devices_with_default_values_on_machine_with_only_rapl_pkg_and_dram_api_create_one_device_configured_for_dram_and_rapl( fs_pkg_dram_one_socket): devices = EnergyDeviceFactory.create_devices() assert len(devices) == 1 assert isinstance(devices[0], RaplDevice) assert devices[0].get_configured_domains() == [ RaplPackageDomain(0), RaplDramDomain(0) ]
def test_get_package_energy_with_only_pkg_rapl_api_return_correct_value(fs_pkg_one_socket): """ Create a RaplDevice instance on a machine with package rapl api with on one socket configure it to monitor package domain use the `get_energy` method and check if: - the returned list contains one element - this element is the power consumption of the package on socket 0 """ device = RaplDevice() device.configure([RaplPackageDomain(0)]) assert device.get_energy() == [fs_pkg_one_socket.domains_current_energy['package_0']]
def test_get_dram_package_energy_with_pkg_dram_rapl_api_return_correct_values_in_correct_order(fs_pkg_dram_one_socket): """ Create a RaplDevice instance on a machine with package and dram rapl api with on one socket configure it to monitor dram and package domains use the `get_energy` method and check if: - the returned list contains two elements - these elements are the power consumption of the dram and package on socket 0 """ device = RaplDevice() device.configure([RaplDramDomain(0), RaplPackageDomain(0)]) assert device.get_energy() == [fs_pkg_dram_one_socket.domains_current_energy['dram_0'], fs_pkg_dram_one_socket.domains_current_energy['package_0']]
def test_measure_rapl_device_default_values(mocked_handler, _mocked_perf_counter, fs_pkg_dram_one_socket, one_gpu_api): correct_trace = CorrectTrace( [RaplPackageDomain(0), RaplDramDomain(0), NvidiaGPUDomain(0)], [fs_pkg_dram_one_socket, one_gpu_api], TIMESTAMP_TRACE) # test correct_trace.add_new_sample('start') # test with EnergyContext(mocked_handler) as energy_context: correct_trace.add_new_sample('second_tag') # test energy_context.record(tag='second_tag') correct_trace.add_new_sample('') # test assert mocked_handler.process.call_count == 2 # test for correct_sample, processed_arg in zip( correct_trace, mocked_handler.process.call_args_list): # test measured_sample = processed_arg[0][0] # test assert_sample_are_equals(correct_sample, measured_sample) # test
def test_configure_device_to_get_pkg_energy_on_cpu1_with_no_cpu1_raise_NoSuchDomainError(fs_pkg_dram_one_socket): device = RaplDevice() with pytest.raises(NoSuchDomainError): device.configure([RaplPackageDomain(1)])
def test_available_domains_with_pkg_dram_rapl_api_two_cpu_return_correct_values(fs_pkg_dram_two_socket): returned_values = RaplDevice.available_domains() correct_values = [RaplPackageDomain(0), RaplDramDomain(0), RaplPackageDomain(1), RaplDramDomain(1)] assert sorted(correct_values) == sorted(returned_values)
def test_available_domains_with_pkg_psys_rapl_api_return_correct_values(fs_pkg_psys_one_socket): returned_values = RaplDevice.available_domains() correct_values = [RaplPackageDomain(0)] assert sorted(correct_values) == sorted(returned_values)
def test_available_domains_with_pkg_uncore_and_dram_rapl_api_return_correct_values(fs_pkg_dram_uncore_one_socket): returned_values = RaplDevice.available_domains() correct_values = [RaplPackageDomain(0), RaplDramDomain(0), RaplUncoreDomain(0)] assert sorted(correct_values) == sorted(returned_values)
def test_get_configured_domains_with_pkg_values_on_pkg_dram_rapl_api_return_correct_values(fs_pkg_dram_one_socket): configured_domains = [RaplPackageDomain(0)] device = RaplDevice() device.configure(configured_domains) assert configured_domains == device.get_configured_domains()
def test_package_get_device_type_return_RaplDevice(): domain = RaplPackageDomain(0) assert domain.get_device_type() == RaplDevice
def test_package_repr_return_package_underscore_socket_id(integer_value): domain = RaplPackageDomain(integer_value) assert str(domain) == 'package_' + str(integer_value)