Boost C++ Libraries: Ticket #13024: Using function as data source in BOOST_DATA_TEST_CASE initiate the conflict with static variables initialization https://svn.boost.org/trac10/ticket/13024 <p> I got the crash like <a class="ext-link" href="https://svn.boost.org/trac/boost/ticket/12987"><span class="icon">​</span>here</a>(ticket 12987) when switched my tests from boost v1.63.0 to v1.64.0. I'm using <code>BOOST_DATA_TEST_CASE</code> with a function as the second parameter. My function uses <code>boost::filesystem::path</code> to walk through directory and collect data files: </p> <pre class="wiki">static std::vector&lt;boost::filesystem::path&gt; get_files() { std::vector&lt;boost::filesystem::path&gt; result; boost::system::error_code error; boost::filesystem::directory_iterator it("C:\\", error); for (boost::filesystem::directory_iterator const eit; it != eit; ++it) if (is_regular_file(it-&gt;status())) result.push_back(it-&gt;path()); return result; } BOOST_DATA_TEST_CASE(test, get_files(), file_name) { std::cout &lt;&lt; file_name &lt;&lt; std::endl; } </pre><p> I was very surprised when found that my <code>get_files()</code> called during static variables initialization (from <code>_initterm()</code>): </p> <pre class="wiki">Exception thrown at 0x0000000000000000 in BoostTests.exe: 0xC0000005: Access violation executing location 0x0000000000000000. occurred 0000000000000000() Unknown BoostTests.exe!`anonymous namespace'::make_permissions(const boost::filesystem::path &amp; p, unsigned long attr) Line 629 C++ BoostTests.exe!`anonymous namespace'::dir_itr_first(void * &amp; handle, const boost::filesystem::path &amp; dir, std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt; &amp; target, boost::filesystem::file_status &amp; sf, boost::filesystem::file_status &amp; symlink_sf) Line 2275 C++ BoostTests.exe!boost::filesystem::detail::directory_iterator_construct(boost::filesystem::directory_iterator &amp; it, const boost::filesystem::path &amp; p, boost::system::error_code * ec) Line 2374 C++ BoostTests.exe!boost::filesystem::directory_iterator::directory_iterator(const boost::filesystem::path &amp; p, boost::system::error_code &amp; ec) Line 907 C++ BoostTests.exe!get_files() Line 15 C++ BoostTests.exe!test::`dynamic initializer for 'testcase_registrar2222''() Line 22 C++ BoostTests.exe!_initterm(void(*)() * first, void(*)() * last) Line 22 C++ [External Code] </pre><p> On my opinion the data collection has to be run immediately before test starting. I see some bonuses in this approach: </p> <ul><li>no unnecessary data collecting when user run only selected set of tests; </li><li>correct and suitable error handling for function, now any exception means crash; </li></ul><p> After some investigation I found that <code>test_case_gen</code> runs test creating in constructor to fill <code>m_test_cases</code> variable which is used only during <code>next()</code> call. However, <code>next()</code> also called from static context from <code>auto_test_unit_registrar</code>. And this is the problem! </p> <p> Could you please change the boost test behavior to grant that test collecting will be made in test main method, but not during static variable initialization? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13024 Trac 1.4.3 Raffi Enficiaud Mon, 15 May 2017 10:11:04 GMT <link>https://svn.boost.org/trac10/ticket/13024#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13024#comment:1</guid> <description> <p> This is quite a big change in the way the initialization of the boost.test framework works, but I agree that this is a nice feature to have. I am leaving this open for the moment. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Tue, 29 Aug 2017 21:41:41 GMT</pubDate> <title>type changed https://svn.boost.org/trac10/ticket/13024#comment:2 https://svn.boost.org/trac10/ticket/13024#comment:2 <ul> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Feature Requests</span> </li> </ul> Ticket Ilia <ki.stfu@…> Tue, 03 Oct 2017 10:07:24 GMT <link>https://svn.boost.org/trac10/ticket/13024#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13024#comment:3</guid> <description> <p> I have faced with similar issue when upgrading to 1.65.1 and I can only say that at the moment BOOST_DATA_TEST_CASE cannot be used with something like <code>get_files()</code> for gettign different input files. </p> <ol><li>Could you update the manual to state that <code>dataset</code> is being initialized during initialization of statics? </li><li>Can you provide the estimated time when this issue be resolved? I don't want to migrate to another test framework, but now it blocks me. </li></ol> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Thu, 28 Dec 2017 19:34:40 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13024#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13024#comment:4</guid> <description> <p> To unblock you, you can always mimic the dataset behaviour by manually registering test cases in the init of the test framework: </p> <ul><li><a href="http://www.boost.org/doc/libs/release/libs/test/doc/html/boost_test/adv_scenarios/test_module_init_overview.html">http://www.boost.org/doc/libs/release/libs/test/doc/html/boost_test/adv_scenarios/test_module_init_overview.html</a> for test initialization function </li><li><a href="http://www.boost.org/doc/libs/release/libs/test/doc/html/boost_test/tests_organization/test_cases/test_organization_nullary.html#ref_BOOST_TEST_CASE">http://www.boost.org/doc/libs/release/libs/test/doc/html/boost_test/tests_organization/test_cases/test_organization_nullary.html#ref_BOOST_TEST_CASE</a> for manual registration </li></ul><p> You may for instance collect the files and then manually register a test for each of them. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Wed, 03 Jan 2018 00:42:42 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13024#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13024#comment:5</guid> <description> <p> I am not sure the crashes you are experiencing is due to a change in Boost.Test between 1.63 and a later version. The <code>get_files</code> function is always evaluated at static initialization time as the <code>BOOST_DATA_TEST_CASE</code> creates a static global object. </p> <p> I tend to think that there is something in filesystem that prevents from calling functions during this global static initialization phase. So I suggest that you ask or raise a ticket on boost.filesystem side to make it clear. </p> <p> However, there is the ticket <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/12953" title="#12953: Feature Requests: access to master_test_suite().{argc, argv} (closed: fixed)">#12953</a> that should help as it postpones the evaluation of the datasets, it would be good if you can give a try. To support this further, I suggest getting the files later in the init phase by providing a proper dataset interface to the function retrieving the files, as shown <a href="http://www.boost.org/doc/libs/1_66_0/libs/test/doc/html/boost_test/tests_organization/test_cases/test_case_generation/datasets.html#boost_test.tests_organization.test_cases.test_case_generation.datasets.example_descr">here</a> (for instance getting the files when calling <code>begin</code> or <code>size</code>). </p> <p> Please keep me posted. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Thu, 18 Jan 2018 19:52:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13024#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13024#comment:6</guid> <description> <p> Any news? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Sun, 11 Feb 2018 18:05:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13024#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13024#comment:7</guid> <description> <p> Kind reminder </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Wed, 27 Jun 2018 08:31:33 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13024#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13024#comment:8</guid> <description> <p> Closing, worst case related to <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/12953" title="#12953: Feature Requests: access to master_test_suite().{argc, argv} (closed: fixed)">#12953</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Raffi Enficiaud</dc:creator> <pubDate>Wed, 01 Aug 2018 17:09:57 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/13024#comment:9 https://svn.boost.org/trac10/ticket/13024#comment:9 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">obsolete</span> </li> </ul> <p> Fixed via <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/12953" title="#12953: Feature Requests: access to master_test_suite().{argc, argv} (closed: fixed)">#12953</a> </p> Ticket