diff --git a/ci/compare_results.py b/ci/compare_results.py index 288c4c380d..0e6246025f 100644 --- a/ci/compare_results.py +++ b/ci/compare_results.py @@ -73,6 +73,7 @@ def process_all_results(results_dir, golden_data): cmd = os.path.basename(data.get("cmd")) results = data.get("results", {}) + args = data.get("args", "") if not cmd: print(f"File {result_file} is missing the 'cmd' key. Skipping.") @@ -84,8 +85,13 @@ def process_all_results(results_dir, golden_data): has_error = True continue + if args not in golden_data[cmd]: + missing_refs.append(f"args '{args}' not found in golden reference for cmd '{cmd}'.") + has_error = True + continue + # Check the specific results against the reference - subset_error = compare_test_subset(cmd, results, golden_data[cmd], differences, missing_refs) + subset_error = compare_test_subset(cmd, results, golden_data[cmd][args], differences, missing_refs) if subset_error: has_error = True diff --git a/ci/pocl/golden.json b/ci/pocl/golden.json index 0187f311d8..6df4bb4a3a 100644 --- a/ci/pocl/golden.json +++ b/ci/pocl/golden.json @@ -1,9 +1,131 @@ { + "test_bruteforce": { + "--wimpy -1": { + "math_edge_cases": "fail", + "acos": "pass", + "acosh": "fail", + "acospi": "fail", + "asin": "pass", + "asinh": "fail", + "asinpi": "fail", + "atan": "pass", + "atanh": "fail", + "atanpi": "fail", + "atan2": "fail", + "atan2pi": "fail", + "cbrt": "fail", + "ceil": "pass", + "copysign": "pass", + "cos": "pass", + "cosh": "pass", + "cospi": "fail", + "exp": "pass", + "exp2": "pass", + "exp10": "pass", + "expm1": "fail", + "fabs": "pass", + "fdim": "fail", + "floor": "pass", + "fma": "pass", + "fmax": "pass", + "fmin": "pass", + "fmod": "pass", + "fract": "fail", + "frexp": "pass", + "hypot": "fail", + "ilogb": "fail", + "isequal": "pass", + "isfinite": "pass", + "isgreater": "pass", + "isgreaterequal": "pass", + "isinf": "pass", + "isless": "pass", + "islessequal": "pass", + "islessgreater": "pass", + "isnan": "pass", + "isnormal": "pass", + "isnotequal": "pass", + "isordered": "pass", + "isunordered": "pass", + "ldexp": "fail", + "lgamma": "fail", + "lgamma_r": "fail", + "log": "fail", + "log2": "pass", + "log10": "pass", + "log1p": "fail", + "logb": "fail", + "mad": "pass", + "maxmag": "pass", + "minmag": "pass", + "modf": "fail", + "nan": "pass", + "nextafter": "fail", + "pow": "pass", + "pown": "fail", + "powr": "fail", + "remainder": "fail", + "remquo": "fail", + "rint": "pass", + "rootn": "fail", + "round": "pass", + "rsqrt": "pass", + "signbit": "pass", + "sin": "pass", + "sincos": "fail", + "sinh": "pass", + "sinpi": "fail", + "sqrt": "pass", + "sqrt_cr": "pass", + "tan": "pass", + "tanh": "pass", + "tanpi": "fail", + "tgamma": "fail", + "trunc": "pass", + "half_cos": "pass", + "half_divide": "pass", + "half_exp": "pass", + "half_exp2": "pass", + "half_exp10": "pass", + "half_log": "pass", + "half_log2": "pass", + "half_log10": "pass", + "half_powr": "pass", + "half_recip": "pass", + "half_rsqrt": "pass", + "half_sin": "pass", + "half_sqrt": "pass", + "half_tan": "pass", + "add": "pass", + "subtract": "pass", + "negation": "pass", + "reciprocal": "pass", + "divide": "pass", + "divide_cr": "pass", + "multiply": "pass", + "assignment": "pass", + "not": "pass", + "erf": "fail", + "erfc": "fail" + } + }, + "test_cl_copy_images": { + "--num-worker-threads 2 small_images": { + "1D": "pass" + } + }, "test_computeinfo": { - "computeinfo": "pass", - "device_uuid": "skip", - "extended_versioning": "pass", - "conformance_version": "pass", - "pci_bus_info": "skip" + "": { + "computeinfo": "pass", + "device_uuid": "skip", + "extended_versioning": "pass", + "conformance_version": "pass", + "pci_bus_info": "skip" + } + }, + "test_image_streams": { + "--num-worker-threads 2 CL_FILTER_NEAREST CL_R": { + "1D": "fail" + } } } diff --git a/test_common/harness/parseParameters.cpp b/test_common/harness/parseParameters.cpp index 97aedb7ccd..b210987366 100644 --- a/test_common/harness/parseParameters.cpp +++ b/test_common/harness/parseParameters.cpp @@ -91,43 +91,38 @@ For spir-v mode only: "\n"); } -int parseCustomParam(int argc, const char *argv[], const char *ignore) +int parseCommonParamAndGetRemovedArgs(int argc, const char *argv[], + std::vector &removed_args, + bool &help) { int delArg = 0; + help = false; for (int i = 1; i < argc; i++) { - if (ignore != 0) - { - // skip parameters that require special/different treatment in - // application (generic interpretation and parameter removal will - // not be performed) - const char *ptr = strstr(ignore, argv[i]); - if (ptr != 0 && (ptr == ignore || ptr[-1] == ' ') - && // first on list or ' ' before - (ptr[strlen(argv[i])] == 0 - || ptr[strlen(argv[i])] == ' ')) // last on list or ' ' after - continue; - } - delArg = 0; size_t i_object_length = strlen("--invalid-object-scenarios="); if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - // Note: we don't increment delArg to delete this argument, - // to allow the caller's argument parsing routine to see the - // option and print its own help. - helpInfo(); + delArg++; + if (!help) + { + help = true; + removed_args.push_back("--help"); + helpInfo(); + } } else if (!strcmp(argv[i], "--list") || !strcmp(argv[i], "-list")) { delArg++; + removed_args.push_back(argv[i]); gListTests = true; } else if (!strcmp(argv[i], "--wimpy") || !strcmp(argv[i], "-w")) { delArg++; + removed_args.push_back("--wimpy"); gWimpyMode = true; } else if (!strcmp(argv[i], "--compilation-mode")) @@ -163,6 +158,7 @@ int parseCustomParam(int argc, const char *argv[], const char *ignore) " --compilation-mode \n"); return -1; } + removed_args.push_back(std::string(argv[i]) + " " + argv[i + 1]); } else if (!strcmp(argv[i], "--num-worker-threads")) { @@ -180,6 +176,7 @@ int parseCustomParam(int argc, const char *argv[], const char *ignore) "A parameter to --num-worker-threads must be provided!\n"); return -1; } + removed_args.push_back(std::string(argv[i]) + " " + argv[i + 1]); } else if (!strcmp(argv[i], "--compilation-cache-mode")) { @@ -221,6 +218,7 @@ int parseCustomParam(int argc, const char *argv[], const char *ignore) "\n"); return -1; } + removed_args.push_back(std::string(argv[i]) + " " + argv[i + 1]); } else if (!strcmp(argv[i], "--compilation-cache-path")) { @@ -236,6 +234,7 @@ int parseCustomParam(int argc, const char *argv[], const char *ignore) "specified.\n"); return -1; } + removed_args.push_back(std::string(argv[i]) + " " + argv[i + 1]); } else if (!strcmp(argv[i], "--compilation-program")) { @@ -251,10 +250,12 @@ int parseCustomParam(int argc, const char *argv[], const char *ignore) "specified.\n"); return -1; } + removed_args.push_back(std::string(argv[i]) + " " + argv[i + 1]); } else if (!strcmp(argv[i], "--disable-spirv-validation")) { delArg++; + removed_args.push_back(argv[i]); gDisableSPIRVValidation = true; } else if (!strcmp(argv[i], "--spirv-validator")) @@ -271,6 +272,7 @@ int parseCustomParam(int argc, const char *argv[], const char *ignore) "specified.\n"); return -1; } + removed_args.push_back(std::string(argv[i]) + " " + argv[i + 1]); } else if (!strncmp(argv[i], "--invalid-object-scenarios=", i_object_length)) @@ -297,6 +299,7 @@ int parseCustomParam(int argc, const char *argv[], const char *ignore) "not specified.\n"); return -1; } + removed_args.push_back(argv[i]); } // cleaning parameters from argv tab @@ -317,6 +320,13 @@ int parseCustomParam(int argc, const char *argv[], const char *ignore) return argc; } +int parseCommonParam(int argc, const char *argv[]) +{ + std::vector unused1; + bool unused2; + return parseCommonParamAndGetRemovedArgs(argc, argv, unused1, unused2); +} + bool is_power_of_two(int number) { return number && !(number & (number - 1)); } extern void parseWimpyReductionFactor(const char *&arg, diff --git a/test_common/harness/parseParameters.h b/test_common/harness/parseParameters.h index ef8a7cb6b3..7ea26a8f94 100644 --- a/test_common/harness/parseParameters.h +++ b/test_common/harness/parseParameters.h @@ -18,6 +18,7 @@ #include "compat.h" #include +#include enum CompilationMode { @@ -43,8 +44,11 @@ extern std::string gSPIRVValidator; extern bool gListTests; extern bool gWimpyMode; -extern int parseCustomParam(int argc, const char *argv[], - const char *ignore = 0); +extern int +parseCommonParamAndGetRemovedArgs(int argc, const char *argv[], + std::vector &removed_args, + bool &help); +extern int parseCommonParam(int argc, const char *argv[]); extern void parseWimpyReductionFactor(const char *&arg, int &wimpyReductionFactor); diff --git a/test_common/harness/testHarness.cpp b/test_common/harness/testHarness.cpp index 92729c4966..f75bab927c 100644 --- a/test_common/harness/testHarness.cpp +++ b/test_common/harness/testHarness.cpp @@ -89,7 +89,8 @@ test_registry &test_registry::getInstance() return instance; } -static int saveResultsToJson(const char *suiteName, test_definition testList[], +static int saveResultsToJson(const char *suiteName, const char *args, + test_definition testList[], unsigned char selectedTestList[], test_status resultTestList[], int testNum) { @@ -128,6 +129,7 @@ static int saveResultsToJson(const char *suiteName, test_definition testList[], fprintf(file, "{\n"); fprintf(file, "\t\"cmd\": \"%s\",\n", suiteName); + fprintf(file, "\t\"args\": \"%s\",\n", args); fprintf(file, "\t\"results\": {\n"); for (int i = 0; i < testNum; ++i) @@ -152,6 +154,17 @@ static int saveResultsToJson(const char *suiteName, test_definition testList[], return ret; } +int runTestHarnessWithCheck(int argc, const char *argv[], int testNum, + test_definition testList[], + int forceNoContextCreation, + cl_command_queue_properties queueProps, + DeviceCheckFn deviceCheckFn) +{ + return runTestHarnessWithCheckAndParse(argc, argv, testNum, testList, + forceNoContextCreation, queueProps, + deviceCheckFn, NULL); +} + int runTestHarness(int argc, const char *argv[], int testNum, test_definition testList[], int forceNoContextCreation, cl_command_queue_properties queueProps) @@ -160,14 +173,20 @@ int runTestHarness(int argc, const char *argv[], int testNum, forceNoContextCreation, queueProps, NULL); } -int suite_did_not_pass_init(const char *suiteName, test_status status, - int testNum, test_definition testList[]) +int suite_did_not_pass_init(const char *suiteName, const char *args, + test_status status, int testNum, + test_definition testList[]) { + if (status == TEST_SKIPPED_ITSELF) + { + status = TEST_SKIP; + } std::vector selectedTestList(testNum, 1); std::vector resultTestList(testNum, status); - int ret = saveResultsToJson(suiteName, testList, selectedTestList.data(), - resultTestList.data(), testNum); + int ret = + saveResultsToJson(suiteName, args, testList, selectedTestList.data(), + resultTestList.data(), testNum); log_info("Test %s while initialization\n", status == TEST_SKIP ? "skipped" : "failed"); @@ -191,6 +210,30 @@ void version_expected_info(const char *test_name, const char *api_name, test_name, api_name, expected_version, api_name, device_version); } +void update_argc_argv_from_args_list(std::vector &argList, + int &argc, const char *argv[]) +{ + argc = 0; + for (auto arg : argList) + { + argv[argc++] = arg; + } +} + +static std::string removed_args_to_string(std::vector &args) +{ + std::sort(args.begin(), args.end()); + std::string result; + for (auto &arg : args) + { + result += arg + " "; + } + if (!result.empty()) + { + result.erase(result.size() - 1); + } + return result; +} static void list_tests(int testNum, test_definition testList[]) { std::set names; @@ -203,11 +246,12 @@ static void list_tests(int testNum, test_definition testList[]) log_info("\t%s\n", name.c_str()); } } -int runTestHarnessWithCheck(int argc, const char *argv[], int testNum, - test_definition testList[], - int forceNoContextCreation, - cl_command_queue_properties queueProps, - DeviceCheckFn deviceCheckFn) +int runTestHarnessWithCheckAndParse(int argc, const char *argv[], int testNum, + test_definition testList[], + int forceNoContextCreation, + cl_command_queue_properties queueProps, + DeviceCheckFn deviceCheckFn, + ParseArgsFn parseArgsFn) { test_start(); @@ -224,6 +268,7 @@ int runTestHarnessWithCheck(int argc, const char *argv[], int testNum, int err, ret; char *endPtr; int based_on_env_var = 0; + std::vector removed_args; /* Check for environment variable to set device type */ @@ -286,7 +331,8 @@ int runTestHarnessWithCheck(int argc, const char *argv[], int testNum, /* Process the command line arguments */ - argc = parseCustomParam(argc, argv); + bool help; + argc = parseCommonParamAndGetRemovedArgs(argc, argv, removed_args, help); if (argc == -1) { return EXIT_FAILURE; @@ -298,23 +344,21 @@ int runTestHarnessWithCheck(int argc, const char *argv[], int testNum, return EXIT_SUCCESS; } - gWimpyMode |= (getenv("CL_WIMPY_MODE") != nullptr); - if (gWimpyMode) + const char *suiteName = argv[0]; + std::string help_description; + if (parseArgsFn != NULL) { - log_info("\n"); - log_info("**************************\n"); - log_info("*** Wimpy mode enabled ***\n"); - log_info("**************************\n"); - log_info("\n"); + help |= (parseArgsFn(argc, argv, removed_args, help_description) + != TEST_PASS); } - if ((argc > 1) && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) + if (help) { char *fileName = getenv("CL_CONFORMANCE_RESULTS_FILENAME"); log_info( - "Usage: %s [*] [pid] [id] []\n", - argv[0]); + "Usage: %s %s[*] [pid] [id] []\n", + argv[0], help_description.empty() ? "" : "[options] "); log_info("\t\tOne or more of: (wildcard character '*') " "(default *)\n"); log_info("\tpid\tIndicates platform at index should be used " @@ -323,6 +367,11 @@ int runTestHarnessWithCheck(int argc, const char *argv[], int testNum, "(default 0).\n"); log_info("\t\tall|cpu|gpu|accelerator| " "(default CL_DEVICE_TYPE_DEFAULT)\n"); + if (!help_description.empty()) + { + log_info("Options:\n"); + log_info("%s", help_description.c_str()); + } log_info("\n"); log_info("\tNOTE: You may pass environment variable " "CL_CONFORMANCE_RESULTS_FILENAME (currently '%s')\n", @@ -337,6 +386,17 @@ int runTestHarnessWithCheck(int argc, const char *argv[], int testNum, return EXIT_SUCCESS; } + gWimpyMode |= (getenv("CL_WIMPY_MODE") != nullptr); + if (gWimpyMode) + { + log_info("\n"); + log_info("**************************\n"); + log_info("*** !! WARNING !! ***\n"); + log_info("*** Wimpy mode enabled ***\n"); + log_info("**************************\n"); + log_info("\n"); + } + /* How are we supposed to seed the random # generators? */ if (argc > 1 && strcmp(argv[argc - 1], "randomize") == 0) { @@ -618,25 +678,15 @@ int runTestHarnessWithCheck(int argc, const char *argv[], int testNum, log_error("Invalid device address bit size returned by device.\n"); return EXIT_FAILURE; } - const char *suiteName = argv[0]; + if (gCompilationMode == kSpir_v) { test_status spirv_readiness = check_spirv_compilation_readiness(device); if (spirv_readiness != TEST_PASS) { - switch (spirv_readiness) - { - case TEST_PASS: break; - case TEST_FAIL: - return suite_did_not_pass_init(suiteName, TEST_FAIL, - testNum, testList); - case TEST_SKIP: - return suite_did_not_pass_init(suiteName, TEST_SKIP, - testNum, testList); - case TEST_SKIPPED_ITSELF: - return suite_did_not_pass_init(suiteName, TEST_SKIP, - testNum, testList); - } + auto args = removed_args_to_string(removed_args); + return suite_did_not_pass_init(suiteName, args.c_str(), + spirv_readiness, testNum, testList); } } @@ -644,18 +694,11 @@ int runTestHarnessWithCheck(int argc, const char *argv[], int testNum, if ((deviceCheckFn != NULL)) { test_status status = deviceCheckFn(device); - switch (status) + if (status != TEST_PASS) { - case TEST_PASS: break; - case TEST_FAIL: - return suite_did_not_pass_init(suiteName, TEST_FAIL, testNum, - testList); - case TEST_SKIP: - return suite_did_not_pass_init(suiteName, TEST_SKIP, testNum, - testList); - case TEST_SKIPPED_ITSELF: - return suite_did_not_pass_init(suiteName, TEST_SKIP, testNum, - testList); + auto args = removed_args_to_string(removed_args); + return suite_did_not_pass_init(suiteName, args.c_str(), status, + testNum, testList); } } @@ -679,8 +722,9 @@ int runTestHarnessWithCheck(int argc, const char *argv[], int testNum, test_harness_config config = { forceNoContextCreation, num_elements, queueProps, gNumWorkerThreads }; - int error = parseAndCallCommandLineTests(argc, argv, device, testNum, - testList, config); + auto args = removed_args_to_string(removed_args); + int error = parseAndCallCommandLineTests(argc, argv, args.c_str(), device, + testNum, testList, config); #if defined(__APPLE__) && defined(__arm__) // Restore the old FP mode before leaving. @@ -769,7 +813,7 @@ static void print_results(int failed, int count, const char *name) fflush(stdout); } -int parseAndCallCommandLineTests(int argc, const char *argv[], +int parseAndCallCommandLineTests(int argc, const char *argv[], const char *args, cl_device_id device, int testNum, test_definition testList[], const test_harness_config &config) @@ -823,7 +867,7 @@ int parseAndCallCommandLineTests(int argc, const char *argv[], print_results(gFailCount, gTestCount, "sub-test"); print_results(gTestsFailed, gTestsFailed + gTestsPassed, "test"); - ret = saveResultsToJson(argv[0], testList, selectedTestList, + ret = saveResultsToJson(argv[0], args, testList, selectedTestList, resultTestList.data(), testNum); if (std::any_of(resultTestList.begin(), resultTestList.end(), diff --git a/test_common/harness/testHarness.h b/test_common/harness/testHarness.h index 76fda76f28..cdd92a4f51 100644 --- a/test_common/harness/testHarness.h +++ b/test_common/harness/testHarness.h @@ -189,11 +189,25 @@ extern int runTestHarnessWithCheck(int argc, const char *argv[], int testNum, cl_command_queue_properties queueProps, DeviceCheckFn deviceCheckFn); +typedef test_status (*ParseArgsFn)(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help_description); + +void update_argc_argv_from_args_list(std::vector &argList, + int &argc, const char *argv[]); + +int runTestHarnessWithCheckAndParse(int argc, const char *argv[], int testNum, + test_definition testList[], + int forceNoContextCreation, + cl_command_queue_properties queueProps, + DeviceCheckFn deviceCheckFn, + ParseArgsFn parseArgsFn); + // The command line parser used by runTestHarness to break up parameters into // calls to callTestFunctions extern int parseAndCallCommandLineTests(int argc, const char *argv[], - cl_device_id device, int testNum, - test_definition testList[], + const char *args, cl_device_id device, + int testNum, test_definition testList[], const test_harness_config &config); // Call this function if you need to do all the setup work yourself, and just diff --git a/test_conformance/allocations/main.cpp b/test_conformance/allocations/main.cpp index b62c2a54c7..3030830dd7 100644 --- a/test_conformance/allocations/main.cpp +++ b/test_conformance/allocations/main.cpp @@ -19,7 +19,6 @@ #include "allocation_fill.h" #include "allocation_execute.h" #include "harness/testHarness.h" -#include "harness/parseParameters.h" #include typedef long long unsigned llu; @@ -42,8 +41,6 @@ cl_long g_global_mem_size; cl_uint checksum; -static void printUsage(const char *execName); - test_status init_cl(cl_device_id device) { int error; @@ -300,31 +297,36 @@ REGISTER_TEST(image2d_write_non_blocking) return doTest(device, context, queue, IMAGE_WRITE_NON_BLOCKING); } -int main(int argc, const char *argv[]) +static test_status parseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help) { char *endPtr; int r; - - argc = parseCustomParam(argc, argv); - if (argc == -1) - { - return 1; - } - - const char **argList = (const char **)calloc(argc, sizeof(char *)); - - if (NULL == argList) - { - log_error("Failed to allocate memory for argList array.\n"); - return 1; - } - - argList[0] = argv[0]; - size_t argCount = 1; - + std::vector kept_args; + + help = + R"( randomize - Uses random seed + single - Tests using a single allocation as large as possible + multiple - Tests using as many allocations as possible + numReps - Optional integer specifying the number of repetitions to run + and average the result (defaults to 1) + reduction% - Optional integer, followed by a % sign, that acts as a + multiplier for the target amount of memory. + Example: target amount of 512MB and a reduction of 75% will + result in a target of 384MB. + do_not_force_fill - Disable explicitly write data to all memory objects + after creating them. Without this, the kernel + execution can not verify its checksum. + do_not_execute - Disable executing a kernel that accesses all of the + memory objects. +)"; + + kept_args.push_back(argv[0]); // Parse arguments for (int i = 1; i < argc; i++) { + removed_args.push_back(argv[i]); if (strcmp(argv[i], "multiple") == 0) g_multiple_allocations = 1; else if (strcmp(argv[i], "single") == 0) @@ -354,57 +356,21 @@ int main(int argc, const char *argv[]) g_execute_kernel = 0; } - else if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) - { - printUsage(argv[0]); - free(argList); - return -1; - } - else { - argList[argCount] = argv[i]; - argCount++; + removed_args.pop_back(); + kept_args.push_back(argv[i]); } } - - int ret = runTestHarnessWithCheck( - argCount, argList, test_registry::getInstance().num_tests(), - test_registry::getInstance().definitions(), false, 0, init_cl); - - free(argList); - return ret; + update_argc_argv_from_args_list(kept_args, argc, argv); + return TEST_PASS; } -void printUsage(const char *execName) +int main(int argc, const char *argv[]) { - const char *p = strrchr(execName, '/'); - if (p != NULL) execName = p + 1; - - log_info("Usage: %s [options] [test_names]\n", execName); - log_info("Options:\n"); - log_info("\trandomize - Uses random seed\n"); - log_info( - "\tsingle - Tests using a single allocation as large as possible\n"); - log_info("\tmultiple - Tests using as many allocations as possible\n"); - log_info("\n"); - log_info("\tnumReps - Optional integer specifying the number of " - "repetitions to run and average the result (defaults to 1)\n"); - log_info("\treduction%% - Optional integer, followed by a %% sign, that " - "acts as a multiplier for the target amount of memory.\n"); - log_info("\t Example: target amount of 512MB and a reduction " - "of 75%% will result in a target of 384MB.\n"); - log_info("\n"); - log_info("\tdo_not_force_fill - Disable explicitly write data to all " - "memory objects after creating them.\n"); - log_info("\t Without this, the kernel execution can not " - "verify its checksum.\n"); - log_info("\tdo_not_execute - Disable executing a kernel that accesses all " - "of the memory objects.\n"); - log_info("\n"); - log_info("Test names (Allocation Types):\n"); - for (int i = 0; i < test_registry::getInstance().num_tests(); i++) - { - log_info("\t%s\n", test_registry::getInstance().definitions()[i].name); - } + int ret = runTestHarnessWithCheckAndParse( + argc, argv, test_registry::getInstance().num_tests(), + test_registry::getInstance().definitions(), false, 0, init_cl, + parseArgs); + return ret; } diff --git a/test_conformance/compiler/main.cpp b/test_conformance/compiler/main.cpp index 6ffa4871cb..cddabce71b 100644 --- a/test_conformance/compiler/main.cpp +++ b/test_conformance/compiler/main.cpp @@ -19,6 +19,7 @@ #include "harness/testHarness.h" #include "harness/stringHelpers.h" #include "harness/os_helpers.h" +#include "harness/parseParameters.h" std::string spvBinariesPath = "spirv_bin"; std::string spvIncludeTestDirectory = "includeTestDirectory"; @@ -29,93 +30,94 @@ const std::string spvIncludeTestDirectoryArg = "--include-test-directory"; const std::string spvSecondIncludeTestDirectoryArg = "--second-include-test-directory"; -void printUsage() +static test_status parseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help) { - log_info("Reading SPIR-V files from default '%s' path.\n", - spvBinariesPath.c_str()); - log_info("In case you want to set other directory use '%s' argument.\n", - spvBinariesPathArg.c_str()); -} - -int main(int argc, const char *argv[]) -{ - char const *sep = get_dir_sep(); - char const *exe_dir = get_exe_dir(); - - // Set default include directories - spvIncludeTestDirectory = - std::string(exe_dir) + sep + "includeTestDirectory"; - spvSecondIncludeTestDirectory = - std::string(exe_dir) + sep + "secondIncludeTestDirectory"; - - free((void *)sep); - free((void *)exe_dir); + help = " " + spvBinariesPathArg + + " - Set path to read SPIR-V files from (default: " + + spvBinariesPath + ")\n" + " " + spvIncludeTestDirectoryArg + + " - Set include test directory\n" + " " + + spvSecondIncludeTestDirectoryArg + + " - Set second include test directory\n"; bool modifiedSpvBinariesPath = false; - bool listTests = false; - for (int i = 0; i < argc; ++i) + std::vector argList; + argList.push_back(argv[0]); + + for (int i = 1; i < argc; ++i) { - int argsRemoveNum = 0; if (argv[i] == spvBinariesPathArg) { - if (i + 1 == argc) + if (i + 1 >= argc || argv[i + 1] == NULL) { log_error("Missing value for '%s' argument.\n", spvBinariesPathArg.c_str()); return TEST_FAIL; } - else - { - spvBinariesPath = std::string(argv[i + 1]); - argsRemoveNum += 2; - modifiedSpvBinariesPath = true; - } + spvBinariesPath = std::string(argv[i + 1]); + removed_args.push_back(std::string(argv[i]) + " " + argv[i + 1]); + modifiedSpvBinariesPath = true; + ++i; // skip the value } - if (argv[i] == spvIncludeTestDirectoryArg) + else if (argv[i] == spvIncludeTestDirectoryArg) { - if (i + 1 == argc) + if (i + 1 >= argc || argv[i + 1] == NULL) { log_error("Missing value for '%s' argument.\n", spvIncludeTestDirectoryArg.c_str()); return TEST_FAIL; } - else - { - spvIncludeTestDirectory = std::string(argv[i + 1]); - argsRemoveNum += 2; - } + spvIncludeTestDirectory = std::string(argv[i + 1]); + removed_args.push_back(std::string(argv[i]) + " " + argv[i + 1]); + ++i; } - if (argv[i] == spvSecondIncludeTestDirectoryArg) + else if (argv[i] == spvSecondIncludeTestDirectoryArg) { - if (i + 1 == argc) + if (i + 1 >= argc || argv[i + 1] == NULL) { log_error("Missing value for '%s' argument.\n", spvSecondIncludeTestDirectoryArg.c_str()); return TEST_FAIL; } - else - { - spvSecondIncludeTestDirectory = std::string(argv[i + 1]); - argsRemoveNum += 2; - } + spvSecondIncludeTestDirectory = std::string(argv[i + 1]); + removed_args.push_back(std::string(argv[i]) + " " + argv[i + 1]); + ++i; } - - if (argsRemoveNum > 0) + else { - for (int j = i; j < (argc - argsRemoveNum); ++j) - argv[j] = argv[j + argsRemoveNum]; - - argc -= argsRemoveNum; - --i; + argList.push_back(argv[i]); } - listTests |= (argv[i] == std::string("--list") - || argv[i] == std::string("-list")); } - if (modifiedSpvBinariesPath == false && !listTests) + + if (!modifiedSpvBinariesPath && !gListTests) { - printUsage(); + log_info("Reading SPIR-V files from default '%s' path.\n", + spvBinariesPath.c_str()); + log_info("In case you want to set other directory use '%s' argument.\n", + spvBinariesPathArg.c_str()); } - return runTestHarness(argc, argv, test_registry::getInstance().num_tests(), - test_registry::getInstance().definitions(), false, 0); + update_argc_argv_from_args_list(argList, argc, argv); + return TEST_PASS; +} + +int main(int argc, const char *argv[]) +{ + char const *sep = get_dir_sep(); + char const *exe_dir = get_exe_dir(); + + // Set default include directories + spvIncludeTestDirectory = + std::string(exe_dir) + sep + "includeTestDirectory"; + spvSecondIncludeTestDirectory = + std::string(exe_dir) + sep + "secondIncludeTestDirectory"; + + free((void *)sep); + free((void *)exe_dir); + + return runTestHarnessWithCheckAndParse( + argc, argv, test_registry::getInstance().num_tests(), + test_registry::getInstance().definitions(), false, 0, nullptr, + parseArgs); } diff --git a/test_conformance/computeinfo/main.cpp b/test_conformance/computeinfo/main.cpp index f09b712562..38594fa942 100644 --- a/test_conformance/computeinfo/main.cpp +++ b/test_conformance/computeinfo/main.cpp @@ -1410,36 +1410,36 @@ REGISTER_TEST(computeinfo) return total_errors; } -int main(int argc, const char** argv) +static test_status parseArgs(int& argc, const char* argv[], + std::vector& removed_args, + std::string& help) { - const char** argList = (const char**)calloc(argc, sizeof(char*)); - if (NULL == argList) - { - log_error("Failed to allocate memory for argList array.\n"); - return 1; - } + help = " -v Dump supported formats\n"; - argList[0] = argv[0]; - size_t argCount = 1; + std::vector argList; + argList.push_back(argv[0]); for (int i = 1; i < argc; i++) { - if (strcmp(argv[1], "-v") == 0) + if (strcmp(argv[i], "-v") == 0) { dump_supported_formats = 1; + removed_args.push_back(argv[i]); } else { - argList[argCount] = argv[i]; - argCount++; + argList.push_back(argv[i]); } } - int error = runTestHarness( - argCount, argList, test_registry::getInstance().num_tests(), - test_registry::getInstance().definitions(), true, 0); - - free(argList); + update_argc_argv_from_args_list(argList, argc, argv); + return TEST_PASS; +} - return error; +int main(int argc, const char* argv[]) +{ + return runTestHarnessWithCheckAndParse( + argc, argv, test_registry::getInstance().num_tests(), + test_registry::getInstance().definitions(), true, 0, nullptr, + parseArgs); } diff --git a/test_conformance/contractions/contractions.cpp b/test_conformance/contractions/contractions.cpp index b3f1098dc5..015315b9ca 100644 --- a/test_conformance/contractions/contractions.cpp +++ b/test_conformance/contractions/contractions.cpp @@ -36,7 +36,6 @@ #include "harness/rounding_mode.h" #include "harness/fpcontrol.h" #include "harness/testHarness.h" -#include "harness/parseParameters.h" #if defined( __APPLE__ ) #include #endif @@ -65,7 +64,6 @@ __thread fpu_control_t fpu_control = 0; #define MAXPATHLEN 2048 #endif -char appName[ MAXPATHLEN ] = ""; cl_context gContext = NULL; cl_command_queue gQueue = NULL; cl_program gProgram[5] = { NULL, NULL, NULL, NULL, NULL }; @@ -92,14 +90,12 @@ int *skipTest[8]; double *buf3_double, *buf4_double, *buf5_double, *buf6_double; double *correct_double[8]; -static const char **gArgList; -static size_t gArgCount; - #define BUFFER_SIZE (1024*1024) -static int ParseArgs( int argc, const char **argv ); -static void PrintUsage( void ); +static test_status ParseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help); test_status InitCL( cl_device_id device ); static void ReleaseCL( void ); static int RunTest( int testNumber ); @@ -252,20 +248,9 @@ REGISTER_TEST(contractions_double_7) { return RunTest_Double(7); } int main( int argc, const char **argv ) { - argc = parseCustomParam(argc, argv); - if (argc == -1) - { - return -1; - } - - int error = ParseArgs( argc, argv ); - - if( !error ) - { - error = runTestHarnessWithCheck( - gArgCount, gArgList, test_registry::getInstance().num_tests(), - test_registry::getInstance().definitions(), true, 0, InitCL); - } + int error = runTestHarnessWithCheckAndParse( + argc, argv, test_registry::getInstance().num_tests(), + test_registry::getInstance().definitions(), true, 0, InitCL, ParseArgs); if( gQueue ) { @@ -275,62 +260,26 @@ int main( int argc, const char **argv ) } ReleaseCL(); - free( gArgList ); return error; } - -static int ParseArgs( int argc, const char **argv ) +static test_status ParseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help) { - if (gListTests) - { - return 0; - } - - gArgList = (const char **)calloc( argc, sizeof( char*) ); - - if( NULL == gArgList ) - { - vlog_error( "Failed to allocate memory for argList\n" ); - return 1; - } + std::vector argList; + argList.push_back(argv[0]); - gArgList[0] = argv[0]; - gArgCount = 1; + help = + R"( -z Toggle FTZ mode (Section 6.5.3) for all functions. (Set by + device capabilities by default.) + -sNUMBER Set random seed. +)"; int length_of_seed = 0; - { // Extract the app name - strncpy(appName, argv[0], MAXPATHLEN - 1); - appName[MAXPATHLEN - 1] = '\0'; - -#if (defined( __APPLE__ ) || defined(__linux__) || defined(__MINGW32__)) - char baseName[MAXPATHLEN]; - char *base = NULL; - strncpy(baseName, argv[0], MAXPATHLEN - 1); - baseName[MAXPATHLEN - 1] = '\0'; - base = basename( baseName ); - if( NULL != base ) - { - strncpy(appName, base, sizeof(appName) - 1); - appName[ sizeof( appName ) -1 ] = '\0'; - } -#elif defined (_WIN32) - char fname[_MAX_FNAME + _MAX_EXT + 1]; - char ext[_MAX_EXT]; - - errno_t err = _splitpath_s( argv[0], NULL, 0, NULL, 0, - fname, _MAX_FNAME, ext, _MAX_EXT ); - if (err == 0) { // no error - strcat (fname, ext); //just cat them, size of frame can keep both - strncpy(appName, fname, sizeof(appName) - 1); - appName[ sizeof( appName ) -1 ] = '\0'; - } -#endif - } - for( int i = 1; i < argc; i++ ) { const char *arg = argv[i]; @@ -344,10 +293,6 @@ static int ParseArgs( int argc, const char **argv ) arg++; switch( *arg ) { - case 'h': - PrintUsage(); - return -1; - case 's': arg++; gSeed = atoi( arg ); @@ -363,35 +308,21 @@ static int ParseArgs( int argc, const char **argv ) default: vlog( " <-- unknown flag: %c (0x%2.2x)\n)", *arg, *arg ); - PrintUsage(); - return -1; + return TEST_FAIL; } } + removed_args.push_back(argv[i]); } else { - gArgList[gArgCount] = arg; - gArgCount++; + argList.push_back(argv[i]); } } + update_argc_argv_from_args_list(argList, argc, argv); PrintArch(); - return 0; -} - -static void PrintUsage( void ) -{ - vlog( "%s [-z]: \n", appName ); - vlog( "\tOptions:\n" ); - vlog( "\t\t-z\tToggle FTZ mode (Section 6.5.3) for all functions. (Set by device capabilities by default.)\n" ); - vlog( "\t\t-sNUMBER set random seed.\n"); - vlog( "\n" ); - vlog( "\tTest names:\n" ); - for (size_t i = 0; i < test_registry::getInstance().num_tests(); i++) - { - vlog("\t\t%s\n", test_registry::getInstance().definitions()[i].name); - } + return TEST_PASS; } const char *sizeNames[] = { "float", "float2", "float4", "float8", "float16" }; diff --git a/test_conformance/conversions/basic_test_conversions.cpp b/test_conformance/conversions/basic_test_conversions.cpp index 79333275f5..796ec99345 100644 --- a/test_conformance/conversions/basic_test_conversions.cpp +++ b/test_conformance/conversions/basic_test_conversions.cpp @@ -94,8 +94,7 @@ int vectorSizes[] = { 1, 1, 2, 3, 4, 8, 16 }; int gMinVectorSize = 0; int gMaxVectorSize = sizeof(vectorSizes) / sizeof(vectorSizes[0]); MTdata gMTdata; -const char **argList = NULL; -int argCount = 0; +std::vector argList; cl_half_rounding_mode DataInitInfo::halfRoundingMode = CL_HALF_RTE; @@ -403,7 +402,7 @@ cl_int CustomConversionsTest::Run() RoundingMode round; SaturationMode sat; - for (int i = 0; i < argCount; i++) + for (int i = 2; i < argList.size(); i++) { if (conv_test::GetTestCase(argList[i], &outType, &inType, &sat, &round)) { diff --git a/test_conformance/conversions/basic_test_conversions.h b/test_conformance/conversions/basic_test_conversions.h index 496ea7301f..abf7f230c0 100644 --- a/test_conformance/conversions/basic_test_conversions.h +++ b/test_conformance/conversions/basic_test_conversions.h @@ -95,8 +95,7 @@ extern void *gRef; extern void *gAllowZ; extern void *gOut[]; -extern const char **argList; -extern int argCount; +extern std::vector argList; extern const char *sizeNames[]; extern int vectorSizes[]; diff --git a/test_conformance/conversions/test_conversions.cpp b/test_conformance/conversions/test_conversions.cpp index 7a143a6b3d..b85ad9e5cd 100644 --- a/test_conformance/conversions/test_conversions.cpp +++ b/test_conformance/conversions/test_conversions.cpp @@ -68,8 +68,9 @@ roundingMode qcom_rm; #endif -static int ParseArgs(int argc, const char **argv); -static void PrintUsage(void); +static test_status ParseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help); test_status InitCL(cl_device_id device); @@ -88,13 +89,12 @@ size_t gTypeSizes[kTypeCount] = { sizeof(cl_double), sizeof(cl_ulong), sizeof(cl_long), }; -char appName[64] = "ctest"; int gMultithread = 1; REGISTER_TEST(conversions) { - if (argCount) + if (argList.size() > 2) { return MakeAndRunTest(device, context, queue, num_elements); @@ -109,51 +109,10 @@ REGISTER_TEST(conversions) int main(int argc, const char **argv) { - int error; - - argc = parseCustomParam(argc, argv); - if (gListTests) - { - for (unsigned dst = 0; dst < kTypeCount; dst++) - { - for (unsigned src = 0; src < kTypeCount; src++) - { - for (unsigned sat = 0; sat < 2; sat++) - { - // skip illegal saturated conversions to float type - if (gSaturationNames[sat] == std::string("_sat") - && (gTypeNames[dst] == std::string("float") - || gTypeNames[dst] == std::string("half") - || gTypeNames[dst] == std::string("double"))) - { - continue; - } - for (unsigned rnd = 0; rnd < kRoundingModeCount; rnd++) - { - vlog("\t%s\n", - (std::string(gTypeNames[dst]) - + gSaturationNames[sat] + gRoundingModeNames[rnd] - + "_" + gTypeNames[src]) - .c_str()); - } - } - } - } - return 0; - } - if (argc == -1) - { - return 1; - } - - if ((error = ParseArgs(argc, argv))) return error; - // Turn off sleep so our tests run to completion PreventSleep(); atexit(ResumeSleep); - if (!gMultithread) SetThreadCount(1); - #if defined(_MSC_VER) && defined(_M_IX86) // VS2005 (and probably others, since long double got deprecated) sets // the x87 to 53-bit precision. This causes problems with the tests @@ -164,19 +123,14 @@ int main(int argc, const char **argv) _controlfp_s(&ignored, _PC_64, _MCW_PC); #endif - vlog("===========================================================\n"); - vlog("Random seed: %u\n", gRandomSeed); - gMTdata = init_genrand(gRandomSeed); - - const char *arg[] = { argv[0] }; - int ret = runTestHarnessWithCheck( - 1, arg, test_registry::getInstance().num_tests(), - test_registry::getInstance().definitions(), true, 0, InitCL); + int ret = runTestHarnessWithCheckAndParse( + argc, argv, test_registry::getInstance().num_tests(), + test_registry::getInstance().definitions(), true, 0, InitCL, ParseArgs); free_mtdata(gMTdata); if (gQueue) { - error = clFinish(gQueue); + int error = clFinish(gQueue); if (error) vlog_error("clFinish failed: %d\n", error); } @@ -193,43 +147,73 @@ int main(int argc, const char **argv) } -static int ParseArgs(int argc, const char **argv) +static test_status ParseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help) { int i; - argList = (const char **)calloc(argc, sizeof(char *)); - argCount = 0; - - if (NULL == argList && argc > 1) return -1; - -#if (defined(__APPLE__) || defined(__linux__) || defined(__MINGW32__)) - { // Extract the app name - char baseName[MAXPATHLEN]; - strncpy(baseName, argv[0], MAXPATHLEN - 1); - baseName[sizeof(baseName) - 1] = '\0'; - char *base = basename(baseName); - if (NULL != base) - { - strncpy(appName, base, sizeof(appName) - 1); - appName[sizeof(appName) - 1] = '\0'; - } - } -#elif defined(_WIN32) + + help = R"( + -d Toggle testing of double precision. On by default if cl_khr_fp64 is enabled, ignored otherwise. + -l Toggle link check mode. When on, testing is skipped, and we just check to see that the kernels build. (Off by default.) + -m Toggle Multithreading. (On by default.) + -[2^n] Set wimpy reduction factor, recommended range of n is 1-12, default factor()" + + std::to_string(gWimpyReductionFactor) + R"() + -z Toggle flush to zero mode (Default: per device) + -# Test just vector size given by #, where # is an element of the set {1,2,3,4,8,16} + + You may also pass the number of the test on which to start. + A second number can be then passed to indicate how many tests to run + +Test names: + destFormat<_sat><_round>_sourceFormat + Possible format types are: + )"; + for (i = 0; i < kTypeCount; i++) help += std::string(gTypeNames[i]) + ", "; + help += R"( + Possible saturation values are: (empty) and _sat + Possible rounding values are: + (empty), )"; + for (i = 1; i < kRoundingModeCount; i++) + help += std::string(gRoundingModeNames[i]) + ", "; + help += R"( + Examples: + ulong_short converts short to ulong + char_sat_rte_float converts float to char with saturated clipping in round to nearest rounding mode +)"; + + if (gListTests) { - char fname[_MAX_FNAME + _MAX_EXT + 1]; - char ext[_MAX_EXT]; - - errno_t err = _splitpath_s(argv[0], NULL, 0, NULL, 0, fname, _MAX_FNAME, - ext, _MAX_EXT); - if (err == 0) - { // no error - strcat(fname, ext); // just cat them, size of frame can keep both - strncpy(appName, fname, sizeof(appName) - 1); - appName[sizeof(appName) - 1] = '\0'; + for (unsigned dst = 0; dst < kTypeCount; dst++) + { + for (unsigned src = 0; src < kTypeCount; src++) + { + for (unsigned sat = 0; sat < 2; sat++) + { + // skip illegal saturated conversions to float type + if (gSaturationNames[sat] == std::string("_sat") + && (gTypeNames[dst] == std::string("float") + || gTypeNames[dst] == std::string("half") + || gTypeNames[dst] == std::string("double"))) + { + continue; + } + for (unsigned rnd = 0; rnd < kRoundingModeCount; rnd++) + { + vlog("\t%s\n", + (std::string(gTypeNames[dst]) + + gSaturationNames[sat] + gRoundingModeNames[rnd] + + "_" + gTypeNames[src]) + .c_str()); + } + } + } } + return TEST_PASS; } -#endif - vlog("\n%s", appName); + argList.push_back(argv[0]); + argList.push_back("all"); for (i = 1; i < argc; i++) { const char *arg = argv[i]; @@ -290,11 +274,11 @@ static int ParseArgs(int argc, const char **argv) default: vlog(" <-- unknown flag: %c (0x%2.2x)\n)", *arg, *arg); - PrintUsage(); - return -1; + return TEST_FAIL; } arg++; } + removed_args.push_back(argv[i]); } else { @@ -309,11 +293,12 @@ static int ParseArgs(int argc, const char **argv) } else { - argList[argCount] = arg; - argCount++; + removed_args.push_back(argv[i]); + argList.push_back(arg); } } } + update_argc_argv_from_args_list(argList, argc, argv); vlog("\n"); @@ -329,42 +314,13 @@ static int ParseArgs(int argc, const char **argv) gWimpyReductionFactor); } - return 0; -} + vlog("===========================================================\n"); + vlog("Random seed: %u\n", gRandomSeed); + gMTdata = init_genrand(gRandomSeed); + if (!gMultithread) SetThreadCount(1); -static void PrintUsage(void) -{ - int i; - vlog("%s [-wz#]: \n", appName); - vlog("\ttest names:\n"); - vlog("\t\tdestFormat<_sat><_round>_sourceFormat\n"); - vlog("\t\t\tPossible format types are:\n\t\t\t\t"); - for (i = 0; i < kTypeCount; i++) vlog("%s, ", gTypeNames[i]); - vlog("\n\n\t\t\tPossible saturation values are: (empty) and _sat\n"); - vlog("\t\t\tPossible rounding values are:\n\t\t\t\t(empty), "); - for (i = 1; i < kRoundingModeCount; i++) - vlog("%s, ", gRoundingModeNames[i]); - vlog("\n\t\t\tExamples:\n"); - vlog("\t\t\t\tulong_short converts short to ulong\n"); - vlog("\t\t\t\tchar_sat_rte_float converts float to char with saturated " - "clipping in round to nearest rounding mode\n\n"); - vlog("\toptions:\n"); - vlog("\t\t-d\tToggle testing of double precision. On by default if " - "cl_khr_fp64 is enabled, ignored otherwise.\n"); - vlog("\t\t-l\tToggle link check mode. When on, testing is skipped, and we " - "just check to see that the kernels build. (Off by default.)\n"); - vlog("\t\t-m\tToggle Multithreading. (On by default.)\n"); - vlog(" \t\t-[2^n]\tSet wimpy reduction factor, recommended range of n is " - "1-12, default factor(%u)\n", - gWimpyReductionFactor); - vlog("\t\t-z\tToggle flush to zero mode (Default: per device)\n"); - vlog("\t\t-#\tTest just vector size given by #, where # is an element of " - "the set {1,2,3,4,8,16}\n"); - vlog("\n"); - vlog( - "You may also pass the number of the test on which to start.\nA second " - "number can be then passed to indicate how many tests to run\n\n"); + return TEST_PASS; } diff --git a/test_conformance/d3d11/main.cpp b/test_conformance/d3d11/main.cpp index 29166adc60..53eb43d1a2 100644 --- a/test_conformance/d3d11/main.cpp +++ b/test_conformance/d3d11/main.cpp @@ -31,7 +31,7 @@ int main(int argc, const char* argv[]) setvbuf(stdout, nullptr, _IONBF, 0); setvbuf(stderr, nullptr, _IONBF, 0); - argc = parseCustomParam(argc, argv); + argc = parseCommonParam(argc, argv); // get the platforms to test result = clGetPlatformIDs(1, &platform, NULL); NonTestRequire(result == CL_SUCCESS, "Failed to get any platforms."); diff --git a/test_conformance/device_execution/main.cpp b/test_conformance/device_execution/main.cpp index 81c198029a..35633b0bea 100644 --- a/test_conformance/device_execution/main.cpp +++ b/test_conformance/device_execution/main.cpp @@ -21,7 +21,6 @@ #endif #include "harness/testHarness.h" -#include "harness/parseParameters.h" #include "utils.h" std::string gKernelName; @@ -55,32 +54,38 @@ test_status InitCL(cl_device_id device) { return TEST_PASS; } -int main(int argc, const char *argv[]) +static test_status ParseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help) { - argc = parseCustomParam(argc, argv); + std::vector argList; + for (int i = 0; i < argc; ++i) + { + if (strcmp(argv[i], "-kernelName") == 0) + { + if ((i + 1) > argc || argv[i + 1] == NULL) + { + vlog("Missing value for -kernelName argument\n"); + return TEST_FAIL; + } - for (int i = 0; i < argc; ++i) { - int argsRemoveNum = 0; - if ( strcmp(argv[i], "-kernelName") == 0 ) { - if((i + 1) > argc && argv[i + 1] == NULL) { - vlog( "Missing value for -kernelName argument\n"); - return -1; + gKernelName = std::string(argv[i + 1]); + removed_args.push_back(std::string(argv[i]) + " " + argv[i + 1]); + } + else + { + argList.push_back(argv[i]); } - - gKernelName = std::string(argv[i + 1]); - argsRemoveNum += 2; - } - - if (argsRemoveNum > 0) { - for (int j = i; j < (argc - argsRemoveNum); ++j) - argv[j] = argv[j + argsRemoveNum]; - - argc -= argsRemoveNum; - --i; - } } + update_argc_argv_from_args_list(argList, argc, argv); - return runTestHarnessWithCheck( + return TEST_PASS; +} + +int main(int argc, const char *argv[]) +{ + return runTestHarnessWithCheckAndParse( argc, argv, test_registry::getInstance().num_tests(), - test_registry::getInstance().definitions(), false, 0, InitCL); + test_registry::getInstance().definitions(), false, 0, InitCL, + ParseArgs); } diff --git a/test_conformance/extensions/cl_khr_dx9_media_sharing/main.cpp b/test_conformance/extensions/cl_khr_dx9_media_sharing/main.cpp index cc4b93777c..65bd295c9f 100644 --- a/test_conformance/extensions/cl_khr_dx9_media_sharing/main.cpp +++ b/test_conformance/extensions/cl_khr_dx9_media_sharing/main.cpp @@ -144,8 +144,13 @@ bool DetectPlatformAndDevice() return true; } -bool CmdlineParse(int argc, const char *argv[]) +static test_status parseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help) { + help = " sw, software - Set CDeviceWrapper::AccelerationType to " + "ACCELERATION_SW\n"; + char *env_mode = getenv("CL_DEVICE_TYPE"); if (env_mode != NULL) { @@ -166,48 +171,55 @@ bool CmdlineParse(int argc, const char *argv[]) log_error("Unknown CL_DEVICE_TYPE env variable setting: " "%s.\nAborting...\n", env_mode); - return false; + return TEST_FAIL; } } - for (int i = 0; i < argc; ++i) + std::vector argList; + argList.push_back(argv[0]); + + for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "gpu") == 0 || strcmp(argv[i], "CL_DEVICE_TYPE_GPU") == 0) { gDeviceTypeSelected = CL_DEVICE_TYPE_GPU; - continue; + argList.push_back(argv[i]); // Retain for standard test harness } else if (strcmp(argv[i], "cpu") == 0 || strcmp(argv[i], "CL_DEVICE_TYPE_CPU") == 0) { gDeviceTypeSelected = CL_DEVICE_TYPE_CPU; - continue; + argList.push_back(argv[i]); // Retain for standard test harness } else if (strcmp(argv[i], "accelerator") == 0 || strcmp(argv[i], "CL_DEVICE_TYPE_ACCELERATOR") == 0) { gDeviceTypeSelected = CL_DEVICE_TYPE_ACCELERATOR; - continue; + argList.push_back(argv[i]); // Retain for standard test harness } else if (strcmp(argv[i], "CL_DEVICE_TYPE_DEFAULT") == 0) { gDeviceTypeSelected = CL_DEVICE_TYPE_DEFAULT; - continue; + argList.push_back(argv[i]); // Retain for standard test harness } else if (strcmp(argv[i], "sw") == 0 || strcmp(argv[i], "software") == 0) { CDeviceWrapper::AccelerationType(CDeviceWrapper::ACCELERATION_SW); + removed_args.push_back(argv[i]); + } + else + { + argList.push_back(argv[i]); } } - return true; + update_argc_argv_from_args_list(argList, argc, argv); + return TEST_PASS; } -int main(int argc, const char *argv[]) +static test_status checkMediaSurfaceSharingExtension(cl_device_id device) { - if (!CmdlineParse(argc, argv)) return TEST_FAIL; - if (!DetectPlatformAndDevice()) { log_info("Test was not run, because the media surface sharing " @@ -217,6 +229,13 @@ int main(int argc, const char *argv[]) if (!MediaSurfaceSharingExtensionInit()) return TEST_FAIL; - return runTestHarness(argc, argv, test_registry::getInstance().num_tests(), - test_registry::getInstance().definitions(), true, 0); + return TEST_PASS; +} + +int main(int argc, const char *argv[]) +{ + return runTestHarnessWithCheckAndParse( + argc, argv, test_registry::getInstance().num_tests(), + test_registry::getInstance().definitions(), true, 0, + checkMediaSurfaceSharingExtension, parseArgs); } diff --git a/test_conformance/gl/main.cpp b/test_conformance/gl/main.cpp index 3720558968..869a04c372 100644 --- a/test_conformance/gl/main.cpp +++ b/test_conformance/gl/main.cpp @@ -164,7 +164,7 @@ int main(int argc, const char *argv[]) int numErrors = 0; test_start(); - argc = parseCustomParam(argc, argv); + argc = parseCommonParam(argc, argv); if (argc == -1) { return -1; @@ -324,7 +324,7 @@ int main(int argc, const char *argv[]) config.forceNoContextCreation = true; config.numElementsToUse = 1024; config.queueProps = 0; - error = parseAndCallCommandLineTests(argc_, argv, deviceIDs[i], + error = parseAndCallCommandLineTests(argc_, argv, "", deviceIDs[i], test_num, test_list, config); if (error != 0) break; } @@ -409,8 +409,9 @@ int main(int argc, const char *argv[]) config.forceNoContextCreation = true; config.numElementsToUse = 1024; config.queueProps = 0; - error = parseAndCallCommandLineTests( - argc_, argv_, deviceIDs[i], test_num32, test_list32, config); + error = + parseAndCallCommandLineTests(argc_, argv_, "", deviceIDs[i], + test_num32, test_list32, config); if (error != 0) break; } diff --git a/test_conformance/gles/main.cpp b/test_conformance/gles/main.cpp index 0327b70e10..17ef1f84e3 100644 --- a/test_conformance/gles/main.cpp +++ b/test_conformance/gles/main.cpp @@ -270,7 +270,7 @@ int main(int argc, const char *argv[]) config.forceNoContextCreation = true; config.numElementsToUse = 1024; config.queueProps = 0; - error = parseAndCallCommandLineTests(argc_tmp, argv_tmp, deviceIDs[i], + error = parseAndCallCommandLineTests(argc_tmp, argv_tmp, "", deviceIDs[i], test_num, test_list, config); if (error != 0) break; } @@ -346,7 +346,7 @@ int main(int argc, const char *argv[]) config.forceNoContextCreation = true; config.numElementsToUse = 1024; config.queueProps = 0; - error = parseAndCallCommandLineTests(argc_, argv_, deviceIDs[i], + error = parseAndCallCommandLineTests(argc_, argv_, "", deviceIDs[i], test_num32, test_list32, config); if( error != 0 ) break; diff --git a/test_conformance/half/main.cpp b/test_conformance/half/main.cpp index 0beec938fd..d6cf602c17 100644 --- a/test_conformance/half/main.cpp +++ b/test_conformance/half/main.cpp @@ -36,18 +36,15 @@ #include "cl_utils.h" #include "tests.h" -const char ** argList = NULL; -size_t argCount = 0; -char appName[64] = "ctest"; const char *addressSpaceNames[AS_NumAddressSpaces] = {"global", "private", "local", "constant"}; #pragma mark - #pragma mark Declarations -static int ParseArgs( int argc, const char **argv ); -static void PrintUsage( void ); - +static test_status ParseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help); int g_arrVecSizes[kVectorSizeCount+kStrangeVectorSizeCount]; int g_arrVecAligns[kLargestVectorSize+1]; @@ -74,21 +71,11 @@ int main (int argc, const char **argv ) g_arrVecAligns[i] = alignbound; } - argc = parseCustomParam(argc, argv); - if (argc == -1) - { - return -1; - } - - if( (error = ParseArgs( argc, argv )) ) - goto exit; - fflush( stdout ); - error = runTestHarnessWithCheck( - argCount, argList, test_registry::getInstance().num_tests(), - test_registry::getInstance().definitions(), true, 0, InitCL); + error = runTestHarnessWithCheckAndParse( + argc, argv, test_registry::getInstance().num_tests(), + test_registry::getInstance().definitions(), true, 0, InitCL, ParseArgs); -exit: if(gQueue) { int flush_error = clFinish(gQueue); @@ -105,52 +92,22 @@ int main (int argc, const char **argv ) #pragma mark - #pragma mark setup -static int ParseArgs( int argc, const char **argv ) +static test_status ParseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help) { - if (gListTests) - { - return 0; - } - int i; - argList = (const char **)calloc(argc, sizeof(char *)); - if( NULL == argList ) - { - vlog_error( "Failed to allocate memory for argList.\n" ); - return 1; - } - argList[0] = argv[0]; - argCount = 1; + help = + R"( -d Toggle double precision testing (default: on if double supported) + -t Toggle reporting performance data. + -r Reset buffers on host instead of on device. + -[2^n] Set wimpy reduction factor, recommended range of n is 1-12, default factor()" + + std::to_string(gWimpyReductionFactor) + ")\n"; -#if (defined( __APPLE__ ) || defined(__linux__) || defined(__MINGW32__)) - { // Extract the app name - char baseName[ MAXPATHLEN ]; - strncpy(baseName, argv[0], MAXPATHLEN - 1); - baseName[MAXPATHLEN - 1] = '\0'; - char *base = basename( baseName ); - if( NULL != base ) - { - strncpy(appName, base, sizeof(appName) - 1); - appName[ sizeof( appName ) -1 ] = '\0'; - } - } -#elif defined (_WIN32) - { - char fname[_MAX_FNAME + _MAX_EXT + 1]; - char ext[_MAX_EXT]; - - errno_t err = _splitpath_s( argv[0], NULL, 0, NULL, 0, - fname, _MAX_FNAME, ext, _MAX_EXT ); - if (err == 0) { // no error - strcat (fname, ext); //just cat them, size of frame can keep both - strncpy (appName, fname, sizeof(appName)); - appName[ sizeof( appName ) -1 ] = '\0'; - } - } -#endif + std::vector argList; + argList.push_back(argv[0]); - vlog( "\n%s", appName ); - for( i = 1; i < argc; i++ ) + for (int i = 1; i < argc; i++) { const char *arg = argv[i]; if( NULL == arg ) @@ -168,10 +125,6 @@ static int ParseArgs( int argc, const char **argv ) gTestDouble ^= 1; break; - case 'h': - PrintUsage(); - return -1; - case 't': gReportTimes ^= 1; break; @@ -183,18 +136,18 @@ static int ParseArgs( int argc, const char **argv ) break; default: vlog_error( " <-- unknown flag: %c (0x%2.2x)\n)", *arg, *arg ); - PrintUsage(); - return -1; + return TEST_FAIL; } arg++; } + removed_args.push_back(argv[i]); } else { - argList[ argCount ] = arg; - argCount++; + argList.push_back(argv[i]); } } + update_argc_argv_from_args_list(argList, argc, argv); PrintArch(); if( gWimpyMode ) @@ -215,22 +168,5 @@ static int ParseArgs( int argc, const char **argv ) vlog("\tProfile: Full\n"); } - return 0; -} - -static void PrintUsage( void ) -{ - vlog("%s [-dthw]: \n", appName); - vlog("\t\t-d\tToggle double precision testing (default: on if double " - "supported)\n"); - vlog("\t\t-t\tToggle reporting performance data.\n"); - vlog("\t\t-r\tReset buffers on host instead of on device.\n"); - vlog("\t\t-[2^n]\tSet wimpy reduction factor, recommended range of n is " - "1-12, default factor(%u)\n", - gWimpyReductionFactor); - vlog("\t\t-h\tHelp\n"); - for (size_t i = 0; i < test_registry::getInstance().num_tests(); i++) - { - vlog("\t\t%s\n", test_registry::getInstance().definitions()[i].name); - } + return TEST_PASS; } diff --git a/test_conformance/images/clCopyImage/main.cpp b/test_conformance/images/clCopyImage/main.cpp index 2ad701b1b2..075e456854 100644 --- a/test_conformance/images/clCopyImage/main.cpp +++ b/test_conformance/images/clCopyImage/main.cpp @@ -31,8 +31,6 @@ cl_channel_order gChannelOrderToUse = (cl_channel_order)-1; extern int test_image_set( cl_device_id device, cl_context context, cl_command_queue queue, MethodsToTest testMethod ); -static void printUsage( const char *execName ); - REGISTER_TEST(1D) { return test_image_set(device, context, queue, k1D); } REGISTER_TEST(2D) { return test_image_set(device, context, queue, k2D); } REGISTER_TEST(3D) { return test_image_set(device, context, queue, k3D); } @@ -81,90 +79,65 @@ REGISTER_TEST(3Dto2Darray) return test_image_set( device, context, queue, k3DTo2DArray ); } -int main(int argc, const char *argv[]) +static test_status parseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help) { + help = R"( test_mipmaps - Test with mipmapped images + debug_trace - Enables additional debug info logging + small_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes + max_images - Runs every format through a set of size combinations with the max values, max values - 1, and max values / 128 + randomize - Use random seed + use_pitches - Enables row and slice pitches +)"; + cl_channel_type chanType; cl_channel_order chanOrder; - const char ** argList = (const char **)calloc( argc, sizeof( char*) ); - - if( NULL == argList ) - { - log_error( "Failed to allocate memory for argList array.\n" ); - return 1; - } - - argList[0] = argv[0]; - size_t argCount = 1; + std::vector argList; + argList.push_back(argv[0]); // Parse arguments - for( int i = 1; i < argc; i++ ) + for (int i = 1; i < argc; i++) { - if( strcmp( argv[i], "test_mipmaps" ) == 0 ) + removed_args.push_back(argv[i]); + if (strcmp(argv[i], "test_mipmaps") == 0) { gTestMipmaps = true; // Don't test pitches with mipmaps, at least currently. gEnablePitch = false; } - else if( strcmp( argv[i], "debug_trace" ) == 0 ) + else if (strcmp(argv[i], "debug_trace") == 0) gDebugTrace = true; - - else if( strcmp( argv[i], "small_images" ) == 0 ) + else if (strcmp(argv[i], "small_images") == 0) gTestSmallImages = true; - else if( strcmp( argv[i], "max_images" ) == 0 ) + else if (strcmp(argv[i], "max_images") == 0) gTestMaxImages = true; - - else if( strcmp( argv[i], "use_pitches" ) == 0 ) + else if (strcmp(argv[i], "use_pitches") == 0) gEnablePitch = true; - - else if( strcmp( argv[i], "--help" ) == 0 || strcmp( argv[i], "-h" ) == 0 ) - { - printUsage( argv[ 0 ] ); - return -1; - } - - else if( ( chanType = get_channel_type_from_name( argv[i] ) ) != (cl_channel_type)-1 ) + else if ((chanType = get_channel_type_from_name(argv[i])) + != (cl_channel_type)-1) gChannelTypeToUse = chanType; - - else if( ( chanOrder = get_channel_order_from_name( argv[i] ) ) != (cl_channel_order)-1 ) + else if ((chanOrder = get_channel_order_from_name(argv[i])) + != (cl_channel_order)-1) gChannelOrderToUse = chanOrder; else { - argList[argCount] = argv[i]; - argCount++; + removed_args.pop_back(); + argList.push_back(argv[i]); } } - if( gTestSmallImages ) - log_info( "Note: Using small test images\n" ); - - int ret = runTestHarnessWithCheck( - argCount, argList, test_registry::getInstance().num_tests(), - test_registry::getInstance().definitions(), false, 0, - verifyImageSupport); + if (gTestSmallImages) log_info("Note: Using small test images\n"); - free(argList); - return ret; + update_argc_argv_from_args_list(argList, argc, argv); + return TEST_PASS; } -static void printUsage( const char *execName ) +int main(int argc, const char *argv[]) { - const char *p = strrchr( execName, '/' ); - if( p != NULL ) - execName = p + 1; - - log_info( "Usage: %s [option] [test_names]\n", execName ); - log_info( "Options:\n" ); - log_info( "\ttest_mipmaps - Test with mipmapped images\n" ); - log_info( "\tdebug_trace - Enables additional debug info logging\n" ); - log_info( "\tsmall_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes\n" ); - log_info( "\tmax_images - Runs every format through a set of size combinations with the max values, max values - 1, and max values / 128\n" ); - log_info( "\trandomize - Use random seed\n" ); - log_info( "\tuse_pitches - Enables row and slice pitches\n" ); - log_info( "\n" ); - log_info( "Test names:\n" ); - for (size_t i = 0; i < test_registry::getInstance().num_tests(); i++) - { - log_info("\t%s\n", test_registry::getInstance().definitions()[i].name); - } + return runTestHarnessWithCheckAndParse( + argc, argv, test_registry::getInstance().num_tests(), + test_registry::getInstance().definitions(), false, 0, + verifyImageSupport, parseArgs); } diff --git a/test_conformance/images/clFillImage/main.cpp b/test_conformance/images/clFillImage/main.cpp index d5f565bd1f..62a94b9cd2 100644 --- a/test_conformance/images/clFillImage/main.cpp +++ b/test_conformance/images/clFillImage/main.cpp @@ -28,9 +28,8 @@ int gTypesToTest; cl_channel_type gChannelTypeToUse = (cl_channel_type)-1; cl_channel_order gChannelOrderToUse = (cl_channel_order)-1; -extern int test_image_set( cl_device_id device, cl_context context, cl_command_queue queue, MethodsToTest testMethod ); -static void printUsage( const char *execName ); - +extern int test_image_set(cl_device_id device, cl_context context, + cl_command_queue queue, MethodsToTest testMethod); REGISTER_TEST(1D) { return test_image_set(device, context, queue, k1D); } REGISTER_TEST(2D) { return test_image_set(device, context, queue, k2D); } @@ -47,101 +46,74 @@ REGISTER_TEST(1Dbuffer) { return test_image_set(device, context, queue, k1DBuffer); } - -int main(int argc, const char *argv[]) +static test_status parseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help) { - cl_channel_type chanType; + help = + R"( The following flags specify the types to test. They can be combined; if none are specified, all are tested: + int - Test integer fill + uint - Test unsigned integer fill + float - Test float fill + + randomize - Uses random seed + debug_trace - Enables additional debug info logging + small_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes + max_images - Runs every format through a set of size combinations with the max values, max values - 1, and max values / 128 + use_pitches - Enables row and slice pitches + + You may also use appropriate CL_ channel type and ordering constants. +)"; + + cl_channel_type chanType; cl_channel_order chanOrder; - const char ** argList = (const char **)calloc( argc, sizeof( char*) ); - - if( NULL == argList ) - { - log_error( "Failed to allocate memory for argList array.\n" ); - return 1; - } - - argList[0] = argv[0]; - size_t argCount = 1; + std::vector argList; + argList.push_back(argv[0]); // Parse arguments - for ( int i = 1; i < argc; i++ ) + for (int i = 1; i < argc; i++) { - if ( strcmp( argv[i], "debug_trace" ) == 0 ) + removed_args.push_back(argv[i]); + if (strcmp(argv[i], "debug_trace") == 0) gDebugTrace = true; - - else if ( strcmp( argv[i], "small_images" ) == 0 ) + else if (strcmp(argv[i], "small_images") == 0) gTestSmallImages = true; - else if ( strcmp( argv[i], "max_images" ) == 0 ) + else if (strcmp(argv[i], "max_images") == 0) gTestMaxImages = true; - - else if ( strcmp( argv[i], "use_pitches" ) == 0 ) + else if (strcmp(argv[i], "use_pitches") == 0) gEnablePitch = true; - - else if( strcmp( argv[i], "int" ) == 0 ) + else if (strcmp(argv[i], "int") == 0) gTypesToTest |= kTestInt; - else if( strcmp( argv[i], "uint" ) == 0 ) + else if (strcmp(argv[i], "uint") == 0) gTypesToTest |= kTestUInt; - else if( strcmp( argv[i], "float" ) == 0 ) + else if (strcmp(argv[i], "float") == 0) gTypesToTest |= kTestFloat; - - else if ( strcmp( argv[i], "--help" ) == 0 || strcmp( argv[i], "-h" ) == 0 ) - { - printUsage( argv[ 0 ] ); - return -1; - } - - else if ( ( chanType = get_channel_type_from_name( argv[i] ) ) != (cl_channel_type)-1 ) + else if ((chanType = get_channel_type_from_name(argv[i])) + != (cl_channel_type)-1) gChannelTypeToUse = chanType; - - else if ( ( chanOrder = get_channel_order_from_name( argv[i] ) ) != (cl_channel_order)-1 ) + else if ((chanOrder = get_channel_order_from_name(argv[i])) + != (cl_channel_order)-1) gChannelOrderToUse = chanOrder; else { - argList[argCount] = argv[i]; - argCount++; + removed_args.pop_back(); + argList.push_back(argv[i]); } } - if ( gTypesToTest == 0 ) - gTypesToTest = kTestAllTypes; - - if ( gTestSmallImages ) - log_info( "Note: Using small test images\n" ); + if (gTypesToTest == 0) gTypesToTest = kTestAllTypes; - int ret = runTestHarnessWithCheck( - argCount, argList, test_registry::getInstance().num_tests(), - test_registry::getInstance().definitions(), false, 0, - verifyImageSupport); + if (gTestSmallImages) log_info("Note: Using small test images\n"); - free(argList); - return ret; + update_argc_argv_from_args_list(argList, argc, argv); + return TEST_PASS; } -static void printUsage( const char *execName ) +int main(int argc, const char *argv[]) { - const char *p = strrchr( execName, '/' ); - if ( p != NULL ) - execName = p + 1; - - log_info( "Usage: %s [options] [test_names]\n", execName ); - log_info( "Options:\n" ); - log_info( "\tThe following flags specify the types to test. They can be combined; if none are specified, all are tested:\n" ); - log_info( "\t\tint - Test integer fill\n" ); - log_info( "\t\tuint - Test unsigned integer fill\n" ); - log_info( "\t\tfloat - Test float fill\n" ); - log_info( "\n" ); - log_info( "\trandomize - Uses random seed\n" ); - log_info( "\tdebug_trace - Enables additional debug info logging\n" ); - log_info( "\tsmall_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes\n" ); - log_info( "\tmax_images - Runs every format through a set of size combinations with the max values, max values - 1, and max values / 128\n" ); - log_info( "\tuse_pitches - Enables row and slice pitches\n" ); - log_info( "\n" ); - log_info( "Test names:\n" ); - for (size_t i = 0; i < test_registry::getInstance().num_tests(); i++) - { - log_info("\t%s\n", test_registry::getInstance().definitions()[i].name); - } - log_info( "\n" ); - log_info( "You may also use appropriate CL_ channel type and ordering constants.\n" ); + return runTestHarnessWithCheckAndParse( + argc, argv, test_registry::getInstance().num_tests(), + test_registry::getInstance().definitions(), false, 0, + verifyImageSupport, parseArgs); } diff --git a/test_conformance/images/clGetInfo/main.cpp b/test_conformance/images/clGetInfo/main.cpp index abca3490b3..5a71fedcae 100644 --- a/test_conformance/images/clGetInfo/main.cpp +++ b/test_conformance/images/clGetInfo/main.cpp @@ -25,8 +25,8 @@ bool gTestMaxImages; cl_channel_type gChannelTypeToUse = (cl_channel_type)-1; cl_channel_order gChannelOrderToUse = (cl_channel_order)-1; -extern int test_image_set( cl_device_id device, cl_context context, cl_mem_object_type image_type ); -static void printUsage( const char *execName ); +extern int test_image_set(cl_device_id device, cl_context context, + cl_mem_object_type image_type); REGISTER_TEST(1D) { @@ -59,76 +59,54 @@ REGISTER_TEST(1Dbuffer) return test_image_set(device, context, CL_MEM_OBJECT_IMAGE1D_BUFFER); } -int main(int argc, const char *argv[]) +static test_status parseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help) { - cl_channel_type chanType; + help = + R"( debug_trace - Enables additional debug info logging (default no debug info) - const char ** argList = (const char **)calloc( argc, sizeof( char*) ); + small_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes (default test random sizes) + max_images - Runs every format through a set of size combinations with the max values, max values - 1, and max values / 128 (default test random sizes) - if( NULL == argList ) - { - log_error( "Failed to allocate memory for argList array.\n" ); - return 1; - } + randomize - Seed random number generator (default do not seed random number generator) +)"; - argList[0] = argv[0]; - size_t argCount = 1; + cl_channel_type chanType; + + std::vector argList; + argList.push_back(argv[0]); // Parse arguments - for( int i = 1; i < argc; i++ ) + for (int i = 1; i < argc; i++) { - if( strcmp( argv[i], "debug_trace" ) == 0 ) + removed_args.push_back(argv[i]); + if (strcmp(argv[i], "debug_trace") == 0) gDebugTrace = true; - - else if( strcmp( argv[i], "small_images" ) == 0 ) + else if (strcmp(argv[i], "small_images") == 0) gTestSmallImages = true; - else if( strcmp( argv[i], "max_images" ) == 0 ) + else if (strcmp(argv[i], "max_images") == 0) gTestMaxImages = true; - - else if( strcmp( argv[i], "--help" ) == 0 || strcmp( argv[i], "-h" ) == 0 ) - { - printUsage( argv[ 0 ] ); - return -1; - } - else if( ( chanType = get_channel_type_from_name( argv[i] ) ) != (cl_channel_type)-1 ) + else if ((chanType = get_channel_type_from_name(argv[i])) + != (cl_channel_type)-1) gChannelTypeToUse = chanType; else { - argList[argCount] = argv[i]; - argCount++; + removed_args.pop_back(); + argList.push_back(argv[i]); } } - if( gTestSmallImages ) - log_info( "Note: Using small test images\n" ); - - int ret = runTestHarnessWithCheck( - argCount, argList, test_registry::getInstance().num_tests(), - test_registry::getInstance().definitions(), false, 0, - verifyImageSupport); + if (gTestSmallImages) log_info("Note: Using small test images\n"); - free(argList); - return ret; + update_argc_argv_from_args_list(argList, argc, argv); + return TEST_PASS; } -static void printUsage( const char *execName ) +int main(int argc, const char *argv[]) { - const char *p = strrchr( execName, '/' ); - if( p != NULL ) - execName = p + 1; - - log_info( "Usage: %s [options] [test_names]\n", execName ); - log_info( "Options:\n" ); - log_info( "\tdebug_trace - Enables additional debug info logging (default no debug info)\n" ); - log_info( "\n" ); - log_info( "\tsmall_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes (default test random sizes)\n" ); - log_info( "\tmax_images - Runs every format through a set of size combinations with the max values, max values - 1, and max values / 128 (default test random sizes)\n" ); - log_info( "\n" ); - log_info( "\trandomize - Seed random number generator (default do not seed random number generator)\n" ); - log_info( "\n" ); - log_info( "Test names:\n" ); - for (size_t i = 0; i < test_registry::getInstance().num_tests(); i++) - { - log_info("\t%s\n", test_registry::getInstance().definitions()[i].name); - } + return runTestHarnessWithCheckAndParse( + argc, argv, test_registry::getInstance().num_tests(), + test_registry::getInstance().definitions(), false, 0, + verifyImageSupport, parseArgs); } diff --git a/test_conformance/images/kernel_image_methods/main.cpp b/test_conformance/images/kernel_image_methods/main.cpp index 0b6f29fe86..13e4e72f16 100644 --- a/test_conformance/images/kernel_image_methods/main.cpp +++ b/test_conformance/images/kernel_image_methods/main.cpp @@ -18,7 +18,6 @@ #include #include "../testBase.h" #include "../harness/compat.h" -#include "../harness/parseParameters.h" bool gDebugTrace; bool gTestSmallImages; @@ -29,8 +28,6 @@ cl_channel_order gChannelOrderToUse = (cl_channel_order)-1; extern int test_image_set( cl_device_id device, cl_context context, cl_command_queue queue, cl_mem_object_type imageType ); -static void printUsage( const char *execName ); - REGISTER_TEST(1D) { return test_image_set( device, context, queue, CL_MEM_OBJECT_IMAGE1D ); @@ -56,30 +53,24 @@ REGISTER_TEST(1Dbuffer) return test_image_set(device, context, queue, CL_MEM_OBJECT_IMAGE1D_BUFFER); } -int main(int argc, const char *argv[]) +static test_status parseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help) { cl_channel_type chanType; + std::vector argList; + argList.push_back(argv[0]); - argc = parseCustomParam(argc, argv); - if (argc == -1) - { - return -1; - } - - const char ** argList = (const char **)calloc( argc, sizeof( char*) ); - - if( NULL == argList ) - { - log_error( "Failed to allocate memory for argList array.\n" ); - return 1; - } - - argList[0] = argv[0]; - size_t argCount = 1; + help = R"( debug_trace - Enables additional debug info logging + small_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes + max_images - Runs every format through a set of size combinations with the max values, max values - 1, and max values / 128 + randomize - Uses random seed +)"; // Parse arguments for( int i = 1; i < argc; i++ ) { + removed_args.push_back(argv[i]); if( strcmp( argv[i], "debug_trace" ) == 0 ) gDebugTrace = true; @@ -88,48 +79,25 @@ int main(int argc, const char *argv[]) else if( strcmp( argv[i], "max_images" ) == 0 ) gTestMaxImages = true; - else if( strcmp( argv[i], "--help" ) == 0 || strcmp( argv[i], "-h" ) == 0 ) - { - printUsage( argv[ 0 ] ); - return -1; - } else if( ( chanType = get_channel_type_from_name( argv[i] ) ) != (cl_channel_type)-1 ) gChannelTypeToUse = chanType; else { - argList[argCount] = argv[i]; - argCount++; + removed_args.pop_back(); + argList.push_back(argv[i]); } } - if( gTestSmallImages ) - log_info( "Note: Using small test images\n" ); + if (gTestSmallImages) log_info("Note: Using small test images\n"); - int ret = runTestHarnessWithCheck( - argCount, argList, test_registry::getInstance().num_tests(), - test_registry::getInstance().definitions(), false, 0, - verifyImageSupport); - - free(argList); - return ret; + update_argc_argv_from_args_list(argList, argc, argv); + return TEST_PASS; } -static void printUsage( const char *execName ) +int main(int argc, const char *argv[]) { - const char *p = strrchr( execName, '/' ); - if( p != NULL ) - execName = p + 1; - - log_info( "Usage: %s [options] [test_names]\n", execName ); - log_info( "Options:\n" ); - log_info( "\tdebug_trace - Enables additional debug info logging\n" ); - log_info( "\tsmall_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes\n" ); - log_info( "\tmax_images - Runs every format through a set of size combinations with the max values, max values - 1, and max values / 128\n" ); - log_info( "\trandomize - Uses random seed\n" ); - log_info( "\n" ); - log_info( "Test names:\n" ); - for (size_t i = 0; i < test_registry::getInstance().num_tests(); i++) - { - log_info("\t%s\n", test_registry::getInstance().definitions()[i].name); - } + return runTestHarnessWithCheckAndParse( + argc, argv, test_registry::getInstance().num_tests(), + test_registry::getInstance().definitions(), false, 0, + verifyImageSupport, parseArgs); } diff --git a/test_conformance/images/kernel_read_write/main.cpp b/test_conformance/images/kernel_read_write/main.cpp index 3a3e13f38f..dc1593b9e9 100644 --- a/test_conformance/images/kernel_read_write/main.cpp +++ b/test_conformance/images/kernel_read_write/main.cpp @@ -19,7 +19,6 @@ #include "../testBase.h" #include "../harness/compat.h" #include "../harness/fpcontrol.h" -#include "../harness/parseParameters.h" #if defined(__PPC__) // Global varaiable used to hold the FPU control register state. The FPSCR register can not @@ -49,8 +48,6 @@ bool gEnablePitch = false; int gtestTypesToRun = 0; static int testTypesToRun; -static void printUsage( const char *execName ); - extern int test_image_set( cl_device_id device, cl_context context, cl_command_queue queue, test_format_set_fn formatTestFn, cl_mem_object_type imageType ); extern int cl_image_requirements_size_ext_negative(cl_device_id device, @@ -340,31 +337,64 @@ REGISTER_TEST_VERSION(cl_ext_image_raw10_raw12, Version(1, 2)) return ext_image_raw10_raw12(device, context, queue); } -int main(int argc, const char *argv[]) +static test_status parseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help) { - cl_channel_type chanType; - cl_channel_order chanOrder; - argc = parseCustomParam(argc, argv); - if (argc == -1) - { - return -1; - } + help = + R"( The following flags specify what kinds of operations to test. They can be combined; if none are specified, all are tested: + read - Tests reading from an image + write - Tests writing to an image (can be specified with read to run both; default is both) - const char ** argList = (const char **)calloc( argc, sizeof( char*) ); + The following flags specify the types to test. They can be combined; if none are specified, all are tested: + int - Test integer I/O (read_imagei, write_imagei) + uint - Test unsigned integer I/O (read_imageui, write_imageui) + float - Test float I/O (read_imagef, write_imagef) - if( NULL == argList ) - { - log_error( "Failed to allocate memory for argList array.\n" ); - return 1; - } + CL_FILTER_LINEAR - Only tests formats with CL_FILTER_LINEAR filtering + CL_FILTER_NEAREST - Only tests formats with CL_FILTER_NEAREST filtering - argList[0] = argv[0]; - size_t argCount = 1; + NORMALIZED - Only tests formats with NORMALIZED coordinates + UNNORMALIZED - Only tests formats with UNNORMALIZED coordinates + + CL_ADDRESS_CLAMP - Only tests formats with CL_ADDRESS_CLAMP addressing + CL_ADDRESS_CLAMP_TO_EDGE - Only tests formats with CL_ADDRESS_CLAMP_TO_EDGE addressing + CL_ADDRESS_REPEAT - Only tests formats with CL_ADDRESS_REPEAT addressing + CL_ADDRESS_MIRRORED_REPEAT - Only tests formats with CL_ADDRESS_MIRRORED_REPEAT addressing + + You may also use appropriate CL_ channel type and ordering constants. + + local_samplers - Use samplers declared in the kernel functions instead of passed in as arguments + + The following specify to use the specific flag to allocate images to use in the tests: + CL_MEM_COPY_HOST_PTR + CL_MEM_USE_HOST_PTR (default) + CL_MEM_ALLOC_HOST_PTR + NO_HOST_PTR - Specifies to use none of the above flags + + The following modify the types of images tested: + small_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes + max_images - Runs every format through a set of size combinations with the max values, max values - 1, and max values / 128 + rounding - Runs every format through a single image filled with every possible value for that image format, to verify rounding works properly + + no_offsets - Disables offsets when testing reads (can be good for diagnosing address repeating/clamping problems) + debug_trace - Enables additional debug info logging + extra_validate - Enables additional validation failure debug information + use_pitches - Enables row and slice pitches + test_mipmaps - Enables mipmapped images +)"; + + cl_channel_type chanType; + cl_channel_order chanOrder; + + std::vector argList; + argList.push_back(argv[0]); // Parse arguments for( int i = 1; i < argc; i++ ) { + removed_args.push_back(argv[i]); if( strcmp( argv[i], "debug_trace" ) == 0 ) gDebugTrace = true; @@ -437,12 +467,6 @@ int main(int argc, const char *argv[]) else if( strcmp( argv[i], "NO_HOST_PTR" ) == 0 ) gMemFlagsToUse = 0; - else if( strcmp( argv[i], "--help" ) == 0 || strcmp( argv[i], "-h" ) == 0 ) - { - printUsage( argv[ 0 ] ); - return -1; - } - else if( ( chanType = get_channel_type_from_name( argv[i] ) ) != (cl_channel_type)-1 ) gChannelTypeToUse = chanType; @@ -450,8 +474,8 @@ int main(int argc, const char *argv[]) gChannelOrderToUse = chanOrder; else { - argList[argCount] = argv[i]; - argCount++; + removed_args.pop_back(); + argList.push_back(argv[i]); } } @@ -463,6 +487,13 @@ int main(int argc, const char *argv[]) if( gTestSmallImages ) log_info( "Note: Using small test images\n" ); + update_argc_argv_from_args_list(argList, argc, argv); + return TEST_PASS; +} + +int main(int argc, const char *argv[]) +{ + // On most platforms which support denorm, default is FTZ off. However, // on some hardware where the reference is computed, default might be flush denorms to zero e.g. arm. // This creates issues in result verification. Since spec allows the implementation to either flush or @@ -474,71 +505,13 @@ int main(int argc, const char *argv[]) FPU_mode_type oldMode; DisableFTZ(&oldMode); - int ret = runTestHarnessWithCheck( - argCount, argList, test_registry::getInstance().num_tests(), + int ret = runTestHarnessWithCheckAndParse( + argc, argv, test_registry::getInstance().num_tests(), test_registry::getInstance().definitions(), false, 0, - verifyImageSupport); + verifyImageSupport, parseArgs); // Restore FP state before leaving RestoreFPState(&oldMode); - free(argList); return ret; } - -static void printUsage( const char *execName ) -{ - const char *p = strrchr( execName, '/' ); - if( p != NULL ) - execName = p + 1; - - log_info( "Usage: %s [options] [test_names]\n", execName ); - log_info( "Options:\n" ); - log_info( "\n" ); - log_info( "\tThe following flags specify what kinds of operations to test. They can be combined; if none are specified, all are tested:\n" ); - log_info( "\t\tread - Tests reading from an image\n" ); - log_info( "\t\twrite - Tests writing to an image (can be specified with read to run both; default is both)\n" ); - log_info( "\n" ); - log_info( "\tThe following flags specify the types to test. They can be combined; if none are specified, all are tested:\n" ); - log_info( "\t\tint - Test integer I/O (read_imagei, write_imagei)\n" ); - log_info( "\t\tuint - Test unsigned integer I/O (read_imageui, write_imageui)\n" ); - log_info( "\t\tfloat - Test float I/O (read_imagef, write_imagef)\n" ); - log_info( "\n" ); - log_info( "\tCL_FILTER_LINEAR - Only tests formats with CL_FILTER_LINEAR filtering\n" ); - log_info( "\tCL_FILTER_NEAREST - Only tests formats with CL_FILTER_NEAREST filtering\n" ); - log_info( "\n" ); - log_info( "\tNORMALIZED - Only tests formats with NORMALIZED coordinates\n" ); - log_info( "\tUNNORMALIZED - Only tests formats with UNNORMALIZED coordinates\n" ); - log_info( "\n" ); - log_info( "\tCL_ADDRESS_CLAMP - Only tests formats with CL_ADDRESS_CLAMP addressing\n" ); - log_info( "\tCL_ADDRESS_CLAMP_TO_EDGE - Only tests formats with CL_ADDRESS_CLAMP_TO_EDGE addressing\n" ); - log_info( "\tCL_ADDRESS_REPEAT - Only tests formats with CL_ADDRESS_REPEAT addressing\n" ); - log_info( "\tCL_ADDRESS_MIRRORED_REPEAT - Only tests formats with CL_ADDRESS_MIRRORED_REPEAT addressing\n" ); - log_info( "\n" ); - log_info( "You may also use appropriate CL_ channel type and ordering constants.\n" ); - log_info( "\n" ); - log_info( "\tlocal_samplers - Use samplers declared in the kernel functions instead of passed in as arguments\n" ); - log_info( "\n" ); - log_info( "\tThe following specify to use the specific flag to allocate images to use in the tests:\n" ); - log_info( "\t\tCL_MEM_COPY_HOST_PTR\n" ); - log_info( "\t\tCL_MEM_USE_HOST_PTR (default)\n" ); - log_info( "\t\tCL_MEM_ALLOC_HOST_PTR\n" ); - log_info( "\t\tNO_HOST_PTR - Specifies to use none of the above flags\n" ); - log_info( "\n" ); - log_info( "\tThe following modify the types of images tested:\n" ); - log_info( "\t\tsmall_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes\n" ); - log_info( "\t\tmax_images - Runs every format through a set of size combinations with the max values, max values - 1, and max values / 128\n" ); - log_info( "\t\trounding - Runs every format through a single image filled with every possible value for that image format, to verify rounding works properly\n" ); - log_info( "\n" ); - log_info( "\tno_offsets - Disables offsets when testing reads (can be good for diagnosing address repeating/clamping problems)\n" ); - log_info( "\tdebug_trace - Enables additional debug info logging\n" ); - log_info( "\textra_validate - Enables additional validation failure debug information\n" ); - log_info( "\tuse_pitches - Enables row and slice pitches\n" ); - log_info( "\ttest_mipmaps - Enables mipmapped images\n"); - log_info( "\n" ); - log_info( "Test names:\n" ); - for (size_t i = 0; i < test_registry::getInstance().num_tests(); i++) - { - log_info("\t%s\n", test_registry::getInstance().definitions()[i].name); - } -} diff --git a/test_conformance/images/samplerlessReads/main.cpp b/test_conformance/images/samplerlessReads/main.cpp index 95945c9c9e..3a6198b0ce 100644 --- a/test_conformance/images/samplerlessReads/main.cpp +++ b/test_conformance/images/samplerlessReads/main.cpp @@ -19,7 +19,6 @@ #include "../testBase.h" #include "../harness/compat.h" #include "../harness/fpcontrol.h" -#include "../harness/parseParameters.h" #if defined(__PPC__) // Global varaiable used to hold the FPU control register state. The FPSCR register can not @@ -37,8 +36,6 @@ cl_channel_type gChannelTypeToUse = (cl_channel_type)-1; cl_channel_order gChannelOrderToUse = (cl_channel_order)-1; bool gEnablePitch = false; -static void printUsage( const char *execName ); - extern int test_image_set( cl_device_id device, cl_context context, cl_command_queue queue, cl_mem_object_type imageType ); REGISTER_TEST(1D) @@ -66,31 +63,38 @@ REGISTER_TEST(2Darray) return test_image_set( device, context, queue, CL_MEM_OBJECT_IMAGE2D_ARRAY ); } -int main(int argc, const char *argv[]) +static test_status parseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help) { - cl_channel_type chanType; - cl_channel_order chanOrder; - argc = parseCustomParam(argc, argv); - if (argc == -1) - { - return -1; - } + help = + R"( The following flags specify the types to test. They can be combined; if none are specified, all are tested: + int - Test integer I/O (read_imagei) + uint - Test unsigned integer I/O (read_imageui) + float - Test float I/O (read_imagef) - const char ** argList = (const char **)calloc( argc, sizeof( char*) ); + You may also use appropriate CL_ channel type and ordering constants. - if( NULL == argList ) - { - log_error( "Failed to allocate memory for argList array.\n" ); - return 1; - } + The following modify the types of images tested: + read_write - Runs the tests with read_write images which allow a kernel do both read and write to the same image + small_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes + max_images - Runs every format through a set of size combinations with the max values, max values - 1, and max values / 128 + + debug_trace - Enables additional debug info logging + use_pitches - Enables row and slice pitches +)"; + + cl_channel_type chanType; + cl_channel_order chanOrder; - argList[0] = argv[0]; - size_t argCount = 1; + std::vector argList; + argList.push_back(argv[0]); // Parse arguments for ( int i = 1; i < argc; i++ ) { + removed_args.push_back(argv[i]); if ( strcmp( argv[i], "debug_trace" ) == 0 ) gDebugTrace = true; else if ( strcmp( argv[i], "read_write" ) == 0 ) @@ -109,12 +113,6 @@ int main(int argc, const char *argv[]) else if ( strcmp( argv[i], "float" ) == 0 ) gTypesToTest |= kTestFloat; - else if ( strcmp( argv[i], "--help" ) == 0 || strcmp( argv[i], "-h" ) == 0 ) - { - printUsage( argv[ 0 ] ); - return -1; - } - else if ( ( chanType = get_channel_type_from_name( argv[i] ) ) != (cl_channel_type)-1 ) gChannelTypeToUse = chanType; @@ -122,8 +120,8 @@ int main(int argc, const char *argv[]) gChannelOrderToUse = chanOrder; else { - argList[argCount] = argv[i]; - argCount++; + removed_args.pop_back(); + argList.push_back(argv[i]); } } @@ -133,6 +131,13 @@ int main(int argc, const char *argv[]) if ( gTestSmallImages ) log_info( "Note: Using small test images\n" ); + update_argc_argv_from_args_list(argList, argc, argv); + return TEST_PASS; +} + +int main(int argc, const char *argv[]) +{ + // On most platforms which support denorm, default is FTZ off. However, // on some hardware where the reference is computed, default might be flush denorms to zero e.g. arm. // This creates issues in result verification. Since spec allows the implementation to either flush or @@ -144,45 +149,13 @@ int main(int argc, const char *argv[]) FPU_mode_type oldMode; DisableFTZ(&oldMode); - int ret = runTestHarnessWithCheck( - argCount, argList, test_registry::getInstance().num_tests(), + int ret = runTestHarnessWithCheckAndParse( + argc, argv, test_registry::getInstance().num_tests(), test_registry::getInstance().definitions(), false, 0, - verifyImageSupport); + verifyImageSupport, parseArgs); // Restore FP state before leaving RestoreFPState(&oldMode); - free(argList); return ret; } - -static void printUsage( const char *execName ) -{ - const char *p = strrchr( execName, '/' ); - if ( p != NULL ) - execName = p + 1; - - log_info( "Usage: %s [options] [test_names]\n", execName ); - log_info( "Options:\n" ); - log_info( "\n" ); - log_info( "\tThe following flags specify the types to test. They can be combined; if none are specified, all are tested:\n" ); - log_info( "\t\tint - Test integer I/O (read_imagei)\n" ); - log_info( "\t\tuint - Test unsigned integer I/O (read_imageui)\n" ); - log_info( "\t\tfloat - Test float I/O (read_imagef)\n" ); - log_info( "\n" ); - log_info( "You may also use appropriate CL_ channel type and ordering constants.\n" ); - log_info( "\n" ); - log_info( "\tThe following modify the types of images tested:\n" ); - log_info( "\t\tread_write - Runs the tests with read_write images which allow a kernel do both read and write to the same image \n" ); - log_info( "\t\tsmall_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes\n" ); - log_info( "\t\tmax_images - Runs every format through a set of size combinations with the max values, max values - 1, and max values / 128\n" ); - log_info( "\n" ); - log_info( "\tdebug_trace - Enables additional debug info logging\n" ); - log_info( "\tuse_pitches - Enables row and slice pitches\n" ); - log_info( "\n" ); - log_info( "Test names:\n" ); - for (size_t i = 0; i < test_registry::getInstance().num_tests(); i++) - { - log_info("\t%s\n", test_registry::getInstance().definitions()[i].name); - } -} diff --git a/test_conformance/math_brute_force/main.cpp b/test_conformance/math_brute_force/main.cpp index cf5ab0d84a..8d529eb55b 100644 --- a/test_conformance/math_brute_force/main.cpp +++ b/test_conformance/math_brute_force/main.cpp @@ -55,8 +55,6 @@ (CL_FP_FMA | CL_FP_ROUND_TO_NEAREST | CL_FP_ROUND_TO_ZERO \ | CL_FP_ROUND_TO_INF | CL_FP_INF_NAN | CL_FP_DENORM) -static std::vector gTestNames; -static char appName[MAXPATHLEN] = ""; cl_device_id gDevice = NULL; cl_context gContext = NULL; cl_command_queue gQueue = NULL; @@ -109,9 +107,9 @@ int gVerboseBruteForce = 0; cl_half_rounding_mode gHalfRoundingMode = CL_HALF_RTE; -static int ParseArgs(int argc, const char **argv); -static void PrintUsage(void); -static void PrintFunctions(void); +static test_status ParseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help); static test_status InitCL(cl_device_id device); static void ReleaseCL(void); static int InitILogbConstants(void); @@ -375,45 +373,12 @@ DO_TEST(erfc) int main(int argc, const char *argv[]) { - int error; - - argc = parseCustomParam(argc, argv); - if (argc == -1) - { - return -1; - } - - error = ParseArgs(argc, argv); - if (error) return error; - - if (!gListTests) - { - // This takes a while, so prevent the machine from going to sleep. - PreventSleep(); - atexit(ResumeSleep); - - if (gSkipCorrectnessTesting) - vlog("*** Skipping correctness testing! ***\n\n"); - else if (gStopOnError) - vlog("Stopping at first error.\n"); - - vlog(" \t "); - if (gWimpyMode) vlog(" "); - if (!gSkipCorrectnessTesting) vlog("\t max_ulps"); - - vlog("\n---------------------------------------------------------------" - "--------------------------------------------\n"); - } - - gMTdata = MTdataHolder(gRandomSeed); - FPU_mode_type oldMode; DisableFTZ(&oldMode); - int ret = runTestHarnessWithCheck( - gTestNames.size(), gTestNames.data(), - test_registry::getInstance().num_tests(), - test_registry::getInstance().definitions(), true, 0, InitCL); + int ret = runTestHarnessWithCheckAndParse( + argc, argv, test_registry::getInstance().num_tests(), + test_registry::getInstance().definitions(), true, 0, InitCL, ParseArgs); RestoreFPState(&oldMode); @@ -428,40 +393,40 @@ int main(int argc, const char *argv[]) return ret; } -static int ParseArgs(int argc, const char **argv) +static test_status ParseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help) { - if (gListTests) - { - return 0; - } - // We only pass test names to runTestHarnessWithCheck, hence global command - // line options defined by the harness cannot be used by the user. - // To respect the implementation details of runTestHarnessWithCheck, - // gTestNames[0] has to exist although its value is not important. - gTestNames.push_back(""); + help = + R"( -d Toggle double precision testing. (Default: on iff khr_fp_64 on) + -f Toggle float precision testing. (Default: on) + -g Toggle half precision testing. (Default: on if khr_fp_16 on) + -r Toggle fast relaxed math precision testing. (Default: on) + -e Toggle test as derived implementations for fast relaxed math precision. (Default: on) + -l link check only (make sure functions are present, skip accuracy checks.) + -m Toggle run multi-threaded. (Default: on) + -s Stop on error + -[2^n] Set wimpy reduction factor, recommended range of n is 1-10, default factor()" + + std::to_string(gWimpyReductionFactor) + R"() + -b Fill buffers on host instead of device. (Default: off) + -z Toggle FTZ mode (Section 6.5.3) for all functions. (Set by device capabilities by default.) + -v Toggle Verbosity (Default: off) + -# Test only vector sizes #, e.g. "-1" tests scalar only, "-16" tests 16-wide vectors only. + + You may also pass a number instead of a function name. + This causes the first N tests to be skipped. The tests are numbered. + If you pass a second number, that is the number tests to run after the first one. + A name list may be used in conjunction with a number range. In that case, + only the named cases in the number range will run. + You may also choose to pass no arguments, in which case all tests will be run. +)"; + + std::vector argList; + argList.push_back(argv[0]); int singleThreaded = 0; int forcedWorkerThreads = 0; - { // Extract the app name - strncpy(appName, argv[0], MAXPATHLEN - 1); - appName[MAXPATHLEN - 1] = '\0'; - -#if defined(__APPLE__) - char baseName[MAXPATHLEN]; - char *base = NULL; - strncpy(baseName, argv[0], MAXPATHLEN - 1); - baseName[MAXPATHLEN - 1] = '\0'; - base = basename(baseName); - if (NULL != base) - { - strncpy(appName, base, sizeof(appName) - 1); - appName[sizeof(appName) - 1] = '\0'; - } -#endif - } - - vlog("\n%s\t", appName); for (int i = 1; i < argc; i++) { const char *arg = argv[i]; @@ -469,6 +434,7 @@ static int ParseArgs(int argc, const char **argv) vlog("\t%s", arg); int optionFound = 0; + removed_args.push_back(argv[i]); if (arg[0] == '-') { while (arg[1] != '\0') @@ -483,15 +449,14 @@ static int ParseArgs(int argc, const char **argv) case 'f': gTestFloat ^= 1; break; - case 'h': PrintUsage(); return -1; - - case 'p': PrintFunctions(); return -1; - case 'l': gSkipCorrectnessTesting ^= 1; break; case 'm': singleThreaded ^= 1; break; case 't': + removed_args.pop_back(); + removed_args.push_back(std::string(argv[i]) + " " + + argv[i + 1]); forcedWorkerThreads = atoi(argv[++i]); vlog(" %d", forcedWorkerThreads); break; @@ -544,8 +509,7 @@ static int ParseArgs(int argc, const char **argv) default: vlog(" <-- unknown flag: %c (0x%2.2x)\n)", *arg, *arg); - PrintUsage(); - return -1; + return TEST_FAIL; } } } @@ -563,25 +527,12 @@ static int ParseArgs(int argc, const char **argv) } else { - // Make sure this is a valid name - unsigned int k; - for (k = 0; k < functionListCount; k++) - { - const Func *f = functionList + k; - if (strcmp(arg, f->name) == 0) - { - gTestNames.push_back(arg); - break; - } - } - // If we didn't find it in the list of test names - if (k >= functionListCount) - { - gTestNames.push_back(arg); - } + removed_args.pop_back(); + argList.push_back(argv[i]); } } } + update_argc_argv_from_args_list(argList, argc, argv); PrintArch(); @@ -605,60 +556,21 @@ static int ParseArgs(int argc, const char **argv) forcedWorkerThreads); SetThreadCount(forcedWorkerThreads); } + if (gSkipCorrectnessTesting) + vlog("*** Skipping correctness testing! ***\n\n"); + else if (gStopOnError) + vlog("Stopping at first error.\n"); - return 0; -} + vlog(" \t "); + if (gWimpyMode) vlog(" "); + if (!gSkipCorrectnessTesting) vlog("\t max_ulps"); + vlog("\n---------------------------------------------------------------" + "--------------------------------------------\n"); -static void PrintFunctions(void) -{ - vlog("\nMath function names:\n"); - for (size_t i = 0; i < functionListCount; i++) - { - vlog("\t%s\n", functionList[i].name); - } -} + gMTdata = MTdataHolder(gRandomSeed); -static void PrintUsage(void) -{ - vlog("%s [-cglsz]: \n", appName); - vlog("\toptions:\n"); - vlog("\t\t-d\tToggle double precision testing. (Default: on iff khr_fp_64 " - "on)\n"); - vlog("\t\t-f\tToggle float precision testing. (Default: on)\n"); - vlog("\t\t-g\tToggle half precision testing. (Default: on if khr_fp_16 " - "on)\n"); - vlog("\t\t-r\tToggle fast relaxed math precision testing. (Default: on)\n"); - vlog("\t\t-e\tToggle test as derived implementations for fast relaxed math " - "precision. (Default: on)\n"); - vlog("\t\t-h\tPrint this message and quit\n"); - vlog("\t\t-p\tPrint all math function names and quit\n"); - vlog("\t\t-l\tlink check only (make sure functions are present, skip " - "accuracy checks.)\n"); - vlog("\t\t-m\tToggle run multi-threaded. (Default: on) )\n"); - vlog("\t\t-s\tStop on error\n"); - vlog("\t\t-[2^n]\tSet wimpy reduction factor, recommended range of n is " - "1-10, default factor(%u)\n", - gWimpyReductionFactor); - vlog("\t\t-b\tFill buffers on host instead of device. (Default: off)\n"); - vlog("\t\t-z\tToggle FTZ mode (Section 6.5.3) for all functions. (Set by " - "device capabilities by default.)\n"); - vlog("\t\t-v\tToggle Verbosity (Default: off)\n "); - vlog("\t\t-#\tTest only vector sizes #, e.g. \"-1\" tests scalar only, " - "\"-16\" tests 16-wide vectors only.\n"); - vlog("\n\tYou may also pass a number instead of a function name.\n"); - vlog("\tThis causes the first N tests to be skipped. The tests are " - "numbered.\n"); - vlog("\tIf you pass a second number, that is the number tests to run after " - "the first one.\n"); - vlog("\tA name list may be used in conjunction with a number range. In " - "that case,\n"); - vlog("\tonly the named cases in the number range will run.\n"); - vlog("\tYou may also choose to pass no arguments, in which case all tests " - "will be run.\n"); - vlog("\tYou may pass CL_DEVICE_TYPE_CPU/GPU/ACCELERATOR to select the " - "device.\n"); - vlog("\n"); + return TEST_PASS; } static void CL_CALLBACK bruteforce_notify_callback(const char *errinfo, @@ -674,6 +586,10 @@ test_status InitCL(cl_device_id device) uint32_t i; cl_device_type device_type; + // This takes a while, so prevent the machine from going to sleep. + PreventSleep(); + atexit(ResumeSleep); + error = clGetDeviceInfo(device, CL_DEVICE_TYPE, sizeof(device_type), &device_type, NULL); if (error) diff --git a/test_conformance/printf/test_printf.cpp b/test_conformance/printf/test_printf.cpp index 9cd9db0045..849d4e875e 100644 --- a/test_conformance/printf/test_printf.cpp +++ b/test_conformance/printf/test_printf.cpp @@ -1016,89 +1016,13 @@ REGISTER_TEST(buffer_size) return TEST_PASS; } -//----------------------------------------- -// printUsage -//----------------------------------------- -static void printUsage(void) -{ - log_info("test_printf: \n"); - log_info("\tdefault is to run the full test on the default device\n"); - log_info("\n"); - for (size_t i = 0; i < test_registry::getInstance().num_tests(); i++) - { - log_info("\t%s\n", test_registry::getInstance().definitions()[i].name); - } -} - //----------------------------------------- // main //----------------------------------------- int main(int argc, const char* argv[]) { - argc = parseCustomParam(argc, argv); - if (argc == -1) - { - return -1; - } - - const char ** argList = (const char **)calloc( argc, sizeof( char*) ); - - if( NULL == argList ) - { - log_error( "Failed to allocate memory for argList array.\n" ); - return 1; - } - - argList[0] = argv[0]; - size_t argCount = 1; - - for (int i=1; i < argc; ++i) { - const char *arg = argv[i]; - if (arg == NULL) - break; - - if (arg[0] == '-') - { - arg++; - while(*arg != '\0') - { - switch(*arg) { - case 'h': - printUsage(); - return 0; - default: - log_error( " <-- unknown flag: %c (0x%2.2x)\n)", *arg, *arg ); - printUsage(); - return 0; - } - arg++; - } - } - else { - argList[argCount] = arg; - argCount++; - } - } - - char* pcTempFname = get_temp_filename(); - if (pcTempFname != nullptr) - { - strncpy(gFileName, pcTempFname, sizeof(gFileName) - 1); - gFileName[sizeof(gFileName) - 1] = '\0'; - } - - free(pcTempFname); - - if (strlen(gFileName) == 0) - { - log_error("get_temp_filename failed\n"); - return -1; - } - - gMTdata = MTdataHolder(gRandomSeed); - int err = runTestHarnessWithCheck( - argCount, argList, test_registry::getInstance().num_tests(), + argc, argv, test_registry::getInstance().num_tests(), test_registry::getInstance().definitions(), true, 0, InitCL); if (gQueue) @@ -1114,13 +1038,29 @@ int main(int argc, const char* argv[]) if (gContext && clReleaseContext(gContext) != CL_SUCCESS) log_error("clReleaseContext\n"); - free(argList); remove(gFileName); return err; } test_status InitCL( cl_device_id device ) { + char* pcTempFname = get_temp_filename(); + if (pcTempFname != nullptr) + { + strncpy(gFileName, pcTempFname, sizeof(gFileName) - 1); + gFileName[sizeof(gFileName) - 1] = '\0'; + } + + free(pcTempFname); + + if (strlen(gFileName) == 0) + { + log_error("get_temp_filename failed\n"); + return TEST_FAIL; + } + + gMTdata = MTdataHolder(gRandomSeed); + uint32_t device_frequency = 0; uint32_t compute_devices = 0; diff --git a/test_conformance/select/test_select.cpp b/test_conformance/select/test_select.cpp index bec85e12d3..7dca37579c 100644 --- a/test_conformance/select/test_select.cpp +++ b/test_conformance/select/test_select.cpp @@ -63,9 +63,6 @@ static cl_program makeSelectProgram(cl_kernel *kernel_ptr, cl_context context, static int doTest(cl_command_queue queue, cl_context context, Type stype, Type cmptype, cl_device_id device); - -static void printUsage( void ); - //----------------------------------------- // Definitions and initializations //----------------------------------------- @@ -571,26 +568,16 @@ REGISTER_TEST(select_double_long) return doTest(queue, context, kdouble, klong, device); } -int main(int argc, const char* argv[]) +static test_status parseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help) { - test_start(); + help = "\t-[2^n] Set wimpy reduction factor, recommended range of n is " + "1-12, default factor(" + + std::to_string(s_wimpy_reduction_factor) + ")\n"; - argc = parseCustomParam(argc, argv); - if (argc == -1) - { - return EXIT_FAILURE; - } - - const char ** argList = (const char **)calloc( argc, sizeof( char*) ); - - if( NULL == argList ) - { - log_error( "Failed to allocate memory for argList array.\n" ); - return 1; - } - - argList[0] = argv[0]; - size_t argCount = 1; + std::vector argList; + argList.push_back(argv[0]); for( int i = 1; i < argc; ++i ) { @@ -605,7 +592,6 @@ int main(int argc, const char* argv[]) { switch (*arg) { - case 'h': printUsage(); return 0; case '[': parseWimpyReductionFactor(arg, s_wimpy_reduction_factor); break; @@ -614,15 +600,15 @@ int main(int argc, const char* argv[]) } arg++; } + removed_args.push_back(argv[i]); } else { - argList[argCount] = arg; - argCount++; + argList.push_back(argv[i]); } } - if (gWimpyMode && !gListTests) + if (gWimpyMode) { log_info("\n"); log_info("*** WARNING: Testing in Wimpy mode! ***\n"); @@ -631,24 +617,16 @@ int main(int argc, const char* argv[]) log_info("*** Wimpy Reduction Factor: %-27u ***\n\n", s_wimpy_reduction_factor); } - int err = runTestHarness( - argCount, argList, test_registry::getInstance().num_tests(), - test_registry::getInstance().definitions(), false, 0); - - free( argList ); - - return err; + update_argc_argv_from_args_list(argList, argc, argv); + return TEST_PASS; } -static void printUsage( void ) +int main(int argc, const char *argv[]) { - log_info("test_select: [-w] \n"); - log_info("\tdefault is to run the full test on the default device\n"); - log_info("\t-[2^n] Set wimpy reduction factor, recommended range of n is 1-12, default factor(%u)\n", s_wimpy_reduction_factor); - log_info("\n"); - log_info("Test names:\n"); - for (size_t i = 0; i < test_registry::getInstance().num_tests(); i++) - { - log_info("\t%s\n", test_registry::getInstance().definitions()[i].name); - } + test_start(); + + return runTestHarnessWithCheckAndParse( + argc, argv, test_registry::getInstance().num_tests(), + test_registry::getInstance().definitions(), false, 0, nullptr, + parseArgs); } diff --git a/test_conformance/spirv_new/main.cpp b/test_conformance/spirv_new/main.cpp index b5421f9203..3d2e75a9db 100644 --- a/test_conformance/spirv_new/main.cpp +++ b/test_conformance/spirv_new/main.cpp @@ -204,53 +204,63 @@ test_status InitCL(cl_device_id id) return TEST_PASS; } -void printUsage() { - log_info("Reading SPIR-V files from default '%s' path.\n", spvBinariesPath.c_str()); - log_info("In case you want to set other directory use '%s' argument.\n", - spvBinariesPathArg.c_str()); - log_info("To skip the SPIR-V version check use the '%s' argument.\n", - spvVersionSkipArg.c_str()); -} - -int main(int argc, const char *argv[]) +static test_status parseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help) { - gReSeed = 1; + help = " " + spvBinariesPathArg + + " - Set path to read SPIR-V files from (default: " + + spvBinariesPath + ")\n" + " " + spvVersionSkipArg + + " - Skip the SPIR-V version check\n"; + bool modifiedSpvBinariesPath = false; - bool listTests = false; - for (int i = 0; i < argc; ++i) { - int argsRemoveNum = 0; - if (argv[i] == spvBinariesPathArg) { - if (i + 1 == argc) { - log_error("Missing value for '%s' argument.\n", spvBinariesPathArg.c_str()); + std::vector argList; + argList.push_back(argv[0]); + + for (int i = 1; i < argc; ++i) + { + if (argv[i] == spvBinariesPathArg) + { + if (i + 1 >= argc || argv[i + 1] == NULL) + { + log_error("Missing value for '%s' argument.\n", + spvBinariesPathArg.c_str()); return TEST_FAIL; - } else { - spvBinariesPath = std::string(argv[i + 1]); - argsRemoveNum += 2; - modifiedSpvBinariesPath = true; } + spvBinariesPath = std::string(argv[i + 1]); + removed_args.push_back(std::string(argv[i]) + " " + argv[i + 1]); + modifiedSpvBinariesPath = true; + ++i; // skip the value } - if (argv[i] == spvVersionSkipArg) + else if (argv[i] == spvVersionSkipArg) { gVersionSkip = true; - argsRemoveNum++; + removed_args.push_back(argv[i]); } - - if (argsRemoveNum > 0) { - for (int j = i; j < (argc - argsRemoveNum); ++j) - argv[j] = argv[j + argsRemoveNum]; - - argc -= argsRemoveNum; - --i; + else + { + argList.push_back(argv[i]); } - listTests |= (argv[i] == std::string("--list") - || argv[i] == std::string("-list")); } - if (modifiedSpvBinariesPath == false && !listTests) + + if (!modifiedSpvBinariesPath && !gListTests) { - printUsage(); + log_info("Reading SPIR-V files from default '%s' path.\n", + spvBinariesPath.c_str()); + log_info("In case you want to set other directory use '%s' argument.\n", + spvBinariesPathArg.c_str()); } - return runTestHarnessWithCheck( + update_argc_argv_from_args_list(argList, argc, argv); + return TEST_PASS; +} + +int main(int argc, const char *argv[]) +{ + gReSeed = 1; + + return runTestHarnessWithCheckAndParse( argc, argv, test_registry::getInstance().num_tests(), - test_registry::getInstance().definitions(), false, 0, InitCL); + test_registry::getInstance().definitions(), false, 0, InitCL, + parseArgs); } diff --git a/test_conformance/thread_dimensions/main.cpp b/test_conformance/thread_dimensions/main.cpp index 6aa573d3ce..38e7377348 100644 --- a/test_conformance/thread_dimensions/main.cpp +++ b/test_conformance/thread_dimensions/main.cpp @@ -24,59 +24,83 @@ cl_uint maxThreadDimension = 0; cl_uint bufferSize = 0; cl_uint bufferStep = 0; -int main(int argc, const char *argv[]) +static test_status parseArgs(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help) { - int delArg = 0; - for (auto i = 0; i < argc; i++) - { - delArg = 0; + help = R"( -n Maximum thread dimension value + -b Specifies a buffer size for calculations + -x Specifies a step for calculations +)"; - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) - { - log_info("Thread dimensions options:\n"); - log_info("\t-n\tMaximum thread dimension value\n"); - log_info("\t-b\tSpecifies a buffer size for calculations\n"); - log_info("\t-x\tSpecifies a step for calculations\n"); - } + std::vector argList; + argList.push_back(argv[0]); + + for (int i = 1; i < argc; i++) + { if (strcmp(argv[i], "-n") == 0) { - delArg++; + if (i + 1 >= argc || argv[i + 1] == NULL) + { + log_info("ERROR: -n Maximum thread dimension value missing\n"); + return TEST_FAIL; + } if (atoi(argv[i + 1]) < 1) { log_info("ERROR: -n Maximum thread dimension value must be " - "greater than 0"); + "greater than 0\n"); return TEST_FAIL; } maxThreadDimension = atoi(argv[i + 1]); - delArg++; + removed_args.push_back(std::string(argv[i]) + " " + argv[i + 1]); + i++; } - if (strcmp(argv[i], "-b") == 0) + else if (strcmp(argv[i], "-b") == 0) { - delArg++; + if (i + 1 >= argc || argv[i + 1] == NULL) + { + log_info("ERROR: -b Buffer size missing\n"); + return TEST_FAIL; + } if (atoi(argv[i + 1]) < 1) { - log_info("ERROR: -b Buffer size must be greater than 0"); + log_info("ERROR: -b Buffer size must be greater than 0\n"); return TEST_FAIL; } bufferSize = atoi(argv[i + 1]); - delArg++; + removed_args.push_back(std::string(argv[i]) + " " + argv[i + 1]); + i++; } - if (strcmp(argv[i], "-x") == 0) + else if (strcmp(argv[i], "-x") == 0) { - delArg++; + if (i + 1 >= argc || argv[i + 1] == NULL) + { + log_info("ERROR: -x Buffer step missing\n"); + return TEST_FAIL; + } if (atoi(argv[i + 1]) < 1) { - log_info("ERROR: -x Buffer step must be greater than 0"); + log_info("ERROR: -x Buffer step must be greater than 0\n"); return TEST_FAIL; } bufferStep = atoi(argv[i + 1]); - delArg++; + removed_args.push_back(std::string(argv[i]) + " " + argv[i + 1]); + i++; + } + else + { + argList.push_back(argv[i]); } - for (int j = i; j < argc - delArg; j++) argv[j] = argv[j + delArg]; - argc -= delArg; - i -= delArg; } - return runTestHarness(argc, argv, test_registry::getInstance().num_tests(), - test_registry::getInstance().definitions(), false, 0); + update_argc_argv_from_args_list(argList, argc, argv); + return TEST_PASS; +} + +int main(int argc, const char *argv[]) +{ + return runTestHarnessWithCheckAndParse( + argc, argv, test_registry::getInstance().num_tests(), + test_registry::getInstance().definitions(), false, 0, nullptr, + parseArgs); } diff --git a/test_conformance/vulkan/main.cpp b/test_conformance/vulkan/main.cpp index 85c1c7dbdb..d69b26ffb5 100644 --- a/test_conformance/vulkan/main.cpp +++ b/test_conformance/vulkan/main.cpp @@ -31,7 +31,6 @@ #endif #include "harness/testHarness.h" -#include "harness/parseParameters.h" unsigned int numCQ; bool multiImport; @@ -43,31 +42,6 @@ bool useValidationLayers = false; bool disableNTHandleType = false; bool enableOffset = false; -static void printUsage(const char *execName) -{ - const char *p = strrchr(execName, '/'); - if (p != NULL) execName = p + 1; - - log_info("Usage: %s [test_names] [options]\n", execName); - log_info("Test names:\n"); - for (unsigned int i = 0; i < test_registry::getInstance().num_tests(); i++) - { - log_info("\t%s\n", test_registry::getInstance().definitions()[i].name); - } - log_info("\n"); - log_info("Options:\n"); - log_info("\t--debug_trace - Enables additional debug info logging\n"); - log_info("\t--useSingleImageKernel - Use the same image " - "(image_single_queue and image_multiple_queue tests)\n"); - log_info("\t--disableDeviceLocal - Skip tests that use images with local " - "memory type\n"); - log_info("\t--disableNTHandleType - Skip tests that use win32 external " - "memory handle\n"); - log_info("\t--useValidationLayers - Enables Vulkan validation layer " - "diagnostic output\n"); - log_info("\t-h - Print test usage\n"); -} - bool isDeviceSelection(const char *arg) { @@ -80,47 +54,43 @@ bool isDeviceSelection(const char *arg) || strcmp(arg, "CL_DEVICE_TYPE_DEFAULT") == 0; } -void parseParams(int &argc, const char *argv[]) +static test_status parseParams(int &argc, const char *argv[], + std::vector &removed_args, + std::string &help) { - argc = parseCustomParam(argc, argv); - + help = R"( --debug_trace - Enables additional debug info logging + --useSingleImageKernel - Use the same image (image_single_queue and image_multiple_queue tests) + --disableDeviceLocal - Skip tests that use images with local memory type + --disableNTHandleType - Skip tests that use win32 external memory handle + --useValidationLayers - Enables Vulkan validation layer diagnostic output +)"; + + std::vector argList; for (int i = 0; i < argc; ++i) { - int argsRemoveNum = 0; - if (argv[i] == NULL) break; + removed_args.push_back(argv[i]); if (argv[i][0] == '-') { if (!strcmp(argv[i], "--debug_trace")) { debug_trace = true; - argsRemoveNum = 1; } if (!strcmp(argv[i], "--useSingleImageKernel")) { useSingleImageKernel = true; - argsRemoveNum = 1; } if (!strcmp(argv[i], "--disableDeviceLocal")) { useDeviceLocal = false; - argsRemoveNum = 1; } if (!strcmp(argv[i], "--useValidationLayers")) { useValidationLayers = true; - argsRemoveNum = 1; } if (!strcmp(argv[i], "--disableNTHandleType")) { disableNTHandleType = true; - argsRemoveNum = 1; - } - if (strcmp(argv[i], "-h") == 0) - { - printUsage(argv[0]); - argc = 0; // Returning argCount=0 to assert error in main() - return; } } else if (isDeviceSelection(argv[i])) @@ -130,20 +100,17 @@ void parseParams(int &argc, const char *argv[]) && strcmp(argv[i], "CL_DEVICE_TYPE_DEFAULT") != 0) { log_info("Vulkan tests can only run on a GPU device.\n"); - argc = 0; - return; + return TEST_FAIL; } } - - if (argsRemoveNum > 0) + else { - for (int j = i; j < (argc - argsRemoveNum); ++j) - argv[j] = argv[j + argsRemoveNum]; - - argc -= argsRemoveNum; - --i; + removed_args.pop_back(); + argList.push_back(argv[i]); } } + update_argc_argv_from_args_list(argList, argc, argv); + return TEST_PASS; } int main(int argc, const char *argv[]) @@ -173,10 +140,8 @@ int main(int argc, const char *argv[]) return 0; } - parseParams(argc, argv); - - if (argc == 0) return 0; - - return runTestHarness(argc, argv, test_registry::getInstance().num_tests(), - test_registry::getInstance().definitions(), false, 0); + return runTestHarnessWithCheckAndParse( + argc, argv, test_registry::getInstance().num_tests(), + test_registry::getInstance().definitions(), false, 0, nullptr, + parseParams); }