Add testsuite for pySim-shell with real cards

This patch adds a comprehensive testsuite for pySim-shell. The testsuite
is based on python's unittest framework in combination with pySim-shell
scripts.

Related: OS#6531
Change-Id: Ieae1330767a6e55e62437f5f988a0d33b727b5de
This commit is contained in:
Philipp Maier
2024-08-12 17:56:43 +02:00
parent d7032955c5
commit f87a00c04f
114 changed files with 22424 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
# Testsuite for pySim-shell.py
#
# (C) 2024 by sysmocom - s.f.m.c. GmbH
# All Rights Reserved
#
# Author: Philipp Maier
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import unittest
import os
import json
from utils import *
class test_case(UnittestUtils):
def test_binary_uicc(self):
cardname = 'sysmoISIM-SJA5-S17'
self.runPySimShell(cardname, "test_binary_uicc.script")
self.assertEqualFiles("test_binary_uicc.tmp")
def test_binary_sim(self):
cardname = 'sysmoSIM-GR1'
self.runPySimShell(cardname, "test_binary_sim.script")
self.assertEqualFiles("test_binary_sim.tmp")
def test_record_uicc(self):
cardname = 'sysmoISIM-SJA5-S17'
self.runPySimShell(cardname, "test_record_uicc.script")
self.assertEqualFiles("test_record_uicc.tmp")
def test_record_sim(self):
cardname = 'sysmoSIM-GR1'
self.runPySimShell(cardname, "test_record_sim.script")
self.assertEqualFiles("test_record_sim.tmp")
def test_ber_tlv_uicc(self):
cardname = 'sysmoISIM-SJA5-S17'
self.runPySimShell(cardname, "test_ber_tlv_uicc.script", add_adm = True)
self.assertEqualFiles("test_ber_tlv_uicc.tmp")
if __name__ == "__main__":
unittest.main()

View File

@@ -0,0 +1,7 @@
[129, 130, 131, 132]
8106aabbccddeeff
820a11223344556677889900
830d187216fff38bbcc22110ffffff
840123
[130, 132]
[]

View File

@@ -0,0 +1,36 @@
set debug true
set echo true
# Create a backup the files we will modify
export --filename MF/ADF.ISIM/EF.IMSConfigData > restore_ef_IMSConfigData.script.tmp
select MF/ADF.ISIM/EF.IMSConfigData
# Empty the file
delete_all
retrieve_tags > test_ber_tlv_uicc.tmp
# Set some tags
set_data 129 aabbccddeeff
set_data 130 11223344556677889900
set_data 131 187216fff38bbcc22110ffffff
set_data 132 23
# Readback tags
retrieve_tags > test_ber_tlv_uicc.tmp
retrieve_data 129 >> test_ber_tlv_uicc.tmp
retrieve_data 130 >> test_ber_tlv_uicc.tmp
retrieve_data 131 >> test_ber_tlv_uicc.tmp
retrieve_data 132 >> test_ber_tlv_uicc.tmp
# Delete some tags
delete_data 131
delete_data 129
retrieve_tags >> test_ber_tlv_uicc.tmp
# Empty file again
delete_all
retrieve_tags >> test_ber_tlv_uicc.tmp
# Restore modified files to their original state
run_script restore_ef_IMSConfigData.script.tmp

View File

@@ -0,0 +1,4 @@
ffffffffffffffffffffff
01234567890abcdeffffff
01234567890abcdeffaaaa
001abcd3440abcdeffaaaa

View File

@@ -0,0 +1,27 @@
set debug true
set echo true
# Create a backup the files we will modify
export --filename MF/DF.GSM/EF.LOCI > restore_ef_loci.script.tmp
# Select an arbitrary file to work with
select MF/DF.GSM/EF.LOCI
# Clear file contents
update_binary ffffffffffffffffffffff
read_binary > test_binary_sim.tmp
# Write some short pattern to the file
update_binary 01234567890abcdeff
read_binary >> test_binary_sim.tmp
# Write some pattern to the file
update_binary 01234567890abcdeffaaaa
read_binary >> test_binary_sim.tmp
# Write some short pattern to the file, we expect the tail to remain unchanged
update_binary 001abcd344
read_binary >> test_binary_sim.tmp
# Restore modified files to their original state
run_script restore_ef_loci.script.tmp

View File

@@ -0,0 +1,13 @@
ffffffffffffffffffffff
01234567890abcdeffffff
01234567890abcdeffaaaa
001abcd3440abcdeffaaaa
{
"tmsi": "12345678",
"lai": {
"mcc_mnc": "262-42",
"lac": "9876"
},
"rfu": 0,
"lu_status": 1
}

View File

@@ -0,0 +1,33 @@
set debug true
set echo true
# Create a backup the files we will modify
export --filename MF/ADF.USIM/EF.LOCI > restore_ef_loci.script.tmp
# Select an arbitrary file to work with
select MF/ADF.USIM/EF.LOCI
# Clear file contents
update_binary ffffffffffffffffffffff
read_binary > test_binary_uicc.tmp
# Write some short pattern to the file
update_binary 01234567890abcdeff
read_binary >> test_binary_uicc.tmp
# Write some pattern to the file
update_binary 01234567890abcdeffaaaa
read_binary >> test_binary_uicc.tmp
# Write some short pattern to the file, we expect the tail to remain unchanged
update_binary 001abcd344
read_binary >> test_binary_uicc.tmp
# Write some json encoded content to the file
update_binary_decoded '{"tmsi": "12345678", "lai": { "mcc_mnc": "262-42", "lac": "9876" }, "rfu": 0, "lu_status": 1 }'
# Read the file, we expect the same json encoded content to show up again.
read_binary_decoded >> test_binary_uicc.tmp
# Restore modified files to their original state
run_script restore_ef_loci.script.tmp

View File

@@ -0,0 +1,7 @@
001 ffffffffffffffffffffffffffff
001 abcdefffffffffffffffffffffff
001 12345678900aabbccdd098765434
002 ffffffffffffffffffffffffffff
003 12345678900aabbccdd098765434
004 ffffffffffffffffffffffffffff
005 12345678900aabbccdd098765434

View File

@@ -0,0 +1,25 @@
set debug true
set echo true
# Create a backup the files we will modify
export --filename MF/DF.TELECOM/EF.CCP > restore_ef_ccp.script.tmp
# Select an arbitrary file to work with
select MF/DF.TELECOM/EF.CCP
# Clear file contents
update_record 1 ffffffffffffffffffffffffffff
read_record 1 > test_record_sim.tmp
# Write some short pattern to the file, expect tail to be padded with 0xff
update_record 1 abcdef
read_record 1 >> test_record_sim.tmp
# Write some pattern to three different records
update_record 1 12345678900AABBCCDD098765434
update_record 3 12345678900AABBCCDD098765434
update_record 5 12345678900AABBCCDD098765434
read_records >> test_record_sim.tmp
# Restore modified files to their original state
run_script restore_ef_ccp.script.tmp

View File

@@ -0,0 +1,146 @@
001 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
001 abcdefffffffffffffffffffffffffffffffffffffffffffffffffffff
001 0123456789abcdef0123456789abcdef0123456789abcdef0123456789
002 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
003 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
004 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
005 0123456789abcdef0123456789abcdef0123456789abcdef0123456789
006 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
007 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
008 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
009 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
010 0123456789abcdef0123456789abcdef0123456789abcdef0123456789
[
{
"alpha_id": null,
"len_of_bcd": 7,
"ton_npi": {
"ext": true,
"type_of_number": "reserved_for_extension",
"numbering_plan_id": "reserved_for_extension"
},
"dialing_nr": "123456",
"cap_conf_id": 42,
"ext4_record_id": 23
},
{
"alpha_id": "",
"len_of_bcd": 255,
"ton_npi": {
"ext": true,
"type_of_number": "reserved_for_extension",
"numbering_plan_id": "reserved_for_extension"
},
"dialing_nr": "",
"cap_conf_id": 255,
"ext4_record_id": 255
},
{
"alpha_id": "",
"len_of_bcd": 255,
"ton_npi": {
"ext": true,
"type_of_number": "reserved_for_extension",
"numbering_plan_id": "reserved_for_extension"
},
"dialing_nr": "",
"cap_conf_id": 255,
"ext4_record_id": 255
},
{
"alpha_id": "",
"len_of_bcd": 255,
"ton_npi": {
"ext": true,
"type_of_number": "reserved_for_extension",
"numbering_plan_id": "reserved_for_extension"
},
"dialing_nr": "",
"cap_conf_id": 255,
"ext4_record_id": 255
},
{
"alpha_id": null,
"len_of_bcd": 7,
"ton_npi": {
"ext": true,
"type_of_number": "reserved_for_extension",
"numbering_plan_id": "reserved_for_extension"
},
"dialing_nr": "123456",
"cap_conf_id": 42,
"ext4_record_id": 23
},
{
"alpha_id": "",
"len_of_bcd": 255,
"ton_npi": {
"ext": true,
"type_of_number": "reserved_for_extension",
"numbering_plan_id": "reserved_for_extension"
},
"dialing_nr": "",
"cap_conf_id": 255,
"ext4_record_id": 255
},
{
"alpha_id": "",
"len_of_bcd": 255,
"ton_npi": {
"ext": true,
"type_of_number": "reserved_for_extension",
"numbering_plan_id": "reserved_for_extension"
},
"dialing_nr": "",
"cap_conf_id": 255,
"ext4_record_id": 255
},
{
"alpha_id": "",
"len_of_bcd": 255,
"ton_npi": {
"ext": true,
"type_of_number": "reserved_for_extension",
"numbering_plan_id": "reserved_for_extension"
},
"dialing_nr": "",
"cap_conf_id": 255,
"ext4_record_id": 255
},
{
"alpha_id": "",
"len_of_bcd": 255,
"ton_npi": {
"ext": true,
"type_of_number": "reserved_for_extension",
"numbering_plan_id": "reserved_for_extension"
},
"dialing_nr": "",
"cap_conf_id": 255,
"ext4_record_id": 255
},
{
"alpha_id": null,
"len_of_bcd": 7,
"ton_npi": {
"ext": true,
"type_of_number": "reserved_for_extension",
"numbering_plan_id": "reserved_for_extension"
},
"dialing_nr": "123456",
"cap_conf_id": 42,
"ext4_record_id": 23
}
]
{
"alpha_id": null,
"len_of_bcd": 7,
"ton_npi": {
"ext": true,
"type_of_number": "reserved_for_extension",
"numbering_plan_id": "reserved_for_extension"
},
"dialing_nr": "123456",
"cap_conf_id": 42,
"ext4_record_id": 23
}

View File

@@ -0,0 +1,32 @@
set debug true
set echo true
# Create a backup the files we will modify
export --filename MF/ADF.USIM/EF.BDN > restore_ef_bdn.script.tmp
# Select an arbitrary file to work with
select MF/ADF.USIM/EF.BDN
# Clear file contents
update_record 1 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
read_record 1 > test_record_uicc.tmp
# Write some short pattern to the file, expect tail to be padded with 0xff
update_record 1 abcdef
read_record 1 >> test_record_uicc.tmp
# Write some pattern to three different records
update_record 1 0123456789abcdef0123456789abcdef0123456789abcdef0123456789
update_record 5 0123456789abcdef0123456789abcdef0123456789abcdef0123456789
update_record 10 0123456789abcdef0123456789abcdef0123456789abcdef0123456789
read_records >> test_record_uicc.tmp
# Write some json encoded content to three different records
update_record_decoded 1 '{ "alpha_id": "", "len_of_bcd": 7, "ton_npi": { "ext": true, "type_of_number": "reserved_for_extension", "numbering_plan_id": "reserved_for_extension" }, "dialing_nr": "1234567", "cap_conf_id": 42, "ext4_record_id": 23 }'
update_record_decoded 5 '{ "alpha_id": "", "len_of_bcd": 7, "ton_npi": { "ext": true, "type_of_number": "reserved_for_extension", "numbering_plan_id": "reserved_for_extension" }, "dialing_nr": "1234567", "cap_conf_id": 42, "ext4_record_id": 23 }'
update_record_decoded 10 '{ "alpha_id": "", "len_of_bcd": 7, "ton_npi": { "ext": true, "type_of_number": "reserved_for_extension", "numbering_plan_id": "reserved_for_extension" }, "dialing_nr": "1234567", "cap_conf_id": 42, "ext4_record_id": 23 }'
read_records_decoded >> test_record_uicc.tmp
read_record_decoded 1 >> test_record_uicc.tmp
# Restore modified files to their original state
run_script restore_ef_bdn.script.tmp