harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leo Li" <liyilei1...@gmail.com>
Subject Re: [classlib][Instrument] Documents for non-unit-tests (was Re:[classlib] Plan on work on java.lang.instrument)
Date Mon, 07 Aug 2006 13:08:39 GMT
On 8/7/06, Jimmy, Jing Lv <firepure@gmail.com> wrote:
>
> 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.


Excuse for my confusing you.
Actually, in premain, I want to write:
public static void premain(String agentArgs, Instrumentation inst)
 {
try
 {
   inst.addTransformer(null);
   //failed, we set error code
   System.exit(1);
  }
  catch(NullPointerException e)
  {
    //expected, the exit code is zero.
  }
}

I think to set error code is enough to denote which exception has been
thrown out. When and only when the expected exception is thrown out and
no other exception  has been thrown out or vm exits abnormally, the return
value is zero which we expect. (Of course, as Varlamov says, there is the
case that VM hangs for us to deal with.)

Besides the java exceptions, other  reasons that cause VM to exit
abnormally, for example, the denoted premain class does not exists, are only
showed by some error strings. Except for these strings, as a black box, what
we know is just VM exits abnormally. Is it necessary for us to write
testcases to verify these error message as the causes? Is it enough for us
just to know VM exits abnormally at the specified stage? Or else maybe we
can use lProcess.getErrorStream() or getOutputStream() to get the error
message, I am not sure.:)

> On 8/7/06, Jimmy, Jing Lv <firepure@gmail.com> wrote:
> >>
> >> Geir Magnusson Jr wrote:
> >> >
> >> > Jimmy, Jing Lv wrote:
> >> >> Richard Liang wrote:
> >> >>>
> >> >>> Jimmy, Jing Lv wrote:
> >> >>>> Hi,
> >> >>>>
> >> >>>>     As it is hard to write unit test for package instrument,
I now
> >> >>>> have an idea: write down some documents for details of non-unit
> test
> >> >>>> cases for instrument. The detail of such test cases contain:
> >> >>> Do you mean it's hard to *write* unit test or it's hard to
> integrate
> >> >>> the tests with Harmony build system?
> >> >>>
> >> >> Hard to write unit test, so record them in some document may be a
> >> better
> >> >> way :)
> >> >
> >> > Why is it hard to create unit tests?
> >> >
> >>
> >> To test java.lang.instrument, mostly we need to start up a new VM to
> see
> >> its behavior. Its function(premain, etc) may be run before most classes
> >> loaded, and almost all exceptions will cause VM abort. And the result
> is
> >> hard to be checked automatic. What's more, extra java/c code is needed
> >> for the test.
> >>
> >> One thought was that we can use exec("java commands") in junit(is that
> >> OK to run exec in tests?), but how to check its output is still a
> >> problem.
> >>
> >> I'll put unit test if any, but I believe most necessary and important
> >> tests are non-unit tests.
> >>
> >> >>>> 1. The test run on which platform, including special environment;
> >> >>>> 2. The test description;
> >> >>>> 3. How to run test (command line, etc.);
> >> >>>> 4. test result;
> >> >>>> 5. resource (or links) for tests, including c/java code for
test
> if
> >> any.
> >> >>>>
> >> >>>>     I hope ensure the code quality in this way. Like unit test,
> such
> >> >>>> tests can be checked and re-run for regression, though
> >> un-automatically.
> >> >>>>
> >> >>>>     And I'll put them in Harmony-wiki[1], and any
> >> test-description is
> >> >>>> welcome!. (Geir, I've found an advancement of wiki :) )
> >> >>>>
> >> >>>>     Any suggestions?  :)
> >> >>>>
> >> >>>> [1]http://wiki.apache.org/harmony/INSTRUMENT
> >> >>>>
> >> >>>>> Geir Magnusson Jr wrote:
> >> >>>>> Never appeal to me using a Wiki as an authority :)  It's
like
> >> finding
> >> >>>>> something written in chalk on the sidewalk.
> >> >>>>>
> >> >>>>> However, if you had pointed out
> >> >>>>>
> >> >>>>>    http://incubator.apache.org/harmony/auth_cont_quest.html
> >> >>>>>
> >> >>>>> I'd have agreed w/o having the opportunity to make fun
of the
> Wiki.
> >> >>>>>
> >> >>>>> So I agree :)
> >> >>>>>
> >> >>>>> geir
> >> >>>>
> >> >>
> >> >
> >> > ---------------------------------------------------------------------
>
> >> > Terms of use : http://incubator.apache.org/harmony/mailing.html
> >> > To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> >> > For additional commands, e-mail:
> harmony-dev-help@incubator.apache.org
> >> >
> >> >
> >>
> >>
> >> --
> >>
> >> Best Regards!
> >>
> >> Jimmy, Jing Lv
> >> China Software Development Lab, IBM
> >>
> >> ---------------------------------------------------------------------
> >> Terms of use : http://incubator.apache.org/harmony/mailing.html
> >> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> >> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
> >>
> >>
> >
> >
>
>
> --
>
> Best Regards!
>
> Jimmy, Jing Lv
> China Software Development Lab, IBM
>
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>


-- 
Leo Li
China Software Development Lab, IBM

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message