firmware_unittest: add tests for all target endpoints
run existing unit tests for all firmware endpoints.
BUG=b:203462311
TEST=./run_tests ./api/controller/firmware_unittest.py
Change-Id: Ie6c068155916eca7f95834d86f436a045747b904
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3237035
Tested-by: Azizur Rahman <azrahman@google.com>
Auto-Submit: Azizur Rahman <azrahman@google.com>
Commit-Queue: Azizur Rahman <azrahman@google.com>
Reviewed-by: Sean McAllister <smcallis@google.com>
diff --git a/api/controller/firmware_unittest.py b/api/controller/firmware_unittest.py
index 2f74b6a..adf8bf1 100644
--- a/api/controller/firmware_unittest.py
+++ b/api/controller/firmware_unittest.py
@@ -41,42 +41,58 @@
def testBuildAllFirmware(self):
"""Test invocation of endpoint by verifying call to cros_build_lib.run."""
- request = self._GetInput(chroot_path=self.chroot_path, code_coverage=True)
- # TODO(mmortensen): Consider refactoring firmware._call_entry code (perhaps
- # putting the parsing of the output file in a function) so that we don't
- # have to mock something as generic as 'json_format.Parse' to avoid an
- # error on parsing an empty(due to mock call) file.
- json_format_patch = self.PatchObject(json_format, 'Parse')
- response = firmware_pb2.BuildAllFirmwareResponse()
- # Call the method under test.
- firmware.BuildAllFirmware(request, response, self.api_config)
- # Because we mock out the function, we verify that it is called as we
- # expect it to be called.
- called_function = os.path.join(constants.SOURCE_ROOT,
- 'src/platform/ec/firmware_builder.py')
- self.cros_build_run_patch.assert_called_with(
- [called_function, '--metrics', mock.ANY, '--code-coverage', 'build'],
- check=False)
- # Verify that we try to parse the metrics file.
- json_format_patch.assert_called()
+ for fw_loc in common_pb2.FwLocation.values():
+ fw_path = firmware.get_fw_loc(fw_loc)
+ if not fw_path:
+ continue
+ request = self._GetInput(chroot_path=self.chroot_path,
+ fw_location=fw_loc,
+ code_coverage=True)
+ # TODO(mmortensen): Consider refactoring firmware._call_entry code
+ # (putting the parsing of the output file in a function) so that we don't
+ # have to mock something as generic as 'json_format.Parse' to avoid an
+ # error on parsing an empty(due to mock call) file.
+ json_format_patch = self.PatchObject(json_format, 'Parse')
+ response = firmware_pb2.BuildAllFirmwareResponse()
+ # Call the method under test.
+ firmware.BuildAllFirmware(request, response, self.api_config)
+ # Because we mock out the function, we verify that it is called as we
+ # expect it to be called.
+ called_function = os.path.join(constants.SOURCE_ROOT,
+ fw_path, 'firmware_builder.py')
+ self.cros_build_run_patch.assert_called_with(
+ [called_function, '--metrics', mock.ANY, '--code-coverage', 'build'],
+ check=False)
+ # Verify that we try to parse the metrics file.
+ json_format_patch.assert_called()
def testValidateOnly(self):
"""Sanity check that a validate only call does not execute any logic."""
- request = self._GetInput(chroot_path=self.chroot_path, code_coverage=True)
- response = firmware_pb2.BuildAllFirmwareResponse()
- firmware.BuildAllFirmware(request, response, self.validate_only_config)
- self.cros_build_run_patch.assert_not_called()
+ for fw_loc in common_pb2.FwLocation.values():
+ if not firmware.get_fw_loc(fw_loc):
+ continue
+ request = self._GetInput(chroot_path=self.chroot_path,
+ fw_location=fw_loc,
+ code_coverage=True)
+ response = firmware_pb2.BuildAllFirmwareResponse()
+ firmware.BuildAllFirmware(request, response, self.validate_only_config)
+ self.cros_build_run_patch.assert_not_called()
def testMockCall(self):
"""Test that a mock call does not execute logic, returns mocked value."""
- request = self._GetInput(chroot_path=self.chroot_path, code_coverage=True)
- response = firmware_pb2.BuildAllFirmwareResponse()
- firmware.BuildAllFirmware(request, response, self.mock_call_config)
- self.cros_build_run_patch.assert_not_called()
- self.assertEqual(len(response.metrics.value), 1)
- self.assertEqual(response.metrics.value[0].target_name, 'foo')
- self.assertEqual(response.metrics.value[0].platform_name, 'bar')
- self.assertEqual(len(response.metrics.value[0].fw_section), 1)
- self.assertEqual(response.metrics.value[0].fw_section[0].region, 'EC_RO')
- self.assertEqual(response.metrics.value[0].fw_section[0].used, 100)
- self.assertEqual(response.metrics.value[0].fw_section[0].total, 150)
+ for fw_loc in common_pb2.FwLocation.values():
+ if not firmware.get_fw_loc(fw_loc):
+ continue
+ request = self._GetInput(chroot_path=self.chroot_path,
+ fw_location=fw_loc,
+ code_coverage=True)
+ response = firmware_pb2.BuildAllFirmwareResponse()
+ firmware.BuildAllFirmware(request, response, self.mock_call_config)
+ self.cros_build_run_patch.assert_not_called()
+ self.assertEqual(len(response.metrics.value), 1)
+ self.assertEqual(response.metrics.value[0].target_name, 'foo')
+ self.assertEqual(response.metrics.value[0].platform_name, 'bar')
+ self.assertEqual(len(response.metrics.value[0].fw_section), 1)
+ self.assertEqual(response.metrics.value[0].fw_section[0].region, 'EC_RO')
+ self.assertEqual(response.metrics.value[0].fw_section[0].used, 100)
+ self.assertEqual(response.metrics.value[0].fw_section[0].total, 150)