Commit bc36b3e1 authored by Greg Williams's avatar Greg Williams
Browse files

Updated system tests to pull hosts/ports from new environment vars rather than...

Updated system tests to pull hosts/ports from new environment vars rather than build time constants.
New system test env vars are: KINETIC_HOST1/2, KINETIC_PORT1/2, and KINETIC_TLS_PORT1/2
parent 2d8384b3
Loading
Loading
Loading
Loading
+39 −12
Original line number Diff line number Diff line
@@ -19,11 +19,11 @@ OPENSSL_PATH ?= .
#===============================================================================
CC ?= gcc
OPTIMIZE = -O3
SYSTEM_TEST_HOST ?= \"localhost\"
SESSION_HMAC_KEY ?= \"asdfasdf\"
SESSION_PIN ?= \"1234\"
KINETIC_HOST1 ?= localhost
SESSION_HMAC_KEY ?= asdfasdf
SESSION_PIN ?= 1234
WARN = -Wall -Wextra -Werror -Wstrict-prototypes -Wcast-align -pedantic -Wno-missing-field-initializers -Werror=strict-prototypes
CDEFS += -D_POSIX_C_SOURCE=199309L -D_C99_SOURCE=1 -DSYSTEM_TEST_HOST=${SYSTEM_TEST_HOST}
CDEFS += -D_POSIX_C_SOURCE=199309L -D_C99_SOURCE=1
CFLAGS += -std=c99 -fPIC -g $(WARN) $(CDEFS) $(OPTIMIZE)
LDFLAGS += -lm -L${OPENSSL_PATH}/lib -lcrypto -lssl -lpthread -ljson-c
NUM_SIMS ?= 2
@@ -434,16 +434,43 @@ run: $(UTIL_EXEC)
	@echo Running test utility: $(UTIL_EXEC)
	@echo --------------------------------------------------------------------------------
	@echo
	# $(UTIL_EXEC) instanterase
	# exec $(UTIL_EXEC) --seterasepin --pin "" --newpin 1234
	# exec $(UTIL_EXEC) --instanterase --pin 1234
	# exec $(UTIL_EXEC) --seterasepin --pin 1234 --newpin ""
	# @echo
	exec $(UTIL_EXEC) --help
	@echo
	exec $(UTIL_EXEC) -?
	exec $(UTIL_EXEC) --noop
	exec $(UTIL_EXEC) --put
	exec $(UTIL_EXEC) --get
	exec $(UTIL_EXEC) --getnext --key ""
	exec $(UTIL_EXEC) --getprevious --key "zzzzzzzzzzzzzzzzz"
	exec $(UTIL_EXEC) --delete --host 127.0.0.1
	exec $(UTIL_EXEC) --getlog
	@echo
	exec $(UTIL_EXEC) --noop --host $(KINETIC_HOST1)
	@echo
	exec $(UTIL_EXEC) --put --host $(KINETIC_HOST1)
	@echo
	exec $(UTIL_EXEC) --get --host $(KINETIC_HOST1)
	@echo
	exec $(UTIL_EXEC) --getnext --key "A" --host $(KINETIC_HOST1)
	@echo
	exec $(UTIL_EXEC) --getprevious --key "zzzzzzzzzzzzzzzzz" --host $(KINETIC_HOST1)
	@echo
	exec $(UTIL_EXEC) --delete --host $(KINETIC_HOST1)
	@echo
	exec $(UTIL_EXEC) --getlog --host $(KINETIC_HOST1)
	@echo
	exec $(UTIL_EXEC) --getlog --logtype utilizations --host $(KINETIC_HOST1)
	@echo
	exec $(UTIL_EXEC) --getlog --logtype temperatures --host $(KINETIC_HOST1)
	@echo
	exec $(UTIL_EXEC) --getlog --logtype capacities --host $(KINETIC_HOST1)
	@echo
	exec $(UTIL_EXEC) --getlog --logtype configuration --host $(KINETIC_HOST1)
	@echo
	exec $(UTIL_EXEC) --getlog --logtype statistics --host $(KINETIC_HOST1)
	@echo
	exec $(UTIL_EXEC) --getlog --logtype messages --host $(KINETIC_HOST1)
	@echo
	exec $(UTIL_EXEC) --getlog --logtype limits --host $(KINETIC_HOST1)
	@echo
	exec $(UTIL_EXEC) --getlog --logtype device --host $(KINETIC_HOST1)
	@echo
	@echo Test Utility integration tests w/ kinetic-c lib passed!
	@echo
+142 −7
Original line number Diff line number Diff line
@@ -25,6 +25,139 @@

SystemTestFixture Fixture = {.connected = false};

static void LoadConfiguration(void)
{
    if (!Fixture.configurationLoaded) {

        //----------------------------------------------------------------------
        // Configure test device #1

        // Configure host
        char * host = getenv("KINETIC_HOST");
        if (host == NULL) {
            host = getenv("KINETIC_HOST1");
        }
        if (host == NULL) {
            strncpy(Fixture.host1, "127.0.0.1", sizeof(Fixture.host1)-1);
        }
        else {
            strncpy(Fixture.host1, host, sizeof(Fixture.host1)-1);
        }

        // Configure standard port
        char * portString = getenv("KINETIC_PORT");
        if (portString == NULL) {
            portString = getenv("KINETIC_PORT1");
        }
        if (portString == NULL) {
            Fixture.port1 = KINETIC_PORT;
        }
        else {
            errno = 0;
            long port = strtol(portString, NULL, 0);
            if (port == 0 && errno != 0) {
                TEST_ASSERT_EQUAL_MESSAGE(0, errno, "Failed parsing kinetic device port! (errno != 0)");
            }
            Fixture.port1 = (int)port;
        }

        // Configure TLS port
        char * tlsPortString = getenv("KINETIC_TLS_PORT");
        if (tlsPortString == NULL) {
            tlsPortString = getenv("KINETIC_TLS_PORT1");
        }
        if (tlsPortString == NULL) {
            Fixture.tlsPort1 = KINETIC_TLS_PORT;
        }
        else {
            errno = 0;
            long port = strtol(tlsPortString, NULL, 0);
            if (port == 0 && errno != 0) {
                TEST_ASSERT_EQUAL_MESSAGE(0, errno, "Failed parsing kinetic device TLS port! (errno != 0)");
            }
            Fixture.tlsPort1 = (int)port;
        }

        //----------------------------------------------------------------------
        // Configure test device #2

        // Configure host
        host = getenv("KINETIC_HOST2");
        if (host == NULL) {
            strncpy(Fixture.host2, "127.0.0.1", sizeof(Fixture.host2)-1);
        }
        else {
            strncpy(Fixture.host2, host, sizeof(Fixture.host2)-1);
        }

        // Configure standard port
        portString = getenv("KINETIC_PORT2");
        if (portString == NULL) {
            Fixture.port2 = KINETIC_PORT+1;
        }
        else {
            errno = 0;
            long port = strtol(portString, NULL, 0);
            if (port == 0 && errno != 0) {
                TEST_ASSERT_EQUAL_MESSAGE(0, errno, "Failed parsing kinetic device port! (errno != 0)");
            }
            Fixture.port2 = (int)port;
        }

        // Configure TLS port
        tlsPortString = getenv("KINETIC_TLS_PORT2");
        if (tlsPortString == NULL) {
            Fixture.tlsPort2 = KINETIC_TLS_PORT+1;
        }
        else {
            errno = 0;
            long port = strtol(tlsPortString, NULL, 0);
            if (port == 0 && errno != 0) {
                TEST_ASSERT_EQUAL_MESSAGE(0, errno, "Failed parsing kinetic device TLS port! (errno != 0)");
            }
            Fixture.tlsPort2 = (int)port;
        }

        Fixture.configurationLoaded = true;
    }
}

const char* GetSystemTestHost1(void)
{
    LoadConfiguration();
    return Fixture.host1;
}

int GetSystemTestPort1(void)
{
    LoadConfiguration();
    return Fixture.port1;
}

int GetSystemTestTlsPort1(void)
{
    LoadConfiguration();
    return Fixture.tlsPort1;
}

const char* GetSystemTestHost2(void)
{
    LoadConfiguration();
    return Fixture.host2;
}

int GetSystemTestPort2(void)
{
    LoadConfiguration();
    return Fixture.port2;
}

int GetSystemTestTlsPort2(void)
{
    LoadConfiguration();
    return Fixture.tlsPort2;
}

void SystemTestSetup(int log_level)
{
    const uint8_t *key = (const uint8_t *)SESSION_HMAC_KEY;
@@ -45,25 +178,25 @@ void SystemTestSetupWithIdentity(int log_level, int64_t identity,
    };

    KineticSessionConfig config = {
        .host = SYSTEM_TEST_HOST,
        .port = KINETIC_PORT,
        .clusterVersion = SESSION_CLUSTER_VERSION,
        .identity = identity,
        .hmacKey = ByteArray_Create((void *)key, key_size),
    };
    strcpy((char*)config.keyData, SESSION_HMAC_KEY);
    strncpy((char*)config.host, GetSystemTestHost1(), sizeof(config.host)-1);
    config.port = GetSystemTestPort1();
    strncpy((char*)config.keyData, SESSION_HMAC_KEY, sizeof(config.keyData)-1);
    KineticStatus status = KineticClient_CreateSession(&config, Fixture.client, &Fixture.session);
    TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status);

    KineticSessionConfig adminConfig = {
        .host = SYSTEM_TEST_HOST,
        .port = KINETIC_TLS_PORT,
        .clusterVersion = SESSION_CLUSTER_VERSION,
        .identity = identity,
        .hmacKey = ByteArray_Create((void *)key, key_size),
        .useSsl = true,
    };
    strcpy((char*)config.keyData, SESSION_HMAC_KEY);
    strncpy(adminConfig.host, GetSystemTestHost1(), sizeof(adminConfig.host)-1);
    adminConfig.port = GetSystemTestTlsPort1();
    strncpy((char*)adminConfig.keyData, SESSION_HMAC_KEY, sizeof(adminConfig.keyData)-1);
    status = KineticAdminClient_CreateSession(&adminConfig, Fixture.client, &Fixture.adminSession);
    TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status);

@@ -84,5 +217,7 @@ void SystemTestShutDown(void)

bool SystemTestIsUnderSimulator(void)
{
    return (0 == strncmp(SYSTEM_TEST_HOST, "localhost", strlen("localhost")));
    LoadConfiguration();
    return ((0 == strncmp(Fixture.host1, "localhost", strlen("localhost"))) ||
            (0 == strncmp(Fixture.host1, "127.0.0.1", strlen("127.0.0.1"))));
}
+13 −4
Original line number Diff line number Diff line
@@ -28,10 +28,6 @@
#include "unity.h"
#include "unity_helper.h"

#ifndef SYSTEM_TEST_HOST
#define SYSTEM_TEST_HOST "localhost"
#endif

#ifndef SESSION_CLUSTER_VERSION
#define SESSION_CLUSTER_VERSION 0
#endif
@@ -54,6 +50,13 @@ typedef struct _SystemTestFixture {
    bool connected;
    int64_t expectedSequence;
    KineticClient * client;
    char host1[257];
    int port1;
    int tlsPort1;
    char host2[257];
    int port2;
    int tlsPort2;
    bool configurationLoaded;
} SystemTestFixture;

extern SystemTestFixture Fixture;
@@ -63,6 +66,12 @@ void SystemTestSetupWithIdentity(int log_level, int64_t identity,
    const uint8_t *key, size_t key_size);
void SystemTestShutDown(void);
bool SystemTestIsUnderSimulator(void);
const char* GetSystemTestHost1(void);
int GetSystemTestPort1(void);
int GetSystemTestTlsPort1(void);
const char* GetSystemTestHost2(void);
int GetSystemTestPort2(void);
int GetSystemTestTlsPort2(void);

#define SYSTEM_TEST_SUITE_TEARDOWN void test_Suite_TearDown(void) {SystemTestShutDown();}

+1 −3
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ static ByteBuffer ValueBuffer;

void setUp(void)
{
    SystemTestSetup(1);
    SystemTestSetup(2);

    KeyBuffer = ByteBuffer_CreateAndAppendCString(KeyData, sizeof(KeyData), "DELETE test key");
    TagBuffer = ByteBuffer_CreateAndAppendCString(TagData, sizeof(TagData), "SomeTagValue");
@@ -58,8 +58,6 @@ void test_Delete_should_delete_an_object_from_device(void)
    };
    status = KineticClient_Put(Fixture.session, &putEntry, NULL);
    TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status);
    // TEST_ASSERT_EQUAL_ByteArray(Key, putEntry.key.array);
    // TEST_ASSERT_EQUAL_ByteArray(Tag, putEntry.tag.array);
    TEST_ASSERT_EQUAL(KINETIC_ALGORITHM_SHA1, putEntry.algorithm);

    // Validate the object exists initially
+1 −1
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ void setUp(void)
    TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status);

    // Set the erase PIN to something non-empty
    strcpy(NewPinData, "123");
    strcpy(NewPinData, SESSION_PIN);
    OldPin = ByteArray_Create(OldPinData, 0);
    NewPin = ByteArray_Create(NewPinData, strlen(NewPinData));
    status = KineticAdminClient_SetErasePin(Fixture.adminSession,
Loading