def hostapd_options_logging_test(): """Test bandsteering.hostapd_options when when logging only.""" unused_raii = experiment_testutils.MakeExperimentDirs() experiment_testutils.enable('WifiHostapdLogging') bandsteering_dir = bandsteering._BANDSTEERING_DIR wvtest.WVPASSEQ( ['-L', os.path.join(bandsteering_dir, '2.4_30abcc9ec8')], bandsteering.hostapd_options('2.4', 'my_ssid')) wvtest.WVPASSEQ( ['-L', os.path.join(bandsteering_dir, '5_30abcc9ec8')], bandsteering.hostapd_options('5', 'my_ssid'))
def hostapd_options_preexisting_dir_test(): """Test normal bandsteering when there is a preexisting directory.""" unused_raii = experiment_testutils.MakeExperimentDirs() experiment_testutils.enable('WifiBandsteering') bandsteering_dir = bandsteering._BANDSTEERING_DIR # Create a preexisting 2.4 GHz bandsteering directory with a file in it. os.makedirs(os.path.join(bandsteering_dir, '2.4_xxxxxxxxxx')) filename = 'foo' open(os.path.join(bandsteering_dir, '2.4_xxxxxxxxxx', filename), 'a').close() # Get the options for 2.4 GHz; this should move the old directory. bandsteering.hostapd_options('2.4', 'my_ssid') # If the old directory was moved correctly, we should see our file in the new # one, and the old directory should be gone. wvtest.WVPASS( os.path.isfile( os.path.join(bandsteering_dir, '2.4_30abcc9ec8', filename))) wvtest.WVFAIL( os.path.exists(os.path.join(bandsteering_dir, '2.4_xxxxxxxxxx')))
def generate_hostapd_config_test(): """Tests generate_hostapd_config.""" unused_raii = experiment_testutils.MakeExperimentDirs() opt = FakeOptDict() # Test a simple case. config = configs.generate_hostapd_config(_PHY_INFO, 'wlan0', '2.4', '1', '20', set(('a', 'b', 'g', 'n', 'ac')), 'asdfqwer', opt) wvtest.WVPASSEQ( '\n'.join( (_HOSTAPD_CONFIG, _HOSTAPD_CONFIG_WPA, '# Experiments: ()\n')), config) # Test bridge. default_bridge, opt.bridge = opt.bridge, 'br0' config = configs.generate_hostapd_config(_PHY_INFO, 'wlan0', '2.4', '1', '20', set(('a', 'b', 'g', 'n', 'ac')), 'asdfqwer', opt) wvtest.WVPASSEQ( '\n'.join((_HOSTAPD_CONFIG_BRIDGE, _HOSTAPD_CONFIG_WPA, '# Experiments: ()\n')), config) opt.bridge = default_bridge # Test WDS. default_wds, opt.wds = opt.wds, True config = configs.generate_hostapd_config(_PHY_INFO, 'wlan0', '2.4', '1', '20', set(('a', 'b', 'g', 'n', 'ac')), 'asdfqwer', opt) wvtest.WVPASSEQ( '\n'.join( (_HOSTAPD_CONFIG_WDS, _HOSTAPD_CONFIG_WPA, '# Experiments: ()\n')), config) opt.wds = default_wds # Test provisioning IEs. default_hidden_mode, opt.hidden_mode = opt.hidden_mode, True default_supports_provisioning, opt.supports_provisioning = ( opt.supports_provisioning, True) config = configs.generate_hostapd_config(_PHY_INFO, 'wlan0', '2.4', '1', '20', set(('a', 'b', 'g', 'n', 'ac')), 'asdfqwer', opt) wvtest.WVPASSEQ( '\n'.join((_HOSTAPD_CONFIG_PROVISION_VIA, _HOSTAPD_CONFIG_WPA, '# Experiments: ()\n')), config) opt.hidden_mode = default_hidden_mode opt.supports_provisioning = default_supports_provisioning # Test with no encryption. default_encryption, opt.encryption = opt.encryption, 'NONE' config = configs.generate_hostapd_config(_PHY_INFO, 'wlan0', '2.4', '1', '20', set(('a', 'b', 'g', 'n', 'ac')), 'asdfqwer', opt) wvtest.WVPASSEQ(_HOSTAPD_CONFIG + '\n# Experiments: ()\n', config) opt.encryption = default_encryption # Now enable extra short timeout intervals and the Wifi80211k experiment. experiment_testutils.enable('Wifi80211k') opt.extra_short_timeouts = 2 new_config = '\n'.join( (_HOSTAPD_CONFIG, _HOSTAPD_CONFIG_WPA, configs._EXPERIMENT_80211K_TPL.format(interface='wlan0'), configs._EXTRA_SHORT_TIMEOUTS2_TPL, '# Experiments: (Wifi80211k)\n')) config = configs.generate_hostapd_config(_PHY_INFO, 'wlan0', '2.4', '1', '20', set(('a', 'b', 'g', 'n', 'ac')), 'asdfqwer', opt) wvtest.WVPASSEQ(new_config, config) opt.extra_short_timeouts = 1 new_config = '\n'.join( (_HOSTAPD_CONFIG, _HOSTAPD_CONFIG_WPA, configs._EXPERIMENT_80211K_TPL.format(interface='wlan0'), configs._EXTRA_SHORT_TIMEOUTS1_TPL, '# Experiments: (Wifi80211k)\n')) config = configs.generate_hostapd_config(_PHY_INFO, 'wlan0', '2.4', '1', '20', set(('a', 'b', 'g', 'n', 'ac')), 'asdfqwer', opt) wvtest.WVPASSEQ(new_config, config) opt.extra_short_timeouts = 2 opt.yottasecond_timeouts = 1 new_config = '\n'.join( (_HOSTAPD_CONFIG, _HOSTAPD_CONFIG_WPA, configs._EXPERIMENT_80211K_TPL.format(interface='wlan0'), configs._YOTTASECOND_TIMEOUTS_TPL, '# Experiments: (Wifi80211k)\n')) config = configs.generate_hostapd_config(_PHY_INFO, 'wlan0', '2.4', '1', '20', set(('a', 'b', 'g', 'n', 'ac')), 'asdfqwer', opt) wvtest.WVPASSEQ(new_config, config)
def simulate_wireless_test(): """Test the WifiSimulateWireless experiment.""" unused_raii = experiment_testutils.MakeExperimentDirs() tmp_dir = tempfile.mkdtemp() interface.CWMP_PATH = tempfile.mkdtemp() interface.MAX_ACS_FAILURE_S = 1 contact = os.path.join(interface.CWMP_PATH, 'acscontact') connected = os.path.join(interface.CWMP_PATH, 'acsconnected') try: autoprov_filepath = os.path.join(tmp_dir, 'autoprov') b = Bridge('br0', '10', acs_autoprovisioning_filepath=autoprov_filepath) b.add_moca_station(0) b.set_gateway_ip('192.168.1.1') b.set_subnet('192.168.1.0/24') b.set_connection_check_result('succeed') b.initialize() # Initially, the connection check passes. wvtest.WVPASS(b.internet()) # Enable the experiment. experiment_testutils.enable('WifiSimulateWireless') # Calling update_routes overwrites the connection status cache, which we # need in order to see the effects we are looking for immediately # (ConnectionManager calls this every few seconds). b.update_routes() wvtest.WVFAIL(b.internet()) # Create an ACS connection attempt. open(contact, 'w') b.update_routes() wvtest.WVFAIL(b.internet()) # Record success. open(connected, 'w') b.update_routes() wvtest.WVFAIL(b.internet()) # Disable the experiment and the connection check should pass again. experiment_testutils.disable('WifiSimulateWireless') b.update_routes() wvtest.WVPASS(b.internet()) # Reenable the experiment and the connection check should fail again. experiment_testutils.enable('WifiSimulateWireless') b.update_routes() wvtest.WVFAIL(b.internet()) # Wait until we've failed for long enough for the experiment to "expire", # then log another attempt without success. Make sure the connection check # passes. time.sleep(interface.MAX_ACS_FAILURE_S) open(contact, 'w') b.update_routes() wvtest.WVPASS(b.internet()) finally: shutil.rmtree(tmp_dir) shutil.rmtree(interface.CWMP_PATH)