diff options
| -rw-r--r-- | meta/lib/oeqa/runtime/cases/ksample.py | 206 |
1 files changed, 206 insertions, 0 deletions
diff --git a/meta/lib/oeqa/runtime/cases/ksample.py b/meta/lib/oeqa/runtime/cases/ksample.py new file mode 100644 index 0000000000..260bc3cfbd --- /dev/null +++ b/meta/lib/oeqa/runtime/cases/ksample.py | |||
| @@ -0,0 +1,206 @@ | |||
| 1 | import os | ||
| 2 | import time | ||
| 3 | |||
| 4 | from oeqa.runtime.case import OERuntimeTestCase | ||
| 5 | from oeqa.core.decorator.depends import OETestDepends | ||
| 6 | from oeqa.core.decorator.oeid import OETestID | ||
| 7 | from oeqa.core.decorator.data import skipIfNotFeature | ||
| 8 | |||
| 9 | # need some kernel fragments | ||
| 10 | # echo "KERNEL_FEATURES_append += \" features\/kernel\-sample\/kernel\-sample.scc\"" >> local.conf | ||
| 11 | class KSample(OERuntimeTestCase): | ||
| 12 | def cmd_and_check(self, cmd='', match_string=''): | ||
| 13 | status, output = self.target.run(cmd) | ||
| 14 | if not match_string: | ||
| 15 | # send cmd | ||
| 16 | msg = '%s failed, %s' % (cmd, output) | ||
| 17 | self.assertEqual(status, 0, msg=msg) | ||
| 18 | else: | ||
| 19 | # check result | ||
| 20 | result = ("%s" % match_string) in output | ||
| 21 | self.assertTrue(result) | ||
| 22 | self.assertEqual(status, 0, cmd) | ||
| 23 | |||
| 24 | def check_config(self, config_opt=''): | ||
| 25 | cmd = "zcat /proc/config.gz | grep %s" % config_opt | ||
| 26 | status, output = self.target.run(cmd) | ||
| 27 | result = ("%s=y" % config_opt) in output | ||
| 28 | if not result: | ||
| 29 | self.skipTest("%s is not set" % config_opt) | ||
| 30 | |||
| 31 | def check_module_exist(self, path='', module_name=''): | ||
| 32 | status, output = self.target.run("uname -r") | ||
| 33 | cmd = "ls " + "/lib/modules/" + output + "/kernel/samples/" + path + module_name | ||
| 34 | status, output = self.target.run(cmd) | ||
| 35 | if status != 0: | ||
| 36 | error_info = module_name + "doesn't exist" | ||
| 37 | self.skipTest(error_info) | ||
| 38 | |||
| 39 | def kfifo_func(self, name=''): | ||
| 40 | module_prename = name + "-example" | ||
| 41 | module_name = name + "-example.ko" | ||
| 42 | sysmbol_name = name + "_example" | ||
| 43 | |||
| 44 | # make sure if module exists | ||
| 45 | self.check_module_exist("kfifo/", module_name) | ||
| 46 | # modprobe | ||
| 47 | self.cmd_and_check("modprobe %s" % module_prename) | ||
| 48 | # lsmod | ||
| 49 | self.cmd_and_check("lsmod | grep %s | cut -d\' \' -f1" % sysmbol_name, sysmbol_name) | ||
| 50 | # check result | ||
| 51 | self.cmd_and_check("dmesg | grep \"test passed\" ", "test passed") | ||
| 52 | # rmmod | ||
| 53 | self.cmd_and_check("rmmod %s" % module_prename) | ||
| 54 | |||
| 55 | def kprobe_func(self, name=''): | ||
| 56 | # check config | ||
| 57 | self.check_config("CONFIG_KPROBES") | ||
| 58 | |||
| 59 | module_prename = name + "_example" | ||
| 60 | module_name = name + "_example.ko" | ||
| 61 | sysmbol_name = module_prename | ||
| 62 | |||
| 63 | # make sure if module exists | ||
| 64 | self.check_module_exist("kprobes/", module_name) | ||
| 65 | # modprobe | ||
| 66 | self.cmd_and_check("modprobe %s" % module_prename) | ||
| 67 | # lsmod | ||
| 68 | self.cmd_and_check("lsmod | grep %s | cut -d\' \' -f1" % sysmbol_name, sysmbol_name) | ||
| 69 | # check result | ||
| 70 | self.cmd_and_check("dmesg | grep Planted | head -n10", "Planted") | ||
| 71 | # rmmod | ||
| 72 | self.cmd_and_check("rmmod %s" % module_prename) | ||
| 73 | |||
| 74 | def kobject_func(self, name=''): | ||
| 75 | module_prename = name + "_example" | ||
| 76 | module_name = name + "-example.ko" | ||
| 77 | sysmbol_name = module_prename | ||
| 78 | |||
| 79 | # make sure if module exists | ||
| 80 | self.check_module_exist("kobject/", module_name) | ||
| 81 | # modprobe | ||
| 82 | self.cmd_and_check("modprobe %s" % module_prename) | ||
| 83 | # lsmod | ||
| 84 | self.cmd_and_check("lsmod | grep %s | cut -d\' \' -f1" % sysmbol_name, sysmbol_name) | ||
| 85 | # check result | ||
| 86 | self.cmd_and_check("ls /sys/kernel/%s/" % sysmbol_name, "bar") | ||
| 87 | # rmmod | ||
| 88 | self.cmd_and_check("rmmod %s" % module_prename) | ||
| 89 | |||
| 90 | class KSampleTest(KSample): | ||
| 91 | # kfifo | ||
| 92 | @OETestDepends(['ssh.SSHTest.test_ssh']) | ||
| 93 | def test_kfifo_test(self): | ||
| 94 | index = ["dma", "bytestream", "inttype", "record"] | ||
| 95 | for i in index: | ||
| 96 | self.kfifo_func(i) | ||
| 97 | |||
| 98 | # kprobe | ||
| 99 | @OETestDepends(['ssh.SSHTest.test_ssh']) | ||
| 100 | def test_kprobe_test(self): | ||
| 101 | index = ["kprobe", "kretprobe"] | ||
| 102 | for i in index: | ||
| 103 | self.kprobe_func(i) | ||
| 104 | |||
| 105 | # kobject | ||
| 106 | @OETestDepends(['ssh.SSHTest.test_ssh']) | ||
| 107 | def test_kobject_test(self): | ||
| 108 | index = ["kobject", "kset"] | ||
| 109 | for i in index: | ||
| 110 | self.kobject_func(i) | ||
| 111 | |||
| 112 | #trace | ||
| 113 | @OETestDepends(['ssh.SSHTest.test_ssh']) | ||
| 114 | def test_trace_events(self): | ||
| 115 | # check config | ||
| 116 | self.check_config("CONFIG_TRACING_SUPPORT") | ||
| 117 | # make sure if module exists | ||
| 118 | self.check_module_exist("trace_events/", "trace-events-sample.ko") | ||
| 119 | # modprobe | ||
| 120 | self.cmd_and_check("modprobe trace-events-sample") | ||
| 121 | # lsmod | ||
| 122 | self.cmd_and_check("lsmod | grep trace_events_sample | cut -d\' \' -f1", "trace_events_sample") | ||
| 123 | # check dir | ||
| 124 | self.cmd_and_check("ls /sys/kernel/debug/tracing/events/ | grep sample-trace", "sample-trace") | ||
| 125 | # enable trace | ||
| 126 | self.cmd_and_check("echo 1 > /sys/kernel/debug/tracing/events/sample-trace/enable") | ||
| 127 | self.cmd_and_check("cat /sys/kernel/debug/tracing/events/sample-trace/enable") | ||
| 128 | # check result | ||
| 129 | self.cmd_and_check("cat /sys/kernel/debug/tracing/trace | grep hello | head -n1 | cut -d\':\' -f2", " foo_bar") | ||
| 130 | # disable trace | ||
| 131 | self.cmd_and_check("echo 0 > /sys/kernel/debug/tracing/events/sample-trace/enable") | ||
| 132 | # clean up trace | ||
| 133 | self.cmd_and_check("echo > /sys/kernel/debug/tracing/trace") | ||
| 134 | # rmmod | ||
| 135 | self.cmd_and_check("rmmod trace-events-sample") | ||
| 136 | |||
| 137 | @OETestDepends(['ssh.SSHTest.test_ssh']) | ||
| 138 | def test_trace_printk(self): | ||
| 139 | # check config | ||
| 140 | self.check_config("CONFIG_TRACING_SUPPORT") | ||
| 141 | # make sure if module exists | ||
| 142 | self.check_module_exist("trace_printk/", "trace-printk.ko") | ||
| 143 | # modprobe | ||
| 144 | self.cmd_and_check("modprobe trace-printk") | ||
| 145 | # lsmod | ||
| 146 | self.cmd_and_check("lsmod | grep trace_printk | cut -d\' \' -f1", "trace_printk") | ||
| 147 | # check result | ||
| 148 | self.cmd_and_check("cat /sys/kernel/debug/tracing/trace | grep trace_printk_irq_work | head -n1 | cut -d\':\' -f2", " trace_printk_irq_work") | ||
| 149 | # clean up trace | ||
| 150 | self.cmd_and_check("echo > /sys/kernel/debug/tracing/trace") | ||
| 151 | # rmmod | ||
| 152 | self.cmd_and_check("rmmod trace-printk") | ||
| 153 | |||
| 154 | # hw breakpoint | ||
| 155 | @OETestDepends(['ssh.SSHTest.test_ssh']) | ||
| 156 | def test_hw_breakpoint_example(self): | ||
| 157 | # check config | ||
| 158 | self.check_config("CONFIG_KALLSYMS_ALL") | ||
| 159 | # make sure if module exists | ||
| 160 | self.check_module_exist("hw_breakpoint/", "data_breakpoint.ko") | ||
| 161 | # modprobe | ||
| 162 | self.cmd_and_check("modprobe data_breakpoint") | ||
| 163 | # lsmod | ||
| 164 | self.cmd_and_check("lsmod | grep data_breakpoint | cut -d\' \' -f1", "data_breakpoint") | ||
| 165 | # check result | ||
| 166 | self.cmd_and_check("cat /var/log/messages | grep sample_hbp_handler", "sample_hbp_handler") | ||
| 167 | # rmmod | ||
| 168 | self.cmd_and_check("rmmod data_breakpoint") | ||
| 169 | |||
| 170 | @OETestDepends(['ssh.SSHTest.test_ssh']) | ||
| 171 | def test_configfs_sample(self): | ||
| 172 | # check config | ||
| 173 | status, ret = self.target.run('zcat /proc/config.gz | grep CONFIG_CONFIGFS_FS') | ||
| 174 | if not ["CONFIG_CONFIGFS_FS=m" in ret or "CONFIG_CONFIGFS_FS=y" in ret]: | ||
| 175 | self.skipTest("CONFIG error") | ||
| 176 | # make sure if module exists | ||
| 177 | self.check_module_exist("configfs/", "configfs_sample.ko") | ||
| 178 | # modprobe | ||
| 179 | self.cmd_and_check("modprobe configfs_sample") | ||
| 180 | # lsmod | ||
| 181 | self.cmd_and_check("lsmod | grep configfs_sample | cut -d\' \' -f1 | head -n1", "configfs_sample") | ||
| 182 | |||
| 183 | status = 1 | ||
| 184 | count = 0 | ||
| 185 | while status != 0: | ||
| 186 | time.sleep(1) | ||
| 187 | status, ret = self.target.run('cat /sys/kernel/config/01-childless/description') | ||
| 188 | count = count + 1 | ||
| 189 | if count > 200: | ||
| 190 | self.skipTest("Time out for check dir") | ||
| 191 | |||
| 192 | # rmmod | ||
| 193 | self.cmd_and_check("rmmod configfs_sample") | ||
| 194 | |||
| 195 | @OETestDepends(['ssh.SSHTest.test_ssh']) | ||
| 196 | def test_cn_test(self): | ||
| 197 | # make sure if module exists | ||
| 198 | self.check_module_exist("connector/", "cn_test.ko") | ||
| 199 | # modprobe | ||
| 200 | self.cmd_and_check("modprobe cn_test") | ||
| 201 | # lsmod | ||
| 202 | self.cmd_and_check("lsmod | grep cn_test | cut -d\' \' -f1", "cn_test") | ||
| 203 | # check result | ||
| 204 | self.cmd_and_check("cat /proc/net/connector | grep cn_test | head -n1 | cut -d\' \' -f1", "cn_test") | ||
| 205 | # rmmod | ||
| 206 | self.cmd_and_check("rmmod cn_test") | ||
