Skip to content

Commit

Permalink
Run local tests with run-test262
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Oct 10, 2024
1 parent 79eee54 commit b9be6d4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 45 deletions.
35 changes: 4 additions & 31 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ jobs:
make stats
- name: test
if: ${{ matrix.config.configType != 'examples' }}
if: ${{ matrix.config.configType != 'examples' && matrix.config.configType != 'tcc' }}
run: |
make test
Expand Down Expand Up @@ -214,16 +214,7 @@ jobs:
cp build\${{matrix.buildType}}\point.dll examples\
build\${{matrix.buildType}}\qjs.exe examples\test_fib.js
build\${{matrix.buildType}}\qjs.exe examples\test_point.js
build\${{matrix.buildType}}\qjs.exe tests\test_bigint.js
build\${{matrix.buildType}}\qjs.exe tests\test_bjson.js
build\${{matrix.buildType}}\qjs.exe tests\test_closure.js
build\${{matrix.buildType}}\qjs.exe tests\test_language.js
build\${{matrix.buildType}}\qjs.exe tests\test_builtin.js
build\${{matrix.buildType}}\qjs.exe tests\test_loop.js
build\${{matrix.buildType}}\qjs.exe tests\test_std.js
build\${{matrix.buildType}}\qjs.exe tests\test_worker.js
build\${{matrix.buildType}}\qjs.exe tests\test_queue_microtask.js
build\${{matrix.buildType}}\qjs.exe tests\test_module_detect.js
build\${{matrix.buildType}}\run-test262.exe -c tests.conf
build\${{matrix.buildType}}\function_source.exe
windows-clang:
Expand All @@ -247,16 +238,7 @@ jobs:
cp build\${{matrix.buildType}}\point.dll examples\
build\${{matrix.buildType}}\qjs.exe examples\test_fib.js
build\${{matrix.buildType}}\qjs.exe examples\test_point.js
build\${{matrix.buildType}}\qjs.exe tests\test_bigint.js
build\${{matrix.buildType}}\qjs.exe tests\test_bjson.js
build\${{matrix.buildType}}\qjs.exe tests\test_closure.js
build\${{matrix.buildType}}\qjs.exe tests\test_language.js
build\${{matrix.buildType}}\qjs.exe tests\test_builtin.js
build\${{matrix.buildType}}\qjs.exe tests\test_loop.js
build\${{matrix.buildType}}\qjs.exe tests\test_std.js
build\${{matrix.buildType}}\qjs.exe tests\test_worker.js
build\${{matrix.buildType}}\qjs.exe tests\test_queue_microtask.js
build\${{matrix.buildType}}\qjs.exe tests\test_module_detect.js
build\${{matrix.buildType}}\run-test262.exe -c tests.conf
build\${{matrix.buildType}}\function_source.exe
windows-ninja:
Expand Down Expand Up @@ -284,16 +266,7 @@ jobs:
cp build\point.dll examples\
build\qjs.exe examples\test_fib.js
build\qjs.exe examples\test_point.js
build\qjs.exe tests\test_bigint.js
build\qjs.exe tests\test_bjson.js
build\qjs.exe tests\test_closure.js
build\qjs.exe tests\test_language.js
build\qjs.exe tests\test_builtin.js
build\qjs.exe tests\test_loop.js
build\qjs.exe tests\test_std.js
build\qjs.exe tests\test_worker.js
build\qjs.exe tests\test_queue_microtask.js
build\qjs.exe tests\test_module_detect.js
build\run-test262.exe -c tests.conf
build\function_source.exe
windows-mingw:
Expand Down
10 changes: 1 addition & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,7 @@ stats: $(QJS)
$(QJS) -qd

test: $(QJS)
$(QJS) tests/test_bigint.js
$(QJS) tests/test_closure.js
$(QJS) tests/test_language.js
$(QJS) tests/test_builtin.js
$(QJS) tests/test_loop.js
$(QJS) tests/test_std.js
$(QJS) tests/test_worker.js
$(QJS) tests/test_queue_microtask.js
$(QJS) tests/test_module_detect.js
$(RUN262) -c tests.conf

testconv: $(BUILD_DIR)/test_conv
$(BUILD_DIR)/test_conv
Expand Down
38 changes: 35 additions & 3 deletions run-test262.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ enum test_mode_t {
TEST_STRICT, /* run tests as strict, skip nostrict tests */
TEST_ALL, /* run tests in both strict and nostrict, unless restricted by spec */
} test_mode = TEST_DEFAULT_NOSTRICT;
int local;
int skip_async;
int skip_module;
int dump_memory;
Expand Down Expand Up @@ -1129,6 +1130,10 @@ void load_config(const char *filename, const char *ignore)
printf("%s:%d: ignoring %s=%s\n", filename, lineno, p, q);
continue;
}
if (str_equal(p, "local")) {
local = str_equal(q, "yes");
continue;
}
if (str_equal(p, "testdir")) {
char *testdir = compose_path(base_name, q);
enumerate_tests(testdir);
Expand Down Expand Up @@ -1512,6 +1517,11 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len,
JS_FreeCString(ctx, msg);
free(s);
}

if (local) {
js_std_loop(ctx);
}

JS_FreeCString(ctx, error_name);
JS_FreeValue(ctx, exception_val);
JS_FreeValue(ctx, res_val);
Expand Down Expand Up @@ -1679,6 +1689,19 @@ void update_stats(JSRuntime *rt, const char *filename) {
js_mutex_unlock(&stats_mutex);
}

JSContext *JS_NewCustomContext(JSRuntime *rt)
{
JSContext *ctx;

ctx = JS_NewContext(rt);
if (ctx && local) {
js_init_module_std(ctx, "std");
js_init_module_os(ctx, "os");
js_init_module_bjson(ctx, "bjson");
}
return ctx;
}

int run_test_buf(const char *filename, char *harness, namelist_t *ip,
char *buf, size_t buf_len, const char* error_type,
int eval_flags, BOOL is_negative, BOOL is_async,
Expand All @@ -1692,7 +1715,8 @@ int run_test_buf(const char *filename, char *harness, namelist_t *ip,
if (rt == NULL) {
fatal(1, "JS_NewRuntime failure");
}
ctx = JS_NewContext(rt);
js_std_init_handlers(rt);
ctx = JS_NewCustomContext(rt);
if (ctx == NULL) {
JS_FreeRuntime(rt);
fatal(1, "JS_NewContext failure");
Expand Down Expand Up @@ -1721,6 +1745,7 @@ int run_test_buf(const char *filename, char *harness, namelist_t *ip,
}
js_agent_free(ctx);
JS_FreeContext(ctx);
js_std_free_handlers(rt);
JS_FreeRuntime(rt);

atomic_inc(&test_count);
Expand Down Expand Up @@ -1757,8 +1782,10 @@ int run_test(const char *filename, int *msec)
}
harness = harnessbuf;
}
namelist_add(ip, NULL, "sta.js");
namelist_add(ip, NULL, "assert.js");
if (!local) {
namelist_add(ip, NULL, "sta.js");
namelist_add(ip, NULL, "assert.js");
}
/* extract the YAML frontmatter */
desc = extract_desc(buf, '-');
if (desc) {
Expand Down Expand Up @@ -1874,6 +1901,9 @@ int run_test(const char *filename, int *msec)
atomic_inc(&test_skipped);
ret = -2;
} else {
if (local) {
is_module = JS_DetectModule(buf, buf_len);
}
if (is_module) {
eval_flags = JS_EVAL_TYPE_MODULE;
} else {
Expand Down Expand Up @@ -2070,6 +2100,8 @@ int main(int argc, char **argv)
BOOL is_test262_harness = FALSE;
BOOL is_module = FALSE;

js_std_set_worker_new_context_func(JS_NewCustomContext);

tls = &(ThreadLocalStorage){};
init_thread_local_storage(tls);
js_mutex_init(&stats_mutex);
Expand Down
8 changes: 8 additions & 0 deletions tests.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[config]
local=yes
verbose=yes
testdir=tests

[exclude]
tests/microbench.js
tests/test_worker_module.js
5 changes: 3 additions & 2 deletions tests/test_std.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function test_popen()
{
var str, f, fname = "tmp_file.txt";
var content = "hello world";
var cmd = isWin ? "type" : "cat";

f = std.open(fname, "w");
f.puts(content);
Expand All @@ -98,8 +99,8 @@ function test_popen()
/* test loadFile */
assert(std.loadFile(fname), content);

/* execute the 'cat' shell command */
f = std.popen("cat " + fname, "r");
/* execute shell command */
f = std.popen(cmd + " " + fname, "r");
str = f.readAsString();
f.close();

Expand Down

0 comments on commit b9be6d4

Please sign in to comment.