mirror of
https://github.com/DoneJS-Runtime/quickjs-done-nextgen.git
synced 2025-01-09 17:43:15 +00:00
Add -vv verboser mode switch to run-test262 (#561)
Prints the test name and running time in milliseconds. Supersedes `-T <ms>` because that switch prints the same info, only for slow tests.
This commit is contained in:
parent
4d4dbcf37e
commit
7db24cc0da
1 changed files with 35 additions and 31 deletions
|
@ -135,6 +135,15 @@ static inline int str_equal(const char *a, const char *b) {
|
||||||
return !strcmp(a, b);
|
return !strcmp(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int str_count(const char *a, const char *b) {
|
||||||
|
int count = 0;
|
||||||
|
while ((a = strstr(a, b))) {
|
||||||
|
a += strlen(b);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
char *str_append(char **pp, const char *sep, const char *str) {
|
char *str_append(char **pp, const char *sep, const char *str) {
|
||||||
char *res, *p;
|
char *res, *p;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
@ -1049,7 +1058,8 @@ void load_config(const char *filename, const char *ignore)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (str_equal(p, "verbose")) {
|
if (str_equal(p, "verbose")) {
|
||||||
verbose = str_equal(q, "yes");
|
int count = str_count(q, "yes");
|
||||||
|
verbose = max_int(verbose, count);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (str_equal(p, "errorfile")) {
|
if (str_equal(p, "errorfile")) {
|
||||||
|
@ -1194,12 +1204,13 @@ int longest_match(const char *str, const char *find, int pos, int *ppos, int lin
|
||||||
static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len,
|
static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len,
|
||||||
const char *filename, int is_test, int is_negative,
|
const char *filename, int is_test, int is_negative,
|
||||||
const char *error_type, FILE *outfile, int eval_flags,
|
const char *error_type, FILE *outfile, int eval_flags,
|
||||||
int is_async)
|
int is_async, int *msec)
|
||||||
{
|
{
|
||||||
JSValue res_val, exception_val;
|
JSValue res_val, exception_val;
|
||||||
int ret, error_line, pos, pos_line;
|
int ret, error_line, pos, pos_line;
|
||||||
BOOL is_error, has_error_line, ret_promise;
|
BOOL is_error, has_error_line, ret_promise;
|
||||||
const char *error_name;
|
const char *error_name;
|
||||||
|
int start, duration;
|
||||||
|
|
||||||
pos = skip_comments(buf, 1, &pos_line);
|
pos = skip_comments(buf, 1, &pos_line);
|
||||||
error_line = pos_line;
|
error_line = pos_line;
|
||||||
|
@ -1211,6 +1222,7 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len,
|
||||||
ret_promise = ((eval_flags & JS_EVAL_TYPE_MODULE) != 0);
|
ret_promise = ((eval_flags & JS_EVAL_TYPE_MODULE) != 0);
|
||||||
async_done = 0; /* counter of "Test262:AsyncTestComplete" messages */
|
async_done = 0; /* counter of "Test262:AsyncTestComplete" messages */
|
||||||
|
|
||||||
|
start = get_clock_ms();
|
||||||
res_val = JS_Eval(ctx, buf, buf_len, filename, eval_flags);
|
res_val = JS_Eval(ctx, buf, buf_len, filename, eval_flags);
|
||||||
|
|
||||||
if ((is_async || ret_promise) && !JS_IsException(res_val)) {
|
if ((is_async || ret_promise) && !JS_IsException(res_val)) {
|
||||||
|
@ -1250,6 +1262,9 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len,
|
||||||
JS_FreeValue(ctx, promise);
|
JS_FreeValue(ctx, promise);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
duration = get_clock_ms() - start;
|
||||||
|
*msec += duration;
|
||||||
|
|
||||||
if (JS_IsException(res_val)) {
|
if (JS_IsException(res_val)) {
|
||||||
exception_val = JS_GetException(ctx);
|
exception_val = JS_GetException(ctx);
|
||||||
is_error = JS_IsError(ctx, exception_val);
|
is_error = JS_IsError(ctx, exception_val);
|
||||||
|
@ -1395,6 +1410,7 @@ static int eval_file(JSContext *ctx, const char *base, const char *p,
|
||||||
char *buf;
|
char *buf;
|
||||||
size_t buf_len;
|
size_t buf_len;
|
||||||
char *filename = compose_path(base, p);
|
char *filename = compose_path(base, p);
|
||||||
|
int msec = 0;
|
||||||
|
|
||||||
buf = load_file(filename, &buf_len);
|
buf = load_file(filename, &buf_len);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
|
@ -1402,7 +1418,7 @@ static int eval_file(JSContext *ctx, const char *base, const char *p,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (eval_buf(ctx, buf, buf_len, filename, FALSE, FALSE, NULL, stderr,
|
if (eval_buf(ctx, buf, buf_len, filename, FALSE, FALSE, NULL, stderr,
|
||||||
eval_flags, FALSE)) {
|
eval_flags, FALSE, &msec)) {
|
||||||
warning("error evaluating %s", filename);
|
warning("error evaluating %s", filename);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -1550,7 +1566,7 @@ void update_stats(JSRuntime *rt, const char *filename) {
|
||||||
int run_test_buf(const char *filename, char *harness, namelist_t *ip,
|
int run_test_buf(const char *filename, char *harness, namelist_t *ip,
|
||||||
char *buf, size_t buf_len, const char* error_type,
|
char *buf, size_t buf_len, const char* error_type,
|
||||||
int eval_flags, BOOL is_negative, BOOL is_async,
|
int eval_flags, BOOL is_negative, BOOL is_async,
|
||||||
BOOL can_block)
|
BOOL can_block, int *msec)
|
||||||
{
|
{
|
||||||
JSRuntime *rt;
|
JSRuntime *rt;
|
||||||
JSContext *ctx;
|
JSContext *ctx;
|
||||||
|
@ -1581,7 +1597,7 @@ int run_test_buf(const char *filename, char *harness, namelist_t *ip,
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = eval_buf(ctx, buf, buf_len, filename, TRUE, is_negative,
|
ret = eval_buf(ctx, buf, buf_len, filename, TRUE, is_negative,
|
||||||
error_type, outfile, eval_flags, is_async);
|
error_type, outfile, eval_flags, is_async, msec);
|
||||||
ret = (ret != 0);
|
ret = (ret != 0);
|
||||||
|
|
||||||
if (dump_memory) {
|
if (dump_memory) {
|
||||||
|
@ -1604,7 +1620,7 @@ int run_test_buf(const char *filename, char *harness, namelist_t *ip,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int run_test(const char *filename, int index)
|
int run_test(const char *filename, int index, int *msec)
|
||||||
{
|
{
|
||||||
char harnessbuf[1024];
|
char harnessbuf[1024];
|
||||||
char *harness;
|
char *harness;
|
||||||
|
@ -1806,30 +1822,24 @@ int run_test(const char *filename, int index)
|
||||||
test_skipped++;
|
test_skipped++;
|
||||||
ret = -2;
|
ret = -2;
|
||||||
} else {
|
} else {
|
||||||
clock_t clocks;
|
|
||||||
|
|
||||||
if (is_module) {
|
if (is_module) {
|
||||||
eval_flags = JS_EVAL_TYPE_MODULE;
|
eval_flags = JS_EVAL_TYPE_MODULE;
|
||||||
} else {
|
} else {
|
||||||
eval_flags = JS_EVAL_TYPE_GLOBAL;
|
eval_flags = JS_EVAL_TYPE_GLOBAL;
|
||||||
}
|
}
|
||||||
clocks = clock();
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
if (use_nostrict) {
|
if (use_nostrict) {
|
||||||
ret = run_test_buf(filename, harness, ip, buf, buf_len,
|
ret = run_test_buf(filename, harness, ip, buf, buf_len,
|
||||||
error_type, eval_flags, is_negative, is_async,
|
error_type, eval_flags, is_negative, is_async,
|
||||||
can_block);
|
can_block, msec);
|
||||||
}
|
}
|
||||||
if (use_strict) {
|
if (use_strict) {
|
||||||
ret |= run_test_buf(filename, harness, ip, buf, buf_len,
|
ret |= run_test_buf(filename, harness, ip, buf, buf_len,
|
||||||
error_type, eval_flags | JS_EVAL_FLAG_STRICT,
|
error_type, eval_flags | JS_EVAL_FLAG_STRICT,
|
||||||
is_negative, is_async, can_block);
|
is_negative, is_async, can_block, msec);
|
||||||
}
|
|
||||||
clocks = clock() - clocks;
|
|
||||||
if (outfile && index >= 0 && clocks >= CLOCKS_PER_SEC / 10) {
|
|
||||||
/* output timings for tests that take more than 100 ms */
|
|
||||||
fprintf(outfile, " time: %d ms\n", (int)(clocks * 1000LL / CLOCKS_PER_SEC));
|
|
||||||
}
|
}
|
||||||
|
if (outfile && index >= 0 && *msec >= 100)
|
||||||
|
fprintf(outfile, " time: %d ms\n", *msec);
|
||||||
}
|
}
|
||||||
namelist_free(&include_list);
|
namelist_free(&include_list);
|
||||||
free(error_type);
|
free(error_type);
|
||||||
|
@ -1964,18 +1974,10 @@ void run_test_dir_list(namelist_t *lp, int start_index, int stop_index)
|
||||||
} else if (stop_index >= 0 && test_index > stop_index) {
|
} else if (stop_index >= 0 && test_index > stop_index) {
|
||||||
test_skipped++;
|
test_skipped++;
|
||||||
} else {
|
} else {
|
||||||
int ti;
|
int msec = 0;
|
||||||
if (slow_test_threshold != 0) {
|
run_test(p, test_index, &msec);
|
||||||
ti = get_clock_ms();
|
if (verbose > 1 || (msec > 0 && msec >= slow_test_threshold))
|
||||||
} else {
|
fprintf(stderr, "%s (%d ms)\n", p, msec);
|
||||||
ti = 0;
|
|
||||||
}
|
|
||||||
run_test(p, test_index);
|
|
||||||
if (slow_test_threshold != 0) {
|
|
||||||
ti = get_clock_ms() - ti;
|
|
||||||
if (ti >= slow_test_threshold)
|
|
||||||
fprintf(stderr, "\n%s (%d ms)\n", p, ti);
|
|
||||||
}
|
|
||||||
show_progress(FALSE);
|
show_progress(FALSE);
|
||||||
}
|
}
|
||||||
test_index++;
|
test_index++;
|
||||||
|
@ -1997,6 +1999,7 @@ void help(void)
|
||||||
"-u update error file\n"
|
"-u update error file\n"
|
||||||
"-C compact output mode; enabled when stderr is not a tty\n"
|
"-C compact output mode; enabled when stderr is not a tty\n"
|
||||||
"-v verbose: output error messages\n"
|
"-v verbose: output error messages\n"
|
||||||
|
"-vv like -v but also print test name and running time\n"
|
||||||
"-T duration display tests taking more than 'duration' ms\n"
|
"-T duration display tests taking more than 'duration' ms\n"
|
||||||
"-c file read configuration from 'file'\n"
|
"-c file read configuration from 'file'\n"
|
||||||
"-d dir run all test files in directory tree 'dir'\n"
|
"-d dir run all test files in directory tree 'dir'\n"
|
||||||
|
@ -2065,8 +2068,8 @@ int main(int argc, char **argv)
|
||||||
test_mode = TEST_ALL;
|
test_mode = TEST_ALL;
|
||||||
} else if (str_equal(arg, "-u")) {
|
} else if (str_equal(arg, "-u")) {
|
||||||
update_errors++;
|
update_errors++;
|
||||||
} else if (str_equal(arg, "-v")) {
|
} else if (arg == strstr(arg, "-v")) {
|
||||||
verbose++;
|
verbose += str_count(arg, "v");
|
||||||
} else if (str_equal(arg, "-C")) {
|
} else if (str_equal(arg, "-C")) {
|
||||||
compact++;
|
compact++;
|
||||||
} else if (str_equal(arg, "-c")) {
|
} else if (str_equal(arg, "-c")) {
|
||||||
|
@ -2153,7 +2156,8 @@ int main(int argc, char **argv)
|
||||||
} else {
|
} else {
|
||||||
outfile = stdout;
|
outfile = stdout;
|
||||||
while (optind < argc) {
|
while (optind < argc) {
|
||||||
run_test(argv[optind++], -1);
|
int msec = 0;
|
||||||
|
run_test(argv[optind++], -1, &msec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue