]> git.proxmox.com Git - ceph.git/blame - ceph/src/seastar/dpdk/test/cmdline_test/cmdline_test.py
update download target update for octopus release
[ceph.git] / ceph / src / seastar / dpdk / test / cmdline_test / cmdline_test.py
CommitLineData
11fdf7f2 1#!/usr/bin/env python
7c673cae
FG
2
3# BSD LICENSE
4#
5# Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
6# All rights reserved.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11#
12# * Redistributions of source code must retain the above copyright
13# notice, this list of conditions and the following disclaimer.
14# * Redistributions in binary form must reproduce the above copyright
15# notice, this list of conditions and the following disclaimer in
16# the documentation and/or other materials provided with the
17# distribution.
18# * Neither the name of Intel Corporation nor the names of its
19# contributors may be used to endorse or promote products derived
20# from this software without specific prior written permission.
21#
22# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34# Script that runs cmdline_test app and feeds keystrokes into it.
11fdf7f2
TL
35from __future__ import print_function
36import cmdline_test_data
37import os
38import pexpect
39import sys
7c673cae 40
7c673cae
FG
41
42#
43# function to run test
44#
11fdf7f2
TL
45def runTest(child, test):
46 child.send(test["Sequence"])
47 if test["Result"] is None:
48 return 0
49 child.expect(test["Result"], 1)
50
7c673cae
FG
51
52#
53# history test is a special case
54#
55# This test does the following:
56# 1) fills the history with garbage up to its full capacity
57# (just enough to remove last entry)
58# 2) scrolls back history to the very beginning
59# 3) checks if the output is as expected, that is, the first
60# number in the sequence (not the last entry before it)
61#
62# This is a self-contained test, it needs only a pexpect child
63#
64def runHistoryTest(child):
11fdf7f2
TL
65 # find out history size
66 child.sendline(cmdline_test_data.CMD_GET_BUFSIZE)
67 child.expect("History buffer size: \\d+", timeout=1)
68 history_size = int(child.after[len(cmdline_test_data.BUFSIZE_TEMPLATE):])
69 i = 0
7c673cae 70
11fdf7f2
TL
71 # fill the history with numbers
72 while i < history_size / 10:
73 # add 1 to prevent from parsing as octals
74 child.send("1" + str(i).zfill(8) + cmdline_test_data.ENTER)
75 # the app will simply print out the number
76 child.expect(str(i + 100000000), timeout=1)
77 i += 1
78 # scroll back history
79 child.send(cmdline_test_data.UP * (i + 2) + cmdline_test_data.ENTER)
80 child.expect("100000000", timeout=1)
7c673cae
FG
81
82# the path to cmdline_test executable is supplied via command-line.
83if len(sys.argv) < 2:
11fdf7f2
TL
84 print("Error: please supply cmdline_test app path")
85 sys.exit(1)
7c673cae
FG
86
87test_app_path = sys.argv[1]
88
89if not os.path.exists(test_app_path):
11fdf7f2
TL
90 print("Error: please supply cmdline_test app path")
91 sys.exit(1)
7c673cae
FG
92
93child = pexpect.spawn(test_app_path)
94
11fdf7f2 95print("Running command-line tests...")
7c673cae 96for test in cmdline_test_data.tests:
11fdf7f2
TL
97 testname = (test["Name"] + ":").ljust(30)
98 try:
99 runTest(child, test)
100 print(testname, "PASS")
101 except:
102 print(testname, "FAIL")
103 print(child)
104 sys.exit(1)
7c673cae
FG
105
106# since last test quits the app, run new instance
107child = pexpect.spawn(test_app_path)
108
11fdf7f2 109testname = ("History fill test:").ljust(30)
7c673cae 110try:
11fdf7f2
TL
111 runHistoryTest(child)
112 print(testname, "PASS")
7c673cae 113except:
11fdf7f2
TL
114 print(testname, "FAIL")
115 print(child)
116 sys.exit(1)
7c673cae
FG
117child.close()
118sys.exit(0)