Share via


Create Your Test DLL for the CTK (Compact 2013)

3/26/2014

Creating a test DLL for the Windows Embedded Compact Test Kit (CTK) is similar to creating a console application; both are subprojects of your OS design.

To create a CTK test DLL

  1. Open your previously created OS design in Platform Builder.

  2. In the Solution Explorer window, right-click Subprojects, and then click Add New Subproject.

  3. In the Subproject Wizard window, click WCE TUX Dynamic-Link Library from the Available templates list.

  4. In the Subproject name field, type DriverTUXTest, and then click Next.

  5. Click Finish.

    Your new subproject appears under Subprojects in Solution Explorer. If you expand the DriverTUXTest subproject node, you find the Source files folder. The folder contains three files: DriverTUXTest.cpp, Globals.cpp, and Test.cpp. In the next step, you will add a test to Test.cpp. Before you add the test, the code resembles the following example.

    #include "main.h"
    #include "globals.h"
    
    TESTPROCAPI TestProc(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
    {
        // The shell doesn't necessarily want us to execute the test.
        // Make sure first.
        if(uMsg != TPM_EXECUTE)
        {
            return TPR_NOT_HANDLED;
        }
    
        // TODO: Replace the following line with your own test code here.
        // Also, change the return value from TPR_SKIP to the appropriate
        // code.
        g_pKato->Log(LOG_COMMENT, TEXT("This test is not yet implemented."));
    
        return TPR_SKIP;
    }
    
  6. Modify Test.cpp file to include calls to ActivateDeviceEx, CreateFile, CloseHandle, and DeactivateDevice, just as you did in the console driver. You can then add any additional calls that are specifically required for testing the driver, such as WriteFile, ReadFile, and DeviceIoControl. For example, in the Test.cpp file, replace the code lines after the TODO comment with the following code.

        g_pKato->Log(LOG_COMMENT, TEXT("Stream driver TUX test starting"));
    
        HANDLE    hActiveDriver = NULL;
        HANDLE    hDriver = NULL;
        bool      bReturn = false;
    
        hActiveDriver = ActivateDeviceEx(L"\\Drivers\\Streamdriver", NULL, 0, NULL);
        if (hActiveDriver == INVALID_HANDLE_VALUE)
        {
            g_pKato->Log(LOG_COMMENT, TEXT("Unable to load stream driver."));
            return TPR_FAIL;
        }
    
        // Open the driver
        hDriver = CreateFile (L"SDT1:",
                        GENERIC_READ| GENERIC_WRITE,
                        FILE_SHARE_READ | FILE_SHARE_WRITE,
                        NULL,
                        OPEN_EXISTING,
                        FILE_ATTRIBUTE_NORMAL,
                        NULL);
        if (hDriver == INVALID_HANDLE_VALUE)
        {
            g_pKato->Log(LOG_COMMENT, TEXT("Unable to open stream driver."));
            return TPR_FAIL;
        }
    
        // Add test code here
    
        // Close the driver
        if (hDriver != INVALID_HANDLE_VALUE)
        {
            bReturn = CloseHandle(hDriver);
            if (bReturn == FALSE)
            {
                g_pKato->Log(LOG_COMMENT, TEXT("Unable to close stream driver."));
            }
        }
    
        // Ask the Device Manager to unload the driver
        if (hActiveDriver != INVALID_HANDLE_VALUE)
        {
            bReturn = DeactivateDevice(hActiveDriver);
            if (bReturn == FALSE)
            {
                g_pKato->Log(LOG_COMMENT, TEXT("Unable to unload stream driver."));
            }
        }
    
        return TPR_PASS;
    
  7. In Solution Explorer, right-click the DriverTuxTest subproject, and then click Build.

See Also

Concepts

Test Your Driver by Using the CTK