-
Notifications
You must be signed in to change notification settings - Fork 997
wasm test suite #1116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wasm test suite #1116
Changes from 7 commits
b70182d
9e5decb
f7d903c
5c3af35
c3686c6
16a7aec
569d4e7
e42b563
8e79bb6
0540e67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| *.wasm | ||
| server | ||
| server.pid | ||
| wasm_exec.js |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #!/usr/bin/env bash | ||
| set -e | ||
|
|
||
| # launch headless chrome and our test server, exit immediately if one of them terminates | ||
| /headless-shell/headless-shell --no-sandbox --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222 & | ||
|
|
||
| cd /wasm | ||
| /bin/server & | ||
|
|
||
| wait -n |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
|
|
||
| FROM chromedp/headless-shell:latest | ||
|
||
|
|
||
| RUN apt-get update && apt-get install dumb-init | ||
|
|
||
| COPY server /bin/server | ||
| COPY 0docker_entrypoint.sh /0docker_entrypoint.sh | ||
| RUN chmod 755 /bin/server /0docker_entrypoint.sh | ||
|
|
||
| ENTRYPOINT ["/usr/bin/dumb-init", "--", "/0docker_entrypoint.sh"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // +build ignore | ||
|
||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "flag" | ||
| "fmt" | ||
| "log" | ||
| "net/http" | ||
| "path/filepath" | ||
| ) | ||
|
|
||
| // This is a standalone static file server which is used to serve pages for browser testing. | ||
| // It is a separate program so we can run it inside the same docker container as headless chrome, | ||
| // in order to avoid port mapping issues. | ||
|
|
||
| var addr = flag.String("addr", ":8826", "Host:port to listen on") | ||
| var dir = flag.String("dir", ".", "Directory to serve static files from") | ||
|
|
||
| func main() { | ||
|
|
||
| absDir, err := filepath.Abs(*dir) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| fsh := http.FileServer(http.Dir(absDir)) | ||
| h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
|
|
||
| if r.URL.Path == "/run" { | ||
| fmt.Fprintf(w, `<!doctype html> | ||
| <html> | ||
| <head> | ||
| <title>Test</title> | ||
| <meta charset="utf-8"/> | ||
| </head> | ||
| <body> | ||
| <div id="main"></div> | ||
| <pre id="log"></pre> | ||
| <script> | ||
| window.wasmLogOutput = []; | ||
| (function() { | ||
| var logdiv = document.getElementById('log'); | ||
| var cl = console.log; | ||
| console.log = function() { | ||
| var a = []; | ||
| for (var i = 0; i < arguments.length; i++) { | ||
| a.push(arguments[i]); | ||
| } | ||
| var line = a.join(' ') + "\n"; | ||
| window.wasmLogOutput.push(line); | ||
| var ret = cl.apply(console, arguments) | ||
| var el = document.createElement('span'); | ||
| el.innerText = line; | ||
| logdiv.appendChild(el); | ||
| return ret | ||
| } | ||
| })() | ||
| </script> | ||
| <script src="/wasm_exec.js"></script> | ||
| <script> | ||
| var wasmSupported = (typeof WebAssembly === "object"); | ||
| if (wasmSupported) { | ||
| var mainWasmReq = fetch("/%s").then(function(res) { | ||
| if (res.ok) { | ||
| const go = new Go(); | ||
| WebAssembly.instantiateStreaming(res, go.importObject).then((result) => { | ||
| go.run(result.instance); | ||
| }); | ||
| } else { | ||
| res.text().then(function(txt) { | ||
| var el = document.getElementById("main"); | ||
| el.style = 'font-family: monospace; background: black; color: red; padding: 10px'; | ||
| el.innerText = txt; | ||
| }) | ||
| } | ||
| }) | ||
| } else { | ||
| document.getElementById("main").innerHTML = 'This application requires WebAssembly support. Please upgrade your browser.'; | ||
| } | ||
| </script> | ||
| </body> | ||
| </html>`, r.FormValue("file")) | ||
| return | ||
| } | ||
|
|
||
| fsh.ServeHTTP(w, r) | ||
| }) | ||
|
|
||
| log.Printf("Starting server at %q for dir: %s", *addr, absDir) | ||
| log.Fatal(http.ListenAndServe(*addr, h)) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
rmhere is not strictly necessary because the CI container will be thrown away anyway after use. But there's no harm either (rmshould be very fast).