-- CacheTestAccessControlImpl.mesa Last edit: KK September 22, 1982 10:51 am DIRECTORY AccessControl USING[ReportCacheStats], AccessControlCache USING[ClearAccessControlCache, SetAccessControlCacheInitialized, VerifyClient], AlpineEnvironment USING[AccessList, Principal], FileIO USING[Open], Inline USING[DIVMOD], IO USING[Close, Handle, PutRope], PerfStats USING[CreateTimer, DestroyTimer, Initialize, InitializeTimer, Print, Start, Stop, Timer], RandomCard USING[Init, Choose], Rope USING[Cat, ROPE], SafeStorage USING[IsCollectorActive, WaitForCollectorDone]; CacheTestAccessControlImpl: PROGRAM IMPORTS AC: AccessControl, ACC: AccessControlCache, AE: AlpineEnvironment, FileIO, Inline, IO, PerfStats, RandomCard, Rope, SafeStorage = BEGIN number: CARDINAL ← 0; charList: ARRAY [0..10) OF Rope.ROPE = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; MakeUniqueName: PROCEDURE RETURNS[name: AE.Principal] = BEGIN q, r, n: CARDINAL; name ← "AlpineFakeName"; n ← number; number ← number + 1; DO [q, r] ← Inline.DIVMOD[n, 10]; name ← Rope.Cat[name, charList[r]]; -- backwards, but so what. IF q = 0 THEN RETURN; n ← q; ENDLOOP; END; nValidNames: CARDINAL = 10; validNames: ARRAY[0..nValidNames) OF Rope.ROPE = ["Atkinson.pa", "Cattell.pa", "Crowther.pa", "Taylor.pa", "Lampson.pa", "Horning.pa", "Donahue.pa", "Morris.pa", "Sturgis.pa", "Guibas.pa"]; -- ten members in CSLOnly↑.pa and in Bldg35↑.pa. GetValidClient: PROCEDURE RETURNS[name: AE.Principal] = BEGIN name ← validNames[RandomCard.Choose[0, nValidNames - 1]]; END; GetValidAccessList: PROCEDURE RETURNS[accessList: AE.AccessList] = BEGIN accessList ← NIL; IF RandomCard.Choose[0, 3] = 1 THEN accessList ← CONS[MakeUniqueName[], accessList]; accessList ← CONS[(IF RandomCard.Choose[0, 1] = 1 THEN "CSLOnly↑.pa" ELSE "Bldg35↑.pa"), accessList]; accessList ← CONS[(IF RandomCard.Choose[0, 1] = 1 THEN "CSLOnly↑.pa" ELSE "Bldg35↑.pa"), accessList]; IF RandomCard.Choose[0, 1] = 1 THEN accessList ← CONS[MakeUniqueName[], accessList]; END; RunTestLaterRegServersDown: ERROR = CODE; ResetStatsAndGetDelta: PROCEDURE = BEGIN nCacheEntries: CARDINAL; currentStatsRegServersDown: LONG CARDINAL; [nCacheEntries, currentStats[cacheHit], currentStats[grapeAuthorized], currentStats[grapeNotAuthorized], currentStatsRegServersDown, currentStats[grapeIndivNotAuthorized]] ← AC.ReportCacheStats[]; IF currentStatsRegServersDown # 0 THEN ERROR RunTestLaterRegServersDown; IF nCacheEntries # nAccessCacheEntries THEN ERROR; FOR statsType: StatsType IN StatsType DO IF currentStats[statsType] < prevStats[statsType] THEN ERROR; deltaStats[statsType] ← currentStats[statsType] - prevStats[statsType]; prevStats[statsType] ← currentStats[statsType]; ENDLOOP; END; CheckInc: PROCEDURE [expectedStats: ARRAY StatsType OF LONG CARDINAL] = BEGIN ResetStatsAndGetDelta[]; FOR statsType: StatsType IN StatsType DO IF deltaStats[statsType] # expectedStats[statsType] THEN ERROR; ENDLOOP; END; StatsType: TYPE = {cacheHit, grapeAuthorized, grapeNotAuthorized, grapeIndivNotAuthorized}; prevStats: ARRAY StatsType OF LONG CARDINAL ← ALL[0]; currentStats: ARRAY StatsType OF LONG CARDINAL ← ALL[0]; deltaStats: ARRAY StatsType OF LONG CARDINAL ← ALL[0]; Main: PROCEDURE = BEGIN -- set up to call from CoPilot for debugging. foo: CARDINAL ← 0; accessList: AE.AccessList ← NIL; timer: PerfStats.Timer; activeCollect: BOOLEAN; prevCollectIncarn, endingPrevCollectIncarn: CARDINAL; [] ← RandomCard.Init[]; BEGIN ENABLE ANY => foo ← foo + 1; -- protect us from the tempcedarexec. SetUp: PROCEDURE = BEGIN ACC.ClearAccessControlCache[]; ResetStatsAndGetDelta[]; PerfStats.InitializeTimer[timer]; [activeCollect, prevCollectIncarn] ← SafeStorage.IsCollectorActive[]; IF activeCollect THEN [prevCollectIncarn, , , ] ← SafeStorage.WaitForCollectorDone[]; PerfStats.Start[timer]; END; FinishUp: PROCEDURE RETURNS[done: BOOLEAN] = BEGIN PerfStats.Stop[timer]; [activeCollect, endingPrevCollectIncarn] ← SafeStorage.IsCollectorActive[]; IF ((activeCollect) OR (endingPrevCollectIncarn # prevCollectIncarn)) THEN RETURN[FALSE]; PerfStats.Print[ , resultsStreamHandle, FALSE]; RETURN[TRUE]; END; PerfStats.Initialize[]; timer ← PerfStats.CreateTimer["timer"]; resultsStreamHandle ← FileIO.Open["CacheTestAccessControl.Results", append, none]; ACC.SetAccessControlCacheInitialized[nAccessCacheEntries]; ResetStatsAndGetDelta[]; -- simple stuff. accessList ← NIL; accessList ← CONS["AlpineImplementors↑.pa", accessList]; accessList ← CONS["NoSuchAlpineList↑.pa", accessList]; accessList ← CONS["CSL↑.pa", accessList]; accessList ← CONS["ListWhatList↑.pa", accessList]; IF (NOT ACC.VerifyClient["Kolling.pa", accessList]) THEN ERROR; CheckInc[[0, 1, 0, 1]]; IF (NOT ACC.VerifyClient["Kolling.pa", accessList]) THEN ERROR; CheckInc[[1, 0, 0, 0]]; IF (NOT ACC.VerifyClient["Taft.pa", accessList]) THEN ERROR; CheckInc[[0, 1, 0, 1]]; IF (NOT ACC.VerifyClient["Kolling.pa", accessList]) THEN ERROR; CheckInc[[1, 0, 0, 0]]; IF (NOT ACC.VerifyClient["Taft.pa", accessList]) THEN ERROR; CheckInc[[1, 0, 0, 0]]; ACC.ClearAccessControlCache[]; -- time for 100 grape failures, one name list. resultsStreamHandle.PutRope[" 100 grape failures: "]; DO SetUp[]; THROUGH [0..100) DO accessList ← NIL; accessList ← CONS[MakeUniqueName[], accessList]; IF ACC.VerifyClient["Kolling.pa", accessList] THEN ERROR; ENDLOOP; IF FinishUp[] THEN BEGIN CheckInc[[0, 0, 100, 100]]; EXIT; END; ENDLOOP; -- time for 1 grape success and 99 cache hits, one name list. DO resultsStreamHandle.PutRope[" 1 grape success and 99 cache hits: "]; SetUp[]; accessList ← NIL; accessList ← CONS["AlpineImplementors↑.pa", accessList]; THROUGH [0..100) DO IF NOT ACC.VerifyClient["Kolling.pa", accessList] THEN ERROR; ENDLOOP; IF FinishUp[] THEN BEGIN CheckInc[[99, 1, 0, 0]]; EXIT; END; ENDLOOP; -- time for 100 grape failures, four name list. resultsStreamHandle.PutRope[" 100 grape failures: "]; DO SetUp[]; THROUGH [0..25) DO accessList ← NIL; accessList ← CONS[MakeUniqueName[], accessList]; accessList ← CONS[MakeUniqueName[], accessList]; accessList ← CONS[MakeUniqueName[], accessList]; accessList ← CONS[MakeUniqueName[], accessList]; IF ACC.VerifyClient["Kolling.pa", accessList] THEN ERROR; ENDLOOP; IF FinishUp[] THEN BEGIN CheckInc[[0, 0, 25, 100]]; EXIT; END; ENDLOOP; -- time for 100 grape failures, same four name list. resultsStreamHandle.PutRope[" 100 grape failures: "]; DO SetUp[]; accessList ← NIL; accessList ← CONS[MakeUniqueName[], accessList]; accessList ← CONS[MakeUniqueName[], accessList]; accessList ← CONS[MakeUniqueName[], accessList]; accessList ← CONS[MakeUniqueName[], accessList]; THROUGH [0..25) DO IF ACC.VerifyClient["Kolling.pa", accessList] THEN ERROR; ENDLOOP; IF FinishUp[] THEN BEGIN CheckInc[[0, 0, 25, 100]]; EXIT; END; ENDLOOP; -- time for 2 grape fails, 1 grape success and 24 cache hits, four name list. resultsStreamHandle.PutRope[" 2 grape fails, 1 grape success and 24 cache hits: "]; DO SetUp[]; accessList ← NIL; accessList ← CONS[MakeUniqueName[], accessList]; accessList ← CONS["AlpineImplementors↑.pa", accessList]; accessList ← CONS[MakeUniqueName[], accessList]; accessList ← CONS[MakeUniqueName[], accessList]; THROUGH [0..25) DO IF NOT ACC.VerifyClient["Kolling.pa", accessList] THEN ERROR; ENDLOOP; IF FinishUp[] THEN BEGIN CheckInc[[24, 1, 0, 2]]; EXIT; END; ENDLOOP; -- time for 200 grape fails. resultsStreamHandle.PutRope[" 200 grape fails: "]; DO SetUp[]; accessList ← NIL; accessList ← CONS[MakeUniqueName[], accessList]; accessList ← CONS[MakeUniqueName[], accessList]; FOR index: CARDINAL IN [0..100) DO IF ACC.VerifyClient[MakeUniqueName[], accessList] THEN ERROR; ENDLOOP; IF FinishUp[] THEN BEGIN CheckInc[[0, 0, 100, 200]]; EXIT; END; ENDLOOP; -- mixture of stuff. ACC.ClearAccessControlCache[]; ResetStatsAndGetDelta[]; FOR index: CARDINAL IN [0..100) DO IF RandomCard.Choose[0,1] = 0 THEN BEGIN IF NOT ACC.VerifyClient[GetValidClient[], GetValidAccessList[]] THEN ERROR; ResetStatsAndGetDelta[]; IF (deltaStats[cacheHit] + deltaStats[grapeAuthorized]) # 1 THEN ERROR; END ELSE BEGIN accessList ← NIL; accessList ← CONS[MakeUniqueName[], accessList]; accessList ← CONS[MakeUniqueName[], accessList]; IF ACC.VerifyClient[MakeUniqueName[], accessList] THEN ERROR; ResetStatsAndGetDelta[]; IF deltaStats[grapeNotAuthorized] # 1 THEN ERROR; END; ENDLOOP; PerfStats.DestroyTimer[timer]; resultsStreamHandle.Close[]; END; END; -- main line code: resultsStreamHandle: IO.Handle; nAccessCacheEntries: LONG CARDINAL = 100; END. Edit Log Initial: Kolling: September 17, 1982 11:47 am: test for AccessControlCache.