checkasm.c 18 KB

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