1 /*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17 #include <stdio.h>
18
19 #include <utils/String8.h>
20
21 #include <UniquePtr.h>
22
23 #include "Log.h"
24 #include "Report.h"
25 #include "task/TaskGeneric.h"
26 #include "task/ModelBuilder.h"
27
28 // For flushing report and log before exiting
29 class CleanupStatics {
30 public:
31
CleanupStatics()32 CleanupStatics() {};
~CleanupStatics()33 ~CleanupStatics() {
34 Log::Finalize();
35 Report::Finalize();
36 }
37 };
38
main(int argc,char * argv[])39 int main(int argc, char *argv[])
40 {
41 if (argc < 2) {
42 fprintf(stderr, "%s [-llog_level] test_xml\n", argv[0]);
43 return 1;
44 }
45 int logLevel = 3;
46 int argCurrent = 1;
47 if (strncmp(argv[argCurrent], "-l", 2) == 0) {
48 logLevel = atoi(argv[argCurrent] + 2);
49 argCurrent++;
50 }
51 if (argCurrent == argc) {
52 fprintf(stderr, "wrong arguments");
53 return 1;
54 }
55 android::String8 xmlFile(argv[argCurrent]);
56
57 android::String8 dirName;
58 if (!FileUtil::prepare(dirName)) {
59 fprintf(stderr, "cannot prepare report dir");
60 return 1;
61 }
62
63 UniquePtr<CleanupStatics> staticStuffs(new CleanupStatics());
64 if (Log::Instance(dirName.string()) == NULL) {
65 fprintf(stderr, "cannot create Log");
66 return 1;
67 }
68 Log::Instance()->setLogLevel((Log::LogLevel)logLevel);
69 // Log can be used from here
70 if (Report::Instance(dirName.string()) == NULL) {
71
72 LOGE("cannot create log");
73 return 1;
74 }
75
76 ModelBuilder modelBuilder;
77 UniquePtr<TaskGeneric> topTask(modelBuilder.parseTestDescriptionXml(xmlFile));
78 if (topTask.get() == NULL) {
79 LOGE("Parsing of %x failed", xmlFile.string());
80 return 1;
81 }
82 topTask->run();
83 return 0;
84 }
85
86