简体   繁体   中英

Cannot allocate memory using boost test

I have a test case like this:

BOOST_AUTO_TEST_CASE(Test) {
    std::thread([](){
        BOOST_CHECK(system("script.sh") >= 0);
    }).detach();
    //other checks here
}

When I run only this test suite everything is ok. When I run my 80 tests then assert fails with "cannot allocate memory" as value returned by system . Is there any workaround?

If you run the test in isolation and it works, while running this test in non-isolation (with other tests) and it fails, then "something" is happening to the state of your test program and that need to be fixed.

For instance,

  • a memory leak in other tests that affects this one,
  • the fact that you started too many threads without waiting for their completion (like what I am seeing in your snippet),
  • etc.

This is not exactly a Boost.Test issue, Boost.Test just shows you that there is an (rather big) issue somewhere in the program. The way to nail down is to run things in isolation, possibly many times such that, for instance, you can really observe the increased need for memory or even a crash. Boost.Test tries hard to mitigate those crashes (intercepts operating systems' signals) and depending on the operating system shows memory leaks, but it is not magic.

Other way of isolating the issue would be to use other programs such as valgind or asan / tsan .

One last possibility is that "script.sh" is eating up all the memory of your operating system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM