Changeset 2863


Ignore:
Timestamp:
Nov 10, 2006, 5:05:39 AM (19 years ago)
Author:
bird
Message:

bare bone dll testcase.

Location:
trunk/kLdr/testcase
Files:
1 edited
6 copied

Legend:

Unmodified
Added
Removed
  • trunk/kLdr/testcase/Makefile.kmk

    r2862 r2863  
    3333
    3434#
    35 # Template for testcases.
     35# Templates for the testcases.
    3636#
    3737TEMPLATE_TST = Testcase template
     
    8282
    8383
     84TEMPLATE_TSTBARE = Bare bone testcase template
     85ifneq ($(filter win nt win32 win64,$(BUILD_TARGET)),)
     86 TEMPLATE_TSTBARE_TOOL = VCC70
     87 TEMPLATE_TSTBARE_CFLAGS = -W3 -Zi -Zl
     88 TEMPLATE_TSTBARE_CFLAGS.release = -O2
     89 TEMPLATE_TSTBARE_CXXFLAGS = -W3 -Zi -Zl
     90 TEMPLATE_TSTBARE_CXXFLAGS.release = -O2
     91 TEMPLATE_TSTBARE_ASFLAGS = -f win
     92 TEMPLATE_TSTBARE_DEFS = __WIN__
     93 TEMPLATE_TSTBARE_SDKS = WIN32SDK
     94
     95else
     96 ifneq ($(filter os2,$(BUILD_TARGET)),)
     97  TEMPLATE_TSTBARE_TOOL = GCC3OMF
     98  TEMPLATE_TSTBARE_ASFLAGS = -f obj
     99  TEMPLATE_TSTBARE_LIBS = os2 gcc end
     100 else
     101  TEMPLATE_TSTBARE_TOOL = GCC3
     102  TEMPLATE_TSTBARE_ASFLAGS = -f elf
     103  TEMPLATE_TSTBARE_LIBS = gcc
     104 endif
     105 TEMPLATE_TSTBARE_CFLAGS = -Wall -pedantic -g
     106 TEMPLATE_TSTBARE_CFLAGS.release = -O2
     107 TEMPLATE_TSTBARE_LDFLAGS = -nostdlib -lgcc
     108endif
     109TEMPLATE_TSTBARE_INCS = .
     110
     111TEMPLATE_TSTBAREPROG = Bare bone testcase program template
     112TEMPLATE_TSTBAREPROG_EXTENDS = TSTBARE
     113ifneq ($(filter win nt win32 win64,$(BUILD_TARGET)),)
     114TEMPLATE_TSTBAREPROG_LDFLAGS += -Entry:WinMain -FIXED:NO
     115else
     116endif
     117
     118
     119TEMPLATE_TSTBAREDLL = Bare bone testcase dll template
     120TEMPLATE_TSTBAREDLL_EXTENDS = TSTBARE
     121ifneq ($(filter win nt win32 win64,$(BUILD_TARGET)),)
     122TEMPLATE_TSTBAREDLL_LDFLAGS += -Entry:DllMain
     123else
     124endif
     125
     126
     127
     128
     129#
     130# tst-0: four dlls, three of which depends on the 4th and no external dependencies.
     131#        The purpose of this testcase is to debug the dynamic loader without
     132#        messing with the native loader at all.
     133#
     134PROGRAMS += tst-0
     135DLLS += tst-0-a tst-0-b tst-0-c tst-0-d
     136
     137tst-0-a_TEMPLATE = TSTBAREDLL
     138tst-0-a_SOURCES  = tst-0-a.c tstDllMainStub.c
     139
     140tst-0-b_TEMPLATE = TSTBAREDLL
     141tst-0-b_SOURCES  = tst-0-b.c tstDllMainStub.c
     142
     143tst-0-c_TEMPLATE = TSTBAREDLL
     144tst-0-c_SOURCES  = tst-0-c.c tstDllMainStub.c
     145
     146tst-0-d_TEMPLATE = TSTBAREDLL
     147tst-0-d_SOURCES  = tst-0-d.c tstDllMainStub.c
     148
     149tst-0_TEMPLATE   = TSTPROG
     150tst-0_SOURCES    = tst-0.c
     151
     152ifeq ($(filter-out nt win win32 win64,$(BUILD_TARGET)),)
     153tst-0-a_LIBS     = $(PATH_TARGET)/tst-0-d/tst-0-d.lib
     154tst-0-b_LIBS     = $(PATH_TARGET)/tst-0-d/tst-0-d.lib
     155tst-0-c_LIBS     = $(PATH_TARGET)/tst-0-d/tst-0-d.lib
     156tst-0_LIBS       = $(TARGET_tst-0-a:.dll=.lib) $(TARGET_tst-0-b:.dll=.lib) $(TARGET_tst-0-c:.dll=.lib)
     157else
     158tst-0-a_LIBS     = $(TARGET_tst-0-a:-a=-d)
     159tst-0-b_LIBS     = $(TARGET_tst-0-b:-b=-d)
     160tst-0-c_LIBS     = $(TARGET_tst-0-c:-c=-d)
     161tst-0_LIBS       = $(TARGET_tst-0-a) $(TARGET_tst-0-b) $(TARGET_tst-0-c)
     162endif
     163
     164
    84165#
    85166# tst-1: four dlls, three of which depends on the 4th and the testcase depends on those three again.
  • trunk/kLdr/testcase/tst-0-a.c

    r2841 r2863  
    66MY_EXPORT(int) FuncA(void)
    77{
    8     return FuncD();
     8    return FuncD() | (g_pszName[0] == 'a' ? 0x42 : 0x0001);
    99}
    1010
  • trunk/kLdr/testcase/tst-0-b.c

    r2841 r2863  
    66MY_EXPORT(int) FuncB(void)
    77{
    8     return FuncD();
     8    return FuncD() | (g_pszName[0] == 'b' ? 0x4200 : 0x0010);
    99}
    1010
  • trunk/kLdr/testcase/tst-0-c.c

    r2841 r2863  
    66MY_EXPORT(int) FuncC(void)
    77{
    8     return FuncD();
     8    return FuncD() | (g_pszName[0] == 'c' ? 0x420000 : 0x0100);
    99}
    1010
  • trunk/kLdr/testcase/tst-0-d.c

    r2841 r2863  
    44MY_EXPORT(int) FuncD(void)
    55{
    6     return 0;
     6    return g_pszName[0] == 'd' ? 0x42000000 : 0x1000;
    77}
    88
  • trunk/kLdr/testcase/tst-0.c

    r2841 r2863  
    88int main()
    99{
     10    unsigned long ul;
    1011    printf("graph:\n"
    11            "  tst-1 -> a -> d\n"
     12           "  tst-0 -> a -> d\n"
    1213           "           b -> d\n"
    1314           "           c -> d\n");
    14     return FuncA() + FuncB() + FuncC();
     15    ul = FuncA() | FuncB() | FuncC();
     16    if (ul == 0x42424242)
     17        printf("tst-0: success, ul=%#lx\n", ul);
     18    else
     19        printf("tst-0: failure, ul=%#lx\n", ul);
     20    return ul == 0x42424242 ? 0 : 1;
    1521}
  • trunk/kLdr/testcase/tstDllMainStub.c

    r2841 r2863  
    22/** @file
    33 *
    4  * kLdr testcase.
     4 * kLdr testcase - DLL Stub.
    55 *
    66 * Copyright (c) 2006 knut st. osmundsen <bird-kbuild-src@anduin.net>
     
    3434# define INCL_BASE
    3535# include <os2.h>
    36 # include <string.h>
    3736
    3837#elif defined(__WIN__)
    3938# include <windows.h>
    40 # include <string.h>
    4139
    4240#else
    4341# error "port me"
    4442#endif
    45 
    46 /*******************************************************************************
    47 *   Internal Functions                                                         *
    48 *******************************************************************************/
    49 static void tstWrite(const char *psz);
    50 
    5143
    5244
     
    5749ULONG _System _DLL_InitTerm(HMODULE hmod, ULONG fFlag)
    5850{
    59     switch (fFlags)
    60     {
    61         case 0:
    62             tstWrite("init: ");
    63             tstWrite(g_pszName);
    64             tstWrite("\n");
    65             return TRUE;
    66 
    67         case 1:
    68             tstWrite("term: ");
    69             tstWrite(g_pszName);
    70             tstWrite("\n");
    71             return TRUE;
    72 
    73         default:
    74             tstWrite("!invalid!: ");
    75             tstWrite(g_pszName);
    76             tstWrite("\n");
    77             return FALSE;
    78     }
     51    return TRUE;
    7952}
    8053
     
    8255
    8356/**
    84  * OS/2 DLL 'main'
     57 * Window DLL 'main'
    8558 */
    8659BOOL __stdcall DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpReserved)
    8760{
    88     switch (dwReason)
    89     {
    90         case DLL_PROCESS_ATTACH:
    91             tstWrite("init: ");
    92             tstWrite(g_pszName);
    93             tstWrite("\n");
    94             return TRUE;
    95 
    96         case DLL_PROCESS_DETACH:
    97             tstWrite("term: ");
    98             tstWrite(g_pszName);
    99             tstWrite("\n");
    100             return TRUE;
    101 
    102         case DLL_THREAD_ATTACH:
    103             tstWrite("thread init: ");
    104             tstWrite(g_pszName);
    105             tstWrite("\n");
    106             return TRUE;
    107 
    108         case DLL_THREAD_DETACH:
    109             tstWrite("thread term: ");
    110             tstWrite(g_pszName);
    111             tstWrite("\n");
    112             return TRUE;
    113 
    114         default:
    115             tstWrite("!invalid!: ");
    116             tstWrite(g_pszName);
    117             tstWrite("\n");
    118             return FALSE;
    119     }
     61    return TRUE;
    12062}
    12163
     
    12466#endif
    12567
    126 
    127 /**
    128  * Writes a string with unix lineendings.
    129  *
    130  * @param   pszMsg  The string.
    131  */
    132 static void tstWrite(const char *pszMsg)
    133 {
    134 #if defined(__OS2__) || defined(__WIN__)
    135     /*
    136      * Line by line.
    137      */
    138     ULONG       cbWritten;
    139     const char *pszNl = strchr(pszMsg, '\n');
    140 
    141     while (pszNl)
    142     {
    143         cbWritten = pszNl - pszMsg;
    144 
    145 #ifdef __OS2__
    146         if (cbWritten)
    147             DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten);
    148         DosWrite((HFILE)2, "\r\n", 2, &cbWritten);
    149 #else /* __WIN32__ */
    150         if (cbWritten)
    151             WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL);
    152         WriteFile((HANDLE)STD_ERROR_HANDLE, "\r\n", 2, &cbWritten, NULL);
    153 #endif
    154 
    155         /* next */
    156         pszMsg = pszNl + 1;
    157         pszNl = strchr(pszMsg, '\n');
    158     }
    159 
    160     /*
    161      * Remaining incomplete line.
    162      */
    163     if (*pszMsg)
    164     {
    165         cbWritten = strlen(pszMsg);
    166 #ifdef __OS2__
    167         DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten);
    168 #else /* __WIN32__ */
    169         WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL);
    170 #endif
    171     }
    172 
    173 #else
    174 # error "port me"
    175 #endif
    176 }
    177 
    178 
Note: See TracChangeset for help on using the changeset viewer.