Skip to content

Commit c24a865

Browse files
committed
Improve run-test262
- add -t to show timings - add -C to select compact progress meter - default to compact progress meter if not attached to console - set agent stack size to 2MB - compute module filename relative to current path - ignore `testdir` for -d and -f options - return non zero status on errors changes
1 parent bbf36d5 commit c24a865

File tree

2 files changed

+91
-20
lines changed

2 files changed

+91
-20
lines changed

Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -488,13 +488,13 @@ test2o test2o-32 test2o-update:
488488
else
489489
# ES5 tests (obsolete)
490490
test2o: run-test262
491-
time ./run-test262 -m -c test262o.conf
491+
time ./run-test262 -t -m -c test262o.conf
492492

493493
test2o-32: run-test262-32
494-
time ./run-test262-32 -m -c test262o.conf
494+
time ./run-test262-32 -t -m -c test262o.conf
495495

496496
test2o-update: run-test262
497-
./run-test262 -u -c test262o.conf
497+
./run-test262 -t -u -c test262o.conf
498498
endif
499499

500500
ifeq ($(wildcard test262o/tests.txt),)
@@ -503,19 +503,19 @@ test2 test2-32 test2-update test2-default test2-check:
503503
else
504504
# Test262 tests
505505
test2-default: run-test262
506-
time ./run-test262 -m -c test262.conf
506+
time ./run-test262 -t -m -c test262.conf
507507

508508
test2: run-test262
509-
time ./run-test262 -m -c test262.conf -a
509+
time ./run-test262 -t -m -c test262.conf -a
510510

511511
test2-32: run-test262-32
512-
time ./run-test262-32 -m -c test262.conf -a
512+
time ./run-test262-32 -t -m -c test262.conf -a
513513

514514
test2-update: run-test262
515-
./run-test262 -u -c test262.conf -a
515+
./run-test262 -t -u -c test262.conf -a
516516

517517
test2-check: run-test262
518-
time ./run-test262 -m -c test262.conf -E -a
518+
time ./run-test262 -t -m -c test262.conf -E -a
519519
endif
520520

521521
testall: all test microbench test2o test2

run-test262.c

Lines changed: 83 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ enum test_mode_t {
6363
TEST_STRICT, /* run tests as strict, skip nostrict tests */
6464
TEST_ALL, /* run tests in both strict and nostrict, unless restricted by spec */
6565
} test_mode = TEST_DEFAULT_NOSTRICT;
66+
int compact;
67+
int show_timings;
6668
int skip_async;
6769
int skip_module;
6870
int new_style;
@@ -530,6 +532,7 @@ static JSValue js_agent_start(JSContext *ctx, JSValue this_val,
530532
{
531533
const char *script;
532534
Test262Agent *agent;
535+
pthread_attr_t attr;
533536

534537
if (JS_GetContextOpaque(ctx) != NULL)
535538
return JS_ThrowTypeError(ctx, "cannot be called inside an agent");
@@ -544,7 +547,12 @@ static JSValue js_agent_start(JSContext *ctx, JSValue this_val,
544547
agent->script = strdup(script);
545548
JS_FreeCString(ctx, script);
546549
list_add_tail(&agent->link, &agent_list);
547-
pthread_create(&agent->tid, NULL, agent_start, agent);
550+
pthread_attr_init(&attr);
551+
// musl libc gives threads 80 kb stacks, much smaller than
552+
// JS_DEFAULT_STACK_SIZE (256 kb)
553+
pthread_attr_setstacksize(&attr, 2 << 20); // 2 MB, glibc default
554+
pthread_create(&agent->tid, &attr, agent_start, agent);
555+
pthread_attr_destroy(&attr);
548556
return JS_UNDEFINED;
549557
}
550558

@@ -813,6 +821,19 @@ static JSModuleDef *js_module_loader_test(JSContext *ctx,
813821
uint8_t *buf;
814822
JSModuleDef *m;
815823
JSValue func_val;
824+
char *filename, *slash, path[1024];
825+
826+
// interpret import("bar.js") from path/to/foo.js as
827+
// import("path/to/bar.js") but leave import("./bar.js") untouched
828+
filename = opaque;
829+
if (!strchr(module_name, '/')) {
830+
slash = strrchr(filename, '/');
831+
if (slash) {
832+
snprintf(path, sizeof(path), "%.*s/%s",
833+
(int)(slash - filename), filename, module_name);
834+
module_name = path;
835+
}
836+
}
816837

817838
buf = js_load_file(ctx, &buf_len, module_name);
818839
if (!buf) {
@@ -910,7 +931,7 @@ void update_exclude_dirs(void)
910931
lp->count = count;
911932
}
912933

913-
void load_config(const char *filename)
934+
void load_config(const char *filename, const char *ignore)
914935
{
915936
char buf[1024];
916937
FILE *f;
@@ -965,6 +986,10 @@ void load_config(const char *filename)
965986
printf("%s:%d: syntax error\n", filename, lineno);
966987
continue;
967988
}
989+
if (strstr(ignore, p)) {
990+
printf("%s:%d: ignoring %s=%s\n", filename, lineno, p, q);
991+
continue;
992+
}
968993
if (str_equal(p, "style")) {
969994
new_style = str_equal(q, "new");
970995
continue;
@@ -1540,7 +1565,7 @@ int run_test_buf(const char *filename, const char *harness, namelist_t *ip,
15401565
JS_SetCanBlock(rt, can_block);
15411566

15421567
/* loader for ES6 modules */
1543-
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader_test, NULL);
1568+
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader_test, (void *)filename);
15441569

15451570
add_helpers(ctx);
15461571

@@ -1656,7 +1681,7 @@ int run_test(const char *filename, int index)
16561681
/* XXX: should extract the phase */
16571682
char *q = find_tag(p, "type:", &state);
16581683
if (q) {
1659-
while (isspace(*q))
1684+
while (isspace((unsigned char)*q))
16601685
q++;
16611686
error_type = strdup_len(q, strcspn(q, " \n"));
16621687
}
@@ -1841,7 +1866,7 @@ int run_test262_harness_test(const char *filename, BOOL is_module)
18411866
JS_SetCanBlock(rt, can_block);
18421867

18431868
/* loader for ES6 modules */
1844-
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader_test, NULL);
1869+
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader_test, (void *)filename);
18451870

18461871
add_helpers(ctx);
18471872

@@ -1900,9 +1925,27 @@ void show_progress(int force) {
19001925
clock_t t = clock();
19011926
if (force || !last_clock || (t - last_clock) > CLOCKS_PER_SEC / 20) {
19021927
last_clock = t;
1903-
/* output progress indicator: erase end of line and return to col 0 */
1904-
fprintf(stderr, "%d/%d/%d\033[K\r",
1905-
test_failed, test_count, test_skipped);
1928+
if (compact) {
1929+
static int last_test_skipped;
1930+
static int last_test_failed;
1931+
static int dots;
1932+
char c = '.';
1933+
if (test_skipped > last_test_skipped)
1934+
c = '-';
1935+
if (test_failed > last_test_failed)
1936+
c = '!';
1937+
last_test_skipped = test_skipped;
1938+
last_test_failed = test_failed;
1939+
fputc(c, stderr);
1940+
if (force || ++dots % 60 == 0) {
1941+
fprintf(stderr, " %d/%d/%d\n",
1942+
test_failed, test_count, test_skipped);
1943+
}
1944+
} else {
1945+
/* output progress indicator: erase end of line and return to col 0 */
1946+
fprintf(stderr, "%d/%d/%d\033[K\r",
1947+
test_failed, test_count, test_skipped);
1948+
}
19061949
fflush(stderr);
19071950
}
19081951
}
@@ -1953,6 +1996,8 @@ void help(void)
19531996
"-N run test prepared by test262-harness+eshost\n"
19541997
"-s run tests in strict mode, skip @nostrict tests\n"
19551998
"-E only run tests from the error file\n"
1999+
"-C use compact progress indicator\n"
2000+
"-t show timings\n"
19562001
"-u update error file\n"
19572002
"-v verbose: output error messages\n"
19582003
"-T duration display tests taking more than 'duration' ms\n"
@@ -1979,14 +2024,29 @@ int main(int argc, char **argv)
19792024
BOOL is_dir_list;
19802025
BOOL only_check_errors = FALSE;
19812026
const char *filename;
2027+
const char *ignore = "";
19822028
BOOL is_test262_harness = FALSE;
19832029
BOOL is_module = FALSE;
2030+
clock_t clocks;
19842031

19852032
#if !defined(_WIN32)
2033+
compact = !isatty(STDERR_FILENO);
19862034
/* Date tests assume California local time */
19872035
setenv("TZ", "America/Los_Angeles", 1);
19882036
#endif
19892037

2038+
optind = 1;
2039+
while (optind < argc) {
2040+
char *arg = argv[optind];
2041+
if (*arg != '-')
2042+
break;
2043+
optind++;
2044+
if (strstr("-c -d -e -x -f -r -E -T", arg))
2045+
optind++;
2046+
if (strstr("-d -f", arg))
2047+
ignore = "testdir"; // run only the tests from -d or -f
2048+
}
2049+
19902050
/* cannot use getopt because we want to pass the command line to
19912051
the script */
19922052
optind = 1;
@@ -2006,12 +2066,16 @@ int main(int argc, char **argv)
20062066
test_mode = TEST_STRICT;
20072067
} else if (str_equal(arg, "-a")) {
20082068
test_mode = TEST_ALL;
2069+
} else if (str_equal(arg, "-t")) {
2070+
show_timings++;
20092071
} else if (str_equal(arg, "-u")) {
20102072
update_errors++;
20112073
} else if (str_equal(arg, "-v")) {
20122074
verbose++;
2075+
} else if (str_equal(arg, "-C")) {
2076+
compact = 1;
20132077
} else if (str_equal(arg, "-c")) {
2014-
load_config(get_opt_arg(arg, argv[optind++]));
2078+
load_config(get_opt_arg(arg, argv[optind++]), ignore);
20152079
} else if (str_equal(arg, "-d")) {
20162080
enumerate_tests(get_opt_arg(arg, argv[optind++]));
20172081
} else if (str_equal(arg, "-e")) {
@@ -2042,7 +2106,7 @@ int main(int argc, char **argv)
20422106
if (is_test262_harness) {
20432107
return run_test262_harness_test(argv[optind], is_module);
20442108
}
2045-
2109+
20462110
error_out = stdout;
20472111
if (error_filename) {
20482112
error_file = load_file(error_filename, NULL);
@@ -2062,8 +2126,10 @@ int main(int argc, char **argv)
20622126

20632127
update_exclude_dirs();
20642128

2129+
clocks = clock();
2130+
20652131
if (is_dir_list) {
2066-
if (optind < argc && !isdigit(argv[optind][0])) {
2132+
if (optind < argc && !isdigit((unsigned char)argv[optind][0])) {
20672133
filename = argv[optind++];
20682134
namelist_load(&test_list, filename);
20692135
}
@@ -2098,6 +2164,8 @@ int main(int argc, char **argv)
20982164
}
20992165
}
21002166

2167+
clocks = clock() - clocks;
2168+
21012169
if (dump_memory) {
21022170
if (dump_memory > 1 && stats_count > 1) {
21032171
printf("\nMininum memory statistics for %s:\n\n", stats_min_filename);
@@ -2126,6 +2194,8 @@ int main(int argc, char **argv)
21262194
fprintf(stderr, ", %d fixed", fixed_errors);
21272195
}
21282196
fprintf(stderr, "\n");
2197+
if (show_timings)
2198+
fprintf(stderr, "Total time: %.3fs\n", (double)clocks / CLOCKS_PER_SEC);
21292199
}
21302200

21312201
if (error_out && error_out != stdout) {
@@ -2141,5 +2211,6 @@ int main(int argc, char **argv)
21412211
free(harness_exclude);
21422212
free(error_file);
21432213

2144-
return 0;
2214+
/* Signal that the error file is out of date. */
2215+
return new_errors || changed_errors || fixed_errors;
21452216
}

0 commit comments

Comments
 (0)