OSDN Git Service

(LibGoblin)
[drdeamon64/drdeamon64.git] / libgoblin / test_libgoblin_loadprog.c
1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
2
3                          D r . D e a m o n  6 4
4                         for INTEL64(R), AMD64(R)
5         
6    Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10
11  1. Redistributions of source code must retain the above copyright notice,
12     this list of conditions and the following disclaimer.
13  2. Redistributions in binary form must reproduce the above copyright
14     notice, this list of conditions and the following disclaimer in the
15     documentation and/or other materials provided with the distribution.
16
17 THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
30
31 /* File Info -----------------------------------------------------------
32 File: drd64_.c
33 Function: 
34 Comment: 
35 ----------------------------------------------------------------------*/
36
37 #define DRD64_SRC_TEST_LIBGOBLIN_LOADPROG
38 #include"drd64_libgoblin.h"
39 #include"test_libgoblin.h"
40
41
42 /* LibGoblin_LoadProgram() API ****************************************/
43 /*--------------------------------------------------------------------*/
44 void Test_LibGoblin_LoadProg_API_LoadProgram_test00_001( void )
45 {
46         int             i_pgid;
47         int             i_bid[20];
48         int             i_cnt           = 1;
49         int             i_result;
50         char    *pstr_ldpath;
51         char    *pstr_env_ldlibpath;
52
53         LibGoblin_ObjectFilePath        t_objpath;
54
55         i_result        = LibBrownie_Init();
56         CU_ASSERT( 0x00 == i_result );
57
58         pstr_ldpath     = LibBrownie_GetLoadLibraryPath( LIBBROWNIE_LDHINTS_ELF64 );
59         if( NULL == pstr_ldpath )
60                 { goto  goto_Test_LibGoblin_LoadProg_API_LoadProgram_test00_001_post; }
61
62         pstr_env_ldlibpath      = getenv("LD_LIBRARY_PATH");
63
64         i_result        = LibGoblin_Init();
65         CU_ASSERT( 0x00 == i_result );
66
67         i_pgid  = LibGoblin_AllocProgInfo();
68         CU_ASSERT( 0x00 <= i_result );
69
70         i_bid[0]        = LibGoblin_LoadProgram_Main( i_pgid, "../testdata/dwarftest",
71                                                                                         "../testdata/dwarftest" );
72         CU_ASSERT( 0x00 == i_bid[0] );
73
74         i_bid[i_cnt]    = LibGoblin_GetUnresolv_ObjectFilePath( i_pgid, &t_objpath );
75         while( 0x00 < i_bid[i_cnt] )    {
76                 i_result        = LibBrownie_GetLibraryPath(
77                                                         t_objpath.str_localpath,
78                                                         t_objpath.str_filename,
79                                                         t_objpath.str_rpath,
80                                                         t_objpath.str_runpath,
81                                                         pstr_env_ldlibpath,
82                                                         pstr_ldpath );
83
84                 CU_ASSERT( 0x00 < i_result );
85                 if( 0x00 >= i_result )
86                         { goto  goto_Test_LibGoblin_LoadProg_API_LoadProgram_test00_001_post; }
87
88                 printf("  file= %s, DT_RPATH= %s, DT_RUNPATH=%s\n      => localpath: %s [bid= %d]\n", 
89                                         t_objpath.str_filename, t_objpath.str_rpath,
90                                         t_objpath.str_runpath, t_objpath.str_localpath, i_bid[i_cnt] );
91
92                 i_result        = LibGoblin_SetPathAndLoad_ObjectFilePath( &t_objpath );
93                 CU_ASSERT( 0x00 == i_result );
94                 if( 0x00 != i_result )
95                         { goto  goto_Test_LibGoblin_LoadProg_API_LoadProgram_test00_001_post; }
96
97                 i_cnt++;
98                 i_bid[i_cnt]    = LibGoblin_GetUnresolv_ObjectFilePath( i_pgid, &t_objpath );
99         }
100
101         i_result        = LibGoblin_AnalyzeMainProgram( i_pgid );
102         CU_ASSERT( 0x00 == i_result );
103
104         //i_result      = LibGoblin_AnalyzeLibrary( i_pgid, i_bid[2], 0x80000000 );
105         //CU_ASSERT( 0x00 == i_result );
106
107         i_result        = LibGoblin_FreeProgInfo( i_pgid );
108         CU_ASSERT( 0x00 == i_result );
109
110         i_result        = LibGoblin_Term();
111         CU_ASSERT( 0x00 == i_result );
112
113         LibBrownie_FreeLoadLibraryPath( LIBBROWNIE_LDHINTS_ELF64 );
114
115 goto_Test_LibGoblin_LoadProg_API_LoadProgram_test00_001_post:
116         LibBrownie_Term();
117
118         return;
119 }
120
121
122 /*----------------------------------------------------------------------
123 ----------------------------------------------------------------------*/
124 DRD64_TEST_LIBGOBLIN_LOADPROG_EXTERN
125 int
126         Test_LibGoblin_LoadProg(
127                 void )
128 {
129         CU_pSuite       pt_goblin;
130
131         pt_goblin       = CU_add_suite( "LibGoblin_LoadProg", NULL, NULL );
132
133         CU_add_test( pt_goblin, "LibGoblin_LoadProg_test00_001",
134                                                                  Test_LibGoblin_LoadProg_API_LoadProgram_test00_001 );
135
136
137         return 0x00;
138 }
139
140
141 /* EOF of drd64_.c ----------------------------------- */