Exemple #1
0
int __cdecl main(int argc, char *argv[])
{
    HANDLE hFile = NULL;
    BOOL bRc = FALSE;


    if (0 != PAL_Initialize(argc,argv))
    {
        return FAIL;
    }

    bRc = SetEndOfFile(NULL);
    if (bRc == TRUE)
    {
        Fail("SetEndOfFile: ERROR -> Operation succeeded on a NULL file "
            "handle\n");
    }

    /* create a test file */
    hFile = CreateFile(szTextFile,
        GENERIC_READ,
        FILE_SHARE_READ,
        NULL,
        OPEN_ALWAYS,
        FILE_ATTRIBUTE_NORMAL,
        NULL);

    if(hFile == INVALID_HANDLE_VALUE)
    {
        Fail("SetEndOfFile: ERROR -> Unable to create file \"%s\".\n",
            szTextFile);
    }

    bRc = SetEndOfFile(hFile);
    if (bRc == TRUE)
    {
        Trace("SetEndOfFile: ERROR -> Operation succeeded on read-only"
              " file.\n");
        bRc = CloseHandle(hFile);
        if (bRc != TRUE)
        {
            Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n",
                szTextFile);
        }
        PAL_TerminateEx(FAIL);
        return FAIL;
    }

    bRc = CloseHandle(hFile);
    if (bRc != TRUE)
    {
        Fail("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n",
            szTextFile);
    }


    PAL_Terminate();
    return PASS;
}
Exemple #2
0
int __cdecl main( int argc, char **argv ) 
{
    int iRetCode = EXIT_OK_CODE; /* preset exit code to OK */
    char szBuf[BUF_LEN];

    WCHAR *swzParam1, *swzParam2, *swzParam3 = NULL;


    if(0 != (PAL_Initialize(argc, argv)))
    {
        return FAIL;
    }
    if (argc != 4)
    {
        return EXIT_ERR_CODE3;
    }

    swzParam1 = convert(argv[1]);
    swzParam2 = convert(argv[2]);
    swzParam3 = convert(argv[3]);

    if (wcscmp(swzParam1, szArg1) != 0
        || wcscmp(swzParam2, szArg2) != 0
        || wcscmp(swzParam3, szArg3) != 0)
    {
        return EXIT_ERR_CODE4;
    }

    free(swzParam1);
    free(swzParam2);
    free(swzParam3);

    memset(szBuf, 0, BUF_LEN);

    /* Read the string that was written by the parent */
    if (fgets(szBuf, BUF_LEN, stdin) == NULL)
    {
        return EXIT_ERR_CODE1;
    }


    /* Write the string out to the stdout & stderr pipes */
    if (fputs(szBuf, stdout) == EOF
        || fputs(szBuf, stderr) == EOF)
    {
        return EXIT_ERR_CODE2;
    }

    /* The exit code will indicate success or failure */
    PAL_TerminateEx(iRetCode);

    /* Return special exit code to indicate success or failure */
    return iRetCode;
}
Exemple #3
0
int __cdecl main( int argc, char **argv )
{
    /* local variables */
    HANDLE                  hEvent = NULL;
    WCHAR                   wcName[] = {'P','A','L','R','o','c','k','s','\0'};
    LPWSTR                  lpName = wcName;
    
    int result = PASS;

    /* initialize the PAL */
    if( PAL_Initialize(argc, argv) != 0 )
    {
	    return( FAIL );
    }


    /* open a handle to the event created in the child process */
    hEvent = OpenEventW( EVENT_ALL_ACCESS,  /* we want all rights */
                         FALSE,             /* no inherit         */
                         lpName );

    if( hEvent == NULL )
    {
        /* ERROR */
        Trace( "ERROR:%lu:OpenEventW() call failed\n", GetLastError() );
        result = FAIL;
        goto parentwait;
    }

    /* set the event -- should take effect in the child process */
    if( ! SetEvent( hEvent ) )
    {
        /* ERROR */
        Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() );
        result = FAIL;
    }

parentwait:
    /* close the event handle */
    if( ! CloseHandle( hEvent ) )
    {
        /* ERROR */
        Fail(   "ERROR:%lu:CloseHandle() call failed in child\n",
                GetLastError());
    }

    /* terminate the PAL */
    PAL_TerminateEx(result);

    /* return success or failure */
    return result;
}
Exemple #4
0
int __cdecl main( int argc, char **argv ) 
{
    extern DWORD dwThreadIdTF;
    DWORD dwThreadIdCT;
    HANDLE hThread; 
    DWORD dwThreadParam = 1;
    DWORD dwThreadWait;
    
    if(0 != (PAL_Initialize(argc, argv)))
    {
        return ( FAIL );
    }
    
    hThread = CreateThread(
        NULL,            
        0,               
        ThreadFunction,  
        &dwThreadParam,  
        0,               
        &dwThreadIdCT);  
    
    if ( NULL == hThread ) 
    {
        Fail ( "CreateThread() call failed - returned NULL");
    }
    else 
    {
	dwThreadWait = WaitForSingleObject( hThread, INFINITE );   
    
        Trace ("dwThreadWait returned %d\n", dwThreadWait );
    
	if ( dwThreadIdCT == dwThreadIdTF )
	{
            Trace ( "ThreadId numbers match - GetCurrentThreadId"
		     " works.  dwThreadIdCT == dwThreadIdTF == %d\n",
		     dwThreadIdTF );
	    PAL_Terminate();
            return ( PASS );
	}
	else 
	{
            Fail ( "ThreadId numbers don't match - "
		     "GetCurrentThreadId fails dwThreadIdCT = %d "
		     "and dwThreadIdTF = %d\n", dwThreadIdCT, dwThreadIdTF);
	}
    }

    PAL_TerminateEx(FAIL);
    return (FAIL);

}
Exemple #5
0
INT __cdecl main( int argc, char **argv ) 
{

    HANDLE hProcess; 
         
    if(0 != (PAL_Initialize(argc, argv)))
    {
        return (FAIL);
    }
    
    hProcess = GetCurrentProcess();
    
    Trace ("Testing TerminateProcess function.\n");
    
    if ( 0 == ( TerminateProcess ( hProcess, PASS ) ) )
    {
        Fail ("TerminateProcess failed.\n");
    }

    PAL_TerminateEx(FAIL);
    return (FAIL);

}
Exemple #6
0
int __cdecl main(int argc, char *argv[])

{



    BOOL testPass = TRUE;

    BOOL bRc = TRUE;

    DWORD errCode;



    const char* sBadSubDirectory = "bad/badDir";



    /* Needed for RemoveDirectoryW */

    const WCHAR tempName[] = {'b','a','d','/',

        'b','a','d','D','i','r'};



    const WCHAR wBadSubDirectory[] = 

        {'w','b','a','d','/','b','a',

        'd','D','i','r','\0'};

 

    if (0 != PAL_Initialize(argc,argv))

    {

        return FAIL;

    }



    /* ---------------------CreateDirectoryA------------------------- */





    /* Testing of CreateDirectoryA */

    bRc = CreateDirectoryA(sBadSubDirectory,NULL);

    if(!bRc)

    {

        errCode = GetLastError();

        if(errCode != ERROR_PATH_NOT_FOUND)

        {

            Trace("CreateDirectoryA: calling GetLastError() after creating a "

                "directory with invalid path returned [%u] while it should "

                "return [%u]\n",errCode, ERROR_PATH_NOT_FOUND);

            testPass = FALSE;

        }

    }

    else

    {

        Trace("CreateDirectoryA: Created a directory with an invalid path.\n");

        bRc = RemoveDirectoryW(tempName);

        if(!bRc)

        {

            Trace("Failed to remove %s with error %u.\n",

                sBadSubDirectory,GetLastError());

        }

        testPass = FALSE;

    }



    /* ---------------------CreateDirectoryW------------------------- */



    /* Testing of CreateDirectoryW */

    bRc = CreateDirectoryW(wBadSubDirectory,NULL);

    if(!bRc)

    {

        errCode = GetLastError();

        if(errCode != ERROR_PATH_NOT_FOUND)

        {

            Trace("CreateDirectoryW: calling GetLastError() after creating a "

                "directory with invalid path returned [%u] while it should "

                "return [%u]\n",errCode, ERROR_PATH_NOT_FOUND);

            testPass = FALSE;

        }

    }

    else

    {

        Trace("CreateDirectoryW: Created a directory with an invalid path.\n");

        bRc = RemoveDirectoryW(wBadSubDirectory);

        if(!bRc)

        {

            Trace("Failed to remove %S with error %u.\n",

                wBadSubDirectory,GetLastError());

        }

        testPass = FALSE;

    }



    /* ---------------------RemoveDirectoryW------------------------ */



    /* Testing of RemoveDirectoryW */

    bRc = RemoveDirectoryW(wBadSubDirectory);

    if(!bRc)

    {

        errCode = GetLastError();

        if(errCode != ERROR_PATH_NOT_FOUND)

        {

            Trace("RemoveDirectoryW: calling GetLastError() after removing a "

                "sub directory with invalid path returned [%u] while it should "

                "return [%u]\n",errCode, ERROR_PATH_NOT_FOUND);

            testPass = FALSE;

        }

    }

    else

    {

        Trace("RemoveDirectoryW: Removed a directory that did not exist.\n");

    }

    int exitCode = testPass ? PASS : FAIL;
    PAL_TerminateEx(exitCode);
    return exitCode;

 






Exemple #7
0
int __cdecl main(int argc, char *argv[])
{
    DWORD   dwRc = 0;

    WCHAR   szReturnedPath[_MAX_DIR+1];
    WCHAR   szFullFileName[_MAX_DIR+1];
    WCHAR   szDirectory[256];
    WCHAR   szCreatedDir[]     = {'t','e','s','t','_','d','i','r','\0'};

    LPWSTR  pPathPtr;
    HANDLE  hFile = NULL;
    BOOL    bRetVal = FAIL;

    /* Initialize the PAL.
     */
    if (0 != PAL_Initialize(argc,argv))
    {
        return (FAIL);
    }

    /* Initialize the buffer.
     */
    memset(szDirectory, '\0', 256);

    /* Create the path to the next level of directory to create.
     */
    wcscat(szDirectory, szDotDot);        /* ..                  */
    wcscat(szDirectory, szSeperator);     /* ../                 */
    wcscat(szDirectory, szCreatedDir);    /* ../test_directory   */

    /* Create a test directory.
     */
    if (!CreateDirectoryW(szDirectory, NULL))
    {
        Fail("ERROR:%u: Unable to create directories \"%S\".\n",
             GetLastError(),
             szDirectory);
    }

    /* Initialize the receiving char buffers.
     */
    memset(szReturnedPath, 0, _MAX_DIR+1);
    memset(szFullFileName, 0, _MAX_DIR+1);

    /* Create Full filename to pass, will include '..\'
     * in the middle of the path.
     */
    wcscat( szFullFileName, szDotDot );     /* ..                            */
    wcscat( szFullFileName, szSeperator );  /* ../                           */
    wcscat( szFullFileName, szCreatedDir ); /* ../test_directory             */
    wcscat( szFullFileName, szSeperator );  /* ../test_directory/            */
    wcscat( szFullFileName, szFileName );   /* ../test_directory/testing.tmp */

    /* Get the full path to the filename.
     */
    dwRc = GetFullPathNameW(szFullFileName,
                            _MAX_DIR,
                            szReturnedPath,
                            &pPathPtr);
    if (dwRc == 0)
    {
        Trace("ERROR :%ld: GetFullPathName failed to "
              "retrieve the path of \"%S\".\n",
              GetLastError(),
              szFileName);
        bRetVal = FAIL;
        goto cleanUpOne;
    }

    /* The returned value should be the parent directory with the
     * file name appended. */
    hFile = CreateFileW(szReturnedPath,
                        GENERIC_READ,
                        FILE_SHARE_READ,
                        NULL,
                        CREATE_ALWAYS,
                        FILE_ATTRIBUTE_NORMAL,
                        NULL);

    if (hFile == INVALID_HANDLE_VALUE)
    {
        Trace("ERROR :%ld: CreateFileA failed to create \"%S\".\n",
              GetLastError(),
              szReturnedPath);
        bRetVal = FAIL;
        goto cleanUpOne;
    }

    /* Close the handle to the created file.
     */
    if (CloseHandle(hFile) != TRUE)
    {
        Trace("ERROR :%ld: CloseHandle failed close hFile=0x%lx.\n",
              GetLastError());
        bRetVal = FAIL;
        goto cleanUpTwo;
    }

    /* Verify that the file was created, attempt to create
     * the file again. */
    hFile = CreateFileW(szReturnedPath,
                        GENERIC_READ,
                        FILE_SHARE_READ,
                        NULL,
                        CREATE_NEW,
                        FILE_ATTRIBUTE_NORMAL,
                        NULL);
    if ((hFile != INVALID_HANDLE_VALUE) &&
            (GetLastError() != ERROR_ALREADY_EXISTS))
    {
        Trace("ERROR :%ld: CreateFileA succeeded to create file "
              "\"%S\", that already existed.\n",
              GetLastError(),
              szFullFileName);
        bRetVal = FAIL;
        goto cleanUpTwo;
    }

    /* Verify that the returned filename is the same as the supplied.
     */
    if (wcscmp(pPathPtr, szFileName) != 0)
    {
        Trace("ERROR : Returned filename \"%S\" is not equal to "
              "supplied filename \"%S\".\n",
              pPathPtr,
              szFileName);
        bRetVal = FAIL;
        goto cleanUpTwo;
    }

    /* Successful test.
     */
    bRetVal = PASS;

cleanUpTwo:

    /* Delete the create file.
     */
    if (DeleteFileW(szReturnedPath) != TRUE)
    {
        Fail("ERROR :%ld: DeleteFileA failed to delete \"%S\".\n",
             GetLastError(),
             szFileName);
    }

cleanUpOne:

    /* Remove the empty directory.
     */
    if (!RemoveDirectoryW(szDirectory))
    {
        Fail("ERROR:%u: Unable to remove directory \"%s\".\n",
             GetLastError(),
             szCreatedDir);
    }

    /* Terminate the PAL.*/
    PAL_TerminateEx(bRetVal);
    return bRetVal;
}
Exemple #8
0
int __cdecl main(int argc, char *argv[])
{

    HANDLE  hFile;
    char    buf[] = "this is a test string";
    char    ch[2048];
    char    lpFileName[] = "test.tmp";
    HANDLE  hFileMapping;
    LPVOID  lpMapViewAddress;
    int     RetVal = PASS;
    int     err;
    DWORD   dwBytesWritten;


    /* Initialize the PAL environment.
     */
    if(0 != PAL_Initialize(argc, argv))
    {
        return FAIL;
    }

    /* Create a file handle with CreateFile.
     */
    hFile = CreateFile( lpFileName,
                        GENERIC_WRITE|GENERIC_READ,
                        FILE_SHARE_READ|FILE_SHARE_WRITE,
                        NULL,
                        CREATE_ALWAYS,
                        FILE_ATTRIBUTE_NORMAL,
                        NULL);

    if (hFile == INVALID_HANDLE_VALUE)
    {
        Fail("ERROR: %u :unable to create file \"%s\".\n",
             GetLastError(),
             lpFileName);
    }

    /* Write to the File handle.
     */ 
    err = WriteFile(hFile,
                    buf,
                    strlen(buf),
                    &dwBytesWritten,
                    NULL);

    if (err == FALSE)
    {
        Trace("ERROR: %u :unable to write to file handle "
                "hFile=0x%lx\n",
                GetLastError(),
                hFile);
        RetVal = FAIL;
        goto CleanUpOne;
    }
    
    /* Flush to the hard-drive.
      */
    FlushFileBuffers(hFile);

    /* Initialize the buffers.
     */
    memset(ch,  0, MAPPINGSIZE);

    /* Create a unnamed file-mapping object with file handle FileHandle
     * and with PAGE_WRITECOPY protection.
     */
    hFileMapping = CreateFileMapping(
                            hFile,
                            NULL,               /*not inherited*/
                            PAGE_WRITECOPY,     /*write copy*/
                            0,                  /*high-order size*/
                            0,                  /*low-order size*/
                            NULL);              /*unnamed object*/

    if(NULL == hFileMapping)
    {
        Trace("ERROR:%u: Failed to create File Mapping.\n", 
              GetLastError());
        RetVal = FAIL;
        goto CleanUpOne;
    }

    /* maps a view of a file into the address space of the calling process.
     */
    lpMapViewAddress = MapViewOfFile(
                            hFileMapping,
                            FILE_MAP_COPY,       /* access code */
                            0,                   /* high order offset*/
                            0,                   /* low order offset*/
                            0);                  /* number of bytes for map */

    if(NULL == lpMapViewAddress)
    {
        Trace("ERROR:%u: Failed to call MapViewOfFile "
              "API to map a view of file!\n", 
              GetLastError());
        RetVal = FAIL;
        goto CleanUpTwo;
    }
    
    /* Write to the Map view.3
     */ 
    memcpy(lpMapViewAddress, buf, strlen(buf));

    /* Read from the Map view.
     */ 
    memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE);
    
    /* Copy the MapViewOfFile to buffer, so we can
     * compare with value read from file directly.
     */
    if (memcmp(ch, buf, strlen(buf))!= 0)
    {
        Trace("ERROR: MapViewOfFile not equal to file contents "
              "retrieved \"%s\", expected \"%s\".\n",
              ch, buf);
        RetVal = FAIL;
        goto CleanUpThree;
    }

CleanUpThree:
        
    /* Unmap the view of file.
        */
    if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
    {
        Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
                GetLastError(),
                lpMapViewAddress);
        RetVal = FAIL;
    }

CleanUpTwo:

    /* Close Handle to opend file mapping.
        */
    if ( CloseHandle(hFileMapping) == FALSE )
    {
        Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
                GetLastError(),
                hFileMapping);
        RetVal = FAIL;
    }

CleanUpOne:
        
    /* Close Handle to create file mapping.
        */
    if ( CloseHandle(hFile) == FALSE )
    {
        Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
                GetLastError(),
                hFile);
        RetVal = FAIL;
    }

    /* Terminate the PAL.
     */ 
    PAL_TerminateEx(RetVal);
    return RetVal;
}
Exemple #9
0
int __cdecl main(int argc, char *argv[])
{
    HANDLE hFile = NULL;
    DWORD dwByteCount = 0;
    DWORD dwOffset = 0;
    DWORD dwRc = 0;
    BOOL bRc = FALSE;

    if (0 != PAL_Initialize(argc,argv))
    {
        return FAIL;
    }

    /* create a test file */
    hFile = CreateFile(szTextFile,
        GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL,
        CREATE_ALWAYS,
        FILE_ATTRIBUTE_NORMAL,
        NULL);

    if(hFile == INVALID_HANDLE_VALUE)
    {
        Fail("SetFilePointer: ERROR -> Unable to create file \"%s\".\n",
            szTextFile);
    }

    bRc = WriteFile(hFile, szText, (DWORD)strlen(szText), &dwByteCount, NULL);
    if (bRc == FALSE)
    {
        Trace("SetFilePointer: ERROR -> Unable to write to file \"%s\".\n",
            szTextFile);
        if (CloseHandle(hFile) != TRUE)
        {
            Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n",
                szTextFile);
        }
        if (!DeleteFileA(szTextFile))
        {
            Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n",
                szTextFile);
        }
        PAL_TerminateEx(FAIL);
        return FAIL;
    }


    /*
     * move -1 from the end
     */
    dwRc = SetFilePointer(hFile, -1, NULL, FILE_END);
    if (dwRc == INVALID_SET_FILE_POINTER)
    {
        if (GetLastError() != ERROR_SUCCESS)
        {
            Trace("SetFilePointer: ERROR -> Failed to move the pointer "
                "back one character from EOF.\n");
            if (CloseHandle(hFile) != TRUE)
            {
                Trace("SetFilePointer: ERROR -> Unable to close file"
                      " \"%s\".\n", szTextFile);
            }
            if (!DeleteFileA(szTextFile))
            {
                Trace("SetFilePointer: ERROR -> Unable to delete file"
                      " \"%s\".\n", szTextFile);
            }
            PAL_TerminateEx(FAIL);
            return FAIL;
        }
    }
    else
    {
        /* verify */
        if ((dwRc != strlen(szText)-1))
        {
            Trace("SetFilePointer: ERROR -> Failed to move the pointer"
                  " -1 bytes from EOF\n");
            if (CloseHandle(hFile) != TRUE)
            {
                Trace("SetFilePointer: ERROR -> Unable to close file"
                      " \"%s\".\n", szTextFile);
            }
            if (!DeleteFileA(szTextFile))
            {
                Trace("SetFilePointer: ERROR -> Unable to delete file"
                      " \"%s\".\n", szTextFile);
            }
            PAL_TerminateEx(FAIL);
            return FAIL;
        }
    }

    /*
     * move the file pointer 0 bytes from the end and verify
     */
    dwRc = SetFilePointer(hFile, 0, NULL, FILE_END);
    if (dwRc != strlen(szText))
    {
        Trace("SetFilePointer: ERROR -> Asked to move 0 bytes from the "
            "end of the file. Function returned %ld instead of 52.\n", dwRc);
        if (CloseHandle(hFile) != TRUE)
        {
            Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n",
                szTextFile);
        }
        if (!DeleteFileA(szTextFile))
        {
            Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n",
                szTextFile);
        }
        PAL_TerminateEx(FAIL);
        return FAIL;
    }

    /*
     * move the pointer past the end of the file and verify
     */
    dwRc = SetFilePointer(hFile, 20, NULL, FILE_END);
    if (dwRc != strlen(szText)+20)
    {
        Trace("SetFilePointer: ERROR -> Asked to move 20 bytes past the "
            "end of the file. Function returned %ld instead of %d.\n",
            dwRc,
            strlen(szText)+20);
        if (CloseHandle(hFile) != TRUE)
        {
            Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n",
            szTextFile);
        }
        if (!DeleteFileA(szTextFile))
        {
            Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n",
                szTextFile);
        }
        PAL_TerminateEx(FAIL);
        return FAIL;
    }
    else
    {
        /* verify results */
        bRc = SetEndOfFile(hFile);
        if ((dwRc = GetFileSize(hFile, NULL)) != strlen(szText)+20)
        {
            Trace("SetFilePointer: ERROR -> Asked to move back 20 bytes past"
                " theend of the file. GetFileSize returned %ld whereas it "
                "should have been %d.\n",
                dwRc,
                strlen(szText)+20);
            if (CloseHandle(hFile) != TRUE)
            {
                Trace("SetFilePointer: ERROR -> Unable to close file"
                      " \"%s\".\n", szTextFile);
            }
            if (!DeleteFileA(szTextFile))
            {
                Trace("SetFilePointer: ERROR -> Unable to delete file"
                      " \"%s\".\n", szTextFile);
            }
            PAL_TerminateEx(FAIL);
            return FAIL;
        }
    }


    /*
     * move the pointer backwards to before the start of the file and verify
     */

    dwOffset = (dwRc + 20) * -1;
    dwRc = SetFilePointer(hFile, dwOffset, NULL, FILE_END);
    if ((dwRc != INVALID_SET_FILE_POINTER) ||
    (GetLastError() == ERROR_SUCCESS))
    {
        Trace("SetFilePointer: ERROR -> Was able to move the pointer "
            "to before the beginning of the file.\n");
        if (CloseHandle(hFile) != TRUE)
        {
            Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", 
                szTextFile);
        }
        if (!DeleteFileA(szTextFile))
        {
            Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", 
                szTextFile);
        }
        PAL_TerminateEx(FAIL);
        return FAIL;
    }


    if (CloseHandle(hFile) != TRUE)
    {
        Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", 
            szTextFile);
        if (!DeleteFileA(szTextFile))
        {
            Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", 
                szTextFile);
        }
        PAL_TerminateEx(FAIL);
        return FAIL;
    }

    if (!DeleteFileA(szTextFile))
    {
        Fail("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", 
            szTextFile);
    }
    PAL_Terminate();
    return PASS;
}
Exemple #10
0
int __cdecl main(int argc, char *argv[])
{
    HANDLE  FileMappingHandle;
    HANDLE  OpenFileMappingHandle;
    HANDLE  lpMapViewAddress;
    HANDLE  OpenFileMappingHandle2;
    HANDLE  lpMapViewAddress2;
    const   int LOWORDERSIZE = 1024;
    WCHAR   MapObject[] = {'m','y','O','b','j','e','c','t','\0'};
    char    buf[] = "this is a test";
    char    ch[1024];
    int     RetVal = PASS;


    /* Initialize the PAL environment.
     */
    if(0 != PAL_Initialize(argc, argv))
    {
        return FAIL;
    }

    /* Create a named file-mapping object with file handle FileHandle.
     */
    FileMappingHandle = CreateFileMapping(
                                INVALID_HANDLE_VALUE,
                                NULL,               /* not inherited */
                                PAGE_READWRITE,     /* read and wite */
                                0,                  /* high-order size */
                                LOWORDERSIZE,       /* low-order size */
                                MapObject);         /* named object */

    if(NULL == FileMappingHandle) 
    {
        Fail("\nFailed to call CreateFileMapping to "
             "create a mapping object!\n");
    }
    if(GetLastError() == ERROR_ALREADY_EXISTS)
    {
        Trace("\nFile mapping object already exists!\n");
        RetVal = FAIL;
        goto CleanUpOne;
    }

    /* Open a named file-mapping object with FILE_MAP_WRITE access.
     */
    OpenFileMappingHandle =  OpenFileMapping(
                                    FILE_MAP_WRITE,
                                    FALSE,
                                    MapObject);

    if(NULL == OpenFileMappingHandle)
    {
        Trace("\nFailed to Call OpenFileMappingW API!\n");
        RetVal = FAIL;
        goto CleanUpOne;
    }

    /* Open a named file-mapping object with 
     * FILE_MAP_ALL_ACCESS access, to verify
     * the FILE_MAP_WRITE access map.
     */
    OpenFileMappingHandle2 =  OpenFileMapping(
                                    FILE_MAP_ALL_ACCESS,
                                    FALSE,
                                    MapObject);

    if(NULL == OpenFileMappingHandle2)
    {
        Trace("\nFailed to Call OpenFileMappingW API!\n");
        RetVal = FAIL;
        goto CleanUpTwo;
    }

    /* Create map view of the open mapping that has
     * FILE_MAP_WRITE access.
     */
    lpMapViewAddress = MapViewOfFile(
                            OpenFileMappingHandle,
                            FILE_MAP_WRITE,      /* access code */
                            0,                   /* high order offset */
                            0,                   /* low order offset */
                            LOWORDERSIZE);       /* number of bytes for map */

    if(NULL == lpMapViewAddress)
    {
        Trace("ERROR:%u: Failed to call MapViewOfFile "
              "API to map a view of file!\n", 
              GetLastError());
        RetVal = FAIL;
        goto CleanUpThree;
    }

    /* Create map view of the open mapping that has
     * FILE_MAP_ALL_ACCESS access.
     */
    
    lpMapViewAddress2 = MapViewOfFile(
                            OpenFileMappingHandle2,
                            FILE_MAP_ALL_ACCESS, /* access code */
                            0,                   /* high order offset */
                            0,                   /* low order offset */
                            LOWORDERSIZE);       /* number of bytes for map */

    if(NULL == lpMapViewAddress2)
    {
        Trace("ERROR:%u: Failed to call MapViewOfFile "
              "API to map a view of file!\n", 
              GetLastError());
        RetVal = FAIL;
        goto CleanUpFour;
    }

    /* Write to the Map View.
     */
    memcpy(lpMapViewAddress, buf, strlen(buf));
    
    /* Read from the Map View.
    */
    memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE); 
    
    /* Compare what was written to the Map View,
     * to what was read.
     */
    if (memcmp(ch, buf, strlen(buf))!= 0)
    {
        
        Trace("ERROR: MapViewOfFile not equal to file contents "
              "retrieved \"%s\", expected \"%s\".\n",
              ch, buf);
        RetVal = FAIL;
        goto CleanUpFive;
    }

    
CleanUpFive:
        
        /* Unmap the view of file.
         */
        if ( UnmapViewOfFile(lpMapViewAddress2) == FALSE )
        {
            Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
                  GetLastError(),
                  lpMapViewAddress2);
            RetVal = FAIL;
        }

CleanUpFour:
        
        /* Unmap the view of file.
         */
        if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
        {
            Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
                  GetLastError(),
                  lpMapViewAddress);
            RetVal = FAIL;
        }

CleanUpThree:

        /* Close Handle to opened file mapping.
         */
        if ( CloseHandle(OpenFileMappingHandle2) == 0 )
        {
            Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
                  GetLastError(),
                  OpenFileMappingHandle2);
            RetVal = FAIL;
        }

CleanUpTwo:

        /* Close Handle to opened file mapping.
         */
        if ( CloseHandle(OpenFileMappingHandle) == 0 )
        {
            Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
                  GetLastError(),
                  OpenFileMappingHandle);
            RetVal = FAIL;
        }

CleanUpOne:
        
        /* Close Handle to create file mapping.
         */
        if ( CloseHandle(FileMappingHandle) == 0 )
        {
            Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
                  GetLastError(),
                  FileMappingHandle);
            RetVal = FAIL;
        }
    
    /* Terminate the PAL.
     */
    PAL_TerminateEx(RetVal);
    return RetVal;
}
Exemple #11
0
int __cdecl main(int argc, char *argv[])
{
    HANDLE hFile = NULL;
    DWORD dwByteCount = 0;
    DWORD dwBytesWritten;
    BOOL bRc = FALSE;
    char szBuffer[100];
    DWORD dwBytesRead = 0;
    FILE *pFile = NULL;


    if (0 != PAL_Initialize(argc,argv))
    {
        return FAIL;
    }

    // create a test file
    hFile = CreateFile(szTextFile, 
        GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL,
        OPEN_ALWAYS,
        FILE_ATTRIBUTE_NORMAL,
        NULL);

    if(hFile == INVALID_HANDLE_VALUE)
    {
        Fail("SetEndOfFile: ERROR -> Unable to create file \"%s\".\n", 
            szTextFile);
    }

    bRc = WriteFile(hFile, szStringTest, 20, &dwBytesWritten, NULL);
    if (bRc != TRUE)
    {
        Trace("SetEndOfFile: ERROR -> Uable to write to \"%s\".\n", 
            szTextFile);
        bRc = CloseHandle(hFile);
        if (bRc != TRUE)
        {
            Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", 
                szTextFile);
        }
        PAL_TerminateEx(FAIL);
        return FAIL;
    }

    bRc = CloseHandle(hFile);
    if (bRc != TRUE)
    {
        Fail("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", 
            szTextFile);
    }

    // open the test file
    hFile = CreateFile(szTextFile, 
        GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL,
        OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL,
        NULL);

    if(hFile == INVALID_HANDLE_VALUE)
    {
        Fail("SetEndOfFile: ERROR -> Unable to open file \"%s\".\n", 
            szTextFile);
    }

    // read a bit of the file to move the file pointer
    dwByteCount = 10;
    bRc = ReadFile(hFile, szBuffer, dwByteCount, &dwBytesRead, NULL);
    if (bRc != TRUE)
    {
        Trace("SetEndOfFile: ERROR -> Uable to read from \"%s\".\n", 
            szTextFile);
        bRc = CloseHandle(hFile);
        if (bRc != TRUE)
        {
            Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", 
                szTextFile);
        }
        PAL_TerminateEx(FAIL);
        return FAIL;
    }

    bRc = SetEndOfFile(hFile);
    if (bRc != TRUE)
    {
        Trace("SetEndOfFile: ERROR -> Uable to set end of file.\n");
        bRc = CloseHandle(hFile);
        if (bRc != TRUE)
        {
            Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", 
                szTextFile);
        }
        PAL_TerminateEx(FAIL);
        return FAIL;
    }

    bRc = CloseHandle(hFile);
    if (bRc != TRUE)
    {
        Fail("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n", 
            szTextFile);
    }

    // open and read the test file
    pFile = fopen(szTextFile, "r");
    if (pFile == NULL)
    {
        Fail("SetEndOfFile: ERROR -> fopen was unable to open file \"%s\".\n", 
            szTextFile);
    }

    // since we truncated the file at 10 characters, 
    // try reading 20 just to be safe
    memset(szBuffer, 0, 100);
    fgets(szBuffer, 20, pFile);
    fclose(pFile);
    if (strlen(szBuffer) != dwByteCount)
    {
        Fail("SetEndOfFile: ERROR -> file apparently not truncated at "
            "correct position.\n");
    }
    if (strncmp(szBuffer, szStringTest, dwByteCount) != 0)
    {
        Fail("SetEndOfFile: ERROR -> truncated file contents doesn't "
            "compare with what should be there\n");
    }

    PAL_Terminate();
    return PASS;
}
Exemple #12
0
int __cdecl main(int argc, char **argv)
{

    DWORD dwRet;
    DWORD dwRet1;
    bTestResult = FAIL;
    
    if ((PAL_Initialize(argc,argv)) != 0)
    {
        return(bTestResult);
    }

    /*
     * Create Critical Section Object
     */
    InitializeCriticalSection ( &CriticalSection );

    EnterCriticalSection ( &CriticalSection );

    hThread[0] = CreateThread(NULL,
                              0,
                              &ThreadTest1,
                              (LPVOID) 0,
                              CREATE_SUSPENDED,
                              &dwThreadId[0]);
    if (hThread[0] == NULL)
    {
        Trace("PALSUITE ERROR: CreateThread(%p, %d, %p, %p, %d, %p) call "
             "failed.\nGetLastError returned %d.\n", NULL, 0, &ThreadTest1,
             (LPVOID) 0, CREATE_SUSPENDED, &dwThreadId[0], GetLastError());
        LeaveCriticalSection(&CriticalSection);
        DeleteCriticalSection ( &CriticalSection );
        Fail("");
    }
    
    hThread[1] = CreateThread(NULL,
                              0,
                              &ThreadTest2,
                              (LPVOID) 0,
                              CREATE_SUSPENDED,
                              &dwThreadId[1]);
    if (hThread[1] == NULL)
    {
        Trace("PALSUITE ERROR: CreateThread(%p, %d, %p, %p, %d, %p) call "
             "failed.\nGetLastError returned %d.\n", NULL, 0, &ThreadTest2,
             (LPVOID) 0, CREATE_SUSPENDED, &dwThreadId[1], GetLastError());
        LeaveCriticalSection(&CriticalSection);

        dwRet = ResumeThread(hThread[0]);
        if (-1 == dwRet)
        {
            Trace("PALSUITE ERROR: ResumeThread(%p) call failed.\n"
                  "GetLastError returned '%d'.\n", hThread[0],
             GetLastError());
    }

        dwRet = WaitForSingleObject(hThread[0], 10000);
        if (WAIT_OBJECT_0 == dwRet)
        {
            Trace("PALSUITE ERROR: WaitForSingleObject(%p, %d) call "
                  "failed.  '%d' was returned instead of the expected '%d'.\n"
                  "GetLastError returned '%d'.\n", hThread[0], 10000, dwRet, 
                  WAIT_OBJECT_0, GetLastError());
        }

        if (0 == CloseHandle(hThread[0]))
        {
            Trace("PALSUITE NOTIFICATION: CloseHandle(%p) call failed.\n"
                  "GetLastError returned %d.  Not failing tests.\n", 
                  hThread[0], GetLastError());
        }

        DeleteCriticalSection(&CriticalSection);
        Fail("");
    }

    /* 
     * Set other thread priorities to be higher than ours & Sleep to ensure 
     * we give up the processor. 
     */
    dwRet = (DWORD) SetThreadPriority(hThread[0], 
                                      THREAD_PRIORITY_ABOVE_NORMAL);
    if (0 == dwRet)
    {
        Trace("PALSUITE ERROR: SetThreadPriority(%p, %d) call failed.\n"
              "GetLastError returned %d", hThread[0], 
              THREAD_PRIORITY_ABOVE_NORMAL, GetLastError());
    }
    
    dwRet = (DWORD) SetThreadPriority(hThread[1], 
                                      THREAD_PRIORITY_ABOVE_NORMAL);
    if (0 == dwRet)
    {
        Trace("PALSUITE ERROR: SetThreadPriority(%p, %d) call failed.\n"
              "GetLastError returned %d", hThread[1], 
              THREAD_PRIORITY_ABOVE_NORMAL, GetLastError());
    }

    dwRet = ResumeThread(hThread[0]);
    if (-1 == dwRet)
    {
        Trace("PALSUITE ERROR: ResumeThread(%p, %d) call failed.\n"
              "GetLastError returned %d", hThread[0], 
              GetLastError() );
    }
   
    dwRet = ResumeThread(hThread[1]); 
    if (-1 == dwRet)
    {
        Trace("PALSUITE ERROR: ResumeThread(%p, %d) call failed.\n"
              "GetLastError returned %d", hThread[0], 
              GetLastError());              
    }

    Sleep (0);

    LeaveCriticalSection (&CriticalSection);
    
    dwRet = WaitForSingleObject(hThread[0], 10000);
    dwRet1 = WaitForSingleObject(hThread[1], 10000);

    if ((WAIT_OBJECT_0 == dwRet) || 
        (WAIT_OBJECT_0 == dwRet1))
    {
        if ((1 == flags[0] && 0 == flags[1]) ||
            (0 == flags[0] && 1 == flags[1]))
        {
            bTestResult = PASS;
        }
        else 
        {
            bTestResult = FAIL;
            Trace ("PALSUITE ERROR: flags[%d] = {%d,%d}.  These values are"
                   "inconsistent.\nCriticalSection test failed.\n",
                   NUM_BLOCKING_THREADS, flags[0], flags[1]);
        }

        /* Fail the test if both threads returned WAIT_OBJECT_0 */
        if ((WAIT_OBJECT_0 == dwRet) && (WAIT_OBJECT_0 == dwRet1))
        {
            bTestResult = FAIL;
            Trace ("PALSUITE ERROR: WaitForSingleObject(%p, %d) and "
                   "WaitForSingleObject(%p, %d)\nboth returned dwRet = '%d'\n"
                   "One should have returned WAIT_TIMEOUT ('%d').\n", 
                   hThread[0], 10000, hThread[1], 10000, dwRet, WAIT_TIMEOUT);
        }        
    }
    else 
    {
        bTestResult = FAIL;
        Trace ("PALSUITE ERROR: WaitForSingleObject(%p, %d) and "
               "WaitForSingleObject(%p, %d)\nReturned dwRet = '%d' and\n"
               "dwRet1 = '%d' respectively.\n", hThread[0], 10000, hThread[1],
               10000, dwRet, dwRet1);
    }    

    if (WAIT_OBJECT_0 == dwRet)
    {
        if (0 == CloseHandle(hThread[0]))
        {
            Trace("PALSUITE NOTIFICATION: CloseHandle(%p) call failed.\n"
                  "GetLastError returned %d.  Not failing tests.\n", 
                  hThread[0], GetLastError());
        }
    }
    if (WAIT_OBJECT_0 == dwRet1)
    {
        if (0 == CloseHandle(hThread[1]))
        {
            Trace("PALSUITE NOTIFICATION: CloseHandle(%p) call failed.\n"
                  "GetLastError returned %d.  Not failing tests.\n", 
                  hThread[1], GetLastError());
        }
    }

    /* Leaking the CS on purpose, since there is still a thread 
       waiting on it */

    PAL_TerminateEx(bTestResult);
    return (bTestResult);
}
Exemple #13
0
int __cdecl main(int argc, char *argv[])
{

    PROCESS_INFORMATION pi;
    STARTUPINFO si;
    HANDLE hEvToHelper;
    HANDLE hEvFromHelper;
    DWORD dwExitCode;
    

    DWORD dwRet;
    char cmdComposeBuf[MAX_PATH];
    PWCHAR uniString;

    if(0 != (PAL_Initialize(argc, argv)))
    {
        return FAIL;
    }

    /* Create the signals we need for cross process communication */
    hEvToHelper = CreateEvent(NULL, TRUE, FALSE, szcToHelperEvName);
    if (!hEvToHelper) 
    {
        Fail("WriteProcessMemory: CreateEvent of '%S' failed. "
             "GetLastError() returned %d.\n", szcToHelperEvName, 
             GetLastError());
    }
    if (GetLastError() == ERROR_ALREADY_EXISTS) 
    {
        Fail("WriteProcessMemory: CreateEvent of '%S' failed. "
             "(already exists!)\n", szcToHelperEvName);
    }
    hEvFromHelper = CreateEvent(NULL, TRUE, FALSE, szcFromHelperEvName);
    if (!hEvToHelper) 
    {
        Fail("WriteProcessMemory: CreateEvent of '%S' failed. "
             "GetLastError() returned %d.\n", szcFromHelperEvName, 
             GetLastError());
    }
    if (GetLastError() == ERROR_ALREADY_EXISTS) 
    {
        Fail("WriteProcessMemory: CreateEvent of '%S' failed. "
             "(already exists!)\n", szcFromHelperEvName);
    }
    ResetEvent(hEvFromHelper);
    ResetEvent(hEvToHelper);
    
    if (!sprintf_s(cmdComposeBuf, _countof(cmdComposeBuf), "helper %s", commsFileName)) 
    {
        Fail("Could not convert command line\n");
    }
    uniString = convert(cmdComposeBuf);

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );
    
    /* Create a new process.  This is the process that will ask for
     * memory munging */
    if(!CreateProcess( NULL, uniString, NULL, NULL, 
                        FALSE, 0, NULL, NULL, &si, &pi)) 
    {
        Trace("ERROR: CreateProcess failed to load executable '%S'.  "
             "GetLastError() returned %u.\n",
              uniString, GetLastError());
        free(uniString);
        Fail("");
    }
    free(uniString);

    while(1) 
    {
        FILE *commsFile;
        char* pSrcMemory;
        char* pDestMemory;
        int Count;
        SIZE_T wpmCount;
        char incomingCMDBuffer[MAX_PATH + 1];

        /* wait until the helper tells us that it has given us
         * something to do */
        dwRet = WaitForSingleObject(hEvFromHelper, TIMEOUT);
        if (dwRet != WAIT_OBJECT_0)
        {
            Trace("test1 WaitForSingleObjectTest:  WaitForSingleObject "
                  "failed (%u)\n", GetLastError());
            break; /* no more work incoming */
        }

        /* get the parameters to test WriteProcessMemory with */
        if (!(commsFile = fopen(commsFileName, "r")))
        {
            /* no file means there is no more work */
            break;
        }
        if ( NULL == fgets(incomingCMDBuffer, MAX_PATH, commsFile))
        {
            Fail ("unable to read from communication file %s "
                  "for reasons %u & %u\n",
                  errno, GetLastError());
        }
        PEDANTIC1(fclose,(commsFile));
        sscanf(incomingCMDBuffer, "%u %u", &pDestMemory, &Count);
        if (argc > 1) 
        {
            Trace("Preparing to write to %u bytes @ %u ('%s')\n", 
                  Count, pDestMemory, incomingCMDBuffer);
        }

        /* compose some data to write to the client process */
        if (!(pSrcMemory = (char*)malloc(Count)))
        {
            Trace("could not dynamically allocate memory to copy from "
                  "for reasons %u & %u\n",
                  errno, GetLastError());
            goto doneIteration;
        }
        memset(pSrcMemory, nextValue, Count);

        /* do the work */
        dwRet = WriteProcessMemory(pi.hProcess, 
                           pDestMemory,
                           pSrcMemory,
                           Count,
                           &wpmCount);
        if (!dwRet)
        {
            Trace("%s: Problem: on a write to %u bytes @ %u ('%s')\n", 
                  argv[0], Count, pDestMemory, incomingCMDBuffer);
            Trace("test1 WriteProcessMemory returned a%u(!=0) (GLE=%u)\n", 
                  GetLastError());
        }
        if(Count != wpmCount)
        {
            Trace("%s: Problem: on a write to %u bytes @ %u ('%s')\n", 
                  argv[0], Count, pDestMemory, incomingCMDBuffer);
            Trace("The number of bytes written should have been "
                 "%u, but was reported as %u.\n", Count, wpmCount);
        }
        free(pSrcMemory);

    doneIteration: 
        PEDANTIC(ResetEvent, (hEvFromHelper));
        PEDANTIC(SetEvent, (hEvToHelper));
    }
            
    /* wait for the child process to complete */
    WaitForSingleObject ( pi.hProcess, TIMEOUT );
    /* this may return a failure code on a success path */

    /* check the exit code from the process */
    if( ! GetExitCodeProcess( pi.hProcess, &dwExitCode ) )
    {
        Trace( "GetExitCodeProcess call failed with error code %u\n", 
              GetLastError() ); 
        dwExitCode = FAIL;
    }


    PEDANTIC(CloseHandle, (hEvToHelper));
    PEDANTIC(CloseHandle, (hEvFromHelper));
    PEDANTIC(CloseHandle, (pi.hThread));
    PEDANTIC(CloseHandle, (pi.hProcess));

    PAL_TerminateEx(dwExitCode);
    return dwExitCode;
}
Exemple #14
0
int __cdecl main (int argc, char **argv) 
{
    HANDLE hThread;
    DWORD dwThreadId;
    DWORD dwRet;

    if(0 != (PAL_Initialize(argc, argv)))
    {
        return (bTestResult);
    }
    
    /*
     * Create critical section object and enter it
     */
    InitializeCriticalSection ( &CriticalSection );
    EnterCriticalSection(&CriticalSection);

    /*
     * Create a suspended thread 
     */
    hThread = CreateThread(NULL,
                           0,
                           &Thread,
                           (LPVOID) NULL,
                           CREATE_SUSPENDED,
                           &dwThreadId);

    if (hThread == NULL)
    {
        Trace("PALSUITE ERROR: CreateThread call failed.  GetLastError "
             "returned %d.\n", GetLastError());
        LeaveCriticalSection(&CriticalSection);
        DeleteCriticalSection(&CriticalSection);
        Fail("");
    }

    EnterCriticalSection(&CriticalSection);
    /* 
     * Set priority of the thread to greater than that of the currently
     * running thread so it is guaranteed to run.
     */
    dwRet = (DWORD) SetThreadPriority(hThread, THREAD_PRIORITY_ABOVE_NORMAL);

    if (0 == dwRet)
    {
        Trace("PALSUITE ERROR: SetThreadPriority (%p, %d) call failed.\n"
             "GetLastError returned %d.\n", hThread, 
             THREAD_PRIORITY_NORMAL, GetLastError());
    LeaveCriticalSection(&CriticalSection);
        CloseHandle(hThread);
        DeleteCriticalSection(&CriticalSection);
        Fail("");
    }

    dwRet = ResumeThread(hThread);
     
    if (-1 == dwRet)
    {
        Trace("PALSUITE ERROR: ResumeThread(%p) call failed.\nGetLastError "
             "returned %d.\n", hThread, GetLastError());
        LeaveCriticalSection(&CriticalSection);
        CloseHandle(hThread);
        DeleteCriticalSection(&CriticalSection);
        Fail("");
    }
    /* 
     * Sleep until we know the thread has been invoked.  This sleep in 
     * combination with the higher priority of the other thread should 
     * guarantee both threads block on the critical section.
     */
    while (t1_aflag == FAIL)
    {
        Sleep(1);
    }

    LeaveCriticalSection(&CriticalSection);

    switch ((WaitForSingleObject(
        hThread,
        10000)))      /* Wait 10 seconds */
    {
    case WAIT_OBJECT_0: 
        /* Object (thread) is signaled */
        LeaveCriticalSection(&CriticalSection);
        CloseHandle(hThread);
        DeleteCriticalSection(&CriticalSection);
        Fail("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have "
             "returned\nWAIT_TIMEOUT ('%d'), instead it returned "
             "WAIT_OBJECT_0 ('%d').\nA nested LeaveCriticalSection(%p) "
             "call released both threads that were waiting on it!\n", 
             hThread, 10000, WAIT_TIMEOUT, WAIT_OBJECT_0, &CriticalSection);
        break;
    case WAIT_ABANDONED: 
        /*
         * Object was mutex object whose owning
         * thread has terminated.  Shouldn't occur.
         */
        Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have "
             "returned\nWAIT_TIMEOUT ('%d'), instead it returned "
             "WAIT_ABANDONED ('%d').\nGetLastError returned '%d'\n", 
             hThread, 10000, WAIT_TIMEOUT, WAIT_ABANDONED, GetLastError());
        LeaveCriticalSection(&CriticalSection);
        CloseHandle(hThread);
        DeleteCriticalSection(&CriticalSection);
        Fail("");
        break;
    case WAIT_FAILED:    /* WaitForSingleObject function failed */
        Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have "
             "returned\nWAIT_TIMEOUT ('%d'), instead it returned "
             "WAIT_FAILED ('%d').\nGetLastError returned '%d'\n", 
             hThread, 10000, WAIT_TIMEOUT, WAIT_FAILED, GetLastError());
        LeaveCriticalSection(&CriticalSection);
        CloseHandle(hThread);
        DeleteCriticalSection(&CriticalSection);
        Fail("");
        break;
    case WAIT_TIMEOUT: 
        /* 
         * We expect this thread to timeout waiting for the 
         * critical section object to become available.
         */
        t0_tflag = PASS;
        break;  
    }

    LeaveCriticalSection(&CriticalSection);

    if (WAIT_OBJECT_0 != WaitForSingleObject (hThread, 10000)) 
    {
        if (0 == CloseHandle(hThread))
        {
            Trace("PALSUITE ERROR: CloseHandle(%p) call failed.\n"
                 "WaitForSingleObject(%p,%d) should have returned "
                 "WAIT_OBJECT_0 ('%d').\nBoth calls failed.  "
                 "Deleted CRITICAL_SECTION object which likely means\n"
                 "thread %p is now in an undefined state.  GetLastError "
                 "returned '%d'.\n", hThread, hThread, 10000, WAIT_OBJECT_0, 
                 hThread, GetLastError());
            DeleteCriticalSection(&CriticalSection);
            Fail("");
        }
        else 
        {
            Trace("PALSUITE ERROR: WaitForSingleObject(%p,%d) should have "
                 "returned WAIT_OBJECT_0 ('%d').\n  GetLastError returned "
                 "'%d'.\n", hThread, hThread, 10000, WAIT_OBJECT_0, 
                 hThread, GetLastError());
            DeleteCriticalSection(&CriticalSection);
            Fail("");
        }
    }    

    if (0 == CloseHandle(hThread))
    {
        Trace("PALSUITE ERROR: CloseHandle(%p) call failed.\n"
             "Deleted CRITICAL_SECTION object which likely means\n"
             "thread %p is now in an undefined state.  GetLastError "
             "returned '%d'.\n", hThread, hThread, GetLastError());
        DeleteCriticalSection(&CriticalSection);
        Fail("");

    }
    DeleteCriticalSection(&CriticalSection);
    /* 
     * Ensure both thread 0 experienced a wait timeout and thread 1 
     * accessed the critical section or fail the test, otherwise pass it.
     */
    if ((t0_tflag == FAIL) || (t1_cflag == FAIL))
    {
        Trace("PALSUITE ERROR: Thread 0 returned %d when %d was expected.\n"
              "Thread 1 returned %d when %d was expected.\n", t0_tflag, 
              PASS, t1_cflag, PASS); 
        bTestResult=FAIL;
    }
    else 
    {
        bTestResult=PASS;
    }
    
    PAL_TerminateEx(bTestResult);
    return (bTestResult);
}
Exemple #15
0
int __cdecl main(int argc, char *argv[])
{
    HANDLE TheFile, WaitFile;
    int result = 0;
    char DataBuffer[BUF_SIZE];
    DWORD BytesRead;
    
    if(0 != (PAL_Initialize(argc, argv)))
    {
        return FAIL;
    }
    
    /* Open the same file that the parent has opened and locked */
    TheFile = CreateFile(FILENAME,     
                         GENERIC_READ|GENERIC_WRITE, 
                         FILE_SHARE_READ|FILE_SHARE_WRITE,
                         NULL,     
                         OPEN_EXISTING,                 
                         FILE_ATTRIBUTE_NORMAL, 
                         NULL);
    
    if (TheFile == INVALID_HANDLE_VALUE) 
    { 
        Trace("ERROR: Could not open file '%s' with CreateFile.\n",FILENAME); 
        result = 1;
    }
    
    /* Open up the WaitFile that we're using for IPC */
    WaitFile = CreateFile(WAITFILENAME,     
                          GENERIC_READ|GENERIC_WRITE, 
                          FILE_SHARE_READ|FILE_SHARE_WRITE,
                          NULL,                          
                          OPEN_ALWAYS,                 
                          FILE_ATTRIBUTE_NORMAL, 
                          NULL);
    
    if (WaitFile == INVALID_HANDLE_VALUE) 
    { 
        Trace("ERROR: Could not open file '%s' with CreateFile. "
              "GetLastError() returned %d.\n",WAITFILENAME,GetLastError()); 
        result = 1;
    }
    
    
    /* Check to ensure the parent lock is respected */
    if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) != 0)
    {
        Trace("ERROR: ReadFile returned success when it should "
              "have failed.  Attempted to read the first 10 bytes "
              "of a file which was locked by the parent process.\n");
        result = 1;
    }

    // Sleep for a bit to give the parent a chance to block before we do.
    Sleep(1000);

    /* Switch back to the parent, so it can unlock the file */
    SignalAndBusyWait(WaitFile);

    if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) == 0)
    {
        Trace("ERROR: ReadFile was unable to read from the file after it "
              "had been unlocked.  Attempted to read 10 bytes and ReadFile "
              "returned 0.  GetLastError() returned %d.\n",GetLastError());
        result = 1;
    }
    
    PAL_TerminateEx(result);
    return result;
}
Exemple #16
0
int __cdecl main(int argc, char *argv[])
{
    HANDLE hFile = NULL;
    DWORD dwByteCount = 0;
    DWORD dwOffset = 25;
    DWORD dwRc = 0;
    BOOL bRc = FALSE;


    if (0 != PAL_Initialize(argc,argv))
    {
        return FAIL;
    }

    /* create a test file */
    hFile = CreateFile(szTextFile,
        GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL,
        CREATE_ALWAYS,
        FILE_ATTRIBUTE_NORMAL,
        NULL);

    if(hFile == INVALID_HANDLE_VALUE)
    {
        Fail("SetEndOfFile: ERROR -> Unable to create file \"%s\".\n",
              szTextFile);
    }

    /* move the file pointer */
    /* assumes a successful SetFilePointer test */
    dwRc = SetFilePointer(hFile, dwOffset, NULL, FILE_BEGIN);
    if (dwRc == INVALID_SET_FILE_POINTER)
    {
        Trace("SetEndOfFile: ERROR -> Call to SetFilePointer failed\n");
        bRc = CloseHandle(hFile);
        if (bRc != TRUE)
        {
            Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n",
                  szTextFile);
        }
        PAL_Terminate();
        return FAIL;
    }

    bRc = SetEndOfFile(hFile);
    if (bRc != TRUE)
    {
        Trace("SetEndOfFile: ERROR -> Uable to set end of file.\n");
        bRc = CloseHandle(hFile);
        if (bRc != TRUE)
        {
            Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n",
                  szTextFile);
        }
        PAL_TerminateEx(FAIL);
        return FAIL;
    }


    /* call GetFileSize to verify pointer position */
    /* assumes a successful GetFileSize test */

    dwByteCount = GetFileSize(hFile, NULL);
    if (dwByteCount != dwOffset)
    {
        Trace("SetEndOfFile: ERROR -> file apparently not expanded to the"
              " correct size.\n");
        bRc = CloseHandle(hFile);
        if (bRc != TRUE)
        {
            Trace("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n",
                  szTextFile);
        }
        PAL_TerminateEx(FAIL);
        return FAIL;
    }

    bRc = CloseHandle(hFile);
    if (bRc != TRUE)
    {
        Fail("SetEndOfFile: ERROR -> Unable to close file \"%s\".\n",
             szTextFile);
    }

    PAL_Terminate();
    return PASS;
}
Exemple #17
0
int __cdecl main(int argc, char *argv[])
{
    HANDLE hFile = NULL;
    DWORD dwOffset = 1;
    LONG dwHighWord = 1;
    DWORD dwReturnedOffset = 0;
    DWORD dwReturnedHighWord = 0;
    DWORD dwRc = 0;
    DWORD dwError = 0;
    BOOL bRc = FALSE;


    if (0 != PAL_Initialize(argc,argv))
    {
        return FAIL;
    }

    /* create a test file */
    hFile = CreateFile(szTextFile,
        GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL,
        CREATE_ALWAYS,
        FILE_ATTRIBUTE_NORMAL,
        NULL);

    if(hFile == INVALID_HANDLE_VALUE)
    {
        dwError = GetLastError();
        Fail("SetFilePointer: ERROR -> Unable to create file \"%s\".\n with "
            "error %ld",
            szTextFile,
            GetLastError());
    }



    /* move -1 from beginning which should fail */
    dwRc = SetFilePointer(hFile, -1, &dwHighWord, FILE_BEGIN);
    if (dwRc != INVALID_SET_FILE_POINTER)
    {
        Trace("SetFilePointer: ERROR -> Succeeded to move the pointer "
            "before the beginning of the file using the high word.\n");
        bRc = CloseHandle(hFile);
        if (bRc != TRUE)
        {
            Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n",
                szTextFile);
        }
        if (!DeleteFileA(szTextFile))
        {
            Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n",
                szTextFile);
        }
        PAL_TerminateEx(FAIL);
        return FAIL;
    }

    /* set the pointer past the end of the file and verify */
    dwRc = SetFilePointer(hFile, dwOffset, &dwHighWord, FILE_BEGIN);
    if ((dwRc == INVALID_SET_FILE_POINTER) &&
        ((dwError = GetLastError()) != ERROR_SUCCESS))
    {
        Trace("SetFilePointer: ERROR -> Failed to move pointer past EOF.\n");
        bRc = CloseHandle(hFile);
        if (bRc != TRUE)
        {
            Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n",
                szTextFile);
        }
        if (!DeleteFileA(szTextFile))
        {
            Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n",
                szTextFile);
        }
        PAL_TerminateEx(FAIL);
        return FAIL;
    }
    else
    {
        /* verify */
        bRc = SetEndOfFile(hFile);
        if (bRc != TRUE)
        {
            dwError = GetLastError();
            if (dwError == 112)
            {
                Trace("SetFilePointer: ERROR -> SetEndOfFile failed due to "
                    "lack of disk space\n");
            }
            else
            {
                Trace("SetFilePointer: ERROR -> SetEndOfFile call failed with "
                    "error %ld\n", dwError);
            }
            bRc = CloseHandle(hFile);
            if (bRc != TRUE)
            {
                Trace("SetFilePointer: ERROR -> Unable to close file"
                      " \"%s\".\n", szTextFile);
            }
            if (!DeleteFileA(szTextFile))
            {
                Trace("SetFilePointer: ERROR -> Unable to delete file"
                      " \"%s\".\n", szTextFile);
            }
            PAL_TerminateEx(FAIL);
            return FAIL;
        }

        dwReturnedOffset = GetFileSize(hFile, &dwReturnedHighWord);
        if ((dwOffset != dwReturnedOffset) ||
           (dwHighWord != dwReturnedHighWord))
        {
            Trace("SetFilePointer: ERROR -> Failed to move pointer past"
                  " EOF.\n");
            bRc = CloseHandle(hFile);
            if (bRc != TRUE)
            {
                Trace("SetFilePointer: ERROR -> Unable to close file"
                      " \"%s\".\n", szTextFile);
            }
            if (!DeleteFileA(szTextFile))
            {
                Trace("SetFilePointer: ERROR -> Unable to delete file"
                      " \"%s\".\n", szTextFile);
            }
            PAL_TerminateEx(FAIL);
            return FAIL;
        }
    }

    bRc = CloseHandle(hFile);
    if (bRc != TRUE)
    {
        Trace("SetFilePointer: ERROR -> Unable to close file \"%s\".\n", 
            szTextFile);
        if (!DeleteFileA(szTextFile))
        {
            Trace("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", 
                szTextFile);
        }
        PAL_TerminateEx(FAIL);
        return FAIL;
    }

    if (!DeleteFileA(szTextFile))
    {
        Fail("SetFilePointer: ERROR -> Unable to delete file \"%s\".\n", 
            szTextFile);
    }

    PAL_Terminate();
    return PASS;
}
Exemple #18
0
int __cdecl main(int argc, char *argv[])
{    
  int testStatus = PASS;

  if (PAL_Initialize(argc, argv))
  {
      return FAIL;
  }

  /* Use WideCharToMultiByte to convert the string in code page CP_ACP.
   * Note that the resulting string will be different on Windows PAL and 
   * Unix PAL. On Windows, the default best fit behavior will map C with 
   * circumflex to C. 
   * 
   *   testStatus |= TestWideCharToMultiByte(CP_ACP, 0, NULL, lpBestFitRes);
   *
   * On Unix, where there is no support for finding best fit, it will be 
   * mapped to a '?'. In addition, it will trigger an ASSERT in the dbg/chk
   * builds.
   *
   *   testStatus |= TestWideCharToMultiByte(CP_ACP, 0, NULL, lpResStr1);
   */

  /* Use WideCharToMultiByte with WC_NO_BEST_FIR_CHARS to convert the string 
   * in CP_ACP (1252 by default). This will prevent it from mapping the C 
   * with circumflex to its closest match in the ANSI code page: C
   */
  testStatus |= TestWideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, NULL, lpResStr1);


  /* Use WideCharToMultiByte with WC_NO_BEST_FIR_CHARS and a default character 
   * to convert the string. This will prevent it from mapping the C with 
   * circumflex to its closest match in the ANSI code page: C. It will be
   * replaced with the specified default character.
   */
  testStatus |= TestWideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, &myDefaultChar, lpResStr2);

  /* Use WideCharToMultiByte to convert the string in code page 1253 
   * Note that the resulting string will be different on Windows PAL and 
   * Unix PAL. On Windows, the default best fit behavior will map C with 
   * circumflex to C. 
   * 
   *   testStatus |= TestWideCharToMultiByte(1253, 0, NULL, lpBestFitRes);
   *
   * On Unix, where there is no support for finding best fit, it will be 
   * mapped to a '?'. In addition, it will trigger an ASSERT in the dbg/chk
   * builds.
   *
   *   testStatus |= TestWideCharToMultiByte(1253, 0, NULL, lpResStr1);
   */

  /* Use WideCharToMultiByte with WC_NO_BEST_FIR_CHARS to convert the string 
   * in 1253. This will prevent it from mapping the C 
   * with circumflex to its closest match in the ANSI code page: C
   */
  testStatus |= TestWideCharToMultiByte(1253, WC_NO_BEST_FIT_CHARS, NULL, lpResStr1);

  /* Use WideCharToMultiByte with WC_NO_BEST_FIR_CHARS and a default 
   * character to convert the string in 1253. This will prevent it from 
   * mapping the C with circumflex to its closest match in the ANSI code 
   * page: C. It will be replaced with the specified default character.
   */
  testStatus |= TestWideCharToMultiByte(1253, WC_NO_BEST_FIT_CHARS, &myDefaultChar, lpResStr2);

  PAL_TerminateEx(testStatus);

  return testStatus;
}
Exemple #19
0
int __cdecl main(int argc, char *argv[])
{
    HANDLE TheFile, WaitFile;
    int result = 0;

    if(0 != (PAL_Initialize(argc, argv)))
    {
        return FAIL;
    }

    /* Open the same file that the parent has opened and locked */
    TheFile = CreateFile(FILENAME,
                         GENERIC_READ|GENERIC_WRITE,
                         FILE_SHARE_READ|FILE_SHARE_WRITE,
                         NULL,
                         OPEN_EXISTING,
                         FILE_ATTRIBUTE_NORMAL,
                         NULL);

    if (TheFile == INVALID_HANDLE_VALUE)
    {
        Trace("ERROR: Could not open file '%s' with CreateFile.\n",FILENAME);
        result = 1;
    }

    /* Open up the WaitFile that we're using for IPC */
    WaitFile = CreateFile(WAITFILENAME,
                          GENERIC_READ|GENERIC_WRITE,
                          FILE_SHARE_READ|FILE_SHARE_WRITE,
                          NULL,
                          OPEN_ALWAYS,
                          FILE_ATTRIBUTE_NORMAL,
                          NULL);

    if (WaitFile == INVALID_HANDLE_VALUE)
    {
        Trace("ERROR: Could not open file '%s' with CreateFile. "
              "GetLastError() returned %d.\n",WAITFILENAME,GetLastError());
        result = 1;
    }

    /* Lock a section of the file different from which was locked in the
       parent proccess
    */
    if(LockFile(TheFile, 10, 0, 10, 0) == 0)
    {
        Trace("ERROR: The LockFile call within the child failed to lock "
              "the file.  GetLastError() returned %d.\n",GetLastError());
        result = 1;
    }

    /* Attempt to unlock the portion of the file which was locked within the
       parent process.
    */
    if(UnlockFile(TheFile, 0, 0, 10, 0) != 0)
    {
        Trace("ERROR: The UnlockFile call within the child succeeded in "
              "calling UnlockFile on the portion of the file which was "
              "locked by the parent.\n");
        result = 1;
    }

    // Sleep for a bit to give the parent a chance to block before we do.
    Sleep(1000);

    /* Switch back to the parent, so it can check the child lock */
    SignalAndBusyWait(WaitFile);

    /* Finally, clean up the lock which was done within this proccess and
       exit.
    */
    if(UnlockFile(TheFile, 10, 0, 10, 0) == 0)
    {
        Trace("ERROR: The UnlockFile call within the child failed to unlock "
              "the portion of the file which was locked by the child.  "
              "GetLastError() returned %d.\n", GetLastError());
        result = 1;
    }

    PAL_TerminateEx(result);
    return result;
}
int __cdecl main(int argc, char *argv[])
{
    char    testString[] = "this is a test string";
    WCHAR   lpObjectName[] = {'m','y','O','b','j','e','c','t','\0'};
    char    results[2048];
    int     RetVal = PASS;
    
    HANDLE hFileMapRW;
    LPVOID lpMapViewRW;
    LPVOID lpMapViewRW2;

    /* Initialize the PAL environment.
     */
    if(0 != PAL_Initialize(argc, argv))
    {
        return FAIL;
    }

    /* Initialize the buffers.
     */
    memset(results,  0, MAPPINGSIZE);

    /* Create a named file-mapping object with file handle FileHandle
     * and with PAGE_READWRITE protection.
    */
    hFileMapRW = CreateFileMapping(
                            SWAP_HANDLE,
                            NULL,               /*not inherited*/
                            PAGE_READWRITE,     /*read write*/
                            0,                  /*high-order size*/
                            MAPPINGSIZE,        /*low-order size*/
                            lpObjectName);      /*named object*/

    if(NULL == hFileMapRW)
    {
        Fail("ERROR:%u: Failed to create File Mapping.\n", 
             GetLastError());
    }

    /* Create a map view of the READWRITE file mapping.
     */
    lpMapViewRW = MapViewOfFile(
                            hFileMapRW,
                            FILE_MAP_ALL_ACCESS,/* access code */
                            0,                  /* high order offset*/
                            0,                  /* low order offset*/
                            MAPPINGSIZE);       /* number of bytes for map */

    if(NULL == lpMapViewRW)
    {
        Trace("ERROR:%u: Failed to call MapViewOfFile "
              "API to map a view of file!\n", 
              GetLastError());
        RetVal = FAIL;
        goto CleanUpOne;
    }


    /* maps a view of a file into the address space of the calling process.
     */
    lpMapViewRW2 = MapViewOfFile(
                            hFileMapRW,
                            FILE_MAP_ALL_ACCESS,  /* access code */
                            0,                    /* high order offset*/
                            0,                    /* low order offset*/
                            MAPPINGSIZE);         /* number of bytes for map */

    if(NULL == lpMapViewRW2)
    {
        Trace("ERROR:%u: Failed to call MapViewOfFile "
              "API to map a view of file!\n", 
              GetLastError());
        RetVal = FAIL;
        goto CleanUpTwo;
    }

    /* Write the test string to the Map view.
    */    
    memcpy(lpMapViewRW, testString, strlen(testString));

    /* Read from the second Map view.
    */
    memcpy(results, (LPCSTR)lpMapViewRW2, MAPPINGSIZE);

    /* Verify the contents of the file mapping,
     * by comparing what was written to what was read.
     */
    if (memcmp(results, testString, strlen(testString))!= 0)
    {
        Trace("ERROR: MapViewOfFile not equal to file contents "
              "retrieved \"%s\", expected \"%s\".\n",
              results,
              testString);
        RetVal = FAIL;
        goto CleanUpThree;
    }

    /* Test successful.
     */
    RetVal = PASS;

CleanUpThree:
        
    /* Unmap the view of file.
     */
    if ( UnmapViewOfFile(lpMapViewRW2) == FALSE )
    {
        Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
                GetLastError(),
                lpMapViewRW2);
        RetVal = FAIL;
    }   

CleanUpTwo:

    /* Unmap the view of file.
     */
    if ( UnmapViewOfFile(lpMapViewRW) == FALSE )
    {
        Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
                GetLastError(),
                lpMapViewRW);
        RetVal = FAIL;
    }


CleanUpOne:
        
    /* Close Handle to create file mapping.
     */
    if ( CloseHandle(hFileMapRW) == FALSE )
    {
        Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
                GetLastError(),
                hFileMapRW);
        RetVal = FAIL;
    }


    /* Terminate the PAL.
     */ 
    PAL_TerminateEx(RetVal);
    return RetVal;
}
Exemple #21
0
int __cdecl main(int argc, char *argv[])
{    
    char mbStr[128];
    WCHAR wideStr[128];
    int ret;
    int i;
    int k;
    BOOL bRet=TRUE;

    /* These codepages are currently supported by the PAL */
    int codePages[] ={
        CP_ACP,
//        932,
        949,
        950,
        1252,
        1258,
        CP_UTF8
    };


    if (PAL_Initialize(argc, argv))
    {
        return FAIL;
    }


    /* Go through all of the code pages */
    for(i=0; i<(sizeof(codePages)/sizeof(int)); i++)
    {

        for (k=0; k<128; k++)
        {
            wideStr[k] = 127 - k;
            mbStr[k] = 0;
        }

        /* Convert with buffer size of 0 */
        ret = WideCharToMultiByte(codePages[i], 0, wideStr, -1, 
                                  mbStr, 0, NULL, NULL);
        if (ret != 128)
        {
            Trace("WideCharToMultiByte did not return correct string length!\n"
                  "Got %d, expected %d for code page %d with error %u.\n", 
                  ret, 128,codePages[i],GetLastError());
            bRet=FALSE;
        }

        /* Make sure the ASCII set (0-127) gets translated correctly */
        ret = WideCharToMultiByte(codePages[i], 0, wideStr, -1, 
                                  mbStr, 128, NULL, NULL);
        if (ret != 128)
        {
            Trace("WideCharToMultiByte did not return correct string length!\n"
                  "Got %d, expected %d for code page %d with error %u.\n", 
                  ret, 128,codePages[i],GetLastError());
            bRet=FALSE;
        }

        for (k=0; k<128; k++)
        {
            if (mbStr[k] != 127 - k)
            {
                Trace("WideCharToMultiByte failed to translate correctly!\n"
                      "Expected character %d to be %c (%x), got %c (%x) for "
                      "code page %d\n",k, 127 - k, 127 - k,mbStr[k], mbStr[k],
                      codePages[i]);
                bRet=FALSE;
            }
        }


        /* try a 0 length string ("") */
        wideStr[0] = '\0';
        ret = WideCharToMultiByte(codePages[i], 0, wideStr, -1, 
                                  mbStr, 0, NULL, NULL);
        if (ret != 1)
        {
            Trace("WideCharToMultiByte did not return correct string length!\n"
                  "Got %d, expected %d for code page %d with error %u.\n", 
                  ret, 1,codePages[i],GetLastError());
            bRet=FALSE;
        }
    }

    int result = bRet ? PASS : FAIL;
    PAL_TerminateEx(result);
    return result;
}
Exemple #22
0
int __cdecl main(int argc, char *argv[])
{

    PROCESS_INFORMATION pi;
    STARTUPINFO si;
    HANDLE hEvToHelper;
    HANDLE hEvFromHelper;
    DWORD dwExitCode;
   
    DWORD dwRet;
    char cmdComposeBuf[MAX_PATH];
    PWCHAR uniString;

    if(0 != (PAL_Initialize(argc, argv)))
    {
        return FAIL;
    }

    /* Create the signals we need for cross process communication */
    hEvToHelper = CreateEvent(NULL, TRUE, FALSE, szcToHelperEvName);
    if (!hEvToHelper) 
    {
        Fail("WriteProcessMemory: CreateEvent of '%S' failed. "
             "GetLastError() returned %d.\n", szcToHelperEvName, 
             GetLastError());
    }
    if (GetLastError() == ERROR_ALREADY_EXISTS) 
    {
        Fail("WriteProcessMemory: CreateEvent of '%S' failed. "
             "(already exists!)\n", szcToHelperEvName);
    }
    hEvFromHelper = CreateEvent(NULL, TRUE, FALSE, szcFromHelperEvName);
    if (!hEvToHelper) 
    {
        Fail("WriteProcessMemory: CreateEvent of '%S' failed. "
             "GetLastError() returned %d.\n", szcFromHelperEvName, 
             GetLastError());
    }
    if (GetLastError() == ERROR_ALREADY_EXISTS) 
    {
        Fail("WriteProcessMemory: CreateEvent of '%S' failed. "
             "(already exists!)\n", szcFromHelperEvName);
    }
    ResetEvent(hEvFromHelper);
    ResetEvent(hEvToHelper);
    
    if (!sprintf(cmdComposeBuf, "helper %s", commsFileName)) 
    {
        Fail("Could not convert command line\n");
    }
    uniString = convert(cmdComposeBuf);

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );
    
    /* Create a new process.  This is the process that will ask for
     * memory munging */
    if(!CreateProcess( NULL, uniString, NULL, NULL, 
                        FALSE, 0, NULL, NULL, &si, &pi)) 
    {
        Trace("ERROR: CreateProcess failed to load executable '%S'.  "
             "GetLastError() returned %u.\n",
              uniString, GetLastError());
        free(uniString);
        Fail("");
    }
    free(uniString);


    while(1) 
    {
        FILE *commsFile;
        char* pSrcMemory;
        char* pDestMemory;
        SIZE_T Count;
        SIZE_T wpmCount;
        char incomingCMDBuffer[MAX_PATH + 1];

        int err;
        HANDLE readProcessHandle;
        DWORD readProcessID;
        char readProcessBuffer[REGIONSIZE]; // size 1024
        BOOL bResult;
        size_t size = 0;

        readProcessID = pi.dwProcessId;

        /* wait until the helper tells us that it has given us
         * something to do */
        dwRet = WaitForSingleObject(hEvFromHelper, TIMEOUT);
        if (dwRet != WAIT_OBJECT_0)
        {
            Trace("test1 WaitForSingleObjectTest:  WaitForSingleObject "
                  "failed (%u)\n", GetLastError());
            break; /* no more work incoming */
        }

        /* get the parameters to test WriteProcessMemory with */
        if (!(commsFile = fopen(commsFileName, "r")))
        {
            /* no file means there is no more work */
            break;
        }
        if ( NULL == fgets(incomingCMDBuffer, MAX_PATH, commsFile))
        {
            Fail ("unable to read from communication file %s "
                  "for reasons %u & %u\n",
                  errno, GetLastError());
        }
        PEDANTIC1(fclose,(commsFile));
        sscanf(incomingCMDBuffer, LLFORMAT " " LLFORMAT, &pDestMemory, &Count);
        if (argc > 1) 
        {
            Trace("Preparing to write to " LLFORMAT " bytes @ " LLFORMAT "('%s')\n", 
                  Count, pDestMemory, incomingCMDBuffer);
        }
     
        /* compose some data to write to the client process */
        if (!(pSrcMemory = malloc(Count)))
        {
            Trace("could not dynamically allocate memory to copy from "
                  "for reasons %u & %u\n",
                  errno, GetLastError());
            goto doneIteration;
        }
        memset(pSrcMemory, nextValue, Count);
        Trace("Preparing to write to " LLFORMAT " bytes @ " LLFORMAT " ('%s')[%u]\n", 
                  Count, pDestMemory, incomingCMDBuffer, pSrcMemory);

        /* do the work */
        dwRet = WriteProcessMemory(pi.hProcess, 
                           pDestMemory,
                           pSrcMemory,
                           Count,
                           &wpmCount);

        if (!dwRet)
        {
            Trace("%s: Problem: on a write to "LLFORMAT " bytes @ " LLFORMAT " ('%s')\n", 
                  argv[0], Count, pDestMemory, incomingCMDBuffer);
            Trace("test1 WriteProcessMemory returned a (!=0) (GLE=%u)\n", 
                  GetLastError());
        }
        if(Count != wpmCount)
        {
            Trace("%s: Problem: on a write to " LLFORMAT " bytes @ " LLFORMAT " ('%s')\n", 
                  argv[0], Count, pDestMemory, incomingCMDBuffer);
            Trace("The number of bytes written should have been "
                 LLFORMAT ", but was reported as " LLFORMAT " \n", Count, wpmCount);
        }
    
        readProcessHandle = OpenProcess(
                PROCESS_VM_READ,
                FALSE,          
                readProcessID);

        if(NULL == readProcessHandle)
        {
            Fail("\nFailed to call OpenProcess API to retrieve "
                    "current process handle error code=%u\n",
                    GetLastError());
        }
        
        /*zero the memory*/
        memset(readProcessBuffer, 0, size);

        /*retrieve the memory contents*/
        bResult = ReadProcessMemory(
                readProcessHandle,         /*current process handle*/
                pDestMemory,      /*base of memory area*/
                (LPVOID)readProcessBuffer,
                Count,            /*buffer length in bytes*/
                &size);
         

        if( !bResult || (Count != size) )
        {
            Trace("\nFailed to call ReadProcessMemory API "
                "to retrieve the memory contents, error code=%u; Bresult[%u] Count[" LLFORMAT "], Size[%d]\n",
                GetLastError(), bResult, Count, size);

            err = CloseHandle(readProcessHandle);

            if(0 == err)
            {
                Trace("\nFailed to call CloseHandle API, error code=%u\n",
                GetLastError());
            }
            dwExitCode = FAIL;
        }

        if( !memcmp (pDestMemory, readProcessBuffer, Count ) )
        {
            Trace("Difference in memory contents, expected [%s], but received [%s]\n", pDestMemory, readProcessBuffer);
            dwExitCode = FAIL;
        }

        Trace("ReadProcessBuffer contains [%s]\n", readProcessBuffer);
        err = CloseHandle(readProcessHandle);
    
        free(pSrcMemory);

    doneIteration: 
        PEDANTIC(ResetEvent, (hEvFromHelper));
        PEDANTIC(SetEvent, (hEvToHelper));
    }
            
    /* wait for the child process to complete */
    WaitForSingleObject ( pi.hProcess, TIMEOUT );
    /* this may return a failure code on a success path */

    /* check the exit code from the process */
    if( ! GetExitCodeProcess( pi.hProcess, &dwExitCode ) )
    {
        Trace( "GetExitCodeProcess call failed with error code %u\n", 
              GetLastError() ); 
        dwExitCode = FAIL;
    }


    PEDANTIC(CloseHandle, (hEvToHelper));
    PEDANTIC(CloseHandle, (hEvFromHelper));
    PEDANTIC(CloseHandle, (pi.hThread));
    PEDANTIC(CloseHandle, (pi.hProcess));

    PAL_TerminateEx(dwExitCode);
    return dwExitCode;
}
Exemple #23
0
int __cdecl main(int argc, char *argv[])
{
    WIN32_FIND_DATAW findFileData;
    WIN32_FIND_DATAW findFileData_02;
    HANDLE hFind = NULL;
    BOOL bRc = FALSE;
    char* pTemp = NULL;


    if (0 != PAL_Initialize(argc,argv))
    {
        return FAIL;
    }

    /* do some clean up just to be sure */
    removeAll();

    /* FindClose a null  handle */
    if(FindClose(NULL)!=0)
    {
         Fail("FindClose: ERROR -> Closing a NULL handle succeeded.\n");
    }

    /* find a file that exists */
    if(createTestFile(szFindName) == FALSE)
    {
        removeAll();
        PAL_TerminateEx(FAIL);
        return FAIL;
    }
    if(createTestFile(szFindName_02) == FALSE)
    {
        removeAll();
        PAL_TerminateEx(FAIL);
        return FAIL;
    }
    if(createTestFile(szFindName_03) == FALSE)
    {
        removeAll();
        PAL_TerminateEx(FAIL);
        return FAIL;
    }

    // close a FindFirstFileW handle
    hFind = FindFirstFileW(szFindName, &findFileData);
    if (hFind == INVALID_HANDLE_VALUE)
    {
        pTemp = convertC((WCHAR*)szFindName);
        Trace("FindClose: ERROR -> Unable to find \"%s\"\n", pTemp);
        free(pTemp);
        removeAll();
        PAL_TerminateEx(FAIL);
        return FAIL;
    }
    else
    {
        bRc = FindClose(hFind);
        if (bRc == FALSE)
        {
            removeAll();
            Fail("FindClose: ERROR -> Unable to close a valid"
                " FindFirstFileW handle.\n");
        }
    }
    hFind = FindFirstFileW(szFindName, &findFileData);
    if (hFind == INVALID_HANDLE_VALUE)
    {
        pTemp = convertC((WCHAR*)szFindName);
        Trace("FindClose: ERROR -> Unable to find \"%s\"\n", pTemp);
        free(pTemp);
        removeAll();
        PAL_TerminateEx(FAIL);
        return FAIL;
    }
    else
    {
        bRc = FindNextFileW(hFind, &findFileData);
        if (bRc != FALSE)
        {
            removeAll();
            Fail("FindClose: ERROR -> Found a file that doesn't exist.\n");
        }
        else
        {
            bRc = FindClose(hFind);
            if (bRc == FALSE)
            {
                removeAll();
                Fail("FindClose: ERROR -> Unable to close a valid "
                    "FindNextFileW handle.\n");
            }
        }
    }

    /* find a directory that exists */
    bRc = CreateDirectoryW(szDirName, NULL);
    if (bRc == FALSE)
    {
        pTemp = convertC((WCHAR*)szDirName);
        Trace("FindClose: ERROR -> Failed to create the directory \"%s\"\n", 
            pTemp);
        free(pTemp);
        removeAll();
        PAL_TerminateEx(FAIL);
        return FAIL;
    }

    bRc = CreateDirectoryW(szDirName_02, NULL);
    if (bRc == FALSE)
    {
        pTemp = convertC((WCHAR*)szDirName_02);
        Trace("FindClose: ERROR -> Failed to create the directory \"%s\"\n",
            pTemp);
        free(pTemp);
        removeAll();
        PAL_TerminateEx(FAIL);
        return FAIL;
    }

    hFind = FindFirstFileW(szDirName, &findFileData);
    if (hFind == INVALID_HANDLE_VALUE)
    {
        pTemp = convertC((WCHAR*)szDirName);
        Trace("FindClose: ERROR. FindFirstFileW was unable to find \"%s\"\n",
            pTemp);
        free(pTemp);
        removeAll();
        PAL_TerminateEx(FAIL);
        return FAIL;
    }
    else
    {
        bRc = FindClose(hFind);
        if (bRc == FALSE)
        {
            removeAll();
            Fail("FindClose: ERROR -> Unable to close a valid"
                " FindFirstFileW handle of a directory.\n");
        }
    }

    /* find a file using wild cards */
    hFind = FindFirstFileW(szFindNameWldCard_01, &findFileData);
    if (hFind == INVALID_HANDLE_VALUE)
    {
        pTemp = convertC((WCHAR*)szFindNameWldCard_01);
        Trace("FindClose: ERROR -> FindFirstFileW was unable to find \"%s\"\n",
            pTemp);
        free(pTemp);
        removeAll();
        PAL_TerminateEx(FAIL);
        return FAIL;
    }
    else
    {
        bRc = FindNextFileW(hFind, &findFileData_02);
        if (bRc == FALSE)
        {
            removeAll();
            Fail("FindClose: ERROR -> Unable to find another file.\n");
        }
        else
        {
            bRc = FindClose(hFind);
            if (bRc == FALSE)
            {
                removeAll();
                Fail("FindClose: ERROR -> Unable to close a valid"
                    " FindNextFileW handle.\n");
            }
        }
    }

    /* find a directory using wild cards */
    hFind = FindFirstFileW(szDirNameWldCard, &findFileData);
    if (hFind == INVALID_HANDLE_VALUE)
    {
        pTemp = convertC((WCHAR*)szDirNameWldCard);
        Trace("FindClose: ERROR -> Unable to find \"%s\"\n",
            pTemp);
        free(pTemp);
        removeAll();
        PAL_TerminateEx(FAIL);
        return FAIL;
    }
    else
    {
        bRc = FindNextFileW(hFind, &findFileData_02);
        if (bRc == FALSE)
        {
            removeAll();
            Fail("FindClose: ERROR -> Unable to find another directory.\n");
        }
        else
        {
            bRc = FindClose(hFind);
            if (bRc == FALSE)
            {
                removeAll();
                Fail("FindClose: ERROR -> Unable to close a valid"
                    " FindNextFileW handle of a directory.\n");
            }
        }
    }


    removeAll();
    PAL_Terminate();  

    return PASS;
}
Exemple #24
0
int __cdecl main(int argc, char **argv)
{
    int i, iRet;
    BOOL bRet;
    BOOL bNamedEvent = 0;
    BOOL bMutex = 0;
    BOOL bMutexAndNamedEvent = 0;
    BOOL bSemaphore = 0;
    DWORD dwRet;
    HANDLE hNamedEvent;
    HANDLE hMutex;
    char szTestName[256];
    WCHAR wszTestName[256] = { 0 };
    char szEventName[128] = { 0 };
    char szMutexName[128] = { 0 };
    char szSemName[128] = { 0 };
    WCHAR wszEventName[128];
    WCHAR wszMutexName[128];
    WCHAR wszSemName[128];
    DWORD iExitCode = 0;
    HANDLE hSemaphore;
    
    if(0 != (PAL_Initialize(argc, argv)))
    {
        return ( FAIL );
    }

    Trace("[child] Starting\n");

    for (i=1; i<argc; i++)
    {
        if (0 == strcmp(argv[i],"-event"))
        {
            bNamedEvent = 1;
        }
        else if (0 == strcmp(argv[i],"-mutex"))
        {
            bMutex = 1;
        }
        else if (0 == strcmp(argv[i],"-mutex_and_named_event"))
        {
            bMutexAndNamedEvent = 1;
        }
        else if (0 == strcmp(argv[i],"-semaphore"))
        {
            bSemaphore = 1;
        }
        else if (0 == strcmp(argv[i],"-exitcode") && i < argc-1 )
        {
            i++;
            iExitCode = atoi(argv[i]);
            Trace("[child] My exit code is %d\n", iExitCode);
        }

        else if ('-' != *argv[i])
        {
            strncpy(szTestName, argv[i], 256);
            szTestName[255] = 0;
            iRet = MultiByteToWideChar(CP_ACP, 0, szTestName, strlen(szTestName)+1, wszTestName, 256);            
            if (0 == iRet)
            {
                Fail("Failed to convert test string\n");
            }
        }
    }

    sprintf_s(szEventName, 128, "%s_Event", szTestName);
    szEventName[127] = 0;
    sprintf_s(szMutexName, 128, "%s_Mutex", szTestName);
    szMutexName[127] = 0;
    sprintf_s(szSemName, 128, "%s_Semaphore", szTestName);
    szSemName[127] = 0;

    iRet = MultiByteToWideChar(CP_ACP, 0, szEventName, strlen(szEventName)+1, wszEventName, 128);
    iRet &= MultiByteToWideChar(CP_ACP, 0, szMutexName, strlen(szMutexName)+1, wszMutexName, 128);
    iRet &= MultiByteToWideChar(CP_ACP, 0, szSemName, strlen(szSemName)+1, wszSemName, 128);
    if (0 == iRet)
    {
        Fail("[child] Failed to convert strings\n");
    }

    Trace("[child] TestName=%s Event: %S, Mutex: %S, Semaphore = %S\n",
          szTestName, wszEventName, wszMutexName, wszSemName);

    hNamedEvent = OpenEventW(0, FALSE, wszEventName);
    if (NULL == hNamedEvent)
    {
        Fail("[child] OpenEventW failed [szEventName=%s GetLastError()=%u]\n",
             szEventName, GetLastError());
    }
    hMutex = OpenMutexW(0, FALSE, wszMutexName);
    if (NULL == hMutex)
    {
        Fail("[child] OpenMutexW failed [GetLastError()=%u]\n", 
             GetLastError());
    }
    hSemaphore = CreateSemaphoreW(NULL, 0, 256, wszSemName);
    if (NULL == hSemaphore)
    {
        Fail("[child] CreateSemaphore failed [GetLastError()=%u]\n",
             GetLastError());
    }

    
    if (bMutex)
    {    
        Trace("[child] Going to wait on mutex %s\n", szMutexName);
        dwRet = WaitForSingleObject(hMutex, INFINITE);
        if (WAIT_FAILED == dwRet)
        {
            Fail("[child] WaitForMultipleObjects failed [GetLastError()=%u]\n",
                 GetLastError());
        }

        Trace("[child] Setting event %s\n", szEventName);
        bRet = SetEvent(hNamedEvent);
        if (FALSE == bRet)
        {
            Fail("[child] SetEvent failed [GetLastError()=%u]\n",
                 GetLastError());
        }

        // mutex will be abandoned        
    }
    else if (bMutexAndNamedEvent)
    {    
        dwRet = WaitForSingleObject(hMutex, INFINITE);
        if (WAIT_FAILED == dwRet)
        {
            Fail("[child] WaitForMultipleObjects failed [GetLastError()=%u]\n",
                 GetLastError());
        }

        Sleep(2000);

        bRet = ReleaseMutex(hMutex);
        if (FALSE == bRet)
        {
            Fail("[child] ReleaseMutex failed [GetLastError()=%u]\n",
                 GetLastError());
        }

        Sleep(1000);

        bRet = SetEvent(hNamedEvent);
        if (FALSE == bRet)
        {
            Fail("[child] SetEvent failed [GetLastError()=%u]\n",
                 GetLastError());
        }
    }
    else if (bSemaphore)
    {
        LONG lPrevCount = 42;        


        Trace("[child] Going to wait on event %s\n", szEventName);
        dwRet = WaitForSingleObject(hNamedEvent, INFINITE);
        if (WAIT_FAILED == dwRet)
        {
            Fail("[child] WaitForMultipleObjects failed [GetLastError()=%u]\n",
                 GetLastError());
        }

        Trace("[child] Releasing semaphore %s\n", szSemName);
        bRet = ReleaseSemaphore(hSemaphore, 10, &lPrevCount);
        if (FALSE == bRet)
        {
            Fail("ReleaseMutex failed [GetLastError()=%u]\n",
                 GetLastError());
        }
        if (0 != lPrevCount)
        {
            Fail("Previous count from semaphore=%d, expected 0\n", lPrevCount);
        }        
    }
    else if (bNamedEvent)
    {   
        Sleep(1000);
    
        bRet = SetEvent(hNamedEvent);
        if (FALSE == bRet)
        {
            Fail("[child] SetEvent failed [GetLastError()=%u]\n",
                 GetLastError());
        }
    }

    Sleep(1000);

    Trace("[child] Done\n");
   
    PAL_TerminateEx(iExitCode);
    return iExitCode;
}
Exemple #25
0
int __cdecl main(int argc, char *argv[])
{
    char szSrcExisting[] =     {"src_existing.tmp"};
    char szSrcNonExistant[] =  {"src_non-existant.tmp"};
    char szDstExisting[] =     {"dst_existing.tmp"};
    char szDstNonExistant[] =  {"dst_non-existant.tmp"};
    BOOL bRc = TRUE;
    BOOL bSuccess = TRUE;
    FILE* tempFile = NULL;
    int i;
    struct TESTS testCase[] =
    {
        {szSrcExisting, szDstExisting, FALSE, 1},
        {szSrcExisting, szDstExisting, TRUE, 0},
        {szSrcExisting, szDstNonExistant, FALSE, 1},
        {szSrcExisting, szDstNonExistant, TRUE, 1},
        {szSrcNonExistant, szDstExisting, FALSE, 0},
        {szSrcNonExistant, szDstExisting, TRUE, 0},
        {szSrcNonExistant, szDstNonExistant, FALSE, 0},
        {szSrcNonExistant, szDstNonExistant, TRUE, 0}
    };


    if (0 != PAL_Initialize(argc,argv))
    {
        return FAIL;
    }

    /* create the src_existing file */
    tempFile = fopen(szSrcExisting, "w");
    if (tempFile != NULL)
    {
        fprintf(tempFile, "CopyFileA test file: src_existing.tmp\n");
        fclose(tempFile);
    }
    else
    {
        Fail("CopyFileA: ERROR-> Couldn't create \"src_existing.tmp\" with "
            "error %ld\n",
            GetLastError());
    }

    /* create the dst_existing file */
    tempFile = fopen(szDstExisting, "w");
    if (tempFile != NULL)
    {
        fprintf(tempFile, "CopyFileA test file: dst_existing.tmp\n");
        fclose(tempFile);
    }
    else
    {
        Fail("CopyFileA: ERROR-> Couldn't create \"dst_existing.tmp\" with "
            "error %ld\n",
            GetLastError());
    }



    for (i = 0; i < (sizeof(testCase) / sizeof(struct TESTS)); i++)
    {
        bRc = CopyFileA(testCase[i].lpSource,
                        testCase[i].lpDestination,
                        testCase[i].bFailIfExists);
        if (!bRc)
        {
            if (testCase[i].nResult == 1)
            {
                Trace("CopyFileA: FAILED: %s -> %s with bFailIfExists = %d "
                    "with error %ld\n",
                    testCase[i].lpSource,
                    testCase[i].lpDestination,
                    testCase[i].bFailIfExists,
                    GetLastError());
                bSuccess = FALSE;
            }
        }
        else
        {
            if (testCase[i].nResult == 0)
            {
                Trace("CopyFileA: FAILED: %s -> %s with bFailIfExists = %d\n",
                    testCase[i].lpSource,
                    testCase[i].lpDestination,
                    testCase[i].bFailIfExists);
                bSuccess = FALSE;
            }
            else
            {
                /* verify the file was moved */
                if (GetFileAttributesA(testCase[i].lpDestination) == -1)
                {
                    Trace("CopyFileA: GetFileAttributes of destination file "
                        "failed with error code %ld. \n",
                        GetLastError());
                    bSuccess = FALSE;
                }
                else if (GetFileAttributesA(testCase[i].lpSource) == -1)
                {
                    Trace("CopyFileA: GetFileAttributes of source file "
                        "failed with error code %ld. \n",
                        GetLastError());
                    bSuccess = FALSE;
                }
                else
                {
                    /* verify attributes of destination file to source file*/                    
                    if(GetFileAttributes(testCase[i].lpSource) !=
                            GetFileAttributes(testCase[i].lpDestination))
                    {
                        Trace("CopyFileA : The file attributes of the "
                            "destination file do not match the file "
                            "attributes of the source file.\n");
                        bSuccess = FALSE;
                    }
                }
            }
        }
        /* delete file file but don't worry if it fails */
        DeleteFileA(szDstNonExistant);
    }

    int exitCode = bSuccess ? PASS : FAIL;
    PAL_TerminateEx(exitCode);
    return exitCode;
}