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

zhigang gong zhigang.gong at gmail.com
Wed May 22 20:29:54 PDT 2013


Hi,

Just one minor comment, could you keep the single case running mode the
same as before?
I think that will be more convenient for the developer.

On Mon, May 20, 2013 at 3:14 PM, Yi Sun <yi.sun at intel.com> wrote:

> 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
>
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/beignet/attachments/20130523/3dd1667f/attachment.html>


More information about the Beignet mailing list