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

Last change on this file since 10367 was 9475, checked in by bird, 23 years ago

Delete kernel. Support for B kernels.

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