[Beignet] [PATCH v2] utest_run: Rewrite the function main, adding the arguments parse.
Yi Sun
yi.sun at intel.com
Mon May 20 00:14:55 PDT 2013
Add three arguments:
-n <casename> : run a single case.
-a : run all sub cases.
-l : list all sub cases name.
Signed-off-by: Yi Sun <yi.sun at intel.com>
diff --git a/utests/utest.cpp b/utests/utest.cpp
index fc3467e..193e931 100644
--- a/utests/utest.cpp
+++ b/utests/utest.cpp
@@ -76,3 +76,13 @@ void UTest::runAll(void) {
}
}
+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 338a4dc..5487911 100644
--- a/utests/utest.hpp
+++ b/utests/utest.hpp
@@ -50,6 +50,8 @@ struct UTest
static void run(const char *name);
/*! Run all the tests */
static void runAll(void);
+ /* List all the sub cases name*/
+ static void listAllCases(void);
};
/*! Register a new unit test */
diff --git a/utests/utest_run.cpp b/utests/utest_run.cpp
index e577b7b..3974bbb 100644
--- a/utests/utest_run.cpp
+++ b/utests/utest_run.cpp
@@ -26,19 +26,67 @@
#include "utest_helper.hpp"
#include "utest_exception.hpp"
#include <iostream>
+#include <getopt.h>
+
+static const char *shortopts = "n:la";
+struct option longopts[] = {
+{"name", required_argument, NULL, 'n'},
+{"list", no_argument, NULL, 'l'},
+{0, 0, 0, 0},
+};
+
+void usage()
+{
+ std::cout << "\
+Usage:\n\
+ ./utest_run <option>\n\
+\n\
+ option:\n\
+ -n <casename>: run sub-case named 'casename'\n\
+ -l : list all the available case name\n\
+ -a : run all test cases\n\
+\
+ "<< std::endl;
+}
int main(int argc, char *argv[])
{
- try {
+
+ int c;
cl_ocl_init();
- if (argc >= 2)
- for (int i = 1; i < argc; ++i)
- UTest::run(argv[i]);
- else
- UTest::runAll();
+
+ while ((c = getopt_long (argc, argv, shortopts, longopts, NULL)) != -1)
+ {
+ switch (c)
+ {
+ case 'n':
+ 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;
+ default: usage();
+ exit(1);
+ }
+ }
+
cl_ocl_destroy();
- } catch (Exception e) {
- std::cout << " " << e.what() << " [SUCCESS]" << std::endl;
- }
}
--
1.7.6.4
More information about the Beignet
mailing list