FSTFuzzTestsPrincipal.mm 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2018 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/NSObject.h>
  17. #include "LibFuzzer/FuzzerDefs.h"
  18. namespace {
  19. // Contains the code to be fuzzed. Called by the fuzzing library with
  20. // different argument values for `data` and `size`.
  21. int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  22. // Code to be fuzz-tested here.
  23. return 0;
  24. }
  25. // Simulates calling the main() function of libFuzzer (FuzzerMain.cpp).
  26. int RunFuzzTestingMain() {
  27. // Arguments to libFuzzer main() function should be added to this array,
  28. // e.g., dictionaries, corpus, number of runs, jobs, etc.
  29. char *program_args[] = {
  30. const_cast<char *>("RunFuzzTestingMain") // First argument is program name.
  31. };
  32. char **argv = program_args;
  33. int argc = sizeof(program_args) / sizeof(program_args[0]);
  34. // Start fuzzing using libFuzzer's driver.
  35. return fuzzer::FuzzerDriver(&argc, &argv, LLVMFuzzerTestOneInput);
  36. }
  37. } // namespace
  38. /**
  39. * This class is registered as the NSPrincipalClass in the
  40. * Firestore_FuzzTests_iOS bundle's Info.plist. XCTest instantiates this class
  41. * to perform one-time setup for the test bundle, as documented here:
  42. *
  43. * https://developer.apple.com/documentation/xctest/xctestobservationcenter
  44. */
  45. @interface FSTFuzzTestsPrincipal : NSObject
  46. @end
  47. @implementation FSTFuzzTestsPrincipal
  48. - (instancetype)init {
  49. self = [super init];
  50. RunFuzzTestingMain();
  51. return self;
  52. }
  53. @end