1 | /* $Id: kLdrRdrFile.c 2857 2006-11-05 04:12:13Z bird $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * kLdr - Dynamic Loader testcase no. 0, Driver.
|
---|
5 | *
|
---|
6 | * Copyright (c) 2006 knut st. osmundsen <bird-kbuild-src@anduin.net>
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * This file is part of kLdr.
|
---|
10 | *
|
---|
11 | * kLdr is free software; you can redistribute it and/or modify
|
---|
12 | * it under the terms of the GNU General Public License as published by
|
---|
13 | * the Free Software Foundation; either version 2 of the License, or
|
---|
14 | * (at your option) any later version.
|
---|
15 | *
|
---|
16 | * kLdr is distributed in the hope that it will be useful,
|
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | * GNU General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with kLdr; if not, write to the Free Software
|
---|
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
24 | *
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*******************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *******************************************************************************/
|
---|
31 | #include <kLdr.h>
|
---|
32 | #include <stdarg.h>
|
---|
33 | #include <stdio.h>
|
---|
34 | #include <stdlib.h>
|
---|
35 | #include <string.h>
|
---|
36 |
|
---|
37 |
|
---|
38 |
|
---|
39 | /*******************************************************************************
|
---|
40 | * Global Variables *
|
---|
41 | *******************************************************************************/
|
---|
42 | /** The numbers of errors. */
|
---|
43 | static int g_cErrors = 0;
|
---|
44 |
|
---|
45 |
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Report failure.
|
---|
49 | */
|
---|
50 | static int Failure(const char *pszFormat, ...)
|
---|
51 | {
|
---|
52 | va_list va;
|
---|
53 |
|
---|
54 | g_cErrors++;
|
---|
55 |
|
---|
56 | printf("tstLdrMod: ");
|
---|
57 | va_start(va, pszFormat);
|
---|
58 | vprintf(pszFormat, va);
|
---|
59 | va_end(va);
|
---|
60 | printf("\n");
|
---|
61 | return 1;
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | int main(int argc, char **argv)
|
---|
66 | {
|
---|
67 | const char *pszErrInit = "Error, szErr wasn't zapped";
|
---|
68 | char szErr[512];
|
---|
69 | HKLDRMOD hMod;
|
---|
70 | int rc;
|
---|
71 |
|
---|
72 | hMod = (HKLDRMOD)0xffffeeee;
|
---|
73 | strcpy(szErr, pszErrInit);
|
---|
74 | rc = kLdrDyldLoad("tst-0", NULL, NULL, KLDRDYLD_SEARCH_KLDR,
|
---|
75 | KLDRDYLD_LOAD_FLAGS_RECURSIVE_INIT, &hMod, szErr, sizeof(szErr));
|
---|
76 | if (rc)
|
---|
77 | Failure("kLdrDyldLoad(\"tst-0\",...) failed, rc=%d (%#x). szErr='%s'.\n", rc, rc, szErr);
|
---|
78 | if (strcmp(szErr, pszErrInit))
|
---|
79 | Failure("szErr wasn't set.\n");
|
---|
80 | if (hMod == (HKLDRMOD)0xffffeeee)
|
---|
81 | Failure("hMod wasn't set.\n");
|
---|
82 | if (hMod == NIL_HKLDRMOD && !rc)
|
---|
83 | Failure("rc=0 but hMod=NIL_HKLDRMOD\n");
|
---|
84 | if (!rc)
|
---|
85 | {
|
---|
86 | rc = kLdrDyldUnload(hMod);
|
---|
87 | if (rc)
|
---|
88 | Failure("kLdrDyldUnload() failed. rc=%d (%#x)\n", rc, rc);
|
---|
89 | }
|
---|
90 |
|
---|
91 | /*
|
---|
92 | * Summary
|
---|
93 | */
|
---|
94 | if (!g_cErrors)
|
---|
95 | printf("tst-0: SUCCESS\n");
|
---|
96 | else
|
---|
97 | printf("tst-0: FAILURE - %d errors\n", g_cErrors);
|
---|
98 | return !!g_cErrors;
|
---|
99 | }
|
---|
100 |
|
---|