1 //===-- Exhaustive test template for math functions -------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include <fenv.h> 10 #include <functional> 11 #include <iostream> 12 #include <sstream> 13 #include <string> 14 #include <thread> 15 #include <vector> 16 17 #include "exhaustive_test.h" 18 #include "utils/UnitTest/Test.h" 19 20 template <typename T> 21 void LlvmLibcExhaustiveTest<T>::test_full_range(T start, T stop, int nthreads, 22 mpfr::RoundingMode rounding) { 23 std::vector<std::thread> thread_list(nthreads); 24 T increment = (stop - start - 1) / nthreads + 1; 25 T begin = start; 26 T end = start + increment - 1; 27 for (int i = 0; i < nthreads; ++i) { 28 thread_list.emplace_back([this, begin, end, rounding]() { 29 std::stringstream msg; 30 msg << "-- Testing from " << begin << " to " << end << " [0x" << std::hex 31 << begin << ", 0x" << end << ") ..." << std::endl; 32 std::cout << msg.str(); 33 msg.str(""); 34 35 bool result = check(begin, end, rounding); 36 37 msg << "** Finished testing from " << std::dec << begin << " to " << end 38 << " [0x" << std::hex << begin << ", 0x" << end 39 << ") : " << (result ? "PASSED" : "FAILED") << std::endl; 40 std::cout << msg.str(); 41 }); 42 begin += increment; 43 end += increment; 44 if (end > stop) 45 end = stop; 46 } 47 for (auto &thread : thread_list) { 48 if (thread.joinable()) { 49 thread.join(); 50 } 51 } 52 } 53 54 template void 55 LlvmLibcExhaustiveTest<uint32_t>::test_full_range(uint32_t, uint32_t, int, 56 mpfr::RoundingMode); 57 template void 58 LlvmLibcExhaustiveTest<uint64_t>::test_full_range(uint64_t, uint64_t, int, 59 mpfr::RoundingMode); 60