shrub/app/ph.hoon

482 lines
13 KiB
Plaintext
Raw Normal View History

2019-02-12 02:25:25 +03:00
:: Test the pH of your aquarium. See if it's safe to put in real fish.
2019-02-06 05:21:41 +03:00
::
:: usage:
:: :aqua [%run-test %test-add]
::
:: TODO:
:: - Restore a fleet
:: - Compose tests
::
/- aquarium, ph
/+ ph, ph-tests, ph-azimuth, ph-philter
=, ph-sur=^ph
2019-02-06 05:21:41 +03:00
=, aquarium
=, ph
=, ph-philter
2019-02-06 05:21:41 +03:00
=> $~ |%
2019-03-06 23:22:37 +03:00
+$ move (pair bone card)
+$ card
2019-03-08 08:15:42 +03:00
$% [%poke wire dock poke-type]
2019-02-09 00:34:24 +03:00
[%peer wire dock path]
[%pull wire dock ~]
2019-03-08 08:15:42 +03:00
[%diff diff-type]
2019-02-06 05:21:41 +03:00
==
::
2019-03-08 08:15:42 +03:00
+$ poke-type
2019-03-07 10:31:14 +03:00
$% [%aqua-events (list aqua-event)]
[%drum-start term term]
2019-03-08 08:15:42 +03:00
[%aqua-vane-control ?(%subscribe %unsubscribe)]
==
::
+$ diff-type
$% [%aqua-effects aqua-effects]
2019-03-07 10:31:14 +03:00
==
::
2019-03-06 23:22:37 +03:00
+$ state
2019-02-06 05:21:41 +03:00
$: %0
2019-03-21 03:37:05 +03:00
test-core=(unit test-core-state)
2019-04-23 00:47:25 +03:00
tests=(map term [(list ship) _*form:(ph ,~)])
2019-02-06 05:21:41 +03:00
other-state
==
2019-03-06 23:22:37 +03:00
::
+$ test-core-state
$: lab=term
hers=(list ship)
2019-04-23 00:47:25 +03:00
test=_*form:(ph ,~)
2019-03-06 23:22:37 +03:00
==
::
+$ other-state
$: test-qeu=(qeu term)
2019-03-21 03:37:05 +03:00
results=(list (pair term ?))
2019-03-27 04:07:42 +03:00
effect-log=(list [who=ship uf=unix-effect])
2019-03-21 03:37:05 +03:00
==
2019-02-06 05:21:41 +03:00
--
=, gall
2019-03-09 00:48:09 +03:00
=/ vane-apps=(list term)
2019-03-23 04:11:04 +03:00
~[%aqua-ames %aqua-behn %aqua-dill %aqua-eyre]
2019-02-06 05:21:41 +03:00
|_ $: hid=bowl
state
==
++ this .
2019-03-20 23:57:24 +03:00
++ manual-tests
2019-04-23 00:47:25 +03:00
^- (list (pair term [(list ship) _*form:(ph ,~)]))
=+ (ph-tests our.hid)
2019-04-24 23:13:52 +03:00
=/ eth-node (spawn:ph-azimuth ~bud)
2019-04-20 01:04:50 +03:00
=/ m (ph ,~)
2019-04-13 09:54:30 +03:00
:~ :+ %boot-bud
~[~bud]
2019-04-14 05:51:46 +03:00
(raw-ship ~bud ~)
2019-04-20 02:29:14 +03:00
::
:+ %add
~[~bud]
;< ~ bind:m (raw-ship ~bud ~)
|= pin=ph-input
?: =(%init -.q.uf.pin)
[& (dojo ~bud "[%test-result (add 2 3)]") %wait ~]
?: (is-dojo-output ~bud who.pin uf.pin "[%test-result 5]")
[& ~ %done ~]
[& ~ %wait ~]
2019-04-18 23:52:00 +03:00
::
:+ %hi
~[~bud ~dev]
2019-04-20 01:04:50 +03:00
;< ~ bind:m (raw-ship ~bud ~)
;< ~ bind:m (raw-ship ~dev ~)
2019-04-18 23:52:00 +03:00
(send-hi ~bud ~dev)
2019-04-20 02:29:14 +03:00
::
:+ %boot-planet
~[~bud ~marbud ~linnup-torsyx]
(planet ~linnup-torsyx)
::
:+ %second-cousin-hi
~[~bud ~marbud ~linnup-torsyx ~dev ~mardev ~mitnep-todsut]
;< ~ bind:m (planet ~linnup-torsyx)
;< ~ bind:m (planet ~mitnep-todsut)
(send-hi ~linnup-torsyx ~mitnep-todsut)
::
:+ %change-file
~[~bud]
;< ~ bind:m (raw-ship ~bud ~)
;< file=@t bind:m (touch-file ~bud %home)
(check-file-touched ~bud %home file)
::
:+ %child-sync
~[~bud ~marbud]
;< ~ bind:m (star ~marbud)
;< file=@t bind:m (touch-file ~bud %base)
(check-file-touched ~marbud %home file)
2019-04-20 04:03:54 +03:00
::
:+ %boot-az
~[~bud]
;< [eth-node=_eth-node ~] bind:m
2019-04-20 04:03:54 +03:00
%+ (wrap-philter ,_eth-node ,~)
router:eth-node
(raw-ship ~bud `(dawn:eth-node ~bud))
(pure:m ~)
::
:+ %breach-hi
~[~bud ~dev]
2019-04-24 23:13:52 +03:00
=. eth-node (spawn:eth-node ~dev)
;< [eth-node=_eth-node ~] bind:m
2019-04-20 04:03:54 +03:00
%+ (wrap-philter ,_eth-node ,~)
router:eth-node
;< ~ bind:m (raw-ship ~bud `(dawn:eth-node ~bud))
;< ~ bind:m (raw-ship ~dev `(dawn:eth-node ~dev))
(send-hi ~bud ~dev)
;< eth-node=_eth-node bind:m
(breach-and-hear:eth-node our.hid ~dev ~bud)
;< [eth-node=_eth-node ~] bind:m
%+ (wrap-philter ,_eth-node ,~)
router:eth-node
;< ~ bind:m (send-hi-not-responding ~bud ~dev)
;< ~ bind:m (raw-ship ~dev `(dawn:eth-node ~dev))
(wait-for-dojo ~bud "hi ~dev successful")
2019-04-23 00:47:25 +03:00
(pure:m ~)
2019-04-24 23:13:52 +03:00
::
:+ %breach-hi-cousin
~[~bud ~dev ~marbud ~mardev]
=. eth-node (spawn:eth-node ~dev)
=. eth-node (spawn:eth-node ~marbud)
=. eth-node (spawn:eth-node ~mardev)
;< [eth-node=_eth-node ~] bind:m
%+ (wrap-philter ,_eth-node ,~)
router:eth-node
;< ~ bind:m (raw-ship ~bud `(dawn:eth-node ~bud))
;< ~ bind:m (raw-ship ~dev `(dawn:eth-node ~dev))
2019-04-30 20:40:38 +03:00
;< ~ bind:m (raw-ship ~marbud `(dawn:eth-node ~marbud))
;< ~ bind:m (raw-ship ~mardev `(dawn:eth-node ~mardev))
2019-04-24 23:13:52 +03:00
(send-hi ~marbud ~mardev)
;< eth-node=_eth-node bind:m
(breach-and-hear:eth-node our.hid ~mardev ~marbud)
;< [eth-node=_eth-node ~] bind:m
%+ (wrap-philter ,_eth-node ,~)
router:eth-node
;< ~ bind:m (send-hi-not-responding ~marbud ~mardev)
;< ~ bind:m (raw-ship ~mardev `(dawn:eth-node ~mardev))
2019-04-30 20:40:38 +03:00
(wait-for-dojo ~marbud "hi ~mardev successful")
(pure:m ~)
::
:+ %breach-sync
2019-05-14 08:20:46 +03:00
~[~bud ~marbud]
=. eth-node (spawn:eth-node ~marbud)
2019-04-30 20:40:38 +03:00
;< [eth-node=_eth-node ~] bind:m
%+ (wrap-philter ,_eth-node ,~)
router:eth-node
;< ~ bind:m (raw-ship ~bud `(dawn:eth-node ~bud))
2019-05-14 08:20:46 +03:00
;< ~ bind:m (raw-ship ~marbud `(dawn:eth-node ~marbud))
;< file=@t bind:m (touch-file ~bud %base)
2019-05-23 00:39:12 +03:00
~& %checking-file-touched
2019-05-14 08:20:46 +03:00
(check-file-touched ~marbud %home file)
2019-05-23 00:39:12 +03:00
~& %checked-file-touched
2019-04-30 20:40:38 +03:00
;< eth-node=_eth-node bind:m
2019-05-14 08:20:46 +03:00
(breach-and-hear:eth-node our.hid ~bud ~marbud)
;< [eth-node=_eth-node ~] bind:m
%+ (wrap-philter ,_eth-node ,~)
router:eth-node
;< ~ bind:m (raw-ship ~bud `(dawn:eth-node ~bud))
;< ~ bind:m (just-events (dojo ~bud "|merge %base ~marbud %kids, =gem %this"))
;< file=@t bind:m (touch-file ~bud %base)
;< file=@t bind:m (touch-file ~bud %base)
(check-file-touched ~marbud %home file)
(pure:m ~)
::
:+ %breach-multiple
~[~bud ~marbud]
=. eth-node (spawn:eth-node ~marbud)
;< [eth-node=_eth-node ~] bind:m
%+ (wrap-philter ,_eth-node ,~)
router:eth-node
;< ~ bind:m (raw-ship ~bud `(dawn:eth-node ~bud))
;< ~ bind:m (raw-ship ~marbud `(dawn:eth-node ~marbud))
;< file=@t bind:m (touch-file ~bud %base)
(check-file-touched ~marbud %home file)
;< eth-node=_eth-node bind:m
(breach-and-hear:eth-node our.hid ~bud ~marbud)
;< [eth-node=_eth-node ~] bind:m
%+ (wrap-philter ,_eth-node ,~)
router:eth-node
(raw-ship ~bud `(dawn:eth-node ~bud))
;< eth-node=_eth-node bind:m
(breach-and-hear:eth-node our.hid ~marbud ~bud)
2019-04-30 20:40:38 +03:00
;< [eth-node=_eth-node ~] bind:m
%+ (wrap-philter ,_eth-node ,~)
router:eth-node
2019-05-14 08:20:46 +03:00
;< ~ bind:m (raw-ship ~marbud `(dawn:eth-node ~marbud))
;< file=@t bind:m (touch-file ~bud %base)
;< file=@t bind:m (touch-file ~bud %base)
(check-file-touched ~marbud %home file)
2019-04-24 23:13:52 +03:00
(pure:m ~)
2019-04-13 09:54:30 +03:00
==
::
2019-03-20 23:57:24 +03:00
++ install-tests
^+ this
=. tests (malt manual-tests)
2019-02-06 05:21:41 +03:00
this
::
++ prep
|= old=(unit [@ tests=* rest=*])
2019-02-09 00:34:24 +03:00
^- (quip move _this)
2019-03-21 03:37:05 +03:00
~& prep=%ph
2019-02-06 05:21:41 +03:00
=. this install-tests
2019-03-21 03:37:05 +03:00
`this
:: ?~ old
:: `this
:: =/ new ((soft other-state) rest.u.old)
:: ?~ new
:: `this
:: `this(+<+>+> u.new)
2019-02-06 05:21:41 +03:00
::
2019-03-07 10:31:14 +03:00
++ publish-aqua-effects
|= afs=aqua-effects
^- (list move)
%+ murn ~(tap by sup.hid)
|= [b=bone her=ship pax=path]
^- (unit move)
?. ?=([%effects ~] pax)
~
2019-03-08 09:28:10 +03:00
`[b %diff %aqua-effects afs]
2019-03-07 10:31:14 +03:00
::
2019-02-06 05:21:41 +03:00
++ run-events
2019-02-09 00:34:24 +03:00
|= [lab=term what=(list ph-event)]
^- (quip move _this)
2019-02-06 05:21:41 +03:00
?: =(~ what)
`this
=/ res
2019-03-21 03:37:05 +03:00
|- ^- (each (list aqua-event) ?)
2019-02-06 05:21:41 +03:00
?~ what
[%& ~]
?: ?=(%test-done -.i.what)
2019-03-21 03:37:05 +03:00
[%| p.i.what]
2019-02-06 05:21:41 +03:00
=/ nex $(what t.what)
?: ?=(%| -.nex)
nex
[%& `aqua-event`i.what p.nex]
?: ?=(%| -.res)
2019-03-21 03:37:05 +03:00
=^ moves-1 this (finish-test lab p.res)
=^ moves-2 this run-test
[(weld moves-1 moves-2) this]
2019-02-06 05:21:41 +03:00
[[ost.hid %poke /running [our.hid %aqua] %aqua-events p.res]~ this]
::
2019-02-09 00:34:24 +03:00
:: Cancel subscriptions to ships
::
2019-03-21 03:37:05 +03:00
++ finish-test
|= [lab=term success=?]
2019-02-09 00:34:24 +03:00
^- (quip move _this)
2019-03-21 03:37:05 +03:00
?~ test-core
2019-02-09 00:34:24 +03:00
`this
2019-04-14 05:51:46 +03:00
~& ?: success
"TEST {(trip lab)} SUCCESSFUL"
"TEST {(trip lab)} FAILED"
2019-03-21 03:37:05 +03:00
:_ this(test-core ~, results [[lab success] results])
2019-02-09 00:34:24 +03:00
%- zing
2019-03-21 03:37:05 +03:00
%+ turn hers.u.test-core
2019-02-09 00:34:24 +03:00
|= her=ship
^- (list move)
:~ [ost.hid %pull /[lab]/(scot %p her) [our.hid %aqua] ~]
:* ost.hid
%poke
/cancelling
[our.hid %aqua]
%aqua-events
[%pause-events her]~
==
==
::
2019-03-23 03:18:54 +03:00
:: Start another test if one is in the queue
2019-03-21 03:37:05 +03:00
::
++ run-test
^- (quip move _this)
?^ test-core
`this
?: =(~ test-qeu)
?~ results
`this
=/ throw-away print-results
`this(results ~)
=^ lab test-qeu ~(get to test-qeu)
~& [running-test=lab test-qeu]
2019-03-27 04:07:42 +03:00
=. effect-log ~
2019-04-23 00:47:25 +03:00
=+ ^- [ships=(list ship) test=_*form:(ph ,~)]
(~(got by tests) lab)
2019-03-21 03:37:05 +03:00
=> .(test-core `(unit test-core-state)`test-core)
=. test-core `[lab ships test]
2019-04-14 05:51:46 +03:00
=^ moves-1 this (subscribe-to-effects lab ships)
=^ moves-2 this
(diff-aqua-effects /[lab]/(scot %p -.ships) -.ships [/ %init ~]~)
2019-03-21 03:37:05 +03:00
[:(weld init-vanes pause-fleet subscribe-vanes moves-1 moves-2) this]
::
2019-03-23 03:18:54 +03:00
:: Print results with ~&
2019-03-21 03:37:05 +03:00
::
++ print-results
~& "TEST REPORT:"
=/ throw-away
%+ turn
results
|= [lab=term success=?]
~& "{?:(success "SUCCESS" "FAILURE")}: {(trip lab)}"
~
~& ?: (levy results |=([term s=?] s))
"ALL TESTS SUCCEEDED"
"FAILURES"
~
::
2019-02-06 05:21:41 +03:00
:: Should check whether we're already subscribed
::
++ subscribe-to-effects
|= [lab=@tas hers=(list ship)]
:_ this
%+ turn hers
|= her=ship
^- move
:* ost.hid
%peer
/[lab]/(scot %p her)
[our.hid %aqua]
/effects/(scot %p her)
==
::
2019-03-09 00:48:09 +03:00
:: Start the vane drivers
::
++ init-vanes
^- (list move)
%+ murn
`(list term)`[%aqua vane-apps]
|= vane-app=term
^- (unit move)
=/ app-started
.^(? %gu /(scot %p our.hid)/[vane-app]/(scot %da now.hid))
?: app-started
~
`[ost.hid %poke /start [our.hid %hood] %drum-start %home vane-app]
::
:: Restart the vane drivers' subscriptions
::
++ subscribe-vanes
^- (list move)
%+ turn
vane-apps
|= vane-app=term
[ost.hid %poke /init [our.hid vane-app] %aqua-vane-control %subscribe]
::
2019-03-13 14:50:56 +03:00
:: Pause all existing ships
::
++ pause-fleet
^- (list move)
:_ ~
:* ost.hid %poke /pause-fleet [our.hid %aqua] %aqua-events
%+ turn
.^((list ship) %gx /(scot %p our.hid)/aqua/(scot %da now.hid)/ships/noun)
|= who=ship
[%pause-events who]
==
::
2019-03-09 00:48:09 +03:00
:: User interface
::
++ poke-ph-command
|= com=cli:ph-sur
2019-02-06 05:21:41 +03:00
^- (quip move _this)
?- -.com
%init [init-vanes this]
%run
?. (~(has by tests) lab.com)
~& [%no-test lab.com]
2019-04-14 05:51:46 +03:00
`this
=. test-qeu (~(put to test-qeu) lab.com)
2019-03-21 03:37:05 +03:00
run-test
::
2019-03-21 03:45:36 +03:00
%cancel
=^ moves-1 this (finish-test %last |)
=. test-qeu ~
=^ moves-2 this run-test
[:(weld moves-1 moves-2) this]
::
%run-all
=. test-qeu
%- ~(gas to test-qeu)
(turn manual-tests head)
run-test
2019-03-06 23:22:37 +03:00
::
2019-03-21 03:37:05 +03:00
%print
2019-03-27 04:07:42 +03:00
~& lent=(lent effect-log)
~& %+ roll effect-log
2019-03-07 10:31:14 +03:00
|= [[who=ship uf=unix-effect] ~]
?: ?=(?(%blit %doze) -.q.uf)
2019-03-06 23:22:37 +03:00
~
2019-03-07 10:31:14 +03:00
?: ?=(%ergo -.q.uf)
~& [who [- +<]:uf %omitted-by-ph]
2019-03-06 23:22:37 +03:00
~
2019-03-07 10:31:14 +03:00
~& [who uf]
2019-03-06 23:22:37 +03:00
~
`this
2019-02-06 05:21:41 +03:00
==
::
2019-03-09 00:48:09 +03:00
:: Receive effects back from aqua
::
2019-02-08 05:03:46 +03:00
++ diff-aqua-effects
2019-03-07 10:31:14 +03:00
|= [way=wire afs=aqua-effects]
2019-02-06 05:21:41 +03:00
^- (quip move _this)
2019-03-08 08:15:42 +03:00
:: ~& [%diff-aqua-effect way who.afs]
2019-02-09 00:34:24 +03:00
?> ?=([@tas @ ~] way)
2019-02-06 05:21:41 +03:00
=/ lab i.way
2019-03-21 03:37:05 +03:00
?~ test-core
2019-04-09 07:13:06 +03:00
~& [%ph-dropping-done lab]
[[ost.hid %pull way [our.hid %aqua] ~]~ this]
?. =(lab lab.u.test-core)
~& [%ph-dropping-strange lab]
[[ost.hid %pull way [our.hid %aqua] ~]~ this]
2019-03-08 08:15:42 +03:00
=+ |- ^- $: thru-effects=(list unix-effect)
events=(list ph-event)
2019-03-27 04:07:42 +03:00
log=_effect-log
2019-04-14 05:51:46 +03:00
done=(unit ?)
test=_test.u.test-core
2019-03-07 10:31:14 +03:00
==
2019-03-08 08:15:42 +03:00
?~ ufs.afs
[~ ~ ~ ~ test.u.test-core]
2019-04-23 00:47:25 +03:00
=/ m-res=_*output:(ph ,~)
(test.u.test-core now.hid who.afs i.ufs.afs)
2019-04-14 05:51:46 +03:00
=? ufs.afs =(%cont -.next.m-res)
2019-04-20 01:04:50 +03:00
[i.ufs.afs [/ %init ~] t.ufs.afs]
=^ done=(unit ?) test.u.test-core
2019-04-14 05:51:46 +03:00
?- -.next.m-res
%wait [~ test.u.test-core]
2019-04-14 05:51:46 +03:00
%cont [~ self.next.m-res]
%fail [`| test.u.test-core]
%done [`& test.u.test-core]
2019-04-14 05:51:46 +03:00
==
=+ ^- _$
?~ done
$(ufs.afs t.ufs.afs)
[~ ~ ~ done test.u.test-core]
2019-04-14 05:51:46 +03:00
:^ ?: thru.m-res
2019-03-27 04:07:42 +03:00
[i.ufs.afs thru-effects]
thru-effects
2019-04-14 05:51:46 +03:00
(weld events.m-res events)
[[who i.ufs]:afs log]
[done test]
=. test.u.test-core test
2019-04-14 05:51:46 +03:00
=. effect-log (weld log effect-log)
=> .(test-core `(unit test-core-state)`test-core)
?^ done
=^ moves-1 this (finish-test lab u.done)
=^ moves-2 this run-test
[(weld moves-1 moves-2) this]
=/ moves-1 (publish-aqua-effects who.afs thru-effects)
=^ moves-2 this (run-events lab events)
[(weld moves-1 moves-2) this]
2019-03-07 10:31:14 +03:00
::
:: Subscribe to effects
::
++ peer-effects
|= pax=path
^- (quip move _this)
?. ?=(~ pax)
~& [%ph-bad-peer-effects pax]
`this
`this
2019-03-13 14:50:56 +03:00
::
:: Subscription cancelled
::
++ pull
|= pax=path
`+>.$
2019-02-06 05:21:41 +03:00
--