Tests: the native suite in seconds, every test on its own, all cores
- scripts/test-native.py (just t WORD): builds once, runs each test in its own process in parallel, longest first, with a timeout; CI and just test use it. - Tests no longer search this machine's apps and icon themes. - Compiled wasm modules are cached between test processes (CHANDRA_WASM_CACHE). - draw_circle fills its middle with spans (same pixels); encode_png writes into one buffer, with a CRC table. - The ffprobe helper always waited out its 20 s: its done file was empty. - The fake polkit helper no longer depends on which shell sh is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d1d1bb398c
commit
5ca7242615
12 files changed
+397
-81
No files matched your search
@@ -744,11 +744,51 @@ static void note_import(Inst *in, const wasm_name_t *m) {
|
||||
in->imports[have + strlen(iface) + 1] = 0;
|
||||
}
|
||||
}
|
||||
/* Compile a core module. With CHANDRA_WASM_CACHE=DIR (scripts/test-native.py, whose every test is
|
||||
* a new process) the compiled code is kept there. Compiled code is loaded unchecked: the directory
|
||||
* has to be ours alone and belong to one wasmer build, so a normal session doesn't use it. */
|
||||
static wasm_module_t *compile_module(const uint8_t *bytes, size_t len) {
|
||||
wasm_byte_vec_t v;
|
||||
wasm_module_t *mod = NULL;
|
||||
const char *dir = getenv("CHANDRA_WASM_CACHE");
|
||||
char path[1024], tmp[1100];
|
||||
int cache = 0;
|
||||
if (dir && *dir) {
|
||||
uint64_t h = 14695981039346656037ull;
|
||||
for (size_t i = 0; i < len; i++) h = (h ^ bytes[i]) * 1099511628211ull;
|
||||
int n = snprintf(path, sizeof path, "%s/%016llx-%zu", dir, (unsigned long long)h, len);
|
||||
cache = n > 0 && (size_t)n < sizeof path;
|
||||
}
|
||||
FILE *f = cache ? fopen(path, "rb") : NULL;
|
||||
if (f) {
|
||||
fseek(f, 0, SEEK_END);
|
||||
long n = ftell(f);
|
||||
rewind(f);
|
||||
if (n > 0) {
|
||||
wasm_byte_vec_new_uninitialized(&v, (size_t)n);
|
||||
if (fread(v.data, 1, (size_t)n, f) == (size_t)n) mod = wasm_module_deserialize(store, &v);
|
||||
wasm_byte_vec_delete(&v);
|
||||
}
|
||||
fclose(f);
|
||||
if (mod) return mod;
|
||||
}
|
||||
wasm_byte_vec_new(&v, len, (const wasm_byte_t *)bytes);
|
||||
mod = wasm_module_new(store, &v);
|
||||
wasm_byte_vec_delete(&v);
|
||||
if (!mod || !cache) return mod;
|
||||
wasm_module_serialize(mod, &v);
|
||||
snprintf(tmp, sizeof tmp, "%s.%d", path, (int)getpid());
|
||||
f = v.size ? fopen(tmp, "wb") : NULL;
|
||||
if (f) {
|
||||
int ok = fwrite(v.data, 1, v.size, f) == v.size;
|
||||
if (fclose(f) != 0 || !ok || rename(tmp, path) != 0) unlink(tmp);
|
||||
}
|
||||
wasm_byte_vec_delete(&v);
|
||||
return mod;
|
||||
}
|
||||
|
||||
static int try_instantiate(Inst *in, const uint8_t *bytes, size_t len) {
|
||||
wasm_byte_vec_t bin;
|
||||
wasm_byte_vec_new(&bin, len, (const wasm_byte_t *)bytes);
|
||||
wasm_module_t *mod = wasm_module_new(store, &bin);
|
||||
wasm_byte_vec_delete(&bin);
|
||||
wasm_module_t *mod = compile_module(bytes, len);
|
||||
if (!mod) return 0;
|
||||
|
||||
wasm_exporttype_vec_t ets;
|
||||
|
||||
Reference in new issue
Block a user