@@ -63,6 +63,8 @@ enum test_mode_t {
63
63
TEST_STRICT , /* run tests as strict, skip nostrict tests */
64
64
TEST_ALL , /* run tests in both strict and nostrict, unless restricted by spec */
65
65
} test_mode = TEST_DEFAULT_NOSTRICT ;
66
+ int compact ;
67
+ int show_timings ;
66
68
int skip_async ;
67
69
int skip_module ;
68
70
int new_style ;
@@ -530,6 +532,7 @@ static JSValue js_agent_start(JSContext *ctx, JSValue this_val,
530
532
{
531
533
const char * script ;
532
534
Test262Agent * agent ;
535
+ pthread_attr_t attr ;
533
536
534
537
if (JS_GetContextOpaque (ctx ) != NULL )
535
538
return JS_ThrowTypeError (ctx , "cannot be called inside an agent" );
@@ -544,7 +547,12 @@ static JSValue js_agent_start(JSContext *ctx, JSValue this_val,
544
547
agent -> script = strdup (script );
545
548
JS_FreeCString (ctx , script );
546
549
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 );
548
556
return JS_UNDEFINED ;
549
557
}
550
558
@@ -813,6 +821,19 @@ static JSModuleDef *js_module_loader_test(JSContext *ctx,
813
821
uint8_t * buf ;
814
822
JSModuleDef * m ;
815
823
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
+ }
816
837
817
838
buf = js_load_file (ctx , & buf_len , module_name );
818
839
if (!buf ) {
@@ -910,7 +931,7 @@ void update_exclude_dirs(void)
910
931
lp -> count = count ;
911
932
}
912
933
913
- void load_config (const char * filename )
934
+ void load_config (const char * filename , const char * ignore )
914
935
{
915
936
char buf [1024 ];
916
937
FILE * f ;
@@ -965,6 +986,10 @@ void load_config(const char *filename)
965
986
printf ("%s:%d: syntax error\n" , filename , lineno );
966
987
continue ;
967
988
}
989
+ if (strstr (ignore , p )) {
990
+ printf ("%s:%d: ignoring %s=%s\n" , filename , lineno , p , q );
991
+ continue ;
992
+ }
968
993
if (str_equal (p , "style" )) {
969
994
new_style = str_equal (q , "new" );
970
995
continue ;
@@ -1540,7 +1565,7 @@ int run_test_buf(const char *filename, const char *harness, namelist_t *ip,
1540
1565
JS_SetCanBlock (rt , can_block );
1541
1566
1542
1567
/* 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 );
1544
1569
1545
1570
add_helpers (ctx );
1546
1571
@@ -1656,7 +1681,7 @@ int run_test(const char *filename, int index)
1656
1681
/* XXX: should extract the phase */
1657
1682
char * q = find_tag (p , "type:" , & state );
1658
1683
if (q ) {
1659
- while (isspace (* q ))
1684
+ while (isspace (( unsigned char ) * q ))
1660
1685
q ++ ;
1661
1686
error_type = strdup_len (q , strcspn (q , " \n" ));
1662
1687
}
@@ -1841,7 +1866,7 @@ int run_test262_harness_test(const char *filename, BOOL is_module)
1841
1866
JS_SetCanBlock (rt , can_block );
1842
1867
1843
1868
/* 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 );
1845
1870
1846
1871
add_helpers (ctx );
1847
1872
@@ -1900,9 +1925,27 @@ void show_progress(int force) {
1900
1925
clock_t t = clock ();
1901
1926
if (force || !last_clock || (t - last_clock ) > CLOCKS_PER_SEC / 20 ) {
1902
1927
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
+ }
1906
1949
fflush (stderr );
1907
1950
}
1908
1951
}
@@ -1953,6 +1996,8 @@ void help(void)
1953
1996
"-N run test prepared by test262-harness+eshost\n"
1954
1997
"-s run tests in strict mode, skip @nostrict tests\n"
1955
1998
"-E only run tests from the error file\n"
1999
+ "-C use compact progress indicator\n"
2000
+ "-t show timings\n"
1956
2001
"-u update error file\n"
1957
2002
"-v verbose: output error messages\n"
1958
2003
"-T duration display tests taking more than 'duration' ms\n"
@@ -1979,14 +2024,29 @@ int main(int argc, char **argv)
1979
2024
BOOL is_dir_list ;
1980
2025
BOOL only_check_errors = FALSE;
1981
2026
const char * filename ;
2027
+ const char * ignore = "" ;
1982
2028
BOOL is_test262_harness = FALSE;
1983
2029
BOOL is_module = FALSE;
2030
+ clock_t clocks ;
1984
2031
1985
2032
#if !defined(_WIN32 )
2033
+ compact = !isatty (STDERR_FILENO );
1986
2034
/* Date tests assume California local time */
1987
2035
setenv ("TZ" , "America/Los_Angeles" , 1 );
1988
2036
#endif
1989
2037
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
+
1990
2050
/* cannot use getopt because we want to pass the command line to
1991
2051
the script */
1992
2052
optind = 1 ;
@@ -2006,12 +2066,16 @@ int main(int argc, char **argv)
2006
2066
test_mode = TEST_STRICT ;
2007
2067
} else if (str_equal (arg , "-a" )) {
2008
2068
test_mode = TEST_ALL ;
2069
+ } else if (str_equal (arg , "-t" )) {
2070
+ show_timings ++ ;
2009
2071
} else if (str_equal (arg , "-u" )) {
2010
2072
update_errors ++ ;
2011
2073
} else if (str_equal (arg , "-v" )) {
2012
2074
verbose ++ ;
2075
+ } else if (str_equal (arg , "-C" )) {
2076
+ compact = 1 ;
2013
2077
} 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 );
2015
2079
} else if (str_equal (arg , "-d" )) {
2016
2080
enumerate_tests (get_opt_arg (arg , argv [optind ++ ]));
2017
2081
} else if (str_equal (arg , "-e" )) {
@@ -2042,7 +2106,7 @@ int main(int argc, char **argv)
2042
2106
if (is_test262_harness ) {
2043
2107
return run_test262_harness_test (argv [optind ], is_module );
2044
2108
}
2045
-
2109
+
2046
2110
error_out = stdout ;
2047
2111
if (error_filename ) {
2048
2112
error_file = load_file (error_filename , NULL );
@@ -2062,8 +2126,10 @@ int main(int argc, char **argv)
2062
2126
2063
2127
update_exclude_dirs ();
2064
2128
2129
+ clocks = clock ();
2130
+
2065
2131
if (is_dir_list ) {
2066
- if (optind < argc && !isdigit (argv [optind ][0 ])) {
2132
+ if (optind < argc && !isdigit (( unsigned char ) argv [optind ][0 ])) {
2067
2133
filename = argv [optind ++ ];
2068
2134
namelist_load (& test_list , filename );
2069
2135
}
@@ -2098,6 +2164,8 @@ int main(int argc, char **argv)
2098
2164
}
2099
2165
}
2100
2166
2167
+ clocks = clock () - clocks ;
2168
+
2101
2169
if (dump_memory ) {
2102
2170
if (dump_memory > 1 && stats_count > 1 ) {
2103
2171
printf ("\nMininum memory statistics for %s:\n\n" , stats_min_filename );
@@ -2126,6 +2194,8 @@ int main(int argc, char **argv)
2126
2194
fprintf (stderr , ", %d fixed" , fixed_errors );
2127
2195
}
2128
2196
fprintf (stderr , "\n" );
2197
+ if (show_timings )
2198
+ fprintf (stderr , "Total time: %.3fs\n" , (double )clocks / CLOCKS_PER_SEC );
2129
2199
}
2130
2200
2131
2201
if (error_out && error_out != stdout ) {
@@ -2141,5 +2211,6 @@ int main(int argc, char **argv)
2141
2211
free (harness_exclude );
2142
2212
free (error_file );
2143
2213
2144
- return 0 ;
2214
+ /* Signal that the error file is out of date. */
2215
+ return new_errors || changed_errors || fixed_errors ;
2145
2216
}
0 commit comments