public inbox for frysk@sourceware.org
 help / color / mirror / Atom feed
* How to send signals to test programs?
@ 2008-03-26  1:43 Nurdin Premji
  2008-03-26 12:36 ` Mark Wielaard
  2008-03-26 13:32 ` Andrew Cagney
  0 siblings, 2 replies; 3+ messages in thread
From: Nurdin Premji @ 2008-03-26  1:43 UTC (permalink / raw)
  To: frysk

Trying to create a test for stepping over and through signals. I have a 
simple the test program and I'm copying testcases from
frysk-core/frysk/stepping/TestStepping.java

How do I send a signal to my test program from the TestStepping test?

Thank you,
Nurdin

funit-signal.c:

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>


volatile int j = 0;

void catch_usr (int sig_num)
{
        signal(SIGUSR1, 
catch_usr);                                             // 
_signalSigHandlerEntry_
        --j;
        ++j;
}

int
main ( int argc, char *argv[]) {

        signal(SIGUSR1, catch_usr);

        
--j;                                                                    
// _startTestEntry_
        ++j;
        return 0;
}


TestStepping.java addition:

public void testStepThroughSignal() {
        /** Variable setup */

        String source = Config.getRootSrcDir()
            + "frysk-core/frysk/pkglibdir/funit-signal.c";

        this.scanner = new TestfileTokenScanner(new File(source));

        /* The line number where the test begins */
        int start = this.scanner.findTokenLine("_startTestEntry_");

        /* The line number the test should end up at */
        int end = this.scanner.findTokenLine("_signalSigHandlerEntry_");

        /* The test process */
        SynchronizedOffspring process
            = new SynchronizedOffspring(Signal.USR1,
                                        new String[] {
                                            getExecPath("funit-signal")
                                        });
        this.testStarted = false;

        /** Test initialization */
        Task myTask = initTask(process, source, start, end);

        this.currentTest = new AssertLine(end, myTask);

        DebugInfoFrame frame = DebugInfoStackFactory
            .createDebugInfoStackTrace(myTask);
        assertTrue("Line information present", frame.getLine() != 
SourceLocation.UNKNOWN);

        /** The stepping operation */
        this.se.stepLine(myTask);

        /* TODO: Send Signal to myTask */

        this.testStarted = true;

        /** Run to completion */
        assertRunUntilStop("Running test");
        cleanup();
    }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to send signals to test programs?
  2008-03-26  1:43 How to send signals to test programs? Nurdin Premji
@ 2008-03-26 12:36 ` Mark Wielaard
  2008-03-26 13:32 ` Andrew Cagney
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Wielaard @ 2008-03-26 12:36 UTC (permalink / raw)
  To: Nurdin Premji; +Cc: frysk

Hi Nurdin,

On Tue, 2008-03-25 at 21:43 -0400, Nurdin Premji wrote:
> Trying to create a test for stepping over and through signals. I have a 
> simple the test program and I'm copying testcases from
> frysk-core/frysk/stepping/TestStepping.java
> 
> How do I send a signal to my test program from the TestStepping test?

You can deliver a signal through frysk.sys.Signal.[SIGNALNAME].kill(pid)
or tkill(tid) (don't confuse that class with frysk.isa.signal.Signal).
Note that you most likely also want to install an SignalObserver to
monitor when your signal arrives (there is no guarantee the signal gets
delivered immediately).

Another method would be to let the test program deliver itself a signal,
either through kill() or alarm()

Cheers,

Mark

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to send signals to test programs?
  2008-03-26  1:43 How to send signals to test programs? Nurdin Premji
  2008-03-26 12:36 ` Mark Wielaard
@ 2008-03-26 13:32 ` Andrew Cagney
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Cagney @ 2008-03-26 13:32 UTC (permalink / raw)
  To: Nurdin Premji; +Cc: frysk

Nurdin,

For this sort of testing, determinism is the key, so you'll want to have 
the program directly generate the signal, two ways:

-> cause an npe or similar
-> execute the kill system-call instruction

this can be done in assembler (see frysk-asm.h, and frysk-raise.S for 
example system calls).

Andrew


Nurdin Premji wrote:
> Trying to create a test for stepping over and through signals. I have 
> a simple the test program and I'm copying testcases from
> frysk-core/frysk/stepping/TestStepping.java
>
> How do I send a signal to my test program from the TestStepping test?
>
> Thank you,
> Nurdin
>
> funit-signal.c:
>
> #include <stdio.h>
> #include <unistd.h>
> #include <sys/types.h>
> #include <signal.h>
>
>
> volatile int j = 0;
>
> void catch_usr (int sig_num)
> {
>        signal(SIGUSR1, 
> catch_usr);                                             // 
> _signalSigHandlerEntry_
>        --j;
>        ++j;
> }
>
> int
> main ( int argc, char *argv[]) {
>
>        signal(SIGUSR1, catch_usr);
>
>        
> --j;                                                                    
> // _startTestEntry_
>        ++j;
>        return 0;
> }
>
>
> TestStepping.java addition:
>
> public void testStepThroughSignal() {
>        /** Variable setup */
>
>        String source = Config.getRootSrcDir()
>            + "frysk-core/frysk/pkglibdir/funit-signal.c";
>
>        this.scanner = new TestfileTokenScanner(new File(source));
>
>        /* The line number where the test begins */
>        int start = this.scanner.findTokenLine("_startTestEntry_");
>
>        /* The line number the test should end up at */
>        int end = this.scanner.findTokenLine("_signalSigHandlerEntry_");
>
>        /* The test process */
>        SynchronizedOffspring process
>            = new SynchronizedOffspring(Signal.USR1,
>                                        new String[] {
>                                            getExecPath("funit-signal")
>                                        });
>        this.testStarted = false;
>
>        /** Test initialization */
>        Task myTask = initTask(process, source, start, end);
>
>        this.currentTest = new AssertLine(end, myTask);
>
>        DebugInfoFrame frame = DebugInfoStackFactory
>            .createDebugInfoStackTrace(myTask);
>        assertTrue("Line information present", frame.getLine() != 
> SourceLocation.UNKNOWN);
>
>        /** The stepping operation */
>        this.se.stepLine(myTask);
>
>        /* TODO: Send Signal to myTask */
>
>        this.testStarted = true;
>
>        /** Run to completion */
>        assertRunUntilStop("Running test");
>        cleanup();
>    }
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-03-26 13:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-26  1:43 How to send signals to test programs? Nurdin Premji
2008-03-26 12:36 ` Mark Wielaard
2008-03-26 13:32 ` Andrew Cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).