Zhomart Mukhamejanov | 72a4d46 | 2018-04-26 15:49:08 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright (C) 2018 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | """ |
Zhomart Mukhamejanov | 96eb59e | 2018-05-04 12:17:01 -0700 | [diff] [blame] | 18 | Tests gen_update_config.py. |
| 19 | |
| 20 | Example: |
| 21 | $ PYTHONPATH=$ANDROID_BUILD_TOP/build/make/tools/releasetools:$PYTHONPATH \\ |
| 22 | python3 -m unittest test_gen_update_config |
Zhomart Mukhamejanov | 72a4d46 | 2018-04-26 15:49:08 -0700 | [diff] [blame] | 23 | """ |
| 24 | |
| 25 | import os.path |
| 26 | import unittest |
| 27 | from gen_update_config import GenUpdateConfig |
| 28 | |
| 29 | |
| 30 | class GenUpdateConfigTest(unittest.TestCase): # pylint: disable=missing-docstring |
| 31 | |
| 32 | def test_ab_install_type_streaming(self): |
| 33 | """tests if streaming property files' offset and size are generated properly""" |
| 34 | config, package = self._generate_config() |
| 35 | property_files = config['ab_streaming_metadata']['property_files'] |
Zhomart Mukhamejanov | 96eb59e | 2018-05-04 12:17:01 -0700 | [diff] [blame] | 36 | self.assertEqual(len(property_files), 6) |
Zhomart Mukhamejanov | 72a4d46 | 2018-04-26 15:49:08 -0700 | [diff] [blame] | 37 | with open(package, 'rb') as pkg_file: |
| 38 | for prop in property_files: |
| 39 | filename, offset, size = prop['filename'], prop['offset'], prop['size'] |
| 40 | pkg_file.seek(offset) |
Zhomart Mukhamejanov | 96eb59e | 2018-05-04 12:17:01 -0700 | [diff] [blame] | 41 | raw_data = pkg_file.read(size) |
| 42 | if filename in ['payload.bin', 'payload_metadata.bin']: |
| 43 | pass |
| 44 | elif filename == 'payload_properties.txt': |
| 45 | pass |
| 46 | elif filename == 'metadata': |
| 47 | self.assertEqual(raw_data.decode('ascii'), 'META-INF/COM/ANDROID/METADATA') |
| 48 | else: |
| 49 | expected_data = filename.replace('.', '-').upper() |
| 50 | self.assertEqual(raw_data.decode('ascii'), expected_data) |
Zhomart Mukhamejanov | 72a4d46 | 2018-04-26 15:49:08 -0700 | [diff] [blame] | 51 | |
| 52 | @staticmethod |
| 53 | def _generate_config(): |
| 54 | """Generates JSON config from ota_002_package.zip.""" |
| 55 | ota_package = os.path.join(os.path.dirname(__file__), |
| 56 | '../tests/res/raw/ota_002_package.zip') |
| 57 | gen = GenUpdateConfig(ota_package, |
| 58 | 'file:///foo.bar', |
| 59 | GenUpdateConfig.AB_INSTALL_TYPE_STREAMING) |
| 60 | gen.run() |
| 61 | return gen.config, ota_package |