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 /* 18 * Example usage: 19 * $ vts_hal_driver 20 * $ vts_hal_driver --spec_dir_path /data/local/tmp/spec/ 21 * --callback_socket_name /data/local/tmp/vts_agent_callback 22 * --server_socket_path /data/local/tmp/vts_tcp_server_port 23 */ 24 #include <getopt.h> 25 #include <iostream> 26 #include <string> 27 28 #include <android-base/logging.h> 29 30 #include "BinderServer.h" 31 #include "SocketServer.h" 32 #include "binder/VtsFuzzerBinderService.h" 33 #include "driver_manager/VtsHalDriverManager.h" 34 35 using namespace std; 36 37 static constexpr const char* kDefaultSpecDirPath = "/data/local/tmp/spec/"; 38 static constexpr const char* kInterfaceSpecLibName = 39 "libvts_interfacespecification.so"; 40 static const int kDefaultEpochCount = 100; 41 42 void ShowUsage() { 43 cout << "Usage: vts_hal_driver [options] <interface spec lib>\n" 44 "--spec_dir_path <path>: Set path that store the vts spec " 45 "files\n" 46 "--callback_socket_name <name>: Set the callback (agent) socket " 47 "name\n" 48 "--server_socket_path <path>: Set the driver server socket path\n" 49 "--service_name <name>: Set the binder service name\n" 50 "--help: Show help\n"; 51 exit(1); 52 } 53 54 int main(int argc, char** argv) { 55 android::base::InitLogging(argv, android::base::StderrLogger); 56 57 const char* const short_opts = "h:d:c:s:n"; 58 const option long_opts[] = { 59 {"help", no_argument, nullptr, 'h'}, 60 {"spec_dir_path", optional_argument, nullptr, 'd'}, 61 {"callback_socket_name", optional_argument, nullptr, 'c'}, 62 #ifndef VTS_AGENT_DRIVER_COMM_BINDER // socket 63 {"server_socket_path", optional_argument, NULL, 's'}, 64 #else // binder 65 {"service_name", required_argument, NULL, 'n'}, 66 #endif 67 {nullptr, 0, nullptr, 0}, 68 }; 69 70 string spec_dir_path = kDefaultSpecDirPath; 71 string callback_socket_name = ""; 72 string server_socket_path; 73 string service_name; 74 75 while (true) { 76 int opt = getopt_long(argc, argv, short_opts, long_opts, nullptr); 77 if (opt == -1) { 78 break; 79 } 80 81 switch (opt) { 82 case 'h': 83 case '?': 84 ShowUsage(); 85 return 0; 86 case 'd': { 87 spec_dir_path = string(optarg); 88 break; 89 } 90 case 'c': { 91 callback_socket_name = string(optarg); 92 break; 93 } 94 #ifndef VTS_AGENT_DRIVER_COMM_BINDER // socket 95 case 's': 96 server_socket_path = string(optarg); 97 break; 98 #else // binder 99 case 'n': 100 service_name = string(optarg); 101 break; 102 #endif 103 default: 104 cerr << "getopt_long returned unexpected value " << opt << endl; 105 return 2; 106 } 107 } 108 109 android::vts::VtsHalDriverManager driver_manager( 110 spec_dir_path, kDefaultEpochCount, callback_socket_name); 111 112 #ifndef VTS_AGENT_DRIVER_COMM_BINDER // socket 113 android::vts::StartSocketServer(server_socket_path, &driver_manager, 114 kInterfaceSpecLibName); 115 #else // binder 116 android::vts::StartBinderServer(service_name, &driver_manager, 117 kInterfaceSpecLibName); 118 #endif 119 120 return 0; 121 } 122