blob: 8b77cb2a29e67aea1b2c58cf5863dc445d2c1d81 [file] [log] [blame]
Zhomart Mukhamejanov72a4d462018-04-26 15:49:08 -07001#!/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 Mukhamejanov96eb59e2018-05-04 12:17:01 -070018Tests gen_update_config.py.
19
20Example:
21 $ PYTHONPATH=$ANDROID_BUILD_TOP/build/make/tools/releasetools:$PYTHONPATH \\
22 python3 -m unittest test_gen_update_config
Zhomart Mukhamejanov72a4d462018-04-26 15:49:08 -070023"""
24
25import os.path
26import unittest
27from gen_update_config import GenUpdateConfig
28
29
30class 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()
Zhomart Mukhamejanov88712f72018-08-21 12:19:02 -070035 property_files = config['ab_config']['property_files']
Zhomart Mukhamejanov96eb59e2018-05-04 12:17:01 -070036 self.assertEqual(len(property_files), 6)
Zhomart Mukhamejanov72a4d462018-04-26 15:49:08 -070037 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 Mukhamejanov96eb59e2018-05-04 12:17:01 -070041 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 Mukhamejanov72a4d462018-04-26 15:49:08 -070051
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',
Zhomart Mukhamejanov88712f72018-08-21 12:19:02 -070059 GenUpdateConfig.AB_INSTALL_TYPE_STREAMING,
60 True, # ab_force_switch_slot
61 True) # ab_verify_payload_metadata
Zhomart Mukhamejanov72a4d462018-04-26 15:49:08 -070062 gen.run()
63 return gen.config, ota_package