Compare commits

..
Author SHA1 Message Date
chainsx a2250c56a4 fix(security): correct openscap cis eval and fix test execution 2026-09-17 05:33:35 +08:00
11 changed files with 54 additions and 63 deletions
+7 -24
View File
@@ -152,29 +152,6 @@ _stressNgTaintCheck() {
# Extract bogo ops/s (real time) for a stressor from a stress-ng metrics log
_stressNgBogoOps() {
local log="$1"
local stressor="${2:-}"
awk -v stressor="$stressor" '
/^stress-ng:[[:space:]]*metrc:/ {
row = $0
sub(/^stress-ng:[[:space:]]*metrc:[[:space:]]*\[[0-9]+\][[:space:]]*/, "", row)
n = split(row, f, /[[:space:]]+/)
if (n >= 7 && f[2] ~ /^[0-9]+$/ && f[6] ~ /^[0-9]+([.][0-9]+)?$/) {
if (stressor != "" && f[1] == stressor && !found) {
print f[6]
found = 1
}
if (first == "") first = f[6]
}
}
END { if (!found && first != "") print first }
' "$log"
}
# Validate stress-ng result from log file
# Checks: successful run completed, failed=0, bogo ops > 0
@@ -225,7 +202,13 @@ _stressNgValidate() {
local bogo
bogo=$(_stressNgBogoOps "$log" "$stressor")
bogo=$(grep -oP "$stressor\s+.*?\s+(\d+\.?\d*)\s+\(\s*real\s+time\s*\)" "$log" | grep -oP '\d+\.?\d*(?=\s*\(\s*real)' | head -1)
if [ -z "$bogo" ]; then
bogo=$(grep "$stressor" "$log" | grep -oP '\d+\.?\d+(?=\s*\(\s*real)' | head -1)
fi
if [ -n "$bogo" ] && [ "$(echo "$bogo > 0" | bc 2>/dev/null || echo 1)" -eq 1 ]; then
@@ -28,7 +28,7 @@ rlJournalStart
rlPhaseStartTest "combined stress: CPU+MEM+PROC"
log="$TmpDir/combo1.log"
local log="$TmpDir/combo1.log"
# simultaneously CPU(2thread) + VM(128M) + FORK(2thread)
@@ -58,11 +58,11 @@ rlJournalStart
# useDocumentation recommends 13 workload (time)
log="$TmpDir/combo2.log"
local log="$TmpDir/combo2.log"
workloads="cpu context fork get mmap vm-splice wait zombie"
local workloads="cpu context fork get mmap vm-splice wait zombie"
args=""
local args=""
for w in $workloads; do args="$args --$w 1"; done
@@ -76,6 +76,7 @@ rlJournalStart
# count passed count
local passed
passed=$(grep -oP 'passed:\s*\K\d+' "$log" | awk '{s+=$1} END {print s}')
@@ -91,6 +92,7 @@ rlJournalStart
# confirmnofailed
local failed
failed=$(grep -oP 'failed:\s*\K\d+' "$log" | awk '{s+=$1} END {print s}')
@@ -110,7 +112,7 @@ rlJournalStart
rlPhaseStartTest "metrics analysis"
log="$TmpDir/combo1.log"
local log="$TmpDir/combo1.log"
# analysis usr/sys time
@@ -120,6 +122,7 @@ rlJournalStart
# usr time shouldtotaltime
local total_usr total_sys
total_usr=$(grep -oP 'usr time\s+\K[\d.]+' "$log" | head -1)
@@ -28,11 +28,11 @@ rlJournalStart
rlPhaseStartTest "CPU stress rampthread"
bogo_vals=()
local bogo_vals=()
for t in 1 2 4; do
log="$TmpDir/cpu_${t}.log"
local log="$TmpDir/cpu_${t}.log"
rlRun "stress-ng --cpu $t --timeout 30s --metrics-brief --log-file $log 2>&1 | tail -5" 0 "CPU $t thread"
@@ -42,8 +42,9 @@ rlJournalStart
# extract bogo ops/s
local bogo
bogo=$(_stressNgBogoOps "$log" "cpu")
bogo=$(grep "cpu" "$log" | grep -oP '\d+\.?\d*(?=\s*\(\s*real)' | head -1)
bogo_vals+=("$bogo")
@@ -82,3 +83,4 @@ rlJournalStart
rlJournalPrintText
rlJournalEnd
@@ -28,7 +28,7 @@ rlJournalStart
rlPhaseStartTest "HDD stress (IO)"
log="$TmpDir/hdd.log"
local log="$TmpDir/hdd.log"
rlRun "stress-ng --hdd 2 --hdd-bytes 32M --temp-path $TmpDir/io_test --timeout 30s --metrics-brief --log-file $log 2>&1 | tail -5" 0 "--hdd 2"
@@ -42,7 +42,7 @@ rlJournalStart
# aio needs libaio supports, possiblesystemnot supported
log="$TmpDir/aio.log"
local log="$TmpDir/aio.log"
stress-ng --aio 2 --timeout 20s --metrics-brief --log-file "$log" 2>&1 | tail -5
@@ -64,7 +64,7 @@ rlJournalStart
rlPhaseStartTest "GETDENT stress (directory)"
log="$TmpDir/getdent.log"
local log="$TmpDir/getdent.log"
rlRun "stress-ng --getdent 2 --timeout 20s --metrics-brief --log-file $log 2>&1 | tail -5" 0 "--getdent 2"
@@ -26,7 +26,7 @@ rlJournalStart
rlPhaseStartTest "MATRIX stress ()"
log="$TmpDir/matrix.log"
local log="$TmpDir/matrix.log"
rlRun "stress-ng --matrix 2 --timeout 30s --metrics-brief --log-file $log 2>&1 | tail -5" 0 "--matrix 2"
@@ -36,6 +36,7 @@ rlJournalStart
if grep -q "matrix" "$log"; then
local usr sys
usr=$(grep "matrix" "$log" | awk '{for(i=1;i<=NF;i++){if($i~/^[0-9.]+$/&&$(i-1)~/secs/)print $i}}' | head -1)
@@ -49,7 +50,7 @@ rlJournalStart
rlPhaseStartTest "AF-ALG stress (kernelcrypto)"
log="$TmpDir/af_alg.log"
local log="$TmpDir/af_alg.log"
stress-ng --af-alg 2 --timeout 20s --metrics-brief --log-file "$log" 2>&1 | tail -5
@@ -71,7 +72,7 @@ rlJournalStart
rlPhaseStartTest "VM-SPLICE stress (pipe splice)"
log="$TmpDir/vm_splice.log"
local log="$TmpDir/vm_splice.log"
stress-ng --vm-splice 2 --timeout 20s --metrics-brief --log-file "$log" 2>&1 | tail -5
@@ -95,7 +96,7 @@ rlJournalStart
#: itemswillExceptionsignalhandlepath, possiblehaspreerror
log="$TmpDir/bad_altstack.log"
local log="$TmpDir/bad_altstack.log"
rlRun "stress-ng --bad-altstack 1 --timeout 10s --metrics-brief --log-file $log 2>&1 | tail -5" 0 "--bad-altstack 1"
@@ -26,7 +26,7 @@ rlJournalStart
rlPhaseStartTest "VM stress (memory)"
log="$TmpDir/vm.log"
local log="$TmpDir/vm.log"
rlRun "stress-ng --vm 2 --vm-bytes 128M --timeout 30s --metrics-brief --log-file $log 2>&1 | tail -5" 0 "--vm 2x128M"
@@ -38,7 +38,7 @@ rlJournalStart
rlPhaseStartTest "MMAP stress"
log="$TmpDir/mmap.log"
local log="$TmpDir/mmap.log"
rlRun "stress-ng --mmap 2 --timeout 30s --metrics-brief --log-file $log 2>&1 | tail -5" 0 "--mmap 2"
@@ -50,7 +50,7 @@ rlJournalStart
rlPhaseStartTest "MADVISE stress"
log="$TmpDir/madvise.log"
local log="$TmpDir/madvise.log"
rlRun "stress-ng --madvise 2 --timeout 30s --metrics-brief --log-file $log 2>&1 | tail -5" 0 "--madvise 2"
@@ -62,7 +62,7 @@ rlJournalStart
rlPhaseStartTest "Memory combined stress"
log="$TmpDir/mem_combo.log"
local log="$TmpDir/mem_combo.log"
# simultaneously VM + MMAP
@@ -26,7 +26,7 @@ rlJournalStart
rlPhaseStartTest "FORK stress"
log="$TmpDir/fork.log"
local log="$TmpDir/fork.log"
rlRun "stress-ng --fork 4 --timeout 30s --metrics-brief --log-file $log 2>&1 | tail -5" 0 "--fork 4"
@@ -42,7 +42,7 @@ rlJournalStart
rlPhaseStartTest "CONTEXT switch stress"
log="$TmpDir/context.log"
local log="$TmpDir/context.log"
rlRun "stress-ng --context 4 --timeout 30s --metrics-brief --log-file $log 2>&1 | tail -5" 0 "--context 4"
@@ -56,7 +56,7 @@ rlJournalStart
# zombie willproducedprocesspost, possiblehaspreerror
log="$TmpDir/zombie.log"
local log="$TmpDir/zombie.log"
rlRun "stress-ng --zombie 2 --timeout 15s --metrics-brief --log-file $log 2>&1 | tail -5" 0 "--zombie 2"
@@ -68,7 +68,7 @@ rlJournalStart
rlPhaseStartTest "WAIT stress (get/gettid)"
log="$TmpDir/wait.log"
local log="$TmpDir/wait.log"
# --get: callwith getpid/getppid
@@ -1,10 +1,11 @@
summary: Security test - OpenSCAP CIS - andreport
framework: beakerlib
test: ./test.sh
tag:
- security
- openscap
- cis
duration: 10m
duration: 30m
tier: 2
path: /tests/security/openscap/cis/test_openscap_cis_eval_report
require:
@@ -16,21 +16,21 @@ rlJournalStart
if [ ! -f "$CIS_DS" ]; then
rlFail "Data stream not found"
else
local out=/tmp/cis_eval_$$
local xml=/tmp/cis_result_$$.xml
local html=/tmp/cis_report_$$.html
out=/tmp/cis_eval_$$
xml=/tmp/cis_result_$$.xml
html=/tmp/cis_report_$$.html
oscap xccdf eval --profile "$CIS_PROFILE" --results-arf "$xml" --report "$html" "$CIS_DS" 2>&1 | tee $out
local rc=${PIPESTATUS[0]}
if [ $rc -ne 0 ]; then
rc=${PIPESTATUS[0]}
if [ $rc -ne 0 ] && [ $rc -ne 2 ]; then
rlFail "oscap eval failed (exit=$rc)"
elif [ ! -f "$xml" ]; then
rlFail "ARF result file not generated"
elif [ ! -f "$html" ]; then
rlFail "HTML report not generated"
else
local pass=$(grep -c '<result>pass</result>' "$xml" 2>/dev/null || echo 0)
local fail=$(grep -c '<result>fail</result>' "$xml" 2>/dev/null || echo 0)
local na=$(grep -c '<result>notapplicable</result>' "$xml" 2>/dev/null || echo 0)
pass=$(grep -c '<result>pass</result>' "$xml" 2>/dev/null || echo 0)
fail=$(grep -c '<result>fail</result>' "$xml" 2>/dev/null || echo 0)
na=$(grep -c '<result>notapplicable</result>' "$xml" 2>/dev/null || echo 0)
rlPass "CIS eval complete: pass=$pass fail=$fail notapplicable=$na"
fi
rm -f $out $xml $html
@@ -1,10 +1,11 @@
summary: Security test - OpenSCAP CIS - scriptGenerate
framework: beakerlib
test: ./test.sh
tag:
- security
- openscap
- cis
duration: 10m
duration: 30m
tier: 2
path: /tests/security/openscap/cis/test_openscap_cis_fix
require:
@@ -16,15 +16,15 @@ rlJournalStart
if [ ! -f "$CIS_DS" ]; then
rlFail "Data stream not found"
else
local out=/tmp/cis_fix_$$
local xml=/tmp/cis_fix_xml_$$.xml
local fix=/tmp/cis_fix_$$.sh
out=/tmp/cis_fix_$$
xml=/tmp/cis_fix_xml_$$.xml
fix=/tmp/cis_fix_$$.sh
oscap xccdf eval --profile "$CIS_PROFILE" --results "$xml" "$CIS_DS" 2>&1 | tee $out
local rc=${PIPESTATUS[0]}
if [ $rc -ne 0 ] || [ ! -f "$xml" ]; then
rc=${PIPESTATUS[0]}
if { [ $rc -ne 0 ] && [ $rc -ne 2 ]; } || [ ! -f "$xml" ]; then
rlFail "oscap eval failed (exit=$rc)"
else
local rid=$(grep -oP 'id="\K[^"]+' "$xml" | head -1)
rid=$(grep -oP '<TestResult[^>]*\bid="\K[^"]+' "$xml" | head -1)
if [ -z "$rid" ]; then
rlFail "Cannot extract TestResult id"
else