-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathtest_commands_kernfs.py
More file actions
45 lines (36 loc) · 1.35 KB
/
test_commands_kernfs.py
File metadata and controls
45 lines (36 loc) · 1.35 KB
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
# -*- coding: utf-8 -*-
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
import unittest
import gdb
import io
import sys
from crash.commands.kernfs import KernfsCommand
from crash.commands import CommandLineError
class TestCommandsKernfs(unittest.TestCase):
def setUp(self):
self.stdout = sys.stdout
self.redirected = io.StringIO()
sys.stdout = self.redirected
self.command = KernfsCommand("kernfs")
self.kn_addr = int(gdb.lookup_symbol('sysfs_root_kn', None)[0].value())
def tearDown(self):
sys.stdout = self.stdout
def output(self):
return self.redirected.getvalue()
def output_lines(self):
output = self.output()
return len(output.split("\n")) - 1
def test_kernfs_empty(self):
"""`kernfs` raises CommandLineError"""
with self.assertRaises(CommandLineError):
self.command.invoke_uncaught("")
def test_kernfs_list(self):
"""`kernfs ls` produces valid output"""
self.command.invoke_uncaught(f"ls {self.kn_addr:x}")
# header + listing
self.assertTrue(self.output_lines() > 1)
def test_kernfs_list_recursive(self):
"""`kernfs ls` produces valid output"""
self.command.invoke_uncaught(f"ls -R 2 {self.kn_addr:x}")
# header + listing
self.assertTrue(self.output_lines() > 1)