parameters2.exp revision e5a8cef0bf0e96480d6ca0355bb64d3121a88858
1# This file is part of ltrace.
2# Copyright (C) 2012 Petr Machata, Red Hat Inc.
3#
4# This program is free software; you can redistribute it and/or
5# modify it under the terms of the GNU General Public License as
6# published by the Free Software Foundation; either version 2 of the
7# License, or (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12# General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17# 02110-1301 USA
18
19set trivial [ltraceCompile {} [ltraceSource c {
20    int main(void) {}
21}]]
22
23ltraceMatch1 [ltraceRun -L -F [ltraceSource conf {
24    typedef aa = int;
25    typedef aaa = int;
26    typedef bbb = struct(aa);
27}] -- $trivial] "error" == 0
28
29ltraceMatch1 [ltraceRun -L -F [ltraceSource conf {
30    typedef aa = int;
31    typedef aa = int;
32}] -- $trivial] "error" != 0
33
34ltraceMatch1 [ltraceRun -L -F [ltraceSource conf {
35    typedef aa = struct;
36    typedef aa = int;
37}] -- $trivial] "error" != 0
38
39ltraceMatch1 [ltraceRun -L -F [ltraceSource conf {
40    typedef aa = struct;
41    typedef aa = struct(int);
42    typedef aa = struct(int);
43}] -- $trivial] "error" != 0
44
45ltraceMatch1 [ltraceRun -L -F [ltraceSource conf {
46    typedef aa = struct;
47    typedef aa = struct();
48    typedef aa = struct();
49}] -- $trivial] "error" != 0
50
51ltraceMatch1 [ltraceRun -L -F [ltraceSource conf {
52    typedef aa = struct(int, struct;);
53}] -- $trivial] "error" != 0
54
55set libll [ltraceCompile libll.so [ltraceSource c {
56    struct xxx;
57    void ll(struct xxx *xxx) {}
58}]]
59
60set conf [ltraceSource conf {
61    typedef xxx = struct;
62    typedef xxx = struct(int, xxx*);
63    void ll(xxx*);
64}]
65
66ltraceMatch [ltraceRun -F $conf -e ll [ltraceCompile {} $libll [ltraceSource c {
67    struct xxx {
68	int i;
69	struct xxx *next;
70    };
71
72    void ll (struct xxx *xxx);
73    int main (int argc, char *argv[])
74    {
75	struct xxx a = { 1, 0 };
76	struct xxx b = { 2, &a };
77	struct xxx c = { 3, &b };
78	struct xxx d = { 4, &c };
79	ll (&d);
80
81	struct xxx e = { 1, 0 };
82	struct xxx f = { 2, &e };
83	e.next = &f;
84	ll (&f);
85
86	struct xxx g = { 1, &g };
87	ll (&g);
88
89	return 0;
90    }
91}]]] {
92    {{->ll\({ 4, { 3, { 2, { 1, nil } } } }\) *= <void>} == 1}
93    {{->ll\({ 2, { 1, recurse\^ } }\) *= <void>} == 1}
94    {{->ll\({ 1, recurse }\) *= <void>} == 1}
95}
96
97ltraceMatch1 [ltraceRun -F $conf -e ll -A 5 \
98-- [ltraceCompile ll $libll [ltraceSource c {
99    #include <stdlib.h>
100    struct ble {
101	int i;
102	struct ble *next;
103    };
104
105    void ll (struct ble *ble);
106    int main (int argc, char *argv[])
107    {
108	struct ble *b = NULL;
109	int i;
110	for (i = 0; i < 10; ++i) {
111	    struct ble *n = malloc(sizeof(*n));
112	    n->i = i;
113	    n->next = b;
114	    b = n;
115	}
116	ll (b);
117
118	return 0;
119    }
120}]]] {->ll\({ 9, { 8, { 7, { 6, { 5, \.\.\. } } } } }\) *= <void>} == 1
121
122proc ltraceParamTest {conf cdecl libcode maincode match} {
123    set conffile [ltraceSource conf $conf]
124    set lib [ltraceCompile liblib.so [ltraceSource c [concat $cdecl $libcode]]]
125    set bin [ltraceCompile {} $lib \
126		 [ltraceSource c \
127		      [concat $cdecl "int main(void) {" $maincode "}"]]]
128
129    return [ltraceMatch [ltraceRun -F $conffile -- $bin] $match]
130}
131
132ltraceParamTest {
133    typedef hexptr = hex(uint*);
134    void fun(hexptr);
135} {
136    void fun(unsigned *arg);
137} {
138    void fun(unsigned *arg) {}
139} {
140    unsigned u = 0x123;
141    fun(&u);
142} {
143    {{fun\(0x123\) *= <void>} == 1}
144}
145
146ltraceParamTest {
147    void fun(bitvec(uint));
148    void fun2(bitvec(array(char, 32)*));
149} {
150    void fun(unsigned i);
151    void fun2(unsigned char *arr);
152} {
153    void fun(unsigned i) {}
154    void fun2(unsigned char *arr) {}
155} {
156    fun(0);
157    fun(0x123);
158    fun(0xfffffffe);
159    fun(0xffffffff);
160
161    unsigned char bytes[32] = {0x00};
162    bytes[1] = 0xff;
163    bytes[31] = 0x80;
164    fun2(bytes);
165} {
166    {{fun\(<>\) *= <void>} == 1}
167    {{fun\(<0-1,5,8>\) *= <void>} == 1}
168    {{fun\(~<0>\) *= <void>} == 1}
169    {{fun\(~<>\) *= <void>} == 1}
170    {{fun2\(<8-15,255>\) *= <void>} == 1}
171}
172
173ltraceParamTest {
174    hex(float) hex_float(hex(float));
175    hex(double) hex_double(hex(double));
176} {
177    float hex_float(float f);
178    double hex_double(double d);
179} {
180    float hex_float(float f) { return f + 1; }
181    double hex_double(double d) { return d + 1; }
182} {
183    hex_float(1.5);
184    hex_double(1.5);
185} {
186    {{hex_float\(0x1.8p\+0\) *= 0x1.4p\+1} == 1}
187    {{hex_double\(0x1.8p\+0\) *= 0x1.4p\+1} == 1}
188}
189
190ltraceDone
191