public static void ReadFile(TestInfo testInfo, FileInfo fileInfo, TestCase initialTestCase) { using (var fs = new FileStream(fileInfo.FullName, FileMode.Open)) { if (IsTextFile(fs)) { ReadTextFile(testInfo, fs, initialTestCase); } else { ReadBinaryFile(testInfo, fs, initialTestCase); } } }
public static void ReadTextFile( TestInfo testInfo, FileStream fs, TestCase initialTestCase) { // TODO: Should be null (but KLEE uses initialTestCase) var testCase = initialTestCase; using (var reader = new StreamReader(fs)) { string line; while (!string.IsNullOrEmpty((line = reader.ReadLine()))) { var items = line.Split(' '); var id = int.Parse(items[0]); var value = int.Parse(items[2]); switch ((ElementType)int.Parse(items[1])) { case ElementType.Statement: testCase.Statements.Add(id); testCase.StatementConditionDecisions.Add(id); testCase.Paths.Add(id); break; case ElementType.Decision: id = (value & 1) == 0 ? id : -id; testCase.Decisions.Add(id); testCase.ConditionDecisions.Add(id); testCase.StatementConditionDecisions.Add(id); break; case ElementType.Condition: id = (value & 1) == 0 ? id : -id; testCase.Conditions.Add(id); testCase.ConditionDecisions.Add(id); testCase.StatementConditionDecisions.Add(id); break; case ElementType.DecisionAndCondition: id = (value & 1) == 0 ? id : -id; testCase.Decisions.Add(id); testCase.Conditions.Add(id); testCase.ConditionDecisions.Add(id); testCase.StatementConditionDecisions.Add(id); break; case ElementType.TestCase: if (testInfo.TestCases.Count <= id) { throw new InvalidOperationException( "There is contradiction between the coverage data and the source code. Please retry to measure coverage data."); } testCase = testInfo.TestCases[id]; break; } } } }
public static void ReadBinaryFile( TestInfo testInfo, FileStream fs, TestCase initialTestCase) { // TODO: Should be null (but KLEE uses initialTestCase) var testCase = initialTestCase; while (true) { var id = (fs.ReadByte() << 24) + (fs.ReadByte() << 16) + (fs.ReadByte() << 8) + (fs.ReadByte() << 0); var value = fs.ReadByte(); if (value == -1) { return; } switch ((ElementType)(value >> 2)) { case ElementType.Statement: testCase.Statements.Add(id); testCase.StatementConditionDecisions.Add(id); testCase.Paths.Add(id); break; case ElementType.Decision: id = (value & 1) == 0 ? id : -id; testCase.Decisions.Add(id); testCase.ConditionDecisions.Add(id); testCase.StatementConditionDecisions.Add(id); break; case ElementType.Condition: id = (value & 1) == 0 ? id : -id; testCase.Conditions.Add(id); testCase.ConditionDecisions.Add(id); testCase.StatementConditionDecisions.Add(id); break; case ElementType.DecisionAndCondition: id = (value & 1) == 0 ? id : -id; testCase.Decisions.Add(id); testCase.Conditions.Add(id); testCase.ConditionDecisions.Add(id); testCase.StatementConditionDecisions.Add(id); break; case ElementType.TestCase: if (testInfo.TestCases.Count <= id) { throw new InvalidOperationException( "There is contradiction between the coverage data and the source code. Please retry to measure coverage data."); } testCase = testInfo.TestCases[id]; break; } } }
private static TestInfo AnalyzeKleeTestFiles(DirectoryInfo testDirInfo) { var files = testDirInfo.EnumerateFiles("*.ktest"); var testInfo = new TestInfo(testDirInfo.FullName); testInfo.InitializeForStoringData(false); foreach (var file in files) { var relativePath = ParaibaPath.GetRelativePath(file.FullName, testDirInfo.FullName); var testCase = new TestCase(relativePath, file.FullName, new CodeRange()); testInfo.TestCases.Add(testCase); testCase.InitializeForStoringData(false); var dataPath = file.FullName + OccfNames.Record; CoverageDataReader.ReadFile(testInfo, new FileInfo(dataPath), testCase); } return testInfo; }