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

Download this file

oprofile-run.exp    270 lines (232 with data), 6.4 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"

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_delete_any_samples {ctrs} {

    global op_var_prefix
    foreach ctr $ctrs {
	set n [lindex $ctr 0]
	foreach f [glob -nocomplain -types f "$op_var_prefix/samples/*#$n"] {
	    if {[catch "file delete $f" err]} {
		verbose "could not delete $f ($err)"
	    } else {
		verbose "deleted $f"
	    }
	}
    }

    foreach sess [glob -nocomplain -types d "$op_var_prefix/samples/session-*"] {
	    if {[catch "file delete -force $sess" err]} {
		verbose "could not delete session $sess ($err)"
	    } else {
		verbose "deleted $sess"
	    }
    }
}

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} {
	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 "opreport 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

    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
	}
    }
}

proc op_daemon_cycle {ctrs} {
    op_daemon_delete_any_samples $ctrs
    op_daemon_start $ctrs
    op_spin 5000
    op_daemon_flush
    op_daemon_check_samples_exist $ctrs
    op_daemon_stop
    op_daemon_delete_any_samples $ctrs
}

proc op_check_daemon {} {
    global op_event_table
    set cpu [op_cpu_type]
    foreach spec $op_event_table($cpu) {
	op_daemon_cycle $spec
    }
}


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

oprofile_start
op_get_version
op_check_daemon