From 5cf325b128c3931652f332fd0bd59f3a3924a1b2 Mon Sep 17 00:00:00 2001 From: Yasir Khan Date: Wed, 3 Jun 2020 16:06:51 -0400 Subject: [PATCH 1/3] Fix #379, Add FileSysAddFixedMap functional API test --- .../file-sys-add-fixed-map-api-test.c | 78 +++++++++++++++++++ 1 file changed, 78 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..0e3a7c321 --- /dev/null +++ b/src/tests/file-sys-add-fixed-map-api-test/file-sys-add-fixed-map-api-test.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + */ + +/* + * 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; + + /* 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_SUCCESS; + actual = OS_FileSysAddFixedMap(&fs_id, "./test", "/test"); + UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_SUCCESS", (long)actual); + + /* Test for invalid inputs */ + expected = OS_INVALID_POINTER; + actual = OS_FileSysAddFixedMap(NULL, NULL, NULL); + UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_SUCCESS", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_FileSysAddFixedMap(&fs_id, NULL, NULL); + UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_SUCCESS", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_FileSysAddFixedMap(&fs_id, "./test", NULL); + UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_SUCCESS", (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 662a8c18986409fd00bfd9a8df8a1b239be6a1c9 Mon Sep 17 00:00:00 2001 From: Yasir Khan Date: Thu, 6 Aug 2020 11:33:44 -0400 Subject: [PATCH 2/3] WIP --- .../file-sys-add-fixed-map-api-test.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 index 0e3a7c321..47bd1e3de 100644 --- 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 @@ -35,6 +35,8 @@ void TestFileSysAddFixedMapApi(void) int32 expected; int32 actual; uint32 fs_id; + char virtual_path[OS_MAX_LOCAL_PATH_LEN]; + char translated_path[OS_MAX_LOCAL_PATH_LEN]; /* Test for nominal inputs */ /* @@ -42,10 +44,17 @@ void TestFileSysAddFixedMapApi(void) * Just map /test to a dir of the same name, relative to current dir. */ + strcpy(virtual_path, "/test"); expected = OS_SUCCESS; - actual = OS_FileSysAddFixedMap(&fs_id, "./test", "/test"); + actual = OS_TranslatePath(virtual_path, translated_path); + + expected = OS_SUCCESS; + actual = OS_FileSysAddFixedMap(&fs_id, "./test", virtual_path); UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_SUCCESS", (long)actual); + expected = OS_SUCCESS; + actual = OS_TranslatePath(virtual_path, translated_path); + /* Test for invalid inputs */ expected = OS_INVALID_POINTER; actual = OS_FileSysAddFixedMap(NULL, NULL, NULL); From c26479d833fba6237c8766971a405253640d0b45 Mon Sep 17 00:00:00 2001 From: Yasir Khan Date: Mon, 10 Aug 2020 10:47:02 -0400 Subject: [PATCH 3/3] Updated branch with requested changes --- .../file-sys-add-fixed-map-api-test.c | 59 +++++++++++++------ 1 file changed, 40 insertions(+), 19 deletions(-) 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 index 47bd1e3de..bd0ea7ec8 100644 --- 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 @@ -1,13 +1,24 @@ /* - * Copyright (c) 2020, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. + * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * 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 * @@ -18,7 +29,6 @@ #include #include #include - #include "common_types.h" #include "osapi.h" #include "utassert.h" @@ -26,8 +36,6 @@ #include "utbsp.h" - - /* *************************************** MAIN ************************************** */ void TestFileSysAddFixedMapApi(void) @@ -35,38 +43,51 @@ void TestFileSysAddFixedMapApi(void) int32 expected; int32 actual; uint32 fs_id; - char virtual_path[OS_MAX_LOCAL_PATH_LEN]; 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. */ - strcpy(virtual_path, "/test"); - expected = OS_SUCCESS; - actual = OS_TranslatePath(virtual_path, translated_path); + 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", virtual_path); + actual = OS_FileSysAddFixedMap(&fs_id, "./test", "/test"); UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_SUCCESS", (long)actual); expected = OS_SUCCESS; - actual = OS_TranslatePath(virtual_path, translated_path); + 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_SUCCESS", (long)actual); + 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_SUCCESS", (long)actual); + 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_SUCCESS", (long)actual); + actual = OS_FileSysAddFixedMap(NULL, "./test", NULL); + UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual); } /* end TestFileSysAddFixedMapApi */