Beispiel #1
0
void test_KineticPDU_Init_should_set_the_exchange_fields_in_the_embedded_protobuf_header(void)
{
    LOG_LOCATION;
    KINETIC_CONNECTION_INIT(&Connection);
    Connection.sequence = 24;
    Connection.connectionID = 8765432;
    Session = (KineticSession) {
        .clusterVersion = 1122334455667788,
         .identity = 37,
    };
    Connection.session = Session;
    KINETIC_PDU_INIT(&PDU, &Connection);

    TEST_ASSERT_TRUE(PDU.protoData.message.header.has_clusterVersion);
    TEST_ASSERT_EQUAL_INT64(1122334455667788,
                            PDU.protoData.message.header.clusterVersion);
    TEST_ASSERT_TRUE(PDU.protoData.message.header.has_identity);
    TEST_ASSERT_EQUAL_INT64(37, PDU.protoData.message.header.identity);
    TEST_ASSERT_TRUE(PDU.protoData.message.header.has_connectionID);
    TEST_ASSERT_EQUAL_INT64(8765432, PDU.protoData.message.header.connectionID);
    TEST_ASSERT_TRUE(PDU.protoData.message.header.has_sequence);
    TEST_ASSERT_EQUAL_INT64(24, PDU.protoData.message.header.sequence);
}


void test_KineticPDU_AttachEntry_should_attach_specified_KineticEntry(void)
{
    LOG_LOCATION;
    KineticPDU_Init(&PDU, &Connection);

    uint8_t data[5];
    ByteArray value = {.data = data, .len = sizeof(data)};
    ByteBuffer valueBuffer = ByteBuffer_CreateWithArray(value);
    KineticEntry entry = {.value = valueBuffer};
    entry.value.bytesUsed = 3;

    KineticPDU_AttachEntry(&PDU, &entry);

    TEST_ASSERT_EQUAL_PTR(entry.value.array.data, PDU.entry.value.array.data);
    TEST_ASSERT_EQUAL(3, PDU.entry.value.bytesUsed);
    TEST_ASSERT_EQUAL(3, entry.value.bytesUsed);
    TEST_ASSERT_EQUAL(sizeof(data), entry.value.array.len);
}


void test_KINETIC_PDU_INIT_WITH_MESSAGE_should_initialize_PDU_and_protobuf_message(void)
{
    LOG_LOCATION;
    memset(&PDU, 0, sizeof(KineticPDU));
    KINETIC_PDU_INIT_WITH_MESSAGE(&PDU, &Connection);

    PDU.protoData.message.status.code = KINETIC_PROTO_STATUS_STATUS_CODE_SERVICE_BUSY;
    PDU.protoData.message.command.status = &PDU.protoData.message.status;

    TEST_ASSERT_EQUAL(
        KINETIC_PROTO_STATUS_STATUS_CODE_SERVICE_BUSY,
        PDU.proto->command->status->code);
}
void test_KineticSession_Connect_should_connect_to_specified_host(void)
{
    const uint8_t hmacKey[] = {1, 6, 3, 5, 4, 8, 19};

    KineticSession expected = {
        .config = (KineticSessionConfig) {
            .host = "valid-host.com",
            .port = 1234,
            .clusterVersion = 17,
            .identity = 12,
            .hmacKey = {
                .data = expected.config.keyData,
                .len = sizeof(hmacKey)},
        },
        .connected = true,
        .socket = 24,
    };
    memcpy(expected.config.hmacKey.data,
        hmacKey, expected.config.hmacKey.len);

    KineticSession session = {
        .config = (KineticSessionConfig) {
            .host = "valid-host.com",
            .port = expected.config.port,
            .clusterVersion = expected.config.clusterVersion,
            .identity = expected.config.identity,
            .hmacKey = {
                .data = Session.config.keyData,
                .len = sizeof(hmacKey)},
        },
        .connected = true,
        .socket = 24,
    };
    memcpy(session.config.hmacKey.data,
        hmacKey, expected.config.hmacKey.len);

    KineticSocket_Connect_ExpectAndReturn(expected.config.host, expected.config.port, expected.socket);
    Bus_RegisterSocket_ExpectAndReturn(NULL, BUS_SOCKET_PLAIN,
        expected.socket, &session, true);
    KineticResourceWaiter_WaitTilAvailable_ExpectAndReturn(&session.connectionReady,
        KINETIC_CONNECTION_TIMEOUT_SECS, true);

    // Establish connection
    KineticStatus status = KineticSession_Connect(&session);

    TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status);
    TEST_ASSERT_TRUE(session.connected);
    TEST_ASSERT_EQUAL(expected.socket, session.socket);
    TEST_ASSERT_EQUAL_STRING(expected.config.host, session.config.host);
    TEST_ASSERT_EQUAL(expected.config.port, session.config.port);
    TEST_ASSERT_EQUAL_INT64(expected.config.clusterVersion, session.config.clusterVersion);
    TEST_ASSERT_EQUAL_INT64(expected.config.identity, session.config.identity);
    TEST_ASSERT_EQUAL_ByteArray(expected.config.hmacKey, session.config.hmacKey);
}
void test_KineticOperation_Create_should_create_a_new_operation_with_allocated_PDUs(void)
{
    LOG_LOCATION;
    KineticAllocator_NewPDU_ExpectAndReturn(&Connection.pdus, &Request);
    KineticAllocator_NewPDU_ExpectAndReturn(&Connection.pdus, &Response);
    KineticPDU_Init_Expect(&Request, &Connection);
    KineticPDU_Init_Expect(&Response, &Connection);

    KineticOperation operation = KineticOperation_Create(&Connection);

    TEST_ASSERT_EQUAL_PTR(&Connection, operation.connection);
    TEST_ASSERT_EQUAL_INT64(ConnectionID, Connection.connectionID);
    TEST_ASSERT_EQUAL_INT64(ConnectionID, operation.request->proto->command->header->connectionID);
    TEST_ASSERT_NOT_NULL(operation.request);
    TEST_ASSERT_NOT_NULL(operation.response);
}
void
test_dot1dBaseNumPorts(void) {
    lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
    size_t size;

    ret = dataplane_bridge_count_port(&size);

    TEST_ASSERT_EQUAL_INT64(ret, LAGOPUS_RESULT_OK);
    TEST_ASSERT_EQUAL_UINT32(2, size);
}
void test_KineticBuilder_BuildSetClusterVersion_should_build_a_SET_CLUSTER_VERSION_operation_with_PIN_auth(void)
{
    KineticOperation_ValidateOperation_Expect(&Operation);

    KineticBuilder_BuildSetClusterVersion(&Operation, 1776);

    TEST_ASSERT_FALSE(Request.pinAuth);
    TEST_ASSERT_NULL(Operation.response);
    TEST_ASSERT_EQUAL(0, Operation.timeoutSeconds);
    TEST_ASSERT_TRUE(Request.message.command.header->has_messagetype);
    TEST_ASSERT_EQUAL(COM__SEAGATE__KINETIC__PROTO__COMMAND__MESSAGE_TYPE__SETUP,
        Request.message.command.header->messagetype);
    TEST_ASSERT_EQUAL_PTR(&Request.message.body, Request.command->body);

    TEST_ASSERT_EQUAL_PTR(&Request.message.setup, Request.command->body->setup);
    TEST_ASSERT_EQUAL_INT64(1776, Request.message.setup.newclusterversion);
    TEST_ASSERT_EQUAL_INT64(1776, Operation.pendingClusterVersion);
    TEST_ASSERT_TRUE(Request.message.setup.has_newclusterversion);
    TEST_ASSERT_FALSE(Request.message.setup.has_firmwaredownload);
    TEST_ASSERT_EQUAL_PTR(&KineticCallbacks_SetClusterVersion, Operation.opCallback);
}
void test_KineticSession_Create_should_allocate_and_destroy_KineticConnections(void)
{
    KineticSession session;
    memset(&session, 0, sizeof(session));

    KineticCountingSemaphore_Create_ExpectAndReturn(KINETIC_MAX_OUTSTANDING_OPERATIONS_PER_SESSION, &Semaphore);

    KineticStatus status = KineticSession_Create(&session, &Client);

    TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status);
    TEST_ASSERT_FALSE(session.connected);
    TEST_ASSERT_EQUAL(-1, session.socket);
    TEST_ASSERT_EQUAL_INT64(0, session.sequence);
    TEST_ASSERT_EQUAL_INT64(0, session.connectionID);

    KineticCountingSemaphore_Destroy_Expect(&Semaphore);
    KineticAllocator_FreeSession_Expect(&session);

    status = KineticSession_Destroy(&session);

    TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status);
}
void test_KineticRequest_Init_should_set_the_exchange_fields_in_the_embedded_protobuf_header(void)
{
    KineticRequest request;
    KineticSession session;

    session = (KineticSession) {
        .config = (KineticSessionConfig) {
            .clusterVersion = 1122334455667788,
            .identity = 37,
        },
        .sequence = 24,
        .connectionID = 8765432,
    };
    KineticRequest_Init(&request, &session);

    TEST_ASSERT_TRUE(request.message.header.has_clusterversion);
    TEST_ASSERT_EQUAL_INT64(1122334455667788, request.message.header.clusterversion);
    TEST_ASSERT_TRUE(request.message.header.has_connectionid);
    TEST_ASSERT_EQUAL_INT64(8765432, request.message.header.connectionid);
    TEST_ASSERT_TRUE(request.message.header.has_sequence);
    TEST_ASSERT_EQUAL_INT64(KINETIC_SEQUENCE_NOT_YET_BOUND, request.message.header.sequence);
}