Home | History | Annotate | Download | only in utils
      1 /*
      2  * Copyright 2017 The Android Open Source Project
      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 
     17 #include "FuncFuzzerUtils.h"
     18 #include <getopt.h>
     19 
     20 namespace android {
     21 namespace vts {
     22 
     23 static void usage() {
     24   fprintf(
     25       stdout,
     26       "Usage:\n"
     27       "\n"
     28       "./<fuzzer> <vts flags> -- <libfuzzer flags>\n"
     29       "\n"
     30       "VTS flags (strictly in form --flag=value):\n"
     31       "\n"
     32       " vts_target_func \tName of function to be fuzzed.\n"
     33       "\n"
     34       "libfuzzer flags (strictly in form -flag=value):\n"
     35       " Use -help=1 to see libfuzzer flags\n"
     36       "Example:\n"
     37       "./<fuzzer_name> --vts_target_func=\"foo\" -- -max_len=128 -runs=100\n"
     38       "\n");
     39 }
     40 
     41 static struct option long_options[] = {
     42     {"help", no_argument, 0, 'h'},
     43     {"vts_target_function", required_argument, 0, 't'}
     44 };
     45 
     46 
     47 FuncFuzzerParams ExtractFuncFuzzerParams(int argc, char **argv) {
     48   FuncFuzzerParams params;
     49   int opt = 0;
     50   int index = 0;
     51   while ((opt = getopt_long_only(argc, argv, "", long_options, &index)) != -1) {
     52     switch (opt) {
     53       case 'h':
     54         usage();
     55         exit(0);
     56       case 't':
     57         params.target_func_ = optarg;
     58         break;
     59       default:
     60         // Ignore. This option will be handled by libfuzzer.
     61         break;
     62     }
     63   }
     64   return params;
     65 }
     66 
     67 }  // namespace vts
     68 }  // namespace android
     69 
     70