The bug that was attempted to be fixed in [1] actually was in the
encoding API - pySim.utils.enc_plmn(). According to 3GPP TS 31.102,
which points to TS 24.008, the three-digit (E)HPLMN shall be encoded
as shown below (ASCII-art interpretation):
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| MCC Digit 2 | MCC Digit 1 |
+---+---+---+---+---+---+---+---+
| MNC Digit 3 | MCC Digit 3 |
+---+---+---+---+---+---+---+---+
| MNC Digit 2 | MNC Digit 1 |
+---+---+---+---+---+---+---+---+
while pySim.utils.enc_plmn() would produce the following:
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| MCC Digit 2 | MCC Digit 1 |
+---+---+---+---+---+---+---+---+
| MNC Digit 1 | MCC Digit 3 |
+---+---+---+---+---+---+---+---+
| MNC Digit 3 | MNC Digit 2 |
+---+---+---+---+---+---+---+---+
Initially the _decoding_ API was correct, but then got changed in
[1] to follow buggy pySim's encoding API. As a result, a (E)HPLMN
programmed with pySim-prog.py would look correct if verified by
pySim-read.py, but the actual file content would be wrong.
This situation shows that our 'program-read-match' build verification
approach alone is insignificant. The lack of unit test coverage,
at least for the core parts of the project, makes it possible to have
symmetrical bugs in both encoding and decoding API parts unnoticed.
This problem was found while trying to enable dead unit tests in [3].
Change [1] that introduced a symmetrical bug is reverted in [2].
Change-Id: Ic7612502e1bb0d280133dabbcb5cb146fc6997e5
Related: [1] I799469206f87e930d8888367890babcb8ebe23a9
Related: [2] If6bf5383988ad442e275efc7c5a159327d104879
Related: [3] I4d4facfabc75187acd5238ff4d0f26022bd58f82
87 lines
2.6 KiB
Python
87 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import unittest
|
|
import pySim.utils as utils
|
|
|
|
class DecTestCase(unittest.TestCase):
|
|
|
|
def testSplitHexStringToListOf5ByteEntries(self):
|
|
input_str = "ffffff0003ffffff0002ffffff0001"
|
|
expected = [
|
|
"ffffff0003",
|
|
"ffffff0002",
|
|
"ffffff0001",
|
|
]
|
|
self.assertEqual(utils.hexstr_to_Nbytearr(input_str, 5), expected)
|
|
|
|
def testDecMCCfromPLMN(self):
|
|
self.assertEqual(utils.dec_mcc_from_plmn("92f501"), 295)
|
|
|
|
def testDecMCCfromPLMN_unused(self):
|
|
self.assertEqual(utils.dec_mcc_from_plmn("ff0f00"), 4095)
|
|
|
|
def testDecMNCfromPLMN_twoDigitMNC(self):
|
|
self.assertEqual(utils.dec_mnc_from_plmn("92f501"), 10)
|
|
|
|
def testDecMNCfromPLMN_threeDigitMNC(self):
|
|
self.assertEqual(utils.dec_mnc_from_plmn("031263"), 361)
|
|
|
|
def testDecMNCfromPLMN_unused(self):
|
|
self.assertEqual(utils.dec_mnc_from_plmn("00f0ff"), 4095)
|
|
|
|
def test_enc_plmn(self):
|
|
with self.subTest("2-digit MCC"):
|
|
self.assertEqual(utils.enc_plmn("001", "01F"), "00F110")
|
|
self.assertEqual(utils.enc_plmn("001", "01"), "00F110")
|
|
self.assertEqual(utils.enc_plmn("295", "10"), "92F501")
|
|
|
|
with self.subTest("3-digit MCC"):
|
|
self.assertEqual(utils.enc_plmn("001", "001"), "001100")
|
|
self.assertEqual(utils.enc_plmn("302", "361"), "031263")
|
|
|
|
def testDecAct_noneSet(self):
|
|
self.assertEqual(utils.dec_act("0000"), [])
|
|
|
|
def testDecAct_onlyUtran(self):
|
|
self.assertEqual(utils.dec_act("8000"), ["UTRAN"])
|
|
|
|
def testDecAct_onlyEUtran(self):
|
|
self.assertEqual(utils.dec_act("4000"), ["E-UTRAN"])
|
|
|
|
def testDecAct_onlyGsm(self):
|
|
self.assertEqual(utils.dec_act("0080"), ["GSM"])
|
|
|
|
def testDecAct_onlyGsmCompact(self):
|
|
self.assertEqual(utils.dec_act("0040"), ["GSM COMPACT"])
|
|
|
|
def testDecAct_onlyCdma2000HRPD(self):
|
|
self.assertEqual(utils.dec_act("0020"), ["cdma2000 HRPD"])
|
|
|
|
def testDecAct_onlyCdma20001xRTT(self):
|
|
self.assertEqual(utils.dec_act("0010"), ["cdma2000 1xRTT"])
|
|
|
|
def testDecAct_allSet(self):
|
|
self.assertEqual(utils.dec_act("ffff"), ["UTRAN", "E-UTRAN", "GSM", "GSM COMPACT", "cdma2000 HRPD", "cdma2000 1xRTT"])
|
|
|
|
def testDecxPlmn_w_act(self):
|
|
expected = {'mcc': 295, 'mnc': 10, 'act': ["UTRAN"]}
|
|
self.assertEqual(utils.dec_xplmn_w_act("92f5018000"), expected)
|
|
|
|
def testFormatxPlmn_w_act(self):
|
|
input_str = "92f501800092f5508000ffffff0000ffffff0000ffffff0000ffffff0000ffffff0000ffffff0000ffffff0000ffffff0000"
|
|
expected = '''92f5018000 # MCC: 295 MNC: 10 AcT: UTRAN
|
|
92f5508000 # MCC: 295 MNC: 5 AcT: UTRAN
|
|
ffffff0000 # unused
|
|
ffffff0000 # unused
|
|
ffffff0000 # unused
|
|
ffffff0000 # unused
|
|
ffffff0000 # unused
|
|
ffffff0000 # unused
|
|
ffffff0000 # unused
|
|
ffffff0000 # unused
|
|
'''
|
|
self.assertEqual(utils.format_xplmn_w_act(input_str), expected)
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|