summaryrefslogtreecommitdiffstats
path: root/test/test-subsystem
diff options
context:
space:
mode:
authorAdrien M <adrienx.martin@intel.com>2015-03-10 15:21:30 +0100
committerEric Laurent <elaurent@google.com>2015-04-24 13:39:12 -0700
commitec5130b950992fe79400ba66336d19169772a530 (patch)
tree0ddf66f1d680bf4be582b949d2596b7f08c8b74a /test/test-subsystem
parent5aaddd16f2aabccf07687f1761567eb6455abe61 (diff)
downloadexternal_parameter-framework-ec5130b950992fe79400ba66336d19169772a530.zip
external_parameter-framework-ec5130b950992fe79400ba66336d19169772a530.tar.gz
external_parameter-framework-ec5130b950992fe79400ba66336d19169772a530.tar.bz2
Add functionnal tests to the pfw.
This patch adds functionnal test to the PFW. The execution of these tests needs the test-subsystem to be compiled. The tests can be launch with 'make test'. We set the environment vars in the cmake. Then we launch ACTCampaignEngine.py. Temporary files like build time conf files are placed on the build directory. Next steps : - Test-subsystem needs to be reworked (with binding python). Signed-off-by: Adrien M <adrienx.martin@intel.com>
Diffstat (limited to 'test/test-subsystem')
-rw-r--r--test/test-subsystem/CMakeLists.txt44
-rw-r--r--test/test-subsystem/TESTMappingKeys.h36
-rw-r--r--test/test-subsystem/TESTSubsystem.cpp112
-rw-r--r--test/test-subsystem/TESTSubsystem.h49
-rw-r--r--test/test-subsystem/TESTSubsystemBinary.cpp64
-rw-r--r--test/test-subsystem/TESTSubsystemBinary.h45
-rw-r--r--test/test-subsystem/TESTSubsystemBuilder.cpp42
-rw-r--r--test/test-subsystem/TESTSubsystemObject.cpp150
-rw-r--r--test/test-subsystem/TESTSubsystemObject.h59
-rw-r--r--test/test-subsystem/TESTSubsystemString.cpp50
-rw-r--r--test/test-subsystem/TESTSubsystemString.h45
11 files changed, 696 insertions, 0 deletions
diff --git a/test/test-subsystem/CMakeLists.txt b/test/test-subsystem/CMakeLists.txt
new file mode 100644
index 0000000..52e66b0
--- /dev/null
+++ b/test/test-subsystem/CMakeLists.txt
@@ -0,0 +1,44 @@
+# Copyright (c) 2015, Intel Corporation
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification,
+# are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation and/or
+# other materials provided with the distribution.
+#
+# 3. Neither the name of the copyright holder nor the names of its contributors
+# may be used to endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+if (BUILD_TESTING)
+
+ add_library(test-subsystem SHARED
+ TESTSubsystem.cpp
+ TESTSubsystemBinary.cpp
+ TESTSubsystemObject.cpp
+ TESTSubsystemString.cpp
+ TESTSubsystemBuilder.cpp)
+
+ include_directories(
+ "${PROJECT_SOURCE_DIR}/xmlserializer"
+ "${PROJECT_SOURCE_DIR}/remote-processor"
+ "${PROJECT_SOURCE_DIR}/parameter")
+
+ target_link_libraries(test-subsystem parameter)
+endif()
diff --git a/test/test-subsystem/TESTMappingKeys.h b/test/test-subsystem/TESTMappingKeys.h
new file mode 100644
index 0000000..90eb869
--- /dev/null
+++ b/test/test-subsystem/TESTMappingKeys.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2015, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#pragma once
+
+// Mapping item types
+enum TESTItemType {
+ ETESTDirectory,
+ ETESTLog
+};
diff --git a/test/test-subsystem/TESTSubsystem.cpp b/test/test-subsystem/TESTSubsystem.cpp
new file mode 100644
index 0000000..214fbb7
--- /dev/null
+++ b/test/test-subsystem/TESTSubsystem.cpp
@@ -0,0 +1,112 @@
+/*
+* Copyright (c) 2011-2015, Intel Corporation
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software without
+* specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+#include <fstream>
+#include <assert.h>
+#include "TESTSubsystem.h"
+#include "TESTSubsystemBinary.h"
+#include "TESTSubsystemString.h"
+#include "TESTMappingKeys.h"
+#include "SubsystemObjectFactory.h"
+#include <stdlib.h>
+#include <stdio.h>
+
+#define base CSubsystem
+
+// Directory for isAlive and NeedResync files
+const char* gacFwNamePropName = getenv("PFW_RESULT");
+
+// Implementation
+CTESTSubsystem::CTESTSubsystem(const std::string& strName) : base(strName)
+{
+ // Provide mapping keys to upper layer
+ addContextMappingKey("Directory");
+ addContextMappingKey("Log");
+
+ // Provide creators to upper layer
+ addSubsystemObjectFactory(new TSubsystemObjectFactory<CTESTSubsystemBinary>("Binary", 1 << ETESTDirectory));
+ addSubsystemObjectFactory(new TSubsystemObjectFactory<CTESTSubsystemString>("String", 1 << ETESTDirectory));
+}
+
+// Susbsystem sanity health
+bool CTESTSubsystem::isAlive() const
+{
+ assert(gacFwNamePropName != NULL);
+ return read(std::string(gacFwNamePropName) + "/isAlive") == "true";
+}
+
+// Resynchronization after subsystem restart needed
+bool CTESTSubsystem::needResync(bool bClear)
+{
+ assert(gacFwNamePropName != NULL);
+ std::string strNeedResyncFile = std::string(gacFwNamePropName) + "/needResync";
+ bool bNeedResync;
+
+ bNeedResync = read(strNeedResyncFile) == "true";
+
+ if (!bNeedResync) {
+
+ // subsystem does not need resync
+ return false;
+ } else {
+ // subsystem needs resync
+ // If indicated, clear need resync state
+ if (bClear) {
+
+ write(strNeedResyncFile, "false");
+ }
+
+ return true;
+ }
+}
+
+// Read boolean from file
+std::string CTESTSubsystem::read(const std::string& strFileName)
+{
+ std::ifstream file;
+ std::string strContent;
+
+ file.open(strFileName.c_str());
+
+ file >> strContent;
+
+ return strContent;
+}
+
+// Write boolean to file
+void CTESTSubsystem::write(const std::string& strFileName, const std::string& strContent)
+{
+ std::ofstream file;
+
+ file.open(strFileName.c_str());
+
+ assert(file.is_open());
+
+ file << strContent;
+}
diff --git a/test/test-subsystem/TESTSubsystem.h b/test/test-subsystem/TESTSubsystem.h
new file mode 100644
index 0000000..bcd0fbd
--- /dev/null
+++ b/test/test-subsystem/TESTSubsystem.h
@@ -0,0 +1,49 @@
+/*
+* Copyright (c) 2011-2015, Intel Corporation
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software without
+* specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+#pragma once
+
+#include "Subsystem.h"
+
+class CTESTSubsystem : public CSubsystem
+{
+public:
+ CTESTSubsystem(const std::string& strName);
+
+ // Susbsystem sanity
+ virtual bool isAlive() const;
+ // Resynchronization after subsystem restart needed
+ virtual bool needResync(bool bClear);
+
+private:
+ // Read boolean from file
+ static std::string read(const std::string& strFileName);
+ // Write boolean to file
+ static void write(const std::string& strFileName, const std::string& strContent);
+};
diff --git a/test/test-subsystem/TESTSubsystemBinary.cpp b/test/test-subsystem/TESTSubsystemBinary.cpp
new file mode 100644
index 0000000..540fde8
--- /dev/null
+++ b/test/test-subsystem/TESTSubsystemBinary.cpp
@@ -0,0 +1,64 @@
+/*
+* Copyright (c) 2011-2015, Intel Corporation
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software without
+* specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+#include <string.h>
+#include <sstream>
+#include <stdlib.h>
+#include <assert.h>
+#include "TESTSubsystemBinary.h"
+
+#define base CTESTSubsystemObject
+
+CTESTSubsystemBinary::CTESTSubsystemBinary(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context)
+ : base(strMappingValue, pInstanceConfigurableElement, context)
+{
+}
+
+std::string CTESTSubsystemBinary::toString(const void* pvValue, uint32_t uiSize) const
+{
+ std::ostringstream strStream;
+ uint32_t uiValue = 0;
+
+ assert(uiSize <= sizeof(uiValue));
+
+ memcpy((void*)&uiValue, pvValue, uiSize);
+
+ strStream << "0x" << std::hex << uiValue;
+
+ return strStream.str();
+}
+
+void CTESTSubsystemBinary::fromString(const std::string& strValue, void* pvValue, uint32_t uiSize)
+{
+ uint32_t uiValue = strtoul(strValue.c_str(), NULL, 0);
+
+ assert(uiSize <= sizeof(uiValue));
+
+ memcpy(pvValue, (const void*)&uiValue, uiSize);
+}
diff --git a/test/test-subsystem/TESTSubsystemBinary.h b/test/test-subsystem/TESTSubsystemBinary.h
new file mode 100644
index 0000000..a8d433e
--- /dev/null
+++ b/test/test-subsystem/TESTSubsystemBinary.h
@@ -0,0 +1,45 @@
+/*
+* Copyright (c) 2011-2015, Intel Corporation
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software without
+* specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+#pragma once
+
+#include "TESTSubsystemObject.h"
+
+class CTESTSubsystemBinary : public CTESTSubsystemObject
+{
+public:
+ CTESTSubsystemBinary(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context);
+
+private:
+ // from CTESTSubsystemObject
+ // Format Data
+ virtual std::string toString(const void* pvValue, uint32_t uiSize) const;
+ virtual void fromString(const std::string& strValue, void* pvValue, uint32_t uiSize);
+
+};
diff --git a/test/test-subsystem/TESTSubsystemBuilder.cpp b/test/test-subsystem/TESTSubsystemBuilder.cpp
new file mode 100644
index 0000000..bcf2afc
--- /dev/null
+++ b/test/test-subsystem/TESTSubsystemBuilder.cpp
@@ -0,0 +1,42 @@
+/*
+* Copyright (c) 2011-2015, Intel Corporation
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software without
+* specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+#include "SubsystemLibrary.h"
+#include "NamedElementBuilderTemplate.h"
+#include "TESTSubsystem.h"
+
+
+extern "C"
+{
+void getTESTSubsystemBuilder(CSubsystemLibrary* pSubsystemLibrary)
+{
+ pSubsystemLibrary->addElementBuilder("TEST",
+ new TNamedElementBuilderTemplate<CTESTSubsystem>());
+}
+}
diff --git a/test/test-subsystem/TESTSubsystemObject.cpp b/test/test-subsystem/TESTSubsystemObject.cpp
new file mode 100644
index 0000000..706053f
--- /dev/null
+++ b/test/test-subsystem/TESTSubsystemObject.cpp
@@ -0,0 +1,150 @@
+/*
+* Copyright (c) 2011-2015, Intel Corporation
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software without
+* specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+#include <fstream>
+#include <alloca.h>
+#include "ParameterType.h"
+#include "MappingContext.h"
+#include "TESTMappingKeys.h"
+#include "InstanceConfigurableElement.h"
+#include "TESTSubsystemObject.h"
+
+#define base CSubsystemObject
+
+CTESTSubsystemObject::CTESTSubsystemObject(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context)
+ : base(pInstanceConfigurableElement)
+{
+ (void)strMappingValue;
+ // Get actual element type
+ const CParameterType* pParameterType = static_cast<const CParameterType*>(pInstanceConfigurableElement->getTypeElement());
+
+ _uiScalarSize = pParameterType->getSize();
+ _uiArraySize = pInstanceConfigurableElement->getFootPrint() / _uiScalarSize;
+ _bIsScalar = pParameterType->isScalar();
+
+ _strFilePath = context.getItem(ETESTDirectory) + "/" + pInstanceConfigurableElement->getName();
+ _bLog = context.iSet(ETESTLog) && (context.getItem(ETESTLog) == "yes");
+}
+
+bool CTESTSubsystemObject::sendToHW(std::string& strError)
+{
+ std::ofstream outputFile;
+
+ outputFile.open(_strFilePath.c_str());
+
+ if (!outputFile.is_open()) {
+
+ strError = "Unable to open file: " + _strFilePath;
+
+ return false;
+ }
+
+ sendToFile(outputFile);
+
+ outputFile.close();
+
+ return true;
+}
+
+
+bool CTESTSubsystemObject::receiveFromHW(std::string& strError)
+{
+ (void)strError;
+ std::ifstream inputFile;
+
+ inputFile.open(_strFilePath.c_str());
+
+ if (!inputFile.is_open()) {
+
+ return true;
+ }
+
+ receiveFromFile(inputFile);
+
+ inputFile.close();
+ return true;
+}
+
+void CTESTSubsystemObject::sendToFile(std::ofstream& outputFile)
+{
+ uint32_t uiIndex;
+
+ for (uiIndex = 0 ; uiIndex < _uiArraySize ; uiIndex++) {
+
+ void* pvValue = alloca(_uiScalarSize);
+
+ // Read Value in BlackBoard
+ blackboardRead(pvValue, _uiScalarSize);
+
+ std::string strValue = toString(pvValue, _uiScalarSize);
+
+ outputFile << strValue << std::endl;
+
+ if (_bLog) {
+
+ if (_bIsScalar) {
+
+ log_info("TESTSUBSYSTEM: Writing \"%s\" to file %s", strValue.c_str(), _strFilePath.c_str());
+ } else {
+
+ log_info("TESTSUBSYSTEM: Writing \"%s\" to file %s[%d]", strValue.c_str(), _strFilePath.c_str(), uiIndex);
+ }
+ }
+ }
+}
+
+void CTESTSubsystemObject::receiveFromFile(std::ifstream& inputFile)
+{
+ uint32_t uiIndex;
+
+ for (uiIndex = 0 ; uiIndex < _uiArraySize ; uiIndex++) {
+
+ void* pvValue = alloca(_uiScalarSize);
+
+ std::string strValue;
+
+ inputFile >> strValue;
+
+ if (_bLog) {
+
+ if (_bIsScalar) {
+
+ log_info("TESTSUBSYSTEM: Writing \"%s\" from file %s", strValue.c_str(), _strFilePath.c_str());
+ } else {
+
+ log_info("TESTSUBSYSTEM: Writing \"%s\" from file %s[%d]", strValue.c_str(), _strFilePath.c_str(), uiIndex);
+ }
+ }
+
+ fromString(strValue, pvValue, _uiScalarSize);
+
+ // Write Value in Blackboard
+ blackboardWrite(pvValue, _uiScalarSize);
+ }
+}
diff --git a/test/test-subsystem/TESTSubsystemObject.h b/test/test-subsystem/TESTSubsystemObject.h
new file mode 100644
index 0000000..527e555
--- /dev/null
+++ b/test/test-subsystem/TESTSubsystemObject.h
@@ -0,0 +1,59 @@
+/*
+* Copyright (c) 2011-2015, Intel Corporation
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software without
+* specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+#pragma once
+
+#include "SubsystemObject.h"
+
+class CMappingContext;
+
+class CTESTSubsystemObject : public CSubsystemObject
+{
+public:
+ CTESTSubsystemObject(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context);
+
+protected:
+ // from CSubsystemObject
+ // Sync to/from HW
+ virtual bool sendToHW(std::string& strError);
+ virtual bool receiveFromHW(std::string& strError);
+
+private:
+ void sendToFile(std::ofstream& outputFile);
+ void receiveFromFile(std::ifstream& inputFile);
+ virtual std::string toString(const void* pvValue, uint32_t uiSize) const = 0;
+ virtual void fromString(const std::string& strValue, void* pvValue, uint32_t uiSize) = 0;
+
+protected:
+ uint32_t _uiScalarSize;
+ uint32_t _uiArraySize;
+ std::string _strFilePath;
+ bool _bLog;
+ bool _bIsScalar;
+};
diff --git a/test/test-subsystem/TESTSubsystemString.cpp b/test/test-subsystem/TESTSubsystemString.cpp
new file mode 100644
index 0000000..81ed793
--- /dev/null
+++ b/test/test-subsystem/TESTSubsystemString.cpp
@@ -0,0 +1,50 @@
+/*
+* Copyright (c) 2011-2015, Intel Corporation
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software without
+* specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+#include <string.h>
+#include "TESTSubsystemString.h"
+
+#define base CTESTSubsystemObject
+
+CTESTSubsystemString::CTESTSubsystemString(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context)
+ : base(strMappingValue, pInstanceConfigurableElement, context)
+{
+}
+
+std::string CTESTSubsystemString::toString(const void* pvValue, uint32_t uiSize) const
+{
+ (void)uiSize;
+
+ return (const char*)pvValue;
+}
+
+void CTESTSubsystemString::fromString(const std::string& strValue, void* pvValue, uint32_t uiSize)
+{
+ strncpy((char*)pvValue, strValue.c_str(), uiSize);
+}
diff --git a/test/test-subsystem/TESTSubsystemString.h b/test/test-subsystem/TESTSubsystemString.h
new file mode 100644
index 0000000..cf7edb7
--- /dev/null
+++ b/test/test-subsystem/TESTSubsystemString.h
@@ -0,0 +1,45 @@
+/*
+* Copyright (c) 2011-2015, Intel Corporation
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* 3. Neither the name of the copyright holder nor the names of its contributors
+* may be used to endorse or promote products derived from this software without
+* specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+#pragma once
+
+#include "TESTSubsystemObject.h"
+
+class CTESTSubsystemString : public CTESTSubsystemObject
+{
+public:
+ CTESTSubsystemString(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context);
+
+private:
+ // from CTESTSubsystemObject
+ // Format Data
+ virtual std::string toString(const void* pvValue, uint32_t uiSize) const;
+ virtual void fromString(const std::string& strValue, void* pvValue, uint32_t uiSize);
+
+};