[svn:parrot] r47720 - in branches/gsoc_instrument: src/dynpmc t/dynpmc
khairul at svn.parrot.org
khairul at svn.parrot.org
Sun Jun 20 08:47:55 UTC 2010
Author: khairul
Date: Sun Jun 20 08:47:54 2010
New Revision: 47720
URL: https://trac.parrot.org/parrot/changeset/47720
Log:
added tests for instrumentop.
Added:
branches/gsoc_instrument/t/dynpmc/instrumentop.t
Modified:
branches/gsoc_instrument/src/dynpmc/instrument.pmc
branches/gsoc_instrument/t/dynpmc/instrument.t
Modified: branches/gsoc_instrument/src/dynpmc/instrument.pmc
==============================================================================
--- branches/gsoc_instrument/src/dynpmc/instrument.pmc Sun Jun 20 01:16:38 2010 (r47719)
+++ branches/gsoc_instrument/src/dynpmc/instrument.pmc Sun Jun 20 08:47:54 2010 (r47720)
@@ -60,6 +60,7 @@
probe_list_t **op_hooks;
probe_list_t *op_catchall;
PMC *old_dynlibs;
+ PMC *instr_op;
} Instrument_runcore_t;
/* Runcore Function Prototypes */
@@ -185,6 +186,7 @@
Parrot_gc_mark_PMC_alive_fun(INTERP, attr->probes);
Parrot_gc_mark_PMC_alive_fun(INTERP, attr->evt_dispatcher);
Parrot_gc_mark_PMC_alive_fun(INTERP, core->old_dynlibs);
+ Parrot_gc_mark_PMC_alive_fun(INTERP, core->instr_op);
}
/*
@@ -596,7 +598,15 @@
Instrument_runcore_init(PARROT_INTERP, Parrot_Interp supervisor, PMC *instrument) {
Instrument_runcore_t * const coredata =
mem_gc_allocate_zeroed_typed(interp, Instrument_runcore_t);
- PMC *dynlibs = VTABLE_get_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_DYN_LIBS);
+ PMC *dynlibs, *interp_pmc;
+ INTVAL instr_op_type;
+
+ /* Get the pmc type of InstrumentOp. */
+ interp_pmc = VTABLE_get_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_INTERPRETER);
+ instr_op_type = Parrot_pmc_get_type_str(supervisor, CONST_STRING(supervisor, "InstrumentOp"));
+
+ /* Grab the dynlib hash. */
+ dynlibs = VTABLE_get_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_DYN_LIBS);
/* Ensure the current loaded runcore is the slow core */
Parrot_set_run_core(interp, PARROT_SLOW_CORE);
@@ -618,6 +628,7 @@
coredata->op_catchall = NULL;
coredata->old_dynlibs = VTABLE_clone(supervisor, dynlibs);
coredata->has_ended = 0;
+ coredata->instr_op = Parrot_pmc_new_init(supervisor, instr_op_type, interp_pmc);
PARROT_RUNCORE_FUNC_TABLE_SET((Parrot_runcore_t *)coredata);
@@ -663,9 +674,8 @@
probe_node_t *cur_probe;
Instrument_runcore_t *core;
Parrot_Interp supervisor;
- PMC *instrument, *op_data, *interp_pmc;
- INTVAL op_params, cur_op_param, pc_relative, done_catchalls;
- INTVAL instr_op_type;
+ PMC *instrument, *op_data;
+ INTVAL done_catchalls;
core = (Instrument_runcore_t *) interp->run_core;
to_recall = NULL; /* TODO: Implement probe recalls */
@@ -674,14 +684,8 @@
supervisor = core->supervisor_interp;
instrument = core->supervisor_pmc;
- /* Calculate the relative position of the pc. */
- pc_relative = pc - interp->code->base.data;
-
- /* Create the InstrumentOp instance and set it. */
- interp_pmc = VTABLE_get_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_INTERPRETER);
- instr_op_type = Parrot_pmc_get_type_str(supervisor, CONST_STRING(supervisor, "InstrumentOp"));
- op_data = Parrot_pmc_new_init(supervisor, instr_op_type, interp_pmc);
-
+ /* Update the pc of the InstrumentOp object. */
+ op_data = core->instr_op;
VTABLE_set_pointer(supervisor, op_data, pc);
/* Execute any probes. */
Modified: branches/gsoc_instrument/t/dynpmc/instrument.t
==============================================================================
--- branches/gsoc_instrument/t/dynpmc/instrument.t Sun Jun 20 01:16:38 2010 (r47719)
+++ branches/gsoc_instrument/t/dynpmc/instrument.t Sun Jun 20 08:47:54 2010 (r47720)
@@ -35,7 +35,7 @@
.sub 'test_loadlib'
.local pmc lib
- lib = loadlib 'instrument'
+ lib = loadlib 'instrument_group'
$I0 = defined lib
ok($I0, 'Instrument dynpmc loaded')
Added: branches/gsoc_instrument/t/dynpmc/instrumentop.t
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/gsoc_instrument/t/dynpmc/instrumentop.t Sun Jun 20 08:47:54 2010 (r47720)
@@ -0,0 +1,134 @@
+#!./parrot
+# Copyright (C) 2010, Parrot Foundation.
+# $Id: instrument.t 47641 2010-06-15 16:38:51Z khairul $
+
+=head1 NAME
+
+t/dynpmc/instrumentop.t - test the InstrumentOp dynpmc
+
+=head1 SYNOPSIS
+
+ % prove t/dynpmc/instrumentop.t
+
+=head1 DESCRIPTION
+
+Tests the op information interface provided by the InstrumentOp.pmc.
+
+=cut
+
+.include 'call_bits.pasm'
+.loadlib 'os'
+
+.sub main :main
+ .include 'test_more.pir'
+
+ # Load the Instrument library.
+ load_bytecode 'Instrument/InstrumentLib.pbc'
+
+ plan(10)
+
+ setup()
+ test_one_op()
+ cleanup()
+
+ .return()
+.end
+
+
+.sub setup
+ # Create a simple 1 op program.
+ .local string program
+ program = <<'PROG'
+.namespace ['TestNS']
+.sub main :main
+ say 'In test program'
+.end
+PROG
+
+ # Write to file.
+ .local pmc fh
+ fh = new ['FileHandle']
+ fh.'open'('t/dynpmc/instrumentop-test1.pir', 'w')
+ fh.'puts'(program)
+ fh.'close'()
+.end
+
+.sub cleanup
+ # Remove the op test program.
+ .local pmc os
+ os = new ['OS']
+ os.'rm'('t/dynpmc/instrumentop-test1.pir')
+.end
+
+.sub test_one_op
+ # Test a single opcode.
+ .local pmc instr, probe, probe_class, args
+
+ # Set up the program args.
+ args = new ['ResizableStringArray']
+ args.'push'('t/dynpmc/instrumentop-test1.pir')
+
+ # Create a catchall probe.
+ probe_class = get_hll_global ['Instrument'], 'Probe'
+ probe = probe_class.'new'()
+ probe.'inspect'('say_sc')
+ probe.'set_callback'('test_one_op_callback')
+
+ # Create the Instrument instance and run it
+ # against t/dynpmc/instrumentop-test1.pir.
+ instr = new ['Instrument']
+ instr.'attach'(probe)
+ instr.'run'('t/dynpmc/instrumentop-test1.pir', args)
+.end
+
+.sub test_one_op_callback
+ .param pmc op
+ .param pmc instr
+
+ # Test op name.
+ $S0 = op.'name'()
+ is($S0, 'say_sc', 'Op name correct.')
+
+ # Test op family name.
+ $S0 = op.'family'()
+ is($S0, 'say', 'Op family name correct.')
+
+ # Test op argument count.
+ $I0 = op.'count'()
+ is($I0, 1, 'Op argument count correct.')
+
+ # Test op arg type.
+ $I1 = .PARROT_ARG_STRING + .PARROT_ARG_CONSTANT
+ $I0 = op.'arg_type'(0)
+ is($I0, $I1, 'Op argument type correct.')
+
+ # Test op arg value.
+ $S0 = op.'get_arg'(0)
+ is($S0, 'In test program', 'Op argument value correct.')
+
+ # Test pc. Op is the first op, so pc is 0.
+ $I0 = op.'pc'()
+ is($I0, 0, 'Op pc value correct.')
+
+ # Test file.
+ $S0 = op.'file'()
+ is($S0, 't/dynpmc/instrumentop-test1.pir', 'Op filename correct.')
+
+ # Test line.
+ $I0 = op.'line'()
+ is($I0, 3, 'Op line correct.')
+
+ # Test subroutine.
+ $S0 = op.'sub'()
+ is($S0, 'main', 'Op sub correct.')
+
+ # Test namespace.
+ $S0 = op.'namespace'()
+ is($S0, 'TestNS', 'Op namespace correct.')
+.end
+
+# Local Variables:
+# mode: pir
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
More information about the parrot-commits
mailing list