2006/8/7, Jimmy, Jing Lv <[EMAIL PROTECTED]>:
Leo Li wrote:
> Hi, all:
>     I have some idea to test instrument.
>     For example, if we would like to test
> Instrumentation.addTransformerwill throw NullPointerException if the
> argument is null,
>     we can first write a TestInstrument with premain function.
>
> import java.lang.instrument.Instrumentation;
> public class TestInstrument {
>
> public static void premain(String agentArgs, Instrumentation inst)
> {
>  try
>  {
>   inst.addTransformer(null);
>  }
>  catch(NullPointerException e)
>  {
>   //failed, we set error code
>   System.exit(1);
>  }
> }
> }
> Normally, the VM will exit with zero as it return value if there is no
> exception occurs in main class.
>
> then, we might write an JUnit Test:
> public void test() throws Exception
> {
>  Process process = Runtime.getRuntime().exec("java -javaagent
> Test.jarTest");
>  //if premain runs as we expected, the exit code is zero.
>  assertEquals(0,process.waitFor());
> }
>
> (Besides,Test is an ordinary class with a main function that will not throw
> error. Test.jar with the manifest to denote the class of TestInstrument as
> the premain class.}
>
> Is it all right? :)
>

Sounds pretty good :)
"exec" do helps, it can check simple situations.
What I'm concern is that if the return code is not enough for some
situations, e.g, what exception is thrown exactly, or what cause VM exit
abnormally. IMHO, it is still necessary for us.

And you forgot to mention cases when tested VM hangs :)
Still, almost any of those situations may be tested automatically,
just fork a tested JVM and setup timeout watchdog. You may examine
1) return value (via j.lProcess.exitValue());
2) out/err streams of the forked process (j.lProcess.getErrorStream()
& j.lProcess.getInputStream());

Though I'm unsure this is readily possible with Ant+junit, likely more
functional harness is needed.

--
Regards,
Alexey

[snip]

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to