"""Tiny test programs for sideloading, built from bytes: no compiler needed. - elf_arm64(), elf_x86_64(): static Linux executables that sleep for a few seconds (nanosleep) and exit 0, so a launch can be seen in `ps`. - pe_x86_64(): a Windows x86-64 .exe with no imports whose entry point returns 0 straight away, which ends the process (Windows and Wine both exit when the main thread returns). Each is a single loadable segment or section; they are what the headset smoke test and the fake Frame's e2e tests install. Python stdlib only. """ import struct SLEEP_SECONDS = 10 BASE = 0x400000 def _elf(machine, code): """ELF64 little-endian ET_EXEC with one PT_LOAD (R+X) covering the whole file.""" ehsize, phsize = 64, 56 entry = BASE + ehsize + phsize size = ehsize + phsize + len(code) ident = b'\x7fELF' + bytes([2, 1, 1, 0]) + b'\0' * 8 header = ident + struct.pack(' (file name, builder) 'arm64': ('fc-smoke-arm64', elf_arm64), 'x86_64': ('fc-smoke-x86_64', elf_x86_64), 'exe': ('fc-smoke-exe.exe', pe_x86_64), } def write(folder, kind): """Write one program into folder; returns its path.""" import os name, build = PROGRAMS[kind] path = os.path.join(folder, name) with open(path, 'wb') as f: f.write(build()) os.chmod(path, 0o755) return path