From 9a9171c5073c8b27975e8d16218556335474305b Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 31 Jul 2020 12:05:36 -0400 Subject: [PATCH 1/4] Fix #550, add function groups to ut assert Clean up and Refactor the internal list storage structures to support having multiple list heads/groups. Define a separate list/group for setup, normal test, and teardown. The existing UtTest_Add() routine maps to the normal test group. Added a UtTest_AddSetup() and UtTest_AddTeardown() routine that maps to the setup and teardown group, respectively. The existing UtTest_Run() routine then merges the groups and executes the full suite of tests. This allows separate, dynamic registration of test setup and teardown routines which are executed before and after the normal test routine, which can create and delete any global/common test prerequisites. --- ut_assert/inc/utlist.h | 52 ++++------ ut_assert/inc/uttest.h | 23 +++++ ut_assert/src/utbsp.c | 2 +- ut_assert/src/utglobal.h | 2 +- ut_assert/src/utlist.c | 201 ++++++++++++++++++++++----------------- ut_assert/src/uttest.c | 72 +++++++++++--- 6 files changed, 216 insertions(+), 136 deletions(-) diff --git a/ut_assert/inc/utlist.h b/ut_assert/inc/utlist.h index 1e1bef199..d38f08586 100644 --- a/ut_assert/inc/utlist.h +++ b/ut_assert/inc/utlist.h @@ -63,9 +63,8 @@ typedef struct UtListNodeTag { } UtListNode_t; typedef struct { - UtListNode_t *First; - UtListNode_t *Last; - uint32 NumberOfEntries; + UtListNode_t *Tags; + uint32 NumberOfTags; } UtListHead_t; /* @@ -75,54 +74,39 @@ typedef struct UtListNodeTag { /* Dynamically allocates a new list head. A list head could also just be declared, this function is useful * if you need to dynamically allocate memory for a new list head. Note always free list heads allocated by * this function by calling UtList_Destroy. */ -UtListHead_t *UtList_Create(void); +UtListHead_t *UtList_Create(uint32 NumTags); /* Frees a list head created by UtList_Create. */ void UtList_Destroy(UtListHead_t *ListHead); /* Deletes all nodes on the list. */ -void UtList_Reset(UtListHead_t *ListHead); +void UtList_Reset(UtListNode_t *TagHead); + +/* Merge two lists heads together */ +void UtList_Merge(UtListNode_t *TagHead1, UtListNode_t *TagHead2); /* Dynamically adds a new node to the list. Nodes are always added to the end of the list. Memory is dynamically * allocated for the new node and to hold the data pointed to by Data. A Tag field is also provided to be used to * store user defined information with the node. */ void UtList_Add(UtListHead_t *ListHead, void *Data, uint32 DataSize, uint32 Tag); -/* Deletes the first node from the list. */ -void UtList_DeleteFirst(UtListHead_t *ListHead); - -/* Deletes the last node from the list. */ -void UtList_DeleteLast(UtListHead_t *ListHead); - /* Deletes the specified node from the list, this will screw up if you do not pass in a valid DeleteNode. I do not * verify that DeleteNode is a member of the list. */ -void UtList_DeleteNode(UtListHead_t *ListHead, UtListNode_t *DeleteNode); - -/* Removes the first node from the list by first copying the data from the node to the memory buffer pointed to by the - * specified Data pointer and then the node is deleted from the list. Make sure the destination pointer points to a - * memory buffer large enough to hold the data. The size of the data on the node is available by referencing UtListNode->DataSize. */ -void UtList_RemoveFirst(UtListHead_t *ListHead, void *Data); +void UtList_DeleteNode(UtListNode_t *DeleteNode); -/* Removes the last node from the list by first copying the data from the node to the memory buffer pointed to by the - * specified Data pointer and then the node is deleted from the list. Make sure the destination pointer points to a - * memory buffer large enough to hold the data. The size of the data on the node is available by referencing UtListNode->DataSize. */ -void UtList_RemoveLast(UtListHead_t *ListHead, void *Data); - -/* Removes the speciified RemoveNode from the list by first copying the data from the node to the memory buffer pointed to by the - * specified Data pointer and then the node is deleted from the list. Make sure the destination pointer points to a - * memory buffer large enough to hold the data. The size of the data on the node is available by referencing UtListNode->DataSize. */ -void UtList_RemoveNode(UtListHead_t *ListHead, void *Data, UtListNode_t *RemoveNode); +/* Returns true if the list is empty. This is the same as (UtListHead->NumberOfEntries == 0). */ +bool UtList_IsEmpty(UtListNode_t *TagHead); -/* Returns a pointer to the first node on the list. This is the same as (UtListHead->First). */ -UtListNode_t *UtList_First(UtListHead_t *ListHead); +/* Returns the head node of a list for the given tag */ +UtListNode_t *UtList_GetHead(UtListHead_t *ListHead, uint32 Tag); -/* Returns a pointer to the last node on the list. This is the same as (UtListHead->Last). */ -UtListNode_t *UtList_Last(UtListHead_t *ListHead); +/* Returns the next node in the list, given the current node */ +UtListNode_t *UtList_GetNext(UtListNode_t *ListNode); -/* Returns true if the list is empty. This is the same as (UtListHead->NumberOfEntries == 0). */ -bool UtList_IsEmpty(UtListHead_t *ListHead); +/* Returns the data object associated with the current node */ +void *UtList_GetObject(UtListNode_t *ListNode); -/* Returns the number of nodes on the list. This is the same as (UtListHead->NumberOfEntries). */ -uint32 UtList_Depth(UtListHead_t *ListHead); +/* Check if the current node marks the end of the list */ +bool UtList_IsEnd(UtListNode_t *TagHead, UtListNode_t *ListNode); #endif diff --git a/ut_assert/inc/uttest.h b/ut_assert/inc/uttest.h index 05b387f3a..143c367b6 100644 --- a/ut_assert/inc/uttest.h +++ b/ut_assert/inc/uttest.h @@ -50,6 +50,29 @@ */ void UtTest_Add(void (*Test)(void), void (*Setup)(void), void (*Teardown)(void), const char *TestName); +/** + * \brief Registers a setup function + * + * This group of functions are invoked BEFORE normal test routines added with UtTest_Add. + * Within the group, functions are executed in the order registered. + * + * \param Setup Setup function, called before the test function + * \param TestName Name of function for logging purposes + */ +void UtTest_AddSetup(void (*Setup)(void), const char *SequenceName); + +/** + * \brief Registers a teardown function + * + * This group of functions is invoked AFTER normal test routines added with UtTest_Add. + * Within the group, functions are executed in the order registered. + * + * \param Teardown Teardown function, called before the test function + * \param TestName Name of function for logging purposes + */ +void UtTest_AddTeardown(void (*Teardown)(void), const char *SequenceName); + + /** * \brief Early initialization function * diff --git a/ut_assert/src/utbsp.c b/ut_assert/src/utbsp.c index f028455ef..ee68f3183 100644 --- a/ut_assert/src/utbsp.c +++ b/ut_assert/src/utbsp.c @@ -240,7 +240,7 @@ void OS_Application_Run(void) */ void OS_Application_Startup(void) { - + UtTest_EarlyInit(); UT_BSP_Setup(); /* diff --git a/ut_assert/src/utglobal.h b/ut_assert/src/utglobal.h index b23098ac4..dc8cbf4f3 100644 --- a/ut_assert/src/utglobal.h +++ b/ut_assert/src/utglobal.h @@ -55,7 +55,7 @@ typedef struct typedef struct { - UtListHead_t DataBase; + UtListHead_t *DataBasePtr; uint32 ExecutedCount; } UtAssert_Global_t; diff --git a/ut_assert/src/utlist.c b/ut_assert/src/utlist.c index 6942bc5ca..328503f37 100644 --- a/ut_assert/src/utlist.c +++ b/ut_assert/src/utlist.c @@ -37,138 +37,165 @@ * Function Definitions */ -UtListHead_t *UtList_Create(void) +UtListHead_t *UtList_Create(uint32 NumTags) { - UtListHead_t *NewList; + struct ListAllocator + { + UtListHead_t Head; + UtListNode_t Tags[]; + }; + struct ListAllocator *NewList; + UtListNode_t *TagHead; + size_t ActualSize; + uint32 i; + + ActualSize = sizeof(struct ListAllocator) + (sizeof(UtListNode_t) * NumTags); + NewList = (struct ListAllocator *)malloc(ActualSize); + + memset(NewList, 0, ActualSize); + + NewList->Head.Tags = NewList->Tags; + NewList->Head.NumberOfTags = NumTags; + + for (i=0; i < NumTags; ++i) + { + TagHead = &NewList->Head.Tags[i]; + TagHead->Tag = i; + TagHead->Next = TagHead; + TagHead->Prev = TagHead; + } - NewList = malloc(sizeof(UtListHead_t)); - NewList->First = NULL; - NewList->Last = NULL; - NewList->NumberOfEntries = 0; - return (NewList); + return (&NewList->Head); } void UtList_Destroy(UtListHead_t *ListHead) { - UtList_Reset(ListHead); + uint32 i; + + for (i=0; i < ListHead->NumberOfTags; ++i) + { + UtList_Reset(&ListHead->Tags[i]); + } free(ListHead); } -void UtList_Reset(UtListHead_t *ListHead) +void UtList_Reset(UtListNode_t *TagHead) { - while (!UtList_IsEmpty(ListHead)) { - UtList_DeleteFirst(ListHead); + while (!UtList_IsEmpty(TagHead)) + { + UtList_DeleteNode(TagHead->Next); } } -void UtList_Add(UtListHead_t *ListHead, void *Data, uint32 DataSize, uint32 Tag) +void UtList_Merge(UtListNode_t *TagHead1, UtListNode_t *TagHead2) { - UtListNode_t *NewNode = NULL; - - NewNode = malloc(sizeof(UtListNode_t)); - if (ListHead->NumberOfEntries == 0) { - - ListHead->First = NewNode; - ListHead->Last = NewNode; - ListHead->NumberOfEntries++; + UtListNode_t *Tail1 = TagHead1->Prev; + UtListNode_t *Tail2 = TagHead2->Prev; - NewNode->Next = NULL; - NewNode->Prev = NULL; - NewNode->Tag = Tag; - NewNode->DataSize = DataSize; - NewNode->Data = malloc(DataSize); - memcpy(NewNode->Data, Data, DataSize); - } - else { + Tail1->Next = TagHead2; + Tail2->Next = TagHead1; + TagHead1->Prev = Tail2; + TagHead2->Prev = Tail1; +} - NewNode->Next = NULL; - NewNode->Prev = ListHead->Last; - NewNode->Tag = Tag; - NewNode->DataSize = DataSize; - NewNode->Data = malloc(DataSize); - memcpy(NewNode->Data, Data, DataSize); +void UtList_Insert_After(UtListNode_t *ExistingNode, UtListNode_t *NewNode) +{ + NewNode->Next = ExistingNode->Next; + NewNode->Prev = ExistingNode; + NewNode->Prev->Next = NewNode; + NewNode->Next->Prev = NewNode; +} - ListHead->Last->Next = NewNode; - ListHead->Last = NewNode; - ListHead->NumberOfEntries++; - } +void UtList_Insert_Before(UtListNode_t *ExistingNode, UtListNode_t *NewNode) +{ + NewNode->Next = ExistingNode; + NewNode->Prev = ExistingNode->Prev; + NewNode->Prev->Next = NewNode; + NewNode->Next->Prev = NewNode; } -void UtList_DeleteFirst(UtListHead_t *ListHead) +void UtList_Extract(UtListNode_t *ExistingNode) { - UtList_DeleteNode(ListHead, ListHead->First); + ExistingNode->Next->Prev = ExistingNode->Prev; + ExistingNode->Prev->Next = ExistingNode->Next; + ExistingNode->Next = ExistingNode; + ExistingNode->Prev = ExistingNode; } -void UtList_DeleteLast(UtListHead_t *ListHead) +UtListNode_t *UtList_NewNode(void *Data, uint32 DataSize) { - UtList_DeleteNode(ListHead, ListHead->Last); + union NodeAllocator + { + UtListNode_t Node; + double AlignDbl; + void* AlignPtr; + long AlignLong; + } *AllocNode; + + AllocNode = malloc(sizeof(union NodeAllocator) + DataSize); + memset(AllocNode, 0, sizeof(union NodeAllocator)); + AllocNode->Node.Data = &AllocNode[1]; + AllocNode->Node.DataSize = DataSize; + memcpy(AllocNode->Node.Data, Data, DataSize); + + AllocNode->Node.Next = &AllocNode->Node; + AllocNode->Node.Prev = &AllocNode->Node; + + return &AllocNode->Node; } -void UtList_DeleteNode(UtListHead_t *ListHead, UtListNode_t *DeleteNode) + +void UtList_Add(UtListHead_t *ListHead, void *Data, uint32 DataSize, uint32 Tag) { - - if (!UtList_IsEmpty(ListHead)) { - - if (ListHead->NumberOfEntries == 1) { - ListHead->First = NULL; - ListHead->Last = NULL; - ListHead->NumberOfEntries = 0; - } - else if (DeleteNode == ListHead->First) { - ListHead->First = DeleteNode->Next; - ListHead->First->Prev = NULL; - ListHead->NumberOfEntries--; - } - else if (DeleteNode == ListHead->Last) { - ListHead->Last = DeleteNode->Prev; - ListHead->Last->Next = NULL; - ListHead->NumberOfEntries--; - } - else { - DeleteNode->Prev->Next = DeleteNode->Next; - DeleteNode->Next->Prev = DeleteNode->Prev; - ListHead->NumberOfEntries--; - } - - free(DeleteNode->Data); - free(DeleteNode); + UtListNode_t *TagHead; + UtListNode_t *NewNode; + + TagHead = UtList_GetHead(ListHead, Tag); + if (TagHead != NULL) + { + NewNode = UtList_NewNode(Data, DataSize); + NewNode->Tag = Tag; + UtList_Insert_Before(TagHead, NewNode); } } -void UtList_RemoveFirst(UtListHead_t *ListHead, void *Data) +void UtList_DeleteNode(UtListNode_t *DeleteNode) { - UtList_RemoveNode(ListHead, Data, ListHead->First); + UtList_Extract(DeleteNode); + + /* non-data/header nodes shouldn't be free()'ed */ + if (DeleteNode->Data != NULL) + { + free(DeleteNode); + } } -void UtList_RemoveLast(UtListHead_t *ListHead, void *Data) +bool UtList_IsEmpty(UtListNode_t *TagHead) { - UtList_RemoveNode(ListHead, Data, ListHead->Last); + return(TagHead->Next == TagHead); } -void UtList_RemoveNode(UtListHead_t *ListHead, void *Data, UtListNode_t *CurrentNode) +UtListNode_t *UtList_GetHead(UtListHead_t *ListHead, uint32 Tag) { - if (!UtList_IsEmpty(ListHead)) { - memcpy(Data, CurrentNode->Data, CurrentNode->DataSize); - UtList_DeleteNode(ListHead, CurrentNode); + if (Tag >= ListHead->NumberOfTags) + { + return NULL; } + return &ListHead->Tags[Tag]; } -UtListNode_t *UtList_First(UtListHead_t *ListHead) +UtListNode_t *UtList_GetNext(UtListNode_t *ListNode) { - return(ListHead->First); + return ListNode->Next; } -UtListNode_t *UtList_Last(UtListHead_t *ListHead) +void *UtList_GetObject(UtListNode_t *ListNode) { - return(ListHead->Last); + return ListNode->Data; } -bool UtList_IsEmpty(UtListHead_t *ListHead) +bool UtList_IsEnd(UtListNode_t *TagHead, UtListNode_t *ListNode) { - return(ListHead->NumberOfEntries == 0); + return(TagHead == ListNode); } -uint32 UtList_Depth(UtListHead_t *ListHead) -{ - return(ListHead->NumberOfEntries); -} diff --git a/ut_assert/src/uttest.c b/ut_assert/src/uttest.c index b1c15a420..f4d1ffce1 100644 --- a/ut_assert/src/uttest.c +++ b/ut_assert/src/uttest.c @@ -35,11 +35,20 @@ */ UtAssert_Global_t UtAssert_Global; +enum +{ + UTASSERT_GROUP_DEFAULT = 0, + UTASSERT_GROUP_SETUP, + UTASSERT_GROUP_TEST, + UTASSERT_GROUP_TEARDOWN, + UTASSERT_GROUP_MAX +}; + /* * Function Definitions */ -void UtTest_Add(void (*Test)(void), void (*Setup)(void), void (*Teardown)(void), const char *TestName) +void UtTest_AddCommon(void (*Test)(void), void (*Setup)(void), void (*Teardown)(void), const char *TestName, uint32 EntryType) { UtTestDataBaseEntry_t UtTestDataBaseEntry; @@ -47,23 +56,61 @@ void UtTest_Add(void (*Test)(void), void (*Setup)(void), void (*Teardown)(void), UtTestDataBaseEntry.Test = Test; UtTestDataBaseEntry.Setup = Setup; UtTestDataBaseEntry.Teardown = Teardown; - strncpy(UtTestDataBaseEntry.TestName, TestName, sizeof(UtTestDataBaseEntry.TestName)-1); - UtList_Add(&UtAssert_Global.DataBase, &UtTestDataBaseEntry, sizeof(UtTestDataBaseEntry_t), 0); + if (TestName != NULL) + { + strncpy(UtTestDataBaseEntry.TestName, TestName, sizeof(UtTestDataBaseEntry.TestName)-1); + } + + UtList_Add(UtAssert_Global.DataBasePtr, &UtTestDataBaseEntry, sizeof(UtTestDataBaseEntry_t), EntryType); +} + +void UtTest_Add(void (*Test)(void), void (*Setup)(void), void (*Teardown)(void), const char *SequenceName) +{ + UtTest_AddCommon(Test, Setup, Teardown, SequenceName, UTASSERT_GROUP_TEST); +} + +void UtTest_AddSetup(void (*Setup)(void), const char *SequenceName) +{ + UtTest_AddCommon(NULL, Setup, NULL, SequenceName, UTASSERT_GROUP_SETUP); +} + +void UtTest_AddTeardown(void (*Teardown)(void), const char *SequenceName) +{ + UtTest_AddCommon(NULL, NULL, Teardown, SequenceName, UTASSERT_GROUP_TEARDOWN); } + void UtTest_Run(void) { - uint32 i; + UtListNode_t *UtListMain; UtListNode_t *UtListNode; UtTestDataBaseEntry_t *UtTestDataBaseEntry; - if (UtAssert_Global.DataBase.NumberOfEntries > 0) { - - UtListNode = UtAssert_Global.DataBase.First; - for (i=0; i < UtAssert_Global.DataBase.NumberOfEntries; i++) { - - UtTestDataBaseEntry = UtListNode->Data; + /* + * The overall test sequence goes SETUP->TEST->TEARDOWN + * + * Combine all registered test groups into a merged group for execution. + * + * This could also (theoretically) randomize the order of the "TEST" group + * while assembling this list, if there was a portable source of entropy. + */ + UtListMain = UtList_GetHead(UtAssert_Global.DataBasePtr,UTASSERT_GROUP_DEFAULT); + UtList_Merge(UtListMain, UtList_GetHead(UtAssert_Global.DataBasePtr,UTASSERT_GROUP_SETUP)); + UtList_Merge(UtListMain, UtList_GetHead(UtAssert_Global.DataBasePtr,UTASSERT_GROUP_TEST)); + UtList_Merge(UtListMain, UtList_GetHead(UtAssert_Global.DataBasePtr,UTASSERT_GROUP_TEARDOWN)); + + /* + * Run through the merged list in order + */ + for (UtListNode = UtList_GetNext(UtListMain); + !UtList_IsEnd(UtListMain, UtListNode); + UtListNode = UtList_GetNext(UtListNode)) + { + UtTestDataBaseEntry = UtList_GetObject(UtListNode); + + if (UtTestDataBaseEntry != NULL) + { UtAssert_BeginTest(UtTestDataBaseEntry->TestName); UtAssert_SetContext(UTASSERT_CASETYPE_TSF); @@ -74,12 +121,10 @@ void UtTest_Run(void) if (UtTestDataBaseEntry->Teardown) { UtTestDataBaseEntry->Teardown(); } UtAssert_EndTest(); - - UtListNode = UtListNode->Next; } } - UtList_Reset(&UtAssert_Global.DataBase); + UtList_Destroy(UtAssert_Global.DataBasePtr); UT_BSP_EndTest(UtAssert_GetCounters()); } @@ -90,6 +135,7 @@ void UtTest_EarlyInit(void) * Reset the test global variables, just in case. */ memset(&UtAssert_Global, 0, sizeof(UtAssert_Global)); + UtAssert_Global.DataBasePtr = UtList_Create(UTASSERT_GROUP_MAX); } From 34e097804cd97f23fd6d068625e857402f46ed1a Mon Sep 17 00:00:00 2001 From: yammajamma <63457333+yammajamma@users.noreply.github.com> Date: Thu, 13 Aug 2020 20:08:35 -0400 Subject: [PATCH 2/4] Fix #379, Add FileSysAddFixedMap functional API test (#489) --- .../file-sys-add-fixed-map-api-test.c | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/tests/file-sys-add-fixed-map-api-test/file-sys-add-fixed-map-api-test.c diff --git a/src/tests/file-sys-add-fixed-map-api-test/file-sys-add-fixed-map-api-test.c b/src/tests/file-sys-add-fixed-map-api-test/file-sys-add-fixed-map-api-test.c new file mode 100644 index 000000000..bd0ea7ec8 --- /dev/null +++ b/src/tests/file-sys-add-fixed-map-api-test/file-sys-add-fixed-map-api-test.c @@ -0,0 +1,108 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * 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. + */ + + +/* + * Filename: file-sys-add-fixed-map-api-test.c + * + * Purpose: This file contains functional tests for "osapi-FileSysAddFixedMap" + * + */ + +#include +#include +#include +#include "common_types.h" +#include "osapi.h" +#include "utassert.h" +#include "uttest.h" +#include "utbsp.h" + + +/* *************************************** MAIN ************************************** */ + +void TestFileSysAddFixedMapApi(void) +{ + int32 expected; + int32 actual; + uint32 fs_id; + char translated_path[OS_MAX_LOCAL_PATH_LEN]; + + /* Test for nominal inputs */ + + /* + * This test case requires a fixed virtual dir for one test case. + * Just map /test to a dir of the same name, relative to current dir. + */ + + expected = OS_FS_ERR_PATH_INVALID; + actual = OS_TranslatePath("/test/myfile.txt", translated_path); + UtAssert_True(actual == expected, "OS_TranslatePath() (%ld) == OS_SUCCESS", (long)actual); + + expected = OS_SUCCESS; + actual = OS_FileSysAddFixedMap(&fs_id, "./test", "/test"); + UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_SUCCESS", (long)actual); + + expected = OS_SUCCESS; + actual = OS_TranslatePath("/test/myfile.txt", translated_path); + UtAssert_True(actual == expected, "OS_TranslatePath() (%ld) == OS_SUCCESS", (long)actual); + + /* Test for invalid inputs */ + expected = OS_ERR_NAME_TAKEN; + actual = OS_FileSysAddFixedMap(NULL, "./test", "/test"); + UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_FileSysAddFixedMap(&fs_id, NULL, "/test"); + UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_FileSysAddFixedMap(&fs_id, "./test", NULL); + UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_FileSysAddFixedMap(NULL, NULL, NULL); + UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_FileSysAddFixedMap(&fs_id, NULL, NULL); + UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_FileSysAddFixedMap(NULL, "./test", NULL); + UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual); + + +} /* end TestFileSysAddFixedMapApi */ + + +void UtTest_Setup(void) +{ + if (OS_API_Init() != OS_SUCCESS) + { + UtAssert_Abort("OS_API_Init() failed"); + } + + /* + * Register the test setup and check routines in UT assert + */ + UtTest_Add(TestFileSysAddFixedMapApi, NULL, NULL, "TestFileSysAddFixedMapApi"); +} + From 187b424f6a90d38bef53606dfab5474e3165e532 Mon Sep 17 00:00:00 2001 From: yammajamma <63457333+yammajamma@users.noreply.github.com> Date: Tue, 18 Aug 2020 10:49:24 -0400 Subject: [PATCH 3/4] Fix #373, Add OSAL network APIs missing functional tests and fix #378 OS_TimedRead and OS_TimedWrite missing functional tests (#549) --- src/tests/network-api-test/network-api-test.c | 624 ++++++++++++++++++ 1 file changed, 624 insertions(+) create mode 100644 src/tests/network-api-test/network-api-test.c diff --git a/src/tests/network-api-test/network-api-test.c b/src/tests/network-api-test/network-api-test.c new file mode 100644 index 000000000..a92cef5d5 --- /dev/null +++ b/src/tests/network-api-test/network-api-test.c @@ -0,0 +1,624 @@ +/* + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" + * + * Copyright (c) 2019 United States Government as represented by + * the Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * 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. + */ + + +/* + * Filename: network-api-test.c + */ + +#include +#include +#include + +#include "common_types.h" +#include "osapi.h" +#include "utassert.h" +#include "uttest.h" +#include "utbsp.h" + +#define UT_EXIT_LOOP_MAX 100 + +uint32 s_task_id; +uint32 p1_socket_id; +uint32 p2_socket_id; +uint32 s_socket_id; +uint32 c_socket_id; +OS_SockAddr_t p1_addr; +OS_SockAddr_t p2_addr; +OS_SockAddr_t s_addr; +OS_SockAddr_t c_addr; + +/***************************************************************************** + * + * Datagram Network Functional Test Setup + * + *****************************************************************************/ + +void TestDatagramNetworkApi_Setup(void) +{ + int32 expected; + int32 actual; + uint32 socket_id; + OS_SockAddr_t addr; + OS_SockAddr_t inv_addr; + + /* Open a peer1 socket */ + expected = OS_SUCCESS; + p1_socket_id = 0; + + actual = OS_SocketOpen(&p1_socket_id, OS_SocketDomain_INET, OS_SocketType_DATAGRAM); + UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(p1_socket_id != 0, "p1_socket_id (%lu) != 0", (unsigned long)p1_socket_id); + + /* Initialize peer1 address */ + actual = OS_SocketAddrInit(&p1_addr, OS_SocketDomain_INET); + UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); + + /* Set peer1 port */ + actual = OS_SocketAddrSetPort(&p1_addr, 9999); + UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); + + /* Set peer1 address */ + actual = OS_SocketAddrFromString(&p1_addr, "127.0.0.1"); + UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); + + /* Bind peer1 socket to address */ + actual = OS_SocketBind(p1_socket_id, &p1_addr); + UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_SUCCESS", (long)actual); + + + /* Open a peer2 socket */ + expected = OS_SUCCESS; + p2_socket_id = 0; + + actual = OS_SocketOpen(&p2_socket_id, OS_SocketDomain_INET, OS_SocketType_DATAGRAM); + UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(p2_socket_id != 0, "p2_socket_id (%lu) != 0", (unsigned long)p2_socket_id); + + /* Initialize peer2 address */ + actual = OS_SocketAddrInit(&p2_addr, OS_SocketDomain_INET); + UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); + + /* Set peer2 port */ + actual = OS_SocketAddrSetPort(&p2_addr, 9998); + UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); + + /* Set peer2 address */ + actual = OS_SocketAddrFromString(&p2_addr, "127.0.0.1"); + UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); + + /* Bind peer2 socket to address */ + actual = OS_SocketBind(p2_socket_id, &p2_addr); + UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_SUCCESS", (long)actual); + + /* + * Test for invalid and other nominal input parameters + * to the network functions being called above + */ + + /* OS_SocketOpen */ + actual = OS_SocketOpen(&socket_id, OS_SocketDomain_INET6, OS_SocketType_DATAGRAM); + UtAssert_True(actual == OS_SUCCESS || OS_ERR_NOT_IMPLEMENTED, "OS_SocketOpen() (%ld) Passed", (long)actual); + OS_close(socket_id); + + expected = OS_INVALID_POINTER; + actual = OS_SocketOpen(NULL, OS_SocketDomain_INVALID, OS_SocketType_INVALID); + UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_ERR_NOT_IMPLEMENTED; + actual = OS_SocketOpen(&socket_id, OS_SocketDomain_MAX, OS_SocketType_MAX); + UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_ERR_NOT_IMPLEMENTED", (long)actual); + + /* OS_SocketAddrInit */ + actual = OS_SocketAddrInit(&addr, OS_SocketDomain_INET6); + UtAssert_True(actual == OS_SUCCESS || OS_ERR_NOT_IMPLEMENTED, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); + + actual = OS_SocketAddrInit(NULL, OS_SocketDomain_INET6); + UtAssert_True(actual == OS_INVALID_POINTER || OS_ERR_NOT_IMPLEMENTED, "OS_SocketAddrInit() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_ERR_NOT_IMPLEMENTED; + actual = OS_SocketAddrInit(&addr, OS_SocketDomain_INVALID); + UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_ERR_NOT_IMPLEMENTED", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketAddrInit(NULL, OS_SocketDomain_INVALID); + UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_INVALID_POINTER", (long)actual); + + /* OS_SocketAddrSetPort */ + expected = OS_ERR_BAD_ADDRESS; + actual = OS_SocketAddrSetPort(&addr, 0xFFFF); + UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_ERR_BAD_ADDRESS", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketAddrSetPort(NULL, 1234); + UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_INVALID_POINTER", (long)actual); + + /* OS_SocketAddrFromString */ + expected = OS_INVALID_POINTER; + actual = OS_SocketAddrFromString(NULL, "127.0.0.1"); + UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); + + /* OS_SocketBind */ + expected = OS_ERR_INVALID_ID; + actual = OS_SocketBind(1, &addr); + UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_ERR_INVALID_ID", (long)actual); + + expected = OS_ERR_INCORRECT_OBJ_STATE; + memset(&inv_addr,0,sizeof(inv_addr)); + actual = OS_SocketBind(p2_socket_id, &inv_addr); + UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); + +} /* end TestDatagramNetworkApi_Setup */ + +/***************************************************************************** + * + * Datagram Network Functional Test + * + *****************************************************************************/ +void TestDatagramNetworkApi(void) +{ + char AddrBuffer1[32]; + char AddrBuffer2[32]; + char AddrBuffer3[32]; + char AddrBuffer4[32]; + uint32 Buf1 = 111; + uint32 Buf2 = 000; + uint32 Buf3 = 222; + uint32 Buf4 = 000; + uint32 objid = 0; + uint16 PortNum; + OS_socket_prop_t prop; + OS_SockAddr_t l_addr; + int32 expected; + int32 actual; + + /* + * Send data from peer1 to peer2 and verify + */ + + /* Send data from peer1 to peer2 */ + expected = sizeof(Buf1); + actual = OS_SocketSendTo(p1_socket_id, &Buf1, sizeof(Buf1), &p2_addr); + UtAssert_True(actual == expected, "OS_SocketSendTo() Passed. sizeof(Buf1) (%ld) == 1", (long)actual); + + /* Recieve data from peer1 to peer2 */ + expected = sizeof(Buf2); + actual = OS_SocketRecvFrom(p2_socket_id, &Buf2, sizeof(Buf2), &l_addr, 100); + UtAssert_True(actual == expected, "OS_SocketRecvFrom() Passed. sizeof(Buf2) (%ld) == 1", (long)actual); + UtAssert_True(Buf1 == Buf2, "Buf1 (%ld) == Buf2 (%ld)", (long)Buf1, (long)Buf2); + + /* Convert addresses to string and verify data is being sent from the correct address */ + expected = OS_SUCCESS; + + actual = OS_SocketAddrToString(AddrBuffer1, sizeof(AddrBuffer1), &p1_addr); + UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_SUCCESS", (long)actual); + + actual = OS_SocketAddrToString(AddrBuffer2, sizeof(AddrBuffer2), &l_addr); + UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_SUCCESS", (long)actual); + + UtAssert_True(strcmp(AddrBuffer1, AddrBuffer2) == 0, "AddrBuffer1 (%s) == AddrBuffer2 (%s)", AddrBuffer1, AddrBuffer2); + + /* + * Send data from peer2 to peer1 and verify + */ + + /* Send data from peer2 to peer1 */ + expected = sizeof(Buf3); + actual = OS_SocketSendTo(p2_socket_id, &Buf3, sizeof(Buf3), &p1_addr); + UtAssert_True(actual == expected, "OS_SocketSendTo() Passed. sizeof(Buf1) (%ld) == 1", (long)actual); + + /* Recieve data from peer2 to peer1 */ + expected = sizeof(Buf4); + actual = OS_SocketRecvFrom(p1_socket_id, &Buf4, sizeof(Buf4), &l_addr, 100); + UtAssert_True(actual == expected, "OS_SocketRecvFrom() Passed. sizeof(Buf3) (%ld) == 1", (long)actual); + UtAssert_True(Buf3 == Buf4, "Buf3 (%ld) == Buf4 (%ld)", (long)Buf3, (long)Buf4); + + /* Convert addresses to string and verify data is being sent from the correct address */ + expected = OS_SUCCESS; + + actual = OS_SocketAddrToString(AddrBuffer3, sizeof(AddrBuffer3), &p2_addr); + UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_SUCCESS", (long)actual); + + actual = OS_SocketAddrToString(AddrBuffer4, sizeof(AddrBuffer4), &l_addr); + UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_SUCCESS", (long)actual); + + UtAssert_True(strcmp(AddrBuffer3, AddrBuffer4) == 0, "AddrBuffer3 (%s) == AddrBuffer4 (%s)", AddrBuffer3, AddrBuffer4); + + /* Get port from incoming address and verify */ + actual = OS_SocketAddrGetPort(&PortNum, &p2_addr); + UtAssert_True(actual == expected, "OS_SocketAddrGetPort() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(PortNum == 9998, "PortNum (%ld) == 9998", (long)actual); + + /* Get socket info and verify */ + actual = OS_SocketGetInfo(p1_socket_id, &prop); + UtAssert_True(actual == expected, "OS_SocketGetInfo() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(prop.creator == 0, "prop.creator (%lu) == 0",(unsigned long)prop.creator); + UtAssert_True(strcmp(prop.name, "127.0.0.1:9999") == 0, "prop.name (%s) == 127.0.0.1:9999", prop.name); + + actual = OS_SocketGetIdByName(&objid,"127.0.0.1:9999"); + UtAssert_True(actual == expected, "OS_SocketGetIdByName() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(objid == p1_socket_id, "objid (%ld) == p1_socket_id", (long)objid); + + /* + * Test for invalid input parameters + * to the network functions being called above + */ + + /* OS_SocketSendTo */ + expected = OS_INVALID_POINTER; + actual = OS_SocketSendTo(1, NULL, 0, NULL); + UtAssert_True(actual == expected, "OS_SocketSendTo(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketSendTo(p1_socket_id, NULL, 1, &p2_addr); + UtAssert_True(actual == expected, "OS_SocketSendTo() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_ERR_INVALID_ID; + actual = OS_SocketSendTo(0xFFFFFFF, &Buf1, 1, &p2_addr); + UtAssert_True(actual == expected, "OS_SocketSendTo() (%ld) == OS_ERR_INVALID_ID", (long)actual); + + /* OS_SocketRecvFrom */ + expected = OS_INVALID_POINTER; + actual = OS_SocketRecvFrom(p2_socket_id, NULL, 1, NULL, 100); + UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketRecvFrom(1, NULL, 0, NULL, 0); + UtAssert_True(actual == expected, "OS_SocketRecvFrom(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_ERR_INVALID_ID; + actual = OS_SocketRecvFrom(1, &Buf2, 1, &l_addr, 100); + UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_ERR_INVALID_ID", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketRecvFrom(p2_socket_id, &Buf2, 0, &l_addr, 100); + UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketRecvFrom(p2_socket_id, &Buf2, 0, NULL, 100); + UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_INVALID_POINTER", (long)actual); + + /* OS_SocketAddrToString */ + expected = OS_INVALID_POINTER; + actual = OS_SocketAddrToString(NULL, 0, NULL); + UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketAddrToString(AddrBuffer1, sizeof(AddrBuffer1), NULL); + UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketAddrToString(0, 0, &p2_addr); + UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_INVALID_POINTER", (long)actual); + + /* OS_SocketAddrGetPort */ + expected = OS_INVALID_POINTER; + actual = OS_SocketAddrGetPort(NULL, NULL); + UtAssert_True(actual == expected, "OS_SocketAddrGetPort() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketAddrGetPort(0, &l_addr); + UtAssert_True(actual == expected, "OS_SocketAddrGetPort() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketAddrGetPort(&PortNum, NULL); + UtAssert_True(actual == expected, "OS_SocketAddrGetPort() (%ld) == OS_INVALID_POINTER", (long)actual); + + /* OS_SocketGetIdByName */ + expected = OS_INVALID_POINTER; + actual = OS_SocketGetIdByName(NULL,NULL); + UtAssert_True(actual == expected, "OS_SocketGetIdByName() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_ERR_NAME_NOT_FOUND; + actual = OS_SocketGetIdByName(&objid,"NF"); + UtAssert_True(actual == expected, "OS_SocketGetIdByName() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); + + /* OS_SocketGetInfo */ + expected = OS_INVALID_POINTER; + actual = OS_SocketGetInfo(1, NULL); + UtAssert_True(actual == expected, "OS_SocketGetInfo() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_ERR_INVALID_ID; + actual = OS_SocketGetInfo(0, &prop); + UtAssert_True(actual == expected, "OS_SocketGetInfo() (%ld) == OS_ERR_INVALID_ID", (long)actual); + +} /* end TestDatagramNetworkApi */ + +/***************************************************************************** + * + * Datagram Network Teardown + * + *****************************************************************************/ +void TestDatagramNetworkApi_Teardown(void) +{ + /* Close sockets */ + OS_close(p1_socket_id); + OS_close(p2_socket_id); + +} /* end TestDatagramNetworkApi_Teardown */ + + +/***************************************************************************** + * + * Server Function for Stream Network Functional Test + * + *****************************************************************************/ +void Server_Fn(void) +{ + uint32 connsock_id = 0; + uint32 iter; + OS_SockAddr_t addr; + char Buf_rcv_s[4] = {0}; + char Buf_trans[8] ={0}; + uint8 Buf_each_char_s[256] = {0}; + + + /* Accept incoming connections */ + OS_SocketAccept(s_socket_id, &connsock_id, &addr, OS_PEND); + + /* Recieve incoming data from client*/ + OS_TimedRead(connsock_id, Buf_rcv_s, sizeof(Buf_rcv_s), 10); + + /* Transform the incoming data and send it back to client */ + strcpy(Buf_trans, "uvw"); + strcat(Buf_trans, Buf_rcv_s); + OS_TimedWrite(connsock_id, Buf_trans, sizeof(Buf_trans), 10); + + /* Send all 256 chars to client */ + for (iter = 0; iter < 256; iter++) + { + Buf_each_char_s[iter] = iter; + } + + OS_TimedWrite(connsock_id, Buf_each_char_s, sizeof(Buf_each_char_s), 10); + + OS_close(s_socket_id); + OS_close(connsock_id); + + +} /* end Server_Fn */ + + +/***************************************************************************** + * + * Stream Network Functional Test + * + *****************************************************************************/ +void TestStreamNetworkApi(void) +{ + int32 status; + int32 expected; + int32 actual; + uint32 iter; + uint32 loopcnt; + uint32 temp_id; + OS_SockAddr_t temp_addr; + OS_task_prop_t taskprop; + char Buf_rcv_c[4] = {0}; + char Buf_send_c[4] = {0}; + char Buf_rcv_trans[8] = {0}; + char Buf_expec_trans[8] ={0}; + uint8 Buf_each_expected[256] = {0}; + uint8 Buf_each_char_rcv[256] = {0}; + + + /* + * Set up a server + */ + + /* Open a server socket */ + s_socket_id = 0; + expected = OS_SUCCESS; + actual = OS_SocketOpen(&s_socket_id, OS_SocketDomain_INET, OS_SocketType_STREAM); + UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(s_socket_id != 0, "s_socket_id (%lu) != 0", (unsigned long)s_socket_id); + + /* Initialize server address */ + actual = OS_SocketAddrInit(&s_addr, OS_SocketDomain_INET); + UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); + + /* Set server port */ + actual = OS_SocketAddrSetPort(&s_addr, 9997); + UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); + + /* Set server address */ + actual = OS_SocketAddrFromString(&s_addr, "127.0.0.1"); + UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); + + /* Bind server socket to server address */ + actual = OS_SocketBind(s_socket_id, &s_addr); + UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_SUCCESS", (long)actual); + + /* + * Set up a client + */ + + /* Open a client socket */ + expected = OS_SUCCESS; + c_socket_id = 0; + + actual = OS_SocketOpen(&c_socket_id, OS_SocketDomain_INET, OS_SocketType_STREAM); + UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(c_socket_id != 0, "c_socket_id (%lu) != 0", (unsigned long)c_socket_id); + + /* Initialize client address */ + actual = OS_SocketAddrInit(&c_addr, OS_SocketDomain_INET); + UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); + + /* Set client port */ + actual = OS_SocketAddrSetPort(&c_addr, 9996); + UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); + + /* Set client address */ + actual = OS_SocketAddrFromString(&c_addr, "127.0.0.1"); + UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); + + /* + * Create a server thread, and connect client from + * this thread to server thread and verify connection + */ + + /* Create a server task/thread */ + status = OS_TaskCreate( &s_task_id, "Server", Server_Fn, 0, 16384, 50, 0); + UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); + + /* Connect to a server */ + actual = OS_SocketConnect(c_socket_id, &s_addr, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); + + + /* + * Test for invalid input parameters + */ + + /* OS_TimedRead */ + expected = OS_ERR_INVALID_ID; + actual = OS_TimedRead(1, Buf_rcv_c, sizeof(Buf_rcv_c), 10); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld",(long)actual, (long)expected); + + expected = OS_INVALID_POINTER; + actual = OS_TimedRead(c_socket_id, NULL, sizeof(Buf_rcv_c), 10); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld",(long)actual, (long)expected); + + expected = OS_ERROR_TIMEOUT; + actual = OS_TimedRead(c_socket_id, Buf_rcv_c, sizeof(Buf_rcv_c), 0); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld",(long)actual, (long)expected); + + /* OS_TimedWrite */ + expected = OS_ERR_INVALID_ID; + actual = OS_TimedWrite(1, Buf_rcv_c, sizeof(Buf_rcv_c), 10); + UtAssert_True(actual == expected, "OS_TimedWrite() (%ld) == %ld",(long)actual, (long)expected); + + expected = OS_INVALID_POINTER; + actual = OS_TimedWrite(c_socket_id, NULL, sizeof(Buf_rcv_c), 10); + UtAssert_True(actual == expected, "OS_TimedWrite() (%ld) == %ld",(long)actual, (long)expected); + + /* OS_SocketAccept */ + expected = OS_INVALID_POINTER; + actual = OS_SocketAccept(1, NULL, NULL, 0); + UtAssert_True(actual == expected, "OS_SocketAccept() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketAccept(s_socket_id, NULL, &temp_addr, 10); + UtAssert_True(actual == expected, "OS_SocketAccept() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketAccept(s_socket_id, &temp_id, NULL, 10); + UtAssert_True(actual == expected, "OS_SocketAccept() (%ld) == OS_INVALID_POINTER", (long)actual); + + /* OS_SocketConnect */ + expected = OS_INVALID_POINTER; + actual = OS_SocketConnect(c_socket_id, NULL, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_ERR_INCORRECT_OBJ_STATE; + actual = OS_SocketConnect(c_socket_id, &s_addr, 0); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); + + expected = OS_ERR_INVALID_ID; + actual = OS_SocketConnect(1, &s_addr, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_ERR_INVALID_ID", (long)actual); + + /* + * Once connection is made between + * server and client, transfer data + */ + + /* Send data to server to be transformed and sent back */ + strcpy(Buf_send_c, "xyz"); + expected = sizeof(Buf_send_c); + actual = OS_TimedWrite(c_socket_id, Buf_send_c, sizeof(Buf_send_c), 10); + UtAssert_True(actual == expected, "OS_TimedWrite() (%ld) == %ld",(long)actual, (long)expected); + + /* Recieve back transformed data from server*/ + expected = sizeof(Buf_expec_trans); + strcpy(Buf_expec_trans, "uvwxyz"); + + actual = OS_TimedRead(c_socket_id, Buf_rcv_trans, sizeof(Buf_rcv_trans), 10); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld",(long)actual, (long)expected); + UtAssert_True(strcmp(Buf_rcv_trans, Buf_expec_trans) == 0, "Buf_rcv_trans (%s) == Buf_expected (%s)", Buf_rcv_trans, Buf_expec_trans); + + /* Recieve all 256 chars from server one at a time */ + expected = sizeof(Buf_each_char_rcv); + actual = OS_TimedRead(c_socket_id, Buf_each_char_rcv, sizeof(Buf_each_char_rcv), 10); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld",(long)actual, (long)expected); + + /* Verify all 256 chars received */ + for (iter = 0; iter < 256; iter++) + { + Buf_each_expected[iter] = iter; + } + + UtAssert_True(memcmp(Buf_each_expected,Buf_each_char_rcv,sizeof(Buf_each_expected)) == 0, "buffer content match"); + + + /* Once connection socket is closed, verify that no data is recieved */ + expected = 0; + actual = OS_TimedRead(c_socket_id, Buf_rcv_c, sizeof(Buf_rcv_c), 10); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld",(long)actual, (long)expected); + + + /* + * NOTE: Tests for invalid and other nominal input parameters + * to some of the network functions being called here are already + * tested in TestDatagramNetworkApi_Setup() + */ + + + /* Looping delay in parent task to wait for child task to exit */ + loopcnt = 0; + while ((OS_TaskGetInfo(s_task_id, &taskprop) == OS_SUCCESS) && (loopcnt < UT_EXIT_LOOP_MAX)) + { + OS_TaskDelay(10); + loopcnt++; + } + UtAssert_True(loopcnt < UT_EXIT_LOOP_MAX, "Task exited after %ld iterations", (long)loopcnt); + +} /* end TestStreamNetworkApi */ + + +/***************************************************************************** + * + * Stream Network Teardown + * + *****************************************************************************/ +void TestStreamNetworkApi_Teardown(void) +{ + /* Close sockets */ + OS_close(c_socket_id); + +} /* end TestStreamNetworkApi_Teardown */ + + + +void UtTest_Setup(void) +{ + if (OS_API_Init() != OS_SUCCESS) + { + UtAssert_Abort("OS_API_Init() failed"); + } + + /* + * Register the test setup and check routines in UT assert + */ + UtTest_Add(TestDatagramNetworkApi, TestDatagramNetworkApi_Setup, TestDatagramNetworkApi_Teardown, "TestDatagramNetworkApi"); + UtTest_Add(TestStreamNetworkApi, NULL, TestStreamNetworkApi_Teardown, "TestStreamNetworkApi"); +} + From 783663cdfbc015da68d6bd0e6b803340a54caba0 Mon Sep 17 00:00:00 2001 From: astrogeco <59618057+astrogeco@users.noreply.github.com> Date: Tue, 18 Aug 2020 14:23:37 -0400 Subject: [PATCH 4/4] Increase version to 5.1.0-rc1+dev5 and update ReadMe --- README.md | 17 ++++++++++++----- src/os/inc/osapi-version.h | 20 ++++++++++---------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ce37ef13f..96e67f1cb 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,14 @@ The autogenerated OSAL user's guide can be viewed at + + ### Development Build: 5.0.0+dev247 - `OS_SocketOpen()` sets `sock_id` and returns a status when successful. @@ -19,7 +27,7 @@ The autogenerated OSAL user's guide can be viewed at ### Development Build: 5.0.16 @@ -215,4 +223,3 @@ See all open issues and closed to milestones later than this version. For best results, submit issues:questions or issues:help wanted requests at . Official cFS page: - diff --git a/src/os/inc/osapi-version.h b/src/os/inc/osapi-version.h index 7794b62b6..1b6a36ae3 100644 --- a/src/os/inc/osapi-version.h +++ b/src/os/inc/osapi-version.h @@ -22,16 +22,16 @@ * @brief Purpose: * @details Provide version identifiers for cFS' Operating System Abstraction Layer * See @ref cfsversions for version and build number and description - * + * */ #ifndef _osapi_version_h_ #define _osapi_version_h_ /* - * Development Build Macro Definitions + * Development Build Macro Definitions */ -#define OS_BUILD_NUMBER 247 -#define OS_BUILD_BASELINE "v5.0.0+dev" +#define OS_BUILD_NUMBER 5 +#define OS_BUILD_BASELINE "v5.1.0-rc1+dev" /* * Version Macro Definitions @@ -43,26 +43,26 @@ /* * Tools to construct version string - */ + */ #define OS_STR_HELPER(x) #x /*!< @brief Helper function to concatenate strings from integer */ #define OS_STR(x) OS_STR_HELPER(x) /*!< @brief Helper function to concatenate strings from integer */ -/*! @brief Development Build Version Number. +/*! @brief Development Build Version Number. * @details Baseline git tag + Number of commits since baseline. @n * See @ref cfsversions for format differences between development and release versions. */ -#define OS_VERSION OS_BUILD_BASELINE OS_STR(OS_BUILD_NUMBER) +#define OS_VERSION OS_BUILD_BASELINE OS_STR(OS_BUILD_NUMBER) /*! @brief Development Build Version String. * @details Reports the current development build's baseline, number, and name. Also includes a note about the latest official version. @n - * See @ref cfsversions for format differences between development and release versions. -*/ + * See @ref cfsversions for format differences between development and release versions. +*/ #define OS_VERSION_STRING \ " OSAL Development Build\n" \ " " OS_VERSION " (Codename: Bootes)\n" /* Codename for current development */ \ " Latest Official Version: osal v5.0.0" /* For full support please use official release version */ -/*! @brief Combines the revision components into a single value +/*! @brief Combines the revision components into a single value * @details Applications can check against this number @n * e.g. "#if OSAL_API_VERSION >= 40100" would check if some feature added in OSAL 4.1 is present.