diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2016-11-23 19:09:09 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2016-11-23 19:09:09 +0900 |
commit | 4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (patch) | |
tree | 98110734c91668dfdbb126fcc0e15ddbd93738ca /src/pal/tests/palsuite/c_runtime | |
parent | fa45f57ed55137c75ac870356a1b8f76c84b229c (diff) | |
download | coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.gz coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.bz2 coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.zip |
Imported Upstream version 1.1.0upstream/1.1.0
Diffstat (limited to 'src/pal/tests/palsuite/c_runtime')
1582 files changed, 51457 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/c_runtime/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/CMakeLists.txt new file mode 100644 index 0000000000..533454c285 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/CMakeLists.txt @@ -0,0 +1,162 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(abs) +add_subdirectory(acos) +add_subdirectory(asin) +add_subdirectory(atan) +add_subdirectory(atan2) +add_subdirectory(atof) +add_subdirectory(atoi) +add_subdirectory(atol) +add_subdirectory(bsearch) +add_subdirectory(ceil) +add_subdirectory(cos) +add_subdirectory(cosh) + +# TODO: make this test compile +# add_subdirectory(ctime) + +add_subdirectory(errno) +add_subdirectory(exit) +add_subdirectory(exp) +add_subdirectory(fabs) +add_subdirectory(fabsf) +add_subdirectory(fclose) +add_subdirectory(feof) +add_subdirectory(ferror) +add_subdirectory(fflush) +add_subdirectory(fgets) +add_subdirectory(floor) +add_subdirectory(fmod) +add_subdirectory(fmodf) +add_subdirectory(fopen) +add_subdirectory(fprintf) +add_subdirectory(fputs) +add_subdirectory(fread) +add_subdirectory(free) +add_subdirectory(fseek) +add_subdirectory(ftell) +add_subdirectory(fwprintf) +add_subdirectory(fwrite) +add_subdirectory(getc) +add_subdirectory(getenv) +add_subdirectory(isalnum) +add_subdirectory(isalpha) +add_subdirectory(isdigit) +add_subdirectory(islower) +add_subdirectory(isprint) +add_subdirectory(isspace) +add_subdirectory(isupper) +add_subdirectory(iswdigit) +add_subdirectory(iswspace) +add_subdirectory(iswupper) +add_subdirectory(iswxdigit) +add_subdirectory(isxdigit) +add_subdirectory(labs) +add_subdirectory(llabs) +add_subdirectory(localtime) +add_subdirectory(log) +add_subdirectory(log10) +add_subdirectory(malloc) +add_subdirectory(memchr) +add_subdirectory(memcmp) +add_subdirectory(memcpy) +add_subdirectory(memmove) +add_subdirectory(memset) +add_subdirectory(modf) +add_subdirectory(modff) +add_subdirectory(pow) +add_subdirectory(printf) +add_subdirectory(qsort) +add_subdirectory(rand_srand) +add_subdirectory(realloc) +add_subdirectory(sin) +add_subdirectory(sinh) +add_subdirectory(sprintf) +add_subdirectory(sqrt) +add_subdirectory(sscanf) +add_subdirectory(strcat) +add_subdirectory(strchr) +add_subdirectory(strcmp) +add_subdirectory(strcpy) +add_subdirectory(strcspn) +add_subdirectory(strlen) +add_subdirectory(strncat) +add_subdirectory(strncmp) +add_subdirectory(strncpy) +add_subdirectory(strpbrk) +add_subdirectory(strrchr) +add_subdirectory(strspn) +add_subdirectory(strstr) +add_subdirectory(strtod) +add_subdirectory(strtok) +add_subdirectory(strtoul) +add_subdirectory(swprintf) +add_subdirectory(swscanf) +add_subdirectory(tan) +add_subdirectory(tanh) +add_subdirectory(time) +add_subdirectory(tolower) +add_subdirectory(toupper) +add_subdirectory(towlower) +add_subdirectory(towupper) +add_subdirectory(ungetc) +add_subdirectory(vfprintf) +add_subdirectory(vprintf) +add_subdirectory(vsprintf) +add_subdirectory(vswprintf) +add_subdirectory(wcscat) +add_subdirectory(wcschr) +add_subdirectory(wcscmp) +add_subdirectory(wcscpy) +add_subdirectory(wcslen) +add_subdirectory(wcsncat) +add_subdirectory(wcsncmp) +add_subdirectory(wcsncpy) +add_subdirectory(wcspbrk) +add_subdirectory(wcsrchr) +add_subdirectory(wcsstr) +add_subdirectory(wcstod) +add_subdirectory(wcstok) +add_subdirectory(wcstol) +add_subdirectory(wcstoul) +add_subdirectory(wprintf) +add_subdirectory(_alloca) +add_subdirectory(_ecvt) +add_subdirectory(_fdopen) +add_subdirectory(_finite) +add_subdirectory(_fullpath) + +# TODO: make this test compile +# add_subdirectory(_gcvt) + +add_subdirectory(_getw) +add_subdirectory(_isnan) +add_subdirectory(_itow) +add_subdirectory(_makepath) +add_subdirectory(_mbsdec) +add_subdirectory(_mbsinc) +add_subdirectory(_mbslen) +add_subdirectory(_mbsninc) +add_subdirectory(_open_osfhandle) +add_subdirectory(_putenv) +add_subdirectory(_putw) +add_subdirectory(_rotl) +add_subdirectory(_rotr) +add_subdirectory(_snprintf) +add_subdirectory(_snwprintf) +add_subdirectory(_splitpath) +add_subdirectory(_stricmp) +add_subdirectory(_strlwr) +add_subdirectory(_strnicmp) +add_subdirectory(_swab) +add_subdirectory(_vsnprintf) +add_subdirectory(_vsnwprintf) +add_subdirectory(_wcsicmp) +add_subdirectory(_wcslwr) +add_subdirectory(_wcsnicmp) +add_subdirectory(_wfopen) +add_subdirectory(_wmakepath) +add_subdirectory(_wsplitpath) +add_subdirectory(_wtoi) +add_subdirectory(__iscsym) diff --git a/src/pal/tests/palsuite/c_runtime/__iscsym/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/__iscsym/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/__iscsym/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/c_runtime/__iscsym/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/__iscsym/test1/CMakeLists.txt new file mode 100644 index 0000000000..a283161f7d --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/__iscsym/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + __iscsym.c +) + +add_executable(paltest_iscsym_test1 + ${SOURCES} +) + +add_dependencies(paltest_iscsym_test1 coreclrpal) + +target_link_libraries(paltest_iscsym_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/__iscsym/test1/__iscsym.c b/src/pal/tests/palsuite/c_runtime/__iscsym/test1/__iscsym.c new file mode 100644 index 0000000000..9c8f1d0f25 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/__iscsym/test1/__iscsym.c @@ -0,0 +1,93 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================= +** +** Source: __iscsym.c +** +** Purpose: Positive test the __iscsym API. +** Call __iscsym to letter, digit and underscore +** +** +**============================================================*/ +#include <palsuite.h> + +int __cdecl main(int argc, char *argv[]) +{ + int err; + int index; + char non_letter_set[]= + {'~','`','!','@','#','$','%','^','&','*','(',')',')', + '-','+','=','|','\\',';',':','"','\'','<','>', + ',','.','?','/','\0'}; + char errBuffer[200]; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*To check if the parameter passed in is a character*/ + for(index = 'a'; index <= 'z'; index++) + { + err = __iscsym(index); + if(0 == err) + { + Fail("\n__iscsym failed to recognize a " + "lower-case letter:%c!\n", index); + } + } + + /*To check if the parameter passed in is a character*/ + for(index = 'A'; index <= 'Z'; index++) + { + err = __iscsym(index); + if(0 == err) + { + Fail("\n__iscsym failed to recognize an " + "upper-case letter: %c!\n", index); + } + } + + /*To check if the parameter passed in is a digit*/ + for(index = '0'; index <= '9'; index++) + { + err = __iscsym(index); + if(0 == err) + { + Fail("\n__iscsym failed to recognize a digit %c!\n", + index); + } + } + + /*To check if the parameter passed in is a underscore*/ + err = __iscsym('_'); + if(0 == err) + { + Fail("\n__iscsym failed to recognize an underscore!\n"); + } + + memset(errBuffer, 0, 200); + + for(index = 0; non_letter_set[index]; index++) + { + err = __iscsym(non_letter_set[index]); + if(0 != err) + { + strncat(errBuffer, &non_letter_set[index], 1); + strcat(errBuffer, ", "); + } + } + + if(strlen(errBuffer) > 0) + { + Fail("\n__iscsym failed to identify the characters '%s' " + "as not letters, digits " + "or underscores\n", errBuffer); + } + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/__iscsym/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/__iscsym/test1/testinfo.dat new file mode 100644 index 0000000000..e6668edccf --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/__iscsym/test1/testinfo.dat @@ -0,0 +1,12 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = __iscsym +Name = Positive test for __iscsym to test letter, digit and underscore +TYPE = DEFAULT +EXE1 = __iscsym +Description +=Test the __iscsym to test letter, digit and underscore diff --git a/src/pal/tests/palsuite/c_runtime/_alloca/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_alloca/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_alloca/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/c_runtime/_alloca/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_alloca/test1/CMakeLists.txt new file mode 100644 index 0000000000..236b356185 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_alloca/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_alloca_test1 + ${SOURCES} +) + +add_dependencies(paltest_alloca_test1 coreclrpal) + +target_link_libraries(paltest_alloca_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_alloca/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_alloca/test1/test1.c new file mode 100644 index 0000000000..c533d84234 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_alloca/test1/test1.c @@ -0,0 +1,62 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================ +** +** Source: test1.c +** +** Purpose: Checks that _alloca allocates memory, and that the memory is +** readable and writeable. +** +** +**==========================================================================*/ + +#include <palsuite.h> + +int __cdecl main(int argc, char **argv) +{ + + char *testA = NULL; + int i = 0; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + + /* check that _alloca really gives us addressable memory */ + testA = (char *)_alloca(20 * sizeof(char)); + if (testA == NULL) + { + Fail ("The call to _alloca failed\n"); + } + + memset(testA, 'a', 20); + + for (i = 0; i < 20; i++) + { + if (testA[i] != 'a') + { + Fail ("The memory returned by _alloca doesn't seem to be" + " properly allocated\n"); + } + } + + PAL_Terminate(); + return PASS; +} + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/_alloca/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_alloca/test1/testinfo.dat new file mode 100644 index 0000000000..e21562195e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_alloca/test1/testinfo.dat @@ -0,0 +1,13 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _alloca +Name = Positive Test for _alloca +TYPE = DEFAULT +EXE1 = test1 +Description += Checks that _alloca allocates memory, and that the memory is += readable and writeable. diff --git a/src/pal/tests/palsuite/c_runtime/_ecvt/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_ecvt/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_ecvt/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/c_runtime/_ecvt/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_ecvt/test1/CMakeLists.txt new file mode 100644 index 0000000000..86f4547b2b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_ecvt/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_ecvt_test1 + ${SOURCES} +) + +add_dependencies(paltest_ecvt_test1 coreclrpal) + +target_link_libraries(paltest_ecvt_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_ecvt/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_ecvt/test1/test1.c new file mode 100644 index 0000000000..fbcf11ecfc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_ecvt/test1/test1.c @@ -0,0 +1,135 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: c_runtime/_ecvt/test1/test1.c +** +** Purpose: Call the _ecvt function on a number of cases. Check that it +** handles negatives, positives and double bounds correctly. Also check that +** the 'digit' specification works. +** +** +**===================================================================*/ + +#include <palsuite.h> + +#define INT64_TO_DOUBLE(a) (*(double*)&a) + +INT64 NaN = 0x7ff8000000000000; +INT64 NegativeInfinity = 0xfff0000000000000; +INT64 NegativeSmall = 0x8000000000000001; +INT64 PositiveInfinity = 0x7ff0000000000000; +INT64 PositiveSmall = 0x0000000000000001; + +struct testCase +{ + double value; /* number to be converted */ + int precision; /* number of digits to be stored */ + int decimal; /* (expected) decimal point position for stored + * number */ + int sign; /* (expected) return value */ + char expResult[256]; /* (expected) character array to be returned + * NOTE: this necessarily limits precision + * to a value between 0 and 255 */ + char bsdExpResult[256]; /* (expected) character array to be returned + * NOTE: this necessarily limits precision + * to a value between 0 and 255 */ +}; + +int __cdecl main(int argc, char **argv) +{ + char *result; + int testDecimal; + int testSign; + int i=0; + + struct testCase testCases[] = + { + /* odd ball values */ + {INT64_TO_DOUBLE(NaN), 7, 1, 0, "1#QNAN0" }, + /* positive values */ + {0, 0, 0, 0, ""}, + {INT64_TO_DOUBLE(PositiveSmall), 17, -323, 0, + "49406564584124654"}, + {.00123, 3, -2, 0, "123"}, + {.123, 3, 0, 0, "123"}, + {123, 3, 3, 0, "123"}, + {3.1415926535, 9, 1, 0, "314159265"}, + {3.1415926535, 10, 1, 0, "3141592654"}, + {3.1415926535, 11, 1, 0, "31415926535"}, + {3.1415926535, 12, 1, 0, "314159265350"}, + {184467444073709570000.0, 21, 21, 0, "184467444073709570000", + "184467444073709568000" }, + {184467444073709570000.0, 22, 21, 0, "1844674440737095700000", + "1844674440737095680000" }, + {INT64_TO_DOUBLE(PositiveInfinity), 7, 1, 0, "1#INF00" }, + /* negative values */ + {-0, 0, 0, 0, ""}, + {INT64_TO_DOUBLE(NegativeSmall), 17, -323, 1, + "49406564584124654"}, + {-.00123, 3, -2, 1, "123"}, + {-.123, 3, 0, 1, "123"}, + {-123, 3, 3, 1, "123"}, + {-3.1415926535, 9, 1, 1, "314159265"}, + {-3.1415926535, 10, 1, 1, "3141592654"}, + {-3.1415926535, 11, 1, 1, "31415926535"}, + {-3.1415926535, 12, 1, 1, "314159265350"}, + {-184467444073709570000.0, 21, 21, 1, "184467444073709570000", + "184467444073709568000" }, + {-184467444073709570000.0, 22, 21, 1, "1844674440737095700000", + "1844674440737095680000" }, + {INT64_TO_DOUBLE(NegativeInfinity), 7, 1, 1, "1#INF00"} + + }; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Loop through each case. Call _ecvt on each test case and check the + result. + */ + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + result = _ecvt(testCases[i].value, + testCases[i].precision, + &testDecimal, + &testSign); + + if (( strcmp(testCases[i].expResult, result) != 0 && + strcmp(testCases[i].bsdExpResult, result) != 0 ) || + + ( testCases[i].sign != testSign ) || + ( testCases[i].decimal != testDecimal )) + + { + Fail("PALSUITE ERROR: Test %d\n" + "-----------------------\n" + "testCases[i].value = '%f'\n" + "testCases[i].precision = '%d'\n" + "testCases[i].decimal = '%d'\n" + "testCases[i].sign = '%d'\n" + "testCases[i].expResult = '%s'\n" + "result = '%s'\n" + "testDecimal = '%d'\n" + "testSign = '%d'\n\n", + i, + testCases[i].value, + testCases[i].precision, + testCases[i].decimal, + testCases[i].sign, + testCases[i].expResult, + result, + testDecimal, + testSign); + } + + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_ecvt/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_ecvt/test1/testinfo.dat new file mode 100644 index 0000000000..12e7292ec7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_ecvt/test1/testinfo.dat @@ -0,0 +1,14 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _ecvt +Name = Call _ecvt on normal values, negatives, exponents and hex digits. +TYPE = DEFAULT +EXE1 = test1 +Description += Call the _ecvt function on a number of cases. Check that it += handles negatives, positives and double bounds correctly. Also check that += the 'digit' specification works. diff --git a/src/pal/tests/palsuite/c_runtime/_fdopen/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_fdopen/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_fdopen/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/c_runtime/_fdopen/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_fdopen/test1/CMakeLists.txt new file mode 100644 index 0000000000..441d32bd5c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_fdopen/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_fdopen_test1 + ${SOURCES} +) + +add_dependencies(paltest_fdopen_test1 coreclrpal) + +target_link_libraries(paltest_fdopen_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_fdopen/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_fdopen/test1/test1.c new file mode 100644 index 0000000000..b88267c6e4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_fdopen/test1/test1.c @@ -0,0 +1,112 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: test1.c (fdopen) +** +** Purpose: Tests the PAL implementation of the fdopen function. +** This will test fdopen in r (read) mode. This test +** creates and opens a test pipe, to write and read +** from. fdopen requires a file handle(int), therefore +** _open_osfhandle is used to get that handle. +** _open_osfhandle is only used with CreatePipe. The +** test will write and read from the pipe comparing +** the results. +** +** See /tests/palsuite/README.txt for more information. +** +** +**===================================================================*/ + +#include <palsuite.h> + +const char* cTestString = "one fish, two fish, read fish, blue fish."; + +int __cdecl main(int argc, char **argv) +{ + HANDLE hReadPipe = NULL; + HANDLE hWritePipe = NULL; + BOOL bRetVal = FALSE; + int iFiledes = 0; + DWORD dwBytesWritten; + char buffer[45]; + FILE *fp; + + SECURITY_ATTRIBUTES lpPipeAttributes; + + /*Initialize the PAL*/ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ + lpPipeAttributes.nLength = sizeof(lpPipeAttributes); + lpPipeAttributes.lpSecurityDescriptor = NULL; + lpPipeAttributes.bInheritHandle = TRUE; + + /*Create a Pipe*/ + bRetVal = CreatePipe(&hReadPipe, // read handle + &hWritePipe, // write handle + &lpPipeAttributes, // security attributes + 0); // pipe size + + if (bRetVal == FALSE) + { + Fail("ERROR: unable to create pipe"); + } + + /*Write to the write pipe handle*/ + bRetVal = WriteFile(hWritePipe, // handle to file + cTestString, // data buffer + (DWORD)strlen(cTestString), // number of bytes to write + &dwBytesWritten, // number of bytes written + NULL); // overlapped buffer + + if (bRetVal == FALSE) + { + Fail("ERROR: unable to write to pipe write handle " + "hWritePipe=0x%lx", hWritePipe); + } + + /*Get a file descriptor for the read pipe handle*/ + iFiledes = _open_osfhandle((long)hReadPipe, _O_RDONLY); + + if (iFiledes == -1) + { + Fail("ERROR: _open_osfhandle failed to open " + " hReadPipe=0x%lx", hReadPipe); + } + + /*Open read pipe handle in read mode*/ + fp = _fdopen(iFiledes, "r"); + + if (fp == NULL) + { + Fail("ERROR: unable to fdopen file descriptor" + " iFiledes=%d", iFiledes); + } + + /*Read from the read pipe handle*/ + if((fread(buffer, sizeof(char), strlen(cTestString), fp)) == 0) + { + Fail("ERROR: Unable to read from file stream fp=0x%lx\n", fp); + } + + /*Compare what was read with what was written.*/ + if ((memcmp(cTestString, buffer, strlen(cTestString))) != 0) + { + Fail("ERROR: read \"%s\" expected \"%s\" \n", buffer, cTestString); + } + + /*Close the file handle*/ + if (_close(iFiledes) != 0) + { + Fail("ERROR: Unable to close file handle iFiledes=%d\n", iFiledes); + } + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/c_runtime/_fdopen/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_fdopen/test1/testinfo.dat new file mode 100644 index 0000000000..89e48bb4c1 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_fdopen/test1/testinfo.dat @@ -0,0 +1,23 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = fdopen +Name = test for fdopen and _close +TYPE = DEFAULT +EXE1 = test1 +Description += Tests the PAL implementation of the fdopen function. += This will test fdopen in r (read) mode. This test += creates and opens a test pipe, to write and read += from. fdopen requires a file handle(int), therefore += _open_osfhandle is used to get that handle. += _open_osfhandle is only used with CreatePipe. The += test will write and read from the pipe comparing += the results. += As a secondary test, _close is tested since it needs += the handle returned by _open_osfhandle. The handle is += closed, then a read is attempted on the handle which += should fail. diff --git a/src/pal/tests/palsuite/c_runtime/_finite/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_finite/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_finite/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/_finite/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_finite/test1/CMakeLists.txt new file mode 100644 index 0000000000..8aca58a8dc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_finite/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_finite_test1 + ${SOURCES} +) + +add_dependencies(paltest_finite_test1 coreclrpal) + +target_link_libraries(paltest_finite_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_finite/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_finite/test1/test1.c new file mode 100644 index 0000000000..c815055b38 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_finite/test1/test1.c @@ -0,0 +1,119 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================ +** +** Source: test1.c +** +** Purpose: Checks that _finite correctly classifies all types +** of floating point numbers (NaN, -Infinity, Infinity, +** finite nonzero, unnormalized, 0, and -0) +** +**==========================================================================*/ + +#include <palsuite.h> + +/* +The IEEE double precision floating point standard looks like this: + + S EEEEEEEEEEE FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF + 0 1 11 12 63 + +S is the sign bit. The E bits are the exponent, and the 52 F bits are +the fraction. These represent a value, V. + +If E=2047 and F is nonzero, then V=NaN ("Not a number") +If E=2047 and F is zero and S is 1, then V=-Infinity +If E=2047 and F is zero and S is 0, then V=Infinity +If 0<E<2047 then V=(-1)^S * 2^(E-1023) * (1.F) where "1.F" is the binary + number created by prefixing F with a leading 1 and a binary point. +If E=0 and F is nonzero, then V=(-1)^S * 2^(-1022) * (0.F) These are + "unnormalized" values. +If E=0 and F is zero and S is 1, then V=-0 +If E=0 and F is zero and S is 0, then V=0 + +*/ + +#define TO_DOUBLE(x) (*((double*)((void*)&x))) + +int __cdecl main(int argc, char **argv) +{ + /*non-finite numbers*/ + UINT64 lsnan = UI64(0xffffffffffffffff); + UINT64 lqnan = UI64(0x7fffffffffffffff); + UINT64 lneginf = UI64(0xfff0000000000000); + UINT64 lposinf = UI64(0x7ff0000000000000); + + double snan = TO_DOUBLE(lsnan); + double qnan = TO_DOUBLE(lqnan); + double neginf = TO_DOUBLE(lneginf); + double posinf = TO_DOUBLE(lposinf); + + /*finite numbers*/ + UINT64 lnegunnormalized = UI64(0x800fffffffffffff); + UINT64 lposunnormalized = UI64(0x000fffffffffffff); + UINT64 lnegzero = UI64(0x8000000000000000); + + double negunnormalized = TO_DOUBLE(lnegunnormalized); + double posunnormalized = TO_DOUBLE(lposunnormalized); + double negzero = TO_DOUBLE(lnegzero); + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + /*non-finite numbers*/ + if (_finite(snan) || _finite(qnan)) + { + Fail("_finite() found NAN to be finite.\n"); + } + + if (_finite(neginf)) + { + Fail("_finite() found negative infinity to be finite.\n"); + } + + if (_finite(posinf)) + { + Fail("_finite() found infinity to be finite.\n"); + } + + /*finite numbers*/ + if (!_finite(negunnormalized)) + { + Fail("_finite() found a negative unnormalized value to be infinite.\n"); + } + + if (!_finite(posunnormalized)) + { + Fail("_finite() found an unnormalized value to be infinite.\n"); + } + + if (!_finite(negzero)) + { + Fail("_finite() found negative zero to be infinite.\n"); + } + + if (!_finite(+0.0)) + { + Fail("_finite() found zero to be infinite.\n"); + } + + if (!_finite(-123.456)) + { + Fail("_finite() found %f to be infinite.\n", -123.456); + } + + if (!_finite(+123.456)) + { + Fail("_finite() found %f to be infinite.\n", +123.456); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_finite/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_finite/test1/testinfo.dat new file mode 100644 index 0000000000..cec0f8ae4a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_finite/test1/testinfo.dat @@ -0,0 +1,13 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _finite +Name = Positive Test for _finite +TYPE = DEFAULT +EXE1 = test1 +Description += Checks that _finite correctly classifies all types of floating point += numbers (NaN, -Infinity, Infinity, finite nonzero, unnormalized, 0, and -0). diff --git a/src/pal/tests/palsuite/c_runtime/_fullpath/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_fullpath/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_fullpath/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/c_runtime/_fullpath/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_fullpath/test1/CMakeLists.txt new file mode 100644 index 0000000000..9306efa700 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_fullpath/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_fullpath_test1 + ${SOURCES} +) + +add_dependencies(paltest_fullpath_test1 coreclrpal) + +target_link_libraries(paltest_fullpath_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_fullpath/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_fullpath/test1/test1.c new file mode 100644 index 0000000000..f390f4309b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_fullpath/test1/test1.c @@ -0,0 +1,181 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================ +** +** Source: _fullpath/test1/test1.c +** +** Purpose: Test to see if the _fullpath function returns the +** proper values. A check is done to ensure NULL is returned +** by _fullpath only for the condition where the length of the +** created absolute path name (absPath) is greater than +** maxLength. +** +** Dependencies: strlen +** strncmp +** SetCurrentDirectory +** GetCurrentDirectory +** + +** +**=========================================================*/ + +#include <palsuite.h> + +struct testcase +{ + char relPath[50]; /* relative path array */ + int maxLength; /* pathlength to pass */ + BOOL bRet; /* TRUE if testcase expects function to return NULL */ +}; + +int __cdecl main( int argc, char **argv ) +{ + + DWORD dwOrigDirLength; + DWORD dwNewDirLength; + DWORD dwRetStrLength; + BOOL bRet; + char *retPath; + char szAbsPath[_MAX_PATH + 1]; + char szDirNameOWD[_MAX_DIR]; + char szDirNameNWD[_MAX_DIR]; + int i; + + struct testcase testcases[]= + { + {"." , _MAX_PATH, FALSE}, + {".." , _MAX_PATH, FALSE}, + {"..\\..", _MAX_PATH, FALSE}, + {"..\\..\\..", _MAX_PATH, FALSE}, + {"..", 1, TRUE} + }; + + if(0 != (PAL_Initialize(argc, argv))) + { + return ( FAIL ); + } + + for (i = 0; i < sizeof(testcases)/sizeof(struct testcase) ; i++) + { + + /* reset variables */ + memset(szAbsPath, 0, _MAX_PATH + 1); + memset(szDirNameOWD, 0, _MAX_DIR); + memset(szDirNameNWD, 0, _MAX_DIR); + + dwOrigDirLength = 0; + dwNewDirLength = 0; + dwRetStrLength = 0; + + /* Get the current directory name */ + dwOrigDirLength = GetCurrentDirectory(_MAX_PATH, szDirNameOWD); + if (0 == dwOrigDirLength) + { + Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." + "\nGetCurrentDirectory (%d, %s) call failed. GetLastError" + " returned '%d'\n", testcases[i].relPath, + testcases[i].maxLength, _MAX_PATH, szDirNameOWD, + GetLastError()); + } + + /* + * Set the current directory to relPath. + */ + bRet = SetCurrentDirectory(testcases[i].relPath); + if (0 == bRet) + { + Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." + "\nSetCurrentDirectory (%s) call failed. GetLastError" + " returned '%d'\n", testcases[i].relPath, + testcases[i].maxLength, testcases[i].relPath, + GetLastError()); + } + + /* Get the new current directory name */ + dwNewDirLength = GetCurrentDirectory(_MAX_PATH, szDirNameNWD); + if (0 == dwNewDirLength) + { + Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." + "\nGetCurrentDirectory(%d, %s) call failed. GetLastError" + " returned '%d'\n", testcases[i].relPath, + testcases[i].maxLength, _MAX_PATH, szDirNameNWD, + GetLastError()); + } + + /* Set the current directory back to the original one */ + bRet = SetCurrentDirectory(szDirNameOWD); + if (0 == bRet) + { + Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." + "\nSetCurrentDirectory(%s) call failed. GetLastError" + " returned '%d'\n", testcases[i].relPath, + testcases[i].maxLength, szDirNameOWD, GetLastError()); + } + + retPath = _fullpath( szAbsPath, + testcases[i].relPath, + testcases[i].maxLength ); + + if ( NULL == retPath ) + { + /* The function returned NULL when a value was expected */ + if ( FALSE == testcases[i].bRet ) + { + Fail("PALSUITE ERROR: test failed.\n" + "_fullpath (char *, %s, %d) returned NULL\n" + "when '%s' was expected\n", testcases[i].relPath, + testcases[i].maxLength, szDirNameNWD ); + } + } + else + { + dwRetStrLength = strlen ( szAbsPath ); + + /* Check that the path lengths are identical. */ + if ( dwRetStrLength != dwNewDirLength ) + { + Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." + "\ndwRetStringLength '%d' is not equal to " + "dwNewDirLength '%d'.\nszAbsPath is '%s' retPath is '%s'\n" + "szDirNameNWD is '%s'\n" , testcases[i].relPath, + testcases[i].maxLength, dwRetStrLength ,dwNewDirLength + ,szAbsPath ,retPath ,szDirNameNWD); + } + + /* + * Perform a string comparison on the path provided by + * GetCurrentDirectory and the path provided by _fullpath + * to ensure they are identical. + */ + if ( 0 != strncmp( szDirNameNWD, szAbsPath, dwNewDirLength )) + { + Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." + "strncmp ( %s, %s, %d ) call failed.\n", + testcases[i].relPath, testcases[i].maxLength, + szDirNameNWD, szAbsPath, dwNewDirLength ); + } + + /* + * Perform a string comparison on both paths provided by + * _fullpath to ensure they are identical. + */ + if ( 0 != strncmp( retPath, szAbsPath, dwNewDirLength )) + { + Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed." + "strncmp ( %s, %s, %d ) call failed.\n", + testcases[i].relPath, testcases[i].maxLength, + szDirNameNWD, szAbsPath, dwNewDirLength ); + } + } + } + + PAL_Terminate(); + return ( PASS ); +} + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/_fullpath/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_fullpath/test1/testinfo.dat new file mode 100644 index 0000000000..cd4db831a4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_fullpath/test1/testinfo.dat @@ -0,0 +1,23 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = c_runtime +Function = _fullpath +Name = Positive Test for _fullpath +TYPE = DEFAULT +EXE1 = test1 +Description += Test to see if the _fullpath function returns the += proper values. A check is done to ensure NULL is returned += by _fullpath only for the condition where the length of the += created absolute path name (absPath) is greater than += maxLength. + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/_gcvt/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_gcvt/CMakeLists.txt new file mode 100644 index 0000000000..ef14ea5352 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_gcvt/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test2) + diff --git a/src/pal/tests/palsuite/c_runtime/_gcvt/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_gcvt/test1/CMakeLists.txt new file mode 100644 index 0000000000..33eb5cf19c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_gcvt/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + _gcvt.c +) + +add_executable(paltest_gcvt_test1 + ${SOURCES} +) + +add_dependencies(paltest_gcvt_test1 coreclrpal) + +target_link_libraries(paltest_gcvt_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_gcvt/test1/_gcvt.c b/src/pal/tests/palsuite/c_runtime/_gcvt/test1/_gcvt.c new file mode 100644 index 0000000000..ccfc286898 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_gcvt/test1/_gcvt.c @@ -0,0 +1,58 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================= +** +** Source: _gcvt.c +** +** Purpose: Positive test the _gcvt API. +** Call _gcvt to convert a floatable value to a string +** with specified sigficant digits stored +** +** +**============================================================*/ +#include <palsuite.h> + +int __cdecl main(int argc, char *argv[]) +{ + int err; + double dValue = -3.1415926535; + char buffer[1024]; + char *pChar7 = "-3.141593"; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + + /* zero the buffer */ + memset(buffer, 0, 1024); + + + /* + + Testing + ======= + + To convert a floating-point value to + a string to save 7 significant digits + */ + _gcvt(dValue, 7, buffer); + if(strcmp(pChar7, buffer)) + { + Fail("\nFailed to call _gcvt to convert a floating-point value " + "to a string with 7 sigficants digits stored\n"); + } + + + /* + Clean up and exit + */ + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_gcvt/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_gcvt/test1/testinfo.dat new file mode 100644 index 0000000000..d527418108 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_gcvt/test1/testinfo.dat @@ -0,0 +1,13 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _gcvt +Name = Positive test for _gcvt API to convert a floatable value to a string +TYPE = DEFAULT +EXE1 = _gcvt +Description +=Test the _gcvt to convert a floatable value to a string +=with specified sigficant digits stored diff --git a/src/pal/tests/palsuite/c_runtime/_gcvt/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_gcvt/test2/CMakeLists.txt new file mode 100644 index 0000000000..05641b9b78 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_gcvt/test2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test2.c +) + +add_executable(paltest_gcvt_test2 + ${SOURCES} +) + +add_dependencies(paltest_gcvt_test2 coreclrpal) + +target_link_libraries(paltest_gcvt_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_gcvt/test2/test2.c b/src/pal/tests/palsuite/c_runtime/_gcvt/test2/test2.c new file mode 100644 index 0000000000..7ac9a4fcf0 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_gcvt/test2/test2.c @@ -0,0 +1,83 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: test2.c +** +** Purpose: Call the _gcvt function on a number of cases. Check that it +** handles negatives, exponents and hex digits properly. Also check that +** the 'digit' specification works. (And that it doesn't truncate negative +** signs or decimals) +** +** +**===================================================================*/ + +#include <palsuite.h> + +struct testCase +{ + double Value; + int Digits; + char WinCorrectResult[128]; + char BsdCorrectResult[128]; /* for the odd case where bsd sprintf + varies from windows sprintf */ +}; + +int __cdecl main(int argc, char **argv) +{ + char result[128]; + int i=0; + + struct testCase testCases[] = + { + {1234567, 7, "1234567"}, + {1234.123, 7, "1234.123"}, + {1234.1234, 7, "1234.123"}, + {12.325678e+2, 7, "1232.568"}, + {-12.3233333, 8, "-12.323333"}, + {-12.32, 8, "-12.32"}, + {-12.32e+2, 8, "-1232.", "-1232" }, + {0x21DDFABC, 8, "5.6819577e+008", "5.6819577e+08" }, + {123456789012345.0, 15, "123456789012345" }, + {12340000.0, 8, "12340000"}, + {12340000000000000.0, 15, "1.234e+016", "1.234e+16" }, + {12340000000000000.0, 17, "12340000000000000" }, + + }; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Loop through each case. Call _gcvt on each test case and check the + result. + */ + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + _gcvt(testCases[i].Value, testCases[i].Digits, result); + + if (strcmp(testCases[i].WinCorrectResult, result) != 0 && + + ( testCases[i].BsdCorrectResult && + strcmp(testCases[i].BsdCorrectResult, result) != 0 ) ) + { + Fail("ERROR: _gcvt attempted to convert %f with %d digits " + "signifigant, which resulted in " + "the string '%s' instead of the correct(Win) string '%s' or the" + "correct(bsd) string '%s'.\n", + testCases[i].Value, + testCases[i].Digits, + result, + testCases[i].WinCorrectResult, + testCases[i].BsdCorrectResult); + } + + memset(result, '\0', 128); + } + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_gcvt/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_gcvt/test2/testinfo.dat new file mode 100644 index 0000000000..e9e192849a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_gcvt/test2/testinfo.dat @@ -0,0 +1,15 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _gcvt +Name = Call _gcvt on normal values, negatives, exponents and hex digits. +TYPE = DEFAULT +EXE1 = test2 +Description += Call the _gcvt function on a number of cases. Check that it += handles negatives, exponents and hex digits properly. Also check that += the 'digit' specification works. (And that it doesn't truncate negative += signs or decimals) diff --git a/src/pal/tests/palsuite/c_runtime/_getw/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_getw/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_getw/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/c_runtime/_getw/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_getw/test1/CMakeLists.txt new file mode 100644 index 0000000000..d44477b232 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_getw/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_getw_test1 + ${SOURCES} +) + +add_dependencies(paltest_getw_test1 coreclrpal) + +target_link_libraries(paltest_getw_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_getw/test1/test.dat b/src/pal/tests/palsuite/c_runtime/_getw/test1/test.dat Binary files differnew file mode 100644 index 0000000000..b20eae054c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_getw/test1/test.dat diff --git a/src/pal/tests/palsuite/c_runtime/_getw/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_getw/test1/test1.c new file mode 100644 index 0000000000..34ce4ee7de --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_getw/test1/test1.c @@ -0,0 +1,96 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================ +** +** Source: test1.c +** +** Purpose: Several integers are read from a previously written file +** using _getw. The test passes if the values read match those known to +** be in the file. +** +** +**==========================================================================*/ + +#include <palsuite.h> + +/*Tests _getw using a previously written data file */ +int __cdecl main(int argc, char **argv) +{ + const int testValues[] = + { + 0, + 1, + -1, + 0x7FFFFFFF, /* largest positive integer on 32 bit systems */ + 0x80000000, /* largest negative integer on 32 bit systems */ + 0xFFFFFFFF, + 0xFFFFAAAA + }; + + int i = 0; + int input = 0; + + const char filename[] = "test.dat"; + + + FILE *fp = NULL; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* write the file that we will use to test */ + + + /* + Don't uncomment this code, it was used to create the data file + initially on windows, but if it is run on all test platforms, the + tests will always pass. + + fp = fopen(filename, "w"); + if (fp == NULL) + { + Fail("Unable to open file for write.\n"); + } + for (i = 0; i < sizeof(testValues) / sizeof(testValues[0]); i++) + { + _putw(testValues[i], fp); + } + + if (fclose(fp) != 0) + { + Fail("Error closing file after writing to it with _putw.\n"); + } + */ + + + /*Now read values back from the file and see if they match.*/ + fp = fopen(filename, "r"); + if (fp == NULL) + { + Fail ("Unable to open file for read.\n"); + } + for (i = 0; i < sizeof(testValues) / sizeof(testValues[0]); i++) + { + input = _getw(fp); + if (VAL32(input) != testValues[i]) + { + Fail ("_getw did not get the expected values when reading " + "from a file.\n"); + } + } + + if (fclose(fp) != 0) + { + Fail ("Error closing file after reading from it with _getw\n"); + } + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_getw/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_getw/test1/testinfo.dat new file mode 100644 index 0000000000..4044dadbcc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_getw/test1/testinfo.dat @@ -0,0 +1,15 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _getw +Name = Positive Test for _getw +TYPE = DEFAULT +EXE1 = test1 +Description +=Several integers are read from a previously written file +=using _getw. The test passes if the values read match those known to +=be in the file. + diff --git a/src/pal/tests/palsuite/c_runtime/_isnan/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_isnan/CMakeLists.txt new file mode 100644 index 0000000000..5e1ef7f28b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_isnan/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) diff --git a/src/pal/tests/palsuite/c_runtime/_isnan/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_isnan/test1/CMakeLists.txt new file mode 100644 index 0000000000..e14d0cc64b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_isnan/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_isnan_test1 + ${SOURCES} +) + +add_dependencies(paltest_isnan_test1 coreclrpal) + +target_link_libraries(paltest_isnan_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_isnan/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_isnan/test1/test1.c new file mode 100644 index 0000000000..d793c9b371 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_isnan/test1/test1.c @@ -0,0 +1,115 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================ +** +** Source: test1.c +** +** Purpose: +** Test _isnan with a number of trivial values, to ensure they indicated that +** they are numbers. Then try with Positive/Negative Infinite, which should +** also be numbers. Finally set the least and most significant bits of +** the fraction to positive and negative, at which point it should return +** the true value. +** +**==========================================================================*/ + +#include <palsuite.h> + +#define TO_DOUBLE(x) (*((double*)((void*)&x))) +#define TO_I64(x) (*((INT64*)((void*)&x))) + +/* + * NaN: any double with maximum exponent (0x7ff) and non-zero fraction + */ +int __cdecl main(int argc, char *argv[]) +{ + /* + * Initialize the PAL and return FAIL if this fails + */ + if (PAL_Initialize(argc, argv) != 0) + { + return FAIL; + } + + /* + * Try some trivial values + */ + if (_isnan(0.0)) + { + Fail("_isnan() incorrectly identified %f as NaN!\n", 0.0); + } + + if (_isnan(1.23456)) + { + Fail("_isnan() incorrectly identified %f as NaN!\n", 1.234567); + } + + if (_isnan(42.0)) + { + Fail("_isnan() incorrectly identified %f as NaN!\n", 42.0); + } + + UINT64 lneginf = UI64(0xfff0000000000000); + UINT64 lposinf = UI64(0x7ff0000000000000); + + double neginf = TO_DOUBLE(lneginf); + double posinf = TO_DOUBLE(lposinf); + + /* + * Try positive and negative infinity + */ + if (_isnan(neginf)) + { + Fail("_isnan() incorrectly identified negative infinity as NaN!\n"); + } + + if (_isnan(posinf)) + { + Fail("_isnan() incorrectly identified infinity as NaN!\n"); + } + + /* + * Try setting the least significant bit of the fraction, + * positive and negative + */ + UINT64 lsnan = UI64(0xfff0000000000001); + double snan = TO_DOUBLE(lsnan); + + if (!_isnan(snan)) + { + Fail("_isnan() failed to identify %I64x as NaN!\n", lsnan); + } + + UINT64 lqnan = UI64(0x7ff0000000000001); + double qnan = TO_DOUBLE(lqnan); + + if (!_isnan(qnan)) + { + Fail("_isnan() failed to identify %I64x as NaN!\n", lqnan); + } + + /* + * Try setting the most significant bit of the fraction, + * positive and negative + */ + lsnan = UI64(0xfff8000000000000); + snan = TO_DOUBLE(lsnan); + + if (!_isnan(snan)) + { + Fail ("_isnan() failed to identify %I64x as NaN!\n", lsnan); + } + + lqnan = UI64(0x7ff8000000000000); + qnan = TO_DOUBLE(lqnan); + + if (!_isnan(qnan)) + { + Fail ("_isnan() failed to identify %I64x as NaN!\n", lqnan); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_isnan/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_isnan/test1/testinfo.dat new file mode 100644 index 0000000000..d5de17e219 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_isnan/test1/testinfo.dat @@ -0,0 +1,16 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _isnan +Name = Test #1 for _isnan +TYPE = DEFAULT +EXE1 = test1 +Description += Test _isnan with a number of trivial values, to ensure they indicated that += they are numbers. Then try with Positive/Negative Infinite, which should += also be numbers. Finally set the least and most significant bits of += the fraction to positive and negative, at which point it should return += the true value. diff --git a/src/pal/tests/palsuite/c_runtime/_itow/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_itow/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_itow/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/c_runtime/_itow/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_itow/test1/CMakeLists.txt new file mode 100644 index 0000000000..bd37f31216 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_itow/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_itow_test1 + ${SOURCES} +) + +add_dependencies(paltest_itow_test1 coreclrpal) + +target_link_libraries(paltest_itow_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_itow/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_itow/test1/test1.c new file mode 100644 index 0000000000..745ce4acaa --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_itow/test1/test1.c @@ -0,0 +1,102 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: test1.c +** +** Purpose: Tests the PAL implementation of the _itow function. +** Test a number of ints with different radix on each, +** to ensure that the string returned is correct. +** +** +**===================================================================*/ + +#define UNICODE + +#include <palsuite.h> + +struct testCase +{ + wchar_t *CorrectResult; + int value; + int radix; +}; + +int __cdecl main(int argc, char **argv) +{ + + wchar_t result[20]; + wchar_t *pResult = NULL; + char *PrintResult = NULL; /* Use with convertC so we can */ + char *PrintCorrectResult = NULL; /* print out the results */ + int i = 0; + + WCHAR case1[] = {'5','0','\0'}; + WCHAR case2[] = {'5','5','5','\0'}; + WCHAR case3[] = {'1','0','1','0','\0'}; + WCHAR case4[] = {'2','2','\0'}; + WCHAR case5[] = {'a','\0'}; + WCHAR case6[] = {'c','g','\0'}; + + /* Correct Result, Value to Convert, Radix to use */ + struct testCase testCases[] = + { + {case1, 50, 10}, + {case2,555,10}, + {case3,10,2}, + {case4,10,4}, + {case5,10,16}, + {case6,400,32} + }; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Loop through each case. Convert the ints to strings. Check + to ensure they were converted properly. + */ + + for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) + { + pResult = _itow(testCases[i].value,result,testCases[i].radix); + + if(pResult != &result[0]) + { + Fail("ERROR: _itow didn't return a correct pointer to the " + "newly formed string.\n"); + } + + if (0 != wcscmp(testCases[i].CorrectResult,pResult)) + { + PrintResult = convertC(pResult); + PrintCorrectResult = convertC(testCases[i].CorrectResult); + Fail("ERROR: _itow was called on %i, returning the string %s " + "when it should have returned the string %s.\n" + , testCases[i].value, PrintResult, PrintCorrectResult); + } + + } + + PAL_Terminate(); + return PASS; +} + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/_itow/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_itow/test1/testinfo.dat new file mode 100644 index 0000000000..394c34dff3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_itow/test1/testinfo.dat @@ -0,0 +1,18 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _itow +Name = Positive Test for _itow +TYPE = DEFAULT +EXE1 = test1 +Description += Tests the PAL implementation of the _itow function. += Test a number of ints with different radix on each, to ensure that the += string returned is correct. + + + + diff --git a/src/pal/tests/palsuite/c_runtime/_makepath/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_makepath/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_makepath/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/c_runtime/_makepath/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_makepath/test1/CMakeLists.txt new file mode 100644 index 0000000000..9fd81cce1a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_makepath/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_makepath_test1 + ${SOURCES} +) + +add_dependencies(paltest_makepath_test1 coreclrpal) + +target_link_libraries(paltest_makepath_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_makepath/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_makepath/test1/test1.c new file mode 100644 index 0000000000..94b366a7bb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_makepath/test1/test1.c @@ -0,0 +1,65 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: test1.c +** +** Purpose: Tests the PAL implementation of the _makepath function. +** Create a path, and ensure that it builds how it is +** supposed to. +** +** +** +**===================================================================*/ + +#if WIN32 +#define PATHNAME "C:\\test\\test.txt" +#else +#define PATHNAME "/test/test.txt" +#endif + +#include <palsuite.h> + +int __cdecl main(int argc, char **argv) +{ + char FullPath[128]; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc,argv))) + { + return FAIL; + } + +#if WIN32 + _makepath(FullPath,"C","\\test","test","txt"); +#else + _makepath(FullPath,NULL,"/test","test","txt"); +#endif + + if(strcmp(FullPath,PATHNAME) != 0) + { + Fail("ERROR: The pathname which was created turned out to be %s " + "when it was supposed to be %s.\n",FullPath,PATHNAME); + } + + + PAL_Terminate(); + return PASS; +} + + + + + + + + + + + + + diff --git a/src/pal/tests/palsuite/c_runtime/_makepath/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_makepath/test1/testinfo.dat new file mode 100644 index 0000000000..2aed8e549b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_makepath/test1/testinfo.dat @@ -0,0 +1,14 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _makepath +Name = Positive Test for _makepath +TYPE = DEFAULT +EXE1 = test1 +Description += Purpose: Tests the PAL implementation of the _makepath function. += Create a path, and ensure that it builds how it is supposed to. + diff --git a/src/pal/tests/palsuite/c_runtime/_mbsdec/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_mbsdec/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbsdec/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/CMakeLists.txt new file mode 100644 index 0000000000..064f241f24 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_mbsdec_test1 + ${SOURCES} +) + +add_dependencies(paltest_mbsdec_test1 coreclrpal) + +target_link_libraries(paltest_mbsdec_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/test1.c new file mode 100644 index 0000000000..1cd7513293 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/test1.c @@ -0,0 +1,77 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================ +** +** Source: test1.c +** +** Purpose: +** Ensure that this function moves the string pointer back one character. +** First do a basic test to check that the pointer gets moved back the one +** character, given str1 and str+1 as params. Then try with both +** params being the same pointer, which should return NULL. Also test +** when the first pointer is past the second pointer, which should +** return null. Finally try this function on an array of single bytes, +** which it assumes are characters and should work in the same fashion. +** +** +**==========================================================================*/ + +#include <palsuite.h> + +/* + * Note: it seems like these functions would only be useful if they + * didn't assume a character was equivalent to a single byte. Be that + * as it may, I haven't seen a way to get it to behave otherwise. + */ + +int __cdecl main(int argc, char *argv[]) +{ + unsigned char *str1 = (unsigned char*) "foo"; + unsigned char str2[] = {0xC0, 0x80, 0xC0, 0x80, 0}; + unsigned char str3[] = {0}; + unsigned char *ret = NULL; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + ret = _mbsdec(str1,str1+1); + if (ret != str1) + { + Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, str1); + } + + ret = _mbsdec(str1,str1); + if (ret != NULL) + { + Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, NULL); + } + + ret = _mbsdec(str1+100,str1); + if (ret != NULL) + { + Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, NULL); + } + + ret = _mbsdec(str2,str2+1); + if (ret != str2) + { + Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, str2+1); + } + + ret = _mbsdec(str3,str3+10); + if (ret != str3+9) + { + Fail ("ERROR: _mbsdec returned %p. Expected %p\n", ret, str3+9); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/testinfo.dat new file mode 100644 index 0000000000..ce2aa29aa5 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbsdec/test1/testinfo.dat @@ -0,0 +1,18 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _mbsdec +Name = Positive Test for _mbsdec +TYPE = DEFAULT +EXE1 = test1 +Description += Ensure that this function moves the string pointer back one character. += First do a basic test to check that the pointer gets moved back the one += character, given str1 and str+1 as params. Then try with both += params being the same pointer, which should return NULL. Also test += when the first pointer is past the second pointer, which should += return null. Finally try this function on an array of single bytes, += which it assumes are characters and should work in the same fashion. diff --git a/src/pal/tests/palsuite/c_runtime/_mbsinc/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_mbsinc/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbsinc/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/CMakeLists.txt new file mode 100644 index 0000000000..531ba8e793 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_mbsinc_test1 + ${SOURCES} +) + +add_dependencies(paltest_mbsinc_test1 coreclrpal) + +target_link_libraries(paltest_mbsinc_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/test1.c new file mode 100644 index 0000000000..95a5041af2 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/test1.c @@ -0,0 +1,62 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================ +** +** Source: test1.c +** +** Purpose: +** Ensure that this function moves the string pointer ahead one character. +** First do a basic test to check that the pointer gets moved ahead the one +** character. Then try with an array of bytes and a NULL array. Each of +** these should still work by returning a pointer to thePointer+1. +** +** +**==========================================================================*/ + +#include <palsuite.h> + +/* + * Note: it seems like these functions would only be useful if they + * didn't assume a character was equivalent to a single byte. Be that + * as it may, I haven't seen a way to get it to behave otherwise. + */ + +int __cdecl main(int argc, char *argv[]) +{ + unsigned char *str1 = (unsigned char*) "foo"; + unsigned char str2[] = {0xC0, 0x80, 0xC0, 0x80, 0}; + unsigned char str3[] = {0}; + unsigned char *ret=NULL; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + ret = _mbsinc(str1); + if (ret != str1 + 1) + { + Fail ("ERROR: _mbsinc returned %p. Expected %p\n", ret, str1); + } + + ret = _mbsinc(str2); + if (ret != str2 + 1) + { + Fail ("ERROR: _mbsinc returned %p. Expected %p\n", ret, str1); + } + + ret = _mbsinc(str3); + if (ret != str3 + 1) + { + Fail ("ERROR: _mbsinc returned %p. Expected %p\n", ret, str1); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/testinfo.dat new file mode 100644 index 0000000000..3f3883fa31 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbsinc/test1/testinfo.dat @@ -0,0 +1,15 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _mbsinc +Name = Positive Test for _mbsinc +TYPE = DEFAULT +EXE1 = test1 +Description += Ensure that this function moves the string pointer ahead one character. += First do a basic test to check that the pointer gets moved ahead the one += character. Then try with an array of bytes and a NULL array. Each of += these should still work by returning a pointer to thePointer+1. diff --git a/src/pal/tests/palsuite/c_runtime/_mbslen/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_mbslen/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbslen/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/c_runtime/_mbslen/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_mbslen/test1/CMakeLists.txt new file mode 100644 index 0000000000..38aa6fb16e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbslen/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_mbslen_test1 + ${SOURCES} +) + +add_dependencies(paltest_mbslen_test1 coreclrpal) + +target_link_libraries(paltest_mbslen_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_mbslen/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_mbslen/test1/test1.c new file mode 100644 index 0000000000..fa24c77d8a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbslen/test1/test1.c @@ -0,0 +1,66 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*======================================================================== +** +** Source: test1.c +** +** Purpose: +** Check the length of a number of arrays. The first is a normal string +** which should return its length. The second has two bytes and a null +** character, which only returns a size of 2, and the last is just a NULL +** array which should return 0. +** +** +**========================================================================*/ + +#include <palsuite.h> + +/* + * Note: it seems like these functions would only be useful if they + * didn't assume a character was equivalent to a single byte. Be that + * as it may, I haven't seen a way to get it to behave otherwise + * (eg locale) + */ + +int __cdecl main(int argc, char *argv[]) +{ + unsigned char *str1 = (unsigned char*) "foo"; + unsigned char str2[] = {0xC0, 0x80, 0}; /* the char U+0080 */ + unsigned char str3[] = {0}; + int ret=0; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + ret = _mbslen(str1); + if (ret != 3) + { + Fail ("ERROR: _mbslen(\"%s\") returned %d. Expected %d\n", + str1, ret, 3); + } + + ret = _mbslen(str2); + if (ret != 2) + { + Fail ("ERROR: _mbslen(\"%s\") returned %d. Expected %d\n", + str2, ret, 2); + } + + ret = _mbslen(str3); + if (ret != 0) + { + Fail ("ERROR: _mbslen(\"%s\") returned %d. Expected %d\n", + str3, ret, 0); + } + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_mbslen/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_mbslen/test1/testinfo.dat new file mode 100644 index 0000000000..cf830a7539 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbslen/test1/testinfo.dat @@ -0,0 +1,15 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _mbsinc +Name = Positive Test for _mbslen +TYPE = DEFAULT +EXE1 = test1 +Description += Check the length of a number of arrays. The first is a normal string += which should return its length. The second has two bytes and a null += character, which only returns a size of 2, and the last is just a NULL += array which should return 0. diff --git a/src/pal/tests/palsuite/c_runtime/_mbsninc/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_mbsninc/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbsninc/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/CMakeLists.txt new file mode 100644 index 0000000000..7285ce229e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_mbsninc_test1 + ${SOURCES} +) + +add_dependencies(paltest_mbsninc_test1 coreclrpal) + +target_link_libraries(paltest_mbsninc_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/test1.c new file mode 100644 index 0000000000..59ef50dcc3 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/test1.c @@ -0,0 +1,65 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================ +** +** Source: test1.c +** +** Purpose: +** Ensure that this functions increases a string pointer by n characters. +** Use a for loop, and increase the pointer by a different number of characters +** on each iteration, ensure that it is indeed pointing to the correct location +** each time. The second test checks to see if you attempt to increase the +** pointer past the end of the string, the pointer should just point at the +** last character. +** +** +**==========================================================================*/ + +#include <palsuite.h> + +/* + * Note: it seems like these functions would only be useful if they + * didn't assume a character was equivalent to a single byte. Be that + * as it may, I haven't seen a way to get it to behave otherwise. + */ + +int __cdecl main(int argc, char *argv[]) +{ + unsigned char str[] = {0xC0, 0x80, 0xC0, 0x80, 0}; + int i=0; + unsigned char *ret=NULL; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + for (i=0; i<5; i++) + { + ret = _mbsninc(str, i); + if (ret != str + i) + { + Fail ("ERROR: _mbsninc returned %p. Expected %p\n", ret, str+i); + } + } + + /* + * trying to advance past the end of the string should just + * return the end. + */ + ret = _mbsninc(str, 5); + if (ret != str + 4) + { + Fail ("ERROR: _mbsninc returned %p. Expected %p\n", ret, str+4); + } + + + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/testinfo.dat new file mode 100644 index 0000000000..b855222af9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_mbsninc/test1/testinfo.dat @@ -0,0 +1,17 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _mbsninc +Name = Positive Test for _mbsninc +TYPE = DEFAULT +EXE1 = test1 +Description += Ensure that this functions increases a string pointer by n characters. += Use a for loop, and increase the pointer by a different number of characters += on each iteration, ensure that it is indeed pointing to the correct location += each time. The second test checks to see if you attempt to increase the += pointer past the end of the string, the pointer should just point at the += last character. diff --git a/src/pal/tests/palsuite/c_runtime/_open_osfhandle/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/CMakeLists.txt new file mode 100644 index 0000000000..ef14ea5352 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test2) + diff --git a/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/CMakeLists.txt new file mode 100644 index 0000000000..e9a3e29192 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_open_osfhandle_test1 + ${SOURCES} +) + +add_dependencies(paltest_open_osfhandle_test1 coreclrpal) + +target_link_libraries(paltest_open_osfhandle_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/test1.c new file mode 100644 index 0000000000..ee2c8ea418 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/test1.c @@ -0,0 +1,132 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: test1.c (_open_osfhandle) +** +** Purpose: Tests the PAL implementation of the _open_osfhandle function. +** This API accepts a OS Handle returned from CreatePipe() and +** a flag of _O_RDONLY and returns a C Run-Time handle. The test +** will write to the pipe and pass the C Run-Time handle to _fdopen +** to open the Read Handle to compare what was written with what +** was wrote. They should be the same. +** +** Depends: CreatePipe +** WriteFile +** _fdopen +** fread +** memcmp +** fclose +** strlen +** CloseHandle +** +** +**===================================================================*/ + +#include <palsuite.h> + +const char* cTestString = "one fish, two fish, red fish, blue fish."; + +int __cdecl main(int argc, char **argv) +{ + HANDLE hReadPipe = NULL; + HANDLE hWritePipe = NULL; + BOOL bRetVal = FALSE; + int iFiledes = 0; + DWORD dwBytesWritten; + char buffer[45]; + FILE *fp; + size_t len; + + SECURITY_ATTRIBUTES lpPipeAttributes; + + /*Initialize the PAL*/ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ + lpPipeAttributes.nLength = sizeof(lpPipeAttributes); + lpPipeAttributes.lpSecurityDescriptor = NULL; + lpPipeAttributes.bInheritHandle = TRUE; + + /*Create a Pipe*/ + bRetVal = CreatePipe(&hReadPipe, /* read handle*/ + &hWritePipe, /* write handle */ + &lpPipeAttributes, /* security attributes*/ + 0); /* pipe size*/ + if (bRetVal == FALSE) + { + Fail("ERROR: unable to create pipe"); + } + + /*Write to the write pipe handle*/ + bRetVal = WriteFile(hWritePipe, /* handle to file*/ + cTestString, /* data buffer*/ + strlen(cTestString),/* number of bytes to write*/ + &dwBytesWritten, /* number of bytes written*/ + NULL); /* overlapped buffer*/ + if (bRetVal == FALSE) + { + Fail("ERROR: unable to write to pipe write handle " + "hWritePipe=0x%lx", hWritePipe); + } + + /*Test to see if the WriteFile wrote the correct amount*/ + if(dwBytesWritten != strlen(cTestString)) + { + Fail("Error: WriteFile wrote \"%d\", should have written \"%d\\n", + dwBytesWritten, strlen(cTestString)); + } + + /*Get a file descriptor for the read pipe handle. + *This is what we are testing.*/ + iFiledes = _open_osfhandle((long)hReadPipe, _O_RDONLY); + if (iFiledes == -1) + { + Fail("ERROR: _open_osfhandle failed to open " + " hReadPipe=0x%lx", hReadPipe); + } + + /*Open read pipe handle in read mode. + *Verify that we have returned a correct, + *C Run-time handle*/ + fp = _fdopen(iFiledes, "r"); + if (fp == NULL) + { + Fail("ERROR: unable to fdopen file descriptor" + " iFiledes=%d", iFiledes); + } + + /*Read from the read pipe handle*/ + len = fread(buffer, sizeof(char), strlen(cTestString), fp); + if((len == 0) || (len != strlen(cTestString))) + { + Fail("ERROR: Unable to read from file stream fp=0x%lx\n", fp); + } + + /*Compare what was read with what was written.*/ + if ((memcmp(cTestString, buffer, strlen(cTestString))) != 0) + { + Fail("ERROR: read \"%s\" expected \"%s\" \n", buffer, cTestString); + } + + /*Close write pipe handle*/ + if (CloseHandle(hWritePipe) == 0) + { + Fail("ERROR: Unable to close write pipe handle " + "hWritePipe=0x%lx", hWritePipe); + } + + if ((fclose(fp)) != 0) + { + Fail("ERROR: Unable to close C-Runtime handle " + "iFilesdes=%d", iFiledes); + } + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/testinfo.dat new file mode 100644 index 0000000000..16317bb188 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test1/testinfo.dat @@ -0,0 +1,17 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _open_osfhandle +Name = Test for _open_osfhandle +TYPE = DEFAULT +EXE1 = test1 +Description += Tests the PAL implementation of the _open_osfhandle function. += This API accepts a OS Handle returned from CreatePipe() and += a flag of _O_RDONLY and returns a C Run-Time handle. The test += will write to the pipe and pass the C Run-Time handle to _fdopen += to open the Read Handle to compare what was written with what += was wrote. They should be the same. diff --git a/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/CMakeLists.txt new file mode 100644 index 0000000000..1031ec1df9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test2.c +) + +add_executable(paltest_open_osfhandle_test2 + ${SOURCES} +) + +add_dependencies(paltest_open_osfhandle_test2 coreclrpal) + +target_link_libraries(paltest_open_osfhandle_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/test2.c b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/test2.c new file mode 100644 index 0000000000..6c756b177a --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/test2.c @@ -0,0 +1,86 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: test2.c (_open_osfhandle) +** +** Purpose: Tests the PAL implementation of the _open_osfhandle function. +** This API accepts a OS Handle returned from CreatePipe() and +** a flag of _O_RDONLY and returns a C Run-Time handle. The test +** will pass a NULL handle, and unsupported flags. All cases +** should fail. +** +** Depends: CreatePipe +** CloseHandle +** +** +**===================================================================*/ + +#include <palsuite.h> + +int __cdecl main(int argc, char **argv) +{ + HANDLE hReadPipe = NULL; + HANDLE hWritePipe = NULL; + BOOL bRetVal = FALSE; + int iFiledes = 0; + + SECURITY_ATTRIBUTES lpPipeAttributes; + + /*Initialize the PAL*/ + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /*Setup SECURITY_ATTRIBUTES structure for CreatePipe*/ + lpPipeAttributes.nLength = sizeof(lpPipeAttributes); + lpPipeAttributes.lpSecurityDescriptor = NULL; + lpPipeAttributes.bInheritHandle = TRUE; + + /*Create a Pipe*/ + bRetVal = CreatePipe(&hReadPipe, /* read handle*/ + &hWritePipe, /* write handle */ + &lpPipeAttributes, /* security attributes*/ + 0); /* pipe size*/ + if (bRetVal == FALSE) + { + Fail("ERROR: unable to create pipe"); + } + + /*Close write pipe handle*/ + if (CloseHandle(hWritePipe) == 0) + { + Fail("ERROR: Unable to close write pipe handle " + "hWritePipe=0x%lx", hWritePipe); + } + + /*Close read pipe handle*/ + if (CloseHandle(hReadPipe) == 0) + { + Fail("ERROR: Unable to close read pipe handle " + "hReadPipe=0x%lx", hReadPipe); + } + + /*Test with a Closed handle and supported flag _O_RDONLY*/ + iFiledes = _open_osfhandle((long)hReadPipe, _O_RDONLY); + if (iFiledes != -1) + { + Fail("ERROR: _open_osfhandle successfullly opened " + " hReadPipe which was closed, with _O_RDONLY"); + } + + /*Test with a NULL handle and supported flag _O_RDONLY*/ + hReadPipe = NULL; + iFiledes = _open_osfhandle((long)hReadPipe, _O_RDONLY); + if (iFiledes != -1) + { + Fail("ERROR: _open_osfhandle successfullly opened " + " hReadPipe=NULL with _O_RDONLY"); + } + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/testinfo.dat new file mode 100644 index 0000000000..822e23fedd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_open_osfhandle/test2/testinfo.dat @@ -0,0 +1,16 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _open_osfhandle +Name = Fail test for _open_osfhandle +TYPE = DEFAULT +EXE1 = test2 +Description += Tests the PAL implementation of the _open_osfhandle function. += This API accepts a OS Handle returned from CreatePipe() and += a flag of _O_RDONLY and returns a C Run-Time handle. The test += will pass a NULL handle, and unsupported flags. All cases += should fail. diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_putenv/CMakeLists.txt new file mode 100644 index 0000000000..a3847f8ca9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putenv/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test2) +add_subdirectory(test3) +add_subdirectory(test4) + diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_putenv/test1/CMakeLists.txt new file mode 100644 index 0000000000..0a75b41113 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_putenv_test1 + ${SOURCES} +) + +add_dependencies(paltest_putenv_test1 coreclrpal) + +target_link_libraries(paltest_putenv_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_putenv/test1/test1.c new file mode 100644 index 0000000000..2d096adc78 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test1/test1.c @@ -0,0 +1,99 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: test1.c +** +** Purpose: Create an environment variable with _putenv and then use getenv +** to check it. Check that we get the expected errors with invalid input. +** +** +**===================================================================*/ + +#include <palsuite.h> + +struct TestElement +{ + char _putenvString[1024]; /* argument string sent to putenv */ + char varName[1024]; /* variable component of argument string */ + char varValue[1024]; /* value component of argument string */ + BOOL bValidString; /* valid argument string identifier */ +}; + +struct TestElement TestCases[] = +{ + {"PalTestingEnvironmentVariable=A value", "PalTestingEnvironmentVariable", + "A value", TRUE}, + {"AnotherVariable=", "AnotherVariable", "", TRUE}, + {"YetAnotherVariable", "", "", FALSE}, + {"=ADifferentVariable", "", "ADifferentVariable", FALSE}, + {"", "", "", FALSE} + +}; + +int __cdecl main(int argc, char **argv) +{ + + int i; + char *variableValue; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + for (i = 0; i < (sizeof(TestCases)/sizeof(struct TestElement)) ; i++) + { + if((_putenv(TestCases[i]._putenvString) == -1) && + ( TestCases[i].bValidString == TRUE)) + { + Fail("ERROR: _putenv failed to set an environment " + "variable with a valid format.\n Call was" + "_putenv(%s)\n", TestCases[i]._putenvString); + } + /* + * For valid _putenvString values, check to see the variable was set + */ + if (TestCases[i].bValidString == TRUE) + { + variableValue = getenv(TestCases[i].varName); + + if (variableValue == NULL) + { + if (*TestCases[i].varValue != '\0') + { + Fail("ERROR: getenv(%s) call returned NULL.\nThe call " + "should have returned \"%s\"\n", TestCases[i].varName + , TestCases[i].varValue); + } + } + else if ( strcmp(variableValue, TestCases[i].varValue) != 0) + { + Fail("ERROR: _putenv(%s)\nshould have set the variable " + "%s\n to \"%s\".\nA subsequent call to getenv(%s)\n" + "returned \"%s\" instead.\n", TestCases[i]._putenvString + , TestCases[i].varName, TestCases[i].varValue + , TestCases[i].varName, variableValue); + } + } + else + /* + * Check to see that putenv fails for malformed _putenvString values + */ + { + variableValue = getenv(TestCases[i].varName); + + if (variableValue != NULL) + { + Fail("ERROR: getenv(%s) call should have returned NULL.\n" + "Instead it returned \"%s\".\n", TestCases[i].varName + , TestCases[i].varValue); + } + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_putenv/test1/testinfo.dat new file mode 100644 index 0000000000..d0978184fc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test1/testinfo.dat @@ -0,0 +1,13 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _putenv +Name = Positive test for _putenv +TYPE = DEFAULT +EXE1 = test1 +Description += Create an environment variable with _putenv and then use getenv to += check it. Check that we get the expected errors with invalid input. diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_putenv/test2/CMakeLists.txt new file mode 100644 index 0000000000..e0539681cd --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test2.c +) + +add_executable(paltest_putenv_test2 + ${SOURCES} +) + +add_dependencies(paltest_putenv_test2 coreclrpal) + +target_link_libraries(paltest_putenv_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test2/test2.c b/src/pal/tests/palsuite/c_runtime/_putenv/test2/test2.c new file mode 100644 index 0000000000..39be4f68b4 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test2/test2.c @@ -0,0 +1,76 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: test2.c +** +** Purpose: Create an environment variable with _putenv and then use getenv +** to check it. This test resets an environment variable. +** +** +**===================================================================*/ + +#include <palsuite.h> + +const char *_putenvString0 = "AnUnusualVariable=AnUnusualValue"; +const char *_putenvString1 = "AnUnusualVariable="; +const char *variable = "AnUnusualVariable"; +const char *value = "AnUnusualValue"; + +int __cdecl main(int argc, char **argv) +{ + + char *variableValue; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + if(_putenv(_putenvString0) == -1) + { + Fail("ERROR: _putenv failed to set an environment " + "variable with a valid format.\n Call was" + "_putenv(%s)\n", _putenvString0); + } + + variableValue = getenv(variable); + + if (variableValue == NULL) + { + Fail("ERROR: getenv(%s) call returned NULL\nThe call " + "should have returned '%s'\n", variable, value); + } + else + { + if ( strcmp(variableValue, value) != 0 ) + { + Fail("ERROR: _putenv(%s)\nshould have set the variable " + "'%s'\n to '%s'.\nA subsequent call to getenv(%s)\n" + "returned '%s' instead.\n", _putenvString0, + variable, value, variable, variableValue); + } + else + { + if(_putenv(_putenvString1) == -1) + { + Fail("ERROR: _putenv failed to set an environment " + "variable with a valid format.\n Call was" + "_putenv(%s)\n", _putenvString1); + } + + variableValue = getenv(variable); + + if (variableValue != NULL) + { + Fail("ERROR: getenv(%s) call did not return NULL.\nThe call " + "returned '%s'.\n", variable, value); + } + } + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_putenv/test2/testinfo.dat new file mode 100644 index 0000000000..8d3a6ced1e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test2/testinfo.dat @@ -0,0 +1,13 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _putenv +Name = Positive test for _putenv +TYPE = DEFAULT +EXE1 = test2 +Description += Create an environment variable with _putenv and then use getenv to += check it. This test resets an environment variable. diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test3/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_putenv/test3/CMakeLists.txt new file mode 100644 index 0000000000..a67241022b --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test3/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test3.c +) + +add_executable(paltest_putenv_test3 + ${SOURCES} +) + +add_dependencies(paltest_putenv_test3 coreclrpal) + +target_link_libraries(paltest_putenv_test3 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test3/test3.c b/src/pal/tests/palsuite/c_runtime/_putenv/test3/test3.c new file mode 100644 index 0000000000..8aa6777307 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test3/test3.c @@ -0,0 +1,102 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: test3.c +** +** Purpose: Create environment variables that differ only in Case, and +** verify that the BSD operating system treats the variables +** differently. +** +** +**===================================================================*/ + +#include <palsuite.h> + +int __cdecl main(int argc, char **argv) +{ +#if WIN32 + + return PASS; + +#else + + const char* FirstVariable = "PalTestingEnvironmentVariable=The value"; + const char* SecondVariable = "PALTESTINGEnvironmentVariable=Different value"; + const char* FirstVarName = "PalTestingEnvironmentVariable"; + const char* FirstVarValue = "The value"; + char* result; + + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Use _putenv to set an environment variable. This ensures that the + variable we're testing on is always present. + */ + + if(_putenv(FirstVariable) != 0) + { + Fail("ERROR: _putenv failed to set an environment variable that " + "getenv will be using for testing.\n"); + } + + + /* Call getenv -- ensure it doesn't return NULL and the string it returns + is the value we set above. Also make sure that each environment variable, + differing only by case, returns it's own value. + */ + + result = getenv(FirstVarName); + if(result == NULL) + { + Fail("ERROR: The result of getenv on a valid Environment Variable " + "was NULL, which indicates the environment varaible was not " + "found.\n"); + } + + if(strcmp(result, FirstVarValue) != 0) + { + Fail("ERROR: The value obtained by getenv() was not equal to the " + "correct value of the environment variable. The correct " + "value is '%s' and the function returned '%s'.\n", + FirstVarValue, + result); + } + + /* Set the second environment variable, which only differs in Case */ + if(_putenv(SecondVariable) != 0) + { + Fail("ERROR: _putenv failed to set an environment variable that " + "getenv will be using for testing.\n"); + } + + /* Verify that the environment variables + */ + + result = getenv(FirstVarName); + if(result == NULL) + { + Fail("ERROR: The result of getenv on a valid Environment Variable " + "was NULL, which indicates the environment varaible was not " + "found.\n"); + } + + if(strcmp(result, FirstVarValue) != 0) + { + Fail("ERROR: The value obtained by getenv() was not equal to the " + "correct value of the environment variable. The correct " + "value is '%s' and the function returned '%s'.\n", + FirstVarValue, + result); + } + + PAL_Terminate(); + return PASS; + +#endif +} diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test3/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_putenv/test3/testinfo.dat new file mode 100644 index 0000000000..2c6af1b5cf --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test3/testinfo.dat @@ -0,0 +1,14 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _putenv +Name = Positive test for _putenv +TYPE = DEFAULT +EXE1 = test3 +Description += Create environment variables that only differ by case += and check that the BSD operating system treats them += as two separate variables. diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test4/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_putenv/test4/CMakeLists.txt new file mode 100644 index 0000000000..518282ccc7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test4/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test4.c +) + +add_executable(paltest_putenv_test4 + ${SOURCES} +) + +add_dependencies(paltest_putenv_test4 coreclrpal) + +target_link_libraries(paltest_putenv_test4 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test4/test4.c b/src/pal/tests/palsuite/c_runtime/_putenv/test4/test4.c new file mode 100644 index 0000000000..48d7ba963c --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test4/test4.c @@ -0,0 +1,75 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: test4.c +** +** Purpose: Create an environment variable and try to retrieve +** it using the same name but with different case. This +** is to show that the Win32 representation of _putenv +** is case insensitive. +** +** +**===================================================================*/ + +#include <palsuite.h> + +int __cdecl main(int argc, char **argv) +{ +#if WIN32 + + const char* FirstVariable = "PalTestingEnvironmentVariable=The value"; + const char* ModifiedName = "PALTESTINGEnvironmentVariable"; + const char* FirstVarValue = "The value"; + char* result; + + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /* Use _putenv to set an environment variable. This ensures that the + variable we're testing on is always present. + */ + + if(_putenv(FirstVariable) != 0) + { + Fail("ERROR: _putenv failed to set an environment variable that " + "getenv will be using for testing.\n"); + } + + + /* Call getenv -- ensure it doesn't return NULL and the string it returns + is the value we set above. Also make sure that each environment variable, + differing only by case, doesn't affect the return value. + */ + + result = getenv(ModifiedName); + if(result == NULL) + { + Fail("ERROR: The result of getenv on a valid Environment Variable " + "was NULL, which indicates the environment varaible was not " + "found.\n"); + } + + if(strcmp(result, FirstVarValue) != 0) + { + Fail("ERROR: The value obtained by getenv() was not equal to the " + "correct value of the environment variable. The correct " + "value is '%s' and the function returned '%s'.\n", + FirstVarValue, + result); + } + + + PAL_Terminate(); + return PASS; + +#else + return PASS; + +#endif +} diff --git a/src/pal/tests/palsuite/c_runtime/_putenv/test4/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_putenv/test4/testinfo.dat new file mode 100644 index 0000000000..af1a01c2fc --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putenv/test4/testinfo.dat @@ -0,0 +1,14 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _putenv +Name = Positive test for _putenv +TYPE = DEFAULT +EXE1 = test4 +Description += Create an environment variable and check += that trying to retrieve it using a name with different += case, returns the correct value. diff --git a/src/pal/tests/palsuite/c_runtime/_putw/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_putw/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putw/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/c_runtime/_putw/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_putw/test1/CMakeLists.txt new file mode 100644 index 0000000000..c3018ad322 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putw/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_putw_test1 + ${SOURCES} +) + +add_dependencies(paltest_putw_test1 coreclrpal) + +target_link_libraries(paltest_putw_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_putw/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_putw/test1/test1.c new file mode 100644 index 0000000000..ecfc9046ac --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putw/test1/test1.c @@ -0,0 +1,112 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================ +** +** Source: test1.c +** +** Purpose: Writes a series of integers to a file, test.dat, +** then verifies the results. +** +** Dependency: fopen(...) +** fclose(...) +** CloseHandle(...) +** DeleteFileA(...) +** _getw(...) +** +** +** +**==========================================================================*/ + + +#include <palsuite.h> + +const char testFileName[] = "test.dat"; + +static void Cleanup(HANDLE hFile) +{ + if (fclose(hFile)) + { + Trace("_putw: ERROR -> Unable to close file \"%s\".\n", + testFileName); + } + if (!DeleteFileA(testFileName)) + { + Trace("_putw: ERROR -> Unable to delete file \"%s\". ", + "GetLastError returned %u.\n", + testFileName, + GetLastError()); + } +} + + +int __cdecl main(int argc, char **argv) +{ + + FILE * pfTest = NULL; + int testArray[] = {0,1,-1,0x7FFFFFFF,0x80000000,0xFFFFFFFF,0xFFFFAAAA}; + int i = 0; + int retValue = 0; + + /* + * Initialize the PAL and return FAIL if this fails + */ + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + /*write the file that we will use to test */ + pfTest = fopen(testFileName, "w"); + if (pfTest == NULL) + { + Fail ("Unable to write test file.\n"); + } + + for (i = 0; i < sizeof(testArray)/sizeof(int) ; i++) + { + _putw(testArray[i], pfTest); + + if( ferror( pfTest ) ) + { + Cleanup(pfTest); + Fail( "Error:in _putw -> error has occurred in the " + "stream while writing to the file: \"test.dat\"\n"); + } + + } + + if (fclose(pfTest) != 0) + { + Cleanup(pfTest); + Fail ("Error closing file after writing with _putw(..).\n"); + } + + /*open the new test file and compare*/ + pfTest = fopen(testFileName, "r"); + if (pfTest == NULL) + { + Fail ("Error opening \"%s\", which is odd, since I just finished " + "creating that file.\n", testFileName); + } + retValue =_getw( pfTest ); + i = 0; + while(retValue != EOF) + { + if(retValue != testArray[i]) + { + Cleanup(pfTest); + Fail ("Integers written by _putw are not in the correct format\n", + testFileName); + } + retValue = _getw( pfTest ); + i++ ; + } + + Cleanup(pfTest); + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/c_runtime/_putw/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_putw/test1/testinfo.dat new file mode 100644 index 0000000000..3007b82407 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_putw/test1/testinfo.dat @@ -0,0 +1,13 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _putw +Name = Positive test for _putw +TYPE = DEFAULT +EXE1 = test1 +Description += Several integers are written to a new file using _putw. This file is += closed, reopened and read from to verify the writes were successful. diff --git a/src/pal/tests/palsuite/c_runtime/_rotl/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_rotl/CMakeLists.txt new file mode 100644 index 0000000000..f6aa0cb2d9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_rotl/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/c_runtime/_rotl/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_rotl/test1/CMakeLists.txt new file mode 100644 index 0000000000..bafaa23732 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_rotl/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.cpp +) + +add_executable(paltest_rotl_test1 + ${SOURCES} +) + +add_dependencies(paltest_rotl_test1 coreclrpal) + +target_link_libraries(paltest_rotl_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/_rotl/test1/test1.cpp b/src/pal/tests/palsuite/c_runtime/_rotl/test1/test1.cpp new file mode 100644 index 0000000000..3a31388893 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_rotl/test1/test1.cpp @@ -0,0 +1,55 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: test1.c (_rotl) +** +** Purpose: Tests the PAL implementation of the _rotl function. +** The _rotl function rotates the unsigned value. _rotl +** rotates the value left and "wraps" bits rotated off +** one end of value to the other end. +** This test compares the result to a previously determined +** value. +** +** +** +**===================================================================*/ +#include <palsuite.h> + +int __cdecl main(int argc, char **argv) +{ + unsigned results = 0; + int i,j; + + unsigned hTestNums[5][8] = { + {0x00ff, 0x01fe, 0x03fc, 0x07f8, 0x0ff0, 0x1fe0, 0x3fc0, 0x7f80}, + {0x0055, 0x00aa, 0x0154, 0x02a8, 0x0550, 0x0aa0, 0x1540, 0x2a80}, + {0x0099, 0x0132, 0x0264, 0x04c8, 0x0990, 0x1320, 0x2640, 0x4c80}, + {0x0036, 0x006c, 0x00d8, 0x01b0, 0x0360, 0x06c0, 0x0d80, 0x1b00}, + {0x008f, 0x011e, 0x023c, 0x0478, 0x08f0, 0x11e0, 0x23c0, 0x4780}}; + + if ((PAL_Initialize(argc, argv)) != 0) + { + return (FAIL); + } + + /*Loop through expected test results*/ + for (j = 0; j <= 4; j++) + { + for(i = 1; i <= 7; i++) + { + results = _rotl(hTestNums[j][0], i); + if (results != hTestNums[j][i]) + { + Fail("ERROR: \"0x%4.4x\" rotated bits to the left %d times" + " gave \"0x%4.4x\", expected \"0x%4.4x\"\n", + hTestNums[j][0], i, results, hTestNums[j][i]) ; + } + } + } + + PAL_Terminate(); + return (PASS); +} diff --git a/src/pal/tests/palsuite/c_runtime/_rotl/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_rotl/test1/testinfo.dat new file mode 100644 index 0000000000..9c87473f8e --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/_rotl/test1/testinfo.dat @@ -0,0 +1,17 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = C Runtime +Function = _rtol +Name = Positive Test for _rotl +TYPE = DEFAULT +EXE1 = test1 +Description += Tests the PAL implementation of the _ro |