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

Download this file

166 lines (136 with data), 5.2 kB

# oprofile-run.exp
#   Copyright (C) 2012 Carl Love, IBM
#
# 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 operf_version 0

proc do_test {ctrs symbol_check} {
#   The tests are run in system-wide mode which requires the user to be
#   root.  System-wide mode is being used to make the operf interface
#   testing as functionally equivalent to the opcontrol interface testing
#   as possible.
#
#   The operf --system-wide command is started in system-wide mode in the
#   background.  Operf in system-wide mode runs until it received a kill
#   command.  The test script captures the parent process id printed by
#   operf.  After the workload has run, a script is called to kill the
#   operf data collection processes.

    global op_workload_table
    set kernel 1
    set user 1
    set ctr_opts {}

    foreach ctr $ctrs {
#       n - counter number, no longer used but didn't want to change
#       specification format
	set n [lindex $ctr 0]
	set event [lindex $ctr 1]
	set um [lindex $ctr 2]
	set count [lindex $ctr 3]
	append ctr_opts "${event}:${count}:${um}:${kernel}:${user},"
    }

    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 test "operf do test"

	set workload_exc [compile_workload $workload_src  $compile_options]

	# create the script to run operf command
	set filename "/tmp/operf_run.zzzz"
	set fileId [open $filename "w"]
	puts $fileId "#!/bin/bash"
	puts -nonewline $fileId "operf --system-wide --events "
	puts -nonewline $fileId $ctr_opts
	puts -nonewline $fileId " 2>&1  | tee > /tmp/operf_out.zzzz"
	close $fileId

	local_exec "chmod 755 /tmp/operf_run.zzzz" "" "" 10

	#  Start operf data collection in the background
	exec /tmp/operf_run.zzzz &

	# Create the script to stop the operf data collection.  Note this
	# must be done after operf starts and writes the kill command out to
	# operf_out.zzzz.
	set filename "/tmp/operf_create_stop.zzzz"
	set fileId [open $filename "w"]
	puts $fileId "#!/bin/bash"
	puts $fileId "echo -n  \"kill -s INT  \" > /tmp/operf_stop.zzzz "

	# Get the process id to kill
	puts $fileId "cat /tmp/operf_out.zzzz | grep \"kill\" | cut -d\"\'\" -f2 | cut -d\" \" -f3 >> /tmp/operf_stop.zzzz "
	close $fileId

	# check that operf started correctly
	if {[lindex [local_exec "grep \"usage\" /tmp/operf_out.zzzz " "" "" 100] 0] == 1} {
	    pass $test
	} else {
	    fail $test
	}

	# Run the script to create the operf stop script based on the
	# output of the operf command.
	local_exec "sleep 2" "" "" 10
	local_exec "chmod 755 /tmp/operf_create_stop.zzzz" "" "" 10
	exec /tmp/operf_create_stop.zzzz

	# Run the workload
	set result [local_exec "$workload_exc" "" "" 60]

	local_exec "chmod 755 /tmp/operf_stop.zzzz" "" "" 10
	exec /tmp/operf_stop.zzzz

	operf_check_samples_exist $ctrs

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

	# cleanup the files created
	local_exec "rm -f /tmp/operf_out.zzzz" "" "" 10
	local_exec "rm -f /tmp/operf_stop.zzzz" "" "" 10
	local_exec "rm -f /tmp/operf_run.zzzz" "" "" 10
	local_exec "rm -f /tmp/operf_create_stop.zzzz" "" "" 10
	operf_delete_samples
    }
}

proc oprofile-operf_run_tests {} {
    global op_event_table
    set cpu [operf_cpu_type]

    if {$cpu == "bogus"} {
	send "Error, not able find cpu type exiting.\n"

    } else {

	set symbol_check 1
	foreach spec $op_event_table($cpu) {
	    # Just do the symbol check on the first event group.  The
	    # assumption is the first event group contains cycles or count
	    # instructions which will reliably collect a lot of samples.
	    do_test $spec $symbol_check
	    set symbol_check 0
	}
    }
}


#main
check_user
if {$user_is_root == 0} {
    send "\nYou must be root to run the operf --system-wide command.\n"
    send "Will not run operf tests.\n"
} else {

    operf_get_version

    if { $operf_version == 0 } {
	send "\nThe OProfile operf user tool is not supported.  Will not run operf tests.\n"
    } else {
	# Make sure there are no samples from the opcontrol or operf laying
	# around that opreport might inadvertenly pick up.
	op_daemon_delete_any_samples
	operf_delete_samples

	oprofile-operf_run_tests
    }
}