Changeset 6788 for trunk/src


Ignore:
Timestamp:
Sep 23, 2001, 8:51:07 AM (24 years ago)
Author:
bird
Message:

Rewrote test2 to produce the fake .DLL.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/win32k/kKrnlLib/testcase/kKrnlLibTst.c

    r6736 r6788  
    1 /* $Id: kKrnlLibTst.c,v 1.1 2001-09-17 01:41:14 bird Exp $
     1/* $Id: kKrnlLibTst.c,v 1.2 2001-09-23 06:51:07 bird Exp $
    22 *
    33 * kKrnlLib test module.
     
    2222#define FlatToSel(flataddr) \
    2323    (PVOID)( ( (((unsigned)(flataddr) << 3) & 0xfff80000) | (SEL_LDT_RPL3 << 16) ) | ((unsigned)(flataddr) & 0xffff) )
     24
     25#define assert(expr) ((expr) ? (void)0 : __interrupt(3))
    2426
    2527#define DWORD   ULONG
     
    3133#define INCL_BASE
    3234#define INCL_SSTODS
     35#define FOR_EXEHDR 1
    3336#include <os2.h>
    3437#include <exe386.h>
     38#include <newexe.h>
    3539
    3640#include "devSegDf.h"                   /* kKrnlLib segment definitions. */
     
    5054#include "kKrnlLib.h"
    5155
     56#include "ProbKrnl.h"
     57#include "krnlPrivate.h"
    5258#include "testcase.h"
    5359
     
    256262int     CompareOptions(struct kKLOptions *pOpt);
    257263int     TestCaseExeLoad2(void);
     264int     WritekKrnlLibDll(void);
    258265
    259266
     
    708715            if (rc == NO_ERROR)
    709716            {
    710                  rc = TestCaseExeLoad2();
     717                rc = WritekKrnlLibDll();
    711718            }
    712719        }
     
    720727}
    721728
    722 /**
    723  * Test case 3.
    724  * Checks that all parameters are read correctly (1).
    725  *
    726  * @sketch  Create init packet with no arguments.
    727  *          Initiate kKrnlHlp
    728  *          Create init packet with no arguments.
    729  *          Initiate kKrnlLib
    730  * @returns 0 on success.
    731  *          1 on failure.
    732  * @status  completely implemented.
    733  * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
    734  */
    735 int TestCase3(void)
     729
     730
     731int WritekKrnlLibDll(void)
    736732{
    737     int         rc = 1;
    738     RP32INIT    rpinit;
    739     char *      pszInitArgs = "-C1 -L:N -Verbose -Quiet -Elf:Yes -Pe:PE -Script:Yes -Rexx:NES -Java:NYes -W4 -Heap:512000 -ResHeap:0256000 -HeapMax:4096000 -ResHeapMax:0x100000";
    740 
    741     /* kKrnlHlp */
    742     initRPInit(SSToDS(&rpinit), pszInitArgs);
    743     rc = InitkKrnlHlp(&rpinit);              /* no SSToDS! */
    744     printf("InitkKrnlHlp returned status=0x%04x\n", rpinit.rph.Status);
    745     if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
    746     {
    747         /* kKrnlLib */
    748         initRPInit(SSToDS(&rpinit), pszInitArgs);
    749         rc = InitkKrnlLib(&rpinit);       /* no SSToDS! */
    750         printf("InitkKrnlLib returned status=0x%04x\n", rpinit.rph.Status);
    751         if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
     733    ULONG   ulAction;
     734    int     rc;
     735    HFILE   hFile = NULLHANDLE;
     736
     737    /*
     738     * Open the file.
     739     */
     740    rc = DosOpen("kKrnlLib.Dll", SSToDS(&hFile), SSToDS(&ulAction), 0, FILE_NORMAL,
     741                 OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS,
     742                 OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYREAD | OPEN_ACCESS_WRITEONLY,
     743                 NULL);
     744    if (rc == NO_ERROR)
     745    {
     746        static struct e32_exe   exehdr;
     747        static struct o32_obj   aObjTab[24];
     748        struct o32_map          page;
     749        int                     i;
     750        int                     j;
     751        ULONG                   ulWritten;
     752        ULONG                   ulPos;
     753        ULONG                   ulNULL = 0;
     754
     755
     756        /* make exehdr */
     757        memset(&exehdr, 0, sizeof(exehdr));
     758        exehdr.e32_magic[0] = E32MAGIC1;
     759        exehdr.e32_magic[1] = E32MAGIC2;
     760        exehdr.e32_cpu      = E32CPU486;
     761        exehdr.e32_os       = NE_OS2;
     762        exehdr.e32_mflags   = E32MODDLL | E32PMW;
     763        exehdr.e32_mpages   = 0;
     764        for (i = 0; i < KKL_SwapMTE.smte_objcnt; i++)
     765            exehdr.e32_mpages += (KKL_SwapMTE.smte_objtab[i].ote_size + 0xfff) >> 12;
     766        exehdr.e32_startobj = 2;
     767        exehdr.e32_eip      = 0;
     768        exehdr.e32_pagesize = 0x1000;
     769        exehdr.e32_fixupsize= exehdr.e32_mpages * sizeof(unsigned long)
     770                            + 4;
     771        exehdr.e32_ldrsize  = KKL_SwapMTE.smte_objcnt * sizeof(struct o32_obj)
     772                            + exehdr.e32_mpages * sizeof(struct o32_map)
     773                            + &KKL_ResNameTabEND[0] - (char*)KKL_SwapMTE.smte_restab
     774                            + exehdr.e32_mpages * sizeof(unsigned long)
     775                            + 4;
     776        exehdr.e32_objtab   = sizeof(exehdr);
     777        exehdr.e32_objcnt   = KKL_SwapMTE.smte_objcnt;
     778        exehdr.e32_objmap   = exehdr.e32_objtab + exehdr.e32_objcnt * sizeof(struct o32_obj);
     779        exehdr.e32_restab   = exehdr.e32_objmap + exehdr.e32_mpages * sizeof(struct o32_map);
     780        exehdr.e32_enttab   = exehdr.e32_restab + &KKL_ResNameTabEND[0] - (char*)KKL_SwapMTE.smte_restab;
     781        exehdr.e32_fpagetab = exehdr.e32_enttab + &KKL_EntryTabEND[0] - (char*)KKL_SwapMTE.smte_enttab;
     782        exehdr.e32_frectab  = exehdr.e32_fpagetab+exehdr.e32_mpages * sizeof(unsigned long);
     783        exehdr.e32_datapage = exehdr.e32_frectab + 4;
     784        exehdr.e32_nrestab  = 0;
     785        exehdr.e32_cbnrestab= 0;
     786
     787        /* make object table */
     788        memcpy(&aObjTab[0], KKL_SwapMTE.smte_objtab, KKL_SwapMTE.smte_objcnt * sizeof(struct o32_obj));
     789        for (i = 0, j = 1; i < KKL_SwapMTE.smte_objcnt; i++)
    752790        {
    753             struct kKLOptions opt = DEFAULT_OPTION_ASSIGMENTS;
    754             opt.cbSwpHeapInit   = 512000;
    755             opt.cbSwpHeapMax    = 4096000;
    756             opt.cbResHeapInit   = 0256000;
    757             opt.cbResHeapMax    = 0x100000;
    758             opt.fQuiet          = TRUE;
    759             opt.fLogging        = FALSE;
    760             opt.usCom           = OUTPUT_COM1;
    761 
    762             rc = CompareOptions(SSToDS(&opt));
    763             if (rc == NO_ERROR)
     791            aObjTab[i].o32_reserved = 0;
     792            aObjTab[i].o32_pagemap = j;
     793            j += aObjTab[i].o32_mapsize = (aObjTab[i].o32_size + 0xfff) >> 12;
     794            printf("obj %02d: base=%08x size=%08x page=%08x pages=%08x\n",
     795                   i, aObjTab[i].o32_base, aObjTab[i].o32_size, aObjTab[i].o32_pagemap, aObjTab[i].o32_mapsize);
     796        }
     797
     798        /* write the header stuff */
     799        DosWrite(hFile, &exehdr, sizeof(exehdr), SSToDS(&ulWritten));
     800        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_objtab);
     801        DosWrite(hFile, &aObjTab[0], exehdr.e32_objcnt * sizeof(struct o32_obj), SSToDS(&ulWritten));
     802        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_objmap);
     803        for (i = 0, page.o32_pagedataoffset = 0; i < KKL_SwapMTE.smte_objcnt; i++)
     804        {
     805            for (j = 0; j < aObjTab[i].o32_mapsize;j++, page.o32_pagedataoffset += 0x1000)
    764806            {
    765                  rc = TestCaseExeLoad2();
     807                page.o32_pageflags = VALID;
     808                page.o32_pagesize = 0x1000;
     809                DosWrite(hFile, SSToDS(&page), sizeof(struct o32_map), SSToDS(&ulWritten));
    766810            }
    767811        }
    768         else
    769             printf("!failed!\n");
    770     }
    771     else
    772         printf("!failed!\n");
    773 
    774     return rc;
     812        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_restab);
     813        DosWrite(hFile, &KKL_ResNameTab[0], &KKL_ResNameTabEND[0] - (char*)KKL_SwapMTE.smte_restab, SSToDS(&ulWritten));
     814        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_enttab);
     815        DosWrite(hFile, &KKL_EntryTab[0], &KKL_EntryTabEND[0] - (char*)KKL_SwapMTE.smte_enttab, SSToDS(&ulWritten));
     816        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_fpagetab);
     817        for (i = 0, page.o32_pagedataoffset = 0; i < KKL_SwapMTE.smte_objcnt; i++)
     818        {
     819            for (j = 0; j < aObjTab[i].o32_mapsize;j++, page.o32_pagedataoffset += 0x1000)
     820                DosWrite(hFile, SSToDS(&ulNULL), sizeof(ulNULL), SSToDS(&ulWritten));
     821        }
     822        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_frectab);
     823        DosWrite(hFile, SSToDS(&ulNULL), sizeof(ulNULL), SSToDS(&ulWritten));
     824
     825        /* Write data pages. */
     826        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_datapage);
     827        for (i = 0; i < KKL_SwapMTE.smte_objcnt; i++)
     828            for (j = 0; j < aObjTab[i].o32_mapsize; j++)
     829            {
     830                static char achPage[0x1000];
     831                char    *pchData = (char*)aObjTab[i].o32_base + j * 0x1000;
     832                int k;
     833                if (aObjTab[i].o32_flags & (OBJINVALID | OBJIOPL))
     834                    memset(achPage[0], 0x1000, 0);
     835                else
     836                    for (k = 0; k < 0x1000; k++, pchData++)
     837                        achPage[k] = *pchData;
     838                DosWrite(hFile, &achPage[0], 0x1000, SSToDS(&ulWritten));
     839            }
     840
     841        /*
     842         * Close file - We're finished in a way.
     843         */
     844        DosClose(hFile);
     845    }
     846
     847    return 0;
    775848}
    776 
    777 
    778 /**
    779  * Test case 4.
    780  * Checks that all parameters are read correctly (3).
    781  *
    782  * @sketch  Create init packet with no arguments.
    783  *          Initiate kKrnlHlp
    784  *          Create init packet with no arguments.
    785  *          Initiate kKrnlLib
    786  * @returns 0 on success.
    787  *          1 on failure.
    788  * @status  completely implemented.
    789  * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
    790  */
    791 int TestCase4(void)
    792 {
    793     int         rc = 1;
    794     RP32INIT    rpinit;
    795     char *      pszInitArgs = "-P:pe";
    796 
    797     /* kKrnlHlp */
    798     initRPInit(SSToDS(&rpinit), pszInitArgs);
    799     rc = InitkKrnlHlp(&rpinit);              /* no SSToDS! */
    800     printf("InitkKrnlHlp returned status=0x%04x\n", rpinit.rph.Status);
    801     if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
    802     {
    803         /* kKrnlLib */
    804         initRPInit(SSToDS(&rpinit), pszInitArgs);
    805         rc = InitkKrnlLib(&rpinit);       /* no SSToDS! */
    806         printf("InitkKrnlLib returned status=0x%04x\n", rpinit.rph.Status);
    807         if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
    808         {
    809             struct kKLOptions opt = DEFAULT_OPTION_ASSIGMENTS;
    810 
    811             rc = CompareOptions(SSToDS(&opt));
    812             /*
    813             if (rc == NO_ERROR)
    814             {
    815                  rc = TestCaseExeLoad2();
    816             }
    817             */
    818         }
    819         else
    820             printf("!failed!\n");
    821     }
    822     else
    823         printf("!failed!\n");
    824 
    825     return rc;
    826 }
    827 
    828 
    829 /**
    830  * Test case 5.
    831  * Checks that all parameters are read correctly (3).
    832  *
    833  * @sketch  Create init packet with no arguments.
    834  *          Initiate kKrnlHlp
    835  *          Create init packet with no arguments.
    836  *          Initiate kKrnlLib
    837  * @returns 0 on success.
    838  *          1 on failure.
    839  * @status  completely implemented.
    840  * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
    841  */
    842 int TestCase5(void)
    843 {
    844     int         rc = 1;
    845     RP32INIT    rpinit;
    846     char *      pszInitArgs = "-Pe:pe";
    847 
    848     /* kKrnlHlp */
    849     initRPInit(SSToDS(&rpinit), pszInitArgs);
    850     rc = InitkKrnlHlp(&rpinit);              /* no SSToDS! */
    851     printf("InitkKrnlHlp returned status=0x%04x\n", rpinit.rph.Status);
    852     if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
    853     {
    854         /* kKrnlLib */
    855         initRPInit(SSToDS(&rpinit), pszInitArgs);
    856         rc = InitkKrnlLib(&rpinit);       /* no SSToDS! */
    857         printf("InitkKrnlLib returned status=0x%04x\n", rpinit.rph.Status);
    858         if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
    859         {
    860             struct kKLOptions opt = DEFAULT_OPTION_ASSIGMENTS;
    861 
    862             rc = CompareOptions(SSToDS(&opt));
    863             /*
    864             if (rc == NO_ERROR)
    865             {
    866                  rc = TestCaseExeLoad2();
    867             }
    868             */
    869         }
    870         else
    871             printf("!failed!\n");
    872     }
    873     else
    874         printf("!failed!\n");
    875 
    876     return rc;
    877 }
    878 
    879849
    880850/**
     
    920890    return rc;
    921891}
    922 
    923 
    924 /**
    925  * Simulates a executable loading (no errors).
    926  * This test requires a PE executable file named ExecLoad1.exe which
    927  * imports the dll ExecLoad1d.dll.
    928  *
    929  * @returns 0 on success.
    930  *          > 0 on failure.
    931  * @sketch
    932  * @status
    933  * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
    934  * @remark
    935  */
    936 int TestCaseExeLoad2(void)
    937 {
    938     APIRET rc;
    939     int    cch;
    940     char * psz;
    941 
    942     /*
    943      * Set global parameters... FIXME.
    944      */
    945 
    946     /*
    947      * Do the real execution.
    948      */
    949     printf("--- TestcaseExeLoad2 - loading win32ktst.exe (LX image) ----\n");
    950     rc = CalltkExecPgm(EXEC_LOAD, NULL, NULL, "GLC6000.TMP");
    951     if (rc == NO_ERROR)
    952     {
    953         psz = "BIN\\DEBUG\\LIBCONV.EXE\0";
    954         printf("--- TestcaseExeLoad2 - loading libconv.exe (LX image) ----\n");
    955         rc = CalltkExecPgm(EXEC_LOAD, NULL, NULL, "bin\\debug\\libconv.exe");
    956         if (rc == NO_ERROR)
    957         {
    958             #if 0 //not implemented by CalltkExecPgm...???
    959             /* check result */
    960             if (memcmp(achTkExecPgmArguments, psz, strlen(psz) + 1) != 0)
    961             {
    962                 rc  = ERROR_BAD_ARGUMENTS;
    963                 printf("Bad Arguments! (%s)\n", achTkExecPgmArguments);
    964             }
    965             #else
    966             psz = psz;
    967             #endif
    968         }
    969     }
    970 
    971     if (rc == NO_ERROR)
    972     {
    973         psz = "REXX\\TST.RX\0OriginalArgument1 OriginalArgument2\0OriginalArgument3\0";
    974         printf("--- TestcaseExeLoad2 - loading rexx\\tst.rx (REXX script) ----\n");
    975         rc = CalltkExecPgm(EXEC_LOAD, psz, NULL, "rexx\\tst.rx");
    976         if (rc == NO_ERROR)
    977         {
    978             /* check result */
    979             psz = "REXX\\TST.RX OriginalArgument1 OriginalArgument2\0OriginalArgument3\0";
    980             cch = strlen(psz);
    981             #if 0
    982             if (memcmp(achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1, psz, cch) != 0)
    983             {
    984                 rc = ERROR_BAD_ARGUMENTS;
    985                 printf("Bad Arguments! (achTkExecPgmArguments=%s).\n", achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1);
    986             }
    987             #endif
    988         }
    989     }
    990 
    991     if (rc == NO_ERROR)
    992     {
    993         psz = "TEST\\TST.SH\0OrgArg1 OrgArg2\0OrgArg3\0";
    994         printf("--- TestcaseExeLoad2 - loading test\\tst.sh (UNIX shell script) ----\n");
    995         rc = CalltkExecPgm(EXEC_LOAD, psz, NULL, "test\\tst.sh");
    996         if (rc == NO_ERROR)
    997         {
    998             /* check result */
    999             psz = "TEST\\TST.SH OrgArg1 OrgArg2\0OrgArg3\0";
    1000             cch = strlen(psz);
    1001             #if 0
    1002             if (memcmp(achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1, psz, cch) != 0)
    1003             {
    1004                 rc  = ERROR_BAD_ARGUMENTS;
    1005                 printf("Bad Arguments! (achTkExecPgmArguments=%s).\n", achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1);
    1006             }
    1007             #endif
    1008         }
    1009     }
    1010 
    1011     if (rc == NO_ERROR)
    1012     {
    1013         psz = "TEST\\TST2.SH\0OrgArg1 OrgArg2\0OrgArg3\0";
    1014         printf("--- TestcaseExeLoad2 - loading test\\tst2.sh (UNIX shell script) ----\n");
    1015         rc = CalltkExecPgm(EXEC_LOAD, psz, NULL, "test\\tst2.sh");
    1016         if (rc == NO_ERROR)
    1017         {
    1018             /* check result */
    1019             psz = "-arg1 -arg2 -arg3 TEST\\TST2.SH OrgArg1 OrgArg2\0OrgArg3\0";
    1020             cch = strlen(psz) + 1;
    1021             #if 0
    1022             if (memcmp(achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1, psz, cch) != 0)
    1023             {
    1024                 rc  = ERROR_BAD_ARGUMENTS;
    1025                 printf("Bad Arguments! (achTkExecPgmArguments=%s).\n", achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1);
    1026             }
    1027             #endif
    1028         }
    1029     }
    1030 
    1031     if (rc == NO_ERROR)
    1032     {
    1033         psz = "E:\\WIN32PROG\\SOL\\SOL.EXE\0";
    1034         printf("--- TestcaseExeLoad2 - loading SOL.EXE (PE image) ----\n");
    1035         rc = CalltkExecPgm(EXEC_LOAD, psz, NULL, "e:\\Win32Prog\\Sol\\Sol.exe");
    1036         #if 0
    1037         if (rc == NO_ERROR)
    1038         {
    1039             /* check result */
    1040             cch = strlen(psz) + 1 + 1;
    1041             if (memcmp(achTkExecPgmArguments, psz, cch) != 0)
    1042             {
    1043                 rc  = ERROR_BAD_ARGUMENTS;
    1044                 printf("Bad Arguments! (achTkExecPgmArguments=%s).\n", achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1);
    1045             }
    1046         }
    1047         #endif
    1048     }
    1049 
    1050     /*
    1051      * The test is successful if rc == NO_ERROR (== 0).
    1052      */
    1053     return rc;
    1054 }
    1055 
Note: See TracChangeset for help on using the changeset viewer.