main.swift 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // main.swift
  3. //
  4. // This file has two purposes, one it provides the entry point for the
  5. // fuzzer, and second, it runs through a battery of tests from the fuzzer
  6. // they are run separately.
  7. //
  8. // Sadly, there does not seem a way of making this file serve two purposes
  9. // at once without editing it every time. If compiled for fuzzing, no
  10. // calls from the toplevel are allowed, but to exercise, you want that call.
  11. //
  12. // Created by Miguel de Icaza on 4/24/20.
  13. //
  14. import Foundation
  15. import SwiftTerm
  16. var queue = DispatchQueue(label: "Runner", qos: .userInteractive, attributes: .concurrent, autoreleaseFrequency: .inherit, target: nil)
  17. // Fuzzer entry point
  18. @_cdecl("LLVMFuzzerTestOneInput") public func fuzzMe(data: UnsafePointer<UInt8>, length: CInt) -> CInt{
  19. let h = HeadlessTerminal (queue: queue) { exitCode in }
  20. let t = h.terminal!
  21. t.silentLog = true
  22. let buffer = UnsafeBufferPointer(start: data, count: Int (length))
  23. let arr = Array(buffer)
  24. t.feed (byteArray: arr)
  25. return 0
  26. }
  27. // For manually testing stuff and use the Xcode debugger
  28. func testInput (d: Data)
  29. {
  30. let h = HeadlessTerminal (queue: queue) { exitCode in }
  31. var data : [UInt8] = []
  32. data.append(contentsOf: d)
  33. let t = h.terminal!
  34. t.silentLog = true
  35. t.feed (byteArray: data)
  36. }
  37. func testCrashes ()
  38. {
  39. let crashes = [
  40. "crash-a58b5a38135bd7ffadad8b420ab8dcd0c3e4a1bd",
  41. "crash-840102113e655342bfc30d2749406756a6e812d3",
  42. "crash-654c8421b816426f584c3347a72cd2e869602ed5",
  43. "crash-c6f850474ed073bb5b2e032c13d66819e68acc88",
  44. "crash-a18a4cccc2a2b1c6f14ea804d15dd7f93682abf2",
  45. "crash-b274a2639cd901a107778760708bb759c52086f8",
  46. "crash-9ff2abe9af46be74ca774b8d684e1df0737aa0bf",
  47. "crash-fb6fa24871a603f7920dd24d467c449ac5b8d893",
  48. "crash-f8e22628b8a2bb06d06fa9c064fe3a7363c35bde",
  49. "crash-dc9cf799322b1223cb9a0e40283cb61812d50fbb",
  50. "crash-c5c6e20dacfbb1a72599f8e135321a343d0dc2c6",
  51. "crash-d38b59abae508cafa02c586d1706cf734977e6eb",
  52. "crash-96e8d67b4e139f9eaebb950c5d25b7d5bd456359",
  53. "crash-be2c5a1d40465efe36dd95771161829427dd6356",
  54. "crash-3154715068e3ec98c7b425cc0fe56c1dbd1e1f58",
  55. "crash-41df255a79feb00f8ded38dac7a51065a2758977",
  56. "crash-45157239bc429db89546e2f0fea38b26f608b8d9",
  57. "crash-2f5d273ae2f2bb95152905486bd9bfd8afa83c02",
  58. "crash-17381a13c18b7bda011f260e38952fb8fb7e4616",
  59. "crash-0a14a360e820c3801095d8bdbc130b3e18d55261",
  60. "slow-unit-16849a4439a9ada62a289f64d122b3f898410375",
  61. "slow-unit-be2210ab3bc792ab4932a65d0aecd1e3bbdb7db1",
  62. "slow-unit-cb67af81341f405834d562bcb49570e2d3a95348",
  63. "slow-unit-ff24adf923bfd5c9ccb4d58722c31c48d3f86480",
  64. "crash-166a328f85dd916e1602764a1792f95b7d749a0e",
  65. "crash-2b6b8631ea3cc418a069994de53e207da2d81230",
  66. "crash-509b3b6f6b74c483c515eecb5114f2f21f7ca576",
  67. "crash-698522a0a18e4fa7dcd0ee6b232d24cacecec07d",
  68. "crash-6f6c2b5c064f8ef4510305a3e04b2ef2c646b731",
  69. "crash-8876cfdf6927d0729ceccb6ae1c03da57c402eca",
  70. "crash-b60503f1c280209282018547ac732afd6d735dd9",
  71. "crash-ce788aaf77fa3219df3dea89f4a6771662402ebe",
  72. "crash-cf873cabbbf89413ae6f40ffc3f87e452cb9ed9b",
  73. "crash-e68d1073bb2f9140f95b4d9ad8dd076e5827f6c8",
  74. "crash-e6a7981c673480824152b1f8c948fac0d4a294f4",
  75. "crash-039a0b21c56b1e3a7a51056dd4f8daa9130c7312",
  76. "crash-36eb1fbfdb3a61e7b17b166d190ffd85ad9c80ab",
  77. "crash-4ba9dc95bc1c5d691fd9e80a4de72d65184e5c56",
  78. "crash-59fb9d3b7ab81c1782d26dfc69a962fae49ec449",
  79. "crash-64300317b2f97db7bfacfd77ba4d879e9726fd68",
  80. "crash-b926cdde789b73ff9680ff9ab643f13fa36c0571",
  81. "crash-c1147059ce893629e13289b43ae2b2ad1edcf44f",
  82. "crash-de2a0b4222547592208f7f85e2cd5b2730194daa",
  83. "crash-e1f2f0f2ef07d6d728316fa1bc336e6d1d699b99",
  84. "crash-ec47d21af677ee8eb18f91e150cdfb5d41d931c1",
  85. ]
  86. for crash in crashes {
  87. let url = URL(fileURLWithPath: "/Users/miguel/cvs/SwiftTerm/\(crash)")
  88. let data: Data
  89. do {
  90. print ("Running test \(crash)")
  91. data = try Data(contentsOf: url)
  92. } catch {
  93. print ("Caught error loading \(crash)")
  94. continue
  95. }
  96. testInput (d: data)
  97. print ("passed crash \(crash)")
  98. }
  99. print ("Happy!")
  100. }
  101. //testCrashes()