Skip to content

Commit 9900b5d

Browse files
Steven Rostedtrostedt
authored andcommitted
ktest: Add DEFINED keyword for IF statements
Have IF statements process if a config variable or option has been defined or not. Can use NOT DEFINED in the case for telling if a variable or option has not been defined. DEFAULTS IF NOT DEFINED SSH_USER SSH_USER = root Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 3d1cc41 commit 9900b5d

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎tools/testing/ktest/ktest.pl‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,13 @@ sub process_compare {
396396
return $ret;
397397
}
398398

399+
sub value_defined {
400+
my ($val) = @_;
401+
402+
return defined($variable{$2}) ||
403+
defined($opt{$2});
404+
}
405+
399406
sub process_if {
400407
my ($name, $value) = @_;
401408

@@ -409,13 +416,21 @@ sub process_if {
409416
return $ret;
410417
}
411418

419+
if ($val =~ /^\s*(NOT\s*)?DEFINED\s+(\S+)\s*$/) {
420+
if (defined $1) {
421+
return !value_defined($2);
422+
} else {
423+
return value_defined($2);
424+
}
425+
}
426+
412427
if ($val =~ /^\s*0\s*$/) {
413428
return 0;
414429
} elsif ($val =~ /^\s*\d+\s*$/) {
415430
return 1;
416431
}
417432

418-
die ("$name: $.: Undefined variable $val in if statement\n");
433+
die ("$name: $.: Undefined content $val in if statement\n");
419434
return 1;
420435
}
421436

‎tools/testing/ktest/sample.conf‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,23 @@
137137
# ELSE
138138
# BUILD_TYPE = useconfig:${CONFIG_DIR}/config-64
139139
#
140+
# The DEFINED keyword can be used by the IF statements too.
141+
# It returns true if the given config variable or option has been defined
142+
# or false otherwise.
143+
#
144+
#
145+
# DEFAULTS IF DEFINED USE_CC
146+
# CC := ${USE_CC}
147+
# ELSE
148+
# CC := gcc
149+
#
150+
#
151+
# As well as NOT DEFINED.
152+
#
153+
# DEFAULTS IF NOT DEFINED MAKE_CMD
154+
# MAKE_CMD := make ARCH=x86
155+
#
156+
#
140157
#
141158
# INCLUDE file
142159
#

0 commit comments

Comments
 (0)