#include "xunit.hpp" #include #include #include using namespace std; string show_build_log(vector& devices, cl::Program& program) { ostringstream complete_log; for (size_t i = 0; i < devices.size(); i++) { string build_log = program.getBuildInfo(devices[i]); if (build_log.size() > 0) { complete_log << build_log << endl; } } return complete_log.str(); } static void test_with_field(const tin::field& f, size_t skip = 1) { cl::Context ctx(CL_DEVICE_TYPE_ALL); cl::Program::Sources sources = cl::Program::Sources(); sources.push_back(make_pair(tin::kernels::finite_fields::text, tin::kernels::finite_fields::size)); sources.push_back(make_pair(tin::kernels::finite_fields::tests::text, tin::kernels::finite_fields::tests::size)); cl::Program program(ctx, sources); vector devices = ctx.getInfo(); bool threw = false; try { ostringstream options; options << "-D ffwidth=" << f.width() << " -D SKIP=" << skip; program.build(devices, options.str().c_str()); string log = show_build_log(devices, program); if (log.size() > 0) { WARN("Build log: " << log); } } catch (cl::Error e) { threw = true; FAIL("Build log: " << show_build_log(devices, program)); } cl::Buffer ffip(ctx, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, f.width(), f.polynomial().data()); cl::Kernel kernel(program, "Test"); kernel.setArg(0, ffip); cl::CommandQueue queue(ctx, devices[0], 0); cl::Event event; queue.enqueueTask(kernel, NULL, &event); event.wait(); cout.flush(); } TEST_CASE ("tin::kernels finite field tests with rijndael field", "[tin::kernels]") { cout << "Testing with Rijndael field:" << endl << endl; test_with_field(tin::field::rijndael(), 1); cout << endl; } TEST_CASE ("tin::kernels finite field tests with sixteen field", "[tin::kernels]") { cout << "Testing with Sixteen field:" << endl << endl; test_with_field(tin::field::sixteen(), 377); cout << endl; }