MCPcopy Create free account
hub / github.com/bshoshany/thread-pool / check_blocks

Function check_blocks

tests/BS_thread_pool_test.cpp:1814–1896  ·  view source on GitHub ↗

* @brief Check that detach_blocks() and submit_blocks() work using several different random values for the range of indices and number of tasks. */

Source from the content-addressed store, hash-verified

1812 * @brief Check that detach_blocks() and submit_blocks() work using several different random values for the range of indices and number of tasks.
1813 */
1814void check_blocks()
1815{
1816 constexpr std::int64_t range = 1000000;
1817 constexpr std::size_t repeats = 10;
1818 BS::thread_pool pool;
1819 for (std::size_t i = 0; i < repeats; ++i)
1820 {
1821 const std::pair<std::int64_t, std::int64_t> indices = random_pair(-range, range);
1822 check(check_blocks_no_return(pool, indices.first, indices.second, random<std::size_t>(1, pool.get_thread_count()), "detach_blocks()"));
1823 }
1824 for (std::size_t i = 0; i < repeats; ++i)
1825 {
1826 const std::pair<std::int64_t, std::int64_t> indices = random_pair(-range, range);
1827 check(check_blocks_no_return(pool, indices.first, indices.second, random<std::size_t>(1, pool.get_thread_count()), "submit_blocks()"));
1828 }
1829 for (std::size_t i = 0; i < repeats; ++i)
1830 {
1831 const std::pair<std::int64_t, std::int64_t> indices = random_pair(-range, range);
1832 check_blocks_return(pool, indices.first, indices.second, random<std::size_t>(1, pool.get_thread_count()));
1833 }
1834 logln("Verifying that detach_blocks() with identical start and end indices does nothing...");
1835 {
1836 std::atomic<std::size_t> count = 0;
1837 const std::int64_t index = random(-range, range);
1838 logln("Range: ", index, " to ", index);
1839 pool.detach_blocks(index, index,
1840 [&count](const std::int64_t, const std::int64_t)
1841 {
1842 ++count;
1843 });
1844 pool.wait();
1845 check(count == 0);
1846 }
1847 logln("Verifying that submit_blocks() with identical start and end indices does nothing...");
1848 {
1849 std::atomic<std::size_t> count = 0;
1850 const std::int64_t index = random(-range, range);
1851 logln("Range: ", index, " to ", index);
1852 pool.submit_blocks(index, index,
1853 [&count](const std::int64_t, const std::int64_t)
1854 {
1855 ++count;
1856 })
1857 .wait();
1858 check(count == 0);
1859 }
1860 logln("Verifying that detach_blocks() with end index smaller than the start index does nothing...");
1861 {
1862 std::atomic<std::size_t> count = 0;
1863 const std::pair<std::int64_t, std::int64_t> indices = random_pair(-range, range);
1864 logln("Range: ", indices.second, " to ", indices.first);
1865 pool.detach_blocks(indices.second, indices.first,
1866 [&count](const std::int64_t, const std::int64_t)
1867 {
1868 ++count;
1869 });
1870 pool.wait();
1871 check(count == 0);

Callers 1

mainFunction · 0.85

Calls 7

random_pairFunction · 0.85
checkFunction · 0.85
check_blocks_no_returnFunction · 0.85
check_blocks_returnFunction · 0.85
loglnFunction · 0.85
randomFunction · 0.85
waitMethod · 0.80

Tested by

no test coverage detected