Skip to content

Commit e5189ca

Browse files
committed
filter command should always use quotes
1 parent 34d4ef9 commit e5189ca

File tree

5 files changed

+28
-23
lines changed

5 files changed

+28
-23
lines changed

sdb/commands/filter.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ class Filter(sdb.SingleInputCommand):
3030
EXAMPLES
3131
Print addresses greater than or equal to 4
3232
33-
sdb> addr 0 1 2 3 4 5 6 | filter obj >= 4
33+
sdb> addr 0 1 2 3 4 5 6 | filter "obj >= 4"
3434
(void *)0x4
3535
(void *)0x5
3636
(void *)0x6
3737
3838
Find the SPA object of the ZFS pool named "jax" and print its 'spa_name'
3939
40-
sdb> spa | filter obj.spa_name == "jax" | member spa_name
40+
sdb> spa | filter 'obj.spa_name == "jax"' | member spa_name
4141
(char [256])"jax"
4242
4343
Print the number of level 3 log statements in the kernel log buffer
4444
45-
sdb> dmesg | filter obj.level == 3 | count
45+
sdb> dmesg | filter 'obj.level == 3' | count
4646
(unsigned long long)24
4747
"""
4848
# pylint: disable=eval-used
@@ -52,7 +52,7 @@ class Filter(sdb.SingleInputCommand):
5252
@classmethod
5353
def _init_parser(cls, name: str) -> argparse.ArgumentParser:
5454
parser = super()._init_parser(name)
55-
parser.add_argument("expr", nargs=argparse.REMAINDER)
55+
parser.add_argument("expr", nargs=1)
5656
return parser
5757

5858
@staticmethod
@@ -63,17 +63,7 @@ def __init__(self,
6363
args: Optional[List[str]] = None,
6464
name: str = "_") -> None:
6565
super().__init__(args, name)
66-
if not self.args.expr:
67-
self.parser.error("no expression specified")
68-
69-
#
70-
# This is a stop-gap solution until we figure out
71-
# exactly how we want the filter command to behave.
72-
#
73-
if len(self.args.expr) == 1:
74-
self.expr = self.args.expr[0].split()
75-
else:
76-
self.expr = self.args.expr
66+
self.expr = self.args.expr[0].split()
7767

7868
index = None
7969
operators = ["==", "!=", ">", "<", ">=", "<="]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sdb: filter: 'spa_t' has no member 'bogus'

tests/integration/test_core_generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
# filter - no left-hand side
161161
"zfs_dbgmsg | filter '== obj'",
162162
# filter - no operator
163-
"zfs_dbgmsg | filter 'obj'"
163+
"zfs_dbgmsg | filter 'obj'",
164164
# filter - bogus member
165165
"spa rpool | filter 'obj.bogus == 1624'",
166166
# filter - bogus op

tests/unit/commands/test_filter.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,43 @@ def test_no_arg() -> None:
3030
invoke(MOCK_PROGRAM, [], line)
3131

3232

33+
def test_no_quotes_0() -> None:
34+
line = 'filter obj'
35+
36+
with pytest.raises(sdb.CommandInvalidInputError):
37+
invoke(MOCK_PROGRAM, [], line)
38+
39+
40+
def test_no_quotes_1() -> None:
41+
line = 'filter obj == 1'
42+
43+
with pytest.raises(sdb.CommandArgumentsError):
44+
invoke(MOCK_PROGRAM, [], line)
45+
46+
3347
def test_no_rhs() -> None:
34-
line = 'filter obj =='
48+
line = 'filter "obj =="'
3549

3650
with pytest.raises(sdb.CommandInvalidInputError):
3751
invoke(MOCK_PROGRAM, [], line)
3852

3953

4054
def test_no_lhs() -> None:
41-
line = 'filter == obj'
55+
line = 'filter "== obj"'
4256

4357
with pytest.raises(sdb.CommandInvalidInputError):
4458
invoke(MOCK_PROGRAM, [], line)
4559

4660

4761
def test_no_operator() -> None:
48-
line = 'filter obj'
62+
line = 'filter "obj"'
4963

5064
with pytest.raises(sdb.CommandInvalidInputError):
5165
invoke(MOCK_PROGRAM, [], line)
5266

5367

5468
def test_single_void_ptr_input_lhs_not_object() -> None:
55-
line = 'filter 0 == obj'
69+
line = 'filter "0 == obj"'
5670
objs = [drgn.Object(MOCK_PROGRAM, 'void *', value=0)]
5771

5872
with pytest.raises(sdb.CommandInvalidInputError):
@@ -77,23 +91,23 @@ def test_multi_void_ptr_input_value_match_ne() -> None:
7791

7892

7993
def test_char_array_input_object_match() -> None:
80-
line = 'filter obj == obj'
94+
line = 'filter "obj == obj"'
8195
objs = [drgn.Object(MOCK_PROGRAM, 'char [4]', value=b"foo")]
8296

8397
with pytest.raises(sdb.CommandError):
8498
invoke(MOCK_PROGRAM, objs, line)
8599

86100

87101
def test_struct_input_invalid_syntax() -> None:
88-
line = 'filter obj->ts_int == 1'
102+
line = 'filter "obj->ts_int == 1"'
89103
objs = [MOCK_PROGRAM["global_struct"]]
90104

91105
with pytest.raises(sdb.CommandEvalSyntaxError):
92106
invoke(MOCK_PROGRAM, objs, line)
93107

94108

95109
def test_struct_input_bogus_member() -> None:
96-
line = 'filter obj.ts_bogus == 1'
110+
line = 'filter "obj.ts_bogus == 1"'
97111
objs = [MOCK_PROGRAM["global_struct"]]
98112

99113
with pytest.raises(sdb.CommandError):

0 commit comments

Comments
 (0)