epson-escpr: restore correct install layout (#373003)
[NixPkgs.git] / nixos / tests / shadps4.nix
blobdafe3553e9c571110843b5914909c77fa19ab362
1 { pkgs, lib, ... }:
3   name = "shadps4-openorbis-example";
4   meta = {
5     inherit (pkgs.shadps4.meta) maintainers;
6     platforms = lib.intersectLists lib.platforms.linux pkgs.shadps4.meta.platforms;
7   };
9   nodes.machine =
10     { config, pkgs, ... }:
11     {
12       imports = [ ./common/x11.nix ];
14       environment = {
15         # Samples from the OpenOrbis PS4 homebrew toolchain, gpl3Only
16         etc."openorbis-sample-packages".source =
17           let
18             sample-packages = pkgs.fetchurl {
19               url = "https://github.com/OpenOrbis/OpenOrbis-PS4-Toolchain/releases/download/v0.5.2/sample-packages.zip";
20               hash = "sha256-aWocIVpyMivA1vsUe9w97J3eMFANyXxyVLBxHGXIcEA=";
21             };
22           in
23           pkgs.runCommand "OpenOrbis-PNG-Sample"
24             {
25               nativeBuildInputs = with pkgs; [ unzip ];
26               meta.license = lib.licenses.gpl3Only;
27             }
28             ''
29               unzip ${sample-packages} samples/IV0000-BREW00086_00-IPNGDRAWEX000000.pkg
30               mkdir $out
31               mv samples/IV0000-BREW00086_00-IPNGDRAWEX000000.pkg $out/OpenOrbis-PNG-Sample.pkg
32             '';
34         systemPackages = with pkgs; [
35           imagemagick # looking for colour on screen
36           shadps4
37           xdotool # move mouse
38         ];
40         variables = {
41           # Emulated CPU doesn't support invariant TSC
42           TRACY_NO_INVARIANT_CHECK = "1";
43         };
44       };
45     };
47   enableOCR = true;
49   testScript = ''
50     from collections.abc import Callable
51     import tempfile
52     import subprocess
54     selectionColor: str = "#2A82DA"
55     openorbisColor: str = "#336081"
57     # Based on terminal-emulators.nix' check_for_pink
58     def check_for_color(color: str) -> Callable[[bool], bool]:
59         def check_for_color_retry(final=False) -> bool:
60             with tempfile.NamedTemporaryFile() as tmpin:
61                 machine.send_monitor_command("screendump {}".format(tmpin.name))
63                 cmd = 'convert {} -define histogram:unique-colors=true -format "%c" histogram:info:'.format(
64                     tmpin.name
65                 )
66                 ret = subprocess.run(cmd, shell=True, capture_output=True)
67                 if ret.returncode != 0:
68                     raise Exception(
69                         "image analysis failed with exit code {}".format(ret.returncode)
70                     )
72                 text = ret.stdout.decode("utf-8")
73                 return color in text
75         return check_for_color_retry
77     machine.wait_for_x()
79     with subtest("starting shadps4 works"):
80         machine.succeed("shadps4 >&2 &")
81         machine.wait_for_text("Directory to install games")
82         machine.screenshot("0001-shadps4-dir-setup-prompt")
84         machine.send_chars("/root\n")
85         machine.wait_for_text("Game List")
86         # Make it fullscreen, so mouse coords are simpler & content isn't cut off
87         machine.send_key("alt-f10")
88         # Should now see the rest too
89         machine.wait_for_text("Play Time")
90         machine.screenshot("0002-shadps4-started")
92     with subtest("installing example works"):
93         machine.succeed("xdotool mousemove 20 30 click 1") # click on "File"
94         machine.wait_for_text("Install Packages")
95         machine.send_key("down")
96         machine.send_key("ret")
98         # Pick the PNG sample (hello world runs too, but text-only output is currently broken)
99         machine.wait_for_text("Look in")
100         machine.send_chars("/etc/openorbis-sample-packages/OpenOrbis-PNG-Sample.pkg\n")
102         # Install to default dir
103         machine.wait_for_text("which directory")
104         machine.send_key("ret")
106         # Wait for installation getting done & return to main window
107         machine.wait_for_text("successfully installed")
108         machine.send_key("ret")
110         # Sample should now be listed
111         machine.wait_for_text("OpenOrbis PNG Sample")
112         machine.screenshot("0003-shadps4-sample-installed")
114     with subtest("emulation works-ish"):
115         # Ensure that selection colours isn't present already
116         assert (
117             check_for_color(selectionColor)(True) == False
118         ), "selectionColor {} was present on the screen before we selected anything!".format(selectionColor)
120         # Select first installed app
121         machine.succeed("xdotool mousemove 20 150 click 1")
123         # Waiting for selection to be confirmed
124         with machine.nested("Waiting for the screen to have selectionColor {} on it:".format(selectionColor)):
125             retry(check_for_color(selectionColor))
127         # Ensure that chosen openorbis logo colour isn't present already
128         assert (
129             check_for_color(openorbisColor)(True) == False
130         ), "openorbisColor {} was present on the screen before we selected anything!".format(openorbisColor)
132         # Click launch button
133         machine.succeed("xdotool mousemove 40 60 click 1")
134         machine.wait_for_console_text("Entering draw loop...")
136         # Look for logo
137         with machine.nested("Waiting for the screen to have openorbisColor {} on it:".format(openorbisColor)):
138             retry(check_for_color(openorbisColor))
139         machine.screenshot("0004-shadps4-sample-running")
140   '';