MODULE TestLocks;
IMPORT SYSTEM, Machine, KernelLog;
PROCEDURE ShowState(msg: ARRAY OF CHAR);
VAR id: LONGINT; ints: BOOLEAN;
BEGIN
ints := Machine.InterruptsEnabled();
KernelLog.String(msg); KernelLog.String(": ");
id := Machine.ID();
KernelLog.String("Processor "); KernelLog.Int(id, 1);
KernelLog.String(", interrupts are ");
IF ints THEN KernelLog.String("on") ELSE KernelLog.String("off") END;
KernelLog.Ln
END ShowState;
PROCEDURE Single*;
BEGIN
Machine.Acquire(Machine.KernelLog);
ShowState("Single");
Machine.Release(Machine.KernelLog);
END Single;
PROCEDURE SingleInt*;
BEGIN
Machine.Acquire(Machine.KernelLog);
Machine.Sti();
ShowState("SingleInt1");
ShowState("SingleInt2");
Machine.Release(Machine.KernelLog);
END SingleInt;
PROCEDURE Long*;
VAR i: LONGINT;
BEGIN
Machine.Acquire(Machine.KernelLog);
FOR i := 0 TO 100000000 DO END;
ShowState("Long");
Machine.Release(Machine.KernelLog);
END Long;
PROCEDURE LongInt*;
VAR i: LONGINT;
BEGIN
Machine.Acquire(Machine.KernelLog);
Machine.Sti;
FOR i := 0 TO 100000000 DO END;
Machine.Cli;
ShowState("LongInt");
Machine.Release(Machine.KernelLog);
END LongInt;
PROCEDURE All*;
BEGIN
Machine.AcquireAll;
Machine.ReleaseAll
END All;
PROCEDURE Recursive*;
BEGIN
Machine.Acquire(Machine.KernelLog);
Machine.Acquire(Machine.KernelLog);
ShowState("Recursive");
Machine.Release(Machine.KernelLog);
Machine.Release(Machine.KernelLog);
END Recursive;
PROCEDURE OutOfOrder*;
BEGIN
Machine.Acquire(Machine.TraceOutput);
Machine.Acquire(Machine.KernelLog);
ShowState("OutOfOrder");
Machine.Release(Machine.KernelLog);
Machine.Release(Machine.TraceOutput)
END OutOfOrder;
(*
(** Acquire special lock. *)
PROCEDURE Special*;
BEGIN
Machine.Cli();
ShowState("Special1");
Machine.AcquireSpecial(Machine.KernelLog);
ShowState("Special2");
Machine.Release(Machine.KernelLog);
ShowState("Special3");
Machine.Sti
END Special;
*)
END TestLocks.
System.OpenKernelLog
TestLocks.Single
TestLocks.SingleInt (should trap if StrongChecks are on)
TestLocks.Long (runs for a few seconds)
TestLocks.LongInt
TestLocks.All
TestLocks.Recursive (should trap or hang)
TestLocks.OutOfOrder (should trap or hang)
TestLocks.Special