--- a
+++ b/testsuite/lib/operf_util.exp
@@ -0,0 +1,234 @@
+# op_util.exp
+#   Copyright (C) 2012 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.
+#
+
+# globals which might change, perhaps?
+set op_proc_prefix "/dev/oprofile"
+set op_var_prefix "/var/lib/oprofile"
+
+proc operf_get_proc_name {string} {
+    # ophelp returns the processor name as a series of space separated
+    # names.  Read string and replace spaces with underscores to match
+    # the format expected in the operf_cpu_type{} switch statement
+    set res ""
+    set len [llength $string]
+    set i 0
+
+    foreach field $string {
+	set res $res$field
+	incr i
+
+	if {$i != $len} {
+	    set res $res\_
+	}
+    }
+    return $res
+}
+
+# detect CPU type
+proc operf_cpu_type {} {
+    global op_proc_prefix
+
+    set ophelp_result [ local_exec "ophelp -r" "" "" 100 ]
+    set cpu_name [operf_get_proc_name [ lindex $ophelp_result 1 ]]
+
+# ophelp -r prints the "pretty" cpu name string.  Unfortunately, ophelp
+# does not print the name string which is a bit more consise.  The
+# following switch statement takes the "pretty" name for each processor
+# as it appears in the OPrifle libop/op_cpu_type.h in the structure
+# static struct cpu_descr const cpu_descrs[MAX_CPU_TYPE]
+# and maps it to the value used as in index in the testsuite.  For each
+# processor, there is also an enum number that corresponds to the processor.
+# The spaces in the "pretty" names have been replaced with underscores.
+# The enum names in the cpu_descrs structure map to the enum values in
+# libop/op_cpu_type.h where the valid enum values start at zero and go up.
+
+    verbose "cpu name string is $cpu_name"
+
+# Note, operf does not support the timer modes
+
+    set type bogus
+
+    switch -exact "$cpu_name" {
+	0 {set type ppro}
+	Pentium_Pro {set type ppro}
+	1 {set type ppro}
+	PII {set type ppro}
+	2 {set type ppro}
+	PIII {set type ppro}
+	3 {set type athlon}
+	Athlon {set type athlon}
+	6 {set type p4}
+	P4_/_Xeon {set type p4}
+	7 {set type ia64}
+	IA64 {set type ia64}
+	8 {set type ia64}
+	Itanium {set type ia64}
+	9 {set type ia64}
+	Itanium_2 {set type ia64}
+	10 {set type athlon}
+	AMD64_processors {set type athlon}
+	11 {set type p4}
+	P4_/_Xeon_with_2_hyper-threads {set type p4}
+	12 {set type alpha}
+	Alpha_EV4 {set type alpha}
+	13 {set type alpha}
+	Alpha_EV5 {set type alpha}
+	14 {set type alpha}
+	Alpha_PCA56 {set type alpha}
+	15 {set type alpha}
+	Alpha_EV6 {set type alpha}
+	16 {set type alpha7}
+	AlphaEV_67 {set type alpha}
+	17 {set type ppro}
+	Pentium_M_(P6_core) {set type ppro}
+	18 {set type gen_arm}
+	ARM/XScale_PMU1 {set type gen_arm}
+	19 {set type gen_arm}
+	ARM/XScale_PMU2 {set type gen_arm}
+	20 {set type power4}
+	ppc64_POWER4 {set type power4}
+	21 {set type power5}
+	ppc64_POWER5 {set type power5}
+	22 {set type power5p}
+	ppc64_POWER5+ {set type power5p}
+	23 {set type power970}
+	ppc64_970 {set type ppc970}
+	24 {set type mips}
+	MIPS_20K {set type mips}
+	25 {set type mips}
+	MIPS_24K {set type mips}
+	26 {set type mips}
+	MIPS_25K {set type mips}
+	27 {set type mips}
+	MIPS_34K {set type mips}
+	28 {set type mips}
+	MIPS_5K {set type mips}
+	29 {set type mips}
+	MIPS_R10000 {set type mips}
+	30 {set type mips}
+	MIPS_R12000 {set type mips}
+	31 {set type mips}
+	QED_RM7000 {set type mips}
+	32 {set type mips}
+	PMC-Sierra_RM9000 {set type mips}
+	33 {set type mips}
+	Sibyte_SB1 {set type mips}
+	34 {set type mips}
+	NEC_VR5432 {set type mips}
+	35 {set type mips}
+	NEC_VR5500 {set type mips}
+	36 {set type e500}
+	e500 {set type e500}
+	37 {set type e500}
+	e500v2 {set type e500}
+	38 {set type ppro}
+	Core_Solo_/_Duo {set type ppro}
+	39 {set type ppc7450}
+	PowerPC_G4 {set type ppc7450}
+	40 {set type core2}
+	Core_2 {set type core2}
+	41 {set type power6}
+	ppc64_POWER6 {set type power6}
+	42 {set type power970}
+	ppc64_970MP {set type power970}
+	43 {set type cell_be}
+	ppc64_Cell_Broadband_Engine {set type cell_be}
+	44 {set type athlon}
+	AMD64_family10 {set type athlon}
+	45 {set type pa6t}
+	ppc64_PA6T {set type pa6t}
+	46 {set type gen_arm}
+	ARM_11MPcore {set type gen_arm}
+	47 {set type gen_arm}
+	ARM_V6_PMU {set type gen_arm}
+	48 {set type power5pp}
+	ppc64_POWER5++ {set type power5pp}
+	49 {set type e500}
+	e300 {set type e500}
+	50 {set type avr32}
+	AVR32 {set type avr32}
+	51 {set type arm7}
+	ARM_Cortex-A8 {set type arm7}
+	52 {set type arch_perf}
+	Intel_Architectural_Perfmon {set type arch_perf}
+	53  {set type athlon}
+	AMD64_family11h {set type athlon}
+	54 {set type power7}
+	ppc64_POWER7 {set type power7}
+	55 {set type ibm_compat_v1}
+	ppc64_compat_version_1 {set type ibm_compat_v1}
+	56 {set type arch_perf}
+	Intel_Core/i7 {set type arch_perf}
+	57 {set type arch_perf}
+	Intel_Atom {set type arch_perf}
+	58 {set type mips}
+	Loongson2 {set type mips}
+	59 {set type arch_perf}
+	Intel_Nehalem_microarchitecture {set type arch_perf}
+	60 {set type arm7}
+	ARM_Cortex-A9 {set type arm7}
+	61 {set type mips}
+	MIPS_74K {set type mips}
+	62 {set type mips}
+	MIPS_1004K {set type mips}
+	63 {set type athlon}
+	AMD64_family12h {set type athlon}
+	64 {set type athlon}
+	AMD64_family14h {set type athlon}
+	65 {set type athlon}
+	AMD64_family15h {set type athlon}
+	66 {set type arch_perf}
+	Intel_Westmere_microarchitecture  {set type arch_perf}
+	67 {set type arm7}
+	ARMv7_Scorpion {set type arm7}
+	68 {set type arm7}
+	ARMv7_ScorpionMP {set type arm7}
+	69 {set type arch_perf}
+	Intel_Sandy_Bridge_microarchitecture {set type sandybridge}
+	70 {set type title64}
+	TILE64 {set type title64}
+	71 {set type titlepro}
+	TILEPro {set type titlepro}
+	72 {set type titlegx}
+	TILE-GX {set type titlegx}
+	73 {set type z10}
+	IBM_System_z10 {set type z10}
+	74 {set type z196}
+	IBM_zEnterprize_z196 {set type z196}
+	75 {set type ivybridge}
+	Intel_Ivy_Bridge_microarchitecture {set type ivybridge}
+	76 {set type arm_cortex}
+	ARM_Cortex-A5 {set type arm_cortex}
+	77 {set type arm_cortex}
+	ARM_Cortex-A7 {set type arm_cortex}
+	78 {set type arm_cortex}
+	ARM_Cortex-A15 {set type arm_cortex}
+    }
+
+    verbose "cpu type is $type"
+    return $type
+}
+
+proc operf_delete_samples {} {
+    set result [local_exec "rm -rf ./oprofile_data" "" "" 100 ]
+    if { [lindex $result 0] == 0 } {
+	verbose "Successfully deleted exiting data directory"
+    } else {
+	verbose "Failed to delete exiting data directory"
+    }
+}