Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[f8a53f]: testsuite / oprofile-opcontrol / oprofile-opcontrol-run.exp Maximize Restore History

Download this file

oprofile-opcontrol-run.exp    305 lines (259 with data), 7.7 kB

# oprofile-run.exp
#   Copyright (C) 2006 Red Hat, Inc.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#


load_lib "op_events.exp"
load_lib "op_util.exp"
load_lib "op_workloads.exp"
load_lib "verify.exp"

set op_daemon_running 0

set op_version ""

proc op_daemon_flush {} {

    global op_daemon_running

    set test "opcontrol --dump"

    if {$op_daemon_running == 0} {
	unsupported $test
	return
    }
    verbose "running opcontrol --dump"
    if {[lindex [local_exec "opcontrol --dump" "" "" 100] 0] == 0} {
	pass $test
    } else {
	fail $test
    }
}

proc op_daemon_check_samples_exist {ctrs} {

    global op_var_prefix op_daemon_running
    global op_version

    set test "nonzero-sized sample file creation"

    if {$op_daemon_running == 0} {
	print "op_daemon_check_samples_exist, op_daemon not running as expected"
	unsupported $test
	return
    }

    verbose "checking for nonzero sample files"

    foreach ctr $ctrs {
	set n [lindex $ctr 0]
	set event [lindex $ctr 1]
	case $op_version {
	    { 0.5* } {
		set files [glob -nocomplain -types f "$op_var_prefix/samples/*#$n"]
		if {[llength $files] == 0} {
		    unresolved "$test: {$ctr} created no files"
		} else {
		    set sz 0
		    verbose "looking at [llength $files] sample files for ctr $n"
		    foreach f $files {
			set nsz [file size $f]
			if {$nsz > $sz} {
			    set sz $nsz
			}
		    }
		    if {$sz == 0} {
			unresolved "$test: {$ctr} created only zero-length files"
		    } else {
			pass "$test: {$ctr} created nonzero sample files"
		    }
		}
	    }
	    { 0.6* 0.7* 0.8* 0.9* } {
		verbose "running opreport --long-filenames event:$event"
		set result [local_exec "opreport --long-filenames event:$event" "" "" 100 ]
		if { [regexp "error:" "$result" ]} {
		    fail "$test: {$event} created nonzero sample files"
		} else {
		    pass "$test: {$event} created nonzero sample files"
		}
	    }
	    { * } {
		fail "Do not know how to handle version {$op_version}"
	    }
	}
    }
}


proc op_daemon_start {ctrs} {
    global op_module_active
    global op_daemon_running
    global op_vmlinux
    global op_version

    # make sure the daemonrc file is deleted to clear any unwanted settings
    local_exec "rm -f /root/.oprofile/daemonrc" "" "" 100

    if {$op_module_active == 0} {
	unsupported "daemon start"
	return
    }

    set ctr_opts {}
    foreach ctr $ctrs {
	set n [lindex $ctr 0]
	set event [lindex $ctr 1]
	set um [lindex $ctr 2]
	set count [lindex $ctr 3]
	case $op_version {
	    { 0.5* } {
		append ctr_opts " --ctr${n}-event=${event}"
		append ctr_opts " --ctr${n}-count=${count}"
		append ctr_opts " --ctr${n}-unit-mask=${um}"
	    }
	    { 0.6* 0.7* 0.8* 0.9* } {
		append ctr_opts " --event=${event}:${count}:${um}"
	    }
	    { * } {
		fail "Do not know how to handle version {$op_version}"
	    }
	}
    }

    verbose "running opcontrol --reset"
    local_exec "opcontrol --reset" "" "" 100

    # this will activate the daemon too. opcontrol is so silly.

    if {$op_vmlinux == 0} {
	set kernel_control "--no-vmlinux"
    } else {
	set kernel_control "--vmlinux=${op_vmlinux}"
    }
    set cmd "opcontrol --setup ${kernel_control} ${ctr_opts}"
    set test $cmd
    verbose "running '$cmd'"
    set result [local_exec $cmd "" "" 100]
    if {[lindex $result 0] == 0} {
	pass $test
    } else {
	fail $test
    }

    # this starts daemon, but doesn't start profiling

    set cmd "opcontrol --start-daemon"
    verbose "running '$cmd'"
    set result [local_exec $cmd "" "" 100]
    if {[lindex $result 0] == 0} {
	if {[regexp oprofiled [exec /bin/ps ax]] == 1} {
	    verbose "daemon is now running"
	    set op_daemon_running 1
	    pass $test
	} else {
	    verbose "daemon did not start as requested"
	    set op_daemon_running 0
	    fail $test
	}
    } else {
	verbose "opcontrol --init failed. are you root?"
	set op_daemon_running 0
	fail $test
    }

    # this activates profiling

    set test "opcontrol --start"
    if {$op_daemon_running == 0} {
	unsupported $test
    } else {
	verbose "running 'opcontrol --start'"
	if {[lindex [local_exec "opcontrol --start" "" "" 100] 0] == 0} {
	    pass $test
	} else {
	    fail $test
	}
    }
}

proc op_daemon_stop {} {
    global op_daemon_running

    set test "opcontrol --shutdown"
    if {$op_daemon_running == 0} {
	unsupported $test
    } else {
	verbose "running 'opcontrol --shutdown'"
	if {[lindex [local_exec "opcontrol --shutdown" "" "" 100] 0] == 0} {
	    pass $test
	    set op_daemon_running 0
	} else {
	    fail $test
	}
    }

    # delete the daemonrc file to remove any settings from the testsuite
    local_exec "rm -f /root/.oprofile/daemonrc" "" "" 100
}

proc op_daemon_cycle {ctrs symbol_check} {
    global op_workload_table

    set ctr_opts {}
    foreach ctr $ctrs {
	set n [lindex $ctr 0]
	set event [lindex $ctr 1]
	set um [lindex $ctr 2]
	set count [lindex $ctr 3]
	append ctr_opts "{$n $event $um $count} "
    }

    foreach entry [array name op_workload_table] {

	set workload_src [lindex $op_workload_table($entry) 0]
	set compile_options [lindex $op_workload_table($entry) 1]
	set workload_exc [compile_workload $workload_src  $compile_options]

	op_daemon_start $ctrs

        # run the workload
	local_exec ${workload_exc} "" "" 100

	op_daemon_flush
	op_daemon_check_samples_exist $ctrs
	op_daemon_stop

	# Verify the interesting symbols for this test are found in
	# the output.  Only checking the symbols for the first group of
	# events.
	if {$symbol_check == 1} {
	    local_exec "sleep 2" "" "" 10
	    verify_output $op_workload_table($entry) $workload_exc $ctr_opts
	}

	op_daemon_delete_any_samples
    }
}

proc op_check_daemon {} {
    global op_event_table
    set cpu [op_cpu_type]
    set symbol_check 1

    foreach spec $op_event_table($cpu) {
	op_daemon_cycle $spec $symbol_check
	set symbol_check 0
    }
}

proc op_get_version {} {
    global op_version
    # this assumes that things work well enough for op_help
    # the modules has to be already installed via opcontrol
    set test "version check"
    verbose $test
    set result [ local_exec "opcontrol -v" "" "" 100 ]

    if {[regexp "\[0-9\]+\(.\[0-9\]+\)+\[a-zA-Z_\]*" $result op_version] == 1} {
	verbose "version is $op_version"
	pass $test
    } else {
	verbose "unable to determine version"
	set op_version 0
	fail $test
    }
}

# main
check_user
if {$user_is_root == 0} {
    send "\nYou must be root to run the OProfile opcontrol interface.\n"
    send "Will not run opcontrol tests.\n"
} else {
    op_get_version

    if {$op_version == 0} {
	send "\nUnable to find the opcontrol command.  Check to make sure \n"
	send "OProfile is properly installed and the opcontrol command is \n"
	send "in the root's path.  Will not run opcontrol tests.\n"
    } else {
	# Just to be paranoid and make sure there is no operf or opcontrol
	# data that opreport might pickup by mistake, delete any existing
	# data.
	operf_delete_samples
	op_daemon_delete_any_samples

	oprofile_start
	op_check_daemon
    }
}