You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

698 lines
19KB

  1. /*
  2. * Assembly testing and benchmarking tool
  3. * Copyright (c) 2015 Henrik Gramner
  4. * Copyright (c) 2008 Loren Merritt
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #include <stdarg.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include "checkasm.h"
  27. #include "libavutil/common.h"
  28. #include "libavutil/cpu.h"
  29. #include "libavutil/intfloat.h"
  30. #include "libavutil/random_seed.h"
  31. #if HAVE_IO_H
  32. #include <io.h>
  33. #endif
  34. #if HAVE_SETCONSOLETEXTATTRIBUTE
  35. #include <windows.h>
  36. #define COLOR_RED FOREGROUND_RED
  37. #define COLOR_GREEN FOREGROUND_GREEN
  38. #define COLOR_YELLOW (FOREGROUND_RED|FOREGROUND_GREEN)
  39. #else
  40. #define COLOR_RED 1
  41. #define COLOR_GREEN 2
  42. #define COLOR_YELLOW 3
  43. #endif
  44. #if HAVE_UNISTD_H
  45. #include <unistd.h>
  46. #endif
  47. #if !HAVE_ISATTY
  48. #define isatty(fd) 1
  49. #endif
  50. #if ARCH_ARM && HAVE_ARMV5TE_EXTERNAL
  51. #include "libavutil/arm/cpu.h"
  52. void (*checkasm_checked_call)(void *func, int dummy, ...) = checkasm_checked_call_novfp;
  53. #endif
  54. /* List of tests to invoke */
  55. static const struct {
  56. const char *name;
  57. void (*func)(void);
  58. } tests[] = {
  59. #if CONFIG_AVCODEC
  60. #if CONFIG_ALAC_DECODER
  61. { "alacdsp", checkasm_check_alacdsp },
  62. #endif
  63. #if CONFIG_AUDIODSP
  64. { "audiodsp", checkasm_check_audiodsp },
  65. #endif
  66. #if CONFIG_BLOCKDSP
  67. { "blockdsp", checkasm_check_blockdsp },
  68. #endif
  69. #if CONFIG_BSWAPDSP
  70. { "bswapdsp", checkasm_check_bswapdsp },
  71. #endif
  72. #if CONFIG_DCA_DECODER
  73. { "synth_filter", checkasm_check_synth_filter },
  74. #endif
  75. #if CONFIG_FLACDSP
  76. { "flacdsp", checkasm_check_flacdsp },
  77. #endif
  78. #if CONFIG_FMTCONVERT
  79. { "fmtconvert", checkasm_check_fmtconvert },
  80. #endif
  81. #if CONFIG_H264DSP
  82. { "h264dsp", checkasm_check_h264dsp },
  83. #endif
  84. #if CONFIG_H264PRED
  85. { "h264pred", checkasm_check_h264pred },
  86. #endif
  87. #if CONFIG_H264QPEL
  88. { "h264qpel", checkasm_check_h264qpel },
  89. #endif
  90. #if CONFIG_HEVC_DECODER
  91. { "hevc_add_res", checkasm_check_hevc_add_res },
  92. { "hevc_idct", checkasm_check_hevc_idct },
  93. #endif
  94. #if CONFIG_JPEG2000_DECODER
  95. { "jpeg2000dsp", checkasm_check_jpeg2000dsp },
  96. #endif
  97. #if CONFIG_HUFFYUVDSP
  98. { "llviddsp", checkasm_check_llviddsp },
  99. #endif
  100. #if CONFIG_PIXBLOCKDSP
  101. { "pixblockdsp", checkasm_check_pixblockdsp },
  102. #endif
  103. #if CONFIG_V210_ENCODER
  104. { "v210enc", checkasm_check_v210enc },
  105. #endif
  106. #if CONFIG_VP8DSP
  107. { "vp8dsp", checkasm_check_vp8dsp },
  108. #endif
  109. #if CONFIG_VP9_DECODER
  110. { "vp9dsp", checkasm_check_vp9dsp },
  111. #endif
  112. #if CONFIG_VIDEODSP
  113. { "videodsp", checkasm_check_videodsp },
  114. #endif
  115. #endif
  116. #if CONFIG_AVFILTER
  117. #if CONFIG_BLEND_FILTER
  118. { "vf_blend", checkasm_check_blend },
  119. #endif
  120. #if CONFIG_COLORSPACE_FILTER
  121. { "vf_colorspace", checkasm_check_colorspace },
  122. #endif
  123. #endif
  124. #if CONFIG_AVUTIL
  125. { "fixed_dsp", checkasm_check_fixed_dsp },
  126. #endif
  127. { NULL }
  128. };
  129. /* List of cpu flags to check */
  130. static const struct {
  131. const char *name;
  132. const char *suffix;
  133. int flag;
  134. } cpus[] = {
  135. #if ARCH_AARCH64
  136. { "ARMV8", "armv8", AV_CPU_FLAG_ARMV8 },
  137. { "NEON", "neon", AV_CPU_FLAG_NEON },
  138. #elif ARCH_ARM
  139. { "ARMV5TE", "armv5te", AV_CPU_FLAG_ARMV5TE },
  140. { "ARMV6", "armv6", AV_CPU_FLAG_ARMV6 },
  141. { "ARMV6T2", "armv6t2", AV_CPU_FLAG_ARMV6T2 },
  142. { "VFP", "vfp", AV_CPU_FLAG_VFP },
  143. { "VFP_VM", "vfp_vm", AV_CPU_FLAG_VFP_VM },
  144. { "VFPV3", "vfp3", AV_CPU_FLAG_VFPV3 },
  145. { "NEON", "neon", AV_CPU_FLAG_NEON },
  146. #elif ARCH_PPC
  147. { "ALTIVEC", "altivec", AV_CPU_FLAG_ALTIVEC },
  148. { "VSX", "vsx", AV_CPU_FLAG_VSX },
  149. { "POWER8", "power8", AV_CPU_FLAG_POWER8 },
  150. #elif ARCH_X86
  151. { "MMX", "mmx", AV_CPU_FLAG_MMX|AV_CPU_FLAG_CMOV },
  152. { "MMXEXT", "mmxext", AV_CPU_FLAG_MMXEXT },
  153. { "3DNOW", "3dnow", AV_CPU_FLAG_3DNOW },
  154. { "3DNOWEXT", "3dnowext", AV_CPU_FLAG_3DNOWEXT },
  155. { "SSE", "sse", AV_CPU_FLAG_SSE },
  156. { "SSE2", "sse2", AV_CPU_FLAG_SSE2|AV_CPU_FLAG_SSE2SLOW },
  157. { "SSE3", "sse3", AV_CPU_FLAG_SSE3|AV_CPU_FLAG_SSE3SLOW },
  158. { "SSSE3", "ssse3", AV_CPU_FLAG_SSSE3|AV_CPU_FLAG_ATOM },
  159. { "SSE4.1", "sse4", AV_CPU_FLAG_SSE4 },
  160. { "SSE4.2", "sse42", AV_CPU_FLAG_SSE42 },
  161. { "AES-NI", "aesni", AV_CPU_FLAG_AESNI },
  162. { "AVX", "avx", AV_CPU_FLAG_AVX },
  163. { "XOP", "xop", AV_CPU_FLAG_XOP },
  164. { "FMA3", "fma3", AV_CPU_FLAG_FMA3 },
  165. { "FMA4", "fma4", AV_CPU_FLAG_FMA4 },
  166. { "AVX2", "avx2", AV_CPU_FLAG_AVX2 },
  167. #endif
  168. { NULL }
  169. };
  170. typedef struct CheckasmFuncVersion {
  171. struct CheckasmFuncVersion *next;
  172. void *func;
  173. int ok;
  174. int cpu;
  175. int iterations;
  176. uint64_t cycles;
  177. } CheckasmFuncVersion;
  178. /* Binary search tree node */
  179. typedef struct CheckasmFunc {
  180. struct CheckasmFunc *child[2];
  181. CheckasmFuncVersion versions;
  182. uint8_t color; /* 0 = red, 1 = black */
  183. char name[1];
  184. } CheckasmFunc;
  185. /* Internal state */
  186. static struct {
  187. CheckasmFunc *funcs;
  188. CheckasmFunc *current_func;
  189. CheckasmFuncVersion *current_func_ver;
  190. const char *current_test_name;
  191. const char *bench_pattern;
  192. int bench_pattern_len;
  193. int num_checked;
  194. int num_failed;
  195. int nop_time;
  196. int cpu_flag;
  197. const char *cpu_flag_name;
  198. const char *test_name;
  199. } state;
  200. /* PRNG state */
  201. AVLFG checkasm_lfg;
  202. /* float compare support code */
  203. static int is_negative(union av_intfloat32 u)
  204. {
  205. return u.i >> 31;
  206. }
  207. int float_near_ulp(float a, float b, unsigned max_ulp)
  208. {
  209. union av_intfloat32 x, y;
  210. x.f = a;
  211. y.f = b;
  212. if (is_negative(x) != is_negative(y)) {
  213. // handle -0.0 == +0.0
  214. return a == b;
  215. }
  216. if (llabs((int64_t)x.i - y.i) <= max_ulp)
  217. return 1;
  218. return 0;
  219. }
  220. int float_near_ulp_array(const float *a, const float *b, unsigned max_ulp,
  221. unsigned len)
  222. {
  223. unsigned i;
  224. for (i = 0; i < len; i++) {
  225. if (!float_near_ulp(a[i], b[i], max_ulp))
  226. return 0;
  227. }
  228. return 1;
  229. }
  230. int float_near_abs_eps(float a, float b, float eps)
  231. {
  232. float abs_diff = fabsf(a - b);
  233. return abs_diff < eps;
  234. }
  235. int float_near_abs_eps_array(const float *a, const float *b, float eps,
  236. unsigned len)
  237. {
  238. unsigned i;
  239. for (i = 0; i < len; i++) {
  240. if (!float_near_abs_eps(a[i], b[i], eps))
  241. return 0;
  242. }
  243. return 1;
  244. }
  245. int float_near_abs_eps_ulp(float a, float b, float eps, unsigned max_ulp)
  246. {
  247. return float_near_ulp(a, b, max_ulp) || float_near_abs_eps(a, b, eps);
  248. }
  249. int float_near_abs_eps_array_ulp(const float *a, const float *b, float eps,
  250. unsigned max_ulp, unsigned len)
  251. {
  252. unsigned i;
  253. for (i = 0; i < len; i++) {
  254. if (!float_near_abs_eps_ulp(a[i], b[i], eps, max_ulp))
  255. return 0;
  256. }
  257. return 1;
  258. }
  259. /* Print colored text to stderr if the terminal supports it */
  260. static void color_printf(int color, const char *fmt, ...)
  261. {
  262. static int use_color = -1;
  263. va_list arg;
  264. #if HAVE_SETCONSOLETEXTATTRIBUTE
  265. static HANDLE con;
  266. static WORD org_attributes;
  267. if (use_color < 0) {
  268. CONSOLE_SCREEN_BUFFER_INFO con_info;
  269. con = GetStdHandle(STD_ERROR_HANDLE);
  270. if (con && con != INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo(con, &con_info)) {
  271. org_attributes = con_info.wAttributes;
  272. use_color = 1;
  273. } else
  274. use_color = 0;
  275. }
  276. if (use_color)
  277. SetConsoleTextAttribute(con, (org_attributes & 0xfff0) | (color & 0x0f));
  278. #else
  279. if (use_color < 0) {
  280. const char *term = getenv("TERM");
  281. use_color = term && strcmp(term, "dumb") && isatty(2);
  282. }
  283. if (use_color)
  284. fprintf(stderr, "\x1b[%d;3%dm", (color & 0x08) >> 3, color & 0x07);
  285. #endif
  286. va_start(arg, fmt);
  287. vfprintf(stderr, fmt, arg);
  288. va_end(arg);
  289. if (use_color) {
  290. #if HAVE_SETCONSOLETEXTATTRIBUTE
  291. SetConsoleTextAttribute(con, org_attributes);
  292. #else
  293. fprintf(stderr, "\x1b[0m");
  294. #endif
  295. }
  296. }
  297. /* Deallocate a tree */
  298. static void destroy_func_tree(CheckasmFunc *f)
  299. {
  300. if (f) {
  301. CheckasmFuncVersion *v = f->versions.next;
  302. while (v) {
  303. CheckasmFuncVersion *next = v->next;
  304. free(v);
  305. v = next;
  306. }
  307. destroy_func_tree(f->child[0]);
  308. destroy_func_tree(f->child[1]);
  309. free(f);
  310. }
  311. }
  312. /* Allocate a zero-initialized block, clean up and exit on failure */
  313. static void *checkasm_malloc(size_t size)
  314. {
  315. void *ptr = calloc(1, size);
  316. if (!ptr) {
  317. fprintf(stderr, "checkasm: malloc failed\n");
  318. destroy_func_tree(state.funcs);
  319. exit(1);
  320. }
  321. return ptr;
  322. }
  323. /* Get the suffix of the specified cpu flag */
  324. static const char *cpu_suffix(int cpu)
  325. {
  326. int i = FF_ARRAY_ELEMS(cpus);
  327. while (--i >= 0)
  328. if (cpu & cpus[i].flag)
  329. return cpus[i].suffix;
  330. return "c";
  331. }
  332. #ifdef AV_READ_TIME
  333. static int cmp_nop(const void *a, const void *b)
  334. {
  335. return *(const uint16_t*)a - *(const uint16_t*)b;
  336. }
  337. /* Measure the overhead of the timing code (in decicycles) */
  338. static int measure_nop_time(void)
  339. {
  340. uint16_t nops[10000];
  341. int i, nop_sum = 0;
  342. for (i = 0; i < 10000; i++) {
  343. uint64_t t = AV_READ_TIME();
  344. nops[i] = AV_READ_TIME() - t;
  345. }
  346. qsort(nops, 10000, sizeof(uint16_t), cmp_nop);
  347. for (i = 2500; i < 7500; i++)
  348. nop_sum += nops[i];
  349. return nop_sum / 500;
  350. }
  351. /* Print benchmark results */
  352. static void print_benchs(CheckasmFunc *f)
  353. {
  354. if (f) {
  355. print_benchs(f->child[0]);
  356. /* Only print functions with at least one assembly version */
  357. if (f->versions.cpu || f->versions.next) {
  358. CheckasmFuncVersion *v = &f->versions;
  359. do {
  360. if (v->iterations) {
  361. int decicycles = (10*v->cycles/v->iterations - state.nop_time) / 4;
  362. printf("%s_%s: %d.%d\n", f->name, cpu_suffix(v->cpu), decicycles/10, decicycles%10);
  363. }
  364. } while ((v = v->next));
  365. }
  366. print_benchs(f->child[1]);
  367. }
  368. }
  369. #endif
  370. /* ASCIIbetical sort except preserving natural order for numbers */
  371. static int cmp_func_names(const char *a, const char *b)
  372. {
  373. const char *start = a;
  374. int ascii_diff, digit_diff;
  375. for (; !(ascii_diff = *(const unsigned char*)a - *(const unsigned char*)b) && *a; a++, b++);
  376. for (; av_isdigit(*a) && av_isdigit(*b); a++, b++);
  377. if (a > start && av_isdigit(a[-1]) && (digit_diff = av_isdigit(*a) - av_isdigit(*b)))
  378. return digit_diff;
  379. return ascii_diff;
  380. }
  381. /* Perform a tree rotation in the specified direction and return the new root */
  382. static CheckasmFunc *rotate_tree(CheckasmFunc *f, int dir)
  383. {
  384. CheckasmFunc *r = f->child[dir^1];
  385. f->child[dir^1] = r->child[dir];
  386. r->child[dir] = f;
  387. r->color = f->color;
  388. f->color = 0;
  389. return r;
  390. }
  391. #define is_red(f) ((f) && !(f)->color)
  392. /* Balance a left-leaning red-black tree at the specified node */
  393. static void balance_tree(CheckasmFunc **root)
  394. {
  395. CheckasmFunc *f = *root;
  396. if (is_red(f->child[0]) && is_red(f->child[1])) {
  397. f->color ^= 1;
  398. f->child[0]->color = f->child[1]->color = 1;
  399. }
  400. if (!is_red(f->child[0]) && is_red(f->child[1]))
  401. *root = rotate_tree(f, 0); /* Rotate left */
  402. else if (is_red(f->child[0]) && is_red(f->child[0]->child[0]))
  403. *root = rotate_tree(f, 1); /* Rotate right */
  404. }
  405. /* Get a node with the specified name, creating it if it doesn't exist */
  406. static CheckasmFunc *get_func(CheckasmFunc **root, const char *name)
  407. {
  408. CheckasmFunc *f = *root;
  409. if (f) {
  410. /* Search the tree for a matching node */
  411. int cmp = cmp_func_names(name, f->name);
  412. if (cmp) {
  413. f = get_func(&f->child[cmp > 0], name);
  414. /* Rebalance the tree on the way up if a new node was inserted */
  415. if (!f->versions.func)
  416. balance_tree(root);
  417. }
  418. } else {
  419. /* Allocate and insert a new node into the tree */
  420. int name_length = strlen(name);
  421. f = *root = checkasm_malloc(sizeof(CheckasmFunc) + name_length);
  422. memcpy(f->name, name, name_length + 1);
  423. }
  424. return f;
  425. }
  426. /* Perform tests and benchmarks for the specified cpu flag if supported by the host */
  427. static void check_cpu_flag(const char *name, int flag)
  428. {
  429. int old_cpu_flag = state.cpu_flag;
  430. flag |= old_cpu_flag;
  431. av_force_cpu_flags(-1);
  432. state.cpu_flag = flag & av_get_cpu_flags();
  433. av_force_cpu_flags(state.cpu_flag);
  434. if (!flag || state.cpu_flag != old_cpu_flag) {
  435. int i;
  436. state.cpu_flag_name = name;
  437. for (i = 0; tests[i].func; i++) {
  438. if (state.test_name && strcmp(tests[i].name, state.test_name))
  439. continue;
  440. state.current_test_name = tests[i].name;
  441. tests[i].func();
  442. }
  443. }
  444. }
  445. /* Print the name of the current CPU flag, but only do it once */
  446. static void print_cpu_name(void)
  447. {
  448. if (state.cpu_flag_name) {
  449. color_printf(COLOR_YELLOW, "%s:\n", state.cpu_flag_name);
  450. state.cpu_flag_name = NULL;
  451. }
  452. }
  453. int main(int argc, char *argv[])
  454. {
  455. unsigned int seed = av_get_random_seed();
  456. int i, ret = 0;
  457. #if ARCH_ARM && HAVE_ARMV5TE_EXTERNAL
  458. if (have_vfp(av_get_cpu_flags()) || have_neon(av_get_cpu_flags()))
  459. checkasm_checked_call = checkasm_checked_call_vfp;
  460. #endif
  461. if (!tests[0].func || !cpus[0].flag) {
  462. fprintf(stderr, "checkasm: no tests to perform\n");
  463. return 0;
  464. }
  465. while (argc > 1) {
  466. if (!strncmp(argv[1], "--bench", 7)) {
  467. #ifndef AV_READ_TIME
  468. fprintf(stderr, "checkasm: --bench is not supported on your system\n");
  469. return 1;
  470. #endif
  471. if (argv[1][7] == '=') {
  472. state.bench_pattern = argv[1] + 8;
  473. state.bench_pattern_len = strlen(state.bench_pattern);
  474. } else
  475. state.bench_pattern = "";
  476. } else if (!strncmp(argv[1], "--test=", 7)) {
  477. state.test_name = argv[1] + 7;
  478. } else {
  479. seed = strtoul(argv[1], NULL, 10);
  480. }
  481. argc--;
  482. argv++;
  483. }
  484. fprintf(stderr, "checkasm: using random seed %u\n", seed);
  485. av_lfg_init(&checkasm_lfg, seed);
  486. check_cpu_flag(NULL, 0);
  487. for (i = 0; cpus[i].flag; i++)
  488. check_cpu_flag(cpus[i].name, cpus[i].flag);
  489. if (state.num_failed) {
  490. fprintf(stderr, "checkasm: %d of %d tests have failed\n", state.num_failed, state.num_checked);
  491. ret = 1;
  492. } else {
  493. fprintf(stderr, "checkasm: all %d tests passed\n", state.num_checked);
  494. #ifdef AV_READ_TIME
  495. if (state.bench_pattern) {
  496. state.nop_time = measure_nop_time();
  497. printf("nop: %d.%d\n", state.nop_time/10, state.nop_time%10);
  498. print_benchs(state.funcs);
  499. }
  500. #endif
  501. }
  502. destroy_func_tree(state.funcs);
  503. return ret;
  504. }
  505. /* Decide whether or not the specified function needs to be tested and
  506. * allocate/initialize data structures if needed. Returns a pointer to a
  507. * reference function if the function should be tested, otherwise NULL */
  508. void *checkasm_check_func(void *func, const char *name, ...)
  509. {
  510. char name_buf[256];
  511. void *ref = func;
  512. CheckasmFuncVersion *v;
  513. int name_length;
  514. va_list arg;
  515. va_start(arg, name);
  516. name_length = vsnprintf(name_buf, sizeof(name_buf), name, arg);
  517. va_end(arg);
  518. if (!func || name_length <= 0 || name_length >= sizeof(name_buf))
  519. return NULL;
  520. state.current_func = get_func(&state.funcs, name_buf);
  521. state.funcs->color = 1;
  522. v = &state.current_func->versions;
  523. if (v->func) {
  524. CheckasmFuncVersion *prev;
  525. do {
  526. /* Only test functions that haven't already been tested */
  527. if (v->func == func)
  528. return NULL;
  529. if (v->ok)
  530. ref = v->func;
  531. prev = v;
  532. } while ((v = v->next));
  533. v = prev->next = checkasm_malloc(sizeof(CheckasmFuncVersion));
  534. }
  535. v->func = func;
  536. v->ok = 1;
  537. v->cpu = state.cpu_flag;
  538. state.current_func_ver = v;
  539. if (state.cpu_flag)
  540. state.num_checked++;
  541. return ref;
  542. }
  543. /* Decide whether or not the current function needs to be benchmarked */
  544. int checkasm_bench_func(void)
  545. {
  546. return !state.num_failed && state.bench_pattern &&
  547. !strncmp(state.current_func->name, state.bench_pattern, state.bench_pattern_len);
  548. }
  549. /* Indicate that the current test has failed */
  550. void checkasm_fail_func(const char *msg, ...)
  551. {
  552. if (state.current_func_ver->cpu && state.current_func_ver->ok) {
  553. va_list arg;
  554. print_cpu_name();
  555. fprintf(stderr, " %s_%s (", state.current_func->name, cpu_suffix(state.current_func_ver->cpu));
  556. va_start(arg, msg);
  557. vfprintf(stderr, msg, arg);
  558. va_end(arg);
  559. fprintf(stderr, ")\n");
  560. state.current_func_ver->ok = 0;
  561. state.num_failed++;
  562. }
  563. }
  564. /* Update benchmark results of the current function */
  565. void checkasm_update_bench(int iterations, uint64_t cycles)
  566. {
  567. state.current_func_ver->iterations += iterations;
  568. state.current_func_ver->cycles += cycles;
  569. }
  570. /* Print the outcome of all tests performed since the last time this function was called */
  571. void checkasm_report(const char *name, ...)
  572. {
  573. static int prev_checked, prev_failed, max_length;
  574. if (state.num_checked > prev_checked) {
  575. int pad_length = max_length + 4;
  576. va_list arg;
  577. print_cpu_name();
  578. pad_length -= fprintf(stderr, " - %s.", state.current_test_name);
  579. va_start(arg, name);
  580. pad_length -= vfprintf(stderr, name, arg);
  581. va_end(arg);
  582. fprintf(stderr, "%*c", FFMAX(pad_length, 0) + 2, '[');
  583. if (state.num_failed == prev_failed)
  584. color_printf(COLOR_GREEN, "OK");
  585. else
  586. color_printf(COLOR_RED, "FAILED");
  587. fprintf(stderr, "]\n");
  588. prev_checked = state.num_checked;
  589. prev_failed = state.num_failed;
  590. } else if (!state.cpu_flag) {
  591. /* Calculate the amount of padding required to make the output vertically aligned */
  592. int length = strlen(state.current_test_name);
  593. va_list arg;
  594. va_start(arg, name);
  595. length += vsnprintf(NULL, 0, name, arg);
  596. va_end(arg);
  597. if (length > max_length)
  598. max_length = length;
  599. }
  600. }