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

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

Corrected problem with kernel build 14053. (new parameter to ldrOpenPath)
Added symbols for 14053 and 8266.

File size: 32.3 KB
Line 
1/* $Id: win32ktst.c,v 1.3 2000-09-22 09:22:43 bird Exp $
2 *
3 * Win32k test module.
4 *
5 * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.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@pmsc.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@pmsc.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@pmsc.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@pmsc.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
581 default:
582 printf("testcase no. %d is not found\n", iTest);
583 rc = -2;
584 }
585 printf("result %d -----------------------------------\n", rc);
586
587 NOREF(argc);
588 NOREF(argv);
589 return rc;
590}
591
592
593
594/**
595 * Test case 1.
596 * Checks that default initiation works fine for a given kernel.
597 *
598 * Syntax: win32ktst.exe 1 <os2krnl> <majorver> <minorver> <build> <kerneltype: S|U|4> <buildtype: A|H|R> [os2krnl.sym]
599 *
600 * @sketch Create init packet with no arguments.
601 * Initiate elf$
602 * Create init packet with no arguments.
603 * Initiate win32k$
604 * @returns 0 on success.
605 * 1 on failure.
606 * @status completely implemented.
607 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
608 */
609int TestCase1(int argc, char **argv)
610{
611 static char szInitArgs[CCHMAXPATH + 10];
612 int rc = 1;
613 RP32INIT rpinit;
614
615 /* verify argument count */
616 if (argc < 8 || argc > 9)
617 {
618 printf("Invalid parameter count for testcase 1.\n");
619 return ERROR_INVALID_PARAMETER;
620 }
621
622 /* init fake variabels */
623 _usFakeVerMajor = (USHORT)atoi(argv[3]);
624 _usFakeVerMinor = (USHORT)atoi(argv[4]);
625
626 /* make init string */
627 strcpy(szInitArgs, "-w3");
628 if (argc >= 9)
629 strcat(strcat(szInitArgs, " -S:"), argv[8]);
630
631 /* $elf */
632 initRPInit(SSToDS(&rpinit), szInitArgs);
633 rc = InitElf(&rpinit); /* no SSToDS! */
634 printf("InitElf returned status=0x%04x\n", rpinit.rph.Status);
635 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
636 {
637 /* $win32k */
638 initRPInit(SSToDS(&rpinit), szInitArgs);
639 rc = InitWin32k(&rpinit); /* no SSToDS! */
640 printf("InitWin32k returned status=0x%04x\n", rpinit.rph.Status);
641 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
642 {
643 struct options opt = DEFAULT_OPTION_ASSIGMENTS;
644 opt.ulInfoLevel = 3;
645 opt.fKernel = (argv[6][0] == 'S' ? KF_SMP : (argv[6][0] == '4' ? KF_W4 | KF_UNI : KF_UNI))
646 | (argv[7][0] == 'A' || argv[7][0] == 'H' ? KF_DEBUG : 0);
647 opt.ulBuild = atoi(argv[5]);
648 opt.usVerMajor = (USHORT)atoi(argv[3]);
649 opt.usVerMinor = (USHORT)atoi(argv[4]);
650
651 rc = CompareOptions(SSToDS(&opt));
652 }
653 else
654 printf("!failed!\n");
655 }
656 else
657 printf("!failed!\n");
658
659 return rc;
660}
661
662/**
663 * Test case 2.
664 * Checks that all parameters are read correctly (1).
665 *
666 * @sketch Create init packet with no arguments.
667 * Initiate elf$
668 * Create init packet with no arguments.
669 * Initiate win32k$
670 * @returns 0 on success.
671 * 1 on failure.
672 * @status completely implemented.
673 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
674 */
675int TestCase2(void)
676{
677 int rc = 1;
678 RP32INIT rpinit;
679 char * pszInitArgs = "-C1 -L:E -Verbose -Elf:Yes -Pe:Mixed -Script:Yes -W4 -Heap:512000 -ResHeap:0256000 -HeapMax:4096000 -ResHeapMax:0x100000";
680
681 options.fLogging = TRUE;
682
683 /* $elf */
684 initRPInit(SSToDS(&rpinit), pszInitArgs);
685 rc = InitElf(&rpinit); /* no SSToDS! */
686 printf("InitElf returned status=0x%04x\n", rpinit.rph.Status);
687 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
688 {
689 /* $win32k */
690 initRPInit(SSToDS(&rpinit), pszInitArgs);
691 rc = InitWin32k(&rpinit); /* no SSToDS! */
692 printf("InitWin32k returned status=0x%04x\n", rpinit.rph.Status);
693 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
694 {
695 struct options opt = DEFAULT_OPTION_ASSIGMENTS;
696 opt.cbSwpHeapInit = 512000;
697 opt.cbSwpHeapMax = 4096000;
698 opt.cbResHeapInit = 0256000;
699 opt.cbResHeapMax = 0x100000;
700 opt.fElf = TRUE;
701 opt.fUNIXScript = TRUE;
702 opt.fPE = FLAGS_PE_MIXED;
703 opt.fQuiet = FALSE;
704 opt.fLogging = TRUE;
705 opt.usCom = OUTPUT_COM1;
706 opt.ulInfoLevel = INFOLEVEL_INFOALL;
707
708 rc = CompareOptions(SSToDS(&opt));
709 if (rc == NO_ERROR)
710 {
711 rc = TestCaseExeLoad2();
712 }
713 }
714 else
715 printf("!failed!\n");
716 }
717 else
718 printf("!failed!\n");
719
720 return rc;
721}
722
723/**
724 * Test case 3.
725 * Checks that all parameters are read correctly (1).
726 *
727 * @sketch Create init packet with no arguments.
728 * Initiate elf$
729 * Create init packet with no arguments.
730 * Initiate win32k$
731 * @returns 0 on success.
732 * 1 on failure.
733 * @status completely implemented.
734 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
735 */
736int TestCase3(void)
737{
738 int rc = 1;
739 RP32INIT rpinit;
740 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";
741
742 /* $elf */
743 initRPInit(SSToDS(&rpinit), pszInitArgs);
744 rc = InitElf(&rpinit); /* no SSToDS! */
745 printf("InitElf returned status=0x%04x\n", rpinit.rph.Status);
746 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
747 {
748 /* $win32k */
749 initRPInit(SSToDS(&rpinit), pszInitArgs);
750 rc = InitWin32k(&rpinit); /* no SSToDS! */
751 printf("InitWin32k returned status=0x%04x\n", rpinit.rph.Status);
752 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
753 {
754 struct options opt = DEFAULT_OPTION_ASSIGMENTS;
755 opt.cbSwpHeapInit = 512000;
756 opt.cbSwpHeapMax = 4096000;
757 opt.cbResHeapInit = 0256000;
758 opt.cbResHeapMax = 0x100000;
759 opt.fElf = TRUE;
760 opt.fUNIXScript = TRUE;
761 opt.fJava = FALSE;
762 opt.fREXXScript = FALSE;
763 opt.fPE = FLAGS_PE_PE;
764 opt.fQuiet = TRUE;
765 opt.fLogging = FALSE;
766 opt.usCom = OUTPUT_COM1;
767 opt.ulInfoLevel = INFOLEVEL_INFOALL;
768
769 rc = CompareOptions(SSToDS(&opt));
770 if (rc == NO_ERROR)
771 {
772 rc = TestCaseExeLoad2();
773 }
774 }
775 else
776 printf("!failed!\n");
777 }
778 else
779 printf("!failed!\n");
780
781 return rc;
782}
783
784
785/**
786 * Compares the options with the option struct passed in.
787 * @returns 0 on success.
788 * number of mismatches on error.
789 * @param pOpt
790 * @status completely implemented.
791 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
792 */
793int CompareOptions(struct options *pOpt)
794{
795 int rc = 0;
796 /*
797 * Check that the option struct is correct.
798 */
799 if (options.fQuiet != pOpt->fQuiet)
800 printf("fQuiet = %d - should be %d\n", options.fQuiet, pOpt->fQuiet, rc++);
801 if (options.usCom != pOpt->usCom)
802 printf("usCom = %d - should be %d\n", options.usCom, pOpt->usCom, rc++);
803 if (options.fLogging != pOpt->fLogging)
804 printf("fLogging = %d - should be %d\n", options.fLogging, pOpt->fLogging, rc++);
805 if (pOpt->ulBuild != ~0UL)
806 {
807 if (options.fKernel != pOpt->fKernel)
808 printf("fKernel = %d - should be %d\n", options.fKernel, pOpt->fKernel, rc++);
809 if (options.ulBuild != pOpt->ulBuild)
810 printf("ulBuild = %d - should be %d\n", options.ulBuild, pOpt->ulBuild, rc++);
811 if (options.usVerMajor != pOpt->usVerMajor)
812 printf("usVerMajor = %d - should be %d\n", options.usVerMajor, pOpt->usVerMajor, rc++);
813 if (options.usVerMinor != pOpt->usVerMinor)
814 printf("usVerMinor = %d - should be %d\n", options.usVerMinor, pOpt->usVerMinor, rc++);
815 }
816 if (options.fPE != pOpt->fPE)
817 printf("fPE = %d - should be %d\n", options.fPE, pOpt->fPE, rc++);
818 if (options.ulInfoLevel != pOpt->ulInfoLevel)
819 printf("ulInfoLevel = %d - should be %d\n", options.ulInfoLevel, pOpt->ulInfoLevel, rc++);
820 if (options.fElf != pOpt->fElf)
821 printf("fElf = %d - should be %d\n", options.fElf, pOpt->fElf, rc++);
822 if (options.fUNIXScript != pOpt->fUNIXScript)
823 printf("fUNIXScript = %d - should be %d\n", options.fUNIXScript, pOpt->fUNIXScript, rc++);
824 if (options.fREXXScript != pOpt->fREXXScript)
825 printf("fREXXScript = %d - should be %d\n", options.fREXXScript, pOpt->fREXXScript, rc++);
826 if (options.fJava != pOpt->fJava)
827 printf("fJava = %d - should be %d\n", options.fJava, pOpt->fJava, rc++);
828 if (options.fNoLoader != pOpt->fNoLoader)
829 printf("fNoLoader = %d - should be %d\n", options.fNoLoader, pOpt->fNoLoader, rc++);
830 if (options.cbSwpHeapInit != pOpt->cbSwpHeapInit)
831 printf("cbSwpHeapInit = %d - should be %d\n", options.cbSwpHeapInit, pOpt->cbSwpHeapInit, rc++);
832 if (options.cbSwpHeapMax != pOpt->cbSwpHeapMax)
833 printf("cbSwpHeapMax = %d - should be %d\n", options.cbSwpHeapMax, pOpt->cbSwpHeapMax, rc++);
834 if (options.cbResHeapInit != pOpt->cbResHeapInit)
835 printf("cbResHeapInit = %d - should be %d\n", options.cbResHeapInit, pOpt->cbResHeapInit, rc++);
836 if (options.cbResHeapMax != pOpt->cbResHeapMax)
837 printf("cbResHeapMax = %d - should be %d\n", options.cbResHeapMax, pOpt->cbResHeapMax, rc++);
838
839 return rc;
840}
841
842
843/**
844 * Simulates a executable loading (no errors).
845 * This test requires a PE executable file named ExecLoad1.exe which
846 * imports the dll ExecLoad1d.dll.
847 *
848 * @returns 0 on success.
849 * > 0 on failure.
850 * @sketch
851 * @status
852 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
853 * @remark
854 */
855int TestCaseExeLoad2(void)
856{
857 APIRET rc;
858 int cch;
859 char * psz;
860
861 /*
862 * Set global parameters... FIXME.
863 */
864
865 /*
866 * Do the real execution.
867 */
868 printf("--- TestcaseExeLoad2 - loading win32ktst.exe (LX image) ----\n");
869 rc = CalltkExecPgm(EXEC_LOAD, NULL, NULL, "GLC6000.TMP");
870 if (rc == NO_ERROR)
871 {
872 psz = "BIN\\DEBUG\\LIBCONV.EXE\0";
873 printf("--- TestcaseExeLoad2 - loading libconv.exe (LX image) ----\n");
874 rc = CalltkExecPgm(EXEC_LOAD, NULL, NULL, "bin\\debug\\libconv.exe");
875 if (rc == NO_ERROR)
876 {
877 #if 0 //not implemented by CalltkExecPgm...???
878 /* check result */
879 if (memcmp(achTkExecPgmArguments, psz, strlen(psz) + 1) != 0)
880 {
881 rc = ERROR_BAD_ARGUMENTS;
882 printf("Bad Arguments! (%s)\n", achTkExecPgmArguments);
883 }
884 #else
885 psz = psz;
886 #endif
887 }
888 }
889
890 if (rc == NO_ERROR)
891 {
892 psz = "REXX\\TST.RX\0OriginalArgument1 OriginalArgument2\0OriginalArgument3\0";
893 printf("--- TestcaseExeLoad2 - loading rexx\\tst.rx (REXX script) ----\n");
894 rc = CalltkExecPgm(EXEC_LOAD, psz, NULL, "rexx\\tst.rx");
895 if (rc == NO_ERROR)
896 {
897 /* check result */
898 psz = "REXX\\TST.RX OriginalArgument1 OriginalArgument2\0OriginalArgument3\0";
899 cch = strlen(psz);
900 if (memcmp(achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1, psz, cch) != 0)
901 {
902 rc = ERROR_BAD_ARGUMENTS;
903 printf("Bad Arguments! (achTkExecPgmArguments=%s).\n", achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1);
904 }
905 }
906 }
907
908 if (rc == NO_ERROR)
909 {
910 psz = "TEST\\TST.SH\0OrgArg1 OrgArg2\0OrgArg3\0";
911 printf("--- TestcaseExeLoad2 - loading test\\tst.sh (UNIX shell script) ----\n");
912 rc = CalltkExecPgm(EXEC_LOAD, psz, NULL, "test\\tst.sh");
913 if (rc == NO_ERROR)
914 {
915 /* check result */
916 psz = "TEST\\TST.SH OrgArg1 OrgArg2\0OrgArg3\0";
917 cch = strlen(psz);
918 if (memcmp(achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1, psz, cch) != 0)
919 {
920 rc = ERROR_BAD_ARGUMENTS;
921 printf("Bad Arguments! (achTkExecPgmArguments=%s).\n", achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1);
922 }
923 }
924 }
925
926 if (rc == NO_ERROR)
927 {
928 psz = "TEST\\TST2.SH\0OrgArg1 OrgArg2\0OrgArg3\0";
929 printf("--- TestcaseExeLoad2 - loading test\\tst2.sh (UNIX shell script) ----\n");
930 rc = CalltkExecPgm(EXEC_LOAD, psz, NULL, "test\\tst2.sh");
931 if (rc == NO_ERROR)
932 {
933 /* check result */
934 psz = "-arg1 -arg2 -arg3 TEST\\TST2.SH OrgArg1 OrgArg2\0OrgArg3\0";
935 cch = strlen(psz) + 1;
936 if (memcmp(achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1, psz, cch) != 0)
937 {
938 rc = ERROR_BAD_ARGUMENTS;
939 printf("Bad Arguments! (achTkExecPgmArguments=%s).\n", achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1);
940 }
941 }
942 }
943
944 if (rc == NO_ERROR)
945 {
946 psz = "E:\\WIN32PROG\\SOL\\SOL.EXE\0";
947 printf("--- TestcaseExeLoad2 - loading SOL.EXE (PE image) ----\n");
948 rc = CalltkExecPgm(EXEC_LOAD, psz, NULL, "e:\\Win32Prog\\Sol\\Sol.exe");
949 if (rc == NO_ERROR)
950 {
951 /* check result */
952 cch = strlen(psz) + 1 + 1;
953 if (memcmp(achTkExecPgmArguments, psz, cch) != 0)
954 {
955 rc = ERROR_BAD_ARGUMENTS;
956 printf("Bad Arguments! (achTkExecPgmArguments=%s).\n", achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1);
957 }
958 }
959 }
960
961 /*
962 * The test is successful if rc == NO_ERROR (== 0).
963 */
964 return rc;
965}
966
Note: See TracBrowser for help on using the repository browser.