Files
hardware_interfaces/audio/common/all-versions/test/utility/src/ValidateXml.cpp

184 lines
6.6 KiB
C++
Raw Normal View History

/*
Audio HAL: Factorize V2 and V4 like libaudiohal Use the same technique developed for the simpler libaudiohal to factorize the audio HAL impl. Generated with script: set -euo pipefail cd hardware/interfaces/audio # Make 2.0 and 4.0 files mostly identical by removing all 2.0, V4.0... # and replacing it by CPP_VERSION and FILE_VERSION # This allow both implementation to be mostly identical, except for code difference # Also remove IncludeGuard.h as it will be included from compiler flag # Also update license to 2018 find -name *.cpp -o -name *h | grep -v -e service.cpp | xargs sed -Ei \ -e 's/(#.*)V[42]_0_(.*_H_?)$/\1\2/' \ -e 's/(LOG_TAG.*)[24]_0/\1/' \ -e '/#ifndef AUDIO_HAL_VERSION/,/#endif/d' \ -e '/^#.*def.*AUDIO_HAL_VERSION\b/d' \ -e's/V[42]_0/CPP_VERSION/' \ -e 's/(#include ).(android.*)[24].0(.*).$/\1PATH(\2FILE_VERSION\3)/' \ -e 's|(#include) .(.*)[24].0/(default/.*).$|\1 "\2\3"|' \ -e 's/\bAUDIO_HAL_VERSION\b/CPP_VERSION/' \ -e '/IncludeGuard.h/d' \ -e 's/(Copyright .C. 201)./\18/' # set MAJOR_VERSION instead of having a different macro for each version # this allow to do preprocessor arithmetic (eg: MAJOR_VERSION >= 4) for v in 2 4; do find -ipath '*/'$v'.0/*/Android.bp' | xargs sed -i -e '/cflags:/,/^$/d' -e '/vndk/{:a;/}/!{N;ba};d}' -e '$i\ cflags: [\ "-DMAJOR_VERSION='$v'",\ "-DMINOR_VERSION=0",\ "-include common/all-versions/VersionMacro.h",\ ]'; done # replace# ifdef VERSION_X by #if MAJOR_VERSION == X find -path *all-versions/*.h | xargs sed -Ei -e 's/def.*AUDIO_HAL_VERSION_([24])_0.*/ MAJOR_VERSION == \1/' \ -e 'T;s/ +/ /' # copy all-versions impl in each version impl find -path '*/[24].0/*.[hc]*' | grep -ve all-versions -e test | xargs -P99 -n4 sed -i -Ee '/include <.*all-versions.default/!b' \ -e 's#.*<#find -path */#' -e 's/>$/|xargs tail -n +16/' -e e # remove all-versions impl rm -r {core,effect}/all-versions/ # merge version impl into a single all-version for dir in core/*.0/vts/functional/*.0/ ;do dest=$(echo $dir | sed 's#/..0/#/all-versions/#') mkdir -p $dest mv -T $dir $dest done find -mindepth 3 -path '*/2.0/*' -a \( -name '*cpp' -o -name '*h' \) | grep -v 'all-versions' | sed -E 'h;s/2/4/g;H;s/4.0/all-versions/;s/4.0//;H;g;s/\n/ /g;'| xargs -P99 -L1 sh -c ' set -euo pipefail mkdir -p $(dirname $2); diff --old-group-format="#if MAJOR_VERSION == 2 %<#endif " \ --new-group-format="#if MAJOR_VERSION == 4 %>#endif " $0 $1 > $2 || true; rm $0 $1' # merge the X.0 Android.bp & OWNERS in the all-versions for dir in common effect core; do for sub in default vts/functional; do test -f $dir/2.0/$sub/Android.bp || continue awk 1 $dir/*.0/$sub/Android.bp >> $dir/all-versions/$sub/Android.bp # delete licenses except for the first one and add whitelines sed -i -e '/^}$/{N;/^}\n$/!s/\n/&\n/}' $dir/all-versions/$sub/Android.bp sed -i -e '1,17b;/^\/\//,/^$/{d}' $dir/all-versions/$sub/Android.bp done for sub in default vts; do test -d $dir/2.0/$sub || continue test -f $dir/2.0/$sub/OWNERS && awk 1 $dir/*.0/$sub/OWNERS | sort -u > $dir/all-versions/$sub/OWNERS || true rm -r $dir/*.0/$sub done done # delete all-versions-impl dependencies find -name 'Android.bp' | xargs sed -i -e '/all-versions-impl/d' # cleanup unused files rm common/all-versions/default/include/common/all-versions/default/HidlUtils* rm common/all-versions/util/include/common/all-versions/IncludeGuard.h find -depth -type d -empty -delete # Clamp consecutive number of empty lines to 2 find -name *.cpp -o -name *h | xargs sed -Ei ':a;/^\n*$/{N;ba};s/\n\n+/\n\n/' # transform #endif\n#if to #elif find -name *.cpp -o -name *h | xargs sed -i '/^#endif/{N;s/.*\n#if/#elif/}' # remove leftover include guard in cpp find -name *.cpp |xargs sed -Ei '/^#.*_H_?$/d' # apply clang-format find -name *cpp -o -name *h | xargs ../../../prebuilts/clang/host/linux-x86/clang-stable/bin/clang-format --style file -i # clang format breaks PATH(a/b) to PATH(a / b), remove the space surrounding / find -name *cpp -o -name *h | xargs sed -i "/#include PATH/s# / #/#g" Test: compile Bug: 118203066 Change-Id: I3692a444307afc5f71064fe0b9e6b8af3c9ff1dd Signed-off-by: Kevin Rocard <krocard@google.com>
2018-11-14 16:22:07 -08:00
* Copyright (C) 2018 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.
*/
#define LOG_TAG "ValidateAudioConfig"
#include <utils/Log.h>
Audio VTS: improve audio policy validation error messages If multiple config are found, each will be validated before failing the test. Also add a missing new line before dumping libxml2 errors. Test: run the following script to check for regressions and test that invalid config make the test fail. runTest() {( set -xu local readonly MODULE=$1 local readonly TEST=$2 local readonly XML=$3 runVTS() { vts-tradefed run commandAndExit vts \ --skip-all-system-status-check --primary-abi-only \ --skip-preconditions --module $MODULE -t $TEST | awk '/FAILED: 0/{e=1} {print} END {exit !e}'; } local FAIL=0 # used instead of return if clean up is needed echo "# Test valid config" runVTS || return 1 echo "# Test multiple invalid match" adb shell touch /system/etc/$XML runVTS && FAIL=2 adb shell rm /system/etc/$XML echo "# Test multiple valid match (not supported if xinclude)" if !adb shell grep -q xi:include /vendor/etc/$XML; then adb shell cp /{vendor,system}/etc/$XML runVTS || FAIL=3 adb shell rm /system/etc/$XML fi echo "# Test invalid config" adb shell sed -i "'2i<fuu/>'" /vendor/etc/$XML runVTS && FAIL=4 adb shell sed -i 2d /vendor/etc/$XML echo "#Test no config" adb shell mv /vendor/etc/$XML{,.hide} runVTS && FAIL=5 adb shell mv /vendor/etc/$XML{.hide,} echo "# Test that the test did not break the config" runVTS || FAIL=6 return $FAIL )} runTest VtsHalAudioV2_0Target CheckConfig.audioPolicyConfigurationValidation audio_policy_configuration.xml && runTest VtsHalAudioEffectV2_0Target CheckConfig.audioEffectsConfigurationValidation audio_effects.xml && echo TEST PASSED Bug: 64881365 Change-Id: If0443f85e0d687eed04819337519e4d9f09f5ca9 Signed-off-by: Kevin Rocard <krocard@google.com>
2017-08-21 18:32:49 -07:00
#include <numeric>
#define LIBXML_SCHEMAS_ENABLED
#include <libxml/xmlschemastypes.h>
#define LIBXML_XINCLUDE_ENABLED
#include <libxml/xinclude.h>
#include <memory>
#include <string>
#include "ValidateXml.h"
namespace android {
namespace hardware {
namespace audio {
namespace common {
namespace test {
namespace utility {
/** Map libxml2 structures to their corresponding deleters. */
template <class T>
constexpr void (*xmlDeleter)(T* t);
template <>
constexpr auto xmlDeleter<xmlSchema> = xmlSchemaFree;
template <>
constexpr auto xmlDeleter<xmlDoc> = xmlFreeDoc;
template <>
constexpr auto xmlDeleter<xmlSchemaParserCtxt> = xmlSchemaFreeParserCtxt;
template <>
constexpr auto xmlDeleter<xmlSchemaValidCtxt> = xmlSchemaFreeValidCtxt;
/** @return a unique_ptr with the correct deleter for the libxml2 object. */
template <class T>
constexpr auto make_xmlUnique(T* t) {
// Wrap deleter in lambda to enable empty base optimization
auto deleter = [](T* t) { xmlDeleter<T>(t); };
return std::unique_ptr<T, decltype(deleter)>{t, deleter};
}
/** Class that handles libxml2 initialization and cleanup. NOT THREAD SAFE*/
struct Libxml2Global {
Libxml2Global() {
xmlLineNumbersDefault(1); // Better error message
xmlSetGenericErrorFunc(this, errorCb);
}
~Libxml2Global() {
// TODO: check if all those cleanup are needed
xmlSetGenericErrorFunc(nullptr, nullptr);
xmlSchemaCleanupTypes();
xmlCleanupParser();
xmlCleanupThreads();
}
const std::string& getErrors() { return errors; }
private:
static void errorCb(void* ctxt, const char* msg, ...) {
auto* self = static_cast<Libxml2Global*>(ctxt);
va_list args;
va_start(args, msg);
char* formatedMsg;
if (vasprintf(&formatedMsg, msg, args) >= 0) {
LOG_PRI(ANDROID_LOG_ERROR, LOG_TAG, "%s", formatedMsg);
self->errors += "Error: ";
self->errors += formatedMsg;
}
free(formatedMsg);
va_end(args);
}
std::string errors;
};
::testing::AssertionResult validateXml(const char* xmlFilePathExpr, const char* xsdFilePathExpr,
const char* xmlFilePath, const char* xsdFilePath) {
Libxml2Global libxml2;
auto context = [&]() {
Audio VTS: improve audio policy validation error messages If multiple config are found, each will be validated before failing the test. Also add a missing new line before dumping libxml2 errors. Test: run the following script to check for regressions and test that invalid config make the test fail. runTest() {( set -xu local readonly MODULE=$1 local readonly TEST=$2 local readonly XML=$3 runVTS() { vts-tradefed run commandAndExit vts \ --skip-all-system-status-check --primary-abi-only \ --skip-preconditions --module $MODULE -t $TEST | awk '/FAILED: 0/{e=1} {print} END {exit !e}'; } local FAIL=0 # used instead of return if clean up is needed echo "# Test valid config" runVTS || return 1 echo "# Test multiple invalid match" adb shell touch /system/etc/$XML runVTS && FAIL=2 adb shell rm /system/etc/$XML echo "# Test multiple valid match (not supported if xinclude)" if !adb shell grep -q xi:include /vendor/etc/$XML; then adb shell cp /{vendor,system}/etc/$XML runVTS || FAIL=3 adb shell rm /system/etc/$XML fi echo "# Test invalid config" adb shell sed -i "'2i<fuu/>'" /vendor/etc/$XML runVTS && FAIL=4 adb shell sed -i 2d /vendor/etc/$XML echo "#Test no config" adb shell mv /vendor/etc/$XML{,.hide} runVTS && FAIL=5 adb shell mv /vendor/etc/$XML{.hide,} echo "# Test that the test did not break the config" runVTS || FAIL=6 return $FAIL )} runTest VtsHalAudioV2_0Target CheckConfig.audioPolicyConfigurationValidation audio_policy_configuration.xml && runTest VtsHalAudioEffectV2_0Target CheckConfig.audioEffectsConfigurationValidation audio_effects.xml && echo TEST PASSED Bug: 64881365 Change-Id: If0443f85e0d687eed04819337519e4d9f09f5ca9 Signed-off-by: Kevin Rocard <krocard@google.com>
2017-08-21 18:32:49 -07:00
return std::string() + " While validating: " + xmlFilePathExpr +
"\n Which is: " + xmlFilePath + "\nAgainst the schema: " + xsdFilePathExpr +
Audio VTS: improve audio policy validation error messages If multiple config are found, each will be validated before failing the test. Also add a missing new line before dumping libxml2 errors. Test: run the following script to check for regressions and test that invalid config make the test fail. runTest() {( set -xu local readonly MODULE=$1 local readonly TEST=$2 local readonly XML=$3 runVTS() { vts-tradefed run commandAndExit vts \ --skip-all-system-status-check --primary-abi-only \ --skip-preconditions --module $MODULE -t $TEST | awk '/FAILED: 0/{e=1} {print} END {exit !e}'; } local FAIL=0 # used instead of return if clean up is needed echo "# Test valid config" runVTS || return 1 echo "# Test multiple invalid match" adb shell touch /system/etc/$XML runVTS && FAIL=2 adb shell rm /system/etc/$XML echo "# Test multiple valid match (not supported if xinclude)" if !adb shell grep -q xi:include /vendor/etc/$XML; then adb shell cp /{vendor,system}/etc/$XML runVTS || FAIL=3 adb shell rm /system/etc/$XML fi echo "# Test invalid config" adb shell sed -i "'2i<fuu/>'" /vendor/etc/$XML runVTS && FAIL=4 adb shell sed -i 2d /vendor/etc/$XML echo "#Test no config" adb shell mv /vendor/etc/$XML{,.hide} runVTS && FAIL=5 adb shell mv /vendor/etc/$XML{.hide,} echo "# Test that the test did not break the config" runVTS || FAIL=6 return $FAIL )} runTest VtsHalAudioV2_0Target CheckConfig.audioPolicyConfigurationValidation audio_policy_configuration.xml && runTest VtsHalAudioEffectV2_0Target CheckConfig.audioEffectsConfigurationValidation audio_effects.xml && echo TEST PASSED Bug: 64881365 Change-Id: If0443f85e0d687eed04819337519e4d9f09f5ca9 Signed-off-by: Kevin Rocard <krocard@google.com>
2017-08-21 18:32:49 -07:00
"\n Which is: " + xsdFilePath + "\nLibxml2 errors:\n" + libxml2.getErrors();
};
auto schemaParserCtxt = make_xmlUnique(xmlSchemaNewParserCtxt(xsdFilePath));
auto schema = make_xmlUnique(xmlSchemaParse(schemaParserCtxt.get()));
if (schema == nullptr) {
return ::testing::AssertionFailure() << "Failed to parse schema (xsd)\n" << context();
}
auto doc = make_xmlUnique(xmlReadFile(xmlFilePath, nullptr, 0));
if (doc == nullptr) {
return ::testing::AssertionFailure() << "Failed to parse xml\n" << context();
}
// Process 'include' directives w/o modifying elements loaded from included files.
if (xmlXIncludeProcessFlags(doc.get(), XML_PARSE_NOBASEFIX) == -1) {
return ::testing::AssertionFailure() << "Failed to resolve xincludes in xml\n" << context();
}
auto schemaCtxt = make_xmlUnique(xmlSchemaNewValidCtxt(schema.get()));
int ret = xmlSchemaValidateDoc(schemaCtxt.get(), doc.get());
if (ret > 0) {
Audio VTS: improve audio policy validation error messages If multiple config are found, each will be validated before failing the test. Also add a missing new line before dumping libxml2 errors. Test: run the following script to check for regressions and test that invalid config make the test fail. runTest() {( set -xu local readonly MODULE=$1 local readonly TEST=$2 local readonly XML=$3 runVTS() { vts-tradefed run commandAndExit vts \ --skip-all-system-status-check --primary-abi-only \ --skip-preconditions --module $MODULE -t $TEST | awk '/FAILED: 0/{e=1} {print} END {exit !e}'; } local FAIL=0 # used instead of return if clean up is needed echo "# Test valid config" runVTS || return 1 echo "# Test multiple invalid match" adb shell touch /system/etc/$XML runVTS && FAIL=2 adb shell rm /system/etc/$XML echo "# Test multiple valid match (not supported if xinclude)" if !adb shell grep -q xi:include /vendor/etc/$XML; then adb shell cp /{vendor,system}/etc/$XML runVTS || FAIL=3 adb shell rm /system/etc/$XML fi echo "# Test invalid config" adb shell sed -i "'2i<fuu/>'" /vendor/etc/$XML runVTS && FAIL=4 adb shell sed -i 2d /vendor/etc/$XML echo "#Test no config" adb shell mv /vendor/etc/$XML{,.hide} runVTS && FAIL=5 adb shell mv /vendor/etc/$XML{.hide,} echo "# Test that the test did not break the config" runVTS || FAIL=6 return $FAIL )} runTest VtsHalAudioV2_0Target CheckConfig.audioPolicyConfigurationValidation audio_policy_configuration.xml && runTest VtsHalAudioEffectV2_0Target CheckConfig.audioEffectsConfigurationValidation audio_effects.xml && echo TEST PASSED Bug: 64881365 Change-Id: If0443f85e0d687eed04819337519e4d9f09f5ca9 Signed-off-by: Kevin Rocard <krocard@google.com>
2017-08-21 18:32:49 -07:00
return ::testing::AssertionFailure() << "XML is not valid according to the xsd\n"
<< context();
}
if (ret < 0) {
return ::testing::AssertionFailure() << "Internal or API error\n" << context();
}
return ::testing::AssertionSuccess();
}
VTS: Do not require XML for Audio effect V2 In O, the Audio effect V2 HAL allows not to have an audio effect XML configuration but to use a .conf format. In P, before this patch, the Audio effect V2 HAL _requires_ to have an audio effect XML configuration and forbids the use of a .conf format. This is discouraged by Treble as it means that an unchanged HAL V2 implementation that was compatible with O VTS will not be with P VTS. As a result, revert to the Oreo behavior for Audio Effect V2 VTS. Note that the audio effect V4 VTS is not changed by this patch and still requires an audio effect XML configuration. Aka device _updating_ to P will not have to upgrade to XML but new devices lunching on P are still required to have an audio effect XML configuration. This commit only changes VTS code. Test: cd hardware/interfaces/audio/effect/ mmm 2.0/vts/functional 4.0/vts/functional && adb sync data adb push *.0/xml/audio_effects_conf_V*.xsd /data/local/tmp/ adb shell cd /data/nativetest64 OPS=--gtest_filter=CheckConfig.audioEffectsConfigurationValidation VtsHalAudioEffectV2_0TargetTest/VtsHalAudioEffectV2_0TargetTest $OPS VtsHalAudioEffectV4_0TargetTest/VtsHalAudioEffectV4_0TargetTest $OPS rm /{odm,vendor,system}/etc/audio_effects.xml || true VtsHalAudioEffectV2_0TargetTest/VtsHalAudioEffectV2_0TargetTest $OPS ! VtsHalAudioEffectV4_0TargetTest/VtsHalAudioEffectV4_0TargetTest $OPS Bug: 111421676 Change-Id: Ifb15d65ae4aa65759c8ebaa91cbc8c02234030dc Signed-off-by: Kevin Rocard <krocard@google.com>
2018-07-19 13:31:47 -07:00
template <bool atLeastOneRequired>
Audio VTS: improve audio policy validation error messages If multiple config are found, each will be validated before failing the test. Also add a missing new line before dumping libxml2 errors. Test: run the following script to check for regressions and test that invalid config make the test fail. runTest() {( set -xu local readonly MODULE=$1 local readonly TEST=$2 local readonly XML=$3 runVTS() { vts-tradefed run commandAndExit vts \ --skip-all-system-status-check --primary-abi-only \ --skip-preconditions --module $MODULE -t $TEST | awk '/FAILED: 0/{e=1} {print} END {exit !e}'; } local FAIL=0 # used instead of return if clean up is needed echo "# Test valid config" runVTS || return 1 echo "# Test multiple invalid match" adb shell touch /system/etc/$XML runVTS && FAIL=2 adb shell rm /system/etc/$XML echo "# Test multiple valid match (not supported if xinclude)" if !adb shell grep -q xi:include /vendor/etc/$XML; then adb shell cp /{vendor,system}/etc/$XML runVTS || FAIL=3 adb shell rm /system/etc/$XML fi echo "# Test invalid config" adb shell sed -i "'2i<fuu/>'" /vendor/etc/$XML runVTS && FAIL=4 adb shell sed -i 2d /vendor/etc/$XML echo "#Test no config" adb shell mv /vendor/etc/$XML{,.hide} runVTS && FAIL=5 adb shell mv /vendor/etc/$XML{.hide,} echo "# Test that the test did not break the config" runVTS || FAIL=6 return $FAIL )} runTest VtsHalAudioV2_0Target CheckConfig.audioPolicyConfigurationValidation audio_policy_configuration.xml && runTest VtsHalAudioEffectV2_0Target CheckConfig.audioEffectsConfigurationValidation audio_effects.xml && echo TEST PASSED Bug: 64881365 Change-Id: If0443f85e0d687eed04819337519e4d9f09f5ca9 Signed-off-by: Kevin Rocard <krocard@google.com>
2017-08-21 18:32:49 -07:00
::testing::AssertionResult validateXmlMultipleLocations(
const char* xmlFileNameExpr, const char* xmlFileLocationsExpr, const char* xsdFilePathExpr,
const char* xmlFileName, const std::vector<std::string>& xmlFileLocations,
const char* xsdFilePath) {
Audio VTS: improve audio policy validation error messages If multiple config are found, each will be validated before failing the test. Also add a missing new line before dumping libxml2 errors. Test: run the following script to check for regressions and test that invalid config make the test fail. runTest() {( set -xu local readonly MODULE=$1 local readonly TEST=$2 local readonly XML=$3 runVTS() { vts-tradefed run commandAndExit vts \ --skip-all-system-status-check --primary-abi-only \ --skip-preconditions --module $MODULE -t $TEST | awk '/FAILED: 0/{e=1} {print} END {exit !e}'; } local FAIL=0 # used instead of return if clean up is needed echo "# Test valid config" runVTS || return 1 echo "# Test multiple invalid match" adb shell touch /system/etc/$XML runVTS && FAIL=2 adb shell rm /system/etc/$XML echo "# Test multiple valid match (not supported if xinclude)" if !adb shell grep -q xi:include /vendor/etc/$XML; then adb shell cp /{vendor,system}/etc/$XML runVTS || FAIL=3 adb shell rm /system/etc/$XML fi echo "# Test invalid config" adb shell sed -i "'2i<fuu/>'" /vendor/etc/$XML runVTS && FAIL=4 adb shell sed -i 2d /vendor/etc/$XML echo "#Test no config" adb shell mv /vendor/etc/$XML{,.hide} runVTS && FAIL=5 adb shell mv /vendor/etc/$XML{.hide,} echo "# Test that the test did not break the config" runVTS || FAIL=6 return $FAIL )} runTest VtsHalAudioV2_0Target CheckConfig.audioPolicyConfigurationValidation audio_policy_configuration.xml && runTest VtsHalAudioEffectV2_0Target CheckConfig.audioEffectsConfigurationValidation audio_effects.xml && echo TEST PASSED Bug: 64881365 Change-Id: If0443f85e0d687eed04819337519e4d9f09f5ca9 Signed-off-by: Kevin Rocard <krocard@google.com>
2017-08-21 18:32:49 -07:00
using namespace std::string_literals;
std::vector<std::string> errors;
std::vector<std::string> foundFiles;
for (const auto& location : xmlFileLocations) {
Audio VTS: improve audio policy validation error messages If multiple config are found, each will be validated before failing the test. Also add a missing new line before dumping libxml2 errors. Test: run the following script to check for regressions and test that invalid config make the test fail. runTest() {( set -xu local readonly MODULE=$1 local readonly TEST=$2 local readonly XML=$3 runVTS() { vts-tradefed run commandAndExit vts \ --skip-all-system-status-check --primary-abi-only \ --skip-preconditions --module $MODULE -t $TEST | awk '/FAILED: 0/{e=1} {print} END {exit !e}'; } local FAIL=0 # used instead of return if clean up is needed echo "# Test valid config" runVTS || return 1 echo "# Test multiple invalid match" adb shell touch /system/etc/$XML runVTS && FAIL=2 adb shell rm /system/etc/$XML echo "# Test multiple valid match (not supported if xinclude)" if !adb shell grep -q xi:include /vendor/etc/$XML; then adb shell cp /{vendor,system}/etc/$XML runVTS || FAIL=3 adb shell rm /system/etc/$XML fi echo "# Test invalid config" adb shell sed -i "'2i<fuu/>'" /vendor/etc/$XML runVTS && FAIL=4 adb shell sed -i 2d /vendor/etc/$XML echo "#Test no config" adb shell mv /vendor/etc/$XML{,.hide} runVTS && FAIL=5 adb shell mv /vendor/etc/$XML{.hide,} echo "# Test that the test did not break the config" runVTS || FAIL=6 return $FAIL )} runTest VtsHalAudioV2_0Target CheckConfig.audioPolicyConfigurationValidation audio_policy_configuration.xml && runTest VtsHalAudioEffectV2_0Target CheckConfig.audioEffectsConfigurationValidation audio_effects.xml && echo TEST PASSED Bug: 64881365 Change-Id: If0443f85e0d687eed04819337519e4d9f09f5ca9 Signed-off-by: Kevin Rocard <krocard@google.com>
2017-08-21 18:32:49 -07:00
std::string xmlFilePath = location + "/"s + xmlFileName;
if (access(xmlFilePath.c_str(), F_OK) != 0) {
// If the file does not exist ignore this location and fallback on the next one
continue;
}
foundFiles.push_back(" " + xmlFilePath + '\n');
auto result = validateXml("xmlFilePath", xsdFilePathExpr, xmlFilePath.c_str(), xsdFilePath);
if (!result) {
errors.push_back(result.message());
}
}
VTS: Do not require XML for Audio effect V2 In O, the Audio effect V2 HAL allows not to have an audio effect XML configuration but to use a .conf format. In P, before this patch, the Audio effect V2 HAL _requires_ to have an audio effect XML configuration and forbids the use of a .conf format. This is discouraged by Treble as it means that an unchanged HAL V2 implementation that was compatible with O VTS will not be with P VTS. As a result, revert to the Oreo behavior for Audio Effect V2 VTS. Note that the audio effect V4 VTS is not changed by this patch and still requires an audio effect XML configuration. Aka device _updating_ to P will not have to upgrade to XML but new devices lunching on P are still required to have an audio effect XML configuration. This commit only changes VTS code. Test: cd hardware/interfaces/audio/effect/ mmm 2.0/vts/functional 4.0/vts/functional && adb sync data adb push *.0/xml/audio_effects_conf_V*.xsd /data/local/tmp/ adb shell cd /data/nativetest64 OPS=--gtest_filter=CheckConfig.audioEffectsConfigurationValidation VtsHalAudioEffectV2_0TargetTest/VtsHalAudioEffectV2_0TargetTest $OPS VtsHalAudioEffectV4_0TargetTest/VtsHalAudioEffectV4_0TargetTest $OPS rm /{odm,vendor,system}/etc/audio_effects.xml || true VtsHalAudioEffectV2_0TargetTest/VtsHalAudioEffectV2_0TargetTest $OPS ! VtsHalAudioEffectV4_0TargetTest/VtsHalAudioEffectV4_0TargetTest $OPS Bug: 111421676 Change-Id: Ifb15d65ae4aa65759c8ebaa91cbc8c02234030dc Signed-off-by: Kevin Rocard <krocard@google.com>
2018-07-19 13:31:47 -07:00
if (atLeastOneRequired && foundFiles.empty()) {
Audio VTS: improve audio policy validation error messages If multiple config are found, each will be validated before failing the test. Also add a missing new line before dumping libxml2 errors. Test: run the following script to check for regressions and test that invalid config make the test fail. runTest() {( set -xu local readonly MODULE=$1 local readonly TEST=$2 local readonly XML=$3 runVTS() { vts-tradefed run commandAndExit vts \ --skip-all-system-status-check --primary-abi-only \ --skip-preconditions --module $MODULE -t $TEST | awk '/FAILED: 0/{e=1} {print} END {exit !e}'; } local FAIL=0 # used instead of return if clean up is needed echo "# Test valid config" runVTS || return 1 echo "# Test multiple invalid match" adb shell touch /system/etc/$XML runVTS && FAIL=2 adb shell rm /system/etc/$XML echo "# Test multiple valid match (not supported if xinclude)" if !adb shell grep -q xi:include /vendor/etc/$XML; then adb shell cp /{vendor,system}/etc/$XML runVTS || FAIL=3 adb shell rm /system/etc/$XML fi echo "# Test invalid config" adb shell sed -i "'2i<fuu/>'" /vendor/etc/$XML runVTS && FAIL=4 adb shell sed -i 2d /vendor/etc/$XML echo "#Test no config" adb shell mv /vendor/etc/$XML{,.hide} runVTS && FAIL=5 adb shell mv /vendor/etc/$XML{.hide,} echo "# Test that the test did not break the config" runVTS || FAIL=6 return $FAIL )} runTest VtsHalAudioV2_0Target CheckConfig.audioPolicyConfigurationValidation audio_policy_configuration.xml && runTest VtsHalAudioEffectV2_0Target CheckConfig.audioEffectsConfigurationValidation audio_effects.xml && echo TEST PASSED Bug: 64881365 Change-Id: If0443f85e0d687eed04819337519e4d9f09f5ca9 Signed-off-by: Kevin Rocard <krocard@google.com>
2017-08-21 18:32:49 -07:00
errors.push_back("No xml file found in provided locations.\n");
}
return ::testing::AssertionResult(errors.empty())
<< errors.size() << " error" << (errors.size() == 1 ? " " : "s ")
<< std::accumulate(begin(errors), end(errors), "occurred during xml validation:\n"s)
<< " While validating all: " << xmlFileNameExpr
<< "\n Which is: " << xmlFileName
<< "\n In the following folders: " << xmlFileLocationsExpr
VTS: Do not require XML for Audio effect V2 In O, the Audio effect V2 HAL allows not to have an audio effect XML configuration but to use a .conf format. In P, before this patch, the Audio effect V2 HAL _requires_ to have an audio effect XML configuration and forbids the use of a .conf format. This is discouraged by Treble as it means that an unchanged HAL V2 implementation that was compatible with O VTS will not be with P VTS. As a result, revert to the Oreo behavior for Audio Effect V2 VTS. Note that the audio effect V4 VTS is not changed by this patch and still requires an audio effect XML configuration. Aka device _updating_ to P will not have to upgrade to XML but new devices lunching on P are still required to have an audio effect XML configuration. This commit only changes VTS code. Test: cd hardware/interfaces/audio/effect/ mmm 2.0/vts/functional 4.0/vts/functional && adb sync data adb push *.0/xml/audio_effects_conf_V*.xsd /data/local/tmp/ adb shell cd /data/nativetest64 OPS=--gtest_filter=CheckConfig.audioEffectsConfigurationValidation VtsHalAudioEffectV2_0TargetTest/VtsHalAudioEffectV2_0TargetTest $OPS VtsHalAudioEffectV4_0TargetTest/VtsHalAudioEffectV4_0TargetTest $OPS rm /{odm,vendor,system}/etc/audio_effects.xml || true VtsHalAudioEffectV2_0TargetTest/VtsHalAudioEffectV2_0TargetTest $OPS ! VtsHalAudioEffectV4_0TargetTest/VtsHalAudioEffectV4_0TargetTest $OPS Bug: 111421676 Change-Id: Ifb15d65ae4aa65759c8ebaa91cbc8c02234030dc Signed-off-by: Kevin Rocard <krocard@google.com>
2018-07-19 13:31:47 -07:00
<< "\n Which is: " << ::testing::PrintToString(xmlFileLocations)
<< (atLeastOneRequired ? "\nWhere at least one file must be found."
: "\nWhere no file might exist.");
Audio VTS: improve audio policy validation error messages If multiple config are found, each will be validated before failing the test. Also add a missing new line before dumping libxml2 errors. Test: run the following script to check for regressions and test that invalid config make the test fail. runTest() {( set -xu local readonly MODULE=$1 local readonly TEST=$2 local readonly XML=$3 runVTS() { vts-tradefed run commandAndExit vts \ --skip-all-system-status-check --primary-abi-only \ --skip-preconditions --module $MODULE -t $TEST | awk '/FAILED: 0/{e=1} {print} END {exit !e}'; } local FAIL=0 # used instead of return if clean up is needed echo "# Test valid config" runVTS || return 1 echo "# Test multiple invalid match" adb shell touch /system/etc/$XML runVTS && FAIL=2 adb shell rm /system/etc/$XML echo "# Test multiple valid match (not supported if xinclude)" if !adb shell grep -q xi:include /vendor/etc/$XML; then adb shell cp /{vendor,system}/etc/$XML runVTS || FAIL=3 adb shell rm /system/etc/$XML fi echo "# Test invalid config" adb shell sed -i "'2i<fuu/>'" /vendor/etc/$XML runVTS && FAIL=4 adb shell sed -i 2d /vendor/etc/$XML echo "#Test no config" adb shell mv /vendor/etc/$XML{,.hide} runVTS && FAIL=5 adb shell mv /vendor/etc/$XML{.hide,} echo "# Test that the test did not break the config" runVTS || FAIL=6 return $FAIL )} runTest VtsHalAudioV2_0Target CheckConfig.audioPolicyConfigurationValidation audio_policy_configuration.xml && runTest VtsHalAudioEffectV2_0Target CheckConfig.audioEffectsConfigurationValidation audio_effects.xml && echo TEST PASSED Bug: 64881365 Change-Id: If0443f85e0d687eed04819337519e4d9f09f5ca9 Signed-off-by: Kevin Rocard <krocard@google.com>
2017-08-21 18:32:49 -07:00
}
template ::testing::AssertionResult validateXmlMultipleLocations<true>(
const char*, const char*, const char*, const char*, const std::vector<std::string>&,
const char*);
template ::testing::AssertionResult validateXmlMultipleLocations<false>(
const char*, const char*, const char*, const char*, const std::vector<std::string>&,
const char*);
VTS: Do not require XML for Audio effect V2 In O, the Audio effect V2 HAL allows not to have an audio effect XML configuration but to use a .conf format. In P, before this patch, the Audio effect V2 HAL _requires_ to have an audio effect XML configuration and forbids the use of a .conf format. This is discouraged by Treble as it means that an unchanged HAL V2 implementation that was compatible with O VTS will not be with P VTS. As a result, revert to the Oreo behavior for Audio Effect V2 VTS. Note that the audio effect V4 VTS is not changed by this patch and still requires an audio effect XML configuration. Aka device _updating_ to P will not have to upgrade to XML but new devices lunching on P are still required to have an audio effect XML configuration. This commit only changes VTS code. Test: cd hardware/interfaces/audio/effect/ mmm 2.0/vts/functional 4.0/vts/functional && adb sync data adb push *.0/xml/audio_effects_conf_V*.xsd /data/local/tmp/ adb shell cd /data/nativetest64 OPS=--gtest_filter=CheckConfig.audioEffectsConfigurationValidation VtsHalAudioEffectV2_0TargetTest/VtsHalAudioEffectV2_0TargetTest $OPS VtsHalAudioEffectV4_0TargetTest/VtsHalAudioEffectV4_0TargetTest $OPS rm /{odm,vendor,system}/etc/audio_effects.xml || true VtsHalAudioEffectV2_0TargetTest/VtsHalAudioEffectV2_0TargetTest $OPS ! VtsHalAudioEffectV4_0TargetTest/VtsHalAudioEffectV4_0TargetTest $OPS Bug: 111421676 Change-Id: Ifb15d65ae4aa65759c8ebaa91cbc8c02234030dc Signed-off-by: Kevin Rocard <krocard@google.com>
2018-07-19 13:31:47 -07:00
} // namespace utility
} // namespace test
} // namespace common
} // namespace audio
} // namespace hardware
} // namespace android