]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
test: add valgrind support to system tests
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 28 Nov 2024 15:05:48 +0000 (16:05 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 28 Nov 2024 15:28:58 +0000 (16:28 +0100)
test/system/099-scfilter
test/system/199-scfilter
test/system/test.common

index 7be02bd342b0802e1ddc9b22910b602f53c846f8..f34863d7b81c682235bd7f00c9a454b84cdff831 100755 (executable)
@@ -4,6 +4,8 @@
 
 check_chronyd_features SCFILTER || test_skip "SCFILTER support disabled"
 
+[[ $CHRONYD_WRAPPER == *valgrind* ]] && test_skip "SCFILTER breaks valgrind"
+
 test_start "system call filter in non-destructive tests"
 
 for level in 1 2 -1 -2; do
index 40441b7c0f8eae273e67ba2114ca18ff87f0a02f..dccdac0d88f9f78f45fae5f2a5f6ea7f236f1e43 100755 (executable)
@@ -4,6 +4,8 @@
 
 check_chronyd_features SCFILTER || test_skip "SCFILTER support disabled"
 
+[[ $CHRONYD_WRAPPER == *valgrind* ]] && test_skip "SCFILTER breaks valgrind"
+
 test_start "system call filter in destructive tests"
 
 for level in 1 2 -1 -2; do
index 79e25a831dbf2c048b72088621fef4c3fa291ba0..9eb2382b21efd468b6859815d25bbac54a950d45 100644 (file)
@@ -266,7 +266,7 @@ get_chronyd_options() {
 
 # Start a chronyd instance
 start_chronyd() {
-       local pid pidfile=$(get_pidfile)
+       local pid pidfile=$(get_pidfile) wrapper_options=""
 
        print_nondefaults
        test_message 1 0 "starting chronyd"
@@ -277,7 +277,12 @@ start_chronyd() {
 
        rm -f "$TEST_LOGDIR"/*.log
 
-       $CHRONYD_WRAPPER "$chronyd" $(get_chronyd_options) > "$TEST_DIR/chronyd.out" 2>&1
+       if [[ $CHRONYD_WRAPPER == *valgrind* ]]; then
+               wrapper_options="--log-file=$TEST_DIR/chronyd.valgrind --enable-debuginfod=no"
+       fi
+
+       $CHRONYD_WRAPPER $wrapper_options \
+               "$chronyd" $(get_chronyd_options) > "$TEST_DIR/chronyd.out" 2>&1
 
        [ $? -eq 0 ] && [ -f "$pidfile" ] && ps -p "$(cat "$pidfile")" > /dev/null && test_ok || test_error
 }
@@ -324,6 +329,12 @@ stop_chronyd() {
        done
 
        test_ok
+
+       if [ -f "$TEST_DIR/chronyd.valgrind" ]; then
+               test_message 2 0 "checking valgrind report"
+               ! grep -q 'ERROR SUMMARY: [^0]' "$TEST_DIR/chronyd.valgrind" && \
+                       test_ok || test_bad
+       fi
 }
 
 # Check chronyd log for expected and unexpected messages
@@ -364,7 +375,7 @@ check_chronyd_files() {
 
 # Run a chronyc command
 run_chronyc() {
-       local host=$chronyc_host options="-n -m"
+       local host=$chronyc_host options="-n -m" wrapper_options="" ret=0
 
        test_message 1 0 "running chronyc $([ -n "$host" ] && echo "@$host ")$*"
 
@@ -374,8 +385,23 @@ run_chronyc() {
                options="$options -p $(grep cmdport "$(get_conffile)" | awk '{print $2}')"
        fi
 
-       $CHRONYC_WRAPPER "$chronyc" -h "$host" $options "$@" > "$TEST_DIR/chronyc.out" && \
-               test_ok || test_error
+       if [[ $CHRONYC_WRAPPER == *valgrind* ]]; then
+               wrapper_options="--log-file=$TEST_DIR/chronyc.valgrind --enable-debuginfod=no"
+       fi
+
+       $CHRONYC_WRAPPER $wrapper_options \
+               "$chronyc" -h "$host" $options "$@" > "$TEST_DIR/chronyc.out" && \
+                       test_ok || test_error
+       [ $? -ne 0 ] && ret=1
+
+       if [ -f "$TEST_DIR/chronyc.valgrind" ]; then
+               test_message 2 0 "checking valgrind report"
+               ! grep -q 'ERROR SUMMARY: [^0]' "$TEST_DIR/chronyc.valgrind" && \
+                       test_ok || test_bad
+               [ $? -ne 0 ] && ret=1
+       fi
+
+       return $ret
 }
 
 # Compare chronyc output with specified pattern