• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 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 <unistd.h>
18 
19 #include <iostream>
20 
21 #include "TcpServerForRunner.h"
22 
23 #define DEFAULT_HAL_DRIVER_FILE_PATH32 "./vts_hal_driver32"
24 #define DEFAULT_HAL_DRIVER_FILE_PATH64 "./vts_hal_driver64"
25 #define DEFAULT_SHELL_DRIVER_FILE_PATH32 "./vts_shell_driver32"
26 #define DEFAULT_SHELL_DRIVER_FILE_PATH64 "./vts_shell_driver64"
27 
28 using namespace std;
29 
main(int argc,char * argv[])30 int main(int argc, char* argv[]) {
31   char* spec_dir_path = NULL;
32   char* hal_path32;
33   char* hal_path64;
34   char* shell_path32;
35   char* shell_path64;
36 
37   printf("|| VTS AGENT ||\n");
38 
39   if (argc == 1) {
40     hal_path32 = (char*) DEFAULT_HAL_DRIVER_FILE_PATH32;
41     hal_path64 = (char*) DEFAULT_HAL_DRIVER_FILE_PATH64;
42     shell_path32 = (char*) DEFAULT_SHELL_DRIVER_FILE_PATH32;
43     shell_path64 = (char*) DEFAULT_SHELL_DRIVER_FILE_PATH64;
44   } else if (argc == 2) {
45     hal_path32 = (char*) DEFAULT_HAL_DRIVER_FILE_PATH32;
46     hal_path64 = (char*) DEFAULT_HAL_DRIVER_FILE_PATH64;
47     spec_dir_path = argv[1];
48     shell_path32 = (char*) DEFAULT_SHELL_DRIVER_FILE_PATH32;
49     shell_path64 = (char*) DEFAULT_SHELL_DRIVER_FILE_PATH64;
50   } else if (argc == 3) {
51     hal_path32 = argv[1];
52     hal_path64 = argv[2];
53   } else if (argc == 4) {
54     hal_path32 = argv[1];
55     hal_path64 = argv[2];
56     spec_dir_path = argv[3];
57   } else if (argc == 6) {
58     hal_path32 = argv[1];
59     hal_path64 = argv[2];
60     spec_dir_path = argv[3];
61     shell_path32 = argv[4];
62     shell_path64 = argv[5];
63   } else {
64     std::cerr << "usage: vts_hal_agent "
65               << "[[<hal 32-bit binary path> [<hal 64-bit binary path>] "
66               << "[<spec file base dir path>]]"
67               << "[[<shell 32-bit binary path> [<shell 64-bit binary path>] "
68               << std::endl;
69     return -1;
70   }
71 
72   char* dir_path;
73   dir_path = (char*)malloc(strlen(argv[0]) + 1);
74   strcpy(dir_path, argv[0]);
75   for (int index = strlen(argv[0]) - 2; index >= 0; index--) {
76     if (dir_path[index] == '/') {
77       dir_path[index] = '\0';
78       break;
79     }
80   }
81   printf("chdir %s\n", dir_path);
82   chdir(dir_path);
83 
84   android::vts::StartTcpServerForRunner(
85       (const char*)spec_dir_path, (const char*)hal_path32,
86       (const char*)hal_path64, (const char*)shell_path32,
87       (const char*)shell_path64);
88   return 0;
89 }
90