summaryrefslogtreecommitdiffstats
path: root/testing/mozbase/mozpower/tests/test_powerbase.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/mozbase/mozpower/tests/test_powerbase.py
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/mozbase/mozpower/tests/test_powerbase.py')
-rw-r--r--testing/mozbase/mozpower/tests/test_powerbase.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/testing/mozbase/mozpower/tests/test_powerbase.py b/testing/mozbase/mozpower/tests/test_powerbase.py
new file mode 100644
index 0000000000..46de941457
--- /dev/null
+++ b/testing/mozbase/mozpower/tests/test_powerbase.py
@@ -0,0 +1,91 @@
+#!/usr/bin/env python
+
+from unittest import mock
+
+import mozunit
+import pytest
+from mozpower.powerbase import (
+ IPGExecutableMissingError,
+ PlatformUnsupportedError,
+ PowerBase,
+)
+
+
+def test_powerbase_intialization():
+ """Tests that the PowerBase class correctly raises
+ a NotImplementedError when attempting to instantiate
+ it directly.
+ """
+ with pytest.raises(NotImplementedError):
+ PowerBase()
+
+
+def test_powerbase_missing_methods(powermeasurer):
+ """Tests that trying to call PowerBase methods
+ without an implementation in the subclass raises
+ the NotImplementedError.
+ """
+ with pytest.raises(NotImplementedError):
+ powermeasurer.initialize_power_measurements()
+
+ with pytest.raises(NotImplementedError):
+ powermeasurer.finalize_power_measurements()
+
+ with pytest.raises(NotImplementedError):
+ powermeasurer.get_perfherder_data()
+
+
+def test_powerbase_get_ipg_path_mac(powermeasurer):
+ """Tests that getting the IPG path returns the expected results."""
+ powermeasurer._os = "darwin"
+ powermeasurer._cpu = "not-intel"
+
+ def os_side_effect(arg):
+ """Used to get around the os.path.exists check in
+ get_ipg_path which raises an IPGExecutableMissingError
+ otherwise.
+ """
+ return True
+
+ with mock.patch("os.path.exists", return_value=True) as m:
+ m.side_effect = os_side_effect
+
+ # None is returned when a non-intel based machine is
+ # tested.
+ ipg_path = powermeasurer.get_ipg_path()
+ assert ipg_path is None
+
+ # Check the path returned for mac intel-based machines.
+ powermeasurer._cpu = "intel"
+ ipg_path = powermeasurer.get_ipg_path()
+ assert ipg_path == "/Applications/Intel Power Gadget/PowerLog"
+
+
+def test_powerbase_get_ipg_path_errors(powermeasurer):
+ """Tests that the appropriate error is output when calling
+ get_ipg_path with invalid/unsupported _os and _cpu entries.
+ """
+
+ powermeasurer._cpu = "intel"
+ powermeasurer._os = "Not-An-OS"
+
+ def os_side_effect(arg):
+ """Used to force the error IPGExecutableMissingError to occur
+ (in case a machine running these tests is a mac, and has intel
+ power gadget installed).
+ """
+ return False
+
+ with pytest.raises(PlatformUnsupportedError):
+ powermeasurer.get_ipg_path()
+
+ with mock.patch("os.path.exists", return_value=False) as m:
+ m.side_effect = os_side_effect
+
+ powermeasurer._os = "darwin"
+ with pytest.raises(IPGExecutableMissingError):
+ powermeasurer.get_ipg_path()
+
+
+if __name__ == "__main__":
+ mozunit.main()