source module.sh
 source special-tests.sh
 
+DIR="$(dirname $(readlink -f "$0"))"
+source "${DIR}"/../kselftest/ktap_helpers.sh
+
 FUNC=basic     # do basic tests by default
 OUTFILE=cpufreq_selftest
 SYSFS=
 CPUROOT=
 CPUFREQROOT=
 
-# Kselftest framework requirement - SKIP code is 4.
-ksft_skip=4
-
 helpme()
 {
        printf "Usage: $0 [-h] [-todg args]
        [-d <driver's module name: only with \"-t modtest>\"]
        [-g <governor's module name: only with \"-t modtest>\"]
        \n"
-       exit 2
+       exit "${KSFT_FAIL}"
 }
 
 prerequisite()
        msg="skip all tests:"
 
        if [ $UID != 0 ]; then
-               echo $msg must be run as root >&2
-               exit $ksft_skip
+               ktap_skip_all "$msg must be run as root"
+               exit "${KSFT_SKIP}"
        fi
 
        taskset -p 01 $$
        SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
 
        if [ ! -d "$SYSFS" ]; then
-               echo $msg sysfs is not mounted >&2
-               exit 2
+               ktap_skip_all "$msg sysfs is not mounted"
+               exit "${KSFT_SKIP}"
        fi
 
        CPUROOT=$SYSFS/devices/system/cpu
        CPUFREQROOT="$CPUROOT/cpufreq"
 
        if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then
-               echo $msg cpus not available in sysfs >&2
-               exit 2
+               ktap_skip_all "$msg cpus not available in sysfs"
+               exit "${KSFT_SKIP}"
        fi
 
        if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then
-               echo $msg cpufreq directory not available in sysfs >&2
-               exit 2
+               ktap_skip_all "$msg cpufreq directory not available in sysfs"
+               exit "${KSFT_SKIP}"
        fi
 }
 
        count=$(count_cpufreq_managed_cpus)
 
        if [ $count = 0 -a $FUNC != "modtest" ]; then
-               echo "No cpu is managed by cpufreq core, exiting"
-               exit 2;
+               ktap_exit_fail_msg "No cpu is managed by cpufreq core, exiting"
        fi
 
        case "$FUNC" in
                "modtest")
                # Do we have modules in place?
                if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then
-                       echo "No driver or governor module passed with -d or -g"
-                       exit 2;
+                       ktap_exit_fail_msg "No driver or governor module passed with -d or -g"
                fi
 
                if [ $DRIVER_MOD ]; then
                        fi
                else
                        if [ $count = 0 ]; then
-                               echo "No cpu is managed by cpufreq core, exiting"
-                               exit 2;
+                               ktap_exit_fail_msg "No cpu is managed by cpufreq core, exiting"
                        fi
 
                        module_governor_test $GOVERNOR_MOD
                ;;
 
                *)
-               echo "Invalid [-f] function type"
+               ktap_print_msg "Invalid [-f] function type"
                helpme
                ;;
        esac
        dmesg >> $1.dmesg_full.txt
 }
 
+ktap_print_header
+
 # Parse arguments
 parse_arguments $@
 
+ktap_set_plan 1
+
 # Make sure all requirements are met
 prerequisite
 
 # Run requested functions
 clear_dumps $OUTFILE
 do_test | tee -a $OUTFILE.txt
+if [ "${PIPESTATUS[0]}" -ne 0 ]; then
+    exit ${PIPESTATUS[0]};
+fi
 dmesg_dumps $OUTFILE
+
+ktap_test_pass "Completed successfully"
+
+ktap_print_totals
+exit "${KSFT_PASS}"