1 # Copyright 2016 The Chromium OS Authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 import requests 6 7 from autotest_lib.client.common_lib import error 8 from autotest_lib.client.common_lib import process_utils 9 from autotest_lib.client.common_lib.brillo import logcat_utils 10 from autotest_lib.server import test 11 12 13 _WEBSERVD_TEST_CLIENT = 'webservd_testc' 14 15 class brillo_WebservdSanity(test.test): 16 """Verify that webservd delegates requests to clients.""" 17 version = 1 18 19 def run_once(self, host=None): 20 """Body of the test.""" 21 # Kill anything the init system knows about and drop signals 22 # on everything else, until there is nothing left. 23 host.run('stop %s' % _WEBSERVD_TEST_CLIENT) 24 process_utils.pkill_process(_WEBSERVD_TEST_CLIENT, host=host) 25 # Start up a clean new instance and get its pid. 26 host.run('start %s' % _WEBSERVD_TEST_CLIENT) 27 pid = int(host.run('pgrep %s' % _WEBSERVD_TEST_CLIENT).stdout.strip()) 28 # Wait for the clean new instance to report it is connected to the 29 # webserver. 30 logcat_utils.wait_for_logcat_log( 31 '/system/bin/%s' % _WEBSERVD_TEST_CLIENT, 32 '.*Webserver is online.*', process_id=pid, host=host) 33 34 # Finally request a test page from our test client. 35 host.adb_run('forward tcp:8998 tcp:80') 36 r = requests.get('http://localhost:8998/webservd-test-client/ping') 37 if r.status_code != 200: 38 raise error.TestFail('Expected successful http request but ' 39 'status=%d' % r.status_code) 40 if r.text != 'Still alive, still alive!\n': 41 raise error.TestFail('Unexpected response: %s' % r.text) 42