Skip to content
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

Autobahn ci #5

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5ea9aeb
add ci for building the server and running tests
francoganga Mar 6, 2024
5b17562
making the test server compile.
francoganga Mar 6, 2024
70178d2
add dune file for building the server.
francoganga Mar 6, 2024
0d77645
using network=host(the other way didnt work for me)
francoganga Mar 6, 2024
d97d4d4
adding a docker image of the test server
francoganga Mar 6, 2024
0cfaeeb
test building and pushing.
francoganga Mar 6, 2024
ff340cb
figuring out build/push github action.
francoganga Mar 6, 2024
4af788b
permissions.
francoganga Mar 6, 2024
4fc419d
dont install ocaml 2 times.
francoganga Mar 6, 2024
573e3bc
try to run the tests with a server running as a service.
francoganga Mar 6, 2024
f8d58dc
run the autobahn image.
francoganga Mar 6, 2024
58ef348
run sequentially.
francoganga Mar 6, 2024
9b5fe9a
try to fix mounts.
francoganga Mar 6, 2024
513c43b
trying to fix mounts again.
francoganga Mar 7, 2024
d26aed4
running autobahn with riot.
francoganga Mar 8, 2024
6100fb2
refactor: using spawn and error handling.
francoganga Mar 8, 2024
cb9b538
running test server with dune so it prints backtrace.
francoganga Mar 8, 2024
2f617dd
install spawn.
francoganga Mar 8, 2024
d614c0a
trying to get the errors to show.
francoganga Mar 8, 2024
8fc3a19
delete unused file.
francoganga Mar 8, 2024
c3ec924
cleaning up the code.
francoganga Mar 9, 2024
4d74ef2
dune fmt.
francoganga Mar 14, 2024
e166b25
using create_process instead of Spawn lib.
francoganga Mar 14, 2024
29e3e87
removing unnecessary Riot prefixes.
francoganga Mar 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/autobahn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Autobahn

on:
[pull_request, push]

permissions: read-all

jobs:
autobahn:
strategy:
fail-fast: false
matrix:
ocaml-compiler:
- "5.1"
allow-prerelease-opam:
- true
opam-repositories:
- |-
default: https://github.com/ocaml/opam-repository.git
# include:
# - os: windows-latest
# ocaml-compiler: ocaml-variants.5.1.0+options,ocaml-option-mingw
# allow-prerelease-opam: false
# opam-repositories: |-
# windows-5.0: https://github.com/dra27/opam-repository.git#windows-5.0
# sunset: https://github.com/ocaml-opam/opam-repository-mingw.git#sunset
# default: https://github.com/ocaml/opam-repository.git

runs-on: ubuntu-latest

steps:
- name: Checkout tree
uses: actions/checkout@v4

- name: Set-up OCaml
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}
allow-prerelease-opam: ${{ matrix.allow-prerelease-opam }}
opam-repositories: ${{ matrix.opam-repositories }}

- name: install dependencies
run: |
opam pin atacama.0.0.5 git+https://github.com/suri-framework/atacama -y
opam pin trail git+https://github.com/suri-framework/trail -y

opam install . --deps-only --with-test
opam install spawn -y

- run: |
eval $(opam env)
dune exec test/autobahn/server.exe

- name: upload reports
uses: actions/upload-artifact@v4
with:
name: report.html
path: _build/reports/clients/index.html
9 changes: 9 additions & 0 deletions test/autobahn/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(executable
(public_name server)
(name server)
(libraries
nomad
riot
trail
spawn
))
4 changes: 2 additions & 2 deletions test/autobahn/run
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
docker run -it --rm \
-v "${PWD}/test/autobahn/fuzzingclient.json:/fuzzingclient.json" \
-v "${PWD}/_build/reports:/reports" \
-p 2113:2113 \
--name nomad \
--network="host" \
crossbario/autobahn-testsuite \
wstest --mode fuzzingclient \
-w ws://host.docker.internal:2112
-w ws://0.0.0.0:2112
96 changes: 86 additions & 10 deletions test/autobahn/server.ml
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
open Riot
francoganga marked this conversation as resolved.
Show resolved Hide resolved

module Echo_server = struct
type args = unit
type state = int

let init conn _args = `continue (conn, 0)

let handle_frame frame _conn _state =
Logger.info (fun f -> f "handling frame: %a" Trail.Frame.pp frame);
`push [ frame ]
end
let init (_args : args) : (state, [> `Unknown_opcode of int]) Trail.Sock.handle_result =
`ok 1

let handle_frame frame _conn _state : (state, [> `Unknown_opcode of int]) Trail.Sock.handle_result =
Riot.Logger.info (fun f -> f "handling frame: %a" Trail.Frame.pp frame);
`push ([ frame ], _state)

module Test : Application.Intf = struct
let name = "test"
(* val handle_message : *)
(* Message.t -> state -> (state, [> `Unknown_opcode of int ]) handle_result *)
let handle_message _message _state : (state, [> `Unknown_opcode of int]) Trail.Sock.handle_result =
`ok 2
end

module Test : Riot.Application.Intf = struct
let start () =
let open Riot in
Logger.set_log_level (Some Debug);
sleep 0.1;
Logger.info (fun f -> f "starting nomad server");
Expand All @@ -25,9 +30,80 @@ module Test : Application.Intf = struct
conn |> Trail.Conn.upgrade (`websocket (upgrade_opts, handler))
in

let handler = Nomad.trail [ Trail.logger ~level:Debug (); ws_echo ] in
let handler = Nomad.trail [ ws_echo ] in

Nomad.start_link ~port:2112 ~handler ()
end

let () = Riot.start ~apps:[ (module Logger); (module Test) ] ()
module Utils = struct

let get_cwd () =
try
Ok(Unix.getcwd ())
with
| Unix.Unix_error (_, _, _) ->
Error "Failed to get current working directory"



let init () =
let (let*) = Result.bind in

let* cwd = get_cwd () in

let config_volume = Filename.concat cwd "/test/autobahn/fuzzingclient.json:/fuzzingclient.json" in
let reports_volume = Filename.concat cwd "/_build/reports:/reports" in

let args = [
"docker";
"run";
"--rm";
"-v";
config_volume;
"-v";
reports_volume;
"--name";
"nomad";
"--net=host";
"crossbario/autobahn-testsuite";
"wstest";
"--mode";
"fuzzingclient";
"-w";
"ws://0.0.0.0:2112"
] in

let path =
match Sys.getenv_opt "PATH" with
| None -> []
| exception Not_found -> []
| Some s -> String.split_on_char ':' s in

let find_prog prog =
let rec search = function
| [] -> None
| x :: xs ->
let prog = Filename.concat x prog in
if Sys.file_exists prog then Some prog else search xs in
search path in

match find_prog "docker" with
| None -> Error "Failed to find docker executable in PATH"
| Some prog ->
let process () =
let pid = Spawn.spawn ~prog ~argv:args ~stdin:Unix.stdin ~stdout:Unix.stdout ~stderr:Unix.stderr () in
Riot.(Logger.info (fun f -> f "Spawed docker with pid %d" pid));
in
Ok process
end

module Autobahn : Riot.Application.Intf = struct

let start () =
let process = Utils.init () in
match process with
| Ok p -> Ok (Riot.spawn p)
| Error err -> Error (`Application_error err)
end

let () = Riot.start ~apps:[ (module Riot.Logger); (module Test) ;(module Autobahn) ] ()