summaryrefslogtreecommitdiff
path: root/emu_test/test_console/testcase_ping.py
blob: 322adb717ce2615b1e22b8941e7f1f8d977025fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""Tests for the ping command."""

import inspect
import time
import unittest

import testcase_base
from utils import util

CMD_PING = 'ping\n'
PING_RESPONSE = 'I am alive!.*\nOK'



class PingTest(testcase_base.BaseConsoleTest):
  """Tests for the ping command."""

  def __init__(self, method_name=None, avd=None):
    if method_name:
      super(PingTest, self).__init__(method_name)
    else:
      super(PingTest, self).__init__()
    self.avd = avd

  def _execute_command_and_verify(self, command, expected_output, assert_msg):
    """Executes console command and verify output.

    Args:
        command: Console command to be executed.
        expected_output: Expected console output.
        assert_msg: Assertion message.
    """
    is_command_successful, output = util.execute_console_command(
        self.telnet, command, expected_output)

    self.assert_cmd_successful(is_command_successful, assert_msg, False, '',
                               'Pattern:\n%s' % expected_output, output)

  def _auth_user_for_emulator_console(self):
    """Authorize user."""
    auth_token = util.get_auth_token()
    self.telnet = util.telnet_emulator()
    self.telnet.write('%s %s\n' % (util.AUTH, auth_token))
    util.wait_on_windows()
    if (not util.check_read_until(
        self.telnet.read_until(util.OK, util.TIMEOUT_S))):
      sys.exit(-1)

  def test_ping(self):
    """Test for command: ping

    Test Rail ID: ?
    Test steps:
      1. Launch an emulator avd
      2. From command prompt, run: ping
      3. Verify 1
      4. Copy the auth_token value from ~/.emulator_console_auth_token
      5. Run: auth auth_token
      6. Run: ping
      7. Verify 1
    Verify:
      1. The ping response is displayed
    """
    print 'Running test: %s' % (inspect.stack()[0][3])
    assert_msg = 'Failed to properly display the ping response.'
    self._execute_command_and_verify(CMD_PING, PING_RESPONSE, assert_msg)
    self._auth_user_for_emulator_console()
    self._execute_command_and_verify(CMD_PING, PING_RESPONSE, assert_msg)

if __name__ == '__main__':
  print '======= Ping Test ======='
  unittest.main()