From 0bf020f2005d6ed6a62a907ec2385fbd6a2d35c5 Mon Sep 17 00:00:00 2001 From: besawn <38794505+besawn@users.noreply.github.com> Date: Thu, 21 Apr 2022 15:47:14 -0400 Subject: [PATCH 1/4] Added additional validation to check:output --- xCAT-test/xcattest | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/xCAT-test/xcattest b/xCAT-test/xcattest index 47ebfa45f..6c2ffe27a 100755 --- a/xCAT-test/xcattest +++ b/xCAT-test/xcattest @@ -1447,6 +1447,11 @@ sub run_case { || (($op eq '==') && ($lvalue ne $rvalue)) || (($op eq '!=') && ($lvalue eq $rvalue))) { $failflag = 1; + } elsif (($op ne '=~') && ($op ne '!~') && ($op ne '==') && ($op ne '!=')) { + $failflag = 1; + log_this($running_log_fd, "CHECK:output unrecognized operator: $op\t[Failed]"); + push(@caselog, "CHECK:output unrecognized operator: $op\t[Failed]"); + last; } if ($failflag) { log_this($running_log_fd, "CHECK:output $op $rvalue\t[Failed]"); @@ -1491,7 +1496,13 @@ sub run_case { } else { log_this($running_log_fd, "CHECK:output $op $rvalue\t[Pass]"); push(@caselog, "CHECK:output $op $rvalue\t[Pass]"); - } } } + } + } else { + $failflag = 1; + log_this($running_log_fd, "Unrecognized testcase syntax: CHECK:$check\t[Failed]"); + push(@caselog, "Unrecognized testcase syntax: CHECK:$check\t[Failed]"); + } + } foreach my $cmdcheck (@{ $cases_ref->[ $case_name_index_map_ref->{$case} ]->{cmdcheck}->[$j] }) { if ($cmdcheck) { &runcmd($cmdcheck); From ee759c065deb485de7a92b2ce964566632a71e62 Mon Sep 17 00:00:00 2001 From: besawn <38794505+besawn@users.noreply.github.com> Date: Thu, 21 Apr 2022 16:02:29 -0400 Subject: [PATCH 2/4] Modified xcattest check:output to enforce stricter syntax checking --- xCAT-test/xcattest | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xCAT-test/xcattest b/xCAT-test/xcattest index 6c2ffe27a..f6b55c3c0 100755 --- a/xCAT-test/xcattest +++ b/xCAT-test/xcattest @@ -1435,8 +1435,7 @@ sub run_case { log_this($running_log_fd, "CHECK:rc $op $rvalue\t[Pass]"); push(@caselog, "CHECK:rc $op $rvalue\t[Pass]"); } - } elsif ($check =~ /output\s*([=!~]+)\s*(\S.*)/ - && $check !~ /output\s*([=!~])\1/) { + } elsif ($check =~ /output\s*(==|!=|=~|!~)\s*(\S.*)/) { my $lvalue = join("\n", @output); my $op = $1; my $rvalue = $2; From 9ddb22a979e644a89f7ea9bf4faec41bc78f5914 Mon Sep 17 00:00:00 2001 From: besawn <38794505+besawn@users.noreply.github.com> Date: Thu, 21 Apr 2022 16:04:10 -0400 Subject: [PATCH 3/4] Added new autotest testcases for xcattest --- xCAT-test/autotest/testcase/xcattest/cases0 | 77 +++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 xCAT-test/autotest/testcase/xcattest/cases0 diff --git a/xCAT-test/autotest/testcase/xcattest/cases0 b/xCAT-test/autotest/testcase/xcattest/cases0 new file mode 100644 index 000000000..202d3bcd7 --- /dev/null +++ b/xCAT-test/autotest/testcase/xcattest/cases0 @@ -0,0 +1,77 @@ +start:xcattest_checkoutput_exactmatch +description:check:output== match an exact string +label:mn_only,ci_test +cmd:echo "Test" +check:output==Test +end + +start:xcattest_checkoutput_not_exactmatch +description:check:output!= check that the output does not match an exact string +label:mn_only,ci_test +cmd:echo "Test" +check:output!=Tes +end + +start:xcattest_checkoutput_regexmatch_full +description:check:output=~ matching a full string +label:mn_only,ci_test +cmd:echo "Running test now" +check:output=~Running test now +end + +start:xcattest_checkoutput_regexmatch_start +description:checkoutput=~ matching a partial string from the start of the output +label:mn_only,ci_test +cmd:echo "Running test now" +check:output=~Running te +end + +start:xcattest_checkoutput_regexmatch_middle +description:checkoutput=~ matching a partial string in the middle of the output +label:mn_only,ci_test +cmd:echo "Running test now" +check:output=~ing test +end + +start:xcattest_checkoutput_regexmatch_end +description:checkoutput=~ matching a partial string up to the end of the output +label:mn_only,ci_test +cmd:echo "Running test now" +check:output=~ now +end + +start:xcattest_checkoutput_not_regexmatch_independent +description:check:output!~ two unrelated strings +label:mn_only,ci_test +cmd:echo "Running test now" +check:output!~uptime +end + +start:xcattest_checkoutput_not_regexmatch_superstring +description:check:output!~ where the tested string is larger than the output +label:mn_only,ci_test +cmd:echo "Running test now" +check:output!~Running test now, please wait +end + +start:xcattest_checkoutput_not_regexmatch_start +description:check:output!~ where the tested string fails near the start +label:mn_only,ci_test +cmd:echo "Running test now" +check:output!~Running tess +end + +start:xcattest_checkoutput_not_regexmatch_middle +description:check:output!~ where the tested string fails in the middle +label:mn_only,ci_test +cmd:echo "Running test now" +check:output!~ing test +end + +start:xcattest_checkoutput_not_regexmatch_end +description:check:output!~ where the tested string fails near the end +label:mn_only,ci_test +cmd:echo "Running test now" +check:output!~est now pl +end + From 42d25d85c803c692ad62e043a269edae1d966d0d Mon Sep 17 00:00:00 2001 From: besawn <38794505+besawn@users.noreply.github.com> Date: Thu, 21 Apr 2022 16:10:46 -0400 Subject: [PATCH 4/4] Fixed testcase syntax by replacing check:output= with check:output== --- xCAT-test/autotest/testcase/UT_openbmc/rspconfig_cases0 | 2 +- xCAT-test/autotest/testcase/gettab/cases0 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xCAT-test/autotest/testcase/UT_openbmc/rspconfig_cases0 b/xCAT-test/autotest/testcase/UT_openbmc/rspconfig_cases0 index 695a6d7e7..105b0a8fb 100644 --- a/xCAT-test/autotest/testcase/UT_openbmc/rspconfig_cases0 +++ b/xCAT-test/autotest/testcase/UT_openbmc/rspconfig_cases0 @@ -152,7 +152,7 @@ check:rc==0 #Remove last generated dump cmd: rspconfig $$CN dump -l | tail -1 | cut -d ' ' -f2 | tr -d "[]" | xargs -i{} rspconfig $$CN dump -c {} check:rc==0 -check:output=clear +check:output==clear end start:openbmc_rspconfig_ntpservers diff --git a/xCAT-test/autotest/testcase/gettab/cases0 b/xCAT-test/autotest/testcase/gettab/cases0 index 0acda2e02..38cb6cf61 100644 --- a/xCAT-test/autotest/testcase/gettab/cases0 +++ b/xCAT-test/autotest/testcase/gettab/cases0 @@ -27,7 +27,7 @@ cmd:gettab -H groups=master site.key check:rc!=0 cmd:gettab -H key=master site.groups check:rc==0 -check:output=site.groups: +check:output==site.groups: end