ADD_DEFINITIONS(-DUSE_FULSIM=0)
ENDIF (USE_FULSIM)
-SET(CMAKE_CXX_FLAGS "-Wall -Wno-invalid-offsetof -mfpmath=sse --no-exceptions --no-rtti -Wcast-align -std=c++0x")
+SET(CMAKE_CXX_FLAGS "-Wall -Wno-invalid-offsetof -mfpmath=sse --no-rtti -Wcast-align -std=c++0x")
SET(CMAKE_C_FLAGS "-Wall -mfpmath=sse -msse2 -Wcast-align")
# XLib
--- /dev/null
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/../include)
+
+ADD_LIBRARY(cl_test SHARED
+ cl_test.c
+ cl_file_map.c
+ common.c
+ assert.cpp
+ utest.cpp)
+ADD_EXECUTABLE(write_only write_only.c)
+TARGET_LINK_LIBRARIES(write_only cl m cl_test)
+
--- /dev/null
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+
+/**
+ * \file assert.cpp
+ * \author Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+#include "assert.hpp"
+#include "exception.hpp"
+#include <cassert>
+#include <cstdlib>
+
+void onFailedAssertion(const char *msg, const char *file, const char *fn, int line)
+{
+ char lineString[256];
+ sprintf(lineString, "%i", line);
+ assert(msg != NULL && file != NULL && fn != NULL);
+ const std::string str = "Compiler error: "
+ + std::string(msg) + "\n at file "
+ + std::string(file)
+ + ", function " + std::string(fn)
+ + ", line " + std::string(lineString);
+ // assert(0);
+ throw Exception(str);
+}
+
--- /dev/null
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+
+/**
+ * \file assert.hpp
+ *
+ * \author Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+#ifndef __OCL_ASSERT_HPP__
+#define __OCL_ASSERT_HPP__
+
+/*! To ensure that condition truth. Optional message is supported */
+void onFailedAssertion(const char *msg, const char *file, const char *fn, int line);
+
+#endif /* __OCL_ASSERT_HPP__ */
+
--- /dev/null
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+
+/**
+ * \file exception.hpp
+ *
+ * \author Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+#ifndef __OCL_EXCEPTION_HPP__
+#define __OCL_EXCEPTION_HPP__
+
+#include <string>
+#include <exception>
+
+/*! Exception are only used while using unit tests */
+class Exception : public std::exception
+{
+public:
+ Exception(const std::string &msg) throw() : msg(msg) {}
+ Exception(const Exception &other) throw() : msg(other.msg) {}
+ ~Exception(void) throw() {}
+ Exception &operator= (const Exception &other) throw() {
+ this->msg = other.msg;
+ return *this;
+ }
+ const char *what(void) const throw() { return msg.c_str(); }
+private:
+ std::string msg; //!< String message
+};
+
+#endif /* __OCL_EXCEPTION_HPP__ */
+
--- /dev/null
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+
+/**
+ * \file utest.cpp
+ * \author Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+#include "utest.hpp"
+#include <vector>
+#include <string>
+#include <iostream>
+#include <cstring>
+
+using namespace std;
+vector<UTest> *UTest::utestList = NULL;
+void releaseUTestList(void) { delete UTest::utestList; }
+
+UTest::UTest(Function fn, const char *name) : fn(fn), name(name) {
+ if (utestList == NULL) {
+ utestList = new vector<UTest>;
+ atexit(releaseUTestList);
+ }
+ utestList->push_back(*this);
+}
+
+UTest::UTest(void) : fn(NULL), name(NULL) {}
+
+static bool strequal(const char *s1, const char *s2) {
+ if (strcmp(s1, s2) == 0) return true;
+ return false;
+}
+
+void UTest::run(const char *name) {
+ if (name == NULL) return;
+ if (utestList == NULL) return;
+ for (size_t i = 0; i < utestList->size(); ++i) {
+ const UTest &utest = (*utestList)[i];
+ if (utest.name == NULL || utest.fn == NULL) continue;
+ if (strequal(utest.name, name)) {
+ std::cout << utest.name << ":" << std::endl;
+ (utest.fn)();
+ std::cout << std::endl;
+ }
+ }
+}
+
+void UTest::runAll(void) {
+ if (utestList == NULL) return;
+ for (size_t i = 0; i < utestList->size(); ++i) {
+ const UTest &utest = (*utestList)[i];
+ if (utest.fn == NULL) continue;
+ std::cout << utest.name << ":" << std::endl;
+ (utest.fn)();
+ std::cout << std::endl;
+ }
+}
+
--- /dev/null
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+
+/**
+ * \file utest.hpp
+ * \author Benjamin Segovia <benjamin.segovia@intel.com>
+ *
+ * Provides all unit test capabilites. It is rather rudimentary but it should
+ * do the job
+ */
+#ifndef __OCL_UTEST_HPP__
+#define __OCL_UTEST_HPP__
+
+#include <vector>
+#include <exception>
+
+/*! Quick and dirty unit test system with registration */
+struct UTest
+{
+ /*! A unit test function to run */
+ typedef void (*Function) (void);
+ /*! Empty test */
+ UTest(void);
+ /*! Build a new unit test and append it to the unit test list */
+ UTest(Function fn, const char *name);
+ /*! Function to execute */
+ Function fn;
+ /*! Name of the test */
+ const char *name;
+ /*! The tests that are registered */
+ static std::vector<UTest> *utestList;
+ /*! Run the test with the given name */
+ static void run(const char *name);
+ /*! Run all the tests */
+ static void runAll(void);
+};
+
+/*! RegisterData a new unit test */
+#define UTEST_REGISTER(FN) static const UTest __##FN##__(FN, #FN);
+
+/*! No assert is expected */
+#define UTEST_EXPECT_SUCCESS(EXPR) \
+ do { \
+ try { \
+ EXPR; \
+ std::cout << " " << #EXPR << " [SUCCESS]" << std::endl; \
+ } \
+ catch (gbe::Exception e) { \
+ std::cout << " " << #EXPR << " [FAILED]" << std::endl; \
+ std::cout << " " << e.what() << std::endl; \
+ } \
+ } while (0)
+
+#define UTEST_EXPECT_FAILED(EXPR) \
+ do { \
+ try { \
+ EXPR; \
+ std::cout << " " << #EXPR << " [FAILED]" << std::endl; \
+ } \
+ catch (gbe::Exception e) { \
+ std::cout << " " << #EXPR << " [SUCCESS]" << std::endl; \
+ } \
+ } while (0)
+
+#endif /* __OCL_UTEST_HPP__ */
+