Skip to content
Merged
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 ReferenceTests/Retro68/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ add_application(HighLevelEventCapture HighLevelEventCapture.c HighLevelEventCapt
add_application(MemoryManagerCapture MemoryManagerCapture.c)
add_application(MixedModeCapture MixedModeCapture.c)
add_application(RegionRecordingCapture RegionRecordingCapture.c)
add_application(ProcessManagerCapture ProcessManagerCapture.c)
1 change: 1 addition & 0 deletions ReferenceTests/Retro68/ProcessManager-macos-9.2.2-ppc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GetCurrentProcess -> 0 00000000:02270001self 00000000:02270001: name "ProcessManagerCapture" type 'APPL' signature '????' mode 00000080 length 60self 00000000:02270001: location set size nonzero free nonzero launcher 00000000:01F20001 launchDate nonzero activeTime zeroself 00000000:02270001: spec vRefNum set parID set name "ProcessManagerCapture"GetFrontProcess -> 0 00000000:01F20001SameProcess self front 00000000:02270001 00000000:01F20001 -> 0 result 0GetNextProcess[0] -> 0 00000000:01EA0001listed 00000000:01EA0001: name "Application Switcher" type 'appe' signature 'apsw' mode 00005CE4 length 60listed 00000000:01EA0001: location set size nonzero free nonzero launcher 00000000:00000001 launchDate nonzero activeTime nonzerolisted 00000000:01EA0001: spec vRefNum set parID set name "Application Switcher"GetNextProcess[1] -> 0 00000000:01EC0001listed 00000000:01EC0001: name "Control Strip Extension" type 'appe' signature 'sdev' mode 00005CC8 length 60listed 00000000:01EC0001: location set size nonzero free nonzero launcher 00000000:00000001 launchDate nonzero activeTime nonzerolisted 00000000:01EC0001: spec vRefNum set parID set name "Control Strip Extension"GetNextProcess[2] -> 0 00000000:01EE0001listed 00000000:01EE0001: name "DVD AutoLauncher" type 'appe' signature 'dval' mode 00005DE0 length 60listed 00000000:01EE0001: location set size nonzero free nonzero launcher 00000000:00000001 launchDate nonzero activeTime nonzerolisted 00000000:01EE0001: spec vRefNum set parID set name "DVD AutoLauncher"GetNextProcess[3] -> 0 00000000:01EF0001listed 00000000:01EF0001: name "FBC Indexing Scheduler" type 'appe' signature 'fbcb' mode 000014E0 length 60listed 00000000:01EF0001: location set size nonzero free nonzero launcher 00000000:00000001 launchDate nonzero activeTime nonzerolisted 00000000:01EF0001: spec vRefNum set parID set name "FBC Indexing Scheduler"GetNextProcess[4] -> 0 00000000:01F00001listed 00000000:01F00001: name "Folder Actions" type 'appe' signature 'ssrv' mode 00005CC0 length 60listed 00000000:01F00001: location set size nonzero free nonzero launcher 00000000:00000001 launchDate nonzero activeTime nonzerolisted 00000000:01F00001: spec vRefNum set parID set name "Folder Actions"GetNextProcess[5] -> 0 00000000:01F20001listed 00000000:01F20001: name "Finder" type 'FNDR' signature 'MACS' mode 00017BEC length 60listed 00000000:01F20001: location set size nonzero free nonzero launcher 00000000:00000000 launchDate nonzero activeTime nonzerolisted 00000000:01F20001: spec vRefNum set parID set name "Finder"GetNextProcess[6] -> 0 00000000:02040002listed 00000000:02040002: name "File Sharing Extension" type 'INIT' signature 'hhgg' mode 00043EC0 length 60listed 00000000:02040002: location set size nonzero free nonzero launcher 00000000:01F20001 launchDate nonzero activeTime nonzerolisted 00000000:02040002: spec vRefNum set parID set name "File Sharing Extension"GetNextProcess[7] -> 0 00000000:02270001listed 00000000:02270001: name "ProcessManagerCapture" type 'APPL' signature '????' mode 00000080 length 60listed 00000000:02270001: location set size nonzero free nonzero launcher 00000000:01F20001 launchDate nonzero activeTime zerolisted 00000000:02270001: spec vRefNum set parID set name "ProcessManagerCapture"GetNextProcess[8] -> -600 00000000:00000000kCurrentProcess 00000000:00000002: name "ProcessManagerCapture" type 'APPL' signature '????' mode 00000080 length 60kCurrentProcess 00000000:00000002: location set size nonzero free nonzero launcher 00000000:01F20001 launchDate nonzero activeTime zerokCurrentProcess 00000000:00000002: spec vRefNum set parID set name "ProcessManagerCapture"kSystemProcess 00000000:00000001: GetProcessInformation -> -600kNoProcess 00000000:00000000: GetProcessInformation -> -600bogus 00001234:00005678: GetProcessInformation -> -600SameProcess self self 00000000:02270001 00000000:02270001 -> 0 result 1SameProcess self kCurrentProcess 00000000:02270001 00000000:00000002 -> 0 result 1SameProcess kCurrentProcess kCurrentProcess 00000000:00000002 00000000:00000002 -> 0 result 1SameProcess self kSystemProcess 00000000:02270001 00000000:00000001 -> 0 result 0SameProcess self kNoProcess 00000000:02270001 00000000:00000000 -> 0 result 0SameProcess self bogus 00000000:02270001 00001234:00005678 -> 0 result 0SameProcess bogus bogus 00001234:00005678 00001234:00005678 -> 0 result 1GetNextProcess bogus -> -600 00000000:00000000GetNextProcess kCurrentProcess -> -600 00000000:00000000GetProcessInformation without name or spec -> 0 length 60GetProcessInformation with length 4 -> -50 name 0SetFrontProcess self -> 0SetFrontProcess bogus -> -600GetFrontProcess after -> 0 00000000:01F20001SameProcess self front after 00000000:02270001 00000000:01F20001 -> 0 result 0done
Expand Down
211 changes: 211 additions & 0 deletions ReferenceTests/Retro68/ProcessManagerCapture.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
/*
* Captures the Process Manager's answers about the running processes,
* writing "ProcessManager.txt" next to itself. It refuses to run if that
* file is already there. Each line is a call and what it returned; the file
* is flushed after every line.
*
* It records the program's own process serial number and information, the
* list GetNextProcess walks, the front process, SameProcess on the special
* serial numbers, and the errors for numbers that name no process. Values
* that differ from run to run (the launch date, active time, sizes and
* free memory) are recorded as whether they are zero, not as numbers.
*/
#include <Processes.h>
#include <Files.h>
#include <MacMemory.h>
#include <stdio.h>
#include <string.h>

/* Retro68's headers leave GetFrontProcess out; InterfaceLib has it. */
extern OSErr GetFrontProcess(ProcessSerialNumber *PSN);

static short out;

static void line(const char *text)
{
long count = strlen(text);
FSWrite(out, &count, text);
count = 1;
FSWrite(out, &count, "\r");
FlushVol(0, 0);
}

static void psnText(char *text, const ProcessSerialNumber *psn)
{
sprintf(text, "%08lX:%08lX", (unsigned long)psn->highLongOfPSN, (unsigned long)psn->lowLongOfPSN);
}

static void code(unsigned long value, char *text)
{
text[0] = '\'';
text[1] = (char)(value >> 24);
text[2] = (char)(value >> 16);
text[3] = (char)(value >> 8);
text[4] = (char)value;
text[5] = '\'';
text[6] = 0;
}

static void information(const char *label, ProcessSerialNumber psn)
{
char text[400], number[32], type[8], signature[8], launcher[32];
Str255 name;
FSSpec spec;
ProcessInfoRec info;
OSErr error;
memset(&info, 0, sizeof info);
memset(&spec, 0, sizeof spec);
name[0] = 0;
info.processInfoLength = sizeof info;
info.processName = name;
info.processAppSpec = &spec;
error = GetProcessInformation(&psn, &info);
psnText(number, &psn);
if (error) {
sprintf(text, "%s %s: GetProcessInformation -> %d", label, number, error);
line(text);
return;
}
code(info.processType, type);
code(info.processSignature, signature);
psnText(launcher, &info.processLauncher);
sprintf(text, "%s %s: name \"%.*s\" type %s signature %s mode %08lX length %lu",
label, number, name[0], (char *)name + 1, type, signature,
(unsigned long)info.processMode, (unsigned long)info.processInfoLength);
line(text);
sprintf(text, "%s %s: location %s size %s free %s launcher %s launchDate %s activeTime %s",
label, number, info.processLocation ? "set" : "nil", info.processSize ? "nonzero" : "zero",
info.processFreeMem ? "nonzero" : "zero", launcher,
info.processLaunchDate ? "nonzero" : "zero", info.processActiveTime ? "nonzero" : "zero");
line(text);
sprintf(text, "%s %s: spec vRefNum %s parID %s name \"%.*s\"", label, number,
spec.vRefNum ? "set" : "zero", spec.parID ? "set" : "zero", spec.name[0], (char *)spec.name + 1);
line(text);
}

static void same(const char *label, ProcessSerialNumber a, ProcessSerialNumber b)
{
char text[160], first[32], second[32];
Boolean result = 99;
OSErr error = SameProcess(&a, &b, &result);
psnText(first, &a);
psnText(second, &b);
sprintf(text, "SameProcess %s %s %s -> %d result %d", label, first, second, error, (int)result);
line(text);
}

int main(void)
{
ProcessSerialNumber self, psn, front, none, current, system, bogus;
char text[200], number[32];
OSErr error;
int count = 0;
short volume;
Str255 name;
FSSpec spec;
ProcessInfoRec info;

/* Created beside the program; refuse to overwrite an earlier capture. */
error = FSOpen("\pProcessManager.txt", 0, &volume);
if (error == noErr) {
FSClose(volume);
return 1;
}
error = Create("\pProcessManager.txt", 0, 'ttxt', 'TEXT');
if (error != noErr) return 1;
if (FSOpen("\pProcessManager.txt", 0, &out) != noErr) return 1;

none.highLongOfPSN = 0;
none.lowLongOfPSN = kNoProcess;
system.highLongOfPSN = 0;
system.lowLongOfPSN = kSystemProcess;
current.highLongOfPSN = 0;
current.lowLongOfPSN = kCurrentProcess;
bogus.highLongOfPSN = 0x1234;
bogus.lowLongOfPSN = 0x5678;

error = GetCurrentProcess(&self);
psnText(number, &self);
sprintf(text, "GetCurrentProcess -> %d %s", error, number);
line(text);
information("self", self);

error = GetFrontProcess(&front);
psnText(number, &front);
sprintf(text, "GetFrontProcess -> %d %s", error, number);
line(text);
same("self front", self, front);

/* The list, in the order GetNextProcess gives it. */
psn = none;
for (;;) {
ProcessSerialNumber next;
error = GetNextProcess(&psn);
psnText(number, &psn);
sprintf(text, "GetNextProcess[%d] -> %d %s", count, error, number);
line(text);
if (error) break;
next = psn;
information("listed", next);
if (++count > 64) break;
}

/* Special serial numbers. */
information("kCurrentProcess", current);
information("kSystemProcess", system);
information("kNoProcess", none);
information("bogus", bogus);
same("self self", self, self);
same("self kCurrentProcess", self, current);
same("kCurrentProcess kCurrentProcess", current, current);
same("self kSystemProcess", self, system);
same("self kNoProcess", self, none);
same("self bogus", self, bogus);
same("bogus bogus", bogus, bogus);

psn = bogus;
error = GetNextProcess(&psn);
psnText(number, &psn);
sprintf(text, "GetNextProcess bogus -> %d %s", error, number);
line(text);

psn = current;
error = GetNextProcess(&psn);
psnText(number, &psn);
sprintf(text, "GetNextProcess kCurrentProcess -> %d %s", error, number);
line(text);

/* A record too short, and one that asks for no name or spec. */
memset(&info, 0, sizeof info);
info.processInfoLength = sizeof info;
error = GetProcessInformation(&self, &info);
sprintf(text, "GetProcessInformation without name or spec -> %d length %lu", error,
(unsigned long)info.processInfoLength);
line(text);
memset(&info, 0, sizeof info);
memset(&spec, 0, sizeof spec);
name[0] = 0;
info.processInfoLength = 4;
info.processName = name;
info.processAppSpec = &spec;
error = GetProcessInformation(&self, &info);
sprintf(text, "GetProcessInformation with length 4 -> %d name %d", error, name[0]);
line(text);

error = SetFrontProcess(&self);
sprintf(text, "SetFrontProcess self -> %d", error);
line(text);
error = SetFrontProcess(&bogus);
sprintf(text, "SetFrontProcess bogus -> %d", error);
line(text);
error = GetFrontProcess(&front);
psnText(number, &front);
sprintf(text, "GetFrontProcess after -> %d %s", error, number);
line(text);
same("self front after", self, front);

line("done");
FSClose(out);
FlushVol(0, 0);
return 0;
}
33 changes: 33 additions & 0 deletions ReferenceTests/Retro68/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,36 @@ UTM setup above.

`RegionRecordingTests` checks `Port.beginRegion` and `endRegion` against the
capture.

## Process Manager

`ProcessManagerCapture.c` records what the Process Manager says about the
processes running: its own serial number and `GetProcessInformation` record,
the list `GetNextProcess` walks, the front process, `SameProcess` on the
special serial numbers and the errors for numbers that name no process. Values
that differ from run to run (launch date, active time, sizes) are recorded as
zero or not. It ran from the Finder, on Mac OS 9.2.2 in UTM with File Sharing
on. Its output is `ProcessManager-macos-9.2.2-ppc.txt` (CR line endings).

- A serial number is a high long of 0 and a low long of the process's number
in its high half and a generation (1, or 2 for the File Sharing extension)
in its low half. `kNoProcess` is 0, `kSystemProcess` 1, `kCurrentProcess` 2.
- `GetNextProcess(kNoProcess)` gave the first process; the list was in launch
order, background-only programs first, the Finder (`FNDR`/`MACS`, no
launcher) after them, then what the Finder opened with the Finder as its
launcher. After the last one it gave procNotFound (-600) and set the serial
number to `kNoProcess`.
- `GetProcessInformation` took `kCurrentProcess` as the caller. `kSystemProcess`,
`kNoProcess` and a number nothing runs under were procNotFound. A record
whose `processInfoLength` was 4 was paramErr; 60 is `sizeof(ProcessInfoRec)`.
Name and `processAppSpec` were filled only when the caller gave pointers.
- `GetNextProcess(kCurrentProcess)` and `GetNextProcess` of a number nothing
runs under were procNotFound.
- `SameProcess` never failed: `kCurrentProcess` equals the caller's own number,
and two equal numbers are the same even when no process has them.
- `SetFrontProcess` of the caller gave noErr but the Finder was still in front
just after: a process comes forward when it next calls the Event Manager.
An unknown number was procNotFound.

`ProcessManagerTests` rebuilds the probe's output from `ProcessManager` and
compares it with the capture line by line.
Loading
Loading