diff options
author | Paul Mundt <lethal@linux-sh.org> | 2012-01-17 07:55:28 -0500 |
---|---|---|
committer | Paul Mundt <lethal@linux-sh.org> | 2012-01-17 07:55:28 -0500 |
commit | 0c929238ca4baefe47f4034732db4c154f2329c6 (patch) | |
tree | 2636079800fa045501982a70e1be0425c1b968c2 /tools | |
parent | 6d7120a713300283a8b73e7d86cd1bab8b9d1971 (diff) | |
parent | 78da107a7ed14fbc6ef77ff4c41d92b11edc9036 (diff) |
Merge branch 'sh/platform-updates' into sh-latest
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/nfsd/inject_fault.sh | 49 | ||||
-rw-r--r-- | tools/perf/Documentation/perf-list.txt | 2 | ||||
-rw-r--r-- | tools/perf/MANIFEST | 1 | ||||
-rw-r--r-- | tools/perf/builtin-annotate.c | 7 | ||||
-rw-r--r-- | tools/perf/builtin-kmem.c | 3 | ||||
-rw-r--r-- | tools/perf/builtin-kvm.c | 6 | ||||
-rw-r--r-- | tools/perf/builtin-script.c | 4 | ||||
-rw-r--r-- | tools/perf/builtin-test.c | 2 | ||||
-rw-r--r-- | tools/perf/builtin-top.c | 5 | ||||
-rw-r--r-- | tools/perf/util/evlist.c | 5 | ||||
-rw-r--r-- | tools/perf/util/hist.c | 131 | ||||
-rw-r--r-- | tools/perf/util/hist.h | 7 | ||||
-rw-r--r-- | tools/perf/util/parse-events.c | 15 | ||||
-rw-r--r-- | tools/perf/util/trace-event-info.c | 1 | ||||
-rw-r--r-- | tools/perf/util/util.c | 15 | ||||
-rw-r--r-- | tools/perf/util/util.h | 4 | ||||
-rwxr-xr-x | tools/testing/ktest/compare-ktest-sample.pl | 4 | ||||
-rwxr-xr-x | tools/testing/ktest/ktest.pl | 682 | ||||
-rw-r--r-- | tools/testing/ktest/sample.conf | 87 | ||||
-rw-r--r-- | tools/testing/selftests/Makefile | 11 | ||||
-rw-r--r-- | tools/testing/selftests/breakpoints/Makefile | 20 | ||||
-rw-r--r-- | tools/testing/selftests/breakpoints/breakpoint_test.c | 394 | ||||
-rw-r--r-- | tools/testing/selftests/run_tests | 8 |
23 files changed, 1187 insertions, 276 deletions
diff --git a/tools/nfsd/inject_fault.sh b/tools/nfsd/inject_fault.sh new file mode 100755 index 000000000000..06a399ac8b2f --- /dev/null +++ b/tools/nfsd/inject_fault.sh | |||
@@ -0,0 +1,49 @@ | |||
1 | #!/bin/bash | ||
2 | # | ||
3 | # Copyright (c) 2011 Bryan Schumaker <bjschuma@netapp.com> | ||
4 | # | ||
5 | # Script for easier NFSD fault injection | ||
6 | |||
7 | # Check that debugfs has been mounted | ||
8 | DEBUGFS=`cat /proc/mounts | grep debugfs` | ||
9 | if [ "$DEBUGFS" == "" ]; then | ||
10 | echo "debugfs does not appear to be mounted!" | ||
11 | echo "Please mount debugfs and try again" | ||
12 | exit 1 | ||
13 | fi | ||
14 | |||
15 | # Check that the fault injection directory exists | ||
16 | DEBUGDIR=`echo $DEBUGFS | awk '{print $2}'`/nfsd | ||
17 | if [ ! -d "$DEBUGDIR" ]; then | ||
18 | echo "$DEBUGDIR does not exist" | ||
19 | echo "Check that your .config selects CONFIG_NFSD_FAULT_INJECTION" | ||
20 | exit 1 | ||
21 | fi | ||
22 | |||
23 | function help() | ||
24 | { | ||
25 | echo "Usage $0 injection_type [count]" | ||
26 | echo "" | ||
27 | echo "Injection types are:" | ||
28 | ls $DEBUGDIR | ||
29 | exit 1 | ||
30 | } | ||
31 | |||
32 | if [ $# == 0 ]; then | ||
33 | help | ||
34 | elif [ ! -f $DEBUGDIR/$1 ]; then | ||
35 | help | ||
36 | elif [ $# != 2 ]; then | ||
37 | COUNT=0 | ||
38 | else | ||
39 | COUNT=$2 | ||
40 | fi | ||
41 | |||
42 | BEFORE=`mktemp` | ||
43 | AFTER=`mktemp` | ||
44 | dmesg > $BEFORE | ||
45 | echo $COUNT > $DEBUGDIR/$1 | ||
46 | dmesg > $AFTER | ||
47 | # Capture lines that only exist in the $AFTER file | ||
48 | diff $BEFORE $AFTER | grep ">" | ||
49 | rm -f $BEFORE $AFTER | ||
diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentation/perf-list.txt index 7a527f7e9da9..ddc22525228d 100644 --- a/tools/perf/Documentation/perf-list.txt +++ b/tools/perf/Documentation/perf-list.txt | |||
@@ -21,6 +21,8 @@ EVENT MODIFIERS | |||
21 | Events can optionally have a modifer by appending a colon and one or | 21 | Events can optionally have a modifer by appending a colon and one or |
22 | more modifiers. Modifiers allow the user to restrict when events are | 22 | more modifiers. Modifiers allow the user to restrict when events are |
23 | counted with 'u' for user-space, 'k' for kernel, 'h' for hypervisor. | 23 | counted with 'u' for user-space, 'k' for kernel, 'h' for hypervisor. |
24 | Additional modifiers are 'G' for guest counting (in KVM guests) and 'H' | ||
25 | for host counting (not in KVM guests). | ||
24 | 26 | ||
25 | The 'p' modifier can be used for specifying how precise the instruction | 27 | The 'p' modifier can be used for specifying how precise the instruction |
26 | address should be. The 'p' modifier is currently only implemented for | 28 | address should be. The 'p' modifier is currently only implemented for |
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST index c12659d8cb26..1078c5fadd5b 100644 --- a/tools/perf/MANIFEST +++ b/tools/perf/MANIFEST | |||
@@ -1,4 +1,5 @@ | |||
1 | tools/perf | 1 | tools/perf |
2 | include/linux/const.h | ||
2 | include/linux/perf_event.h | 3 | include/linux/perf_event.h |
3 | include/linux/rbtree.h | 4 | include/linux/rbtree.h |
4 | include/linux/list.h | 5 | include/linux/list.h |
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 214ba7f9f577..806e0a286634 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
@@ -235,7 +235,7 @@ out_delete: | |||
235 | } | 235 | } |
236 | 236 | ||
237 | static const char * const annotate_usage[] = { | 237 | static const char * const annotate_usage[] = { |
238 | "perf annotate [<options>] <command>", | 238 | "perf annotate [<options>]", |
239 | NULL | 239 | NULL |
240 | }; | 240 | }; |
241 | 241 | ||
@@ -313,10 +313,5 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __used) | |||
313 | annotate.sym_hist_filter = argv[0]; | 313 | annotate.sym_hist_filter = argv[0]; |
314 | } | 314 | } |
315 | 315 | ||
316 | if (field_sep && *field_sep == '.') { | ||
317 | pr_err("'.' is the only non valid --field-separator argument\n"); | ||
318 | return -1; | ||
319 | } | ||
320 | |||
321 | return __cmd_annotate(&annotate); | 316 | return __cmd_annotate(&annotate); |
322 | } | 317 | } |
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index fe1ad8f21961..39104c0beea3 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c | |||
@@ -108,7 +108,9 @@ static void setup_cpunode_map(void) | |||
108 | continue; | 108 | continue; |
109 | cpunode_map[cpu] = mem; | 109 | cpunode_map[cpu] = mem; |
110 | } | 110 | } |
111 | closedir(dir2); | ||
111 | } | 112 | } |
113 | closedir(dir1); | ||
112 | } | 114 | } |
113 | 115 | ||
114 | static void insert_alloc_stat(unsigned long call_site, unsigned long ptr, | 116 | static void insert_alloc_stat(unsigned long call_site, unsigned long ptr, |
@@ -645,6 +647,7 @@ static int setup_sorting(struct list_head *sort_list, const char *arg) | |||
645 | break; | 647 | break; |
646 | if (sort_dimension__add(tok, sort_list) < 0) { | 648 | if (sort_dimension__add(tok, sort_list) < 0) { |
647 | error("Unknown --sort key: '%s'", tok); | 649 | error("Unknown --sort key: '%s'", tok); |
650 | free(str); | ||
648 | return -1; | 651 | return -1; |
649 | } | 652 | } |
650 | } | 653 | } |
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 032324a76b87..9fc6e0fa3dce 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c | |||
@@ -22,9 +22,6 @@ | |||
22 | static const char *file_name; | 22 | static const char *file_name; |
23 | static char name_buffer[256]; | 23 | static char name_buffer[256]; |
24 | 24 | ||
25 | bool perf_host = 1; | ||
26 | bool perf_guest; | ||
27 | |||
28 | static const char * const kvm_usage[] = { | 25 | static const char * const kvm_usage[] = { |
29 | "perf kvm [<options>] {top|record|report|diff|buildid-list}", | 26 | "perf kvm [<options>] {top|record|report|diff|buildid-list}", |
30 | NULL | 27 | NULL |
@@ -107,7 +104,8 @@ static int __cmd_buildid_list(int argc, const char **argv) | |||
107 | 104 | ||
108 | int cmd_kvm(int argc, const char **argv, const char *prefix __used) | 105 | int cmd_kvm(int argc, const char **argv, const char *prefix __used) |
109 | { | 106 | { |
110 | perf_host = perf_guest = 0; | 107 | perf_host = 0; |
108 | perf_guest = 1; | ||
111 | 109 | ||
112 | argc = parse_options(argc, argv, kvm_options, kvm_usage, | 110 | argc = parse_options(argc, argv, kvm_options, kvm_usage, |
113 | PARSE_OPT_STOP_AT_NON_OPTION); | 111 | PARSE_OPT_STOP_AT_NON_OPTION); |
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index fd1909afcfd6..bb68ddf257b7 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
@@ -1018,13 +1018,17 @@ static char *get_script_path(const char *script_root, const char *suffix) | |||
1018 | __script_root = get_script_root(&script_dirent, suffix); | 1018 | __script_root = get_script_root(&script_dirent, suffix); |
1019 | if (__script_root && !strcmp(script_root, __script_root)) { | 1019 | if (__script_root && !strcmp(script_root, __script_root)) { |
1020 | free(__script_root); | 1020 | free(__script_root); |
1021 | closedir(lang_dir); | ||
1022 | closedir(scripts_dir); | ||
1021 | snprintf(script_path, MAXPATHLEN, "%s/%s", | 1023 | snprintf(script_path, MAXPATHLEN, "%s/%s", |
1022 | lang_path, script_dirent.d_name); | 1024 | lang_path, script_dirent.d_name); |
1023 | return strdup(script_path); | 1025 | return strdup(script_path); |
1024 | } | 1026 | } |
1025 | free(__script_root); | 1027 | free(__script_root); |
1026 | } | 1028 | } |
1029 | closedir(lang_dir); | ||
1027 | } | 1030 | } |
1031 | closedir(scripts_dir); | ||
1028 | 1032 | ||
1029 | return NULL; | 1033 | return NULL; |
1030 | } | 1034 | } |
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c index 2b9a7f497a20..3854e869dce1 100644 --- a/tools/perf/builtin-test.c +++ b/tools/perf/builtin-test.c | |||
@@ -1396,7 +1396,7 @@ int cmd_test(int argc, const char **argv, const char *prefix __used) | |||
1396 | NULL, | 1396 | NULL, |
1397 | }; | 1397 | }; |
1398 | const struct option test_options[] = { | 1398 | const struct option test_options[] = { |
1399 | OPT_INTEGER('v', "verbose", &verbose, | 1399 | OPT_INCR('v', "verbose", &verbose, |
1400 | "be more verbose (show symbol address, etc)"), | 1400 | "be more verbose (show symbol address, etc)"), |
1401 | OPT_END() | 1401 | OPT_END() |
1402 | }; | 1402 | }; |
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 4f81eeb99875..8f80df896038 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
@@ -235,7 +235,6 @@ static struct hist_entry *perf_evsel__add_hist_entry(struct perf_evsel *evsel, | |||
235 | if (he == NULL) | 235 | if (he == NULL) |
236 | return NULL; | 236 | return NULL; |
237 | 237 | ||
238 | evsel->hists.stats.total_period += sample->period; | ||
239 | hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); | 238 | hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); |
240 | return he; | 239 | return he; |
241 | } | 240 | } |
@@ -889,6 +888,10 @@ try_again: | |||
889 | ui__warning("The %s event is not supported.\n", | 888 | ui__warning("The %s event is not supported.\n", |
890 | event_name(counter)); | 889 | event_name(counter)); |
891 | goto out_err; | 890 | goto out_err; |
891 | } else if (err == EMFILE) { | ||
892 | ui__warning("Too many events are opened.\n" | ||
893 | "Try again after reducing the number of events\n"); | ||
894 | goto out_err; | ||
892 | } | 895 | } |
893 | 896 | ||
894 | ui__warning("The sys_perf_event_open() syscall " | 897 | ui__warning("The sys_perf_event_open() syscall " |
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index fa1837088ca8..3f16e08a5c8d 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -111,8 +111,11 @@ int perf_evlist__add_default(struct perf_evlist *evlist) | |||
111 | .type = PERF_TYPE_HARDWARE, | 111 | .type = PERF_TYPE_HARDWARE, |
112 | .config = PERF_COUNT_HW_CPU_CYCLES, | 112 | .config = PERF_COUNT_HW_CPU_CYCLES, |
113 | }; | 113 | }; |
114 | struct perf_evsel *evsel = perf_evsel__new(&attr, 0); | 114 | struct perf_evsel *evsel; |
115 | |||
116 | event_attr_init(&attr); | ||
115 | 117 | ||
118 | evsel = perf_evsel__new(&attr, 0); | ||
116 | if (evsel == NULL) | 119 | if (evsel == NULL) |
117 | goto error; | 120 | goto error; |
118 | 121 | ||
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index abef2703cd24..6f505d1abac7 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -76,21 +76,21 @@ static void hists__calc_col_len(struct hists *hists, struct hist_entry *h) | |||
76 | } | 76 | } |
77 | } | 77 | } |
78 | 78 | ||
79 | static void hist_entry__add_cpumode_period(struct hist_entry *self, | 79 | static void hist_entry__add_cpumode_period(struct hist_entry *he, |
80 | unsigned int cpumode, u64 period) | 80 | unsigned int cpumode, u64 period) |
81 | { | 81 | { |
82 | switch (cpumode) { | 82 | switch (cpumode) { |
83 | case PERF_RECORD_MISC_KERNEL: | 83 | case PERF_RECORD_MISC_KERNEL: |
84 | self->period_sys += period; | 84 | he->period_sys += period; |
85 | break; | 85 | break; |
86 | case PERF_RECORD_MISC_USER: | 86 | case PERF_RECORD_MISC_USER: |
87 | self->period_us += period; | 87 | he->period_us += period; |
88 | break; | 88 | break; |
89 | case PERF_RECORD_MISC_GUEST_KERNEL: | 89 | case PERF_RECORD_MISC_GUEST_KERNEL: |
90 | self->period_guest_sys += period; | 90 | he->period_guest_sys += period; |
91 | break; | 91 | break; |
92 | case PERF_RECORD_MISC_GUEST_USER: | 92 | case PERF_RECORD_MISC_GUEST_USER: |
93 | self->period_guest_us += period; | 93 | he->period_guest_us += period; |
94 | break; | 94 | break; |
95 | default: | 95 | default: |
96 | break; | 96 | break; |
@@ -165,18 +165,18 @@ void hists__decay_entries_threaded(struct hists *hists, | |||
165 | static struct hist_entry *hist_entry__new(struct hist_entry *template) | 165 | static struct hist_entry *hist_entry__new(struct hist_entry *template) |
166 | { | 166 | { |
167 | size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_root) : 0; | 167 | size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_root) : 0; |
168 | struct hist_entry *self = malloc(sizeof(*self) + callchain_size); | 168 | struct hist_entry *he = malloc(sizeof(*he) + callchain_size); |
169 | 169 | ||
170 | if (self != NULL) { | 170 | if (he != NULL) { |
171 | *self = *template; | 171 | *he = *template; |
172 | self->nr_events = 1; | 172 | he->nr_events = 1; |
173 | if (self->ms.map) | 173 | if (he->ms.map) |
174 | self->ms.map->referenced = true; | 174 | he->ms.map->referenced = true; |
175 | if (symbol_conf.use_callchain) | 175 | if (symbol_conf.use_callchain) |
176 | callchain_init(self->callchain); | 176 | callchain_init(he->callchain); |
177 | } | 177 | } |
178 | 178 | ||
179 | return self; | 179 | return he; |
180 | } | 180 | } |
181 | 181 | ||
182 | static void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h) | 182 | static void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h) |
@@ -677,15 +677,16 @@ static size_t callchain__fprintf_flat(FILE *fp, struct callchain_node *self, | |||
677 | return ret; | 677 | return ret; |
678 | } | 678 | } |
679 | 679 | ||
680 | static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self, | 680 | static size_t hist_entry_callchain__fprintf(struct hist_entry *he, |
681 | u64 total_samples, int left_margin) | 681 | u64 total_samples, int left_margin, |
682 | FILE *fp) | ||
682 | { | 683 | { |
683 | struct rb_node *rb_node; | 684 | struct rb_node *rb_node; |
684 | struct callchain_node *chain; | 685 | struct callchain_node *chain; |
685 | size_t ret = 0; | 686 | size_t ret = 0; |
686 | u32 entries_printed = 0; | 687 | u32 entries_printed = 0; |
687 | 688 | ||
688 | rb_node = rb_first(&self->sorted_chain); | 689 | rb_node = rb_first(&he->sorted_chain); |
689 | while (rb_node) { | 690 | while (rb_node) { |
690 | double percent; | 691 | double percent; |
691 | 692 | ||
@@ -730,35 +731,35 @@ void hists__output_recalc_col_len(struct hists *hists, int max_rows) | |||
730 | } | 731 | } |
731 | } | 732 | } |
732 | 733 | ||
733 | static int hist_entry__pcnt_snprintf(struct hist_entry *self, char *s, | 734 | static int hist_entry__pcnt_snprintf(struct hist_entry *he, char *s, |
734 | size_t size, struct hists *pair_hists, | 735 | size_t size, struct hists *pair_hists, |
735 | bool show_displacement, long displacement, | 736 | bool show_displacement, long displacement, |
736 | bool color, u64 session_total) | 737 | bool color, u64 total_period) |
737 | { | 738 | { |
738 | u64 period, total, period_sys, period_us, period_guest_sys, period_guest_us; | 739 | u64 period, total, period_sys, period_us, period_guest_sys, period_guest_us; |
739 | u64 nr_events; | 740 | u64 nr_events; |
740 | const char *sep = symbol_conf.field_sep; | 741 | const char *sep = symbol_conf.field_sep; |
741 | int ret; | 742 | int ret; |
742 | 743 | ||
743 | if (symbol_conf.exclude_other && !self->parent) | 744 | if (symbol_conf.exclude_other && !he->parent) |
744 | return 0; | 745 | return 0; |
745 | 746 | ||
746 | if (pair_hists) { | 747 | if (pair_hists) { |
747 | period = self->pair ? self->pair->period : 0; | 748 | period = he->pair ? he->pair->period : 0; |
748 | nr_events = self->pair ? self->pair->nr_events : 0; | 749 | nr_events = he->pair ? he->pair->nr_events : 0; |
749 | total = pair_hists->stats.total_period; | 750 | total = pair_hists->stats.total_period; |
750 | period_sys = self->pair ? self->pair->period_sys : 0; | 751 | period_sys = he->pair ? he->pair->period_sys : 0; |
751 | period_us = self->pair ? self->pair->period_us : 0; | 752 | period_us = he->pair ? he->pair->period_us : 0; |
752 | period_guest_sys = self->pair ? self->pair->period_guest_sys : 0; | 753 | period_guest_sys = he->pair ? he->pair->period_guest_sys : 0; |
753 | period_guest_us = self->pair ? self->pair->period_guest_us : 0; | 754 | period_guest_us = he->pair ? he->pair->period_guest_us : 0; |
754 | } else { | 755 | } else { |
755 | period = self->period; | 756 | period = he->period; |
756 | nr_events = self->nr_events; | 757 | nr_events = he->nr_events; |
757 | total = session_total; | 758 | total = total_period; |
758 | period_sys = self->period_sys; | 759 | period_sys = he->period_sys; |
759 | period_us = self->period_us; | 760 | period_us = he->period_us; |
760 | period_guest_sys = self->period_guest_sys; | 761 | period_guest_sys = he->period_guest_sys; |
761 | period_guest_us = self->period_guest_us; | 762 | period_guest_us = he->period_guest_us; |
762 | } | 763 | } |
763 | 764 | ||
764 | if (total) { | 765 | if (total) { |
@@ -812,8 +813,8 @@ static int hist_entry__pcnt_snprintf(struct hist_entry *self, char *s, | |||
812 | 813 | ||
813 | if (total > 0) | 814 | if (total > 0) |
814 | old_percent = (period * 100.0) / total; | 815 | old_percent = (period * 100.0) / total; |
815 | if (session_total > 0) | 816 | if (total_period > 0) |
816 | new_percent = (self->period * 100.0) / session_total; | 817 | new_percent = (he->period * 100.0) / total_period; |
817 | 818 | ||
818 | diff = new_percent - old_percent; | 819 | diff = new_percent - old_percent; |
819 | 820 | ||
@@ -862,9 +863,10 @@ int hist_entry__snprintf(struct hist_entry *he, char *s, size_t size, | |||
862 | return ret; | 863 | return ret; |
863 | } | 864 | } |
864 | 865 | ||
865 | int hist_entry__fprintf(struct hist_entry *he, size_t size, struct hists *hists, | 866 | static int hist_entry__fprintf(struct hist_entry *he, size_t size, |
866 | struct hists *pair_hists, bool show_displacement, | 867 | struct hists *hists, struct hists *pair_hists, |
867 | long displacement, FILE *fp, u64 session_total) | 868 | bool show_displacement, long displacement, |
869 | u64 total_period, FILE *fp) | ||
868 | { | 870 | { |
869 | char bf[512]; | 871 | char bf[512]; |
870 | int ret; | 872 | int ret; |
@@ -874,14 +876,14 @@ int hist_entry__fprintf(struct hist_entry *he, size_t size, struct hists *hists, | |||
874 | 876 | ||
875 | ret = hist_entry__pcnt_snprintf(he, bf, size, pair_hists, | 877 | ret = hist_entry__pcnt_snprintf(he, bf, size, pair_hists, |
876 | show_displacement, displacement, | 878 | show_displacement, displacement, |
877 | true, session_total); | 879 | true, total_period); |
878 | hist_entry__snprintf(he, bf + ret, size - ret, hists); | 880 | hist_entry__snprintf(he, bf + ret, size - ret, hists); |
879 | return fprintf(fp, "%s\n", bf); | 881 | return fprintf(fp, "%s\n", bf); |
880 | } | 882 | } |
881 | 883 | ||
882 | static size_t hist_entry__fprintf_callchain(struct hist_entry *self, | 884 | static size_t hist_entry__fprintf_callchain(struct hist_entry *he, |
883 | struct hists *hists, FILE *fp, | 885 | struct hists *hists, |
884 | u64 session_total) | 886 | u64 total_period, FILE *fp) |
885 | { | 887 | { |
886 | int left_margin = 0; | 888 | int left_margin = 0; |
887 | 889 | ||
@@ -889,11 +891,10 @@ static size_t hist_entry__fprintf_callchain(struct hist_entry *self, | |||
889 | struct sort_entry *se = list_first_entry(&hist_entry__sort_list, | 891 | struct sort_entry *se = list_first_entry(&hist_entry__sort_list, |
890 | typeof(*se), list); | 892 | typeof(*se), list); |
891 | left_margin = hists__col_len(hists, se->se_width_idx); | 893 | left_margin = hists__col_len(hists, se->se_width_idx); |
892 | left_margin -= thread__comm_len(self->thread); | 894 | left_margin -= thread__comm_len(he->thread); |
893 | } | 895 | } |
894 | 896 | ||
895 | return hist_entry_callchain__fprintf(fp, self, session_total, | 897 | return hist_entry_callchain__fprintf(he, total_period, left_margin, fp); |
896 | left_margin); | ||
897 | } | 898 | } |
898 | 899 | ||
899 | size_t hists__fprintf(struct hists *hists, struct hists *pair, | 900 | size_t hists__fprintf(struct hists *hists, struct hists *pair, |
@@ -903,6 +904,7 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair, | |||
903 | struct sort_entry *se; | 904 | struct sort_entry *se; |
904 | struct rb_node *nd; | 905 | struct rb_node *nd; |
905 | size_t ret = 0; | 906 | size_t ret = 0; |
907 | u64 total_period; | ||
906 | unsigned long position = 1; | 908 | unsigned long position = 1; |
907 | long displacement = 0; | 909 | long displacement = 0; |
908 | unsigned int width; | 910 | unsigned int width; |
@@ -917,20 +919,6 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair, | |||
917 | 919 | ||
918 | fprintf(fp, "# %s", pair ? "Baseline" : "Overhead"); | 920 | fprintf(fp, "# %s", pair ? "Baseline" : "Overhead"); |
919 | 921 | ||
920 | if (symbol_conf.show_nr_samples) { | ||
921 | if (sep) | ||
922 | fprintf(fp, "%cSamples", *sep); | ||
923 | else | ||
924 | fputs(" Samples ", fp); | ||
925 | } | ||
926 | |||
927 | if (symbol_conf.show_total_period) { | ||
928 | if (sep) | ||
929 | ret += fprintf(fp, "%cPeriod", *sep); | ||
930 | else | ||
931 | ret += fprintf(fp, " Period "); | ||
932 | } | ||
933 | |||
934 | if (symbol_conf.show_cpu_utilization) { | 922 | if (symbol_conf.show_cpu_utilization) { |
935 | if (sep) { | 923 | if (sep) { |
936 | ret += fprintf(fp, "%csys", *sep); | 924 | ret += fprintf(fp, "%csys", *sep); |
@@ -940,8 +928,8 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair, | |||
940 | ret += fprintf(fp, "%cguest us", *sep); | 928 | ret += fprintf(fp, "%cguest us", *sep); |
941 | } | 929 | } |
942 | } else { | 930 | } else { |
943 | ret += fprintf(fp, " sys "); | 931 | ret += fprintf(fp, " sys "); |
944 | ret += fprintf(fp, " us "); | 932 | ret += fprintf(fp, " us "); |
945 | if (perf_guest) { | 933 | if (perf_guest) { |
946 | ret += fprintf(fp, " guest sys "); | 934 | ret += fprintf(fp, " guest sys "); |
947 | ret += fprintf(fp, " guest us "); | 935 | ret += fprintf(fp, " guest us "); |
@@ -949,6 +937,20 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair, | |||
949 | } | 937 | } |
950 | } | 938 | } |
951 | 939 | ||
940 | if (symbol_conf.show_nr_samples) { | ||
941 | if (sep) | ||
942 | fprintf(fp, "%cSamples", *sep); | ||
943 | else | ||
944 | fputs(" Samples ", fp); | ||
945 | } | ||
946 | |||
947 | if (symbol_conf.show_total_period) { | ||
948 | if (sep) | ||
949 | ret += fprintf(fp, "%cPeriod", *sep); | ||
950 | else | ||
951 | ret += fprintf(fp, " Period "); | ||
952 | } | ||
953 | |||
952 | if (pair) { | 954 | if (pair) { |
953 | if (sep) | 955 | if (sep) |
954 | ret += fprintf(fp, "%cDelta", *sep); | 956 | ret += fprintf(fp, "%cDelta", *sep); |
@@ -993,6 +995,8 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair, | |||
993 | goto print_entries; | 995 | goto print_entries; |
994 | 996 | ||
995 | fprintf(fp, "# ........"); | 997 | fprintf(fp, "# ........"); |
998 | if (symbol_conf.show_cpu_utilization) | ||
999 | fprintf(fp, " ....... ......."); | ||
996 | if (symbol_conf.show_nr_samples) | 1000 | if (symbol_conf.show_nr_samples) |
997 | fprintf(fp, " .........."); | 1001 | fprintf(fp, " .........."); |
998 | if (symbol_conf.show_total_period) | 1002 | if (symbol_conf.show_total_period) |
@@ -1025,6 +1029,8 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair, | |||
1025 | goto out; | 1029 | goto out; |
1026 | 1030 | ||
1027 | print_entries: | 1031 | print_entries: |
1032 | total_period = hists->stats.total_period; | ||
1033 | |||
1028 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { | 1034 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
1029 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | 1035 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
1030 | 1036 | ||
@@ -1040,11 +1046,10 @@ print_entries: | |||
1040 | ++position; | 1046 | ++position; |
1041 | } | 1047 | } |
1042 | ret += hist_entry__fprintf(h, max_cols, hists, pair, show_displacement, | 1048 | ret += hist_entry__fprintf(h, max_cols, hists, pair, show_displacement, |
1043 | displacement, fp, hists->stats.total_period); | 1049 | displacement, total_period, fp); |
1044 | 1050 | ||
1045 | if (symbol_conf.use_callchain) | 1051 | if (symbol_conf.use_callchain) |
1046 | ret += hist_entry__fprintf_callchain(h, hists, fp, | 1052 | ret += hist_entry__fprintf_callchain(h, hists, total_period, fp); |
1047 | hists->stats.total_period); | ||
1048 | if (max_rows && ++nr_rows >= max_rows) | 1053 | if (max_rows && ++nr_rows >= max_rows) |
1049 | goto out; | 1054 | goto out; |
1050 | 1055 | ||
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index ff6f9d56ea41..f55f0a8d1f81 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -66,11 +66,8 @@ struct hists { | |||
66 | struct hist_entry *__hists__add_entry(struct hists *self, | 66 | struct hist_entry *__hists__add_entry(struct hists *self, |
67 | struct addr_location *al, | 67 | struct addr_location *al, |
68 | struct symbol *parent, u64 period); | 68 | struct symbol *parent, u64 period); |
69 | extern int64_t hist_entry__cmp(struct hist_entry *, struct hist_entry *); | 69 | int64_t hist_entry__cmp(struct hist_entry *left, struct hist_entry *right); |
70 | extern int64_t hist_entry__collapse(struct hist_entry *, struct hist_entry *); | 70 | int64_t hist_entry__collapse(struct hist_entry *left, struct hist_entry *right); |
71 | int hist_entry__fprintf(struct hist_entry *he, size_t size, struct hists *hists, | ||
72 | struct hists *pair_hists, bool show_displacement, | ||
73 | long displacement, FILE *fp, u64 session_total); | ||
74 | int hist_entry__snprintf(struct hist_entry *self, char *bf, size_t size, | 71 | int hist_entry__snprintf(struct hist_entry *self, char *bf, size_t size, |
75 | struct hists *hists); | 72 | struct hists *hists); |
76 | void hist_entry__free(struct hist_entry *); | 73 | void hist_entry__free(struct hist_entry *); |
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 531c283fc0c5..b029296d20d9 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -735,8 +735,8 @@ static int | |||
735 | parse_event_modifier(const char **strp, struct perf_event_attr *attr) | 735 | parse_event_modifier(const char **strp, struct perf_event_attr *attr) |
736 | { | 736 | { |
737 | const char *str = *strp; | 737 | const char *str = *strp; |
738 | int exclude = 0; | 738 | int exclude = 0, exclude_GH = 0; |
739 | int eu = 0, ek = 0, eh = 0, precise = 0; | 739 | int eu = 0, ek = 0, eh = 0, eH = 0, eG = 0, precise = 0; |
740 | 740 | ||
741 | if (!*str) | 741 | if (!*str) |
742 | return 0; | 742 | return 0; |
@@ -760,6 +760,14 @@ parse_event_modifier(const char **strp, struct perf_event_attr *attr) | |||
760 | if (!exclude) | 760 | if (!exclude) |
761 | exclude = eu = ek = eh = 1; | 761 | exclude = eu = ek = eh = 1; |
762 | eh = 0; | 762 | eh = 0; |
763 | } else if (*str == 'G') { | ||
764 | if (!exclude_GH) | ||
765 | exclude_GH = eG = eH = 1; | ||
766 | eG = 0; | ||
767 | } else if (*str == 'H') { | ||
768 | if (!exclude_GH) | ||
769 | exclude_GH = eG = eH = 1; | ||
770 | eH = 0; | ||
763 | } else if (*str == 'p') { | 771 | } else if (*str == 'p') { |
764 | precise++; | 772 | precise++; |
765 | } else | 773 | } else |
@@ -776,6 +784,8 @@ parse_event_modifier(const char **strp, struct perf_event_attr *attr) | |||
776 | attr->exclude_kernel = ek; | 784 | attr->exclude_kernel = ek; |
777 | attr->exclude_hv = eh; | 785 | attr->exclude_hv = eh; |
778 | attr->precise_ip = precise; | 786 | attr->precise_ip = precise; |
787 | attr->exclude_host = eH; | ||
788 | attr->exclude_guest = eG; | ||
779 | 789 | ||
780 | return 0; | 790 | return 0; |
781 | } | 791 | } |
@@ -838,6 +848,7 @@ int parse_events(struct perf_evlist *evlist , const char *str, int unset __used) | |||
838 | for (;;) { | 848 | for (;;) { |
839 | ostr = str; | 849 | ostr = str; |
840 | memset(&attr, 0, sizeof(attr)); | 850 | memset(&attr, 0, sizeof(attr)); |
851 | event_attr_init(&attr); | ||
841 | ret = parse_event_symbols(evlist, &str, &attr); | 852 | ret = parse_event_symbols(evlist, &str, &attr); |
842 | if (ret == EVT_FAILED) | 853 | if (ret == EVT_FAILED) |
843 | return -1; | 854 | return -1; |
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c index ac6830d8292b..fc22cf5c605f 100644 --- a/tools/perf/util/trace-event-info.c +++ b/tools/perf/util/trace-event-info.c | |||
@@ -18,7 +18,6 @@ | |||
18 | * | 18 | * |
19 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 19 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
20 | */ | 20 | */ |
21 | #include <ctype.h> | ||
22 | #include "util.h" | 21 | #include "util.h" |
23 | #include <dirent.h> | 22 | #include <dirent.h> |
24 | #include <mntent.h> | 23 | #include <mntent.h> |
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 5b3ea49aa63e..813141047fc2 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
@@ -1,6 +1,21 @@ | |||
1 | #include "../perf.h" | ||
1 | #include "util.h" | 2 | #include "util.h" |
2 | #include <sys/mman.h> | 3 | #include <sys/mman.h> |
3 | 4 | ||
5 | /* | ||
6 | * XXX We need to find a better place for these things... | ||
7 | */ | ||
8 | bool perf_host = true; | ||
9 | bool perf_guest = true; | ||
10 | |||
11 | void event_attr_init(struct perf_event_attr *attr) | ||
12 | { | ||
13 | if (!perf_host) | ||
14 | attr->exclude_host = 1; | ||
15 | if (!perf_guest) | ||
16 | attr->exclude_guest = 1; | ||
17 | } | ||
18 | |||
4 | int mkdir_p(char *path, mode_t mode) | 19 | int mkdir_p(char *path, mode_t mode) |
5 | { | 20 | { |
6 | struct stat st; | 21 | struct stat st; |
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 37be34dff798..b9c530cce79a 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -242,6 +242,10 @@ int strtailcmp(const char *s1, const char *s2); | |||
242 | unsigned long convert_unit(unsigned long value, char *unit); | 242 | unsigned long convert_unit(unsigned long value, char *unit); |
243 | int readn(int fd, void *buf, size_t size); | 243 | int readn(int fd, void *buf, size_t size); |
244 | 244 | ||
245 | struct perf_event_attr; | ||
246 | |||
247 | void event_attr_init(struct perf_event_attr *attr); | ||
248 | |||
245 | #define _STR(x) #x | 249 | #define _STR(x) #x |
246 | #define STR(x) _STR(x) | 250 | #define STR(x) _STR(x) |
247 | 251 | ||
diff --git a/tools/testing/ktest/compare-ktest-sample.pl b/tools/testing/ktest/compare-ktest-sample.pl index 9a571e71683c..a373a5bfff68 100755 --- a/tools/testing/ktest/compare-ktest-sample.pl +++ b/tools/testing/ktest/compare-ktest-sample.pl | |||
@@ -2,7 +2,9 @@ | |||
2 | 2 | ||
3 | open (IN,"ktest.pl"); | 3 | open (IN,"ktest.pl"); |
4 | while (<IN>) { | 4 | while (<IN>) { |
5 | # hashes are now used | ||
5 | if (/\$opt\{"?([A-Z].*?)(\[.*\])?"?\}/ || | 6 | if (/\$opt\{"?([A-Z].*?)(\[.*\])?"?\}/ || |
7 | /^\s*"?([A-Z].*?)"?\s*=>\s*/ || | ||
6 | /set_test_option\("(.*?)"/) { | 8 | /set_test_option\("(.*?)"/) { |
7 | $opt{$1} = 1; | 9 | $opt{$1} = 1; |
8 | } | 10 | } |
@@ -11,7 +13,7 @@ close IN; | |||
11 | 13 | ||
12 | open (IN, "sample.conf"); | 14 | open (IN, "sample.conf"); |
13 | while (<IN>) { | 15 | while (<IN>) { |
14 | if (/^\s*#?\s*(\S+)\s*=/) { | 16 | if (/^\s*#?\s*([A-Z]\S*)\s*=/) { |
15 | $samp{$1} = 1; | 17 | $samp{$1} = 1; |
16 | } | 18 | } |
17 | } | 19 | } |
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 8b4c2535b266..62a134dc421a 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl | |||
@@ -18,40 +18,50 @@ $| = 1; | |||
18 | my %opt; | 18 | my %opt; |
19 | my %repeat_tests; | 19 | my %repeat_tests; |
20 | my %repeats; | 20 | my %repeats; |
21 | my %default; | ||
22 | 21 | ||
23 | #default opts | 22 | #default opts |
24 | $default{"NUM_TESTS"} = 1; | 23 | my %default = ( |
25 | $default{"REBOOT_TYPE"} = "grub"; | 24 | "NUM_TESTS" => 1, |
26 | $default{"TEST_TYPE"} = "test"; | 25 | "TEST_TYPE" => "build", |
27 | $default{"BUILD_TYPE"} = "randconfig"; | 26 | "BUILD_TYPE" => "randconfig", |
28 | $default{"MAKE_CMD"} = "make"; | 27 | "MAKE_CMD" => "make", |
29 | $default{"TIMEOUT"} = 120; | 28 | "TIMEOUT" => 120, |
30 | $default{"TMP_DIR"} = "/tmp/ktest/\${MACHINE}"; | 29 | "TMP_DIR" => "/tmp/ktest/\${MACHINE}", |
31 | $default{"SLEEP_TIME"} = 60; # sleep time between tests | 30 | "SLEEP_TIME" => 60, # sleep time between tests |
32 | $default{"BUILD_NOCLEAN"} = 0; | 31 | "BUILD_NOCLEAN" => 0, |
33 | $default{"REBOOT_ON_ERROR"} = 0; | 32 | "REBOOT_ON_ERROR" => 0, |
34 | $default{"POWEROFF_ON_ERROR"} = 0; | 33 | "POWEROFF_ON_ERROR" => 0, |
35 | $default{"REBOOT_ON_SUCCESS"} = 1; | 34 | "REBOOT_ON_SUCCESS" => 1, |
36 | $default{"POWEROFF_ON_SUCCESS"} = 0; | 35 | "POWEROFF_ON_SUCCESS" => 0, |
37 | $default{"BUILD_OPTIONS"} = ""; | 36 | "BUILD_OPTIONS" => "", |
38 | $default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects | 37 | "BISECT_SLEEP_TIME" => 60, # sleep time between bisects |
39 | $default{"PATCHCHECK_SLEEP_TIME"} = 60; # sleep time between patch checks | 38 | "PATCHCHECK_SLEEP_TIME" => 60, # sleep time between patch checks |
40 | $default{"CLEAR_LOG"} = 0; | 39 | "CLEAR_LOG" => 0, |
41 | $default{"BISECT_MANUAL"} = 0; | 40 | "BISECT_MANUAL" => 0, |
42 | $default{"BISECT_SKIP"} = 1; | 41 | "BISECT_SKIP" => 1, |
43 | $default{"SUCCESS_LINE"} = "login:"; | 42 | "SUCCESS_LINE" => "login:", |
44 | $default{"DETECT_TRIPLE_FAULT"} = 1; | 43 | "DETECT_TRIPLE_FAULT" => 1, |
45 | $default{"NO_INSTALL"} = 0; | 44 | "NO_INSTALL" => 0, |
46 | $default{"BOOTED_TIMEOUT"} = 1; | 45 | "BOOTED_TIMEOUT" => 1, |
47 | $default{"DIE_ON_FAILURE"} = 1; | 46 | "DIE_ON_FAILURE" => 1, |
48 | $default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND"; | 47 | "SSH_EXEC" => "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND", |
49 | $default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE"; | 48 | "SCP_TO_TARGET" => "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE", |
50 | $default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot"; | 49 | "REBOOT" => "ssh \$SSH_USER\@\$MACHINE reboot", |
51 | $default{"STOP_AFTER_SUCCESS"} = 10; | 50 | "STOP_AFTER_SUCCESS" => 10, |
52 | $default{"STOP_AFTER_FAILURE"} = 60; | 51 | "STOP_AFTER_FAILURE" => 60, |
53 | $default{"STOP_TEST_AFTER"} = 600; | 52 | "STOP_TEST_AFTER" => 600, |
54 | $default{"LOCALVERSION"} = "-test"; | 53 | |
54 | # required, and we will ask users if they don't have them but we keep the default | ||
55 | # value something that is common. | ||
56 | "REBOOT_TYPE" => "grub", | ||
57 | "LOCALVERSION" => "-test", | ||
58 | "SSH_USER" => "root", | ||
59 | "BUILD_TARGET" => "arch/x86/boot/bzImage", | ||
60 | "TARGET_IMAGE" => "/boot/vmlinuz-test", | ||
61 | |||
62 | "LOG_FILE" => undef, | ||
63 | "IGNORE_UNUSED" => 0, | ||
64 | ); | ||
55 | 65 | ||
56 | my $ktest_config; | 66 | my $ktest_config; |
57 | my $version; | 67 | my $version; |
@@ -73,6 +83,8 @@ my $reboot_script; | |||
73 | my $power_cycle; | 83 | my $power_cycle; |
74 | my $reboot; | 84 | my $reboot; |
75 | my $reboot_on_error; | 85 | my $reboot_on_error; |
86 | my $switch_to_good; | ||
87 | my $switch_to_test; | ||
76 | my $poweroff_on_error; | 88 | my $poweroff_on_error; |
77 | my $die_on_failure; | 89 | my $die_on_failure; |
78 | my $powercycle_after_reboot; | 90 | my $powercycle_after_reboot; |
@@ -92,17 +104,24 @@ my $start_minconfig; | |||
92 | my $start_minconfig_defined; | 104 | my $start_minconfig_defined; |
93 | my $output_minconfig; | 105 | my $output_minconfig; |
94 | my $ignore_config; | 106 | my $ignore_config; |
107 | my $ignore_errors; | ||
95 | my $addconfig; | 108 | my $addconfig; |
96 | my $in_bisect = 0; | 109 | my $in_bisect = 0; |
97 | my $bisect_bad = ""; | 110 | my $bisect_bad_commit = ""; |
98 | my $reverse_bisect; | 111 | my $reverse_bisect; |
99 | my $bisect_manual; | 112 | my $bisect_manual; |
100 | my $bisect_skip; | 113 | my $bisect_skip; |
101 | my $config_bisect_good; | 114 | my $config_bisect_good; |
115 | my $bisect_ret_good; | ||
116 | my $bisect_ret_bad; | ||
117 | my $bisect_ret_skip; | ||
118 | my $bisect_ret_abort; | ||
119 | my $bisect_ret_default; | ||
102 | my $in_patchcheck = 0; | 120 | my $in_patchcheck = 0; |
103 | my $run_test; | 121 | my $run_test; |
104 | my $redirect; | 122 | my $redirect; |
105 | my $buildlog; | 123 | my $buildlog; |
124 | my $testlog; | ||
106 | my $dmesg; | 125 | my $dmesg; |
107 | my $monitor_fp; | 126 | my $monitor_fp; |
108 | my $monitor_pid; | 127 | my $monitor_pid; |
@@ -112,6 +131,7 @@ my $bisect_sleep_time; | |||
112 | my $patchcheck_sleep_time; | 131 | my $patchcheck_sleep_time; |
113 | my $ignore_warnings; | 132 | my $ignore_warnings; |
114 | my $store_failures; | 133 | my $store_failures; |
134 | my $store_successes; | ||
115 | my $test_name; | 135 | my $test_name; |
116 | my $timeout; | 136 | my $timeout; |
117 | my $booted_timeout; | 137 | my $booted_timeout; |
@@ -124,10 +144,34 @@ my $stop_after_failure; | |||
124 | my $stop_test_after; | 144 | my $stop_test_after; |
125 | my $build_target; | 145 | my $build_target; |
126 | my $target_image; | 146 | my $target_image; |
147 | my $checkout; | ||
127 | my $localversion; | 148 | my $localversion; |
128 | my $iteration = 0; | 149 | my $iteration = 0; |
129 | my $successes = 0; | 150 | my $successes = 0; |
130 | 151 | ||
152 | my $bisect_good; | ||
153 | my $bisect_bad; | ||
154 | my $bisect_type; | ||
155 | my $bisect_start; | ||
156 | my $bisect_replay; | ||
157 | my $bisect_files; | ||
158 | my $bisect_reverse; | ||
159 | my $bisect_check; | ||
160 | |||
161 | my $config_bisect; | ||
162 | my $config_bisect_type; | ||
163 | |||
164 | my $patchcheck_type; | ||
165 | my $patchcheck_start; | ||
166 | my $patchcheck_end; | ||
167 | |||
168 | # set when a test is something other that just building or install | ||
169 | # which would require more options. | ||
170 | my $buildonly = 1; | ||
171 | |||
172 | # set when creating a new config | ||
173 | my $newconfig = 0; | ||
174 | |||
131 | my %entered_configs; | 175 | my %entered_configs; |
132 | my %config_help; | 176 | my %config_help; |
133 | my %variable; | 177 | my %variable; |
@@ -136,11 +180,99 @@ my %force_config; | |||
136 | # do not force reboots on config problems | 180 | # do not force reboots on config problems |
137 | my $no_reboot = 1; | 181 | my $no_reboot = 1; |
138 | 182 | ||
183 | my %option_map = ( | ||
184 | "MACHINE" => \$machine, | ||
185 | "SSH_USER" => \$ssh_user, | ||
186 | "TMP_DIR" => \$tmpdir, | ||
187 | "OUTPUT_DIR" => \$outputdir, | ||
188 | "BUILD_DIR" => \$builddir, | ||
189 | "TEST_TYPE" => \$test_type, | ||
190 | "BUILD_TYPE" => \$build_type, | ||
191 | "BUILD_OPTIONS" => \$build_options, | ||
192 | "PRE_BUILD" => \$pre_build, | ||
193 | "POST_BUILD" => \$post_build, | ||
194 | "PRE_BUILD_DIE" => \$pre_build_die, | ||
195 | "POST_BUILD_DIE" => \$post_build_die, | ||
196 | "POWER_CYCLE" => \$power_cycle, | ||
197 | "REBOOT" => \$reboot, | ||
198 | "BUILD_NOCLEAN" => \$noclean, | ||
199 | "MIN_CONFIG" => \$minconfig, | ||
200 | "OUTPUT_MIN_CONFIG" => \$output_minconfig, | ||
201 | "START_MIN_CONFIG" => \$start_minconfig, | ||
202 | "IGNORE_CONFIG" => \$ignore_config, | ||
203 | "TEST" => \$run_test, | ||
204 | "ADD_CONFIG" => \$addconfig, | ||
205 | "REBOOT_TYPE" => \$reboot_type, | ||
206 | "GRUB_MENU" => \$grub_menu, | ||
207 | "POST_INSTALL" => \$post_install, | ||
208 | "NO_INSTALL" => \$no_install, | ||
209 | "REBOOT_SCRIPT" => \$reboot_script, | ||
210 | "REBOOT_ON_ERROR" => \$reboot_on_error, | ||
211 | "SWITCH_TO_GOOD" => \$switch_to_good, | ||
212 | "SWITCH_TO_TEST" => \$switch_to_test, | ||
213 | "POWEROFF_ON_ERROR" => \$poweroff_on_error, | ||
214 | "DIE_ON_FAILURE" => \$die_on_failure, | ||
215 | "POWER_OFF" => \$power_off, | ||
216 | "POWERCYCLE_AFTER_REBOOT" => \$powercycle_after_reboot, | ||
217 | "POWEROFF_AFTER_HALT" => \$poweroff_after_halt, | ||
218 | "SLEEP_TIME" => \$sleep_time, | ||
219 | "BISECT_SLEEP_TIME" => \$bisect_sleep_time, | ||
220 | "PATCHCHECK_SLEEP_TIME" => \$patchcheck_sleep_time, | ||
221 | "IGNORE_WARNINGS" => \$ignore_warnings, | ||
222 | "IGNORE_ERRORS" => \$ignore_errors, | ||
223 | "BISECT_MANUAL" => \$bisect_manual, | ||
224 | "BISECT_SKIP" => \$bisect_skip, | ||
225 | "CONFIG_BISECT_GOOD" => \$config_bisect_good, | ||
226 | "BISECT_RET_GOOD" => \$bisect_ret_good, | ||
227 | "BISECT_RET_BAD" => \$bisect_ret_bad, | ||
228 | "BISECT_RET_SKIP" => \$bisect_ret_skip, | ||
229 | "BISECT_RET_ABORT" => \$bisect_ret_abort, | ||
230 | "BISECT_RET_DEFAULT" => \$bisect_ret_default, | ||
231 | "STORE_FAILURES" => \$store_failures, | ||
232 | "STORE_SUCCESSES" => \$store_successes, | ||
233 | "TEST_NAME" => \$test_name, | ||
234 | "TIMEOUT" => \$timeout, | ||
235 | "BOOTED_TIMEOUT" => \$booted_timeout, | ||
236 | "CONSOLE" => \$console, | ||
237 | "DETECT_TRIPLE_FAULT" => \$detect_triplefault, | ||
238 | "SUCCESS_LINE" => \$success_line, | ||
239 | "REBOOT_SUCCESS_LINE" => \$reboot_success_line, | ||
240 | "STOP_AFTER_SUCCESS" => \$stop_after_success, | ||
241 | "STOP_AFTER_FAILURE" => \$stop_after_failure, | ||
242 | "STOP_TEST_AFTER" => \$stop_test_after, | ||
243 | "BUILD_TARGET" => \$build_target, | ||
244 | "SSH_EXEC" => \$ssh_exec, | ||
245 | "SCP_TO_TARGET" => \$scp_to_target, | ||
246 | "CHECKOUT" => \$checkout, | ||
247 | "TARGET_IMAGE" => \$target_image, | ||
248 | "LOCALVERSION" => \$localversion, | ||
249 | |||
250 | "BISECT_GOOD" => \$bisect_good, | ||
251 | "BISECT_BAD" => \$bisect_bad, | ||
252 | "BISECT_TYPE" => \$bisect_type, | ||
253 | "BISECT_START" => \$bisect_start, | ||
254 | "BISECT_REPLAY" => \$bisect_replay, | ||
255 | "BISECT_FILES" => \$bisect_files, | ||
256 | "BISECT_REVERSE" => \$bisect_reverse, | ||
257 | "BISECT_CHECK" => \$bisect_check, | ||
258 | |||
259 | "CONFIG_BISECT" => \$config_bisect, | ||
260 | "CONFIG_BISECT_TYPE" => \$config_bisect_type, | ||
261 | |||
262 | "PATCHCHECK_TYPE" => \$patchcheck_type, | ||
263 | "PATCHCHECK_START" => \$patchcheck_start, | ||
264 | "PATCHCHECK_END" => \$patchcheck_end, | ||
265 | ); | ||
266 | |||
267 | # Options may be used by other options, record them. | ||
268 | my %used_options; | ||
269 | |||
139 | # default variables that can be used | 270 | # default variables that can be used |
140 | chomp ($variable{"PWD"} = `pwd`); | 271 | chomp ($variable{"PWD"} = `pwd`); |
141 | 272 | ||
142 | $config_help{"MACHINE"} = << "EOF" | 273 | $config_help{"MACHINE"} = << "EOF" |
143 | The machine hostname that you will test. | 274 | The machine hostname that you will test. |
275 | For build only tests, it is still needed to differentiate log files. | ||
144 | EOF | 276 | EOF |
145 | ; | 277 | ; |
146 | $config_help{"SSH_USER"} = << "EOF" | 278 | $config_help{"SSH_USER"} = << "EOF" |
@@ -150,11 +282,15 @@ EOF | |||
150 | ; | 282 | ; |
151 | $config_help{"BUILD_DIR"} = << "EOF" | 283 | $config_help{"BUILD_DIR"} = << "EOF" |
152 | The directory that contains the Linux source code (full path). | 284 | The directory that contains the Linux source code (full path). |
285 | You can use \${PWD} that will be the path where ktest.pl is run, or use | ||
286 | \${THIS_DIR} which is assigned \${PWD} but may be changed later. | ||
153 | EOF | 287 | EOF |
154 | ; | 288 | ; |
155 | $config_help{"OUTPUT_DIR"} = << "EOF" | 289 | $config_help{"OUTPUT_DIR"} = << "EOF" |
156 | The directory that the objects will be built (full path). | 290 | The directory that the objects will be built (full path). |
157 | (can not be same as BUILD_DIR) | 291 | (can not be same as BUILD_DIR) |
292 | You can use \${PWD} that will be the path where ktest.pl is run, or use | ||
293 | \${THIS_DIR} which is assigned \${PWD} but may be changed later. | ||
158 | EOF | 294 | EOF |
159 | ; | 295 | ; |
160 | $config_help{"BUILD_TARGET"} = << "EOF" | 296 | $config_help{"BUILD_TARGET"} = << "EOF" |
@@ -162,6 +298,11 @@ $config_help{"BUILD_TARGET"} = << "EOF" | |||
162 | (relative to OUTPUT_DIR) | 298 | (relative to OUTPUT_DIR) |
163 | EOF | 299 | EOF |
164 | ; | 300 | ; |
301 | $config_help{"BUILD_OPTIONS"} = << "EOF" | ||
302 | Options to add to \"make\" when building. | ||
303 | i.e. -j20 | ||
304 | EOF | ||
305 | ; | ||
165 | $config_help{"TARGET_IMAGE"} = << "EOF" | 306 | $config_help{"TARGET_IMAGE"} = << "EOF" |
166 | The place to put your image on the test machine. | 307 | The place to put your image on the test machine. |
167 | EOF | 308 | EOF |
@@ -227,20 +368,36 @@ $config_help{"REBOOT_SCRIPT"} = << "EOF" | |||
227 | EOF | 368 | EOF |
228 | ; | 369 | ; |
229 | 370 | ||
230 | sub read_yn { | 371 | sub read_prompt { |
231 | my ($prompt) = @_; | 372 | my ($cancel, $prompt) = @_; |
232 | 373 | ||
233 | my $ans; | 374 | my $ans; |
234 | 375 | ||
235 | for (;;) { | 376 | for (;;) { |
236 | print "$prompt [Y/n] "; | 377 | if ($cancel) { |
378 | print "$prompt [y/n/C] "; | ||
379 | } else { | ||
380 | print "$prompt [Y/n] "; | ||
381 | } | ||
237 | $ans = <STDIN>; | 382 | $ans = <STDIN>; |
238 | chomp $ans; | 383 | chomp $ans; |
239 | if ($ans =~ /^\s*$/) { | 384 | if ($ans =~ /^\s*$/) { |
240 | $ans = "y"; | 385 | if ($cancel) { |
386 | $ans = "c"; | ||
387 | } else { | ||
388 | $ans = "y"; | ||
389 | } | ||
241 | } | 390 | } |
242 | last if ($ans =~ /^y$/i || $ans =~ /^n$/i); | 391 | last if ($ans =~ /^y$/i || $ans =~ /^n$/i); |
243 | print "Please answer either 'y' or 'n'.\n"; | 392 | if ($cancel) { |
393 | last if ($ans =~ /^c$/i); | ||
394 | print "Please answer either 'y', 'n' or 'c'.\n"; | ||
395 | } else { | ||
396 | print "Please answer either 'y' or 'n'.\n"; | ||
397 | } | ||
398 | } | ||
399 | if ($ans =~ /^c/i) { | ||
400 | exit; | ||
244 | } | 401 | } |
245 | if ($ans !~ /^y$/i) { | 402 | if ($ans !~ /^y$/i) { |
246 | return 0; | 403 | return 0; |
@@ -248,6 +405,18 @@ sub read_yn { | |||
248 | return 1; | 405 | return 1; |
249 | } | 406 | } |
250 | 407 | ||
408 | sub read_yn { | ||
409 | my ($prompt) = @_; | ||
410 | |||
411 | return read_prompt 0, $prompt; | ||
412 | } | ||
413 | |||
414 | sub read_ync { | ||
415 | my ($prompt) = @_; | ||
416 | |||
417 | return read_prompt 1, $prompt; | ||
418 | } | ||
419 | |||
251 | sub get_ktest_config { | 420 | sub get_ktest_config { |
252 | my ($config) = @_; | 421 | my ($config) = @_; |
253 | my $ans; | 422 | my $ans; |
@@ -261,7 +430,7 @@ sub get_ktest_config { | |||
261 | 430 | ||
262 | for (;;) { | 431 | for (;;) { |
263 | print "$config = "; | 432 | print "$config = "; |
264 | if (defined($default{$config})) { | 433 | if (defined($default{$config}) && length($default{$config})) { |
265 | print "\[$default{$config}\] "; | 434 | print "\[$default{$config}\] "; |
266 | } | 435 | } |
267 | $ans = <STDIN>; | 436 | $ans = <STDIN>; |
@@ -274,22 +443,37 @@ sub get_ktest_config { | |||
274 | next; | 443 | next; |
275 | } | 444 | } |
276 | } | 445 | } |
277 | $entered_configs{$config} = process_variables($ans); | 446 | $entered_configs{$config} = ${ans}; |
278 | last; | 447 | last; |
279 | } | 448 | } |
280 | } | 449 | } |
281 | 450 | ||
282 | sub get_ktest_configs { | 451 | sub get_ktest_configs { |
283 | get_ktest_config("MACHINE"); | 452 | get_ktest_config("MACHINE"); |
284 | get_ktest_config("SSH_USER"); | ||
285 | get_ktest_config("BUILD_DIR"); | 453 | get_ktest_config("BUILD_DIR"); |
286 | get_ktest_config("OUTPUT_DIR"); | 454 | get_ktest_config("OUTPUT_DIR"); |
287 | get_ktest_config("BUILD_TARGET"); | 455 | |
288 | get_ktest_config("TARGET_IMAGE"); | 456 | if ($newconfig) { |
289 | get_ktest_config("POWER_CYCLE"); | 457 | get_ktest_config("BUILD_OPTIONS"); |
290 | get_ktest_config("CONSOLE"); | 458 | } |
459 | |||
460 | # options required for other than just building a kernel | ||
461 | if (!$buildonly) { | ||
462 | get_ktest_config("POWER_CYCLE"); | ||
463 | get_ktest_config("CONSOLE"); | ||
464 | } | ||
465 | |||
466 | # options required for install and more | ||
467 | if ($buildonly != 1) { | ||
468 | get_ktest_config("SSH_USER"); | ||
469 | get_ktest_config("BUILD_TARGET"); | ||
470 | get_ktest_config("TARGET_IMAGE"); | ||
471 | } | ||
472 | |||
291 | get_ktest_config("LOCALVERSION"); | 473 | get_ktest_config("LOCALVERSION"); |
292 | 474 | ||
475 | return if ($buildonly); | ||
476 | |||
293 | my $rtype = $opt{"REBOOT_TYPE"}; | 477 | my $rtype = $opt{"REBOOT_TYPE"}; |
294 | 478 | ||
295 | if (!defined($rtype)) { | 479 | if (!defined($rtype)) { |
@@ -303,8 +487,6 @@ sub get_ktest_configs { | |||
303 | 487 | ||
304 | if ($rtype eq "grub") { | 488 | if ($rtype eq "grub") { |
305 | get_ktest_config("GRUB_MENU"); | 489 | get_ktest_config("GRUB_MENU"); |
306 | } else { | ||
307 | get_ktest_config("REBOOT_SCRIPT"); | ||
308 | } | 490 | } |
309 | } | 491 | } |
310 | 492 | ||
@@ -334,6 +516,10 @@ sub process_variables { | |||
334 | } else { | 516 | } else { |
335 | # put back the origin piece. | 517 | # put back the origin piece. |
336 | $retval = "$retval\$\{$var\}"; | 518 | $retval = "$retval\$\{$var\}"; |
519 | # This could be an option that is used later, save | ||
520 | # it so we don't warn if this option is not one of | ||
521 | # ktests options. | ||
522 | $used_options{$var} = 1; | ||
337 | } | 523 | } |
338 | $value = $end; | 524 | $value = $end; |
339 | } | 525 | } |
@@ -348,6 +534,19 @@ sub process_variables { | |||
348 | sub set_value { | 534 | sub set_value { |
349 | my ($lvalue, $rvalue, $override, $overrides, $name) = @_; | 535 | my ($lvalue, $rvalue, $override, $overrides, $name) = @_; |
350 | 536 | ||
537 | my $prvalue = process_variables($rvalue); | ||
538 | |||
539 | if ($buildonly && $lvalue =~ /^TEST_TYPE(\[.*\])?$/ && $prvalue ne "build") { | ||
540 | # Note if a test is something other than build, then we | ||
541 | # will need other manditory options. | ||
542 | if ($prvalue ne "install") { | ||
543 | $buildonly = 0; | ||
544 | } else { | ||
545 | # install still limits some manditory options. | ||
546 | $buildonly = 2; | ||
547 | } | ||
548 | } | ||
549 | |||
351 | if (defined($opt{$lvalue})) { | 550 | if (defined($opt{$lvalue})) { |
352 | if (!$override || defined(${$overrides}{$lvalue})) { | 551 | if (!$override || defined(${$overrides}{$lvalue})) { |
353 | my $extra = ""; | 552 | my $extra = ""; |
@@ -356,13 +555,12 @@ sub set_value { | |||
356 | } | 555 | } |
357 | die "$name: $.: Option $lvalue defined more than once!\n$extra"; | 556 | die "$name: $.: Option $lvalue defined more than once!\n$extra"; |
358 | } | 557 | } |
359 | ${$overrides}{$lvalue} = $rvalue; | 558 | ${$overrides}{$lvalue} = $prvalue; |
360 | } | 559 | } |
361 | if ($rvalue =~ /^\s*$/) { | 560 | if ($rvalue =~ /^\s*$/) { |
362 | delete $opt{$lvalue}; | 561 | delete $opt{$lvalue}; |
363 | } else { | 562 | } else { |
364 | $rvalue = process_variables($rvalue); | 563 | $opt{$lvalue} = $prvalue; |
365 | $opt{$lvalue} = $rvalue; | ||
366 | } | 564 | } |
367 | } | 565 | } |
368 | 566 | ||
@@ -712,6 +910,15 @@ sub __read_config { | |||
712 | return $test_case; | 910 | return $test_case; |
713 | } | 911 | } |
714 | 912 | ||
913 | sub get_test_case { | ||
914 | print "What test case would you like to run?\n"; | ||
915 | print " (build, install or boot)\n"; | ||
916 | print " Other tests are available but require editing the config file\n"; | ||
917 | my $ans = <STDIN>; | ||
918 | chomp $ans; | ||
919 | $default{"TEST_TYPE"} = $ans; | ||
920 | } | ||
921 | |||
715 | sub read_config { | 922 | sub read_config { |
716 | my ($config) = @_; | 923 | my ($config) = @_; |
717 | 924 | ||
@@ -726,10 +933,7 @@ sub read_config { | |||
726 | # was a test specified? | 933 | # was a test specified? |
727 | if (!$test_case) { | 934 | if (!$test_case) { |
728 | print "No test case specified.\n"; | 935 | print "No test case specified.\n"; |
729 | print "What test case would you like to run?\n"; | 936 | get_test_case; |
730 | my $ans = <STDIN>; | ||
731 | chomp $ans; | ||
732 | $default{"TEST_TYPE"} = $ans; | ||
733 | } | 937 | } |
734 | 938 | ||
735 | # set any defaults | 939 | # set any defaults |
@@ -739,6 +943,37 @@ sub read_config { | |||
739 | $opt{$default} = $default{$default}; | 943 | $opt{$default} = $default{$default}; |
740 | } | 944 | } |
741 | } | 945 | } |
946 | |||
947 | if ($opt{"IGNORE_UNUSED"} == 1) { | ||
948 | return; | ||
949 | } | ||
950 | |||
951 | my %not_used; | ||
952 | |||
953 | # check if there are any stragglers (typos?) | ||
954 | foreach my $option (keys %opt) { | ||
955 | my $op = $option; | ||
956 | # remove per test labels. | ||
957 | $op =~ s/\[.*\]//; | ||
958 | if (!exists($option_map{$op}) && | ||
959 | !exists($default{$op}) && | ||
960 | !exists($used_options{$op})) { | ||
961 | $not_used{$op} = 1; | ||
962 | } | ||
963 | } | ||
964 | |||
965 | if (%not_used) { | ||
966 | my $s = "s are"; | ||
967 | $s = " is" if (keys %not_used == 1); | ||
968 | print "The following option$s not used; could be a typo:\n"; | ||
969 | foreach my $option (keys %not_used) { | ||
970 | print "$option\n"; | ||
971 | } | ||
972 | print "Set IGRNORE_UNUSED = 1 to have ktest ignore unused variables\n"; | ||
973 | if (!read_yn "Do you want to continue?") { | ||
974 | exit -1; | ||
975 | } | ||
976 | } | ||
742 | } | 977 | } |
743 | 978 | ||
744 | sub __eval_option { | 979 | sub __eval_option { |
@@ -873,6 +1108,17 @@ sub reboot { | |||
873 | } | 1108 | } |
874 | } | 1109 | } |
875 | 1110 | ||
1111 | sub reboot_to_good { | ||
1112 | my ($time) = @_; | ||
1113 | |||
1114 | if (defined($switch_to_good)) { | ||
1115 | run_command $switch_to_good; | ||
1116 | return; | ||
1117 | } | ||
1118 | |||
1119 | reboot $time; | ||
1120 | } | ||
1121 | |||
876 | sub do_not_reboot { | 1122 | sub do_not_reboot { |
877 | my $i = $iteration; | 1123 | my $i = $iteration; |
878 | 1124 | ||
@@ -889,7 +1135,7 @@ sub dodie { | |||
889 | if ($reboot_on_error && !do_not_reboot) { | 1135 | if ($reboot_on_error && !do_not_reboot) { |
890 | 1136 | ||
891 | doprint "REBOOTING\n"; | 1137 | doprint "REBOOTING\n"; |
892 | reboot; | 1138 | reboot_to_good; |
893 | 1139 | ||
894 | } elsif ($poweroff_on_error && defined($power_off)) { | 1140 | } elsif ($poweroff_on_error && defined($power_off)) { |
895 | doprint "POWERING OFF\n"; | 1141 | doprint "POWERING OFF\n"; |
@@ -975,6 +1221,43 @@ sub wait_for_monitor { | |||
975 | print "** Monitor flushed **\n"; | 1221 | print "** Monitor flushed **\n"; |
976 | } | 1222 | } |
977 | 1223 | ||
1224 | sub save_logs { | ||
1225 | my ($result, $basedir) = @_; | ||
1226 | my @t = localtime; | ||
1227 | my $date = sprintf "%04d%02d%02d%02d%02d%02d", | ||
1228 | 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0]; | ||
1229 | |||
1230 | my $type = $build_type; | ||
1231 | if ($type =~ /useconfig/) { | ||
1232 | $type = "useconfig"; | ||
1233 | } | ||
1234 | |||
1235 | my $dir = "$machine-$test_type-$type-$result-$date"; | ||
1236 | |||
1237 | $dir = "$basedir/$dir"; | ||
1238 | |||
1239 | if (!-d $dir) { | ||
1240 | mkpath($dir) or | ||
1241 | die "can't create $dir"; | ||
1242 | } | ||
1243 | |||
1244 | my %files = ( | ||
1245 | "config" => $output_config, | ||
1246 | "buildlog" => $buildlog, | ||
1247 | "dmesg" => $dmesg, | ||
1248 | "testlog" => $testlog, | ||
1249 | ); | ||
1250 | |||
1251 | while (my ($name, $source) = each(%files)) { | ||
1252 | if (-f "$source") { | ||
1253 | cp "$source", "$dir/$name" or | ||
1254 | die "failed to copy $source"; | ||
1255 | } | ||
1256 | } | ||
1257 | |||
1258 | doprint "*** Saved info to $dir ***\n"; | ||
1259 | } | ||
1260 | |||
978 | sub fail { | 1261 | sub fail { |
979 | 1262 | ||
980 | if ($die_on_failure) { | 1263 | if ($die_on_failure) { |
@@ -988,7 +1271,7 @@ sub fail { | |||
988 | # no need to reboot for just building. | 1271 | # no need to reboot for just building. |
989 | if (!do_not_reboot) { | 1272 | if (!do_not_reboot) { |
990 | doprint "REBOOTING\n"; | 1273 | doprint "REBOOTING\n"; |
991 | reboot $sleep_time; | 1274 | reboot_to_good $sleep_time; |
992 | } | 1275 | } |
993 | 1276 | ||
994 | my $name = ""; | 1277 | my $name = ""; |
@@ -1003,38 +1286,9 @@ sub fail { | |||
1003 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; | 1286 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; |
1004 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; | 1287 | doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; |
1005 | 1288 | ||
1006 | return 1 if (!defined($store_failures)); | 1289 | if (defined($store_failures)) { |
1007 | 1290 | save_logs "fail", $store_failures; | |
1008 | my @t = localtime; | 1291 | } |
1009 | my $date = sprintf "%04d%02d%02d%02d%02d%02d", | ||
1010 | 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0]; | ||
1011 | |||
1012 | my $type = $build_type; | ||
1013 | if ($type =~ /useconfig/) { | ||
1014 | $type = "useconfig"; | ||
1015 | } | ||
1016 | |||
1017 | my $dir = "$machine-$test_type-$type-fail-$date"; | ||
1018 | my $faildir = "$store_failures/$dir"; | ||
1019 | |||
1020 | if (!-d $faildir) { | ||
1021 | mkpath($faildir) or | ||
1022 | die "can't create $faildir"; | ||
1023 | } | ||
1024 | if (-f "$output_config") { | ||
1025 | cp "$output_config", "$faildir/config" or | ||
1026 | die "failed to copy .config"; | ||
1027 | } | ||
1028 | if (-f $buildlog) { | ||
1029 | cp $buildlog, "$faildir/buildlog" or | ||
1030 | die "failed to move $buildlog"; | ||
1031 | } | ||
1032 | if (-f $dmesg) { | ||
1033 | cp $dmesg, "$faildir/dmesg" or | ||
1034 | die "failed to move $dmesg"; | ||
1035 | } | ||
1036 | |||
1037 | doprint "*** Saved info to $faildir ***\n"; | ||
1038 | 1292 | ||
1039 | return 1; | 1293 | return 1; |
1040 | } | 1294 | } |
@@ -1170,13 +1424,16 @@ sub wait_for_input | |||
1170 | } | 1424 | } |
1171 | 1425 | ||
1172 | sub reboot_to { | 1426 | sub reboot_to { |
1427 | if (defined($switch_to_test)) { | ||
1428 | run_command $switch_to_test; | ||
1429 | } | ||
1430 | |||
1173 | if ($reboot_type eq "grub") { | 1431 | if ($reboot_type eq "grub") { |
1174 | run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'"; | 1432 | run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'"; |
1175 | reboot; | 1433 | } elsif (defined $reboot_script) { |
1176 | return; | 1434 | run_command "$reboot_script"; |
1177 | } | 1435 | } |
1178 | 1436 | reboot; | |
1179 | run_command "$reboot_script"; | ||
1180 | } | 1437 | } |
1181 | 1438 | ||
1182 | sub get_sha1 { | 1439 | sub get_sha1 { |
@@ -1274,7 +1531,7 @@ sub monitor { | |||
1274 | } | 1531 | } |
1275 | 1532 | ||
1276 | if ($full_line =~ /call trace:/i) { | 1533 | if ($full_line =~ /call trace:/i) { |
1277 | if (!$bug && !$skip_call_trace) { | 1534 | if (!$ignore_errors && !$bug && !$skip_call_trace) { |
1278 | $bug = 1; | 1535 | $bug = 1; |
1279 | $failure_start = time; | 1536 | $failure_start = time; |
1280 | } | 1537 | } |
@@ -1341,12 +1598,19 @@ sub monitor { | |||
1341 | return 1; | 1598 | return 1; |
1342 | } | 1599 | } |
1343 | 1600 | ||
1601 | sub eval_kernel_version { | ||
1602 | my ($option) = @_; | ||
1603 | |||
1604 | $option =~ s/\$KERNEL_VERSION/$version/g; | ||
1605 | |||
1606 | return $option; | ||
1607 | } | ||
1608 | |||
1344 | sub do_post_install { | 1609 | sub do_post_install { |
1345 | 1610 | ||
1346 | return if (!defined($post_install)); | 1611 | return if (!defined($post_install)); |
1347 | 1612 | ||
1348 | my $cp_post_install = $post_install; | 1613 | my $cp_post_install = eval_kernel_version $post_install; |
1349 | $cp_post_install =~ s/\$KERNEL_VERSION/$version/g; | ||
1350 | run_command "$cp_post_install" or | 1614 | run_command "$cp_post_install" or |
1351 | dodie "Failed to run post install"; | 1615 | dodie "Failed to run post install"; |
1352 | } | 1616 | } |
@@ -1355,7 +1619,9 @@ sub install { | |||
1355 | 1619 | ||
1356 | return if ($no_install); | 1620 | return if ($no_install); |
1357 | 1621 | ||
1358 | run_scp "$outputdir/$build_target", "$target_image" or | 1622 | my $cp_target = eval_kernel_version $target_image; |
1623 | |||
1624 | run_scp "$outputdir/$build_target", "$cp_target" or | ||
1359 | dodie "failed to copy image"; | 1625 | dodie "failed to copy image"; |
1360 | 1626 | ||
1361 | my $install_mods = 0; | 1627 | my $install_mods = 0; |
@@ -1640,9 +1906,13 @@ sub success { | |||
1640 | doprint "*******************************************\n"; | 1906 | doprint "*******************************************\n"; |
1641 | doprint "*******************************************\n"; | 1907 | doprint "*******************************************\n"; |
1642 | 1908 | ||
1909 | if (defined($store_successes)) { | ||
1910 | save_logs "success", $store_successes; | ||
1911 | } | ||
1912 | |||
1643 | if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) { | 1913 | if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) { |
1644 | doprint "Reboot and wait $sleep_time seconds\n"; | 1914 | doprint "Reboot and wait $sleep_time seconds\n"; |
1645 | reboot $sleep_time; | 1915 | reboot_to_good $sleep_time; |
1646 | } | 1916 | } |
1647 | } | 1917 | } |
1648 | 1918 | ||
@@ -1669,7 +1939,10 @@ sub child_run_test { | |||
1669 | $poweroff_on_error = 0; | 1939 | $poweroff_on_error = 0; |
1670 | $die_on_failure = 1; | 1940 | $die_on_failure = 1; |
1671 | 1941 | ||
1942 | $redirect = "$testlog"; | ||
1672 | run_command $run_test or $failed = 1; | 1943 | run_command $run_test or $failed = 1; |
1944 | undef $redirect; | ||
1945 | |||
1673 | exit $failed; | 1946 | exit $failed; |
1674 | } | 1947 | } |
1675 | 1948 | ||
@@ -1744,6 +2017,43 @@ sub do_run_test { | |||
1744 | waitpid $child_pid, 0; | 2017 | waitpid $child_pid, 0; |
1745 | $child_exit = $?; | 2018 | $child_exit = $?; |
1746 | 2019 | ||
2020 | if (!$bug && $in_bisect) { | ||
2021 | if (defined($bisect_ret_good)) { | ||
2022 | if ($child_exit == $bisect_ret_good) { | ||
2023 | return 1; | ||
2024 | } | ||
2025 | } | ||
2026 | if (defined($bisect_ret_skip)) { | ||
2027 | if ($child_exit == $bisect_ret_skip) { | ||
2028 | return -1; | ||
2029 | } | ||
2030 | } | ||
2031 | if (defined($bisect_ret_abort)) { | ||
2032 | if ($child_exit == $bisect_ret_abort) { | ||
2033 | fail "test abort" and return -2; | ||
2034 | } | ||
2035 | } | ||
2036 | if (defined($bisect_ret_bad)) { | ||
2037 | if ($child_exit == $bisect_ret_skip) { | ||
2038 | return 0; | ||
2039 | } | ||
2040 | } | ||
2041 | if (defined($bisect_ret_default)) { | ||
2042 | if ($bisect_ret_default eq "good") { | ||
2043 | return 1; | ||
2044 | } elsif ($bisect_ret_default eq "bad") { | ||
2045 | return 0; | ||
2046 | } elsif ($bisect_ret_default eq "skip") { | ||
2047 | return -1; | ||
2048 | } elsif ($bisect_ret_default eq "abort") { | ||
2049 | return -2; | ||
2050 | } else { | ||
2051 | fail "unknown default action: $bisect_ret_default" | ||
2052 | and return -2; | ||
2053 | } | ||
2054 | } | ||
2055 | } | ||
2056 | |||
1747 | if ($bug || $child_exit) { | 2057 | if ($bug || $child_exit) { |
1748 | return 0 if $in_bisect; | 2058 | return 0 if $in_bisect; |
1749 | fail "test failed" and return 0; | 2059 | fail "test failed" and return 0; |
@@ -1770,7 +2080,7 @@ sub run_git_bisect { | |||
1770 | if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) { | 2080 | if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) { |
1771 | doprint "$1 [$2]\n"; | 2081 | doprint "$1 [$2]\n"; |
1772 | } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) { | 2082 | } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) { |
1773 | $bisect_bad = $1; | 2083 | $bisect_bad_commit = $1; |
1774 | doprint "Found bad commit... $1\n"; | 2084 | doprint "Found bad commit... $1\n"; |
1775 | return 0; | 2085 | return 0; |
1776 | } else { | 2086 | } else { |
@@ -1783,7 +2093,7 @@ sub run_git_bisect { | |||
1783 | 2093 | ||
1784 | sub bisect_reboot { | 2094 | sub bisect_reboot { |
1785 | doprint "Reboot and sleep $bisect_sleep_time seconds\n"; | 2095 | doprint "Reboot and sleep $bisect_sleep_time seconds\n"; |
1786 | reboot $bisect_sleep_time; | 2096 | reboot_to_good $bisect_sleep_time; |
1787 | } | 2097 | } |
1788 | 2098 | ||
1789 | # returns 1 on success, 0 on failure, -1 on skip | 2099 | # returns 1 on success, 0 on failure, -1 on skip |
@@ -1868,21 +2178,28 @@ sub run_bisect { | |||
1868 | } | 2178 | } |
1869 | } | 2179 | } |
1870 | 2180 | ||
2181 | sub update_bisect_replay { | ||
2182 | my $tmp_log = "$tmpdir/ktest_bisect_log"; | ||
2183 | run_command "git bisect log > $tmp_log" or | ||
2184 | die "can't create bisect log"; | ||
2185 | return $tmp_log; | ||
2186 | } | ||
2187 | |||
1871 | sub bisect { | 2188 | sub bisect { |
1872 | my ($i) = @_; | 2189 | my ($i) = @_; |
1873 | 2190 | ||
1874 | my $result; | 2191 | my $result; |
1875 | 2192 | ||
1876 | die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"})); | 2193 | die "BISECT_GOOD[$i] not defined\n" if (!defined($bisect_good)); |
1877 | die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"})); | 2194 | die "BISECT_BAD[$i] not defined\n" if (!defined($bisect_bad)); |
1878 | die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"})); | 2195 | die "BISECT_TYPE[$i] not defined\n" if (!defined($bisect_type)); |
1879 | 2196 | ||
1880 | my $good = $opt{"BISECT_GOOD[$i]"}; | 2197 | my $good = $bisect_good; |
1881 | my $bad = $opt{"BISECT_BAD[$i]"}; | 2198 | my $bad = $bisect_bad; |
1882 | my $type = $opt{"BISECT_TYPE[$i]"}; | 2199 | my $type = $bisect_type; |
1883 | my $start = $opt{"BISECT_START[$i]"}; | 2200 | my $start = $bisect_start; |
1884 | my $replay = $opt{"BISECT_REPLAY[$i]"}; | 2201 | my $replay = $bisect_replay; |
1885 | my $start_files = $opt{"BISECT_FILES[$i]"}; | 2202 | my $start_files = $bisect_files; |
1886 | 2203 | ||
1887 | if (defined($start_files)) { | 2204 | if (defined($start_files)) { |
1888 | $start_files = " -- " . $start_files; | 2205 | $start_files = " -- " . $start_files; |
@@ -1894,8 +2211,7 @@ sub bisect { | |||
1894 | $good = get_sha1($good); | 2211 | $good = get_sha1($good); |
1895 | $bad = get_sha1($bad); | 2212 | $bad = get_sha1($bad); |
1896 | 2213 | ||
1897 | if (defined($opt{"BISECT_REVERSE[$i]"}) && | 2214 | if (defined($bisect_reverse) && $bisect_reverse == 1) { |
1898 | $opt{"BISECT_REVERSE[$i]"} == 1) { | ||
1899 | doprint "Performing a reverse bisect (bad is good, good is bad!)\n"; | 2215 | doprint "Performing a reverse bisect (bad is good, good is bad!)\n"; |
1900 | $reverse_bisect = 1; | 2216 | $reverse_bisect = 1; |
1901 | } else { | 2217 | } else { |
@@ -1907,8 +2223,31 @@ sub bisect { | |||
1907 | $type = "boot"; | 2223 | $type = "boot"; |
1908 | } | 2224 | } |
1909 | 2225 | ||
1910 | my $check = $opt{"BISECT_CHECK[$i]"}; | 2226 | # Check if a bisect was running |
1911 | if (defined($check) && $check ne "0") { | 2227 | my $bisect_start_file = "$builddir/.git/BISECT_START"; |
2228 | |||
2229 | my $check = $bisect_check; | ||
2230 | my $do_check = defined($check) && $check ne "0"; | ||
2231 | |||
2232 | if ( -f $bisect_start_file ) { | ||
2233 | print "Bisect in progress found\n"; | ||
2234 | if ($do_check) { | ||
2235 | print " If you say yes, then no checks of good or bad will be done\n"; | ||
2236 | } | ||
2237 | if (defined($replay)) { | ||
2238 | print "** BISECT_REPLAY is defined in config file **"; | ||
2239 | print " Ignore config option and perform new git bisect log?\n"; | ||
2240 | if (read_ync " (yes, no, or cancel) ") { | ||
2241 | $replay = update_bisect_replay; | ||
2242 | $do_check = 0; | ||
2243 | } | ||
2244 | } elsif (read_yn "read git log and continue?") { | ||
2245 | $replay = update_bisect_replay; | ||
2246 | $do_check = 0; | ||
2247 | } | ||
2248 | } | ||
2249 | |||
2250 | if ($do_check) { | ||
1912 | 2251 | ||
1913 | # get current HEAD | 2252 | # get current HEAD |
1914 | my $head = get_sha1("HEAD"); | 2253 | my $head = get_sha1("HEAD"); |
@@ -1973,7 +2312,7 @@ sub bisect { | |||
1973 | run_command "git bisect reset" or | 2312 | run_command "git bisect reset" or |
1974 | dodie "could not reset git bisect"; | 2313 | dodie "could not reset git bisect"; |
1975 | 2314 | ||
1976 | doprint "Bad commit was [$bisect_bad]\n"; | 2315 | doprint "Bad commit was [$bisect_bad_commit]\n"; |
1977 | 2316 | ||
1978 | success $i; | 2317 | success $i; |
1979 | } | 2318 | } |
@@ -2129,7 +2468,7 @@ sub run_config_bisect { | |||
2129 | } | 2468 | } |
2130 | 2469 | ||
2131 | doprint "***** RUN TEST ***\n"; | 2470 | doprint "***** RUN TEST ***\n"; |
2132 | my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"}; | 2471 | my $type = $config_bisect_type; |
2133 | my $ret; | 2472 | my $ret; |
2134 | my %current_config; | 2473 | my %current_config; |
2135 | 2474 | ||
@@ -2233,7 +2572,7 @@ sub run_config_bisect { | |||
2233 | sub config_bisect { | 2572 | sub config_bisect { |
2234 | my ($i) = @_; | 2573 | my ($i) = @_; |
2235 | 2574 | ||
2236 | my $start_config = $opt{"CONFIG_BISECT[$i]"}; | 2575 | my $start_config = $config_bisect; |
2237 | 2576 | ||
2238 | my $tmpconfig = "$tmpdir/use_config"; | 2577 | my $tmpconfig = "$tmpdir/use_config"; |
2239 | 2578 | ||
@@ -2346,29 +2685,29 @@ sub config_bisect { | |||
2346 | 2685 | ||
2347 | sub patchcheck_reboot { | 2686 | sub patchcheck_reboot { |
2348 | doprint "Reboot and sleep $patchcheck_sleep_time seconds\n"; | 2687 | doprint "Reboot and sleep $patchcheck_sleep_time seconds\n"; |
2349 | reboot $patchcheck_sleep_time; | 2688 | reboot_to_good $patchcheck_sleep_time; |
2350 | } | 2689 | } |
2351 | 2690 | ||
2352 | sub patchcheck { | 2691 | sub patchcheck { |
2353 | my ($i) = @_; | 2692 | my ($i) = @_; |
2354 | 2693 | ||
2355 | die "PATCHCHECK_START[$i] not defined\n" | 2694 | die "PATCHCHECK_START[$i] not defined\n" |
2356 | if (!defined($opt{"PATCHCHECK_START[$i]"})); | 2695 | if (!defined($patchcheck_start)); |
2357 | die "PATCHCHECK_TYPE[$i] not defined\n" | 2696 | die "PATCHCHECK_TYPE[$i] not defined\n" |
2358 | if (!defined($opt{"PATCHCHECK_TYPE[$i]"})); | 2697 | if (!defined($patchcheck_type)); |
2359 | 2698 | ||
2360 | my $start = $opt{"PATCHCHECK_START[$i]"}; | 2699 | my $start = $patchcheck_start; |
2361 | 2700 | ||
2362 | my $end = "HEAD"; | 2701 | my $end = "HEAD"; |
2363 | if (defined($opt{"PATCHCHECK_END[$i]"})) { | 2702 | if (defined($patchcheck_end)) { |
2364 | $end = $opt{"PATCHCHECK_END[$i]"}; | 2703 | $end = $patchcheck_end; |
2365 | } | 2704 | } |
2366 | 2705 | ||
2367 | # Get the true sha1's since we can use things like HEAD~3 | 2706 | # Get the true sha1's since we can use things like HEAD~3 |
2368 | $start = get_sha1($start); | 2707 | $start = get_sha1($start); |
2369 | $end = get_sha1($end); | 2708 | $end = get_sha1($end); |
2370 | 2709 | ||
2371 | my $type = $opt{"PATCHCHECK_TYPE[$i]"}; | 2710 | my $type = $patchcheck_type; |
2372 | 2711 | ||
2373 | # Can't have a test without having a test to run | 2712 | # Can't have a test without having a test to run |
2374 | if ($type eq "test" && !defined($run_test)) { | 2713 | if ($type eq "test" && !defined($run_test)) { |
@@ -2963,7 +3302,7 @@ sub make_min_config { | |||
2963 | } | 3302 | } |
2964 | 3303 | ||
2965 | doprint "Reboot and wait $sleep_time seconds\n"; | 3304 | doprint "Reboot and wait $sleep_time seconds\n"; |
2966 | reboot $sleep_time; | 3305 | reboot_to_good $sleep_time; |
2967 | } | 3306 | } |
2968 | 3307 | ||
2969 | success $i; | 3308 | success $i; |
@@ -2985,13 +3324,27 @@ if ($#ARGV == 0) { | |||
2985 | } | 3324 | } |
2986 | 3325 | ||
2987 | if (! -f $ktest_config) { | 3326 | if (! -f $ktest_config) { |
3327 | $newconfig = 1; | ||
3328 | get_test_case; | ||
2988 | open(OUT, ">$ktest_config") or die "Can not create $ktest_config"; | 3329 | open(OUT, ">$ktest_config") or die "Can not create $ktest_config"; |
2989 | print OUT << "EOF" | 3330 | print OUT << "EOF" |
2990 | # Generated by ktest.pl | 3331 | # Generated by ktest.pl |
2991 | # | 3332 | # |
3333 | |||
3334 | # PWD is a ktest.pl variable that will result in the process working | ||
3335 | # directory that ktest.pl is executed in. | ||
3336 | |||
3337 | # THIS_DIR is automatically assigned the PWD of the path that generated | ||
3338 | # the config file. It is best to use this variable when assigning other | ||
3339 | # directory paths within this directory. This allows you to easily | ||
3340 | # move the test cases to other locations or to other machines. | ||
3341 | # | ||
3342 | THIS_DIR := $variable{"PWD"} | ||
3343 | |||
2992 | # Define each test with TEST_START | 3344 | # Define each test with TEST_START |
2993 | # The config options below it will override the defaults | 3345 | # The config options below it will override the defaults |
2994 | TEST_START | 3346 | TEST_START |
3347 | TEST_TYPE = $default{"TEST_TYPE"} | ||
2995 | 3348 | ||
2996 | DEFAULTS | 3349 | DEFAULTS |
2997 | EOF | 3350 | EOF |
@@ -3011,7 +3364,7 @@ if ($#new_configs >= 0) { | |||
3011 | open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config"; | 3364 | open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config"; |
3012 | foreach my $config (@new_configs) { | 3365 | foreach my $config (@new_configs) { |
3013 | print OUT "$config = $entered_configs{$config}\n"; | 3366 | print OUT "$config = $entered_configs{$config}\n"; |
3014 | $opt{$config} = $entered_configs{$config}; | 3367 | $opt{$config} = process_variables($entered_configs{$config}); |
3015 | } | 3368 | } |
3016 | } | 3369 | } |
3017 | 3370 | ||
@@ -3091,61 +3444,10 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { | |||
3091 | 3444 | ||
3092 | my $makecmd = set_test_option("MAKE_CMD", $i); | 3445 | my $makecmd = set_test_option("MAKE_CMD", $i); |
3093 | 3446 | ||
3094 | $machine = set_test_option("MACHINE", $i); | 3447 | # Load all the options into their mapped variable names |
3095 | $ssh_user = set_test_option("SSH_USER", $i); | 3448 | foreach my $opt (keys %option_map) { |
3096 | $tmpdir = set_test_option("TMP_DIR", $i); | 3449 | ${$option_map{$opt}} = set_test_option($opt, $i); |
3097 | $outputdir = set_test_option("OUTPUT_DIR", $i); | 3450 | } |
3098 | $builddir = set_test_option("BUILD_DIR", $i); | ||
3099 | $test_type = set_test_option("TEST_TYPE", $i); | ||
3100 | $build_type = set_test_option("BUILD_TYPE", $i); | ||
3101 | $build_options = set_test_option("BUILD_OPTIONS", $i); | ||
3102 | $pre_build = set_test_option("PRE_BUILD", $i); | ||
3103 | $post_build = set_test_option("POST_BUILD", $i); | ||
3104 | $pre_build_die = set_test_option("PRE_BUILD_DIE", $i); | ||
3105 | $post_build_die = set_test_option("POST_BUILD_DIE", $i); | ||
3106 | $power_cycle = set_test_option("POWER_CYCLE", $i); | ||
3107 | $reboot = set_test_option("REBOOT", $i); | ||
3108 | $noclean = set_test_option("BUILD_NOCLEAN", $i); | ||
3109 | $minconfig = set_test_option("MIN_CONFIG", $i); | ||
3110 | $output_minconfig = set_test_option("OUTPUT_MIN_CONFIG", $i); | ||
3111 | $start_minconfig = set_test_option("START_MIN_CONFIG", $i); | ||
3112 | $ignore_config = set_test_option("IGNORE_CONFIG", $i); | ||
3113 | $run_test = set_test_option("TEST", $i); | ||
3114 | $addconfig = set_test_option("ADD_CONFIG", $i); | ||
3115 | $reboot_type = set_test_option("REBOOT_TYPE", $i); | ||
3116 | $grub_menu = set_test_option("GRUB_MENU", $i); | ||
3117 | $post_install = set_test_option("POST_INSTALL", $i); | ||
3118 | $no_install = set_test_option("NO_INSTALL", $i); | ||
3119 | $reboot_script = set_test_option("REBOOT_SCRIPT", $i); | ||
3120 | $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i); | ||
3121 | $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i); | ||
3122 | $die_on_failure = set_test_option("DIE_ON_FAILURE", $i); | ||
3123 | $power_off = set_test_option("POWER_OFF", $i); | ||
3124 | $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i); | ||
3125 | $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i); | ||
3126 | $sleep_time = set_test_option("SLEEP_TIME", $i); | ||
3127 | $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i); | ||
3128 | $patchcheck_sleep_time = set_test_option("PATCHCHECK_SLEEP_TIME", $i); | ||
3129 | $ignore_warnings = set_test_option("IGNORE_WARNINGS", $i); | ||
3130 | $bisect_manual = set_test_option("BISECT_MANUAL", $i); | ||
3131 | $bisect_skip = set_test_option("BISECT_SKIP", $i); | ||
3132 | $config_bisect_good = set_test_option("CONFIG_BISECT_GOOD", $i); | ||
3133 | $store_failures = set_test_option("STORE_FAILURES", $i); | ||
3134 | $test_name = set_test_option("TEST_NAME", $i); | ||
3135 | $timeout = set_test_option("TIMEOUT", $i); | ||
3136 | $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i); | ||
3137 | $console = set_test_option("CONSOLE", $i); | ||
3138 | $detect_triplefault = set_test_option("DETECT_TRIPLE_FAULT", $i); | ||
3139 | $success_line = set_test_option("SUCCESS_LINE", $i); | ||
3140 | $reboot_success_line = set_test_option("REBOOT_SUCCESS_LINE", $i); | ||
3141 | $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i); | ||
3142 | $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i); | ||
3143 | $stop_test_after = set_test_option("STOP_TEST_AFTER", $i); | ||
3144 | $build_target = set_test_option("BUILD_TARGET", $i); | ||
3145 | $ssh_exec = set_test_option("SSH_EXEC", $i); | ||
3146 | $scp_to_target = set_test_option("SCP_TO_TARGET", $i); | ||
3147 | $target_image = set_test_option("TARGET_IMAGE", $i); | ||
3148 | $localversion = set_test_option("LOCALVERSION", $i); | ||
3149 | 3451 | ||
3150 | $start_minconfig_defined = 1; | 3452 | $start_minconfig_defined = 1; |
3151 | 3453 | ||
@@ -3166,26 +3468,26 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { | |||
3166 | $ENV{"SSH_USER"} = $ssh_user; | 3468 | $ENV{"SSH_USER"} = $ssh_user; |
3167 | $ENV{"MACHINE"} = $machine; | 3469 | $ENV{"MACHINE"} = $machine; |
3168 | 3470 | ||
3169 | $target = "$ssh_user\@$machine"; | ||
3170 | |||
3171 | $buildlog = "$tmpdir/buildlog-$machine"; | 3471 | $buildlog = "$tmpdir/buildlog-$machine"; |
3472 | $testlog = "$tmpdir/testlog-$machine"; | ||
3172 | $dmesg = "$tmpdir/dmesg-$machine"; | 3473 | $dmesg = "$tmpdir/dmesg-$machine"; |
3173 | $make = "$makecmd O=$outputdir"; | 3474 | $make = "$makecmd O=$outputdir"; |
3174 | $output_config = "$outputdir/.config"; | 3475 | $output_config = "$outputdir/.config"; |
3175 | 3476 | ||
3176 | if ($reboot_type eq "grub") { | 3477 | if (!$buildonly) { |
3177 | dodie "GRUB_MENU not defined" if (!defined($grub_menu)); | 3478 | $target = "$ssh_user\@$machine"; |
3178 | } elsif (!defined($reboot_script)) { | 3479 | if ($reboot_type eq "grub") { |
3179 | dodie "REBOOT_SCRIPT not defined" | 3480 | dodie "GRUB_MENU not defined" if (!defined($grub_menu)); |
3481 | } | ||
3180 | } | 3482 | } |
3181 | 3483 | ||
3182 | my $run_type = $build_type; | 3484 | my $run_type = $build_type; |
3183 | if ($test_type eq "patchcheck") { | 3485 | if ($test_type eq "patchcheck") { |
3184 | $run_type = $opt{"PATCHCHECK_TYPE[$i]"}; | 3486 | $run_type = $patchcheck_type; |
3185 | } elsif ($test_type eq "bisect") { | 3487 | } elsif ($test_type eq "bisect") { |
3186 | $run_type = $opt{"BISECT_TYPE[$i]"}; | 3488 | $run_type = $bisect_type; |
3187 | } elsif ($test_type eq "config_bisect") { | 3489 | } elsif ($test_type eq "config_bisect") { |
3188 | $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"}; | 3490 | $run_type = $config_bisect_type; |
3189 | } | 3491 | } |
3190 | 3492 | ||
3191 | if ($test_type eq "make_min_config") { | 3493 | if ($test_type eq "make_min_config") { |
@@ -3205,6 +3507,7 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { | |||
3205 | 3507 | ||
3206 | unlink $dmesg; | 3508 | unlink $dmesg; |
3207 | unlink $buildlog; | 3509 | unlink $buildlog; |
3510 | unlink $testlog; | ||
3208 | 3511 | ||
3209 | if (defined($addconfig)) { | 3512 | if (defined($addconfig)) { |
3210 | my $min = $minconfig; | 3513 | my $min = $minconfig; |
@@ -3216,7 +3519,6 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { | |||
3216 | $minconfig = "$tmpdir/add_config"; | 3519 | $minconfig = "$tmpdir/add_config"; |
3217 | } | 3520 | } |
3218 | 3521 | ||
3219 | my $checkout = $opt{"CHECKOUT[$i]"}; | ||
3220 | if (defined($checkout)) { | 3522 | if (defined($checkout)) { |
3221 | run_command "git checkout $checkout" or | 3523 | run_command "git checkout $checkout" or |
3222 | die "failed to checkout $checkout"; | 3524 | die "failed to checkout $checkout"; |
@@ -3267,7 +3569,7 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) { | |||
3267 | if ($opt{"POWEROFF_ON_SUCCESS"}) { | 3569 | if ($opt{"POWEROFF_ON_SUCCESS"}) { |
3268 | halt; | 3570 | halt; |
3269 | } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) { | 3571 | } elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) { |
3270 | reboot; | 3572 | reboot_to_good; |
3271 | } | 3573 | } |
3272 | 3574 | ||
3273 | doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n"; | 3575 | doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n"; |
diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf index 553c06b7d6f2..5ea04c6a71bf 100644 --- a/tools/testing/ktest/sample.conf +++ b/tools/testing/ktest/sample.conf | |||
@@ -346,7 +346,10 @@ | |||
346 | #GRUB_MENU = Test Kernel | 346 | #GRUB_MENU = Test Kernel |
347 | 347 | ||
348 | # A script to reboot the target into the test kernel | 348 | # A script to reboot the target into the test kernel |
349 | # (Only mandatory if REBOOT_TYPE = script) | 349 | # This and SWITCH_TO_TEST are about the same, except |
350 | # SWITCH_TO_TEST is run even for REBOOT_TYPE = grub. | ||
351 | # This may be left undefined. | ||
352 | # (default undefined) | ||
350 | #REBOOT_SCRIPT = | 353 | #REBOOT_SCRIPT = |
351 | 354 | ||
352 | #### Optional Config Options (all have defaults) #### | 355 | #### Optional Config Options (all have defaults) #### |
@@ -468,6 +471,27 @@ | |||
468 | # The test will not modify that file. | 471 | # The test will not modify that file. |
469 | #REBOOT_TYPE = grub | 472 | #REBOOT_TYPE = grub |
470 | 473 | ||
474 | # If you are using a machine that doesn't boot with grub, and | ||
475 | # perhaps gets its kernel from a remote server (tftp), then | ||
476 | # you can use this option to update the target image with the | ||
477 | # test image. | ||
478 | # | ||
479 | # You could also do the same with POST_INSTALL, but the difference | ||
480 | # between that option and this option is that POST_INSTALL runs | ||
481 | # after the install, where this one runs just before a reboot. | ||
482 | # (default undefined) | ||
483 | #SWITCH_TO_TEST = cp ${OUTPUT_DIR}/${BUILD_TARGET} ${TARGET_IMAGE} | ||
484 | |||
485 | # If you are using a machine that doesn't boot with grub, and | ||
486 | # perhaps gets its kernel from a remote server (tftp), then | ||
487 | # you can use this option to update the target image with the | ||
488 | # the known good image to reboot safely back into. | ||
489 | # | ||
490 | # This option holds a command that will execute before needing | ||
491 | # to reboot to a good known image. | ||
492 | # (default undefined) | ||
493 | #SWITCH_TO_GOOD = ssh ${SSH_USER}/${MACHINE} cp good_image ${TARGET_IMAGE} | ||
494 | |||
471 | # The min config that is needed to build for the machine | 495 | # The min config that is needed to build for the machine |
472 | # A nice way to create this is with the following: | 496 | # A nice way to create this is with the following: |
473 | # | 497 | # |
@@ -589,6 +613,12 @@ | |||
589 | # (default undefined) | 613 | # (default undefined) |
590 | #STORE_FAILURES = /home/test/failures | 614 | #STORE_FAILURES = /home/test/failures |
591 | 615 | ||
616 | # Directory to store success directories on success. If this is not | ||
617 | # set, the .config, dmesg and bootlog will not be saved if a | ||
618 | # test succeeds. | ||
619 | # (default undefined) | ||
620 | #STORE_SUCCESSES = /home/test/successes | ||
621 | |||
592 | # Build without doing a make mrproper, or removing .config | 622 | # Build without doing a make mrproper, or removing .config |
593 | # (default 0) | 623 | # (default 0) |
594 | #BUILD_NOCLEAN = 0 | 624 | #BUILD_NOCLEAN = 0 |
@@ -700,6 +730,25 @@ | |||
700 | # (default 1) | 730 | # (default 1) |
701 | #DETECT_TRIPLE_FAULT = 0 | 731 | #DETECT_TRIPLE_FAULT = 0 |
702 | 732 | ||
733 | # All options in the config file should be either used by ktest | ||
734 | # or could be used within a value of another option. If an option | ||
735 | # in the config file is not used, ktest will warn about it and ask | ||
736 | # if you want to continue. | ||
737 | # | ||
738 | # If you don't care if there are non-used options, enable this | ||
739 | # option. Be careful though, a non-used option is usually a sign | ||
740 | # of an option name being typed incorrectly. | ||
741 | # (default 0) | ||
742 | #IGNORE_UNUSED = 1 | ||
743 | |||
744 | # When testing a kernel that happens to have WARNINGs, and call | ||
745 | # traces, ktest.pl will detect these and fail a boot or test run | ||
746 | # due to warnings. By setting this option, ktest will ignore | ||
747 | # call traces, and will not fail a test if the kernel produces | ||
748 | # an oops. Use this option with care. | ||
749 | # (default 0) | ||
750 | #IGNORE_ERRORS = 1 | ||
751 | |||
703 | #### Per test run options #### | 752 | #### Per test run options #### |
704 | # The following options are only allowed in TEST_START sections. | 753 | # The following options are only allowed in TEST_START sections. |
705 | # They are ignored in the DEFAULTS sections. | 754 | # They are ignored in the DEFAULTS sections. |
@@ -862,6 +911,42 @@ | |||
862 | # BISECT_BAD with BISECT_CHECK = good or | 911 | # BISECT_BAD with BISECT_CHECK = good or |
863 | # BISECT_CHECK = bad, respectively. | 912 | # BISECT_CHECK = bad, respectively. |
864 | # | 913 | # |
914 | # BISECT_RET_GOOD = 0 (optional, default undefined) | ||
915 | # | ||
916 | # In case the specificed test returns something other than just | ||
917 | # 0 for good, and non-zero for bad, you can override 0 being | ||
918 | # good by defining BISECT_RET_GOOD. | ||
919 | # | ||
920 | # BISECT_RET_BAD = 1 (optional, default undefined) | ||
921 | # | ||
922 | # In case the specificed test returns something other than just | ||
923 | # 0 for good, and non-zero for bad, you can override non-zero being | ||
924 | # bad by defining BISECT_RET_BAD. | ||
925 | # | ||
926 | # BISECT_RET_ABORT = 255 (optional, default undefined) | ||
927 | # | ||
928 | # If you need to abort the bisect if the test discovers something | ||
929 | # that was wrong, you can define BISECT_RET_ABORT to be the error | ||
930 | # code returned by the test in order to abort the bisect. | ||
931 | # | ||
932 | # BISECT_RET_SKIP = 2 (optional, default undefined) | ||
933 | # | ||
934 | # If the test detects that the current commit is neither good | ||
935 | # nor bad, but something else happened (another bug detected) | ||
936 | # you can specify BISECT_RET_SKIP to an error code that the | ||
937 | # test returns when it should skip the current commit. | ||
938 | # | ||
939 | # BISECT_RET_DEFAULT = good (optional, default undefined) | ||
940 | # | ||
941 | # You can override the default of what to do when the above | ||
942 | # options are not hit. This may be one of, "good", "bad", | ||
943 | # "abort" or "skip" (without the quotes). | ||
944 | # | ||
945 | # Note, if you do not define any of the previous BISECT_RET_* | ||
946 | # and define BISECT_RET_DEFAULT, all bisects results will do | ||
947 | # what the BISECT_RET_DEFAULT has. | ||
948 | # | ||
949 | # | ||
865 | # Example: | 950 | # Example: |
866 | # TEST_START | 951 | # TEST_START |
867 | # TEST_TYPE = bisect | 952 | # TEST_TYPE = bisect |
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile new file mode 100644 index 000000000000..4ec84018cc13 --- /dev/null +++ b/tools/testing/selftests/Makefile | |||
@@ -0,0 +1,11 @@ | |||
1 | TARGETS = breakpoints | ||
2 | |||
3 | all: | ||
4 | for TARGET in $(TARGETS); do \ | ||
5 | make -C $$TARGET; \ | ||
6 | done; | ||
7 | |||
8 | clean: | ||
9 | for TARGET in $(TARGETS); do \ | ||
10 | make -C $$TARGET clean; \ | ||
11 | done; | ||
diff --git a/tools/testing/selftests/breakpoints/Makefile b/tools/testing/selftests/breakpoints/Makefile new file mode 100644 index 000000000000..f362722cdce7 --- /dev/null +++ b/tools/testing/selftests/breakpoints/Makefile | |||
@@ -0,0 +1,20 @@ | |||
1 | # Taken from perf makefile | ||
2 | uname_M := $(shell uname -m 2>/dev/null || echo not) | ||
3 | ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/) | ||
4 | ifeq ($(ARCH),i386) | ||
5 | ARCH := x86 | ||
6 | endif | ||
7 | ifeq ($(ARCH),x86_64) | ||
8 | ARCH := x86 | ||
9 | endif | ||
10 | |||
11 | |||
12 | all: | ||
13 | ifeq ($(ARCH),x86) | ||
14 | gcc breakpoint_test.c -o run_test | ||
15 | else | ||
16 | echo "Not an x86 target, can't build breakpoints selftests" | ||
17 | endif | ||
18 | |||
19 | clean: | ||
20 | rm -fr run_test | ||
diff --git a/tools/testing/selftests/breakpoints/breakpoint_test.c b/tools/testing/selftests/breakpoints/breakpoint_test.c new file mode 100644 index 000000000000..a0743f3b2b57 --- /dev/null +++ b/tools/testing/selftests/breakpoints/breakpoint_test.c | |||
@@ -0,0 +1,394 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2011 Red Hat, Inc., Frederic Weisbecker <fweisbec@redhat.com> | ||
3 | * | ||
4 | * Licensed under the terms of the GNU GPL License version 2 | ||
5 | * | ||
6 | * Selftests for breakpoints (and more generally the do_debug() path) in x86. | ||
7 | */ | ||
8 | |||
9 | |||
10 | #include <sys/ptrace.h> | ||
11 | #include <unistd.h> | ||
12 | #include <stddef.h> | ||
13 | #include <sys/user.h> | ||
14 | #include <stdio.h> | ||
15 | #include <stdlib.h> | ||
16 | #include <signal.h> | ||
17 | #include <sys/types.h> | ||
18 | #include <sys/wait.h> | ||
19 | |||
20 | |||
21 | /* Breakpoint access modes */ | ||
22 | enum { | ||
23 | BP_X = 1, | ||
24 | BP_RW = 2, | ||
25 | BP_W = 4, | ||
26 | }; | ||
27 | |||
28 | static pid_t child_pid; | ||
29 | |||
30 | /* | ||
31 | * Ensures the child and parent are always "talking" about | ||
32 | * the same test sequence. (ie: that we haven't forgotten | ||
33 | * to call check_trapped() somewhere). | ||
34 | */ | ||
35 | static int nr_tests; | ||
36 | |||
37 | static void set_breakpoint_addr(void *addr, int n) | ||
38 | { | ||
39 | int ret; | ||
40 | |||
41 | ret = ptrace(PTRACE_POKEUSER, child_pid, | ||
42 | offsetof(struct user, u_debugreg[n]), addr); | ||
43 | if (ret) { | ||
44 | perror("Can't set breakpoint addr\n"); | ||
45 | exit(-1); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | static void toggle_breakpoint(int n, int type, int len, | ||
50 | int local, int global, int set) | ||
51 | { | ||
52 | int ret; | ||
53 | |||
54 | int xtype, xlen; | ||
55 | unsigned long vdr7, dr7; | ||
56 | |||
57 | switch (type) { | ||
58 | case BP_X: | ||
59 | xtype = 0; | ||
60 | break; | ||
61 | case BP_W: | ||
62 | xtype = 1; | ||
63 | break; | ||
64 | case BP_RW: | ||
65 | xtype = 3; | ||
66 | break; | ||
67 | } | ||
68 | |||
69 | switch (len) { | ||
70 | case 1: | ||
71 | xlen = 0; | ||
72 | break; | ||
73 | case 2: | ||
74 | xlen = 4; | ||
75 | break; | ||
76 | case 4: | ||
77 | xlen = 0xc; | ||
78 | break; | ||
79 | case 8: | ||
80 | xlen = 8; | ||
81 | break; | ||
82 | } | ||
83 | |||
84 | dr7 = ptrace(PTRACE_PEEKUSER, child_pid, | ||
85 | offsetof(struct user, u_debugreg[7]), 0); | ||
86 | |||
87 | vdr7 = (xlen | xtype) << 16; | ||
88 | vdr7 <<= 4 * n; | ||
89 | |||
90 | if (local) { | ||
91 | vdr7 |= 1 << (2 * n); | ||
92 | vdr7 |= 1 << 8; | ||
93 | } | ||
94 | if (global) { | ||
95 | vdr7 |= 2 << (2 * n); | ||
96 | vdr7 |= 1 << 9; | ||
97 | } | ||
98 | |||
99 | if (set) | ||
100 | dr7 |= vdr7; | ||
101 | else | ||
102 | dr7 &= ~vdr7; | ||
103 | |||
104 | ret = ptrace(PTRACE_POKEUSER, child_pid, | ||
105 | offsetof(struct user, u_debugreg[7]), dr7); | ||
106 | if (ret) { | ||
107 | perror("Can't set dr7"); | ||
108 | exit(-1); | ||
109 | } | ||
110 | } | ||
111 | |||
112 | /* Dummy variables to test read/write accesses */ | ||
113 | static unsigned long long dummy_var[4]; | ||
114 | |||
115 | /* Dummy functions to test execution accesses */ | ||
116 | static void dummy_func(void) { } | ||
117 | static void dummy_func1(void) { } | ||
118 | static void dummy_func2(void) { } | ||
119 | static void dummy_func3(void) { } | ||
120 | |||
121 | static void (*dummy_funcs[])(void) = { | ||
122 | dummy_func, | ||
123 | dummy_func1, | ||
124 | dummy_func2, | ||
125 | dummy_func3, | ||
126 | }; | ||
127 | |||
128 | static int trapped; | ||
129 | |||
130 | static void check_trapped(void) | ||
131 | { | ||
132 | /* | ||
133 | * If we haven't trapped, wake up the parent | ||
134 | * so that it notices the failure. | ||
135 | */ | ||
136 | if (!trapped) | ||
137 | kill(getpid(), SIGUSR1); | ||
138 | trapped = 0; | ||
139 | |||
140 | nr_tests++; | ||
141 | } | ||
142 | |||
143 | static void write_var(int len) | ||
144 | { | ||
145 | char *pcval; short *psval; int *pival; long long *plval; | ||
146 | int i; | ||
147 | |||
148 | for (i = 0; i < 4; i++) { | ||
149 | switch (len) { | ||
150 | case 1: | ||
151 | pcval = (char *)&dummy_var[i]; | ||
152 | *pcval = 0xff; | ||
153 | break; | ||
154 | case 2: | ||
155 | psval = (short *)&dummy_var[i]; | ||
156 | *psval = 0xffff; | ||
157 | break; | ||
158 | case 4: | ||
159 | pival = (int *)&dummy_var[i]; | ||
160 | *pival = 0xffffffff; | ||
161 | break; | ||
162 | case 8: | ||
163 | plval = (long long *)&dummy_var[i]; | ||
164 | *plval = 0xffffffffffffffffLL; | ||
165 | break; | ||
166 | } | ||
167 | check_trapped(); | ||
168 | } | ||
169 | } | ||
170 | |||
171 | static void read_var(int len) | ||
172 | { | ||
173 | char cval; short sval; int ival; long long lval; | ||
174 | int i; | ||
175 | |||
176 | for (i = 0; i < 4; i++) { | ||
177 | switch (len) { | ||
178 | case 1: | ||
179 | cval = *(char *)&dummy_var[i]; | ||
180 | break; | ||
181 | case 2: | ||
182 | sval = *(short *)&dummy_var[i]; | ||
183 | break; | ||
184 | case 4: | ||
185 | ival = *(int *)&dummy_var[i]; | ||
186 | break; | ||
187 | case 8: | ||
188 | lval = *(long long *)&dummy_var[i]; | ||
189 | break; | ||
190 | } | ||
191 | check_trapped(); | ||
192 | } | ||
193 | } | ||
194 | |||
195 | /* | ||
196 | * Do the r/w/x accesses to trigger the breakpoints. And run | ||
197 | * the usual traps. | ||
198 | */ | ||
199 | static void trigger_tests(void) | ||
200 | { | ||
201 | int len, local, global, i; | ||
202 | char val; | ||
203 | int ret; | ||
204 | |||
205 | ret = ptrace(PTRACE_TRACEME, 0, NULL, 0); | ||
206 | if (ret) { | ||
207 | perror("Can't be traced?\n"); | ||
208 | return; | ||
209 | } | ||
210 | |||
211 | /* Wake up father so that it sets up the first test */ | ||
212 | kill(getpid(), SIGUSR1); | ||
213 | |||
214 | /* Test instruction breakpoints */ | ||
215 | for (local = 0; local < 2; local++) { | ||
216 | for (global = 0; global < 2; global++) { | ||
217 | if (!local && !global) | ||
218 | continue; | ||
219 | |||
220 | for (i = 0; i < 4; i++) { | ||
221 | dummy_funcs[i](); | ||
222 | check_trapped(); | ||
223 | } | ||
224 | } | ||
225 | } | ||
226 | |||
227 | /* Test write watchpoints */ | ||
228 | for (len = 1; len <= sizeof(long); len <<= 1) { | ||
229 | for (local = 0; local < 2; local++) { | ||
230 | for (global = 0; global < 2; global++) { | ||
231 | if (!local && !global) | ||
232 | continue; | ||
233 | write_var(len); | ||
234 | } | ||
235 | } | ||
236 | } | ||
237 | |||
238 | /* Test read/write watchpoints (on read accesses) */ | ||
239 | for (len = 1; len <= sizeof(long); len <<= 1) { | ||
240 | for (local = 0; local < 2; local++) { | ||
241 | for (global = 0; global < 2; global++) { | ||
242 | if (!local && !global) | ||
243 | continue; | ||
244 | read_var(len); | ||
245 | } | ||
246 | } | ||
247 | } | ||
248 | |||
249 | /* Icebp trap */ | ||
250 | asm(".byte 0xf1\n"); | ||
251 | check_trapped(); | ||
252 | |||
253 | /* Int 3 trap */ | ||
254 | asm("int $3\n"); | ||
255 | check_trapped(); | ||
256 | |||
257 | kill(getpid(), SIGUSR1); | ||
258 | } | ||
259 | |||
260 | static void check_success(const char *msg) | ||
261 | { | ||
262 | const char *msg2; | ||
263 | int child_nr_tests; | ||
264 | int status; | ||
265 | |||
266 | /* Wait for the child to SIGTRAP */ | ||
267 | wait(&status); | ||
268 | |||
269 | msg2 = "Failed"; | ||
270 | |||
271 | if (WSTOPSIG(status) == SIGTRAP) { | ||
272 | child_nr_tests = ptrace(PTRACE_PEEKDATA, child_pid, | ||
273 | &nr_tests, 0); | ||
274 | if (child_nr_tests == nr_tests) | ||
275 | msg2 = "Ok"; | ||
276 | if (ptrace(PTRACE_POKEDATA, child_pid, &trapped, 1)) { | ||
277 | perror("Can't poke\n"); | ||
278 | exit(-1); | ||
279 | } | ||
280 | } | ||
281 | |||
282 | nr_tests++; | ||
283 | |||
284 | printf("%s [%s]\n", msg, msg2); | ||
285 | } | ||
286 | |||
287 | static void launch_instruction_breakpoints(char *buf, int local, int global) | ||
288 | { | ||
289 | int i; | ||
290 | |||
291 | for (i = 0; i < 4; i++) { | ||
292 | set_breakpoint_addr(dummy_funcs[i], i); | ||
293 | toggle_breakpoint(i, BP_X, 1, local, global, 1); | ||
294 | ptrace(PTRACE_CONT, child_pid, NULL, 0); | ||
295 | sprintf(buf, "Test breakpoint %d with local: %d global: %d", | ||
296 | i, local, global); | ||
297 | check_success(buf); | ||
298 | toggle_breakpoint(i, BP_X, 1, local, global, 0); | ||
299 | } | ||
300 | } | ||
301 | |||
302 | static void launch_watchpoints(char *buf, int mode, int len, | ||
303 | int local, int global) | ||
304 | { | ||
305 | const char *mode_str; | ||
306 | int i; | ||
307 | |||
308 | if (mode == BP_W) | ||
309 | mode_str = "write"; | ||
310 | else | ||
311 | mode_str = "read"; | ||
312 | |||
313 | for (i = 0; i < 4; i++) { | ||
314 | set_breakpoint_addr(&dummy_var[i], i); | ||
315 | toggle_breakpoint(i, mode, len, local, global, 1); | ||
316 | ptrace(PTRACE_CONT, child_pid, NULL, 0); | ||
317 | sprintf(buf, "Test %s watchpoint %d with len: %d local: " | ||
318 | "%d global: %d", mode_str, i, len, local, global); | ||
319 | check_success(buf); | ||
320 | toggle_breakpoint(i, mode, len, local, global, 0); | ||
321 | } | ||
322 | } | ||
323 | |||
324 | /* Set the breakpoints and check the child successfully trigger them */ | ||
325 | static void launch_tests(void) | ||
326 | { | ||
327 | char buf[1024]; | ||
328 | int len, local, global, i; | ||
329 | |||
330 | /* Instruction breakpoints */ | ||
331 | for (local = 0; local < 2; local++) { | ||
332 | for (global = 0; global < 2; global++) { | ||
333 | if (!local && !global) | ||
334 | continue; | ||
335 | launch_instruction_breakpoints(buf, local, global); | ||
336 | } | ||
337 | } | ||
338 | |||
339 | /* Write watchpoint */ | ||
340 | for (len = 1; len <= sizeof(long); len <<= 1) { | ||
341 | for (local = 0; local < 2; local++) { | ||
342 | for (global = 0; global < 2; global++) { | ||
343 | if (!local && !global) | ||
344 | continue; | ||
345 | launch_watchpoints(buf, BP_W, len, | ||
346 | local, global); | ||
347 | } | ||
348 | } | ||
349 | } | ||
350 | |||
351 | /* Read-Write watchpoint */ | ||
352 | for (len = 1; len <= sizeof(long); len <<= 1) { | ||
353 | for (local = 0; local < 2; local++) { | ||
354 | for (global = 0; global < 2; global++) { | ||
355 | if (!local && !global) | ||
356 | continue; | ||
357 | launch_watchpoints(buf, BP_RW, len, | ||
358 | local, global); | ||
359 | } | ||
360 | } | ||
361 | } | ||
362 | |||
363 | /* Icebp traps */ | ||
364 | ptrace(PTRACE_CONT, child_pid, NULL, 0); | ||
365 | check_success("Test icebp"); | ||
366 | |||
367 | /* Int 3 traps */ | ||
368 | ptrace(PTRACE_CONT, child_pid, NULL, 0); | ||
369 | check_success("Test int 3 trap"); | ||
370 | |||
371 | ptrace(PTRACE_CONT, child_pid, NULL, 0); | ||
372 | } | ||
373 | |||
374 | int main(int argc, char **argv) | ||
375 | { | ||
376 | pid_t pid; | ||
377 | int ret; | ||
378 | |||
379 | pid = fork(); | ||
380 | if (!pid) { | ||
381 | trigger_tests(); | ||
382 | return 0; | ||
383 | } | ||
384 | |||
385 | child_pid = pid; | ||
386 | |||
387 | wait(NULL); | ||
388 | |||
389 | launch_tests(); | ||
390 | |||
391 | wait(NULL); | ||
392 | |||
393 | return 0; | ||
394 | } | ||
diff --git a/tools/testing/selftests/run_tests b/tools/testing/selftests/run_tests new file mode 100644 index 000000000000..320718a4e6bf --- /dev/null +++ b/tools/testing/selftests/run_tests | |||
@@ -0,0 +1,8 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | TARGETS=breakpoints | ||
4 | |||
5 | for TARGET in $TARGETS | ||
6 | do | ||
7 | $TARGET/run_test | ||
8 | done | ||