4 Replies Latest reply on Jan 18, 2016 4:08 AM by adinn

    Debugging byteman tests

    jameslivingston

      When working on Byteman, certain kinds of test failures could me made a lot simpler to debug, especially any changes that affect the loading of rules. Right now, what happens is that a number of tests fail reporting that the output does not contain the extra entries added by the rule, without indicating that was because the rule didn't load.

       

      If you add 'prop:org.jboss.byteman.verbose=true' to the agent string in the POM, it will report "unexpected error parsing rule ..." and the basic exception info in the maven output (but not in the test report). It may be useful to have TransformContext.transform() print the exception stack trace too, rather than just the class and message, especially if Filipe's tracing work was done so it could be done at a more detailed logging level.

       

      TransformListener's LIST command dumps out the rules that are loaded, including what it matches and any exceptions thrown. Starting up the listener for unit tests may not be a good idea, but dumping that output for a test that fails it's output check may be useful.

        • 1. Re: Debugging byteman tests
          adinn

          Hi James,

           

          I agree that we ought to enable verbose trace for Byteman tests. Unfortunately we are stuck with maven's inability to provide an execution schema. So, in order to achieve this I think we need to globally substitute the command args for each test execution to insert the relevant property setting (-Dorg.jboss.byteman.verbose -- there is no need to specify a value).

           

          Adding a stack trace at a finer trace level also sounds like a very good idea

           

          Regarding the LIST functionality:

           

          First, I'll note that tests run with BMUnit have to start up the listener. That's what BMUnit uses to upload and unload rules -- or rather what the Submit class employed by BMUnit uses. That's a deliberate choice to simplify securingthe agent. If you leave aside apps which provide trheir own uplaod manager (via the javaagent manager: option) then the only way to get rules into the Byteman agent is either via the javaagent script option or via the TransformListener's socket. There is no JVM-internal backdoor providing access to the TransformListener instance.

           

          That said, I think this is a great idea. If we want to dump a rule listing for failing tests then we need to do that at the point where the rules are about to be unloaded. I will have to check that the class requesting the unload actually knows whether or not the test succeeded. If so then it can use the Submit class to request the listing (although we will need to wrap that request up inside an API method of class BMUnit since only it knows the agent host and port).

           

          I'll raise a JIRA for this functionality.

          • 2. Re: Debugging byteman tests
            adinn
            • 3. Re: Debugging byteman tests
              jameslivingston

              If we didn't want the socket opened for normal tests, we could write an alternative manager for the tests instead of TransformListener, which stored the Retransformer in a static variable and provided a static method which called Retransformer.listScripts() which could be used by the JUnit tests. Using the existing code would probably be easier though.

              • 4. Re: Debugging byteman tests
                adinn

                James Livingston wrote:

                 

                If we didn't want the socket opened for normal tests, we could write an alternative manager for the tests instead of TransformListener, which stored the Retransformer in a static variable and provided a static method which called Retransformer.listScripts() which could be used by the JUnit tests. Using the existing code would probably be easier though.

                 

                Hmm, bypassing the socket upload in BMUnit is an interesting idea.  If the BMUnit implementation were to provide the manager class then class BMUnit could actually have direct, private (i.e. secure) access to the transformer instance. Still, the socket stuff is already there, works reliably enough and does not pose any major problems in a dev environment -- so this is a low priority.