[Beignet] [PATCH] Rewrite the function main, adding the arguments parse.

Yi Sun yi.sun at intel.com
Fri May 17 01:06:06 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..e841347 100644
--- a/utests/utest_run.cpp
+++ b/utests/utest_run.cpp
@@ -26,19 +26,52 @@
 #include "utest_helper.hpp"
 #include "utest_exception.hpp"
 #include <iostream>
+#include <getopt.h>
+
+static const char *shortopts = "n:l";
+struct option longopts[] = {
+{"name", required_argument, NULL, 'n'},
+{"list", no_argument, NULL, 'l'},
+{0, 0, 0, 0},
+};
+
 
 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();
-    cl_ocl_destroy();
-  } catch (Exception e) {
-      std::cout << "  " << e.what() << "    [SUCCESS]" << std::endl;
-  }
+
+    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;
+        }
+    }
+
+	cl_ocl_destroy();
 }
 
-- 
1.7.6.4



More information about the Beignet mailing list