Chromium Code Reviews| Index: third_party/qcms/src/tests/qcms_test_main.c |
| diff --git a/third_party/qcms/src/tests/qcms_test_main.c b/third_party/qcms/src/tests/qcms_test_main.c |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..54920363b64e3c7efd7e074819ade1a986c7c885 |
| --- /dev/null |
| +++ b/third_party/qcms/src/tests/qcms_test_main.c |
| @@ -0,0 +1,131 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the Chromium LICENSE file. |
| + |
| +#include "qcms.h" |
| +#include "qcms_test_util.h" |
| +#include "timing.h" |
| + |
| +#include <math.h> |
| +#include <stdio.h> |
| +#include <stdlib.h> |
| +#include <string.h> |
| + |
| +// Manually update the items below to add more tests. |
| +extern struct qcms_test_case qcms_test_tetra_clut_rgba_info; |
| +extern struct qcms_test_case qcms_test_munsell_info; |
| + |
| +struct qcms_test_case qcms_test[2]; |
| +#define TEST_CASES (sizeof(qcms_test) / sizeof(qcms_test[0])) |
| + |
| +static void initialize_tests() |
| +{ |
| + qcms_test[0] = qcms_test_tetra_clut_rgba_info; |
| + qcms_test[1] = qcms_test_munsell_info; |
| +} |
| + |
| +static void list_tests() |
| +{ |
| + int i; |
| + printf("Available QCMS tests:\n"); |
|
Noel Gordon
2015/10/08 03:12:49
QCMS -> qcms
radu.velea
2015/10/08 09:39:13
Done.
|
| + |
| + for (i = 0; i < TEST_CASES; ++i) { |
| + printf("\t%s\n", qcms_test[i].test_name); |
| + } |
| + |
| + exit(1); |
| +} |
| + |
| +static void print_usage() |
| +{ |
| + printf("Usage:\n\tqcms_test -w WIDTH -h HEIGHT -n ITERATIONS -t TEST\n"); |
| + printf("\t-w INT\t\ttest image width\n"); |
| + printf("\t-h INT\t\ttest image height\n"); |
| + printf("\t-n INT\t\tnumber of iterations for each test\n"); |
| + printf("\t-a\t\trun all tests\n"); |
| + printf("\t-l\t\tlist available tests\n"); |
| + printf("\t-s \t\tforce software(non-sse) transform function, where available\n"); |
| + printf("\t-i STRING\tspecify input icc color profile\n"); |
| + printf("\t-o STRING\tspecify output icc color profile\n"); |
| + printf("\t-t STRING\trun specific test - use \"-l\" to list possible values\n"); |
| + printf("\n"); |
| + exit(1); |
| +} |
| + |
| +int enable_test(const char *args) |
| +{ |
| + int i; |
| + |
| + for (i = 0; i < TEST_CASES; ++i) { |
|
Noel Gordon
2015/10/08 03:12:49
% ./out/Release/qcms_tests -t
Segmentation fault
radu.velea
2015/10/08 09:39:12
Done.
|
| + if (strcmp(qcms_test[i].test_name, args) == 0) { |
| + qcms_test[i].status = QCMS_TEST_ENABLED; |
| + return 1; |
| + } |
| + } |
| + |
| + return 0; |
| +} |
| + |
| +void generate_source_uint8_t(unsigned char *src, const size_t length, const size_t pixel_size) |
| +{ |
| + size_t bytes = length * pixel_size; |
| + size_t i; |
| + |
| + for (i = 0; i < bytes; ++i) { |
| + *src++ = rand() & 255; |
| + } |
| +} |
| + |
| +int main(int argc, const char **argv) |
| +{ |
| + int iterations = 1; |
| + size_t height = 2000; |
| + size_t width = 2000; |
| + int run_all = 0; |
| + const char *in = NULL, *out = NULL; |
| + int force_software = 0; |
| + int exit_status; |
| + int enabled_tests = 0; |
| + int i; |
| + |
| + initialize_tests(); |
| + |
| + if (argc == 1) { |
| + print_usage(); |
| + } |
| + |
| + while (argc > 1) { |
| + if (strcmp(argv[1], "-n") == 0) |
| + iterations = abs(atoi(argv[2])); |
| + else if (strcmp(argv[1], "-w") == 0) |
| + width = (size_t) abs(atoi(argv[2])); |
| + else if (strcmp(argv[1], "-h") == 0) |
| + height = (size_t) abs(atoi(argv[2])); |
| + else if (strcmp(argv[1], "-l") == 0) |
| + list_tests(); |
| + else if (strcmp(argv[1], "-t") == 0) |
| + enabled_tests += enable_test(argv[2]); |
|
Noel Gordon
2015/10/08 03:12:49
Use spaces (not tabs) here. (git apply complains).
radu.velea
2015/10/08 09:39:13
Done.
|
| + else if (strcmp(argv[1], "-a") == 0) |
| + run_all = 1; |
| + else if (strcmp(argv[1], "-i") == 0) |
| + in = argv[2]; |
| + else if (strcmp(argv[1], "-o") == 0) |
| + out = argv[2]; |
| + else if (strcmp(argv[1], "-s") == 0) |
| + force_software = 1; |
| + (--argc, ++argv); |
| + } |
| + |
| + if (!run_all && !enabled_tests) { |
| + print_usage(); |
|
Noel Gordon
2015/10/08 03:12:49
Use spaces (not tabs) here. (git apply complains).
radu.velea
2015/10/08 09:39:12
Done.
|
| + } |
| + |
| + exit_status = 0; |
| + |
| + for (i = 0; i < TEST_CASES; ++i) { |
| + if (run_all || QCMS_TEST_ENABLED == qcms_test[i].status) |
| + exit_status += qcms_test[i].test_fn(width, height, iterations, in, out, force_software); |
|
Noel Gordon
2015/10/08 03:12:49
Use spaces (not tabs) here. (git apply complains).
radu.velea
2015/10/08 09:39:12
Done.
|
| + } |
| + |
| + return exit_status; |
| +} |