summaryrefslogtreecommitdiffstats
path: root/python/mozbuild/mozbuild/test/test_android_version_code.py
blob: 7600ebe0d8234264d378b69ffc6ac258a3a342cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import unittest

from mozunit import main

from mozbuild.android_version_code import (
    android_version_code_v0,
    android_version_code_v1,
)


class TestAndroidVersionCode(unittest.TestCase):
    def test_android_version_code_v0(self):
        # From https://treeherder.mozilla.org/#/jobs?repo=mozilla-central&revision=e25de9972a77.
        buildid = "20150708104620"
        arm_api9 = 2015070819
        arm_api11 = 2015070821
        x86_api9 = 2015070822
        self.assertEqual(
            android_version_code_v0(
                buildid, cpu_arch="armeabi", min_sdk=9, max_sdk=None
            ),
            arm_api9,
        )
        self.assertEqual(
            android_version_code_v0(
                buildid, cpu_arch="armeabi-v7a", min_sdk=11, max_sdk=None
            ),
            arm_api11,
        )
        self.assertEqual(
            android_version_code_v0(buildid, cpu_arch="x86", min_sdk=9, max_sdk=None),
            x86_api9,
        )

    def test_android_version_code_v1(self):
        buildid = "20150825141628"
        arm_api16 = 0b01111000001000000001001001110001
        arm64_api21 = 0b01111000001000000001001001110100
        x86_api9 = 0b01111000001000000001001001110100
        self.assertEqual(
            android_version_code_v1(
                buildid, cpu_arch="armeabi-v7a", min_sdk=16, max_sdk=None
            ),
            arm_api16,
        )
        self.assertEqual(
            android_version_code_v1(
                buildid, cpu_arch="arm64-v8a", min_sdk=21, max_sdk=None
            ),
            arm64_api21,
        )
        self.assertEqual(
            android_version_code_v1(buildid, cpu_arch="x86", min_sdk=9, max_sdk=None),
            x86_api9,
        )

    def test_android_version_code_v1_underflow(self):
        """Verify that it is an error to ask for v1 codes predating the cutoff."""
        buildid = "201508010000"  # Earliest possible.
        arm_api9 = 0b01111000001000000000000000000000
        self.assertEqual(
            android_version_code_v1(
                buildid, cpu_arch="armeabi", min_sdk=9, max_sdk=None
            ),
            arm_api9,
        )
        with self.assertRaises(ValueError) as cm:
            underflow = "201507310000"  # Latest possible (valid) underflowing date.
            android_version_code_v1(
                underflow, cpu_arch="armeabi", min_sdk=9, max_sdk=None
            )
        self.assertTrue("underflow" in cm.exception.message)

    def test_android_version_code_v1_running_low(self):
        """Verify there is an informative message if one asks for v1
        codes that are close to overflow."""
        with self.assertRaises(ValueError) as cm:
            overflow = "20290801000000"
            android_version_code_v1(
                overflow, cpu_arch="armeabi", min_sdk=9, max_sdk=None
            )
        self.assertTrue("Running out of low order bits" in cm.exception.message)

    def test_android_version_code_v1_overflow(self):
        """Verify that it is an error to ask for v1 codes that actually does overflow."""
        with self.assertRaises(ValueError) as cm:
            overflow = "20310801000000"
            android_version_code_v1(
                overflow, cpu_arch="armeabi", min_sdk=9, max_sdk=None
            )
        self.assertTrue("overflow" in cm.exception.message)

    def test_android_version_code_v0_relative_v1(self):
        """Verify that the first v1 code is greater than the equivalent v0 code."""
        buildid = "20150801000000"
        self.assertGreater(
            android_version_code_v1(
                buildid, cpu_arch="armeabi", min_sdk=9, max_sdk=None
            ),
            android_version_code_v0(
                buildid, cpu_arch="armeabi", min_sdk=9, max_sdk=None
            ),
        )


if __name__ == "__main__":
    main()