@@ -1182,6 +1182,66 @@ def testEvictedManifest(self):
11821182 self .assertEqual (subprocess .call (cmd , env = customEnv ), 0 )
11831183
11841184
1185+ class TestTracker (unittest .TestCase ):
1186+ def readTlog (self , tlogDir ):
1187+ content = ""
1188+ for fileName in glob .glob (os .path .join (tlogDir , '*read.1.tlog' )):
1189+ with open (fileName , 'rb' ) as f :
1190+ content += f .read ().decode ("utf-16" )
1191+ return content
1192+
1193+ def testStatsTxtOnUnsupportedArgumens (self ):
1194+ with tempfile .TemporaryDirectory () as tempDir , tempfile .TemporaryDirectory () as trackDir :
1195+ customEnv = dict (os .environ , CLCACHE_DIR = tempDir )
1196+ clcmd = CLCACHE_CMD + ["/nologo" , "/c" , "/Zi" , os .path .join (ASSETS_DIR , "fibonacci.c" )]
1197+ cmd = ['tracker' , '/i' , trackDir , '/c' ] + clcmd
1198+
1199+ #initialize stats.txt in cache
1200+ subprocess .check_call (clcmd , env = customEnv )
1201+
1202+ subprocess .check_call (cmd , env = customEnv )
1203+
1204+ self .assertTrue ("STATS.TXT" not in self .readTlog (trackDir ))
1205+
1206+ def testSourceOnCacheHit (self ):
1207+ with tempfile .TemporaryDirectory () as tempDir , tempfile .TemporaryDirectory () as trackDir :
1208+ customEnv = dict (os .environ , CLCACHE_DIR = tempDir )
1209+ clcmd = CLCACHE_CMD + ["/nologo" , "/c" , os .path .join (ASSETS_DIR , "fibonacci.c" )]
1210+ cmd = ['tracker' , '/i' , trackDir , '/c' ] + clcmd
1211+
1212+ #warm up cache
1213+ subprocess .check_call (clcmd , env = customEnv )
1214+
1215+ subprocess .check_call (cmd , env = customEnv )
1216+
1217+ self .assertTrue ("FIBONACCI.C" in self .readTlog (trackDir ))
1218+
1219+ def testManifest (self ):
1220+ with tempfile .TemporaryDirectory () as tempDir , tempfile .TemporaryDirectory () as trackDir :
1221+ customEnv = dict (os .environ , CLCACHE_DIR = tempDir )
1222+ clcmd = CLCACHE_CMD + ["/nologo" , "/c" , os .path .join (ASSETS_DIR , "fibonacci.c" )]
1223+ cmd = ['tracker' , '/i' , trackDir , '/c' ] + clcmd
1224+
1225+ #warm up cache
1226+ subprocess .check_call (clcmd , env = customEnv )
1227+
1228+ subprocess .check_call (cmd , env = customEnv )
1229+
1230+ self .assertTrue (os .path .join (tempDir , "manifests" ).upper () not in self .readTlog (trackDir ))
1231+
1232+ def testCacheLimit (self ):
1233+ with tempfile .TemporaryDirectory () as tempDir , tempfile .TemporaryDirectory () as trackDir :
1234+ customEnv = dict (os .environ , CLCACHE_DIR = tempDir )
1235+ clcmd = CLCACHE_CMD + ["/nologo" , "/c" , os .path .join (ASSETS_DIR , "fibonacci.c" )]
1236+ cmd = ['tracker' , '/i' , trackDir , '/c' ] + clcmd
1237+
1238+ #setup small cache limit
1239+ subprocess .check_call (CLCACHE_CMD + ['-M' , '100' ], env = customEnv )
1240+
1241+ subprocess .check_call (cmd , env = customEnv )
1242+
1243+ self .assertTrue ("STATS.TXT" not in self .readTlog (trackDir ))
1244+
11851245if __name__ == '__main__' :
11861246 unittest .TestCase .longMessage = True
11871247 unittest .main ()
0 commit comments