diff options
author | Stan Rokita <srok@google.com> | 2020-05-19 15:17:27 -0700 |
---|---|---|
committer | Stan Rokita <srok@google.com> | 2020-05-28 17:22:17 -0700 |
commit | ae4af00d674975b46cb82404e7e196356e04da0e (patch) | |
tree | dcac21f4de9c7811b5f1928e02e21d6491e95110 /apps | |
parent | ed6ecbb23de98058ebcdc2c6a22b02ad11bc68e5 (diff) | |
download | chre-ae4af00d674975b46cb82404e7e196356e04da0e.tar.gz |
Implement the nanoapp validate step
Implement everything for the wifi cross validator plumbing code but
ignore the comparison logic saving that as a todo for next CL.
Bug: 154271547
Test: Test currently fails at final comparison result assertion with the error
that the ap and chre wifi scan result arrays are different sizes which
will be addressed in a later CL
Change-Id: I817948aa2281bf6d6de4c24c6408c478c159f62e
Diffstat (limited to 'apps')
5 files changed, 193 insertions, 1 deletions
diff --git a/apps/test/common/chre_cross_validator_wifi/Makefile b/apps/test/common/chre_cross_validator_wifi/Makefile index bfcb8b2a..0ad79071 100644 --- a/apps/test/common/chre_cross_validator_wifi/Makefile +++ b/apps/test/common/chre_cross_validator_wifi/Makefile @@ -35,6 +35,7 @@ NANOPB_FLAGS += --proto_path=$(NANOPB_PROTO_PATH) COMMON_SRCS += $(NANOAPP_PATH)/src/chre_cross_validator_wifi.cc COMMON_SRCS += $(NANOAPP_PATH)/src/chre_cross_validator_wifi_manager.cc +COMMON_SRCS += $(NANOAPP_PATH)/src/wifi_scan_result.cc COMMON_SRCS += $(CHRE_PREFIX)/util/nanoapp/callbacks.cc # Compiler Flags ############################################################### 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 39289210..6b4f1814 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 @@ -18,6 +18,7 @@ #define CHRE_CROSS_VALIDATOR_WIFI_MANAGER_H_ #include <cinttypes> +#include <cstdint> #include <chre.h> #include <pb_common.h> @@ -29,6 +30,8 @@ #include "chre_cross_validation_wifi.nanopb.h" #include "chre_test_common.nanopb.h" +#include "wifi_scan_result.h" + namespace chre { namespace cross_validator_wifi { @@ -58,6 +61,23 @@ class Manager { //! Struct that holds some information about the state of the cross validator CrossValidatorState mCrossValidatorState; + // TODO: Find a better max scan results val + static constexpr uint8_t kMaxScanResults = UINT8_MAX; + WifiScanResult mApScanResults[kMaxScanResults]; + WifiScanResult mChreScanResults[kMaxScanResults]; + + //! The current index that cross validator should assign to when a new scan + //! result comes in. + uint8_t mApScanResultsI = 0; + uint8_t mChreScanResultsI = 0; + + //! The number of wifi scan results processed from CHRE apis + uint8_t mNumResultsProcessed = 0; + + //! Bools indicating that data collection is complete for each side + bool mApDataCollectionDone = false; + bool mChreDataCollectionDone = false; + /** * Handle a message from the host. * @param senderInstanceId The instance id of the sender. @@ -92,6 +112,24 @@ class Manager { */ void encodeAndSendMessageToHost(const void *message, const pb_field_t *fields); + /** + * Handle a wifi scan result data message sent from AP. + * + * @param hostData The message. + */ + void handleDataMessage(const chreMessageFromHostData *hostData); + + /** + * Handle a wifi scan result event from a CHRE event. + * + * @param event the wifi scan event from CHRE api. + */ + void handleWifiScanResult(const chreWifiScanEvent *event); + + /** + * Compare the AP and CHRE wifi scan results and send test result to host. + */ + void compareAndSendResultToHost(); /** * Setup WiFi scan monitoring from CHRE apis. 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 new file mode 100644 index 00000000..fabc7e3c --- /dev/null +++ b/apps/test/common/chre_cross_validator_wifi/inc/wifi_scan_result.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2020 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. + */ + +#ifndef WIFI_SCAN_RESULT_H_ +#define WIFI_SCAN_RESULT_H_ + +#include <cinttypes> + +#include <chre.h> +#include "chre_cross_validation_wifi.nanopb.h" + +class WifiScanResult { + public: + WifiScanResult() { + } // Need for default ctor of WifiScanResult arrays in manager + + /** + * The ctor for the scan result for the AP. + * + * @param apScanResult The wifi scan result proto received from AP. + */ + WifiScanResult(const chre_cross_validation_wifi_WifiScanResult &apScanResult); + + /** + * The ctor for the scan result for CHRE. + * + * @param apScanResult The wifi scan result struct received from CHRE apis. + */ + WifiScanResult(const chreWifiScanResult &chreScanResult); + + static bool areEqual(WifiScanResult result1, WifiScanResult result2); +}; + +#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 7bc82818..9c9ddee6 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 @@ -45,6 +45,8 @@ void Manager::handleEvent(uint32_t senderInstanceId, uint16_t eventType, break; case CHRE_EVENT_WIFI_ASYNC_RESULT: handleWifiAsyncResult(static_cast<const chreAsyncResult *>(eventData)); + case CHRE_EVENT_WIFI_SCAN_RESULT: + handleWifiScanResult(static_cast<const chreWifiScanEvent *>(eventData)); default: LOGE("Unknown message type %" PRIu16 "received when handling event", eventType); @@ -73,6 +75,9 @@ void Manager::handleMessageFromHost(uint32_t senderInstanceId, } break; } + case chre_cross_validation_wifi_MessageType_SCAN_RESULT: + handleDataMessage(hostData); + break; default: LOGE("Unknown message type %" PRIu32 " for host message", hostData->messageType); @@ -101,17 +106,91 @@ void Manager::handleStepStartMessage( } break; case chre_cross_validation_wifi_Step_VALIDATE: + LOGE("start message received in VALIDATE phase"); break; } mStep = stepStartCommand.step; } +void Manager::handleDataMessage(const chreMessageFromHostData *hostData) { + pb_istream_t stream = + 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"); + } else { + mApDataCollectionDone = true; + if (mChreDataCollectionDone) { + compareAndSendResultToHost(); + } + } +} + +void Manager::handleWifiScanResult(const chreWifiScanEvent *event) { + if (event->resultTotal == 0) { + // TODO: Find out why this happens and how to deal with it. + LOGD("event->resultTotal was 0. Ignoring this event."); + } else { + for (uint8_t i = 0; i < event->resultCount; i++) { + mChreScanResults[mChreScanResultsI++] = WifiScanResult(event->results[i]); + } + mNumResultsProcessed += event->resultCount; + if (mNumResultsProcessed >= event->resultTotal) { + mChreDataCollectionDone = true; + if (mApDataCollectionDone) { + compareAndSendResultToHost(); + } + } + } +} + +void Manager::compareAndSendResultToHost() { + constexpr uint16_t kMaxSizeErrMsg = 1000; + char *errMsg = static_cast<char *>(chreHeapAlloc(kMaxSizeErrMsg)); + memset(errMsg, 0, kMaxSizeErrMsg); + chre_test_common_TestResult testResult; + if (errMsg == nullptr) { + LOG_OOM(); + } else { + bool success = true; + if (mApScanResultsI != mChreScanResultsI) { + 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; + } else { + for (uint8_t i = 0; i < mApScanResultsI; 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; + } + } + } + encodeAndSendMessageToHost(static_cast<const void *>(&testResult), + chre_test_common_TestResult_fields); + chreHeapFree(errMsg); + } +} + bool Manager::encodeErrorMessage(pb_ostream_t *stream, const pb_field_t * /*field*/, void *const *arg) { const char *str = static_cast<const char *>(const_cast<const void *>(*arg)); size_t len = strlen(str); - return pb_encode_string(stream, reinterpret_cast<const pb_byte_t *>(str), + return pb_encode_tag_for_field( + stream, &chre_test_common_TestResult_fields + [chre_test_common_TestResult_errorMessage_tag - 1]) && + pb_encode_string(stream, reinterpret_cast<const pb_byte_t *>(str), len); } 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 new file mode 100644 index 00000000..28dbe24d --- /dev/null +++ b/apps/test/common/chre_cross_validator_wifi/src/wifi_scan_result.cc @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2020 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 "wifi_scan_result.h" + +WifiScanResult::WifiScanResult( + const chre_cross_validation_wifi_WifiScanResult &apScanResult) {} + +WifiScanResult::WifiScanResult(const chreWifiScanResult &chreScanResult) {} + +bool WifiScanResult::areEqual(WifiScanResult result1, WifiScanResult result2) { + // TODO: Implement real comparison + return true; +} |