main.swift 1.0 KB

1234567891011121314151617181920212223242526272829303132
  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. }