1# Lint as: python2, python3 2# Copyright (c) 2021 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6from __future__ import absolute_import 7from __future__ import division 8from __future__ import print_function 9 10import logging 11import random 12 13from six.moves import range 14 15from autotest_lib.client.bin import test 16from autotest_lib.client.common_lib import error 17from autotest_lib.client.cros.cellular import cellular_logging 18from autotest_lib.client.cros.cellular import hermes_utils 19 20log = cellular_logging.SetupCellularLogging('HermesMultiProfile') 21 22class cellular_Hermes_MultiProfile(test.test): 23 """ 24 Test that Hermes can perform enable/disable operations on multiple profiles 25 26 Prerequisites 27 28 1) For test CI: 29 Before running this test on test CI, two profiles need to be created on 30 go/stork-profile. The profiles required to be linked to the EID of the dut. 31 Profiles with class=operational and type=Android GTS test are known to work 32 well with this test. 33 34 We rely on the SMDS event to find the activation codes for the test. 35 There is a limit of 99 downloads before profiles to be deleted and 36 recreated.(b/181723689) 37 38 2) For prod CI: 39 Install two production profiles before running the test. 40 41 """ 42 version = 1 43 44 def run_once(self, test_env, is_prod_ci=False): 45 """ Enable/Disable a profile """ 46 self.is_prod_ci = is_prod_ci 47 48 self.mm_proxy, self.hermes_manager, euicc_path = \ 49 hermes_utils.initialize_test(is_prod_ci) 50 # separate testci and prodici procedure to get 2 iccids 51 if not is_prod_ci: 52 first_iccid = hermes_utils.install_profile_test(euicc_path, self.hermes_manager) 53 second_iccid = hermes_utils.install_profile_test(euicc_path, self.hermes_manager) 54 else: 55 _, installed_profiles = \ 56 hermes_utils.request_installed_profiles(euicc_path, self.hermes_manager) 57 58 profiles_count = len(installed_profiles) 59 if profiles_count < 2: 60 raise error.TestError('Two distinct profiles need to be ' 61 'installed before test begins but count is '+ profiles_count) 62 63 first_iccid = list(installed_profiles.values())[0].iccid 64 second_iccid = list(installed_profiles.values())[1].iccid 65 66 if not first_iccid or not second_iccid : 67 fail_iccid = 'first' if not first_iccid else 'second' 68 raise error.TestError('Could not get' + fail_iccid + ' iccid') 69 70 if first_iccid == second_iccid: 71 raise error.TestError('Two distinct profiles need to be installed ' 72 'before test begins. Got only ' + first_iccid) 73 74 # first get two profiles, check first_iccid and disable if not disabled, 75 # also check second profile is enabled or not. if not enable 2nd one 76 logging.info('Disabling first profile to prevent enabling already ' 77 'enabled profile in next stress loop. first_iccid:%s, ' 78 'second_iccid:%s', first_iccid, second_iccid) 79 # get profile state to make sure to keep in expected state 80 first_state = hermes_utils.get_profile_state( 81 euicc_path, self.hermes_manager, first_iccid) 82 83 if first_state: 84 hermes_utils.set_profile_state( 85 False, euicc_path, self.hermes_manager, first_iccid, None) 86 87 second_state = hermes_utils.get_profile_state( 88 euicc_path, self.hermes_manager, second_iccid) 89 90 if not second_state: 91 hermes_utils.set_profile_state( 92 True, euicc_path, self.hermes_manager, second_iccid, None) 93 94 logging.info('Stress enable/disable profiles') 95 for i in range(1,5): 96 logging.info('Iteration :: %d', i) 97 for iccid in [first_iccid, second_iccid]: 98 if not hermes_utils.get_profile_state( 99 euicc_path, self.hermes_manager, iccid): 100 logging.info('Enabling profile:%s', iccid) 101 hermes_utils.enable_or_disable_profile_test( 102 euicc_path, self.hermes_manager, iccid, True) 103 explicitly_disable_profile = random.choice([True,False]) 104 if (explicitly_disable_profile): 105 if hermes_utils.get_profile_state( 106 euicc_path, self.hermes_manager, iccid): 107 logging.info('Disabling profile:%s', iccid) 108 hermes_utils.enable_or_disable_profile_test( 109 euicc_path, self.hermes_manager, iccid, False) 110 111 logging.info('HermesMultiProfileTest Completed') 112