public void TestCache(int matrixSize, int blockSize, int blockCount) { var cacheProcess = new MyCommandGenerator(_cts); Action <string> cacheSimMessageCallback = s => LogFilteredSimOutput(matrixSize, s); // TODO: Run the cache sim once for all the test... var generatorTask = cacheProcess.RunGenerator( Path.Combine(GeneratorTestsBase <object> .ToolsPath, GeneratorName), string.Format("{0} {1}", blockSize, blockCount), cacheSimMessageCallback, true, false); int swapCount = 0; Action <string> matrixOutputHandler = s => { swapCount++; cacheProcess.Process.WriteLineToStdIn(s); }; Matrix <int> m = new Matrix <int>(matrixOutputHandler, matrixSize, matrixSize); m.Transpose(); cacheProcess.Process.WriteLineToStdIn("\0"); // Terminate the program swapCount -= 2; // There were two more logs -- N and E Assert.AreEqual(swapCount, (matrixSize * matrixSize - matrixSize) / 2); generatorTask.Wait(20000, _cts.Token); // Wait for 20 sec }
public GeneratorTestsBase(string logFolderName, string logFileName, int consumerCount) { _logFolderName = logFolderName ?? @"Log"; _logFileName = logFileName; CancellationTokenSource = new CancellationTokenSource(); CancellationTokenSource.Token.Register(() => Log("Cancellation requested.")); Buffer = new AsyncBuffer <TWorkItem>(CancellationTokenSource.Token); Generator = new MyCommandGenerator(CancellationTokenSource); Consumers = Enumerable .Range(0, consumerCount) .Select(n => new MyCommandConsumer <TWorkItem>(Buffer, CancellationTokenSource)) .ToArray(); }