Bug 1120

Summary: NS_LOG environment variable not working with test.py
Product: ns-3 Reporter: Nicola Baldo <nicola>
Component: test frameworkAssignee: Mitch Watrous <watrous>
Status: RESOLVED FIXED    
Severity: enhancement CC: jpelkey, ns-bugs, tomh, watrous
Priority: P3    
Version: ns-3-dev   
Hardware: All   
OS: All   
Attachments: document how to debug tests by enabling logging

Description Nicola Baldo 2011-05-02 07:25:01 UTC
Currently it is not possible to do the following:

NS_LOG=MyLogComponent ./test.py  -s my-test-suite

Hence, to turn on loggin in test programs I have to hardcode "LogComponentEnable" statements in the test code. This makes it more time consuming to debug tests.

This is an enhancement request, but I think we should give it high priority, because based on my opinion if writing tests is too complex then people won't write many tests.
Comment 1 Mitch Watrous 2011-05-13 18:02:58 UTC
Here is what test.py says and does:

    # If lots of logging is enabled, we can crash Python when it tries to 
    # save all of the text.  We just don't allow logging to be turned on when
    # test.py runs.  If you want to see logging output from your tests, you
    # have to run them using the test-runner directly.
    #
    os.environ["NS_LOG"] = ""

Try running the test using the test-runner like this:

    ./waf --run "test-runner --basedir=`pwd` --suite=my-test-suite"

and see if logging works .

If you want to see what happened when your test ran, send the output to an XML file like this:

    ./waf --run "test-runner --basedir=`pwd` --suite=my-test-suite --out=my-test-suite-result.xml"

Does this let you do the logging you need?
Comment 2 Josh Pelkey 2011-05-13 18:12:44 UTC
(In reply to comment #1)
> Here is what test.py says and does:
> 
>     # If lots of logging is enabled, we can crash Python when it tries to 
>     # save all of the text.  We just don't allow logging to be turned on when
>     # test.py runs.  If you want to see logging output from your tests, you
>     # have to run them using the test-runner directly.
>     #
>     os.environ["NS_LOG"] = ""
> 
> Try running the test using the test-runner like this:
> 
>     ./waf --run "test-runner --basedir=`pwd` --suite=my-test-suite"
> 
> and see if logging works .
> 
> If you want to see what happened when your test ran, send the output to an XML
> file like this:
> 
>     ./waf --run "test-runner --basedir=`pwd` --suite=my-test-suite
> --out=my-test-suite-result.xml"
> 
> Does this let you do the logging you need?

This is exactly right. We used to have logging possible during tests, but it led to other bugs. See https://www.nsnam.org/bugzilla/﷒0
Comment 3 Nicola Baldo 2011-07-05 08:03:29 UTC
I understand, but this behavior is not documented at all. My experience is that for people that are writing a test for the first time it is a pain to find out how to debug it. Hence I think we should document this feature.
Comment 4 Nicola Baldo 2011-07-05 08:04:34 UTC
Created attachment 1186 [details]
document how to debug tests by enabling logging

here is a proposed patch to the documentation that adds some minimum of information regarding this issue.
Comment 5 Mitch Watrous 2011-07-05 16:29:12 UTC
Patch applied.  Thanks.

Bug closed.

ns-3-dev changeset:  99762b541ef9