diff --git a/ioc/tests/default.nix b/ioc/tests/default.nix index 4150e7d8..5ee713fb 100644 --- a/ioc/tests/default.nix +++ b/ioc/tests/default.nix @@ -3,6 +3,7 @@ with pkgs.lib; { default-ioc-epics-base-3 = import ./default-ioc "3" args; default-ioc-epics-base-7 = import ./default-ioc "7" args; + example-ioc = import ./example-ioc args; pyepics = import ./pyepics args; diff --git a/ioc/tests/example-ioc/default.nix b/ioc/tests/example-ioc/default.nix new file mode 100644 index 00000000..dcd711a5 --- /dev/null +++ b/ioc/tests/example-ioc/default.nix @@ -0,0 +1,69 @@ +{pkgs, ...}: let + inherit (pkgs) epnixLib; + inherit (pkgs.stdenv.hostPlatform) system; + + result = epnixLib.evalEpnixModules { + nixpkgsConfig.system = system; + epnixConfig.imports = [ + (import ./epnix.nix) + ]; + }; + + service = result.config.epnix.nixos.services.ioc.config; + + ioc = result.outputs.build; +in + pkgs.nixosTest { + name = "example-ioc"; + meta.maintainers = with epnixLib.maintainers; [minijackson]; + + nodes.machine = { + environment.systemPackages = [pkgs.epnix.epics-base]; + systemd.services.ioc = service; + }; + + testScript = '' + machine.wait_for_unit("default.target") + machine.wait_for_unit("ioc.service") + + def logs_has(content: str) -> None: + machine.wait_until_succeeds(f"journalctl --no-pager -u ioc.service | grep -F '{content}'") + + with subtest("wait until started"): + machine.wait_until_succeeds("caget -t epnix:aiExample") + + with subtest("EPICS revision is correct"): + logs_has("## EPICS R7") + + with subtest("ai/calc records"): + ai_example = int(machine.wait_until_succeeds("caget -t epnix:aiExample").strip()) + assert 0 <= ai_example <= 9 + + with subtest("version record"): + assert machine.succeed("caget -t epnix:simple:version").strip() == "EPNix" + + with subtest("aSub record"): + logs_has("Record epnix:aSubExample called myAsubInit") + logs_has("Record epnix:aSubExample called myAsubProcess") + + # Also needs the debug mode activated above + with subtest("sub record"): + logs_has("Record epnix:subExample called mySubInit") + machine.succeed("caput epnix:subExample 42") + logs_has("Record epnix:subExample called mySubProcess") + + with subtest("Sequencer program is running"): + logs_has("sncExample: Startup delay over") + logs_has("sncExample: Changing to") + + with subtest("Sequencer program is running"): + machine.succeed("echo 'hello world' | nc localhost 2000 -N") + logs_has("Hello world, from simple") + + # TODO: test QSRV, but it feels flaky, pvget times-out most of the time + ''; + + passthru = { + inherit ioc; + }; + } diff --git a/ioc/tests/example-ioc/epnix.nix b/ioc/tests/example-ioc/epnix.nix new file mode 100644 index 00000000..28911e17 --- /dev/null +++ b/ioc/tests/example-ioc/epnix.nix @@ -0,0 +1,23 @@ +{pkgs, ...}: { + epnix = { + meta.name = "checks-example-ioc"; + buildConfig.src = + pkgs.runCommand "example-top" { + nativeBuildInputs = [pkgs.epnix.epics-base]; + } '' + mkdir $out + cd $out + makeBaseApp.pl -u epnix -t example simple + makeBaseApp.pl -u epnix -t example -i -a linux-x86_64 -p simple Simple + ''; + + buildConfig.attrs.patches = [./example-top.patch]; + + support.modules = with pkgs.epnix.support; [seq]; + + nixos.services.ioc = { + app = "simple"; + ioc = "iocSimple"; + }; + }; +} diff --git a/ioc/tests/example-ioc/example-top.patch b/ioc/tests/example-ioc/example-top.patch new file mode 100644 index 00000000..95c2e9fb --- /dev/null +++ b/ioc/tests/example-ioc/example-top.patch @@ -0,0 +1,21 @@ +diff --git a/iocBoot/iocSimple/st.cmd b/iocBoot/iocSimple/st.cmd +index af59327..bc12277 100755 +--- a/iocBoot/iocSimple/st.cmd ++++ b/iocBoot/iocSimple/st.cmd +@@ -17,13 +17,13 @@ dbLoadRecords "db/simpleVersion.db", "user=epnix" + dbLoadRecords "db/dbSubExample.db", "user=epnix" + + #- Set this to see messages from mySub +-#-var mySubDebug 1 ++var mySubDebug 1 + + #- Run this to trace the stages of iocInit +-#-traceIocInit ++traceIocInit + + cd "${TOP}/iocBoot/${IOC}" + iocInit + + ## Start any sequence programs +-#seq sncExample, "user=epnix" ++seq sncExample, "user=epnix"