New syntax for config files (build issue resolved).
am: ab614eabaa
Change-Id: I62a2be7dab2b182710477ce929653b96791a8f33
diff --git a/poc/host/SecurityPoCKernelTest.py b/poc/host/SecurityPoCKernelTest.py
index f92c626..e2c89dd 100644
--- a/poc/host/SecurityPoCKernelTest.py
+++ b/poc/host/SecurityPoCKernelTest.py
@@ -36,8 +36,6 @@
_dut: AndroidDevice, the device under test as config
_testcases: string list, list of testcases to run
_model: string, device model e.g. "Nexus 5X"
- _host_input: dict, info passed to PoC test
- _test_flags: string, flags that will be passed to PoC test
"""
def setUpClass(self):
"""Creates device under test instance, and copies data files."""
@@ -48,39 +46,18 @@
self.getUserParams(required_params)
logging.info("%s: %s", keys.ConfigKeys.IKEY_DATA_FILE_PATH,
- self.data_file_path)
+ self.data_file_path)
self._dut = self.registerController(android_device)[0]
self._testcases = config.POC_TEST_CASES_STABLE
if self.run_staging:
self._testcases += config.POC_TEST_CASES_STAGING
- self._host_input = self.CreateHostInput()
-
- self._test_flags = ["--%s=\"%s\"" % (k, v) for k, v in self._host_input.items()]
- self._test_flags = " ".join(self._test_flags)
- logging.info("Test flags: %s", self._test_flags)
-
def tearDownClass(self):
"""Deletes all copied data."""
rm_cmd = "rm -rf %s" % config.POC_TEST_DIR
self._dut.adb.shell("'%s'" % rm_cmd)
- def CreateHostInput(self):
- """Gathers information that will be passed to target-side code.
-
- Returns:
- host_input: dict, information passed to native PoC test.
- """
- cmd = "getprop | grep ro.product.model"
- out = self._dut.adb.shell("'%s'" % cmd)
- device_model = out.strip().split('[')[-1][:-1]
-
- host_input = {
- "device_model": device_model,
- }
- return host_input
-
def PushFiles(self):
"""adb pushes related file to target."""
mkdir_cmd = "mkdir %s -p" % config.POC_TEST_DIR
@@ -89,20 +66,58 @@
push_src = os.path.join(self.data_file_path, "security", "poc", ".")
self._dut.adb.push("%s %s" % (push_src, config.POC_TEST_DIR))
- def IsRelevant(self, testcase):
- """Returns True iff testcase should run according to its config.
+ def CreateHostInput(self, testcase):
+ """Gathers information that will be passed to target-side code.
Args:
testcase: string, format testsuite/testname, specifies which
test case to examine.
+
+ Returns:
+ dict, information passed to native PoC test, contains info collected
+ from device and config. If None, poc should be skipped.
"""
+ cmd = "getprop ro.product.model"
+ out = self._dut.adb.shell("'%s'" % cmd)
+ device_model = out.strip()
+
test_config_path = os.path.join(
self.data_file_path, "security", "poc", testcase + ".config")
with open(test_config_path) as test_config_file:
- test_config = json.load(test_config_file)
- target_models = test_config["target_models"]
- return self._host_input["device_model"] in target_models
+ poc_config = json.load(test_config_file)["target_models"]
+
+ # If dut model is not in the test config, test should be skipped.
+ if not device_model in poc_config.keys():
+ return None
+
+ params = poc_config.get("default", {})
+ params.update(poc_config[device_model])
+
+ host_input = {
+ "device_model": device_model,
+ "params": params
+ }
+
+ return host_input
+
+ def CreateTestFlags(self, host_input):
+ """Packs host input info into command line flags.
+
+ Args:
+ host_input: dict, information passed to native PoC test.
+
+ Returns:
+ string, host_input packed into command-line flags.
+ """
+ device_model_flag = "--device_model=\"%s\"" % host_input["device_model"]
+
+ params = ["%s=%s" % (k, v) for k, v in host_input["params"].items()]
+ params = ",".join(params)
+ params_flag = "--params=\"%s\"" % params
+
+ test_flags = [device_model_flag, params_flag]
+ return " ".join(test_flags)
def RunTestcase(self, testcase):
"""Runs the given testcase and asserts the result.
@@ -111,8 +126,9 @@
testcase: string, format testsuite/testname, specifies which
test case to run.
"""
- asserts.skipIf(not self.IsRelevant(testcase),
- "%s not configured to run against this target model." % testcase)
+ host_input = self.CreateHostInput(testcase)
+ asserts.skipIf(not host_input,
+ "%s not configured to run against this target model." % testcase)
items = testcase.split("/", 1)
testsuite = items[0]
@@ -121,10 +137,12 @@
logging.info("Executing: %s", chmod_cmd)
self._dut.adb.shell("'%s'" % chmod_cmd)
+ test_flags = self.CreateTestFlags(host_input)
test_cmd = "%s %s" % (
os.path.join(config.POC_TEST_DIR, testcase),
- self._test_flags)
+ test_flags)
logging.info("Executing: %s", test_cmd)
+
try:
stdout = self._dut.adb.shell("'%s'" % test_cmd)
result = {
@@ -138,6 +156,7 @@
const.STDERR: e.stderr,
const.EXIT_CODE: e.ret_code
}
+ logging.info("Test results:\n%s", result)
self.AssertTestResult(result)
diff --git a/poc/host/poc_test_config.py b/poc/host/poc_test_config.py
index 85f5daa..f23a77d 100644
--- a/poc/host/poc_test_config.py
+++ b/poc/host/poc_test_config.py
@@ -36,7 +36,7 @@
"kernel_bluetooth/30149612",
"kernel_wifi/32219453",
"kernel_wifi/31707909",
- "kernel_wifi/32402310"
+ "kernel_wifi/32402310",
]
POC_TEST_CASES_DISABLED = [
diff --git a/poc/target/Android.mk b/poc/target/Android.mk
index b1d4b56..f7b5a22 100644
--- a/poc/target/Android.mk
+++ b/poc/target/Android.mk
@@ -22,7 +22,7 @@
include $(CLEAR_VARS)
poc_test_src_files := \
- poc_test.c \
+ poc_test.cpp \
# TODO(trong): tests should not emit warnings.
poc_test_cflags := \
diff --git a/poc/target/Android.poc_test_list.mk b/poc/target/Android.poc_test_list.mk
index 6f7f09a..165d76b 100644
--- a/poc/target/Android.poc_test_list.mk
+++ b/poc/target/Android.poc_test_list.mk
@@ -16,7 +16,7 @@
#Bluetooth POCs
module_testname := kernel_bluetooth/30149612
-module_src_files := kernel_bluetooth/30149612/poc.c
+module_src_files := kernel_bluetooth/30149612/poc.cpp
module_cflags :=
module_c_includes :=
module_static_libraries :=
@@ -25,7 +25,7 @@
#Sound POCs
module_testname := kernel_sound/28838221
-module_src_files := kernel_sound/28838221/poc.c
+module_src_files := kernel_sound/28838221/poc.cpp
module_cflags :=
module_c_includes :=
module_static_libraries :=
@@ -34,7 +34,7 @@
#Wifi POCs
module_testname := kernel_wifi/32219453
-module_src_files := kernel_wifi/32219453/poc.c
+module_src_files := kernel_wifi/32219453/poc.cpp
module_cflags :=
module_c_includes :=
module_static_libraries :=
@@ -42,7 +42,7 @@
include $(build_poc_test)
module_testname := kernel_wifi/31707909
-module_src_files := kernel_wifi/31707909/poc.c
+module_src_files := kernel_wifi/31707909/poc.cpp
module_cflags :=
module_c_includes :=
module_static_libraries :=
@@ -50,7 +50,7 @@
include $(build_poc_test)
module_testname := kernel_wifi/32402310
-module_src_files := kernel_wifi/32402310/poc.c
+module_src_files := kernel_wifi/32402310/poc.cpp
module_cflags :=
module_c_includes :=
module_static_libraries :=
diff --git a/poc/target/kernel_bluetooth/30149612/poc.config b/poc/target/kernel_bluetooth/30149612/poc.config
index fb23a7d..98988d7 100644
--- a/poc/target/kernel_bluetooth/30149612/poc.config
+++ b/poc/target/kernel_bluetooth/30149612/poc.config
@@ -1,7 +1,7 @@
{
- "target_models": [
- "Nexus 5",
- "Nexus 6P",
- "Android One"
- ]
+ "target_models": {
+ "Nexus 5": {},
+ "Nexus 6P": {},
+ "Android One": {}
+ }
}
diff --git a/poc/target/kernel_bluetooth/30149612/poc.c b/poc/target/kernel_bluetooth/30149612/poc.cpp
similarity index 97%
rename from poc/target/kernel_bluetooth/30149612/poc.c
rename to poc/target/kernel_bluetooth/30149612/poc.cpp
index 519283d..0e27c97 100644
--- a/poc/target/kernel_bluetooth/30149612/poc.c
+++ b/poc/target/kernel_bluetooth/30149612/poc.cpp
@@ -10,7 +10,7 @@
int main(int argc, char* argv[]) {
VtsHostInput host_input = ParseVtsHostFlags(argc, argv);
struct sockaddr sa;
- unsigned int len, i;
+ socklen_t len, i;
int fd;
fd = socket(AF_BLUETOOTH, SOCK_STREAM, 3);
diff --git a/poc/target/kernel_sound/28838221/poc.config b/poc/target/kernel_sound/28838221/poc.config
index 464b6a7..7212046 100644
--- a/poc/target/kernel_sound/28838221/poc.config
+++ b/poc/target/kernel_sound/28838221/poc.config
@@ -1,9 +1,16 @@
{
- "target_models": [
- "Nexus 5",
- "Nexus 5X",
- "Nexus 6",
- "Nexus 6P",
- "Nexus Player"
- ]
+ "target_models": {
+ "Nexus 5": {},
+ "Nexus 5X": {
+ "path": "/sys/kernel/debug/asoc/msm8994-tomtom-snd-card/snd-soc-dummy/codec_reg"
+ },
+ "Nexus 6": {},
+ "Nexus 6P": {
+ "path": "/sys/kernel/debug/asoc/msm8994-tomtom-mtp-snd-card/snd-soc-dummy/codec_reg"
+ },
+ "Nexus Player": {},
+ "default": {
+ "path": "/sys/kernel/debug/asoc/msm8994-tomtom-snd-card/snd-soc-dummy/codec_reg"
+ }
+ }
}
diff --git a/poc/target/kernel_sound/28838221/poc.c b/poc/target/kernel_sound/28838221/poc.cpp
similarity index 68%
rename from poc/target/kernel_sound/28838221/poc.c
rename to poc/target/kernel_sound/28838221/poc.cpp
index 949d068..c4f0847 100644
--- a/poc/target/kernel_sound/28838221/poc.c
+++ b/poc/target/kernel_sound/28838221/poc.cpp
@@ -14,16 +14,10 @@
int main(int argc, char* argv[]) {
VtsHostInput host_input = ParseVtsHostFlags(argc, argv);
- const char* path;
- switch (host_input.device_model) {
- case NEXUS_5X:
- path = "/sys/kernel/debug/asoc/msm8994-tomtom-snd-card/snd-soc-dummy/codec_reg";
- break;
- case NEXUS_6P:
- path = "/sys/kernel/debug/asoc/msm8994-tomtom-mtp-snd-card/snd-soc-dummy/codec_reg";
- break;
- default:
- return POC_TEST_SKIP;
+ const char* path = host_input.params["path"].c_str();
+ if (strlen(path) == 0) {
+ fprintf(stderr, "path parameter is empty.\n");
+ return POC_TEST_FAIL;
}
int ret;
diff --git a/poc/target/kernel_wifi/31707909/poc.config b/poc/target/kernel_wifi/31707909/poc.config
index 39ed876..1bb7913 100644
--- a/poc/target/kernel_wifi/31707909/poc.config
+++ b/poc/target/kernel_wifi/31707909/poc.config
@@ -1,7 +1,10 @@
{
- "target_models": [
- "Nexus 6",
- "Nexus 6P",
- "Nexus Player"
- ]
+ "target_models": {
+ "Nexus 6": {},
+ "Nexus 6P": {},
+ "Nexus Player": {},
+ "default": {
+ "ifname": "wlan0"
+ }
+ }
}
diff --git a/poc/target/kernel_wifi/31707909/poc.c b/poc/target/kernel_wifi/31707909/poc.cpp
similarity index 89%
rename from poc/target/kernel_wifi/31707909/poc.c
rename to poc/target/kernel_wifi/31707909/poc.cpp
index 3cc3759..2434604 100644
--- a/poc/target/kernel_wifi/31707909/poc.c
+++ b/poc/target/kernel_wifi/31707909/poc.cpp
@@ -63,7 +63,7 @@
uint driver; /* to identify target driver */
} dhd_ioctl_t;
-int poc() {
+int poc(const char *ifname) {
int fd, i, res;
dhd_ioctl_t ioc;
struct ifreq arg;
@@ -72,7 +72,6 @@
android_wifi_priv_cmd priv_cmd;
char buf[BUF_LEN];
char iocbuf[IOC_BUF_LEN];
- const char *ifname = "wlan0"; /* default iface name is wlan0 */
fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0) {
@@ -104,10 +103,17 @@
}
int main(int argc, char **argv) {
+ VtsHostInput host_input = ParseVtsHostFlags(argc, argv);
+ const char *ifname = host_input.params["ifname"].c_str();
+ if (strlen(ifname) == 0) {
+ fprintf(stderr, "ifname parameter is empty.\n");
+ return POC_TEST_FAIL;
+ }
+
int i, ret;
for (i = 0; i < TEST_CNT; i++) {
- if ((ret = poc()) != POC_TEST_PASS) break;
+ if ((ret = poc(ifname)) != POC_TEST_PASS) break;
}
return ret;
diff --git a/poc/target/kernel_wifi/32219453/poc.config b/poc/target/kernel_wifi/32219453/poc.config
index 39ed876..1bb7913 100644
--- a/poc/target/kernel_wifi/32219453/poc.config
+++ b/poc/target/kernel_wifi/32219453/poc.config
@@ -1,7 +1,10 @@
{
- "target_models": [
- "Nexus 6",
- "Nexus 6P",
- "Nexus Player"
- ]
+ "target_models": {
+ "Nexus 6": {},
+ "Nexus 6P": {},
+ "Nexus Player": {},
+ "default": {
+ "ifname": "wlan0"
+ }
+ }
}
diff --git a/poc/target/kernel_wifi/32219453/poc.c b/poc/target/kernel_wifi/32219453/poc.cpp
similarity index 96%
rename from poc/target/kernel_wifi/32219453/poc.c
rename to poc/target/kernel_wifi/32219453/poc.cpp
index 3a80359..9e60851 100644
--- a/poc/target/kernel_wifi/32219453/poc.c
+++ b/poc/target/kernel_wifi/32219453/poc.cpp
@@ -223,9 +223,15 @@
int main(int argc, char *argv[]) {
+ VtsHostInput host_input = ParseVtsHostFlags(argc, argv);
+ const char *ifname = host_input.params["ifname"].c_str();
+ if (strlen(ifname) == 0) {
+ fprintf(stderr, "ifname parameter is empty.");
+ return POC_TEST_FAIL;
+ }
+
int ret = 0;
int family_id = 0;
- const char *ifname = "wlan0"; /* default iface name is wlan0 */
if (getuid() != 0) {
printf("need root privilege\n");
diff --git a/poc/target/kernel_wifi/32402310/poc.config b/poc/target/kernel_wifi/32402310/poc.config
index 84ffaad..21ca0b9 100644
--- a/poc/target/kernel_wifi/32402310/poc.config
+++ b/poc/target/kernel_wifi/32402310/poc.config
@@ -1,5 +1,7 @@
{
- "target_models": [
- "Nexus 5X"
- ]
+ "target_models": {
+ "Nexus 5X": {
+ "ifname": "wlan0"
+ }
+ }
}
diff --git a/poc/target/kernel_wifi/32402310/poc.c b/poc/target/kernel_wifi/32402310/poc.cpp
similarity index 95%
rename from poc/target/kernel_wifi/32402310/poc.c
rename to poc/target/kernel_wifi/32402310/poc.cpp
index d314e61..3461c19 100644
--- a/poc/target/kernel_wifi/32402310/poc.c
+++ b/poc/target/kernel_wifi/32402310/poc.cpp
@@ -147,9 +147,15 @@
}
int main(int argc, char *argv[]) {
+ VtsHostInput host_input = ParseVtsHostFlags(argc, argv);
+ const char *ifname = host_input.params["ifname"].c_str();
+ if (strlen(ifname) == 0) {
+ fprintf(stderr, "ifname parameter is empty.");
+ return POC_TEST_FAIL;
+ }
+
int ret = 0;
int family_id = 0;
- const char *ifname = "wlan0";
gid_t gid_groups[] = {AID_INET, AID_NET_ADMIN};
if (getuid() != 0) {
diff --git a/poc/target/poc_test.c b/poc/target/poc_test.c
deleted file mode 100644
index 94b6b01..0000000
--- a/poc/target/poc_test.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "poc_test.h"
-
-#include <getopt.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-static struct option long_options[] = {
- {"device_model", required_argument, 0, 'd'}
-};
-
-static DeviceModel TranslateDeviceModel(const char *name) {
- DeviceModel device_model;
- if (!strcmp("Nexus 5", name)) device_model = NEXUS_5;
- if (!strcmp("Nexus 5X", name)) device_model = NEXUS_5X;
- if (!strcmp("Nexus 6", name)) device_model = NEXUS_6;
- if (!strcmp("Nexus 6P", name)) device_model = NEXUS_6P;
- if (!strcmp("Pixel", name)) device_model = PIXEL;
- if (!strcmp("Pixel XL", name)) device_model = PIXEL_XL;
- return device_model;
-}
-
-VtsHostInput ParseVtsHostFlags(int argc, char *argv[]) {
- VtsHostInput host_input;
- int opt = 0;
- int index = 0;
- while ((opt = getopt_long_only(argc, argv, "", long_options, &index)) != -1) {
- switch(opt) {
- case 'd':
- host_input.device_model = TranslateDeviceModel(optarg);
- break;
- default:
- printf("Wrong parameters.");
- exit(POC_TEST_FAIL);
- }
- }
- return host_input;
-}
diff --git a/poc/target/poc_test.cpp b/poc/target/poc_test.cpp
new file mode 100644
index 0000000..72a3b12
--- /dev/null
+++ b/poc/target/poc_test.cpp
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "poc_test.h"
+
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <iostream>
+#include <sstream>
+
+using std::cout;
+using std::cerr;
+using std::endl;
+using std::map;
+using std::string;
+
+static struct option long_options[] = {
+ {"device_model", required_argument, 0, 'd'},
+ {"params", required_argument, 0, 'p'}
+};
+
+static DeviceModel TranslateDeviceModel(const char *model_name) {
+ DeviceModel device_model;
+ if (!strcmp("Nexus 5", model_name)) {
+ device_model = NEXUS_5;
+ } else if (!strcmp("Nexus 5X", model_name)) {
+ device_model = NEXUS_5X;
+ } else if (!strcmp("Nexus 6", model_name)) {
+ device_model = NEXUS_6;
+ } else if (!strcmp("Nexus 6P", model_name)) {
+ device_model = NEXUS_6P;
+ } else if (!strcmp("Pixel", model_name)) {
+ device_model = PIXEL;
+ } else if (!strcmp("Pixel XL", model_name)) {
+ device_model = PIXEL_XL;
+ } else {
+ device_model = OTHER;
+ }
+ return device_model;
+}
+
+static map<string, string> ExtractParams(const char *test_params) {
+ map<string, string> params;
+ string input(test_params);
+ std::istringstream iss(input);
+
+ string key_value;
+ while(std::getline(iss, key_value, ',')) {
+ size_t delim = key_value.find('=');
+ if (delim == string::npos) {
+ cerr << "Missing '=' delimiter.\n";
+ exit(POC_TEST_SKIP);
+ }
+
+ string key = key_value.substr(0, delim);
+ string value = key_value.substr(delim + 1);
+
+ params[key] = value;
+ }
+
+ return params;
+}
+
+VtsHostInput ParseVtsHostFlags(int argc, char *argv[]) {
+ VtsHostInput host_input;
+ int opt = 0;
+ int index = 0;
+ while ((opt = getopt_long_only(argc, argv, "", long_options, &index)) != -1) {
+ switch(opt) {
+ case 'd':
+ host_input.device_model = TranslateDeviceModel(optarg);
+ break;
+ case 'p':
+ host_input.params = ExtractParams(optarg);
+ break;
+ default:
+ cerr << "Wrong parameters.\n";
+ exit(POC_TEST_SKIP);
+ }
+ }
+ return host_input;
+}
diff --git a/poc/target/poc_test.h b/poc/target/poc_test.h
index 8649f33..6415116 100644
--- a/poc/target/poc_test.h
+++ b/poc/target/poc_test.h
@@ -17,6 +17,9 @@
#ifndef __VTS_TESTCASES_SECURITY_POC_TARGET_POC_TEST_H__
#define __VTS_TESTCASES_SECURITY_POC_TARGET_POC_TEST_H__
+#include <map>
+#include <string>
+
/* define poc_test exit codes */
#define POC_TEST_PASS 0
#define POC_TEST_FAIL 1
@@ -28,11 +31,13 @@
NEXUS_6,
NEXUS_6P,
PIXEL,
- PIXEL_XL
+ PIXEL_XL,
+ OTHER
} DeviceModel;
typedef struct {
DeviceModel device_model;
+ std::map<std::string, std::string> params;
} VtsHostInput;
extern VtsHostInput ParseVtsHostFlags(int argc, char *argv[]);