LGTM, pushed, thanks.
On Wed, Sep 04, 2013 at 10:48:48AM +0800, Yi Sun wrote: > Add some arguments: > -c <casename>: run sub-case named 'casename' > -l : list all the available case name > -a : run all test cases > -n : run all test cases without known issue > -h : display this usage > > Add a alternate macro named MAKE_UTEST_FROM_FUNCTION_WITH_ISSUE to register a > new test case, which has some known issue to be fixed till now. > While utest_run running, only cases which registered by > MAKE_UTEST_FROM_FUNCTION will be involved by defalut. > If you want to run all the test cases including those with known issue, you > should use argument '-a'. > Besides, you can use option '-c' to run any test case. > > Signed-off-by: Yi Sun <[email protected]> > > diff --git a/utests/utest.cpp b/utests/utest.cpp > index 24045c7..04e205a 100644 > --- a/utests/utest.cpp > +++ b/utests/utest.cpp > @@ -32,7 +32,7 @@ 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) { > +UTest::UTest(Function fn, const char *name, bool haveIssue) : fn(fn), > name(name), haveIssue(haveIssue) { > if (utestList == NULL) { > utestList = new vector<UTest>; > atexit(releaseUTestList); > @@ -40,7 +40,7 @@ UTest::UTest(Function fn, const char *name) : fn(fn), > name(name) { > utestList->push_back(*this); > } > > -UTest::UTest(void) : fn(NULL), name(NULL) {} > +UTest::UTest(void) : fn(NULL), name(NULL), haveIssue(false) {} > > static bool strequal(const char *s1, const char *s2) { > if (strcmp(s1, s2) == 0) return true; > @@ -52,7 +52,7 @@ void UTest::run(const char *name) { > 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 (utest.name == NULL || utest.fn == NULL || utest.haveIssue) continue; > if (strequal(utest.name, name)) { > std::cout << utest.name << ":" << std::endl; > (utest.fn)(); > @@ -76,10 +76,24 @@ void UTest::runAll(void) { > } > } > > -void UTest::listAll(void) { > +void UTest::runAllNoIssue(void) { > if (utestList == NULL) return; > for (size_t i = 0; i < utestList->size(); ++i) { > const UTest &utest = (*utestList)[i]; > + if (utest.fn == NULL || utest.haveIssue) continue; > + std::cout << utest.name << ":" << std::endl; > + (utest.fn)(); > + std::cout << std::endl; > + cl_kernel_destroy(); > + cl_buffer_destroy(); > + } > +} > + > +void UTest::listAllCases() > +{ > +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; > } > diff --git a/utests/utest.hpp b/utests/utest.hpp > index 93b3d87..d3a6a6f 100644 > --- a/utests/utest.hpp > +++ b/utests/utest.hpp > @@ -39,19 +39,23 @@ struct UTest > /*! Empty test */ > UTest(void); > /*! Build a new unit test and append it to the unit test list */ > - UTest(Function fn, const char *name); > + UTest(Function fn, const char *name, bool haveIssue = false); > /*! Function to execute */ > Function fn; > /*! Name of the test */ > const char *name; > + /*! Indicate whether current test cases has issue to be fixes */ > + bool haveIssue; > /*! 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 without known issue*/ > + static void runAllNoIssue(void); > /*! Run all the tests */ > static void runAll(void); > - /*! List all the tests */ > - static void listAll(void); > + /*! List all test cases */ > + static void listAllCases(void); > }; > > /*! Register a new unit test */ > @@ -62,6 +66,12 @@ struct UTest > static void __ANON__##FN##__(void) { UTEST_EXPECT_SUCCESS(FN()); } \ > static const UTest __##FN##__(__ANON__##FN##__, #FN); > > +/*! Register a test case which has issue to be fixed */ > +#define MAKE_UTEST_FROM_FUNCTION_WITH_ISSUE(FN) \ > + static void __ANON__##FN##__(void) { UTEST_EXPECT_SUCCESS(FN()); } \ > + static const UTest __##FN##__(__ANON__##FN##__, #FN, true); > + > + > /*! No assert is expected */ > #define UTEST_EXPECT_SUCCESS(EXPR) \ > do { \ > diff --git a/utests/utest_run.cpp b/utests/utest_run.cpp > index 86536d7..94fbbee 100644 > --- a/utests/utest_run.cpp > +++ b/utests/utest_run.cpp > @@ -25,26 +25,94 @@ > */ > #include "utest_helper.hpp" > #include "utest_exception.hpp" > -#include <string.h> > #include <iostream> > +#include <getopt.h> > + > +static const char *shortopts = "c:lanh"; > +struct option longopts[] = { > +{"casename", required_argument, NULL, 'c'}, > +{"list", no_argument, NULL, 'l'}, > +{"all", no_argument, NULL, 'a'}, > +{"allnoissue", no_argument, NULL, 'n'}, > +{"help", no_argument, NULL, 'h'}, > +{0, 0, 0, 0}, > +}; > + > +void usage() > +{ > + std::cout << "\ > +Usage:\n\ > + ./utest_run <option>\n\ > +\n\ > + option:\n\ > + -c <casename>: run sub-case named 'casename'\n\ > + -l : list all the available case name\n\ > + -a : run all test cases\n\ > + -n : run all test cases without known issue (default option)\n\ > + -h : display this usage\n\ > +\ > + "<< std::endl; > +} > > int main(int argc, char *argv[]) > { > - try { > - if (argc == 2 && !strcmp(argv[1], "--list")) { > - UTest::listAll(); > - return 0; > - } > > - cl_ocl_init(); > - if (argc >= 2) > - for (int i = 1; i < argc; ++i) > - UTest::run(argv[i]); > - else > - UTest::runAll(); > - cl_ocl_destroy(); > - } catch (Exception e) { > - std::cout << " " << e.what() << " [SUCCESS]" << std::endl; > + int c = 0; > + cl_ocl_init(); > + > + c = getopt_long (argc, argv, shortopts, longopts, NULL); > + > + if (argc == 1) > + c = 'n'; > + if (argc == 2 && c < 1 ){ > + c = 'c'; > + optarg = argv[1]; > } > + > + { > + switch (c) > + { > + case 'c': > + try { > + UTest::run(optarg); > + } > + catch (Exception e){ > + std::cout << " " << e.what() << " [SUCCESS]" << std::endl; > + } > + > + break; > + > + case 'l': > + UTest::listAllCases(); > + break; > + > + case 'a': > + try { > + UTest::runAll(); > + } > + catch (Exception e){ > + std::cout << " " << e.what() << " [SUCCESS]" << std::endl; > + } > + > + break; > + > + case 'n': > + try { > + UTest::runAllNoIssue(); > + } > + catch (Exception e){ > + std::cout << " " << e.what() << " [SUCCESS]" << std::endl; > + } > + > + break; > + > + case 'h': > + default: > + usage(); > + exit(1); > + } > + } while ((c = getopt_long (argc, argv, shortopts, longopts, NULL)) != -1) > + > + cl_ocl_destroy(); > } > > -- > 1.7.6.4 > > _______________________________________________ > Beignet mailing list > [email protected] > http://lists.freedesktop.org/mailman/listinfo/beignet _______________________________________________ Beignet mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/beignet
