Example #1
0
func TestSymbolizeStackwalk(t *testing.T) {
	files := []string{
		"stackwalk1.txt",
		"stackwalk2.txt",
	}

	for _, file := range files {
		filePath := testdata(file)
		expectedPath := filePath + ".expected"

		parser := NewStackwalkParser()
		inputData, err := testutils.ReadSourceFile(filePath)
		if err != nil {
			t.Errorf("%s: %v", filePath, err)
			continue
		}
		err = parser.ParseInput(string(inputData))
		if err != nil {
			t.Errorf("Error parsing input for %s: %v", file, err)
			continue
		}

		modules := parser.RequiredModules()
		tables := make([]breakpad.SymbolTable, len(modules))
		for i, module := range modules {
			name := module.ModuleName
			// Leave one module a mystery.
			if name == "libSystem.B.dylib" {
				name = "__not found__"
			}
			tables[i] = &testTable{
				name:   name,
				symbol: strings.Replace(module.ModuleName, " ", "_", -1),
			}
		}

		outputData, err := testutils.ReadSourceFile(expectedPath)
		if err != nil {
			t.Errorf("%s: %s", expectedPath, err)
		}

		actual := parser.Symbolize(tables)

		if err := testutils.CheckStringsEqual(string(outputData), actual); err != nil {
			t.Errorf("Input data for %s does not symbolize to expected output", file)
			t.Error(err)
		}
	}
}
Example #2
0
func TestSymbolizeApple(t *testing.T) {
	files := []string{
		"crash_10.6_v6.crash",
		"crash_10.7_v9.crash",
		"crash_10.8_v10.crash",
		"crash_10.8_v10_2.crash",
		"crash_10.9_v11.crash",
		"crash_iOS6_v104.crash",
		"crash_iOS7_v104.crash",
		"hang_10.7_v7.crash",
		"hang_10.8_v7.crash",
		"hang_10.9_v18.crash",
	}

	for _, input := range files {
		inputData, err := testutils.ReadSourceFile(testdata(input))
		if err != nil {
			t.Errorf("Failed to read file: %v", err)
			continue
		}

		tables := []breakpad.SymbolTable{
			&testTable{name: "Chrome", symbol: "ChromeiOS"},
			&testTable{name: "Google Chrome Framework", symbol: "Framework"},
			&testTable{name: "Google Chrome Canary", symbol: "Chrome"},
		}

		parser := NewAppleParser()
		err = parser.ParseInput(string(inputData))
		if err != nil {
			t.Errorf("%s: %s", input, err)
			continue
		}

		// Write the output to a .actual file, which can be used to create a new baseline
		// .expected file by copying it into the testdata/ directory.

		actual := parser.Symbolize(tables)
		actualFileName, actualFile, err := testutils.CreateTempFile(input + ".actual")
		if err != nil {
			t.Errorf("Could not create actual file output: %v", err)
			continue
		}
		fmt.Fprint(actualFile, actual)
		actualFile.Close()

		expectedFileName := testutils.GetSourceFilePath(testdata(input + ".expected"))
		err = testutils.CheckFilesEqual(expectedFileName, actualFileName)
		if err != nil {
			t.Errorf("Input data for %s does not symbolize to expected output", input)
			t.Error(err)
		}
	}
}
Example #3
0
func getTable(file string) (*breakpadFile, error) {
	data, err := testutils.ReadSourceFile(path.Join("breakpad/testdata", file))
	if err != nil {
		return nil, err
	}

	table, err := NewBreakpadSymbolTable(string(data))
	if err != nil {
		return nil, err
	}

	bf, _ := table.(*breakpadFile)
	return bf, nil
}
Example #4
0
// TestSymbolizeAndroid tests the symbolize function of androidParser.  This function
// is almost identical to the TestSymbolize function in input_apple_test.go.
func TestSymbolizeAndroid(t *testing.T) {
	files := []string{
		"android1.txt",
		"android2.txt",
	}

	for _, file := range files {
		var testmod testModuleInfoServiceAndroid

		inputData, err := testutils.ReadSourceFile(testdata(file))
		if err != nil {
			t.Errorf("Failed to read file : " + file)
			continue
		}

		tables := []breakpad.SymbolTable{
			&testTable{name: "libchromeview.so", symbol: "Framework"},
		}

		parser := NewAndroidParser(context.Background(), &testmod, "")
		err = parser.ParseInput(string(inputData))
		if err != nil {
			t.Errorf("%s: %s", file, err)
			continue
		}

		// Write the output to a .actual file, which can be used to create a new baseline
		// .expected file by copying it into the testdata/ directory.

		actual := parser.Symbolize(tables)
		actualFileName, actualFile, err := testutils.CreateTempFile(file + ".actual")
		if err != nil {
			t.Errorf("Could not create actual file output: %v", err)
			continue
		}
		fmt.Fprint(actualFile, actual)
		actualFile.Close()

		expectedFileName := testutils.GetSourceFilePath(testdata(file + ".expected"))
		err = testutils.CheckFilesEqual(expectedFileName, actualFileName)
		if err != nil {
			t.Errorf("Input data for %s does not symbolize to expected output", file)
			t.Error(err)
		}
	}
}
Example #5
0
func TestParseAppleInput(t *testing.T) {
	expected := []struct {
		filename      string
		reportVersion int
		images        []binaryImage
	}{
		{
			"crash_10.7_v9.crash",
			9,
			[]binaryImage{
				binaryImage{
					0x4c000,
					"com.google.Chrome.canary",
					"26A6C8D5-C994-73CA-195E-55656E111C97",
					"Google Chrome Canary",
				},
				binaryImage{
					0x51000,
					"com.google.Chrome.framework",
					"18D7EF91-5100-665A-BE61-EC3140EADD1A",
					"Google Chrome Framework",
				},
			},
		},
	}

	for _, e := range expected {
		data, err := testutils.ReadSourceFile(testdata(e.filename))
		if err != nil {
			t.Error(err)
			continue
		}

		parser := NewAppleParser().(*appleParser)
		err = parser.ParseInput(string(data))
		if err != nil {
			t.Error(err)
		}

		if parser.reportVersion != e.reportVersion {
			t.Errorf("Report version mismatch for %s, expected %d, got %d", e.filename, e.reportVersion, parser.reportVersion)
		}

		for _, image := range e.images {
			actual, ok := parser.modules[image.name]
			if !ok {
				t.Errorf("Could not find module %s", image.name)
				continue
			}

			if actual.baseAddress != image.baseAddress {
				t.Errorf("Base address for %s in %s wrong, expected 0x%x, got 0x%x", image.name, e.filename, image.baseAddress, actual.baseAddress)
			}
			if actual.ident != image.ident {
				t.Errorf("UUID for %s in %s is wrong, expected '%s', got '%s'", image.name, e.filename, image.ident, actual.ident)
			}
			lastComponent := path.Base(actual.path)
			if image.path != lastComponent {
				t.Errorf("Last path component for %s in %s is wrong, expected '%s', got '%s'", image.name, e.filename, image.path, lastComponent)
			}
		}
	}
}