aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2020-05-29 19:04:53 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-05-29 19:04:53 +0000
commitcbeb95cdb4ffbfcd4590db572f85f36be6d4ce98 (patch)
treefe6f0df808b10b623af7924a4300249478ea9890
parent2474fb6e7f375f6306bc1f1a54687dd7c96da02d (diff)
parent2915f2a9a78cfdabcdf329d0040f6b1b3714272c (diff)
downloadchre-cbeb95cdb4ffbfcd4590db572f85f36be6d4ce98.tar.gz
Merge "Implement wifi scan result comparison and logging." into rvc-dev am: 2915f2a9a7
Change-Id: I3d3106badca0604bdf4df4e2885d6f6e3e3b5456
-rw-r--r--apps/test/common/chre_cross_validator_wifi/inc/chre_cross_validator_wifi_manager.h4
-rw-r--r--apps/test/common/chre_cross_validator_wifi/inc/wifi_scan_result.h32
-rw-r--r--apps/test/common/chre_cross_validator_wifi/src/chre_cross_validator_wifi_manager.cc40
-rw-r--r--apps/test/common/chre_cross_validator_wifi/src/wifi_scan_result.cc53
-rw-r--r--apps/test/common/proto/chre_cross_validation_wifi.proto8
-rw-r--r--java/test/cross_validation/src/com/google/android/chre/test/crossvalidator/ChreCrossValidatorWifi.java15
6 files changed, 120 insertions, 32 deletions
diff --git a/apps/test/common/chre_cross_validator_wifi/inc/chre_cross_validator_wifi_manager.h b/apps/test/common/chre_cross_validator_wifi/inc/chre_cross_validator_wifi_manager.h
index 6b4f1814..e1d5c274 100644
--- a/apps/test/common/chre_cross_validator_wifi/inc/chre_cross_validator_wifi_manager.h
+++ b/apps/test/common/chre_cross_validator_wifi/inc/chre_cross_validator_wifi_manager.h
@@ -68,9 +68,11 @@ class Manager {
//! The current index that cross validator should assign to when a new scan
//! result comes in.
- uint8_t mApScanResultsI = 0;
uint8_t mChreScanResultsI = 0;
+ uint8_t mChreScanResultsSize = 0;
+ uint8_t mApScanResultsSize = 0;
+
//! The number of wifi scan results processed from CHRE apis
uint8_t mNumResultsProcessed = 0;
diff --git a/apps/test/common/chre_cross_validator_wifi/inc/wifi_scan_result.h b/apps/test/common/chre_cross_validator_wifi/inc/wifi_scan_result.h
index fabc7e3c..6bba0a3e 100644
--- a/apps/test/common/chre_cross_validator_wifi/inc/wifi_scan_result.h
+++ b/apps/test/common/chre_cross_validator_wifi/inc/wifi_scan_result.h
@@ -20,6 +20,8 @@
#include <cinttypes>
#include <chre.h>
+#include <pb_decode.h>
+
#include "chre_cross_validation_wifi.nanopb.h"
class WifiScanResult {
@@ -30,9 +32,10 @@ class WifiScanResult {
/**
* The ctor for the scan result for the AP.
*
- * @param apScanResult The wifi scan result proto received from AP.
+ * @param apWifiScanResultStream The wifi istream build from the nanoapp
+ * message buffer from AP.
*/
- WifiScanResult(const chre_cross_validation_wifi_WifiScanResult &apScanResult);
+ WifiScanResult(pb_istream_t *apWifiScanResultStream);
/**
* The ctor for the scan result for CHRE.
@@ -42,6 +45,31 @@ class WifiScanResult {
WifiScanResult(const chreWifiScanResult &chreScanResult);
static bool areEqual(WifiScanResult result1, WifiScanResult result2);
+
+ uint8_t getResultIndex() const {
+ return mResultIndex;
+ }
+ uint8_t getTotalNumResults() const {
+ return mTotalNumResults;
+ }
+
+ // TODO(b/154271547): Remove this method and check that all scan results are
+ // valid instead
+ bool isLastMessage() const {
+ return mResultIndex >= mTotalNumResults - 1;
+ }
+
+ private:
+ char mSsid[CHRE_WIFI_SSID_MAX_LEN];
+ uint8_t mBssid[CHRE_WIFI_BSSID_LEN];
+
+ uint8_t mTotalNumResults = 0;
+ uint8_t mResultIndex = 0;
+
+ static bool decodeString(pb_istream_t *stream, const pb_field_t * /*field*/,
+ void **arg);
+
+ static bool byteArraysAreEqual(uint8_t *arr1, uint8_t *arr2, uint8_t len);
};
#endif // WIFI_SCAN_RESULT_H_
diff --git a/apps/test/common/chre_cross_validator_wifi/src/chre_cross_validator_wifi_manager.cc b/apps/test/common/chre_cross_validator_wifi/src/chre_cross_validator_wifi_manager.cc
index 9c9ddee6..3014249c 100644
--- a/apps/test/common/chre_cross_validator_wifi/src/chre_cross_validator_wifi_manager.cc
+++ b/apps/test/common/chre_cross_validator_wifi/src/chre_cross_validator_wifi_manager.cc
@@ -117,15 +117,18 @@ void Manager::handleDataMessage(const chreMessageFromHostData *hostData) {
pb_istream_from_buffer(reinterpret_cast<const pb_byte_t *>(
const_cast<const void *>(hostData->message)),
hostData->messageSize);
- chre_cross_validation_wifi_WifiScanResult scanResult =
- chre_cross_validation_wifi_WifiScanResult_init_default;
- if (!pb_decode(&stream, chre_cross_validation_wifi_WifiScanResult_fields,
- &scanResult)) {
- LOGE("Could not decode wifi scan result from AP");
+ WifiScanResult scanResult(&stream);
+ uint8_t scanResultIndex = scanResult.getResultIndex();
+ mApScanResultsSize = scanResult.getTotalNumResults();
+ if (scanResultIndex > mApScanResultsSize) {
+ LOGE("AP scan result index is greater than scan results size");
} else {
- mApDataCollectionDone = true;
- if (mChreDataCollectionDone) {
- compareAndSendResultToHost();
+ mApScanResults[scanResultIndex] = scanResult;
+ if (scanResult.isLastMessage()) {
+ mApDataCollectionDone = true;
+ if (mChreDataCollectionDone) {
+ compareAndSendResultToHost();
+ }
}
}
}
@@ -140,6 +143,7 @@ void Manager::handleWifiScanResult(const chreWifiScanEvent *event) {
}
mNumResultsProcessed += event->resultCount;
if (mNumResultsProcessed >= event->resultTotal) {
+ mChreScanResultsSize = mChreScanResultsI;
mChreDataCollectionDone = true;
if (mApDataCollectionDone) {
compareAndSendResultToHost();
@@ -156,23 +160,20 @@ void Manager::compareAndSendResultToHost() {
if (errMsg == nullptr) {
LOG_OOM();
} else {
- bool success = true;
- if (mApScanResultsI != mChreScanResultsI) {
+ // Logging all info about the scan results for debug purposes
+ if (mApScanResultsSize != mChreScanResultsSize) {
testResult = makeTestResultProtoMessage(
false, "There is a different number of AP and CHRE scan results.");
- LOGE(
- "There is a different number of AP and CHRE scan results. AP = "
- "%" PRIu8 ", CHRE = %" PRIu8,
- mApScanResultsI, mChreScanResultsI);
- success = false;
+ LOGE("AP and CHRE wifi scan result counts differ, AP = %" PRIu8
+ ", CHRE = %" PRIu8,
+ mApScanResultsSize, mChreScanResultsSize);
} else {
- for (uint8_t i = 0; i < mApScanResultsI; i++) {
+ for (uint8_t i = 0; i < mApScanResultsSize; i++) {
if (!WifiScanResult::areEqual(mApScanResults[i], mChreScanResults[i])) {
testResult = makeTestResultProtoMessage(
false, "One of the AP and CHRE scan results are not equal.");
LOGE("The AP and CHRE scan results are not equal on index %" PRIu8,
i);
- success = false;
}
}
}
@@ -235,7 +236,6 @@ void Manager::encodeAndSendMessageToHost(const void *message,
}
void Manager::handleWifiAsyncResult(const chreAsyncResult *result) {
- LOGI("handleWifiAsyncResult method");
chre_test_common_TestResult testResult;
if (result->requestType == CHRE_WIFI_REQUEST_TYPE_CONFIGURE_SCAN_MONITOR) {
if (mStep != chre_cross_validation_wifi_Step_SETUP) {
@@ -252,13 +252,13 @@ void Manager::handleWifiAsyncResult(const chreAsyncResult *result) {
testResult = makeTestResultProtoMessage(
false, "Wifi scan monitoring setup failed async.");
}
- encodeAndSendMessageToHost(static_cast<void *>(&testResult),
- chre_test_common_TestResult_fields);
}
} else {
testResult = makeTestResultProtoMessage(
false, "Unknown chre async result type received");
}
+ encodeAndSendMessageToHost(static_cast<void *>(&testResult),
+ chre_test_common_TestResult_fields);
}
} // namespace cross_validator_wifi
diff --git a/apps/test/common/chre_cross_validator_wifi/src/wifi_scan_result.cc b/apps/test/common/chre_cross_validator_wifi/src/wifi_scan_result.cc
index 28dbe24d..46a74e8a 100644
--- a/apps/test/common/chre_cross_validator_wifi/src/wifi_scan_result.cc
+++ b/apps/test/common/chre_cross_validator_wifi/src/wifi_scan_result.cc
@@ -16,12 +16,57 @@
#include "wifi_scan_result.h"
-WifiScanResult::WifiScanResult(
- const chre_cross_validation_wifi_WifiScanResult &apScanResult) {}
+#include <chre.h>
-WifiScanResult::WifiScanResult(const chreWifiScanResult &chreScanResult) {}
+#include "chre/util/nanoapp/log.h"
+
+#include <stdio.h>
+#include <cstring>
+
+#define LOG_TAG "ChreCrossValidatorWifi"
+
+WifiScanResult::WifiScanResult(pb_istream_t *apWifiScanResultStream) {
+ memset(mSsid, 0, CHRE_WIFI_SSID_MAX_LEN);
+ chre_cross_validation_wifi_WifiScanResult wifiScanResultProto =
+ chre_cross_validation_wifi_WifiScanResult_init_default;
+ wifiScanResultProto.ssid = {.funcs = {.decode = decodeString}, .arg = mSsid};
+ wifiScanResultProto.bssid = {.funcs = {.decode = decodeString},
+ .arg = mBssid};
+ if (!pb_decode(apWifiScanResultStream,
+ chre_cross_validation_wifi_WifiScanResult_fields,
+ &wifiScanResultProto)) {
+ LOGE("AP wifi scan result proto message decode failed");
+ }
+ mTotalNumResults = wifiScanResultProto.totalNumResults;
+ mResultIndex = wifiScanResultProto.resultIndex;
+ LOGI("AP scan result mSsid = %s", mSsid);
+}
+
+WifiScanResult::WifiScanResult(const chreWifiScanResult &chreScanResult) {
+ LOGI("CHRE scan result mSsid = %s", chreScanResult.ssid);
+ memset(mSsid, 0, CHRE_WIFI_SSID_MAX_LEN);
+ memcpy(mSsid, chreScanResult.ssid, chreScanResult.ssidLen);
+ memcpy(mBssid, chreScanResult.bssid, CHRE_WIFI_BSSID_LEN);
+}
bool WifiScanResult::areEqual(WifiScanResult result1, WifiScanResult result2) {
- // TODO: Implement real comparison
+ // TODO(srok): Compare all fields that are shared between AP and CHRE scan
+ // result.
+ return strcmp(result1.mSsid, result2.mSsid) == 0 &&
+ byteArraysAreEqual(result1.mBssid, result2.mBssid,
+ CHRE_WIFI_BSSID_LEN);
+}
+
+bool WifiScanResult::decodeString(pb_istream_t *stream,
+ const pb_field_t * /*field*/, void **arg) {
+ pb_byte_t *strPtr = reinterpret_cast<pb_byte_t *>(*arg);
+ return pb_read(stream, strPtr, stream->bytes_left);
+}
+
+bool WifiScanResult::byteArraysAreEqual(uint8_t *arr1, uint8_t *arr2,
+ uint8_t len) {
+ for (uint8_t i = 0; i < len; i++) {
+ if (arr1[i] != arr2[i]) return false;
+ }
return true;
}
diff --git a/apps/test/common/proto/chre_cross_validation_wifi.proto b/apps/test/common/proto/chre_cross_validation_wifi.proto
index e15e870e..8a400f46 100644
--- a/apps/test/common/proto/chre_cross_validation_wifi.proto
+++ b/apps/test/common/proto/chre_cross_validation_wifi.proto
@@ -44,9 +44,13 @@ message StepStartCommand {
* //system/chre/chre_api/include/chre_api/chre/wifi.h
*/
message WifiScanResult {
+ // The name of the access point
+ optional string ssid = 1;
+ // The mac address of the access point
+ optional bytes bssid = 2;
// The total number of results that will be sent from AP.
- optional uint32 totalNumResults = 1;
+ optional uint32 totalNumResults = 3;
// The index of this result in relation to the entire set of results.
// [0 - totalNumResults)
- optional uint32 resultIndex = 2;
+ optional uint32 resultIndex = 4;
}
diff --git a/java/test/cross_validation/src/com/google/android/chre/test/crossvalidator/ChreCrossValidatorWifi.java b/java/test/cross_validation/src/com/google/android/chre/test/crossvalidator/ChreCrossValidatorWifi.java
index b1c5dee1..bd08e812 100644
--- a/java/test/cross_validation/src/com/google/android/chre/test/crossvalidator/ChreCrossValidatorWifi.java
+++ b/java/test/cross_validation/src/com/google/android/chre/test/crossvalidator/ChreCrossValidatorWifi.java
@@ -34,10 +34,12 @@ import androidx.test.InstrumentationRegistry;
import com.google.android.chre.nanoapp.proto.ChreCrossValidationWifi;
import com.google.android.chre.nanoapp.proto.ChreCrossValidationWifi.Step;
import com.google.android.chre.nanoapp.proto.ChreTestCommon;
+import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import org.junit.Assert;
+import java.math.BigInteger;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -174,10 +176,11 @@ public class ChreCrossValidatorWifi extends ChreCrossValidatorBase {
private NanoAppMessage makeWifiScanResultMessage(ScanResult result, int totalNumResults,
int resultIndex) {
- ChreCrossValidationWifi.WifiScanResult scanResult = ChreCrossValidationWifi.WifiScanResult
- .newBuilder().setTotalNumResults(totalNumResults).setResultIndex(resultIndex)
- .build();
int messageType = ChreCrossValidationWifi.MessageType.SCAN_RESULT_VALUE;
+ ChreCrossValidationWifi.WifiScanResult scanResult = ChreCrossValidationWifi.WifiScanResult
+ .newBuilder().setSsid(result.SSID)
+ .setBssid(ByteString.copyFrom(bssidToBytes(result.BSSID)))
+ .setTotalNumResults(totalNumResults).setResultIndex(resultIndex).build();
NanoAppMessage message = NanoAppMessage.createMessageToNanoApp(
mNappBinary.getNanoAppId(), messageType, scanResult.toByteArray());
return message;
@@ -239,6 +242,12 @@ public class ChreCrossValidatorWifi extends ChreCrossValidatorBase {
}
}
+ private static byte[] bssidToBytes(String bssid) {
+ // the ScanResult.BSSID field comes in format ff:ff:ff:ff:ff and needs to be converted to
+ // bytes in order to be compared to CHRE bssid
+ return (new BigInteger(bssid.replace(":" , ""), 16)).toByteArray();
+ }
+
// TODO: Implement this method
@Override
protected void unregisterApDataListener() {}