diff options
author | Steven Rostedt <srostedt@redhat.com> | 2011-09-30 21:00:00 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2011-10-17 11:54:11 -0400 |
commit | 2ed3b16128e93309758e62937e7f137ac9844227 (patch) | |
tree | 60d7b1ecf43121c662ffceac558232161a1e5f20 /tools/testing | |
parent | ab7a3f52cef5ff1c784de7adfbda3421b10754a4 (diff) |
ktest: Add INCLUDE keyword to include other config files
Have the reading of the config file allow reading of other config
files using the INCLUDE keyword. This allows multiple config files
to share config options.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'tools/testing')
-rwxr-xr-x | tools/testing/ktest/ktest.pl | 55 | ||||
-rw-r--r-- | tools/testing/ktest/sample.conf | 32 |
2 files changed, 78 insertions, 9 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index ed20d6881ec9..62de47de2b04 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl | |||
@@ -412,15 +412,16 @@ sub process_if { | |||
412 | return 1; | 412 | return 1; |
413 | } | 413 | } |
414 | 414 | ||
415 | sub read_config { | 415 | sub __read_config { |
416 | my ($config) = @_; | 416 | my ($config, $current_test_num) = @_; |
417 | 417 | ||
418 | open(IN, $config) || die "can't read file $config"; | 418 | my $in; |
419 | open($in, $config) || die "can't read file $config"; | ||
419 | 420 | ||
420 | my $name = $config; | 421 | my $name = $config; |
421 | $name =~ s,.*/(.*),$1,; | 422 | $name =~ s,.*/(.*),$1,; |
422 | 423 | ||
423 | my $test_num = 0; | 424 | my $test_num = $$current_test_num; |
424 | my $default = 1; | 425 | my $default = 1; |
425 | my $repeat = 1; | 426 | my $repeat = 1; |
426 | my $num_tests_set = 0; | 427 | my $num_tests_set = 0; |
@@ -430,7 +431,7 @@ sub read_config { | |||
430 | my $if = 0; | 431 | my $if = 0; |
431 | my $if_set = 0; | 432 | my $if_set = 0; |
432 | 433 | ||
433 | while (<IN>) { | 434 | while (<$in>) { |
434 | 435 | ||
435 | # ignore blank lines and comments | 436 | # ignore blank lines and comments |
436 | next if (/^\s*$/ || /\s*\#/); | 437 | next if (/^\s*$/ || /\s*\#/); |
@@ -539,6 +540,33 @@ sub read_config { | |||
539 | die "$name: $.: Gargbage found after DEFAULTS\n$_"; | 540 | die "$name: $.: Gargbage found after DEFAULTS\n$_"; |
540 | } | 541 | } |
541 | 542 | ||
543 | } elsif (/^\s*INCLUDE\s+(\S+)/) { | ||
544 | |||
545 | next if ($skip); | ||
546 | |||
547 | if (!$default) { | ||
548 | die "$name: $.: INCLUDE can only be done in default sections\n$_"; | ||
549 | } | ||
550 | |||
551 | my $file = process_variables($1); | ||
552 | |||
553 | if ($file !~ m,^/,) { | ||
554 | # check the path of the config file first | ||
555 | if ($config =~ m,(.*)/,) { | ||
556 | if (-f "$1/$file") { | ||
557 | $file = "$1/$file"; | ||
558 | } | ||
559 | } | ||
560 | } | ||
561 | |||
562 | if ( ! -r $file ) { | ||
563 | die "$name: $.: Can't read file $file\n$_"; | ||
564 | } | ||
565 | |||
566 | if (__read_config($file, \$test_num)) { | ||
567 | $test_case = 1; | ||
568 | } | ||
569 | |||
542 | } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) { | 570 | } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) { |
543 | 571 | ||
544 | next if ($skip); | 572 | next if ($skip); |
@@ -594,13 +622,26 @@ sub read_config { | |||
594 | } | 622 | } |
595 | } | 623 | } |
596 | 624 | ||
597 | close(IN); | ||
598 | |||
599 | if ($test_num) { | 625 | if ($test_num) { |
600 | $test_num += $repeat - 1; | 626 | $test_num += $repeat - 1; |
601 | $opt{"NUM_TESTS"} = $test_num; | 627 | $opt{"NUM_TESTS"} = $test_num; |
602 | } | 628 | } |
603 | 629 | ||
630 | close($in); | ||
631 | |||
632 | $$current_test_num = $test_num; | ||
633 | |||
634 | return $test_case; | ||
635 | } | ||
636 | |||
637 | sub read_config { | ||
638 | my ($config) = @_; | ||
639 | |||
640 | my $test_case; | ||
641 | my $test_num = 0; | ||
642 | |||
643 | $test_case = __read_config $config, \$test_num; | ||
644 | |||
604 | # make sure we have all mandatory configs | 645 | # make sure we have all mandatory configs |
605 | get_ktest_configs; | 646 | get_ktest_configs; |
606 | 647 | ||
diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf index 4e8fb91fd517..ae2a93c732ac 100644 --- a/tools/testing/ktest/sample.conf +++ b/tools/testing/ktest/sample.conf | |||
@@ -122,8 +122,36 @@ | |||
122 | # ELSE | 122 | # ELSE |
123 | # BUILD_TYPE = useconfig:${CONFIG_DIR}/config-64 | 123 | # BUILD_TYPE = useconfig:${CONFIG_DIR}/config-64 |
124 | # | 124 | # |
125 | 125 | # | |
126 | 126 | # INCLUDE file | |
127 | # | ||
128 | # The INCLUDE keyword may be used in DEFAULT sections. This will | ||
129 | # read another config file and process that file as well. The included | ||
130 | # file can include other files, add new test cases or default | ||
131 | # statements. Config variables will be passed to these files and changes | ||
132 | # to config variables will be seen by top level config files. Including | ||
133 | # a file is processed just like the contents of the file was cut and pasted | ||
134 | # into the top level file, except, that include files that end with | ||
135 | # TEST_START sections will have that section ended at the end of | ||
136 | # the include file. That is, an included file is included followed | ||
137 | # by another DEFAULT keyword. | ||
138 | # | ||
139 | # Unlike other files referenced in this config, the file path does not need | ||
140 | # to be absolute. If the file does not start with '/', then the directory | ||
141 | # that the current config file was located in is used. If no config by the | ||
142 | # given name is found there, then the current directory is searched. | ||
143 | # | ||
144 | # INCLUDE myfile | ||
145 | # DEFAULT | ||
146 | # | ||
147 | # is the same as: | ||
148 | # | ||
149 | # INCLUDE myfile | ||
150 | # | ||
151 | # Note, if the include file does not contain a full path, the file is | ||
152 | # searched first by the location of the original include file, and then | ||
153 | # by the location that ktest.pl was executed in. | ||
154 | # | ||
127 | 155 | ||
128 | #### Config variables #### | 156 | #### Config variables #### |
129 | # | 157 | # |