sentry_test.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright (C) 2019 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package main
  7. import (
  8. "fmt"
  9. "os"
  10. "testing"
  11. )
  12. func TestParseReport(t *testing.T) {
  13. bs, err := os.ReadFile("_testdata/panic.log")
  14. if err != nil {
  15. t.Fatal(err)
  16. }
  17. pkt, err := parseCrashReport("1/2/345", bs)
  18. if err != nil {
  19. t.Fatal(err)
  20. }
  21. bs, err = pkt.JSON()
  22. if err != nil {
  23. t.Fatal(err)
  24. }
  25. fmt.Printf("%s\n", bs)
  26. }
  27. func TestCrashReportFingerprint(t *testing.T) {
  28. cases := []struct {
  29. message, exp string
  30. ldb bool
  31. }{
  32. {
  33. message: "panic: leveldb/table: corruption on data-block (pos=51308946): checksum mismatch, want=0xa89f9aa0 got=0xd27cc4c7 [file=004003.ldb]",
  34. exp: "panic: leveldb/table: corruption on data-block (pos=x): checksum mismatch, want=0xX got=0xX [file=x.ldb]",
  35. ldb: true,
  36. },
  37. {
  38. message: "panic: leveldb/table: corruption on table-footer (pos=248): bad magic number [file=001370.ldb]",
  39. exp: "panic: leveldb/table: corruption on table-footer (pos=x): bad magic number [file=x.ldb]",
  40. ldb: true,
  41. },
  42. {
  43. message: "panic: runtime error: slice bounds out of range [4294967283:4194304]",
  44. exp: "panic: runtime error: slice bounds out of range [x]",
  45. },
  46. {
  47. message: "panic: runtime error: slice bounds out of range [-2:]",
  48. exp: "panic: runtime error: slice bounds out of range [x]",
  49. },
  50. {
  51. message: "panic: runtime error: slice bounds out of range [:4294967283] with capacity 32768",
  52. exp: "panic: runtime error: slice bounds out of range [x] with capacity x",
  53. },
  54. {
  55. message: "panic: runtime error: index out of range [0] with length 0",
  56. exp: "panic: runtime error: index out of range [x] with length x",
  57. },
  58. {
  59. message: `panic: leveldb: internal key "\x01", len=1: invalid length`,
  60. exp: `panic: leveldb: internal key "x", len=x: invalid length`,
  61. ldb: true,
  62. },
  63. {
  64. message: `panic: write /var/syncthing/config/index-v0.14.0.db/2732813.log: cannot allocate memory`,
  65. exp: `panic: write x: cannot allocate memory`,
  66. ldb: true,
  67. },
  68. {
  69. message: `panic: filling Blocks: read C:\Users\Serv-Resp-Tizayuca\AppData\Local\Syncthing\index-v0.14.0.db\006561.ldb: Error de datos (comprobación de redundancia cíclica).`,
  70. exp: `panic: filling Blocks: read x: Error de datos (comprobación de redundancia cíclica).`,
  71. ldb: true,
  72. },
  73. }
  74. for i, tc := range cases {
  75. fingerprint := crashReportFingerprint(tc.message)
  76. expLen := 2
  77. if tc.ldb {
  78. expLen = 1
  79. }
  80. if l := len(fingerprint); l != expLen {
  81. t.Errorf("tc %v: Unexpected fingerprint length: %v != %v", i, l, expLen)
  82. } else if msg := fingerprint[expLen-1]; msg != tc.exp {
  83. t.Errorf("tc %v:\n\"%v\" !=\n\"%v\"", i, msg, tc.exp)
  84. }
  85. }
  86. }