TEST_F(DataHandlerTestProbeSmokeTest, InitialTest)
{
    // TODO: Remove when changing the API. 
    uint32_t bytesRead;
    uint32_t bytesWritten;


    // Purspose of the test:
    // A full lifecycle of read/write operations, combining both TestProbe and Applications.
    //
    // Preconditions:
    // As DataHandler design provides two interfaces (named DataHandler.h and DataHandlerAdvanced.h)
    // They will be used as follows:
    // - DataHandler.h will be used by the Applications. 
    // - DataHandlerTest.h will be used by the TestProbe. 
    //
    // Steps in this test:
    // Step 1:
    // Perform a write operation over a data packet from an application and read that value. 
    // Step 2:
    // Write from TestProbe the shadow database and activate the shadow data packet.
    // Step 3: 
    // Application: Read again the data packet. The read value should be the one written by the TestProbe. 
    // Step 4:
    // Read from TestProbe in shadow database (read in master database is allowed, but theoretically, not used). 
    // Take into account that TestProbe can use less bytes than the topic size (to check). 
    // Step 5:
    // Write from TestProbe in both databases different values. 
    // Step 6: 
    // Read from standard application. This operation will read the value written by the TestProbe in Step 5
    // from shadow database. 
    // Step 7:
    // Activate the master database (aka deactivate the shadow database). 
    // Step 8:
    // Read from standard application. This operation will read the value written by the TestProbe in Step 5
    // from master database. 
    // Step 9:
    // Read from TestProbe both from Master Database and from Shadow Database. 

    // Database Status (before Step 1)
    // 
    //      ------------------------
    // DP1  |     0     |     0    |
    //      ------------------------
    //       Master(1)*   Shadow(2)

    // Step 1:
    // Perform a write operation over a data packet from an application and read that value. 
    {
        int32_t readDataDP1;

        // Start write operation (DP1).
        ASSERT_EQ(XME_STATUS_SUCCESS, xme_core_dataHandler_startWriteOperation(dataPacketID1));

        // Write (from Application)
        ASSERT_EQ(XME_STATUS_SUCCESS, xme_core_dataHandler_writeData(dataPacketID1, &masterFirstWrittenData, sizeof(masterFirstWrittenData)));

        // Complete write operation (DP1). 
        ASSERT_EQ(XME_STATUS_SUCCESS, xme_core_dataHandler_completeWriteOperation(dataPacketID1));

        // Read DP1 (from Application).
        ASSERT_EQ(XME_STATUS_SUCCESS, xme_core_dataHandler_readData(dataPacketID1, &readDataDP1, sizeof(readDataDP1), &bytesRead));
        EXPECT_EQ(sizeof(readDataDP1), bytesRead);
        EXPECT_EQ(masterFirstWrittenData, readDataDP1);
    }

    // Database Status (before Step 2)
    // 
    //      ------------------------
    // DP1  |    1234   |     0    |
    //      ------------------------
    //       Master(1)*   Shadow(2)

    // Step 2:
    // Write from TestProbe the shadow database and activate the shadow data packet.
    {
        // Write (from TestProbe in Shadow Database (2))
        ASSERT_EQ(XME_STATUS_SUCCESS, xme_core_dataHandlerTestProbe_writeDataInDatabase(DB_SHADOW, dataPacketID1, OFFSET_ZERO, &shadowFirstWrittenData, sizeof(shadowFirstWrittenData), &bytesWritten)); 
        EXPECT_EQ(sizeof(masterFirstWrittenData), bytesWritten);

        // TestProbe: Activate the data packet to be used by the applications. 
        ASSERT_EQ(XME_STATUS_SUCCESS, xme_core_dataHandlerTestProbe_activateDatabaseForDataPacket(DB_SHADOW, dataPacketID1));
    }

    // Database Status (before Step 3)
    // 
    //      ------------------------
    // DP1  |    1234   |   5678    |
    //      ------------------------
    //       Master(1)   Shadow(2)*

    // Step 3: 
    // Application: Read again the data packet. The read value should be the one written by the TestProbe. 
    {
        // Read data. 
        int32_t readDataDP1;

        // Read DP1 (from Application).
        ASSERT_EQ(XME_STATUS_SUCCESS, xme_core_dataHandler_readData(dataPacketID1, &readDataDP1, sizeof(readDataDP1), &bytesRead));
        EXPECT_EQ(sizeof(readDataDP1), bytesRead);
        EXPECT_EQ(shadowFirstWrittenData, readDataDP1);
    }

    // Database Status (before Step 4)
    // 
    //      ------------------------
    // DP1  |   -1234   |   5678    |
    //      ------------------------
    //       Master(1)   Shadow(2)*

    // Step 4:
    // Read from TestProbe in shadow database (read in master database is allowed, but theoretically, not used). 
    // Take into account that TestProbe can use less bytes than the topic size (to check in a separate test). 
    {
        // Read datas. 
        int32_t readDataDP1;

        // Read DP1 (from TestProbe from Shadow Database(2)).
        ASSERT_EQ(XME_STATUS_SUCCESS, xme_core_dataHandlerTestProbe_readDataInDatabase(DB_SHADOW, dataPacketID1, OFFSET_ZERO, &readDataDP1, sizeof(readDataDP1), &bytesRead));
        EXPECT_EQ(sizeof(readDataDP1), bytesRead);
        EXPECT_EQ(shadowFirstWrittenData, readDataDP1);
    }

    // Database Status (before Step 5)
    // 
    //      ------------------------
    // DP1  |   -1234   |   5678    |
    //      ------------------------
    //       Master(1)   Shadow(2)*

    // Step 5:
    // Write from TestProbe in both databases different values. 
    {
        // Write (from TestProbe in Master Database (1)) -- This is the directManipulation. 
        ASSERT_EQ(XME_STATUS_SUCCESS, xme_core_dataHandlerTestProbe_writeDataInDatabase(DB_MASTER, dataPacketID1, OFFSET_ZERO, &masterSecondWrittenData, sizeof(masterSecondWrittenData), &bytesWritten)); 
        EXPECT_EQ(sizeof(masterSecondWrittenData), bytesWritten);
        // Note: For write operation from TestProbe is not needed to lock/unlock the data packet. 
        //       The call will directly invoke the write operation.

        // Write (from TestProbe in Shadow Database (2)) -- This is the manipulation. 
        ASSERT_EQ(XME_STATUS_SUCCESS, xme_core_dataHandlerTestProbe_writeDataInDatabase(DB_SHADOW, dataPacketID1, OFFSET_ZERO, &shadowSecondWrittenData, sizeof(shadowSecondWrittenData), &bytesWritten)); 
        EXPECT_EQ(sizeof(shadowSecondWrittenData), bytesWritten);
        // We do need not to activate again, because it was previously activated by the TestProbe in the first write.
    }

    // Database Status (before Step 6)
    // 
    //      ------------------------
    // DP1  |   3456    |   -7890   |
    //      ------------------------
    //       Master(1)   Shadow(2)*

    // Step 6: 
    // Read from standard application. This operation will read the value written by the TestProbe in Step 5
    // from shadow database. 
    {
        // Read datas. 
        int32_t readDataDP1;

        // Read DP1 (from Application).
        ASSERT_EQ(XME_STATUS_SUCCESS, xme_core_dataHandler_readData(dataPacketID1, &readDataDP1, sizeof(readDataDP1), &bytesRead));
        EXPECT_EQ(sizeof(readDataDP1), bytesRead);
        EXPECT_EQ(shadowSecondWrittenData, readDataDP1);
    }

    // Database Status (before Step 7)
    // 
    //      ------------------------
    // DP1  |   3456    |   -7890   |
    //      ------------------------
    //       Master(1)   Shadow(2)*

    // Step 7:
    // Activate the master database (aka deactivate the shadow database). 
    {
        // Activate the master database (index=1U) (from TestProbe)
        ASSERT_EQ(XME_STATUS_SUCCESS, xme_core_dataHandlerTestProbe_activateDatabaseForDataPacket(DB_MASTER, dataPacketID1));
    }

    // Database Status (before Step 8)
    // 
    //      ------------------------
    // DP1  |   3456    |   -7890   |
    //      ------------------------
    //       Master(1)*   Shadow(2)

    // Step 8:
    // Read from standard application. This operation will read the value written by the TestProbe in Step 5
    // from master database. 
    {
        int32_t readDataDP1;

        // Read DP1 (from Application).
        ASSERT_EQ(XME_STATUS_SUCCESS, xme_core_dataHandler_readData(dataPacketID1, &readDataDP1, sizeof(readDataDP1), &bytesRead));
        EXPECT_EQ(sizeof(readDataDP1), bytesRead);
        EXPECT_EQ(masterSecondWrittenData, readDataDP1);
    }

    // Database Status (before Step 9)
    // 
    //      ------------------------
    // DP1  |   3456    |   -7890   |
    //      ------------------------
    //       Master(1)*   Shadow(2)

    // Step 9:
    // Read from TestProbe both from Master Database and from Shadow Database. 
    {
        int32_t readDataDP1a;
        int32_t readDataDP1b;

        // Read DP1 (from TestProbe from Master Database(1)).
        // Note that this is NOT the normal read operation from TestProbe. 
        ASSERT_EQ(XME_STATUS_SUCCESS, xme_core_dataHandlerTestProbe_readDataInDatabase(DB_MASTER, dataPacketID1, OFFSET_ZERO, &readDataDP1a, sizeof(readDataDP1a), &bytesRead));
        EXPECT_EQ(sizeof(readDataDP1a), bytesRead);
        EXPECT_EQ(masterSecondWrittenData, readDataDP1a);

        // Read DP1 (from TestProbe from Shadow Database(2)).
        // Note that this is the normal read operation from TestProbe. 
        ASSERT_EQ(XME_STATUS_SUCCESS, xme_core_dataHandlerTestProbe_readDataInDatabase(DB_SHADOW, dataPacketID1, OFFSET_ZERO, &readDataDP1b, sizeof(readDataDP1b), &bytesRead));
        EXPECT_EQ(sizeof(readDataDP1b), bytesRead);
        EXPECT_EQ(shadowSecondWrittenData, readDataDP1b);
    }
}
Exemplo n.º 2
0
xme_status_t
doMarshaling
(
	xme_core_topic_t topic,
	xme_core_dataManager_dataPacketId_t inputPort,
	xme_core_dataManager_dataPacketId_t outputPort
)
{
	void* buffer;
	unsigned int bufferSize;
	xme_status_t status;

	// Switch for the correct topic
	// In the respective cases we allocate a buffer with the right size for the topic and
	// call a function that performs the read from the inputPort and the actual marshaling
	if (XME_CORE_TOPIC(CHROMOSOMEGUI_TOPIC_BUTTONSIGNAL) == topic)
	{
		uint8_t marshaledData[1];
		
		buffer = marshaledData;
		bufferSize = 1;
		
		status = doMarshalingForButtonSignal
		(
			inputPort,
			(void*)marshaledData
		);
	}
	else if (XME_CORE_TOPIC(CHROMOSOMEGUI_TOPIC_WRITETEXT) == topic)
	{
		uint8_t marshaledData[1000];
		
		buffer = marshaledData;
		bufferSize = 1000;
		
		status = doMarshalingForWriteText
		(
			inputPort,
			(void*)marshaledData
		);
	}
	else if (XME_CORE_TOPIC(XME_CORE_TOPIC_PNPMANAGER_RUNTIME_GRAPH_MODEL) == topic)
	{
		uint8_t marshaledData[2962];
		
		buffer = marshaledData;
		bufferSize = 2962;
		
		status = doMarshalingForPnpManager_runtime_graph_model
		(
			inputPort,
			(void*)marshaledData
		);
	}
	else if (XME_CORE_TOPIC(XME_CORE_TOPIC_PNPMANAGER_RUNTIME_GRAPH_MODEL2) == topic)
	{
		uint8_t marshaledData[2962];
		
		buffer = marshaledData;
		bufferSize = 2962;
		
		status = doMarshalingForPnpManager_runtime_graph_model2
		(
			inputPort,
			(void*)marshaledData
		);
	}
	else if (XME_CORE_TOPIC(XME_CORE_TOPIC_PNPMANAGER_RUNTIME_GRAPH_MODEL3) == topic)
	{
		uint8_t marshaledData[2962];
		
		buffer = marshaledData;
		bufferSize = 2962;
		
		status = doMarshalingForPnpManager_runtime_graph_model3
		(
			inputPort,
			(void*)marshaledData
		);
	}
	else
	{
		XME_LOG
		(
			XME_LOG_ERROR,
			"xme_wp_marshaler_run(): Given topic with id %" PRIu64 " is not "
			"supported by this marshaler.",
			topic
		);
		return XME_STATUS_INTERNAL_ERROR;
	}

	XME_CHECK
	(
		XME_STATUS_SUCCESS == status,
		XME_STATUS_INTERNAL_ERROR
	);

	// Write marshaled data to outputPort
	status = xme_core_dataHandler_writeData
	(
		outputPort,
		buffer,
		bufferSize
	);

	XME_CHECK
	(
		XME_STATUS_SUCCESS == status,
		XME_STATUS_INTERNAL_ERROR
	);
	
	xme_core_dataHandler_completeWriteOperation(outputPort);
	xme_core_dataHandler_completeReadOperation(inputPort);

	return XME_STATUS_SUCCESS;
}
Exemplo n.º 3
0
xme_status_t
doMarshaling
(
    xme_core_topic_t topic,
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort
)
{
    void* buffer;
    unsigned int bufferSize;
    xme_status_t status;

    // Switch for the correct topic
    // In the respective cases we allocate a buffer with the right size for the topic and
    // call a function that performs the read from the inputPort and the actual marshaling
    if (XME_CORE_TOPIC(XME_WP_DEMARSHALERTEST_TOPIC_TEST) == topic)
    {
        uint8_t marshaledData[90];
        
        buffer = marshaledData;
        bufferSize = 90;
        
        status = doMarshalingForTest
        (
            inputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC(XME_WP_DEMARSHALERTEST_TOPIC_TOPIC0) == topic)
    {
        uint8_t marshaledData[4];
        
        buffer = marshaledData;
        bufferSize = 4;
        
        status = doMarshalingForTopic0
        (
            inputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC(XME_WP_DEMARSHALERTEST_TOPIC_TOPIC1) == topic)
    {
        uint8_t marshaledData[4];
        
        buffer = marshaledData;
        bufferSize = 4;
        
        status = doMarshalingForTopic1
        (
            inputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC(XME_WP_DEMARSHALERTEST_TOPIC_TOPIC2) == topic)
    {
        uint8_t marshaledData[4];
        
        buffer = marshaledData;
        bufferSize = 4;
        
        status = doMarshalingForTopic2
        (
            inputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC(XME_CORE_TOPIC_PNPMANAGER_RUNTIME_GRAPH_MODEL) == topic)
    {
        uint8_t marshaledData[3024];
        
        buffer = marshaledData;
        bufferSize = 3024;
        
        status = doMarshalingForPnpManager_runtime_graph_model
        (
            inputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC(XME_CORE_TOPIC_LOGIN_LOGINREQUEST) == topic)
    {
        uint8_t marshaledData[18];
        
        buffer = marshaledData;
        bufferSize = 18;
        
        status = doMarshalingForLogin_loginRequest
        (
            inputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC(XME_CORE_TOPIC_LOGIN_LOGINRESPONSE) == topic)
    {
        uint8_t marshaledData[22];
        
        buffer = marshaledData;
        bufferSize = 22;
        
        status = doMarshalingForLogin_loginResponse
        (
            inputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC(XME_CORE_TOPIC_LOGIN_PNPLOGINREQUEST) == topic)
    {
        uint8_t marshaledData[10];
        
        buffer = marshaledData;
        bufferSize = 10;
        
        status = doMarshalingForLogin_pnpLoginRequest
        (
            inputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC(XME_CORE_TOPIC_LOGIN_PNPLOGINRESPONSE) == topic)
    {
        uint8_t marshaledData[10];
        
        buffer = marshaledData;
        bufferSize = 10;
        
        status = doMarshalingForLogin_pnpLoginResponse
        (
            inputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC(XME_CORE_TOPIC_LOGIN_LOGINACKNOWLEDGMENT) == topic)
    {
        uint8_t marshaledData[4];
        
        buffer = marshaledData;
        bufferSize = 4;
        
        status = doMarshalingForLogin_loginAcknowledgment
        (
            inputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC(XME_CORE_TOPIC_PNP_COMPONENTINSTANCEMANIFEST) == topic)
    {
        uint8_t marshaledData[84];
        
        buffer = marshaledData;
        bufferSize = 84;
        
        status = doMarshalingForPnp_componentInstanceManifest
        (
            inputPort,
            (void*)marshaledData
        );
    }
    else
    {
        XME_LOG
        (
            XME_LOG_ERROR,
            "xme_wp_marshal_marshaler_run(): Given topic with id %" PRIu64 " is not "
            "supported by this marshaler.",
            topic
        );
        return XME_STATUS_INTERNAL_ERROR;
    }

    XME_CHECK
    (
        XME_STATUS_SUCCESS == status,
        XME_STATUS_INTERNAL_ERROR
    );

    // Write marshaled data to outputPort
    status = xme_core_dataHandler_writeData
    (
        outputPort,
        buffer,
        bufferSize
    );

    XME_CHECK
    (
        XME_STATUS_SUCCESS == status,
        XME_STATUS_INTERNAL_ERROR
    );
    
    XME_CHECK(XME_STATUS_SUCCESS == xme_core_dataHandler_completeWriteOperation(outputPort), XME_STATUS_INTERNAL_ERROR);
    XME_CHECK(XME_STATUS_SUCCESS == xme_core_dataHandler_completeReadOperation(inputPort), XME_STATUS_INTERNAL_ERROR);

    return XME_STATUS_SUCCESS;
}