source: trunk/src/win32k/test/win32ktst.c@ 4810

Last change on this file since 4810 was 4810, checked in by bird, 25 years ago

Synced test env. with the rest of win32k.sys.
Added testcases for testing -PE:pe vs. -P:pe.

File size: 35.2 KB
Line 
1/* $Id: win32ktst.c,v 1.5 2000-12-16 23:03:32 bird Exp $
2 *
3 * Win32k test module.
4 *
5 * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
6 *
7 * Project Odin Software License can be found in LICENSE.TXT
8 *
9 */
10
11/*******************************************************************************
12* Defined Constants And Macros *
13*******************************************************************************/
14#define INCL_BASE
15#define INCL_OS2KRNL_ALL
16#define INCL_SSTODS
17
18#define SEL_FLATMASK 0x01fff0000
19#define SEL_FLAT_SHIFT 0x0d
20#define SEL_LDT_RPL3 0x07
21
22#define SelToFlat(sel, off) \
23 (PVOID)( (((unsigned)(sel) << SEL_FLAT_SHIFT) & SEL_FLAT_MASK) + (unsigned)(off))
24
25#define FlatToSel(flataddr) \
26 (PVOID)( ( (((unsigned)(flataddr) << 3) & 0xfff80000) | (SEL_LDT_RPL3 << 16) ) | ((unsigned)(flataddr) & 0xffff) )
27
28#define DWORD ULONG
29#define WORD USHORT
30
31/*******************************************************************************
32* Internal Functions *
33*******************************************************************************/
34#include <os2.h>
35#include <exe386.h>
36
37#include "devSegDf.h" /* Win32k segment definitions. */
38
39#include "malloc.h"
40
41#include <stdio.h>
42#include <string.h>
43#include <stdlib.h>
44
45#include "options.h"
46#include "dev1632.h"
47#include "dev32.h"
48#include "devcmd.h"
49#include "os2krnl.h"
50#include "avl.h"
51#include "ldr.h"
52#include "ldrCalls.h"
53#include "test.h"
54#include "asmutils.h"
55#include "macros.h"
56#include "log.h"
57
58
59
60
61
62/** @design Win32k Ring-3 Testing
63 * I'll try to make it possible to test parts or all the win32k code in ring-3.
64 * To archive this the interface against the kernel has to be faked/emulated.
65 * More precisely:
66 * - DevHelps.
67 * - Worker routines for imported kernel functions. (calltab.asm jumps to them.)
68 * - 16-bit stack 1Kb.
69 * - Strategy calls.
70 * - Fake module loadings (= testcases).
71 * - ?
72 *
73 * Some of the initstuff has to be omitted, at least in the start. The first
74 * goal is to be able to test _ldrOpenPath and _ldrOpen.
75 *
76 *
77 * @subsection Device Helper Routines
78 *
79 * These I think we'll implemented by providing the kernel interface, a far 16:16
80 * pointer to a dh-router. Our router will in most cases thunk back to 32-bit
81 * code and implementet the required devhelp routines in pure C code.
82 *
83 * These are the needed routines:
84 * - DevHelp_VirtToLin - ok
85 * - DevHelp_VMAlloc - ok
86 * - DevHelp_VMFree - ok
87 * - DevHelp_GetDOSVar - ok
88 * - DevHelp_VMLock
89 * - DevHelp_VMUnLock ?
90 * - DevHelp_VMSetMem ?
91 * - DevHelp_Yield ?
92 *
93 *
94 * @subsection Worker routines for imported kernel functions
95 *
96 * Create worker routines for the imported kernel functions. Calltab will be
97 * set up to jump to them. This is done in d32init.c, in stead of using
98 * the importtab.
99 *
100 * Some of these workers will be parts of testcases. For example g_tkExecPgm
101 * and _LDRQAppType.
102 *
103 * Only the imported functions are implemented on demand. Initially these
104 * functions will be provided:
105 * - ldrOpen
106 * - ldrRead
107 * - ldrClose
108 * - ldrOpenPath
109 * - SftFileSize
110 *
111 *
112 * @subsection 16-bit stack
113 *
114 * To make this test real the stack has to be 16-bit and _very_ small (1KB).
115 * TKSSBase have to be implemented by the DevHelp_GetDOSVar DosTable2 stuff.
116 * The stack will be thunked to 16-bit by a thunking procedure called from
117 * main. This procedure thunks the stack (quite easy, we're in tiled memory!),
118 * set the value of TKSSBase, calls a C function which does all the rest of
119 * the testing. When taht function returns, the stack will be thunked back
120 * to 32-bit, TKSSBase will be zeroed, and the procedure returns to main.
121 *
122 *
123 * @subsection Straegy routine calls (not implemented)
124 *
125 * We'll call the strategy entry points with init request packets. The initiation
126 * will require a replacement for DosDevIOCtl (16-bit) which calls the
127 * $elf strategy routine. We'll also have to provide fakes for kernel probing,
128 * verifing and overloading in d32init.c.
129 *
130 *
131 * @subsection Order of events
132 *
133 * This is the order this testing environment currently works:
134 * 1) init devhelp subsystem
135 * 2) init workers
136 * 3) thunk stack
137 * 4) Fake 16-bit init. Set TKSSBase, FlatDS, FlatCS, DevHelp pointer....
138 * 5) Call R0Init32().
139 * (d32init.c is modified a bit to setup the calltab correctly.)
140 * 6) Start testing...
141 * 7) Testing finished - thunk stack back to 32-bit.
142 */
143
144
145/*******************************************************************************
146* Structures and Typedefs *
147*******************************************************************************/
148#ifndef QS_MTE
149 /* From OS/2 Toolkit v4.5 (BSEDOS.H) */
150
151 /* Global Record structure
152 * Holds all global system information. Placed first in user buffer
153 */
154 typedef struct qsGrec_s { /* qsGrec */
155 ULONG cThrds;
156 ULONG c32SSem;
157 ULONG cMFTNodes;
158 }qsGrec_t;
159
160 /*
161 * System wide MTE information
162 * ________________________________
163 * | pNextRec |----|
164 * |-------------------------------| |
165 * | hmte | |
166 * |-------------------------------| |
167 * | ctImpMod | |
168 * |-------------------------------| |
169 * | ctObj | |
170 * |-------------------------------| |
171 * | pObjInfo |----|----------|
172 * |-------------------------------| | |
173 * | pName |----|----| |
174 * |-------------------------------| | | |
175 * | imported module handles | | | |
176 * | . | | | |
177 * | . | | | |
178 * | . | | | |
179 * |-------------------------------| <--|----| |
180 * | "pathname" | | |
181 * |-------------------------------| <--|----------|
182 * | Object records | |
183 * | (if requested) | |
184 * |_______________________________| |
185 * <-----
186 * NOTE that if the level bit is set to QS_MTE, the base Lib record will be followed
187 * by a series of object records (qsLObj_t); one for each object of the
188 * module.
189 */
190
191 typedef struct qsLObjrec_s { /* qsLOrec */
192 ULONG oaddr; /* object address */
193 ULONG osize; /* object size */
194 ULONG oflags; /* object flags */
195 } qsLObjrec_t;
196
197 typedef struct qsLrec_s { /* qsLrec */
198 void FAR *pNextRec; /* pointer to next record in buffer */
199 USHORT hmte; /* handle for this mte */
200 USHORT fFlat; /* true if 32 bit module */
201 ULONG ctImpMod; /* # of imported modules in table */
202 ULONG ctObj; /* # of objects in module (mte_objcnt)*/
203 qsLObjrec_t FAR *pObjInfo; /* pointer to per object info if any */
204 UCHAR FAR *pName; /* -> name string following struc */
205 } qsLrec_t;
206
207
208
209 /* Pointer Record Structure
210 * This structure is the first in the user buffer.
211 * It contains pointers to heads of record types that are loaded
212 * into the buffer.
213 */
214
215 typedef struct qsPtrRec_s { /* qsPRec */
216 qsGrec_t *pGlobalRec;
217 void *pProcRec; /* ptr to head of process records */
218 void *p16SemRec; /* ptr to head of 16 bit sem recds */
219 void *p32SemRec; /* ptr to head of 32 bit sem recds */
220 void *pMemRec; /* ptr to head of shared mem recs */
221 qsLrec_t *pLibRec; /* ptr to head of mte records */
222 void *pShrMemRec; /* ptr to head of shared mem records */
223 void *pFSRec; /* ptr to head of file sys records */
224 } qsPtrRec_t;
225
226#endif
227
228
229/*******************************************************************************
230* Global Variables *
231*******************************************************************************/
232extern BOOL fInited; /* malloc.c */
233int cObjectsFake = 14;
234OTE aKrnlOTE[24];
235
236
237/*******************************************************************************
238* External Functions *
239*******************************************************************************/
240#ifndef QS_MTE
241 /* from OS/2 Toolkit v4.5 */
242
243 APIRET APIENTRY DosQuerySysState(ULONG EntityList, ULONG EntityLevel, PID pid,
244 TID tid, PVOID pDataBuf, ULONG cbBuf);
245 #define QS_MTE 0x0004
246#endif
247
248
249/*******************************************************************************
250* Internal Functions *
251*******************************************************************************/
252void syntax(void);
253int kernelInit(int iTest, int argc, char **argv);
254void workersinit(void);
255void initRPInit(RP32INIT *pRpInit, char *pszInitArgs);
256int tests(int iTest, int argc, char **argv);
257int TestCase1(int argc, char **argv);
258int TestCase2(void);
259int TestCase3(void);
260int TestCase4(void);
261int TestCase5(void);
262int TestCase6(void);
263int CompareOptions(struct options *pOpt);
264int TestCaseExeLoad2(void);
265
266
267/**
268 * Main function. Arguments _currently_ unused.
269 */
270int main(int argc, char **argv)
271{
272 int iTest;
273 int rc;
274
275 /*
276 * Init devhelp subsystems.
277 */
278 dhinit();
279
280 /*
281 * Parse arguments.
282 * (printf don't work before dhinit is called...)
283 */
284 if (argc < 2 || (iTest = atoi(argv[1])) <= 0)
285 {
286 syntax();
287 printf("syntax error\n");
288 return -1;
289 }
290
291 /*
292 * Init workers if necessary.
293 */
294 workersinit();
295
296 /*
297 * Init Kernel
298 */
299 if (!kernelInit(iTest, argc, argv))
300 return -2;
301
302 /*
303 * Thunk Stack to 16-bits.
304 *
305 * IMPORTANT! From now on SSToDS have to be used when making pointers
306 * to stack objects.
307 */
308 ThunkStack32To16();
309
310 rc = tests(iTest, argc, argv);
311
312 /*
313 * Thunk Stack back to 32-bits.
314 */
315 ThunkStack16To32();
316
317
318 /*
319 * To avoid a sfree error message we'll set fInited (heap init flag) to false.
320 */
321 fInited = FALSE;
322 return rc;
323}
324
325
326/**
327 * Prints syntax information.
328 * @status partially implemented.
329 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
330 */
331void syntax(void)
332{
333 printf(
334 "Win32kTst.exe v%d.%d.%d - Ring 3 testing of win32k.sys\n"
335 "syntax: Win32kTst.exe <testcase number> [optional arguments]\n",
336 0,0,4
337 );
338}
339
340
341/**
342 * test case 1: Load the specified kernel
343 * other cases: Load running kernel.
344 * @returns Success indicator. (true/false)
345 * @param iTest Testcase number.
346 * @param argc main argc
347 * @param argv main argv
348 * @status completely implemented.
349 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
350 */
351int kernelInit(int iTest, int argc, char **argv)
352{
353 static char achBuffer[1024*256];
354 char szError[256];
355 HMODULE hmod = NULLHANDLE;
356 int rc;
357 char szName[CCHMAXPATH];
358 char * pszSrcName;
359 char * pszTmp;
360 ULONG ulAction;
361 HFILE hFile;
362 struct e32_exe* pe32 = (struct e32_exe*)(void*)&achBuffer[0];
363 qsPtrRec_t * pPtrRec = (qsPtrRec_t*)(void*)&achBuffer[0];
364 qsLrec_t * pLrec;
365 int i;
366 FILESTATUS3 fsts3;
367
368 /*
369 * If not testcase 1, use the running kernel.
370 */
371 if (iTest != 1)
372 {
373 ULONG ulBootDrv = 3;
374 pszSrcName = "c:\\os2krnl";
375 DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, SSToDS(&ulBootDrv), sizeof(ulBootDrv));
376 pszSrcName[0] = (char)(ulBootDrv + 'a' - 1);
377 }
378 else
379 {
380 if (argc < 3)
381 {
382 printf("Missing parameter!\n");
383 return FALSE;
384 }
385 pszSrcName = argv[2];
386 }
387
388 /*
389 * Make a temporary copy of the kernel.
390 */
391 if (DosScanEnv("TMP", &pszTmp) != NO_ERROR || pszTmp == NULL)
392 {
393 printf("Environment variable TMP is not set.\n");
394 return FALSE;
395 }
396 strcpy(szName, pszTmp);
397 if (szName[strlen(pszTmp) - 1] != '\\' && szName[strlen(pszTmp) - 1] != '/')
398 strcat(szName, "\\");
399 strcat(szName, "os2krnl");
400 rc = DosCopy(pszSrcName, szName, DCPY_EXISTING);
401 if (rc != NO_ERROR)
402 {
403 printf("Failed to copy %s to %s.\n", pszSrcName, szName);
404 return FALSE;
405 }
406 if (DosQueryPathInfo(szName, FIL_STANDARD, &fsts3, sizeof(fsts3)) != NO_ERROR
407 || !(fsts3.attrFile = FILE_ARCHIVED)
408 || DosSetPathInfo(szName, FIL_STANDARD, &fsts3, sizeof(fsts3), 0) != NO_ERROR
409 )
410 {
411 printf("Failed to set attributes for %s.\n", szName);
412 return FALSE;
413 }
414
415 /*
416 * Patch the kernel.
417 * Remove the entrypoint.
418 */
419 ulAction = 0;
420 rc = DosOpen(szName, &hFile, &ulAction, 0, FILE_NORMAL,
421 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
422 OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
423 NULL);
424 if (rc != NO_ERROR)
425 {
426 printf("Failed to open temporary kernel file. rc = %d\n", rc);
427 return FALSE;
428 }
429 rc = DosRead(hFile, &achBuffer[0], 0x200, &ulAction);
430 if (rc != NO_ERROR)
431 {
432 DosClose(hFile);
433 printf("Failed to read LX header from temporary kernel file.\n");
434 return FALSE;
435 }
436 pe32 = (struct e32_exe*)(void*)&achBuffer[*(unsigned long*)(void*)&achBuffer[0x3c]];
437 if (*(PUSHORT)pe32->e32_magic != E32MAGIC)
438 {
439 DosClose(hFile);
440 printf("Failed to read LX header from temporary kernel file (2).\n");
441 return FALSE;
442 }
443 pe32->e32_eip = 0;
444 pe32->e32_startobj = 0;
445 pe32->e32_mflags &= ~(E32LIBTERM | E32LIBINIT);
446 if ((rc = DosSetFilePtr(hFile, *(unsigned long*)(void*)&achBuffer[0x3c], FILE_BEGIN, &ulAction)) != NO_ERROR
447 || (rc = DosWrite(hFile, pe32, sizeof(struct e32_exe), &ulAction)) != NO_ERROR)
448 {
449 DosClose(hFile);
450 printf("Failed to write patched LX header to temporary kernel file.\n");
451 return FALSE;
452 }
453 DosClose(hFile);
454
455 /*
456 * Load the module.
457 */
458 rc = DosLoadModule(szError, sizeof(szError), szName, SSToDS(&hmod));
459 if (rc != NO_ERROR && (rc != ERROR_INVALID_PARAMETER && hmod == NULLHANDLE))
460 {
461 printf("Failed to load OS/2 kernel image %s.");
462 return FALSE;
463 }
464
465 /*
466 * Get object information.
467 */
468 rc = DosQuerySysState(QS_MTE, QS_MTE, 0L, 0L, pPtrRec, sizeof(achBuffer));
469 if (rc != NO_ERROR)
470 {
471 printf("DosQuerySysState failed with rc=%d.\n", rc);
472 return FALSE;
473 }
474
475 pLrec = pPtrRec->pLibRec;
476 while (pLrec != NULL)
477 {
478 /*
479 * Bug detected in OS/2 FP13. Probably a problem which occurs
480 * in _LDRSysMteInfo when qsCheckCache is calle before writing
481 * object info. The result is that the cache flushed and the
482 * attempt of updating the qsLrec_t next and object pointer is
483 * not done. This used to work earlier and on Aurora AFAIK.
484 *
485 * The fix for this problem is to check if the pObjInfo is NULL
486 * while the number of objects isn't 0 and correct this. pNextRec
487 * will also be NULL at this time. This will be have to corrected
488 * before we exit the loop or moves to the next record.
489 * There is also a nasty alignment of the object info... Hope
490 * I got it right. (This aligment seems new to FP13.)
491 */
492 if (pLrec->pObjInfo == NULL /*&& pLrec->pNextRec == NULL*/ && pLrec->ctObj > 0)
493 {
494 pLrec->pObjInfo = (qsLObjrec_t*)(void*)(
495 (char*)(void*)pLrec
496 + ((sizeof(qsLrec_t) /* size of the lib record */
497 + pLrec->ctImpMod * sizeof(short) /* size of the array of imported modules */
498 + strlen((char*)(void*)pLrec->pName) + 1 /* size of the filename */
499 + 3) & ~3)); /* the size is align on 4 bytes boundrary */
500 pLrec->pNextRec = (qsLrec_t*)(void*)((char*)(void*)pLrec->pObjInfo
501 + sizeof(qsLObjrec_t) * pLrec->ctObj);
502 }
503 if (pLrec->hmte == hmod)
504 break;
505
506 /*
507 * Next record
508 */
509 pLrec = (qsLrec_t*)pLrec->pNextRec;
510 }
511
512 if (pLrec == NULL)
513 {
514 printf("DosQuerySysState(os2krnl): not found\n");
515 return FALSE;
516 }
517 if (pLrec->pObjInfo == NULL)
518 {
519 printf("DosQuerySysState(os2krnl): no object info\n");
520 return FALSE;
521 }
522
523 /*
524 * Fill the aKrnlOTE array.
525 */
526 for (i = 0; i < pLrec->ctObj; i++)
527 {
528 aKrnlOTE[i].ote_size = pLrec->pObjInfo[i].osize;
529 aKrnlOTE[i].ote_base = pLrec->pObjInfo[i].oaddr;
530 aKrnlOTE[i].ote_flags = pLrec->pObjInfo[i].oflags;
531 aKrnlOTE[i].ote_pagemap = i > 0 ? aKrnlOTE[i-1].ote_pagemap + aKrnlOTE[i-1].ote_mapsize : 0;
532 aKrnlOTE[i].ote_mapsize = (pLrec->pObjInfo[i].osize + 0x0FFF) / 0x1000;
533 aKrnlOTE[i].ote_sel = (USHORT)FlatToSel(pLrec->pObjInfo[i].oaddr);
534 aKrnlOTE[i].ote_hob = 0;
535 }
536 cObjectsFake = pLrec->ctObj;
537
538 return TRUE;
539}
540
541
542/**
543 * Initiates a init reqest packet.
544 * @param pRpInit Pointer to request packet to init.
545 * @param pszInitArgs Pointer to init arguments.
546 * @status completely implemented.
547 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
548 */
549void initRPInit(RP32INIT *pRpInit, char *pszInitArgs)
550{
551 /* $elf */
552 memset(pRpInit, 0, sizeof(RP32INIT));
553 pRpInit->rph.Len = sizeof(RP32INIT);
554 pRpInit->rph.Cmd = CMDInit;
555 pRpInit->DevHlpEP = getDHRouterFarPtr();
556 pRpInit->InitArgs = (PSZ)FlatToSel(pszInitArgs);
557}
558
559
560/**
561 * Testcase fan-out.
562 * @returns Testcase return value.
563 * -2 if testcase not found.
564 * @param iTest Testcase number.
565 * @param argc main argc
566 * @param argv main argv
567 * @status completely implemented.
568 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
569 */
570int tests(int iTest, int argc, char **argv)
571{
572 int rc;
573
574 printf("-------------------------------- Testcase %d:\n", iTest);
575 switch (iTest)
576 {
577 case 1: rc = TestCase1(argc, argv); break;
578 case 2: rc = TestCase2(); break;
579 case 3: rc = TestCase3(); break;
580 case 4: rc = TestCase4(); break;
581 case 5: rc = TestCase5(); break;
582
583 default:
584 printf("testcase no. %d is not found\n", iTest);
585 rc = -2;
586 }
587 printf("result %d -----------------------------------\n", rc);
588
589 NOREF(argc);
590 NOREF(argv);
591 return rc;
592}
593
594
595
596/**
597 * Test case 1.
598 * Checks that default initiation works fine for a given kernel.
599 *
600 * Syntax: win32ktst.exe 1 <os2krnl> <majorver> <minorver> <build> <kerneltype: S|U|4> <buildtype: A|H|R> [os2krnl.sym]
601 *
602 * @sketch Create init packet with no arguments.
603 * Initiate elf$
604 * Create init packet with no arguments.
605 * Initiate win32k$
606 * @returns 0 on success.
607 * 1 on failure.
608 * @status completely implemented.
609 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
610 */
611int TestCase1(int argc, char **argv)
612{
613 static char szInitArgs[CCHMAXPATH + 10];
614 int rc = 1;
615 RP32INIT rpinit;
616
617 /* verify argument count */
618 if (argc < 8 || argc > 9)
619 {
620 printf("Invalid parameter count for testcase 1.\n");
621 return ERROR_INVALID_PARAMETER;
622 }
623
624 /* init fake variabels */
625 _usFakeVerMajor = (USHORT)atoi(argv[3]);
626 _usFakeVerMinor = (USHORT)atoi(argv[4]);
627
628 /* make init string */
629 strcpy(szInitArgs, "-w3");
630 if (argc >= 9)
631 strcat(strcat(szInitArgs, " -S:"), argv[8]);
632
633 /* $elf */
634 initRPInit(SSToDS(&rpinit), szInitArgs);
635 rc = InitElf(&rpinit); /* no SSToDS! */
636 printf("InitElf returned status=0x%04x\n", rpinit.rph.Status);
637 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
638 {
639 /* $win32k */
640 initRPInit(SSToDS(&rpinit), szInitArgs);
641 rc = InitWin32k(&rpinit); /* no SSToDS! */
642 printf("InitWin32k returned status=0x%04x\n", rpinit.rph.Status);
643 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
644 {
645 struct options opt = DEFAULT_OPTION_ASSIGMENTS;
646 opt.ulInfoLevel = 3;
647 opt.fKernel = (argv[6][0] == 'S' ? KF_SMP : (argv[6][0] == '4' ? KF_W4 | KF_UNI : KF_UNI))
648 | (argv[7][0] == 'A' || argv[7][0] == 'H' ? KF_DEBUG : 0);
649 opt.ulBuild = atoi(argv[5]);
650 opt.usVerMajor = (USHORT)atoi(argv[3]);
651 opt.usVerMinor = (USHORT)atoi(argv[4]);
652
653 rc = CompareOptions(SSToDS(&opt));
654 }
655 else
656 printf("!failed!\n");
657 }
658 else
659 printf("!failed!\n");
660
661 return rc;
662}
663
664/**
665 * Test case 2.
666 * Checks that all parameters are read correctly (1).
667 *
668 * @sketch Create init packet with no arguments.
669 * Initiate elf$
670 * Create init packet with no arguments.
671 * Initiate win32k$
672 * @returns 0 on success.
673 * 1 on failure.
674 * @status completely implemented.
675 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
676 */
677int TestCase2(void)
678{
679 int rc = 1;
680 RP32INIT rpinit;
681 char * pszInitArgs = "-C1 -L:E -Verbose -Elf:Yes -Pe:Mixed -Script:Yes -W4 -Heap:512000 -ResHeap:0256000 -HeapMax:4096000 -ResHeapMax:0x100000";
682
683 options.fLogging = TRUE;
684
685 /* $elf */
686 initRPInit(SSToDS(&rpinit), pszInitArgs);
687 rc = InitElf(&rpinit); /* no SSToDS! */
688 printf("InitElf returned status=0x%04x\n", rpinit.rph.Status);
689 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
690 {
691 /* $win32k */
692 initRPInit(SSToDS(&rpinit), pszInitArgs);
693 rc = InitWin32k(&rpinit); /* no SSToDS! */
694 printf("InitWin32k returned status=0x%04x\n", rpinit.rph.Status);
695 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
696 {
697 struct options opt = DEFAULT_OPTION_ASSIGMENTS;
698 opt.cbSwpHeapInit = 512000;
699 opt.cbSwpHeapMax = 4096000;
700 opt.cbResHeapInit = 0256000;
701 opt.cbResHeapMax = 0x100000;
702 opt.fElf = TRUE;
703 opt.fUNIXScript = TRUE;
704 opt.fPE = FLAGS_PE_MIXED;
705 opt.fQuiet = FALSE;
706 opt.fLogging = TRUE;
707 opt.usCom = OUTPUT_COM1;
708 opt.ulInfoLevel = INFOLEVEL_INFOALL;
709
710 rc = CompareOptions(SSToDS(&opt));
711 if (rc == NO_ERROR)
712 {
713 rc = TestCaseExeLoad2();
714 }
715 }
716 else
717 printf("!failed!\n");
718 }
719 else
720 printf("!failed!\n");
721
722 return rc;
723}
724
725/**
726 * Test case 3.
727 * Checks that all parameters are read correctly (1).
728 *
729 * @sketch Create init packet with no arguments.
730 * Initiate elf$
731 * Create init packet with no arguments.
732 * Initiate win32k$
733 * @returns 0 on success.
734 * 1 on failure.
735 * @status completely implemented.
736 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
737 */
738int TestCase3(void)
739{
740 int rc = 1;
741 RP32INIT rpinit;
742 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";
743
744 /* $elf */
745 initRPInit(SSToDS(&rpinit), pszInitArgs);
746 rc = InitElf(&rpinit); /* no SSToDS! */
747 printf("InitElf returned status=0x%04x\n", rpinit.rph.Status);
748 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
749 {
750 /* $win32k */
751 initRPInit(SSToDS(&rpinit), pszInitArgs);
752 rc = InitWin32k(&rpinit); /* no SSToDS! */
753 printf("InitWin32k returned status=0x%04x\n", rpinit.rph.Status);
754 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
755 {
756 struct options opt = DEFAULT_OPTION_ASSIGMENTS;
757 opt.cbSwpHeapInit = 512000;
758 opt.cbSwpHeapMax = 4096000;
759 opt.cbResHeapInit = 0256000;
760 opt.cbResHeapMax = 0x100000;
761 opt.fElf = TRUE;
762 opt.fUNIXScript = TRUE;
763 opt.fJava = FALSE;
764 opt.fREXXScript = FALSE;
765 opt.fPE = FLAGS_PE_PE;
766 opt.fQuiet = TRUE;
767 opt.fLogging = FALSE;
768 opt.usCom = OUTPUT_COM1;
769 opt.ulInfoLevel = INFOLEVEL_INFOALL;
770
771 rc = CompareOptions(SSToDS(&opt));
772 if (rc == NO_ERROR)
773 {
774 rc = TestCaseExeLoad2();
775 }
776 }
777 else
778 printf("!failed!\n");
779 }
780 else
781 printf("!failed!\n");
782
783 return rc;
784}
785
786
787/**
788 * Test case 4.
789 * Checks that all parameters are read correctly (3).
790 *
791 * @sketch Create init packet with no arguments.
792 * Initiate elf$
793 * Create init packet with no arguments.
794 * Initiate win32k$
795 * @returns 0 on success.
796 * 1 on failure.
797 * @status completely implemented.
798 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
799 */
800int TestCase4(void)
801{
802 int rc = 1;
803 RP32INIT rpinit;
804 char * pszInitArgs = "-P:pe";
805
806 /* $elf */
807 initRPInit(SSToDS(&rpinit), pszInitArgs);
808 rc = InitElf(&rpinit); /* no SSToDS! */
809 printf("InitElf returned status=0x%04x\n", rpinit.rph.Status);
810 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
811 {
812 /* $win32k */
813 initRPInit(SSToDS(&rpinit), pszInitArgs);
814 rc = InitWin32k(&rpinit); /* no SSToDS! */
815 printf("InitWin32k returned status=0x%04x\n", rpinit.rph.Status);
816 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
817 {
818 struct options opt = DEFAULT_OPTION_ASSIGMENTS;
819 opt.fPE = FLAGS_PE_PE;
820
821 rc = CompareOptions(SSToDS(&opt));
822 /*
823 if (rc == NO_ERROR)
824 {
825 rc = TestCaseExeLoad2();
826 }
827 */
828 }
829 else
830 printf("!failed!\n");
831 }
832 else
833 printf("!failed!\n");
834
835 return rc;
836}
837
838
839/**
840 * Test case 5.
841 * Checks that all parameters are read correctly (3).
842 *
843 * @sketch Create init packet with no arguments.
844 * Initiate elf$
845 * Create init packet with no arguments.
846 * Initiate win32k$
847 * @returns 0 on success.
848 * 1 on failure.
849 * @status completely implemented.
850 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
851 */
852int TestCase5(void)
853{
854 int rc = 1;
855 RP32INIT rpinit;
856 char * pszInitArgs = "-Pe:pe";
857
858 /* $elf */
859 initRPInit(SSToDS(&rpinit), pszInitArgs);
860 rc = InitElf(&rpinit); /* no SSToDS! */
861 printf("InitElf returned status=0x%04x\n", rpinit.rph.Status);
862 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
863 {
864 /* $win32k */
865 initRPInit(SSToDS(&rpinit), pszInitArgs);
866 rc = InitWin32k(&rpinit); /* no SSToDS! */
867 printf("InitWin32k returned status=0x%04x\n", rpinit.rph.Status);
868 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
869 {
870 struct options opt = DEFAULT_OPTION_ASSIGMENTS;
871 opt.fPE = FLAGS_PE_PE;
872
873 rc = CompareOptions(SSToDS(&opt));
874 /*
875 if (rc == NO_ERROR)
876 {
877 rc = TestCaseExeLoad2();
878 }
879 */
880 }
881 else
882 printf("!failed!\n");
883 }
884 else
885 printf("!failed!\n");
886
887 return rc;
888}
889
890
891/**
892 * Compares the options with the option struct passed in.
893 * @returns 0 on success.
894 * number of mismatches on error.
895 * @param pOpt
896 * @status completely implemented.
897 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
898 */
899int CompareOptions(struct options *pOpt)
900{
901 int rc = 0;
902 /*
903 * Check that the option struct is correct.
904 */
905 if (options.fQuiet != pOpt->fQuiet)
906 printf("fQuiet = %d - should be %d\n", options.fQuiet, pOpt->fQuiet, rc++);
907 if (options.usCom != pOpt->usCom)
908 printf("usCom = %d - should be %d\n", options.usCom, pOpt->usCom, rc++);
909 if (options.fLogging != pOpt->fLogging)
910 printf("fLogging = %d - should be %d\n", options.fLogging, pOpt->fLogging, rc++);
911 if (pOpt->ulBuild != ~0UL)
912 {
913 if (options.fKernel != pOpt->fKernel)
914 printf("fKernel = %d - should be %d\n", options.fKernel, pOpt->fKernel, rc++);
915 if (options.ulBuild != pOpt->ulBuild)
916 printf("ulBuild = %d - should be %d\n", options.ulBuild, pOpt->ulBuild, rc++);
917 if (options.usVerMajor != pOpt->usVerMajor)
918 printf("usVerMajor = %d - should be %d\n", options.usVerMajor, pOpt->usVerMajor, rc++);
919 if (options.usVerMinor != pOpt->usVerMinor)
920 printf("usVerMinor = %d - should be %d\n", options.usVerMinor, pOpt->usVerMinor, rc++);
921 }
922 if (options.fPE != pOpt->fPE)
923 printf("fPE = %d - should be %d\n", options.fPE, pOpt->fPE, rc++);
924 if (options.ulInfoLevel != pOpt->ulInfoLevel)
925 printf("ulInfoLevel = %d - should be %d\n", options.ulInfoLevel, pOpt->ulInfoLevel, rc++);
926 if (options.fElf != pOpt->fElf)
927 printf("fElf = %d - should be %d\n", options.fElf, pOpt->fElf, rc++);
928 if (options.fUNIXScript != pOpt->fUNIXScript)
929 printf("fUNIXScript = %d - should be %d\n", options.fUNIXScript, pOpt->fUNIXScript, rc++);
930 if (options.fREXXScript != pOpt->fREXXScript)
931 printf("fREXXScript = %d - should be %d\n", options.fREXXScript, pOpt->fREXXScript, rc++);
932 if (options.fJava != pOpt->fJava)
933 printf("fJava = %d - should be %d\n", options.fJava, pOpt->fJava, rc++);
934 if (options.fNoLoader != pOpt->fNoLoader)
935 printf("fNoLoader = %d - should be %d\n", options.fNoLoader, pOpt->fNoLoader, rc++);
936 if (options.cbSwpHeapInit != pOpt->cbSwpHeapInit)
937 printf("cbSwpHeapInit = %d - should be %d\n", options.cbSwpHeapInit, pOpt->cbSwpHeapInit, rc++);
938 if (options.cbSwpHeapMax != pOpt->cbSwpHeapMax)
939 printf("cbSwpHeapMax = %d - should be %d\n", options.cbSwpHeapMax, pOpt->cbSwpHeapMax, rc++);
940 if (options.cbResHeapInit != pOpt->cbResHeapInit)
941 printf("cbResHeapInit = %d - should be %d\n", options.cbResHeapInit, pOpt->cbResHeapInit, rc++);
942 if (options.cbResHeapMax != pOpt->cbResHeapMax)
943 printf("cbResHeapMax = %d - should be %d\n", options.cbResHeapMax, pOpt->cbResHeapMax, rc++);
944
945 return rc;
946}
947
948
949/**
950 * Simulates a executable loading (no errors).
951 * This test requires a PE executable file named ExecLoad1.exe which
952 * imports the dll ExecLoad1d.dll.
953 *
954 * @returns 0 on success.
955 * > 0 on failure.
956 * @sketch
957 * @status
958 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
959 * @remark
960 */
961int TestCaseExeLoad2(void)
962{
963 APIRET rc;
964 int cch;
965 char * psz;
966
967 /*
968 * Set global parameters... FIXME.
969 */
970
971 /*
972 * Do the real execution.
973 */
974 printf("--- TestcaseExeLoad2 - loading win32ktst.exe (LX image) ----\n");
975 rc = CalltkExecPgm(EXEC_LOAD, NULL, NULL, "GLC6000.TMP");
976 if (rc == NO_ERROR)
977 {
978 psz = "BIN\\DEBUG\\LIBCONV.EXE\0";
979 printf("--- TestcaseExeLoad2 - loading libconv.exe (LX image) ----\n");
980 rc = CalltkExecPgm(EXEC_LOAD, NULL, NULL, "bin\\debug\\libconv.exe");
981 if (rc == NO_ERROR)
982 {
983 #if 0 //not implemented by CalltkExecPgm...???
984 /* check result */
985 if (memcmp(achTkExecPgmArguments, psz, strlen(psz) + 1) != 0)
986 {
987 rc = ERROR_BAD_ARGUMENTS;
988 printf("Bad Arguments! (%s)\n", achTkExecPgmArguments);
989 }
990 #else
991 psz = psz;
992 #endif
993 }
994 }
995
996 if (rc == NO_ERROR)
997 {
998 psz = "REXX\\TST.RX\0OriginalArgument1 OriginalArgument2\0OriginalArgument3\0";
999 printf("--- TestcaseExeLoad2 - loading rexx\\tst.rx (REXX script) ----\n");
1000 rc = CalltkExecPgm(EXEC_LOAD, psz, NULL, "rexx\\tst.rx");
1001 if (rc == NO_ERROR)
1002 {
1003 /* check result */
1004 psz = "REXX\\TST.RX OriginalArgument1 OriginalArgument2\0OriginalArgument3\0";
1005 cch = strlen(psz);
1006 if (memcmp(achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1, psz, cch) != 0)
1007 {
1008 rc = ERROR_BAD_ARGUMENTS;
1009 printf("Bad Arguments! (achTkExecPgmArguments=%s).\n", achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1);
1010 }
1011 }
1012 }
1013
1014 if (rc == NO_ERROR)
1015 {
1016 psz = "TEST\\TST.SH\0OrgArg1 OrgArg2\0OrgArg3\0";
1017 printf("--- TestcaseExeLoad2 - loading test\\tst.sh (UNIX shell script) ----\n");
1018 rc = CalltkExecPgm(EXEC_LOAD, psz, NULL, "test\\tst.sh");
1019 if (rc == NO_ERROR)
1020 {
1021 /* check result */
1022 psz = "TEST\\TST.SH OrgArg1 OrgArg2\0OrgArg3\0";
1023 cch = strlen(psz);
1024 if (memcmp(achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1, psz, cch) != 0)
1025 {
1026 rc = ERROR_BAD_ARGUMENTS;
1027 printf("Bad Arguments! (achTkExecPgmArguments=%s).\n", achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1);
1028 }
1029 }
1030 }
1031
1032 if (rc == NO_ERROR)
1033 {
1034 psz = "TEST\\TST2.SH\0OrgArg1 OrgArg2\0OrgArg3\0";
1035 printf("--- TestcaseExeLoad2 - loading test\\tst2.sh (UNIX shell script) ----\n");
1036 rc = CalltkExecPgm(EXEC_LOAD, psz, NULL, "test\\tst2.sh");
1037 if (rc == NO_ERROR)
1038 {
1039 /* check result */
1040 psz = "-arg1 -arg2 -arg3 TEST\\TST2.SH OrgArg1 OrgArg2\0OrgArg3\0";
1041 cch = strlen(psz) + 1;
1042 if (memcmp(achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1, psz, cch) != 0)
1043 {
1044 rc = ERROR_BAD_ARGUMENTS;
1045 printf("Bad Arguments! (achTkExecPgmArguments=%s).\n", achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1);
1046 }
1047 }
1048 }
1049
1050 if (rc == NO_ERROR)
1051 {
1052 psz = "E:\\WIN32PROG\\SOL\\SOL.EXE\0";
1053 printf("--- TestcaseExeLoad2 - loading SOL.EXE (PE image) ----\n");
1054 rc = CalltkExecPgm(EXEC_LOAD, psz, NULL, "e:\\Win32Prog\\Sol\\Sol.exe");
1055 if (rc == NO_ERROR)
1056 {
1057 /* check result */
1058 cch = strlen(psz) + 1 + 1;
1059 if (memcmp(achTkExecPgmArguments, psz, cch) != 0)
1060 {
1061 rc = ERROR_BAD_ARGUMENTS;
1062 printf("Bad Arguments! (achTkExecPgmArguments=%s).\n", achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1);
1063 }
1064 }
1065 }
1066
1067 /*
1068 * The test is successful if rc == NO_ERROR (== 0).
1069 */
1070 return rc;
1071}
1072
Note: See TracBrowser for help on using the repository browser.