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

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

Moved ldrCalls.h into the OS2Krnl.h tree as OS2KLDR.h.
Also moved the Ldr definitions from OS2Krnl.h and into OS2KLDR.h.

File size: 35.7 KB
Line 
1/* $Id: win32ktst.c,v 1.7 2001-02-10 11:11:48 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#ifndef QS_MTE
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 = DosCopy(pszSrcName, szName, DCPY_EXISTING);
400 if (rc != NO_ERROR)
401 {
402 printf("Failed to copy %s to %s.\n", pszSrcName, szName);
403 return FALSE;
404 }
405 if (DosQueryPathInfo(szName, FIL_STANDARD, &fsts3, sizeof(fsts3)) != NO_ERROR
406 || !(fsts3.attrFile = FILE_ARCHIVED)
407 || DosSetPathInfo(szName, FIL_STANDARD, &fsts3, sizeof(fsts3), 0) != NO_ERROR
408 )
409 {
410 printf("Failed to set attributes for %s.\n", szName);
411 return FALSE;
412 }
413
414 /*
415 * Patch the kernel.
416 * Remove the entrypoint.
417 */
418 ulAction = 0;
419 rc = DosOpen(szName, &hFile, &ulAction, 0, FILE_NORMAL,
420 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
421 OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
422 NULL);
423 if (rc != NO_ERROR)
424 {
425 printf("Failed to open temporary kernel file. rc = %d\n", rc);
426 return FALSE;
427 }
428 rc = DosRead(hFile, &achBuffer[0], 0x200, &ulAction);
429 if (rc != NO_ERROR)
430 {
431 DosClose(hFile);
432 printf("Failed to read LX header from temporary kernel file.\n");
433 return FALSE;
434 }
435 pe32 = (struct e32_exe*)(void*)&achBuffer[*(unsigned long*)(void*)&achBuffer[0x3c]];
436 if (*(PUSHORT)pe32->e32_magic != E32MAGIC)
437 {
438 DosClose(hFile);
439 printf("Failed to read LX header from temporary kernel file (2).\n");
440 return FALSE;
441 }
442 pe32->e32_eip = 0;
443 pe32->e32_startobj = 0;
444 pe32->e32_mflags &= ~(E32LIBTERM | E32LIBINIT);
445 if ((rc = DosSetFilePtr(hFile, *(unsigned long*)(void*)&achBuffer[0x3c], FILE_BEGIN, &ulAction)) != NO_ERROR
446 || (rc = DosWrite(hFile, pe32, sizeof(struct e32_exe), &ulAction)) != NO_ERROR)
447 {
448 DosClose(hFile);
449 printf("Failed to write patched LX header to temporary kernel file.\n");
450 return FALSE;
451 }
452 DosClose(hFile);
453
454 /*
455 * Load the module.
456 */
457 rc = DosLoadModule(szError, sizeof(szError), szName, SSToDS(&hmod));
458 if (rc != NO_ERROR && (rc != ERROR_INVALID_PARAMETER && hmod == NULLHANDLE))
459 {
460 printf("Failed to load OS/2 kernel image %s.");
461 return FALSE;
462 }
463
464 /*
465 * Get object information.
466 */
467 rc = DosQuerySysState(QS_MTE, QS_MTE, 0L, 0L, pPtrRec, sizeof(achBuffer));
468 if (rc != NO_ERROR)
469 {
470 printf("DosQuerySysState failed with rc=%d.\n", rc);
471 return FALSE;
472 }
473
474 pLrec = pPtrRec->pLibRec;
475 while (pLrec != NULL)
476 {
477 /*
478 * Bug detected in OS/2 FP13. Probably a problem which occurs
479 * in _LDRSysMteInfo when qsCheckCache is calle before writing
480 * object info. The result is that the cache flushed and the
481 * attempt of updating the qsLrec_t next and object pointer is
482 * not done. This used to work earlier and on Aurora AFAIK.
483 *
484 * The fix for this problem is to check if the pObjInfo is NULL
485 * while the number of objects isn't 0 and correct this. pNextRec
486 * will also be NULL at this time. This will be have to corrected
487 * before we exit the loop or moves to the next record.
488 * There is also a nasty alignment of the object info... Hope
489 * I got it right. (This aligment seems new to FP13.)
490 */
491 if (pLrec->pObjInfo == NULL /*&& pLrec->pNextRec == NULL*/ && pLrec->ctObj > 0)
492 {
493 pLrec->pObjInfo = (qsLObjrec_t*)(void*)(
494 (char*)(void*)pLrec
495 + ((sizeof(qsLrec_t) /* size of the lib record */
496 + pLrec->ctImpMod * sizeof(short) /* size of the array of imported modules */
497 + strlen((char*)(void*)pLrec->pName) + 1 /* size of the filename */
498 + 3) & ~3)); /* the size is align on 4 bytes boundrary */
499 pLrec->pNextRec = (qsLrec_t*)(void*)((char*)(void*)pLrec->pObjInfo
500 + sizeof(qsLObjrec_t) * pLrec->ctObj);
501 }
502 if (pLrec->hmte == hmod)
503 break;
504
505 /*
506 * Next record
507 */
508 pLrec = (qsLrec_t*)pLrec->pNextRec;
509 }
510
511 if (pLrec == NULL)
512 {
513 printf("DosQuerySysState(os2krnl): not found\n");
514 return FALSE;
515 }
516 if (pLrec->pObjInfo == NULL)
517 {
518 printf("DosQuerySysState(os2krnl): no object info\n");
519 return FALSE;
520 }
521
522 /*
523 * Fill the aKrnlOTE array.
524 */
525 for (i = 0; i < pLrec->ctObj; i++)
526 {
527 aKrnlOTE[i].ote_size = pLrec->pObjInfo[i].osize;
528 aKrnlOTE[i].ote_base = pLrec->pObjInfo[i].oaddr;
529 aKrnlOTE[i].ote_flags = pLrec->pObjInfo[i].oflags;
530 aKrnlOTE[i].ote_pagemap = i > 0 ? aKrnlOTE[i-1].ote_pagemap + aKrnlOTE[i-1].ote_mapsize : 0;
531 aKrnlOTE[i].ote_mapsize = (pLrec->pObjInfo[i].osize + 0x0FFF) / 0x1000;
532 aKrnlOTE[i].ote_sel = (USHORT)FlatToSel(pLrec->pObjInfo[i].oaddr);
533 aKrnlOTE[i].ote_hob = 0;
534 }
535 cObjectsFake = pLrec->ctObj;
536
537 return TRUE;
538}
539
540
541/**
542 * Initiates a init reqest packet.
543 * @param pRpInit Pointer to request packet to init.
544 * @param pszInitArgs Pointer to init arguments.
545 * @status completely implemented.
546 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
547 */
548void initRPInit(RP32INIT *pRpInit, char *pszInitArgs)
549{
550 /* $elf */
551 memset(pRpInit, 0, sizeof(RP32INIT));
552 pRpInit->rph.Len = sizeof(RP32INIT);
553 pRpInit->rph.Cmd = CMDInit;
554 pRpInit->DevHlpEP = getDHRouterFarPtr();
555 pRpInit->InitArgs = (PSZ)FlatToSel(pszInitArgs);
556}
557
558
559/**
560 * Testcase fan-out.
561 * @returns Testcase return value.
562 * -2 if testcase not found.
563 * @param iTest Testcase number.
564 * @param argc main argc
565 * @param argv main argv
566 * @status completely implemented.
567 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
568 */
569int tests(int iTest, int argc, char **argv)
570{
571 int rc;
572
573 printf("-------------------------------- Testcase %d:\n", iTest);
574 switch (iTest)
575 {
576 case 1: rc = TestCase1(argc, argv); break;
577 case 2: rc = TestCase2(); break;
578 case 3: rc = TestCase3(); break;
579 case 4: rc = TestCase4(); break;
580 case 5: rc = TestCase5(); break;
581
582 default:
583 printf("testcase no. %d is not found\n", iTest);
584 rc = -2;
585 }
586 printf("result %d -----------------------------------\n", rc);
587
588 NOREF(argc);
589 NOREF(argv);
590 return rc;
591}
592
593
594
595/**
596 * Test case 1.
597 * Checks that default initiation works fine for a given kernel.
598 *
599 * Syntax: win32ktst.exe 1 <os2krnl> <majorver> <minorver> <build> <kerneltype: S|U|4> <buildtype: A|H|R> [rev] [os2krnl.sym]
600 *
601 * @sketch Create init packet with no arguments.
602 * Initiate elf$
603 * Create init packet with no arguments.
604 * Initiate win32k$
605 * @returns 0 on success.
606 * 1 on failure.
607 * @status completely implemented.
608 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
609 */
610int TestCase1(int argc, char **argv)
611{
612 static char szInitArgs[CCHMAXPATH + 10];
613 int rc = 1;
614 RP32INIT rpinit;
615
616 /* verify argument count */
617 if (argc < 8 || argc > 10)
618 {
619 printf("Invalid parameter count for testcase 1.\n");
620 return ERROR_INVALID_PARAMETER;
621 }
622
623 /* init fake variabels */
624 _usFakeVerMajor = (USHORT)atoi(argv[3]);
625 _usFakeVerMinor = (USHORT)atoi(argv[4]);
626
627 /* make init string */
628 strcpy(szInitArgs, "-w3");
629 if (argc >= 9 && argv[argc-1][1] != '\0')
630 strcat(strcat(szInitArgs, " -S:"), argv[argc-1]);
631
632 /* $elf */
633 initRPInit(SSToDS(&rpinit), szInitArgs);
634 rc = InitElf(&rpinit); /* no SSToDS! */
635 printf("InitElf returned status=0x%04x\n", rpinit.rph.Status);
636 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
637 {
638 /* $win32k */
639 initRPInit(SSToDS(&rpinit), szInitArgs);
640 rc = InitWin32k(&rpinit); /* no SSToDS! */
641 printf("InitWin32k returned status=0x%04x\n", rpinit.rph.Status);
642 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
643 {
644 struct options opt = DEFAULT_OPTION_ASSIGMENTS;
645 opt.ulInfoLevel = 3;
646 opt.fKernel = (argv[6][0] == 'S' ? KF_SMP : (argv[6][0] == '4' ? KF_W4 | KF_UNI : KF_UNI))
647 | (argv[7][0] == 'A' || argv[7][0] == 'H' ? KF_DEBUG : 0);
648 if (argc >= 9 && argv[8][1] == '\0')
649 switch (argv[8][0])
650 {
651 case 'a': case 'A': opt.fKernel |= KF_REV_A; break;
652 case 'b': case 'B': opt.fKernel |= KF_REV_B; break;
653 case 'c': case 'C': opt.fKernel |= KF_REV_C; break;
654 default:
655 opt.fKernel = (argv[8][0] - (argv[8][0] >= 'a' ? 'a'-1 : 'A'-1)) << KF_REV_SHIFT;
656 }
657 opt.ulBuild = atoi(argv[5]);
658 opt.usVerMajor = (USHORT)atoi(argv[3]);
659 opt.usVerMinor = (USHORT)atoi(argv[4]);
660
661 rc = CompareOptions(SSToDS(&opt));
662 }
663 else
664 printf("!failed!\n");
665 }
666 else
667 printf("!failed!\n");
668
669 return rc;
670}
671
672/**
673 * Test case 2.
674 * Checks that all parameters are read correctly (1).
675 *
676 * @sketch Create init packet with no arguments.
677 * Initiate elf$
678 * Create init packet with no arguments.
679 * Initiate win32k$
680 * @returns 0 on success.
681 * 1 on failure.
682 * @status completely implemented.
683 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
684 */
685int TestCase2(void)
686{
687 int rc = 1;
688 RP32INIT rpinit;
689 char * pszInitArgs = "-C1 -L:E -Verbose -Elf:Yes -Pe:Mixed -Script:Yes -W4 -Heap:512000 -ResHeap:0256000 -HeapMax:4096000 -ResHeapMax:0x100000";
690
691 options.fLogging = TRUE;
692
693 /* $elf */
694 initRPInit(SSToDS(&rpinit), pszInitArgs);
695 rc = InitElf(&rpinit); /* no SSToDS! */
696 printf("InitElf returned status=0x%04x\n", rpinit.rph.Status);
697 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
698 {
699 /* $win32k */
700 initRPInit(SSToDS(&rpinit), pszInitArgs);
701 rc = InitWin32k(&rpinit); /* no SSToDS! */
702 printf("InitWin32k returned status=0x%04x\n", rpinit.rph.Status);
703 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
704 {
705 struct options opt = DEFAULT_OPTION_ASSIGMENTS;
706 opt.cbSwpHeapInit = 512000;
707 opt.cbSwpHeapMax = 4096000;
708 opt.cbResHeapInit = 0256000;
709 opt.cbResHeapMax = 0x100000;
710 opt.fElf = TRUE;
711 opt.fUNIXScript = TRUE;
712 opt.fPE = FLAGS_PE_MIXED;
713 opt.fQuiet = FALSE;
714 opt.fLogging = TRUE;
715 opt.usCom = OUTPUT_COM1;
716 opt.ulInfoLevel = INFOLEVEL_INFOALL;
717
718 rc = CompareOptions(SSToDS(&opt));
719 if (rc == NO_ERROR)
720 {
721 rc = TestCaseExeLoad2();
722 }
723 }
724 else
725 printf("!failed!\n");
726 }
727 else
728 printf("!failed!\n");
729
730 return rc;
731}
732
733/**
734 * Test case 3.
735 * Checks that all parameters are read correctly (1).
736 *
737 * @sketch Create init packet with no arguments.
738 * Initiate elf$
739 * Create init packet with no arguments.
740 * Initiate win32k$
741 * @returns 0 on success.
742 * 1 on failure.
743 * @status completely implemented.
744 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
745 */
746int TestCase3(void)
747{
748 int rc = 1;
749 RP32INIT rpinit;
750 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";
751
752 /* $elf */
753 initRPInit(SSToDS(&rpinit), pszInitArgs);
754 rc = InitElf(&rpinit); /* no SSToDS! */
755 printf("InitElf returned status=0x%04x\n", rpinit.rph.Status);
756 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
757 {
758 /* $win32k */
759 initRPInit(SSToDS(&rpinit), pszInitArgs);
760 rc = InitWin32k(&rpinit); /* no SSToDS! */
761 printf("InitWin32k returned status=0x%04x\n", rpinit.rph.Status);
762 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
763 {
764 struct options opt = DEFAULT_OPTION_ASSIGMENTS;
765 opt.cbSwpHeapInit = 512000;
766 opt.cbSwpHeapMax = 4096000;
767 opt.cbResHeapInit = 0256000;
768 opt.cbResHeapMax = 0x100000;
769 opt.fElf = TRUE;
770 opt.fUNIXScript = TRUE;
771 opt.fJava = FALSE;
772 opt.fREXXScript = FALSE;
773 opt.fPE = FLAGS_PE_PE;
774 opt.fQuiet = TRUE;
775 opt.fLogging = FALSE;
776 opt.usCom = OUTPUT_COM1;
777 opt.ulInfoLevel = INFOLEVEL_INFOALL;
778
779 rc = CompareOptions(SSToDS(&opt));
780 if (rc == NO_ERROR)
781 {
782 rc = TestCaseExeLoad2();
783 }
784 }
785 else
786 printf("!failed!\n");
787 }
788 else
789 printf("!failed!\n");
790
791 return rc;
792}
793
794
795/**
796 * Test case 4.
797 * Checks that all parameters are read correctly (3).
798 *
799 * @sketch Create init packet with no arguments.
800 * Initiate elf$
801 * Create init packet with no arguments.
802 * Initiate win32k$
803 * @returns 0 on success.
804 * 1 on failure.
805 * @status completely implemented.
806 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
807 */
808int TestCase4(void)
809{
810 int rc = 1;
811 RP32INIT rpinit;
812 char * pszInitArgs = "-P:pe";
813
814 /* $elf */
815 initRPInit(SSToDS(&rpinit), pszInitArgs);
816 rc = InitElf(&rpinit); /* no SSToDS! */
817 printf("InitElf returned status=0x%04x\n", rpinit.rph.Status);
818 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
819 {
820 /* $win32k */
821 initRPInit(SSToDS(&rpinit), pszInitArgs);
822 rc = InitWin32k(&rpinit); /* no SSToDS! */
823 printf("InitWin32k returned status=0x%04x\n", rpinit.rph.Status);
824 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
825 {
826 struct options opt = DEFAULT_OPTION_ASSIGMENTS;
827 opt.fPE = FLAGS_PE_PE;
828
829 rc = CompareOptions(SSToDS(&opt));
830 /*
831 if (rc == NO_ERROR)
832 {
833 rc = TestCaseExeLoad2();
834 }
835 */
836 }
837 else
838 printf("!failed!\n");
839 }
840 else
841 printf("!failed!\n");
842
843 return rc;
844}
845
846
847/**
848 * Test case 5.
849 * Checks that all parameters are read correctly (3).
850 *
851 * @sketch Create init packet with no arguments.
852 * Initiate elf$
853 * Create init packet with no arguments.
854 * Initiate win32k$
855 * @returns 0 on success.
856 * 1 on failure.
857 * @status completely implemented.
858 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
859 */
860int TestCase5(void)
861{
862 int rc = 1;
863 RP32INIT rpinit;
864 char * pszInitArgs = "-Pe:pe";
865
866 /* $elf */
867 initRPInit(SSToDS(&rpinit), pszInitArgs);
868 rc = InitElf(&rpinit); /* no SSToDS! */
869 printf("InitElf returned status=0x%04x\n", rpinit.rph.Status);
870 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
871 {
872 /* $win32k */
873 initRPInit(SSToDS(&rpinit), pszInitArgs);
874 rc = InitWin32k(&rpinit); /* no SSToDS! */
875 printf("InitWin32k returned status=0x%04x\n", rpinit.rph.Status);
876 if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
877 {
878 struct options opt = DEFAULT_OPTION_ASSIGMENTS;
879 opt.fPE = FLAGS_PE_PE;
880
881 rc = CompareOptions(SSToDS(&opt));
882 /*
883 if (rc == NO_ERROR)
884 {
885 rc = TestCaseExeLoad2();
886 }
887 */
888 }
889 else
890 printf("!failed!\n");
891 }
892 else
893 printf("!failed!\n");
894
895 return rc;
896}
897
898
899/**
900 * Compares the options with the option struct passed in.
901 * @returns 0 on success.
902 * number of mismatches on error.
903 * @param pOpt
904 * @status completely implemented.
905 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
906 */
907int CompareOptions(struct options *pOpt)
908{
909 int rc = 0;
910 /*
911 * Check that the option struct is correct.
912 */
913 if (options.fQuiet != pOpt->fQuiet)
914 printf("fQuiet = %d - should be %d\n", options.fQuiet, pOpt->fQuiet, rc++);
915 if (options.usCom != pOpt->usCom)
916 printf("usCom = %d - should be %d\n", options.usCom, pOpt->usCom, rc++);
917 if (options.fLogging != pOpt->fLogging)
918 printf("fLogging = %d - should be %d\n", options.fLogging, pOpt->fLogging, rc++);
919 if (pOpt->ulBuild != ~0UL)
920 {
921 if (options.fKernel != pOpt->fKernel)
922 printf("fKernel = %x - should be %x\n", options.fKernel, pOpt->fKernel, rc++);
923 if (options.ulBuild != pOpt->ulBuild)
924 printf("ulBuild = %d - should be %d\n", options.ulBuild, pOpt->ulBuild, rc++);
925 if (options.usVerMajor != pOpt->usVerMajor)
926 printf("usVerMajor = %d - should be %d\n", options.usVerMajor, pOpt->usVerMajor, rc++);
927 if (options.usVerMinor != pOpt->usVerMinor)
928 printf("usVerMinor = %d - should be %d\n", options.usVerMinor, pOpt->usVerMinor, rc++);
929 }
930 if (options.fPE != pOpt->fPE)
931 printf("fPE = %d - should be %d\n", options.fPE, pOpt->fPE, rc++);
932 if (options.ulInfoLevel != pOpt->ulInfoLevel)
933 printf("ulInfoLevel = %d - should be %d\n", options.ulInfoLevel, pOpt->ulInfoLevel, rc++);
934 if (options.fElf != pOpt->fElf)
935 printf("fElf = %d - should be %d\n", options.fElf, pOpt->fElf, rc++);
936 if (options.fUNIXScript != pOpt->fUNIXScript)
937 printf("fUNIXScript = %d - should be %d\n", options.fUNIXScript, pOpt->fUNIXScript, rc++);
938 if (options.fREXXScript != pOpt->fREXXScript)
939 printf("fREXXScript = %d - should be %d\n", options.fREXXScript, pOpt->fREXXScript, rc++);
940 if (options.fJava != pOpt->fJava)
941 printf("fJava = %d - should be %d\n", options.fJava, pOpt->fJava, rc++);
942 if (options.fNoLoader != pOpt->fNoLoader)
943 printf("fNoLoader = %d - should be %d\n", options.fNoLoader, pOpt->fNoLoader, rc++);
944 if (options.cbSwpHeapInit != pOpt->cbSwpHeapInit)
945 printf("cbSwpHeapInit = %d - should be %d\n", options.cbSwpHeapInit, pOpt->cbSwpHeapInit, rc++);
946 if (options.cbSwpHeapMax != pOpt->cbSwpHeapMax)
947 printf("cbSwpHeapMax = %d - should be %d\n", options.cbSwpHeapMax, pOpt->cbSwpHeapMax, rc++);
948 if (options.cbResHeapInit != pOpt->cbResHeapInit)
949 printf("cbResHeapInit = %d - should be %d\n", options.cbResHeapInit, pOpt->cbResHeapInit, rc++);
950 if (options.cbResHeapMax != pOpt->cbResHeapMax)
951 printf("cbResHeapMax = %d - should be %d\n", options.cbResHeapMax, pOpt->cbResHeapMax, rc++);
952
953 return rc;
954}
955
956
957/**
958 * Simulates a executable loading (no errors).
959 * This test requires a PE executable file named ExecLoad1.exe which
960 * imports the dll ExecLoad1d.dll.
961 *
962 * @returns 0 on success.
963 * > 0 on failure.
964 * @sketch
965 * @status
966 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
967 * @remark
968 */
969int TestCaseExeLoad2(void)
970{
971 APIRET rc;
972 int cch;
973 char * psz;
974
975 /*
976 * Set global parameters... FIXME.
977 */
978
979 /*
980 * Do the real execution.
981 */
982 printf("--- TestcaseExeLoad2 - loading win32ktst.exe (LX image) ----\n");
983 rc = CalltkExecPgm(EXEC_LOAD, NULL, NULL, "GLC6000.TMP");
984 if (rc == NO_ERROR)
985 {
986 psz = "BIN\\DEBUG\\LIBCONV.EXE\0";
987 printf("--- TestcaseExeLoad2 - loading libconv.exe (LX image) ----\n");
988 rc = CalltkExecPgm(EXEC_LOAD, NULL, NULL, "bin\\debug\\libconv.exe");
989 if (rc == NO_ERROR)
990 {
991 #if 0 //not implemented by CalltkExecPgm...???
992 /* check result */
993 if (memcmp(achTkExecPgmArguments, psz, strlen(psz) + 1) != 0)
994 {
995 rc = ERROR_BAD_ARGUMENTS;
996 printf("Bad Arguments! (%s)\n", achTkExecPgmArguments);
997 }
998 #else
999 psz = psz;
1000 #endif
1001 }
1002 }
1003
1004 if (rc == NO_ERROR)
1005 {
1006 psz = "REXX\\TST.RX\0OriginalArgument1 OriginalArgument2\0OriginalArgument3\0";
1007 printf("--- TestcaseExeLoad2 - loading rexx\\tst.rx (REXX script) ----\n");
1008 rc = CalltkExecPgm(EXEC_LOAD, psz, NULL, "rexx\\tst.rx");
1009 if (rc == NO_ERROR)
1010 {
1011 /* check result */
1012 psz = "REXX\\TST.RX OriginalArgument1 OriginalArgument2\0OriginalArgument3\0";
1013 cch = strlen(psz);
1014 if (memcmp(achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1, psz, cch) != 0)
1015 {
1016 rc = ERROR_BAD_ARGUMENTS;
1017 printf("Bad Arguments! (achTkExecPgmArguments=%s).\n", achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1);
1018 }
1019 }
1020 }
1021
1022 if (rc == NO_ERROR)
1023 {
1024 psz = "TEST\\TST.SH\0OrgArg1 OrgArg2\0OrgArg3\0";
1025 printf("--- TestcaseExeLoad2 - loading test\\tst.sh (UNIX shell script) ----\n");
1026 rc = CalltkExecPgm(EXEC_LOAD, psz, NULL, "test\\tst.sh");
1027 if (rc == NO_ERROR)
1028 {
1029 /* check result */
1030 psz = "TEST\\TST.SH OrgArg1 OrgArg2\0OrgArg3\0";
1031 cch = strlen(psz);
1032 if (memcmp(achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1, psz, cch) != 0)
1033 {
1034 rc = ERROR_BAD_ARGUMENTS;
1035 printf("Bad Arguments! (achTkExecPgmArguments=%s).\n", achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1);
1036 }
1037 }
1038 }
1039
1040 if (rc == NO_ERROR)
1041 {
1042 psz = "TEST\\TST2.SH\0OrgArg1 OrgArg2\0OrgArg3\0";
1043 printf("--- TestcaseExeLoad2 - loading test\\tst2.sh (UNIX shell script) ----\n");
1044 rc = CalltkExecPgm(EXEC_LOAD, psz, NULL, "test\\tst2.sh");
1045 if (rc == NO_ERROR)
1046 {
1047 /* check result */
1048 psz = "-arg1 -arg2 -arg3 TEST\\TST2.SH OrgArg1 OrgArg2\0OrgArg3\0";
1049 cch = strlen(psz) + 1;
1050 if (memcmp(achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1, psz, cch) != 0)
1051 {
1052 rc = ERROR_BAD_ARGUMENTS;
1053 printf("Bad Arguments! (achTkExecPgmArguments=%s).\n", achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1);
1054 }
1055 }
1056 }
1057
1058 if (rc == NO_ERROR)
1059 {
1060 psz = "E:\\WIN32PROG\\SOL\\SOL.EXE\0";
1061 printf("--- TestcaseExeLoad2 - loading SOL.EXE (PE image) ----\n");
1062 rc = CalltkExecPgm(EXEC_LOAD, psz, NULL, "e:\\Win32Prog\\Sol\\Sol.exe");
1063 if (rc == NO_ERROR)
1064 {
1065 /* check result */
1066 cch = strlen(psz) + 1 + 1;
1067 if (memcmp(achTkExecPgmArguments, psz, cch) != 0)
1068 {
1069 rc = ERROR_BAD_ARGUMENTS;
1070 printf("Bad Arguments! (achTkExecPgmArguments=%s).\n", achTkExecPgmArguments + strlen(achTkExecPgmArguments) + 1);
1071 }
1072 }
1073 }
1074
1075 /*
1076 * The test is successful if rc == NO_ERROR (== 0).
1077 */
1078 return rc;
1079}
1080
Note: See TracBrowser for help on using the repository browser.