Skip to content

Commit

Permalink
ioc/tests: init example-ioc test
Browse files Browse the repository at this point in the history
Tests that the example IOC generated by makeBaseApp.pl compiles, run,
and is coherent.
  • Loading branch information
minijackson committed Jul 29, 2024
1 parent 25f2e10 commit 394901a
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
1 change: 1 addition & 0 deletions ioc/tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
69 changes: 69 additions & 0 deletions ioc/tests/example-ioc/default.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
23 changes: 23 additions & 0 deletions ioc/tests/example-ioc/epnix.nix
Original file line number Diff line number Diff line change
@@ -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";
};
};
}
21 changes: 21 additions & 0 deletions ioc/tests/example-ioc/example-top.patch
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 394901a

Please sign in to comment.