Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/daemon/driver-discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ async function discoverIosDriver(
idGenerator: options.idGenerator,
instanceId: options.instanceId,
logger: logger.child("ios"),
logsRoot: `${homedir()}/Library/Logs/CoreSimulator`,
onSilenceFailed: logSilenceFailure(logger),
onWindowFailed: logWindowFailure(logger),
onSlimmed: emitSlimDiagnostic(options.eventBus),
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/state-owners.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ describe("the seed tables' one-ready-seed-per-kind index (#1367)", () => {
state.database
.prepare("SELECT version FROM schema_versions WHERE owner = ?")
.get(owner.name),
).toEqual({ version: 2 });
).toEqual({ version: owner.version });
expect(
state.database
.prepare(`SELECT source_id, kind, state FROM ${table} ORDER BY source_id`)
Expand Down
2 changes: 2 additions & 0 deletions src/drivers/ios/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Resolve and boot:
Seeds (ADR 0061):

- A simulator is a clone of its kind's seed. A seed is known by its `ios_source_data` row, never by name, and lives in the sources set: `sources` in the owned set, an owned root of its own under `default`. It is in no `listManaged` or `simlock simctl list`.
- A seed is made from a throwaway (ADR 0076): `simlock-seed-<id>` is created in the device set, booted once and shut down, cloned unbooted into the sources set, then deleted with its log folder (`logsRoot`), so a seed never names its own folder. Under `default` the throwaway carries this instance's marks and DeviceHub clipboard sync is off before its boot. `saveSource` deletes the saved-from lease's log folder the same way. A log folder that cannot be deleted is logged and the make or save goes on; a throwaway that cannot be deleted fails the make.
- A throwaway is deleted only through the `making` row that names it (`throwaway_udid`): `listManaged` leaves it out, and the first `listSources` of a later process (or the next make of its kind) deletes it with its log folder and the row.
- Every clone (a seed's copy, `saveSource`'s own clone, a `provision` with `source`) has its `data/var/db/lsd/com.apple.LaunchServices-*.csstore` deleted before its first boot: it records each app, system apps included, under the original device's folder. A clone whose drop fails is deleted.
- Two provisions of a kind make one seed; clones of a seed and its deletion take turns.
- A `clone` or `create` waits `ios.simulator.createTimeoutMs`. At the limit it fails but `simctl` runs on: the UDID it later prints is deleted, the seed's deletion waits for it, and one silent 5 minutes more is killed and logged.
Expand Down
2 changes: 2 additions & 0 deletions src/drivers/ios/driver-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export interface IosSimctlDriverOptions {
/** why: the daemon's pid is named in the staging directory of a new root. */
readonly pid?: number;
readonly coreSimulatorRoot?: string;
// why: where CoreSimulator keeps each simulator's log folder, which `simctl delete` leaves behind; with none given the driver deletes no log folder.
readonly logsRoot?: string;
// why: where launchd_sim keeps each simulator's overrides folder; a test points it elsewhere.
readonly launchdOverridesRoot?: string;
readonly onSlimmed?: (fact: SlimmedFact) => void;
Expand Down
23 changes: 15 additions & 8 deletions src/drivers/ios/index-device-set.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
seededDatabase,
simctlPassthrough,
spec,
throwawayUdid,
} from "./test-index.js";

describe("IosSimctlDriver device set", () => {
Expand Down Expand Up @@ -75,13 +76,18 @@ describe("IosSimctlDriver device set", () => {
{
args: ["create", "simlock-seed-device-1", driverData.deviceTypeId, driverData.runtimeId],
scoped: true,
sources: true,
stdout: `${throwawayUdid}\n`,
},
{ args: ["boot", throwawayUdid], scoped: true },
{ args: ["bootstatus", throwawayUdid, "-b"], scoped: true },
{ args: ["listapps", throwawayUdid], scoped: true },
{ args: ["shutdown", throwawayUdid], scoped: true },
{
args: ["clone", throwawayUdid, "simlock-seed-device-1", sourcesSet],
scoped: true,
stdout: `${seedUdid}\n`,
},
{ args: ["boot", seedUdid], scoped: true, sources: true },
{ args: ["bootstatus", seedUdid, "-b"], scoped: true, sources: true },
{ args: ["listapps", seedUdid], scoped: true, sources: true },
{ args: ["shutdown", seedUdid], scoped: true, sources: true },
{ args: ["delete", throwawayUdid], scoped: true },
{
args: ["clone", seedUdid, driverData.name, devicesDir],
scoped: true,
Expand Down Expand Up @@ -109,9 +115,9 @@ describe("IosSimctlDriver device set", () => {
: ["simctl", ...step.args];
const runner = new ScriptedProcessRunner(
steps.flatMap((step) => [
...(!scoped && step.args[0] === "boot" && step.sources !== true
...(!scoped && step.args[0] === "boot" && step.args[1] !== seedUdid
? deviceHubEdit(
`Set :DevicePreferences:${driverData.udid}:pasteboardSyncEnabled false`,
`Set :DevicePreferences:${String(step.args[1])}:pasteboardSyncEnabled false`,
).map((match) => ({ match }))
: []),
{
Expand All @@ -121,14 +127,15 @@ describe("IosSimctlDriver device set", () => {
: { result: { code: 0, stderr: "", stdout: step.stdout } }),
},
...(!scoped && step.args[0] === "delete"
? deviceHubEdit(`Delete :DevicePreferences:${driverData.udid}`).map((match) => ({
? deviceHubEdit(`Delete :DevicePreferences:${String(step.args[1])}`).map((match) => ({
match,
}))
: []),
]),
);
const filesystem = new MemoryFilesystem();
await plantDevice(filesystem, devicesDir);
await filesystem.mkdirp(`${devicesDir}/${throwawayUdid}/data`);
if (scoped) await plantManagedDevice(filesystem);
const driver = await IosSimctlDriver.create({
database: await memorySourceDatabase(),
Expand Down
72 changes: 25 additions & 47 deletions src/drivers/ios/index-seed-provision.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
seededDatabase,
sourcesSimctl,
spec,
throwawaySeedSteps,
throwawayUdid,
} from "./test-index.js";

/**
Expand Down Expand Up @@ -61,19 +63,7 @@ describe("IosSimctlDriver", () => {
const cloneInvocation = sourcesSimctl("clone", seedUdid, driverData.name, deviceRoot);
const runner = new ScriptedProcessRunner([
{ match: listInvocation, result: { code: 0, stderr: "", stdout: listFixture } },
{
match: sourcesSimctl(
"create",
"simlock-seed-device-1",
driverData.deviceTypeId,
driverData.runtimeId,
),
result: { code: 0, stderr: "", stdout: `${seedUdid}\n` },
},
{ match: sourcesSimctl("boot", seedUdid) },
{ match: sourcesSimctl("bootstatus", seedUdid, "-b") },
{ match: sourcesSimctl("listapps", seedUdid) },
{ match: sourcesSimctl("shutdown", seedUdid) },
...throwawaySeedSteps(),
{ match: cloneInvocation, result: { code: 0, stderr: "", stdout: `${driverData.udid}\n` } },
]);
const filesystem = new MemoryFilesystem();
Expand All @@ -100,28 +90,26 @@ describe("IosSimctlDriver", () => {
const copyUdid = "00000000-0000-0000-0000-000000000002";
const database = await memorySourceDatabase();
const rowsWhenCreated: unknown[] = [];
const seedCreate = sourcesSimctl(
const seedCreate = simctl(
"create",
"simlock-seed-device-1",
driverData.deviceTypeId,
driverData.runtimeId,
);
const cloneInvocation = sourcesSimctl("clone", seedUdid, driverData.name, deviceRoot);
const [create, ...afterCreate] = throwawaySeedSteps();
const runner = new ScriptedProcessRunner([
{ match: listInvocation, result: { code: 0, stderr: "", stdout: listFixture } },
{
...create,
match: seedCreate,
onSpawn: () => {
rowsWhenCreated.push(
...database.prepare("SELECT state, udid FROM ios_source_data").all(),
);
},
result: { code: 0, stderr: "", stdout: `${seedUdid}\n` },
},
{ match: sourcesSimctl("boot", seedUdid) },
{ match: sourcesSimctl("bootstatus", seedUdid, "-b") },
{ match: sourcesSimctl("listapps", seedUdid) },
{ match: sourcesSimctl("shutdown", seedUdid) },
...afterCreate,
{ match: cloneInvocation, result: { code: 0, stderr: "", stdout: `${driverData.udid}\n` } },
{ match: cloneInvocation, result: { code: 0, stderr: "", stdout: `${copyUdid}\n` } },
]);
Expand All @@ -146,15 +134,20 @@ describe("IosSimctlDriver", () => {
expect(runner.calls).toEqual([
{ ...listInvocation, options: { timeoutMs: 30_000 } },
{ ...seedCreate, options: { timeoutMs: 330_000 } },
{ ...sourcesSimctl("boot", seedUdid), options: { timeoutMs: 300_000 } },
{ ...sourcesSimctl("bootstatus", seedUdid, "-b"), options: { timeoutMs: 300_000 } },
{ ...sourcesSimctl("listapps", seedUdid), options: { timeoutMs: 30_000 } },
{ ...sourcesSimctl("shutdown", seedUdid), options: { timeoutMs: 30_000 } },
{ ...simctl("boot", throwawayUdid), options: { timeoutMs: 300_000 } },
{ ...simctl("bootstatus", throwawayUdid, "-b"), options: { timeoutMs: 300_000 } },
{ ...simctl("listapps", throwawayUdid), options: { timeoutMs: 30_000 } },
{ ...simctl("shutdown", throwawayUdid), options: { timeoutMs: 30_000 } },
{
...simctl("clone", throwawayUdid, "simlock-seed-device-1", `${deviceRoot}/sources`),
options: { timeoutMs: 330_000 },
},
{ ...simctl("delete", throwawayUdid), options: { timeoutMs: 30_000 } },
{ ...cloneInvocation, options: { timeoutMs: 330_000 } },
]);

await expect(driver.provision(spec)).resolves.toMatchObject({ deviceId: copyUdid });
expect(runner.calls.slice(7)).toEqual([
expect(runner.calls.slice(9)).toEqual([
{ ...cloneInvocation, options: { timeoutMs: 330_000 } },
]);
});
Expand Down Expand Up @@ -188,19 +181,7 @@ describe("IosSimctlDriver", () => {
const runner = new ScriptedProcessRunner([
{ match: listInvocation, result: { code: 0, stderr: "", stdout: listFixture } },
{ match: listInvocation, result: { code: 0, stderr: "", stdout: listFixture } },
{
match: sourcesSimctl(
"create",
"simlock-seed-device-1",
driverData.deviceTypeId,
driverData.runtimeId,
),
result: { code: 0, stderr: "", stdout: `${seedUdid}\n` },
},
{ match: sourcesSimctl("boot", seedUdid) },
{ match: sourcesSimctl("bootstatus", seedUdid, "-b") },
{ match: sourcesSimctl("listapps", seedUdid) },
{ match: sourcesSimctl("shutdown", seedUdid) },
...throwawaySeedSteps(),
{ hangs: true, match: cloneInvocation },
{ match: cloneInvocation, result: { code: 0, stderr: "", stdout: `${copyUdid}\n` } },
]);
Expand All @@ -209,12 +190,13 @@ describe("IosSimctlDriver", () => {
const driver = await createDriver(runner, clock, filesystem);
await plantManagedDevice(filesystem);
await filesystem.mkdirp(`${deviceRoot}/${copyUdid}/data`);
const clones = (): number => runner.calls.filter((call) => call.args[3] === "clone").length;
const clones = (): number =>
runner.calls.filter((call) => call.args[3] === "clone" && call.args[4] === seedUdid).length;

const first = driver.provision(spec);
const second = driver.provision(spec);
const firstSettled = first.catch((caught: unknown) => caught);
await waitForCalls(runner, 8);
await waitForCalls(runner, 10);

expect(runner.calls.filter((call) => call.args[3] === "create")).toHaveLength(1);
for (let tick = 0; tick < 100; tick += 1) await Promise.resolve();
Expand Down Expand Up @@ -243,7 +225,7 @@ describe("IosSimctlDriver", () => {
steps: [
{
hangs: true,
match: sourcesSimctl(
match: simctl(
"create",
"simlock-seed-device-1",
driverData.deviceTypeId,
Expand Down Expand Up @@ -338,13 +320,9 @@ describe("IosSimctlDriver", () => {
{
call: "a seed's create",
act: (driver: IosSimctlDriver) => driver.provision(spec),
deleteArgs: (udid: string) => sourcesSimctl("delete", udid).args,
hung: sourcesSimctl(
"create",
"simlock-seed-device-1",
driverData.deviceTypeId,
driverData.runtimeId,
).args,
deleteArgs: (udid: string) => simctl("delete", udid).args,
hung: simctl("create", "simlock-seed-device-1", driverData.deviceTypeId, driverData.runtimeId)
.args,
isDefault: false,
seeded: false,
steps: [],
Expand Down
Loading
Loading