|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: |
| 3 | +import unittest |
| 4 | +import gdb |
| 5 | +import io |
| 6 | +import sys |
| 7 | + |
| 8 | +from decorators import skip_without_symbol |
| 9 | +from decorators import skip_with_symbol |
| 10 | + |
| 11 | +from crash.commands.kmem import KmemCommand |
| 12 | +from crash.commands import CommandLineError, CommandError |
| 13 | + |
| 14 | +class TestCommandsKmem(unittest.TestCase): |
| 15 | + def setUp(self): |
| 16 | + self.stdout = sys.stdout |
| 17 | + sys.stdout = io.StringIO() |
| 18 | + self.command = KmemCommand("kmem") |
| 19 | + |
| 20 | + def tearDown(self): |
| 21 | + sys.stdout = self.stdout |
| 22 | + |
| 23 | + def output(self): |
| 24 | + return sys.stdout.getvalue() |
| 25 | + |
| 26 | + def test_kmem_empty(self): |
| 27 | + with self.assertRaises(CommandLineError): |
| 28 | + self.command.invoke_uncaught("") |
| 29 | + |
| 30 | + def test_kmem_invalid(self): |
| 31 | + """`kmem' returns error""" |
| 32 | + with self.assertRaises(CommandLineError): |
| 33 | + self.command.invoke_uncaught("invalid") |
| 34 | + |
| 35 | + @unittest.skip("takes a huge amount of time on a real core") |
| 36 | + def test_kmem_s(self): |
| 37 | + """`kmem -s' produces valid output""" |
| 38 | + self.command.invoke_uncaught("-s") |
| 39 | + output = self.output() |
| 40 | + self.assertTrue(len(output.split("\n")) > 2) |
| 41 | + |
| 42 | + def test_kmem_s_inode_cache(self): |
| 43 | + """`kmem -s inode_cache' produces valid output""" |
| 44 | + self.command.invoke_uncaught("-s inode_cache") |
| 45 | + output = self.output() |
| 46 | + self.assertTrue(len(output.split("\n")) > 2) |
| 47 | + |
| 48 | + def test_kmem_s_unknown_cache(self): |
| 49 | + """`kmem -s unknown_cache' raises CommandError""" |
| 50 | + with self.assertRaises(CommandError): |
| 51 | + self.command.invoke_uncaught("-s unknown_cache") |
| 52 | + |
| 53 | + def test_kmem_sz(self): |
| 54 | + """`kmem -s -z' raises CommandLineError""" |
| 55 | + with self.assertRaises(CommandLineError): |
| 56 | + self.command.invoke_uncaught("-s -z") |
| 57 | + |
| 58 | + def test_kmem_sz_valid_cache(self): |
| 59 | + """`kmem -s -z' raises CommandLineError""" |
| 60 | + with self.assertRaises(CommandLineError): |
| 61 | + self.command.invoke_uncaught("-s inode_cache -z") |
| 62 | + |
| 63 | + def test_kmem_sz_invalid_cache(self): |
| 64 | + """`kmem -s unknown_cache -z' raises CommandLineError""" |
| 65 | + with self.assertRaises(CommandLineError): |
| 66 | + self.command.invoke_uncaught("-s unknown_cache -z") |
| 67 | + |
| 68 | + def test_kmem_sv(self): |
| 69 | + """`kmem -s -V' raises CommandLineError""" |
| 70 | + with self.assertRaises(CommandLineError): |
| 71 | + self.command.invoke_uncaught("-s -V") |
| 72 | + |
| 73 | + def test_kmem_sv_valid_cache(self): |
| 74 | + """`kmem -s inode_cache -V' raises CommandLineError""" |
| 75 | + with self.assertRaises(CommandLineError): |
| 76 | + self.command.invoke_uncaught("-s inode_cache -V") |
| 77 | + |
| 78 | + def test_kmem_sv_invalid_cache(self): |
| 79 | + """`kmem -s unknown_cache -V' raises CommandLineError""" |
| 80 | + with self.assertRaises(CommandLineError): |
| 81 | + self.command.invoke_uncaught("-s unknown_cache -V") |
| 82 | + |
| 83 | + def test_kmem_z(self): |
| 84 | + """`kmem -z' produces valid output""" |
| 85 | + self.command.invoke_uncaught("-z") |
| 86 | + output = self.output() |
| 87 | + self.assertTrue(len(output.split("\n")) > 2) |
| 88 | + |
| 89 | + def test_kmem_z_invalid(self): |
| 90 | + """`kmem -z invalid' raises CommandLineError""" |
| 91 | + with self.assertRaises(CommandLineError): |
| 92 | + self.command.invoke_uncaught("-z invalid") |
| 93 | + |
| 94 | + @skip_without_symbol('vm_stat') |
| 95 | + def test_kmem_v(self): |
| 96 | + """`kmem -V' produces valid output""" |
| 97 | + self.command.invoke_uncaught("-V") |
| 98 | + output = self.output() |
| 99 | + self.assertTrue(len(output.split("\n")) > 0) |
| 100 | + |
| 101 | + @skip_with_symbol('vm_stat') |
| 102 | + def test_kmem_v_unimplemented(self): |
| 103 | + """`kmem -V' raises CommandError due to missing symbol""" |
| 104 | + with self.assertRaises(CommandError): |
| 105 | + self.command.invoke_uncaught("-V") |
| 106 | + |
| 107 | + def test_kmem_v_invalid(self): |
| 108 | + """`kmem -V invalid' raises CommandLineError""" |
| 109 | + with self.assertRaises(CommandLineError): |
| 110 | + self.command.invoke_uncaught("-V invalid") |
| 111 | + |
| 112 | + def test_kmem_vz(self): |
| 113 | + """`kmem -V -z' raises CommandLineError""" |
| 114 | + with self.assertRaises(CommandLineError): |
| 115 | + self.command.invoke_uncaught("-V -z") |
| 116 | + |
| 117 | + def test_kmem_svz(self): |
| 118 | + """`kmem -V -z -s' raises CommandLineError""" |
| 119 | + with self.assertRaises(CommandLineError): |
| 120 | + self.command.invoke_uncaught("-V -z -s") |
| 121 | + |
| 122 | + def test_kmem_svz_valid_cache(self): |
| 123 | + """`kmem -V -z -s inode_cache' raises CommandLineError""" |
| 124 | + with self.assertRaises(CommandLineError): |
| 125 | + self.command.invoke_uncaught("-V -z -s inode_cache") |
| 126 | + |
| 127 | + def test_kmem_svz_invalid_cache(self): |
| 128 | + """`kmem -V -z -s unknown_cache' raises CommandLineError""" |
| 129 | + with self.assertRaises(CommandLineError): |
| 130 | + self.command.invoke_uncaught("-V -z -s unknown_cache") |
0 commit comments