ยปCore Development>Code coverage>Modules/_ctypes/libffi/testsuite/libffi.call/float_va.c

Python code coverage for Modules/_ctypes/libffi/testsuite/libffi.call/float_va.c

#countcontent
1n/a/* Area: fp and variadics
2n/a Purpose: check fp inputs and returns work on variadics, even the fixed params
3n/a Limitations: None
4n/a PR: none
5n/a Originator: <david.gilbert@linaro.org> 2011-01-25
6n/a
7n/a Intended to stress the difference in ABI on ARM vfp
8n/a*/
9n/a
10n/a/* { dg-do run } */
11n/a
12n/a#include <stdarg.h>
13n/a
14n/a#include "ffitest.h"
15n/a
16n/a/* prints out all the parameters, and returns the sum of them all.
17n/a * 'x' is the number of variadic parameters all of which are double in this test
18n/a */
19n/adouble float_va_fn(unsigned int x, double y,...)
20n/a{
21n/a double total=0.0;
22n/a va_list ap;
23n/a unsigned int i;
24n/a
25n/a total+=(double)x;
26n/a total+=y;
27n/a
28n/a printf("%u: %.1f :", x, y);
29n/a
30n/a va_start(ap, y);
31n/a for(i=0;i<x;i++)
32n/a {
33n/a double arg=va_arg(ap, double);
34n/a total+=arg;
35n/a printf(" %d:%.1f ", i, arg);
36n/a }
37n/a va_end(ap);
38n/a
39n/a printf(" total: %.1f\n", total);
40n/a
41n/a return total;
42n/a}
43n/a
44n/aint main (void)
45n/a{
46n/a ffi_cif cif;
47n/a
48n/a ffi_type *arg_types[5];
49n/a void *values[5];
50n/a double doubles[5];
51n/a unsigned int firstarg;
52n/a double resfp;
53n/a
54n/a /* First test, pass float_va_fn(0,2.0) - note there are no actual
55n/a * variadic parameters, but it's declared variadic so the ABI may be
56n/a * different. */
57n/a /* Call it statically and then via ffi */
58n/a resfp=float_va_fn(0,2.0);
59n/a /* { dg-output "0: 2.0 : total: 2.0" } */
60n/a printf("compiled: %.1f\n", resfp);
61n/a /* { dg-output "\ncompiled: 2.0" } */
62n/a
63n/a arg_types[0] = &ffi_type_uint;
64n/a arg_types[1] = &ffi_type_double;
65n/a arg_types[2] = NULL;
66n/a CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 2, 2,
67n/a &ffi_type_double, arg_types) == FFI_OK);
68n/a
69n/a firstarg = 0;
70n/a doubles[0] = 2.0;
71n/a values[0] = &firstarg;
72n/a values[1] = &doubles[0];
73n/a ffi_call(&cif, FFI_FN(float_va_fn), &resfp, values);
74n/a /* { dg-output "\n0: 2.0 : total: 2.0" } */
75n/a printf("ffi: %.1f\n", resfp);
76n/a /* { dg-output "\nffi: 2.0" } */
77n/a
78n/a /* Second test, float_va_fn(2,2.0,3.0,4.0), now with variadic params */
79n/a /* Call it statically and then via ffi */
80n/a resfp=float_va_fn(2,2.0,3.0,4.0);
81n/a /* { dg-output "\n2: 2.0 : 0:3.0 1:4.0 total: 11.0" } */
82n/a printf("compiled: %.1f\n", resfp);
83n/a /* { dg-output "\ncompiled: 11.0" } */
84n/a
85n/a arg_types[0] = &ffi_type_uint;
86n/a arg_types[1] = &ffi_type_double;
87n/a arg_types[2] = &ffi_type_double;
88n/a arg_types[3] = &ffi_type_double;
89n/a arg_types[4] = NULL;
90n/a CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 2, 4,
91n/a &ffi_type_double, arg_types) == FFI_OK);
92n/a
93n/a firstarg = 2;
94n/a doubles[0] = 2.0;
95n/a doubles[1] = 3.0;
96n/a doubles[2] = 4.0;
97n/a values[0] = &firstarg;
98n/a values[1] = &doubles[0];
99n/a values[2] = &doubles[1];
100n/a values[3] = &doubles[2];
101n/a ffi_call(&cif, FFI_FN(float_va_fn), &resfp, values);
102n/a /* { dg-output "\n2: 2.0 : 0:3.0 1:4.0 total: 11.0" } */
103n/a printf("ffi: %.1f\n", resfp);
104n/a /* { dg-output "\nffi: 11.0" } */
105n/a
106n/a exit(0);
107n/a}