blob: 88c8eb70f54aeb3508dda9c668f082b9a43b0c78 [file] [log] [blame]
Steven Rostedt60a11772008-05-12 21:20:44 +02001/* Include in trace.c */
2
3#include <linux/kthread.h>
Ingo Molnarc7aafc52008-05-12 21:20:45 +02004#include <linux/delay.h>
Steven Rostedt60a11772008-05-12 21:20:44 +02005
Ingo Molnare309b412008-05-12 21:20:51 +02006static inline int trace_valid_entry(struct trace_entry *entry)
Steven Rostedt60a11772008-05-12 21:20:44 +02007{
8 switch (entry->type) {
9 case TRACE_FN:
10 case TRACE_CTX:
Ingo Molnar57422792008-05-12 21:20:51 +020011 case TRACE_WAKE:
Steven Rostedtdd0e5452008-08-01 12:26:41 -040012 case TRACE_CONT:
Steven Rostedt06fa75a2008-05-12 21:20:54 +020013 case TRACE_STACK:
Steven Rostedtdd0e5452008-08-01 12:26:41 -040014 case TRACE_PRINT:
Steven Rostedt06fa75a2008-05-12 21:20:54 +020015 case TRACE_SPECIAL:
Steven Rostedt80e5ea42008-11-12 15:24:24 -050016 case TRACE_BRANCH:
Steven Rostedt60a11772008-05-12 21:20:44 +020017 return 1;
18 }
19 return 0;
20}
21
Steven Rostedt3928a8a2008-09-29 23:02:41 -040022static int trace_test_buffer_cpu(struct trace_array *tr, int cpu)
Steven Rostedt60a11772008-05-12 21:20:44 +020023{
Steven Rostedt3928a8a2008-09-29 23:02:41 -040024 struct ring_buffer_event *event;
25 struct trace_entry *entry;
Steven Rostedt60a11772008-05-12 21:20:44 +020026
Steven Rostedt3928a8a2008-09-29 23:02:41 -040027 while ((event = ring_buffer_consume(tr->buffer, cpu, NULL))) {
28 entry = ring_buffer_event_data(event);
Steven Rostedt60a11772008-05-12 21:20:44 +020029
Steven Rostedt3928a8a2008-09-29 23:02:41 -040030 if (!trace_valid_entry(entry)) {
Ingo Molnarc7aafc52008-05-12 21:20:45 +020031 printk(KERN_CONT ".. invalid entry %d ",
Steven Rostedt3928a8a2008-09-29 23:02:41 -040032 entry->type);
Steven Rostedt60a11772008-05-12 21:20:44 +020033 goto failed;
34 }
Steven Rostedt60a11772008-05-12 21:20:44 +020035 }
Steven Rostedt60a11772008-05-12 21:20:44 +020036 return 0;
37
38 failed:
Steven Rostedt08bafa02008-05-12 21:20:45 +020039 /* disable tracing */
40 tracing_disabled = 1;
Steven Rostedt60a11772008-05-12 21:20:44 +020041 printk(KERN_CONT ".. corrupted trace buffer .. ");
42 return -1;
43}
44
45/*
46 * Test the trace buffer to see if all the elements
47 * are still sane.
48 */
49static int trace_test_buffer(struct trace_array *tr, unsigned long *count)
50{
Steven Rostedt30afdcb2008-05-12 21:20:56 +020051 unsigned long flags, cnt = 0;
52 int cpu, ret = 0;
Steven Rostedt60a11772008-05-12 21:20:44 +020053
Steven Rostedt30afdcb2008-05-12 21:20:56 +020054 /* Don't allow flipping of max traces now */
Steven Rostedtd51ad7a2008-11-15 15:48:29 -050055 local_irq_save(flags);
Steven Rostedt30afdcb2008-05-12 21:20:56 +020056 __raw_spin_lock(&ftrace_max_lock);
Steven Rostedt3928a8a2008-09-29 23:02:41 -040057
58 cnt = ring_buffer_entries(tr->buffer);
59
Steven Rostedt60a11772008-05-12 21:20:44 +020060 for_each_possible_cpu(cpu) {
Steven Rostedt3928a8a2008-09-29 23:02:41 -040061 ret = trace_test_buffer_cpu(tr, cpu);
Steven Rostedt60a11772008-05-12 21:20:44 +020062 if (ret)
63 break;
64 }
Steven Rostedt30afdcb2008-05-12 21:20:56 +020065 __raw_spin_unlock(&ftrace_max_lock);
Steven Rostedtd51ad7a2008-11-15 15:48:29 -050066 local_irq_restore(flags);
Steven Rostedt60a11772008-05-12 21:20:44 +020067
68 if (count)
69 *count = cnt;
70
71 return ret;
72}
73
Frederic Weisbecker1c800252008-11-16 05:57:26 +010074static inline void warn_failed_init_tracer(struct tracer *trace, int init_ret)
75{
76 printk(KERN_WARNING "Failed to init %s tracer, init returned %d\n",
77 trace->name, init_ret);
78}
Steven Rostedt606576c2008-10-06 19:06:12 -040079#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedt77a2b372008-05-12 21:20:45 +020080
81#ifdef CONFIG_DYNAMIC_FTRACE
82
Steven Rostedt77a2b372008-05-12 21:20:45 +020083#define __STR(x) #x
84#define STR(x) __STR(x)
Steven Rostedt77a2b372008-05-12 21:20:45 +020085
86/* Test dynamic code modification and ftrace filters */
87int trace_selftest_startup_dynamic_tracing(struct tracer *trace,
88 struct trace_array *tr,
89 int (*func)(void))
90{
Steven Rostedt77a2b372008-05-12 21:20:45 +020091 int save_ftrace_enabled = ftrace_enabled;
92 int save_tracer_enabled = tracer_enabled;
Steven Rostedtdd0e5452008-08-01 12:26:41 -040093 unsigned long count;
Steven Rostedt4e491d12008-05-14 23:49:44 -040094 char *func_name;
Steven Rostedtdd0e5452008-08-01 12:26:41 -040095 int ret;
Steven Rostedt77a2b372008-05-12 21:20:45 +020096
97 /* The ftrace test PASSED */
98 printk(KERN_CONT "PASSED\n");
99 pr_info("Testing dynamic ftrace: ");
100
101 /* enable tracing, and record the filter function */
102 ftrace_enabled = 1;
103 tracer_enabled = 1;
104
105 /* passed in by parameter to fool gcc from optimizing */
106 func();
107
Steven Rostedt4e491d12008-05-14 23:49:44 -0400108 /*
109 * Some archs *cough*PowerPC*cough* add charachters to the
110 * start of the function names. We simply put a '*' to
111 * accomodate them.
112 */
113 func_name = "*" STR(DYN_FTRACE_TEST_NAME);
114
Steven Rostedt77a2b372008-05-12 21:20:45 +0200115 /* filter only on our function */
Steven Rostedt4e491d12008-05-14 23:49:44 -0400116 ftrace_set_filter(func_name, strlen(func_name), 1);
Steven Rostedt77a2b372008-05-12 21:20:45 +0200117
118 /* enable tracing */
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100119 ret = trace->init(tr);
120 if (ret) {
121 warn_failed_init_tracer(trace, ret);
122 goto out;
123 }
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400124
Steven Rostedt77a2b372008-05-12 21:20:45 +0200125 /* Sleep for a 1/10 of a second */
126 msleep(100);
127
128 /* we should have nothing in the buffer */
129 ret = trace_test_buffer(tr, &count);
130 if (ret)
131 goto out;
132
133 if (count) {
134 ret = -1;
135 printk(KERN_CONT ".. filter did not filter .. ");
136 goto out;
137 }
138
139 /* call our function again */
140 func();
141
142 /* sleep again */
143 msleep(100);
144
145 /* stop the tracing. */
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500146 tracing_stop();
Steven Rostedt77a2b372008-05-12 21:20:45 +0200147 ftrace_enabled = 0;
148
149 /* check the trace buffer */
150 ret = trace_test_buffer(tr, &count);
151 trace->reset(tr);
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500152 tracing_start();
Steven Rostedt77a2b372008-05-12 21:20:45 +0200153
154 /* we should only have one item */
155 if (!ret && count != 1) {
Steven Rostedt06fa75a2008-05-12 21:20:54 +0200156 printk(KERN_CONT ".. filter failed count=%ld ..", count);
Steven Rostedt77a2b372008-05-12 21:20:45 +0200157 ret = -1;
158 goto out;
159 }
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500160
Steven Rostedt77a2b372008-05-12 21:20:45 +0200161 out:
162 ftrace_enabled = save_ftrace_enabled;
163 tracer_enabled = save_tracer_enabled;
164
165 /* Enable tracing on all functions again */
166 ftrace_set_filter(NULL, 0, 1);
167
168 return ret;
169}
170#else
171# define trace_selftest_startup_dynamic_tracing(trace, tr, func) ({ 0; })
172#endif /* CONFIG_DYNAMIC_FTRACE */
Steven Rostedt60a11772008-05-12 21:20:44 +0200173/*
174 * Simple verification test of ftrace function tracer.
175 * Enable ftrace, sleep 1/10 second, and then read the trace
176 * buffer to see if all is in order.
177 */
178int
179trace_selftest_startup_function(struct tracer *trace, struct trace_array *tr)
180{
Steven Rostedt77a2b372008-05-12 21:20:45 +0200181 int save_ftrace_enabled = ftrace_enabled;
182 int save_tracer_enabled = tracer_enabled;
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400183 unsigned long count;
184 int ret;
Steven Rostedt60a11772008-05-12 21:20:44 +0200185
Steven Rostedt77a2b372008-05-12 21:20:45 +0200186 /* make sure msleep has been recorded */
187 msleep(1);
188
Steven Rostedt60a11772008-05-12 21:20:44 +0200189 /* start the tracing */
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200190 ftrace_enabled = 1;
Steven Rostedt77a2b372008-05-12 21:20:45 +0200191 tracer_enabled = 1;
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200192
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100193 ret = trace->init(tr);
194 if (ret) {
195 warn_failed_init_tracer(trace, ret);
196 goto out;
197 }
198
Steven Rostedt60a11772008-05-12 21:20:44 +0200199 /* Sleep for a 1/10 of a second */
200 msleep(100);
201 /* stop the tracing. */
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500202 tracing_stop();
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200203 ftrace_enabled = 0;
204
Steven Rostedt60a11772008-05-12 21:20:44 +0200205 /* check the trace buffer */
206 ret = trace_test_buffer(tr, &count);
207 trace->reset(tr);
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500208 tracing_start();
Steven Rostedt60a11772008-05-12 21:20:44 +0200209
210 if (!ret && !count) {
211 printk(KERN_CONT ".. no entries found ..");
212 ret = -1;
Steven Rostedt77a2b372008-05-12 21:20:45 +0200213 goto out;
Steven Rostedt60a11772008-05-12 21:20:44 +0200214 }
215
Steven Rostedt77a2b372008-05-12 21:20:45 +0200216 ret = trace_selftest_startup_dynamic_tracing(trace, tr,
217 DYN_FTRACE_TEST_NAME);
218
219 out:
220 ftrace_enabled = save_ftrace_enabled;
221 tracer_enabled = save_tracer_enabled;
222
Steven Rostedt4eebcc82008-05-12 21:20:48 +0200223 /* kill ftrace totally if we failed */
224 if (ret)
225 ftrace_kill();
226
Steven Rostedt60a11772008-05-12 21:20:44 +0200227 return ret;
228}
Steven Rostedt606576c2008-10-06 19:06:12 -0400229#endif /* CONFIG_FUNCTION_TRACER */
Steven Rostedt60a11772008-05-12 21:20:44 +0200230
231#ifdef CONFIG_IRQSOFF_TRACER
232int
233trace_selftest_startup_irqsoff(struct tracer *trace, struct trace_array *tr)
234{
235 unsigned long save_max = tracing_max_latency;
236 unsigned long count;
237 int ret;
238
239 /* start the tracing */
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100240 ret = trace->init(tr);
241 if (ret) {
242 warn_failed_init_tracer(trace, ret);
243 return ret;
244 }
245
Steven Rostedt60a11772008-05-12 21:20:44 +0200246 /* reset the max latency */
247 tracing_max_latency = 0;
248 /* disable interrupts for a bit */
249 local_irq_disable();
250 udelay(100);
251 local_irq_enable();
252 /* stop the tracing. */
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500253 tracing_stop();
Steven Rostedt60a11772008-05-12 21:20:44 +0200254 /* check both trace buffers */
255 ret = trace_test_buffer(tr, NULL);
256 if (!ret)
257 ret = trace_test_buffer(&max_tr, &count);
258 trace->reset(tr);
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500259 tracing_start();
Steven Rostedt60a11772008-05-12 21:20:44 +0200260
261 if (!ret && !count) {
262 printk(KERN_CONT ".. no entries found ..");
263 ret = -1;
264 }
265
266 tracing_max_latency = save_max;
267
268 return ret;
269}
270#endif /* CONFIG_IRQSOFF_TRACER */
271
272#ifdef CONFIG_PREEMPT_TRACER
273int
274trace_selftest_startup_preemptoff(struct tracer *trace, struct trace_array *tr)
275{
276 unsigned long save_max = tracing_max_latency;
277 unsigned long count;
278 int ret;
279
Steven Rostedt769c48e2008-11-07 22:36:02 -0500280 /*
281 * Now that the big kernel lock is no longer preemptable,
282 * and this is called with the BKL held, it will always
283 * fail. If preemption is already disabled, simply
284 * pass the test. When the BKL is removed, or becomes
285 * preemptible again, we will once again test this,
286 * so keep it in.
287 */
288 if (preempt_count()) {
289 printk(KERN_CONT "can not test ... force ");
290 return 0;
291 }
292
Steven Rostedt60a11772008-05-12 21:20:44 +0200293 /* start the tracing */
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100294 ret = trace->init(tr);
295 if (ret) {
296 warn_failed_init_tracer(trace, ret);
297 return ret;
298 }
299
Steven Rostedt60a11772008-05-12 21:20:44 +0200300 /* reset the max latency */
301 tracing_max_latency = 0;
302 /* disable preemption for a bit */
303 preempt_disable();
304 udelay(100);
305 preempt_enable();
306 /* stop the tracing. */
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500307 tracing_stop();
Steven Rostedt60a11772008-05-12 21:20:44 +0200308 /* check both trace buffers */
309 ret = trace_test_buffer(tr, NULL);
310 if (!ret)
311 ret = trace_test_buffer(&max_tr, &count);
312 trace->reset(tr);
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500313 tracing_start();
Steven Rostedt60a11772008-05-12 21:20:44 +0200314
315 if (!ret && !count) {
316 printk(KERN_CONT ".. no entries found ..");
317 ret = -1;
318 }
319
320 tracing_max_latency = save_max;
321
322 return ret;
323}
324#endif /* CONFIG_PREEMPT_TRACER */
325
326#if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
327int
328trace_selftest_startup_preemptirqsoff(struct tracer *trace, struct trace_array *tr)
329{
330 unsigned long save_max = tracing_max_latency;
331 unsigned long count;
332 int ret;
333
Steven Rostedt769c48e2008-11-07 22:36:02 -0500334 /*
335 * Now that the big kernel lock is no longer preemptable,
336 * and this is called with the BKL held, it will always
337 * fail. If preemption is already disabled, simply
338 * pass the test. When the BKL is removed, or becomes
339 * preemptible again, we will once again test this,
340 * so keep it in.
341 */
342 if (preempt_count()) {
343 printk(KERN_CONT "can not test ... force ");
344 return 0;
345 }
346
Steven Rostedt60a11772008-05-12 21:20:44 +0200347 /* start the tracing */
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100348 ret = trace->init(tr);
349 if (ret) {
350 warn_failed_init_tracer(trace, ret);
351 goto out;
352 }
Steven Rostedt60a11772008-05-12 21:20:44 +0200353
354 /* reset the max latency */
355 tracing_max_latency = 0;
356
357 /* disable preemption and interrupts for a bit */
358 preempt_disable();
359 local_irq_disable();
360 udelay(100);
361 preempt_enable();
362 /* reverse the order of preempt vs irqs */
363 local_irq_enable();
364
365 /* stop the tracing. */
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500366 tracing_stop();
Steven Rostedt60a11772008-05-12 21:20:44 +0200367 /* check both trace buffers */
368 ret = trace_test_buffer(tr, NULL);
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500369 if (ret) {
370 tracing_start();
Steven Rostedt60a11772008-05-12 21:20:44 +0200371 goto out;
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500372 }
Steven Rostedt60a11772008-05-12 21:20:44 +0200373
374 ret = trace_test_buffer(&max_tr, &count);
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500375 if (ret) {
376 tracing_start();
Steven Rostedt60a11772008-05-12 21:20:44 +0200377 goto out;
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500378 }
Steven Rostedt60a11772008-05-12 21:20:44 +0200379
380 if (!ret && !count) {
381 printk(KERN_CONT ".. no entries found ..");
382 ret = -1;
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500383 tracing_start();
Steven Rostedt60a11772008-05-12 21:20:44 +0200384 goto out;
385 }
386
387 /* do the test by disabling interrupts first this time */
388 tracing_max_latency = 0;
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500389 tracing_start();
Steven Rostedt60a11772008-05-12 21:20:44 +0200390 preempt_disable();
391 local_irq_disable();
392 udelay(100);
393 preempt_enable();
394 /* reverse the order of preempt vs irqs */
395 local_irq_enable();
396
397 /* stop the tracing. */
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500398 tracing_stop();
Steven Rostedt60a11772008-05-12 21:20:44 +0200399 /* check both trace buffers */
400 ret = trace_test_buffer(tr, NULL);
401 if (ret)
402 goto out;
403
404 ret = trace_test_buffer(&max_tr, &count);
405
406 if (!ret && !count) {
407 printk(KERN_CONT ".. no entries found ..");
408 ret = -1;
409 goto out;
410 }
411
412 out:
413 trace->reset(tr);
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500414 tracing_start();
Steven Rostedt60a11772008-05-12 21:20:44 +0200415 tracing_max_latency = save_max;
416
417 return ret;
418}
419#endif /* CONFIG_IRQSOFF_TRACER && CONFIG_PREEMPT_TRACER */
420
Steven Noonanfb1b6d82008-09-19 03:06:43 -0700421#ifdef CONFIG_NOP_TRACER
422int
423trace_selftest_startup_nop(struct tracer *trace, struct trace_array *tr)
424{
425 /* What could possibly go wrong? */
426 return 0;
427}
428#endif
429
Steven Rostedt60a11772008-05-12 21:20:44 +0200430#ifdef CONFIG_SCHED_TRACER
431static int trace_wakeup_test_thread(void *data)
432{
Steven Rostedt05bd68c2008-05-12 21:20:59 +0200433 /* Make this a RT thread, doesn't need to be too high */
434 struct sched_param param = { .sched_priority = 5 };
Steven Rostedt60a11772008-05-12 21:20:44 +0200435 struct completion *x = data;
436
Steven Rostedt05bd68c2008-05-12 21:20:59 +0200437 sched_setscheduler(current, SCHED_FIFO, &param);
Steven Rostedt60a11772008-05-12 21:20:44 +0200438
439 /* Make it know we have a new prio */
440 complete(x);
441
442 /* now go to sleep and let the test wake us up */
443 set_current_state(TASK_INTERRUPTIBLE);
444 schedule();
445
446 /* we are awake, now wait to disappear */
447 while (!kthread_should_stop()) {
448 /*
449 * This is an RT task, do short sleeps to let
450 * others run.
451 */
452 msleep(100);
453 }
454
455 return 0;
456}
457
458int
459trace_selftest_startup_wakeup(struct tracer *trace, struct trace_array *tr)
460{
461 unsigned long save_max = tracing_max_latency;
462 struct task_struct *p;
463 struct completion isrt;
464 unsigned long count;
465 int ret;
466
467 init_completion(&isrt);
468
469 /* create a high prio thread */
470 p = kthread_run(trace_wakeup_test_thread, &isrt, "ftrace-test");
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200471 if (IS_ERR(p)) {
Steven Rostedt60a11772008-05-12 21:20:44 +0200472 printk(KERN_CONT "Failed to create ftrace wakeup test thread ");
473 return -1;
474 }
475
476 /* make sure the thread is running at an RT prio */
477 wait_for_completion(&isrt);
478
479 /* start the tracing */
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100480 ret = trace->init(tr);
481 if (ret) {
482 warn_failed_init_tracer(trace, ret);
483 return ret;
484 }
485
Steven Rostedt60a11772008-05-12 21:20:44 +0200486 /* reset the max latency */
487 tracing_max_latency = 0;
488
489 /* sleep to let the RT thread sleep too */
490 msleep(100);
491
492 /*
493 * Yes this is slightly racy. It is possible that for some
494 * strange reason that the RT thread we created, did not
495 * call schedule for 100ms after doing the completion,
496 * and we do a wakeup on a task that already is awake.
497 * But that is extremely unlikely, and the worst thing that
498 * happens in such a case, is that we disable tracing.
499 * Honestly, if this race does happen something is horrible
500 * wrong with the system.
501 */
502
503 wake_up_process(p);
504
Steven Rostedt5aa60c62008-09-29 23:02:37 -0400505 /* give a little time to let the thread wake up */
506 msleep(100);
507
Steven Rostedt60a11772008-05-12 21:20:44 +0200508 /* stop the tracing. */
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500509 tracing_stop();
Steven Rostedt60a11772008-05-12 21:20:44 +0200510 /* check both trace buffers */
511 ret = trace_test_buffer(tr, NULL);
512 if (!ret)
513 ret = trace_test_buffer(&max_tr, &count);
514
515
516 trace->reset(tr);
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500517 tracing_start();
Steven Rostedt60a11772008-05-12 21:20:44 +0200518
519 tracing_max_latency = save_max;
520
521 /* kill the thread */
522 kthread_stop(p);
523
524 if (!ret && !count) {
525 printk(KERN_CONT ".. no entries found ..");
526 ret = -1;
527 }
528
529 return ret;
530}
531#endif /* CONFIG_SCHED_TRACER */
532
533#ifdef CONFIG_CONTEXT_SWITCH_TRACER
534int
535trace_selftest_startup_sched_switch(struct tracer *trace, struct trace_array *tr)
536{
537 unsigned long count;
538 int ret;
539
540 /* start the tracing */
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100541 ret = trace->init(tr);
542 if (ret) {
543 warn_failed_init_tracer(trace, ret);
544 return ret;
545 }
546
Steven Rostedt60a11772008-05-12 21:20:44 +0200547 /* Sleep for a 1/10 of a second */
548 msleep(100);
549 /* stop the tracing. */
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500550 tracing_stop();
Steven Rostedt60a11772008-05-12 21:20:44 +0200551 /* check the trace buffer */
552 ret = trace_test_buffer(tr, &count);
553 trace->reset(tr);
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500554 tracing_start();
Steven Rostedt60a11772008-05-12 21:20:44 +0200555
556 if (!ret && !count) {
557 printk(KERN_CONT ".. no entries found ..");
558 ret = -1;
559 }
560
561 return ret;
562}
563#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
Ingo Molnara6dd24f2008-05-12 21:20:47 +0200564
565#ifdef CONFIG_SYSPROF_TRACER
566int
567trace_selftest_startup_sysprof(struct tracer *trace, struct trace_array *tr)
568{
569 unsigned long count;
570 int ret;
571
572 /* start the tracing */
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100573 ret = trace->init(tr);
574 if (ret) {
575 warn_failed_init_tracer(trace, ret);
576 return 0;
577 }
578
Ingo Molnara6dd24f2008-05-12 21:20:47 +0200579 /* Sleep for a 1/10 of a second */
580 msleep(100);
581 /* stop the tracing. */
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500582 tracing_stop();
Ingo Molnara6dd24f2008-05-12 21:20:47 +0200583 /* check the trace buffer */
584 ret = trace_test_buffer(tr, &count);
585 trace->reset(tr);
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500586 tracing_start();
Ingo Molnara6dd24f2008-05-12 21:20:47 +0200587
Ingo Molnara6dd24f2008-05-12 21:20:47 +0200588 return ret;
589}
590#endif /* CONFIG_SYSPROF_TRACER */
Steven Rostedt80e5ea42008-11-12 15:24:24 -0500591
592#ifdef CONFIG_BRANCH_TRACER
593int
594trace_selftest_startup_branch(struct tracer *trace, struct trace_array *tr)
595{
596 unsigned long count;
597 int ret;
598
599 /* start the tracing */
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100600 ret = trace->init(tr);
601 if (ret) {
602 warn_failed_init_tracer(trace, ret);
603 return ret;
604 }
605
Steven Rostedt80e5ea42008-11-12 15:24:24 -0500606 /* Sleep for a 1/10 of a second */
607 msleep(100);
608 /* stop the tracing. */
609 tracing_stop();
610 /* check the trace buffer */
611 ret = trace_test_buffer(tr, &count);
612 trace->reset(tr);
613 tracing_start();
614
615 return ret;
616}
617#endif /* CONFIG_BRANCH_TRACER */