This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[_Complex test 4/4] _Complex tests in callfuncs.exp


These tests in this patch is about passing _Complex type args and return
_Complex type.

Rerun callfuncs.exp on i686-pc-linux-gnu, and get two new KFAIL and one
FAIL.  This extra FAIL is caused by these two KFAILs.  PR 12783 is opened.

KFAIL: gdb.base/callfuncs.exp: call inferior func with struct - returns
double _Complex (PRMS: gdb/12783)
KFAIL: gdb.base/callfuncs.exp: call inferior func with struct - returns
long double _Complex (PRMS: gdb/12783)

FAIL: gdb.base/callfuncs.exp: gdb function calls preserve register contents

                === gdb Summary ===

# of expected passes            153
# of unexpected failures        1
# of known failures             2

Note that there is no tests about _Complex in aggregate types in this
patch set, because gdb.base/structs.exp can not be extended to cover
_Complex types easily.  I find there is an interesting test on
struct/union in gcc (gcc.dg/compat/struct-layout-1.exp), and still need
some time to see if we can make use of it in gdb tests.

-- 
Yao (éå)
gdb/testsuite/

	* gdb.base/callfuncs.c (t_structs_fc): New.
	(t_structs_dc, t_structs_ldc): New.
	(t_double_many_args):
	(DEF_FUNC_MANY_ARGS_1, DEF_FUNC_MANY_ARGS_2): Define.
	(DEF_FUNC_MANY_ARGS_3, DEF_FUNC_VALUES_1): Define.
	(DEF_FUNC_VALUES_2, DEF_FUNC_VALUES_3): Define.
	* gdb.base/callfuncs.exp: Call new functions.

>From 12b36674dc96051b3b5b9f1eb6b14e1cce022bcc Mon Sep 17 00:00:00 2001
From: Yao Qi <yao@codesourcery.com>
Date: Wed, 18 May 2011 21:43:57 +0800
Subject: [PATCH 4/4] pass args of type complex to func

---
 gdb/testsuite/gdb.base/callfuncs.c   |  151 +++++++++++++++++++++++++++++++++-
 gdb/testsuite/gdb.base/callfuncs.exp |   55 ++++++++++++-
 2 files changed, 204 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/gdb.base/callfuncs.c b/gdb/testsuite/gdb.base/callfuncs.c
index 406d22a..80815f9 100644
--- a/gdb/testsuite/gdb.base/callfuncs.c
+++ b/gdb/testsuite/gdb.base/callfuncs.c
@@ -73,6 +73,30 @@ double double_val13 = 10.25;
 double double_val14 = 11.25;
 double double_val15 = 12.25;
 
+#ifdef TEST_COMPLEX
+extern float crealf (float _Complex);
+extern float cimagf (float _Complex);
+extern double creal (double _Complex);
+extern double cimag (double _Complex);
+extern long double creall (long double _Complex);
+extern long double cimagl (long double _Complex);
+
+float _Complex fc1 = 1.0F + 1.0iF;
+float _Complex fc2 = 2.0F + 2.0iF;
+float _Complex fc3 = 3.0F + 3.0iF;
+float _Complex fc4 = 4.0F + 4.0iF;
+
+double _Complex dc1 = 1.0 + 1.0i;
+double _Complex dc2 = 2.0 + 2.0i;
+double _Complex dc3 = 3.0 + 3.0i;
+double _Complex dc4 = 4.0 + 4.0i;
+
+long double _Complex ldc1 = 1.0L + 1.0Li;
+long double _Complex ldc2 = 2.0L + 2.0Li;
+long double _Complex ldc3 = 3.0L + 3.0Li;
+long double _Complex ldc4 = 4.0L + 4.0Li;
+#endif /* TEST_COMPLEX */
+
 #define DELTA (0.001)
 
 char *string_val1 = (char *)"string 1";
@@ -89,8 +113,15 @@ struct struct1 {
   float f;
   double d;
   char a[4];
+#ifdef TEST_COMPLEX
+  float _Complex fc;
+  double _Complex dc;
+  long double _Complex ldc;
+} struct_val1 ={ 'x', 87, 76, 51, 2.1234, 9.876, "foo", 3.0F + 3.0Fi,
+		 4.0L + 4.0Li, 5.0L + 5.0Li};
+#else
 } struct_val1 = { 'x', 87, 76, 51, 2.1234, 9.876, "foo" };
-
+#endif /* TEST_COMPLEX */
 /* Some functions that can be passed as arguments to other test
    functions, or called directly. */
 #ifdef PROTOTYPES
@@ -183,6 +214,11 @@ char  *t_structs_a (struct struct1 tstruct)
   strcpy (buf, tstruct.a);
   return buf;
 }
+#ifdef TEST_COMPLEX
+float _Complex t_structs_fc (struct struct1 tstruct) { return tstruct.fc;}
+double _Complex t_structs_dc (struct struct1 tstruct) { return tstruct.dc;}
+long double _Complex t_structs_fc (struct struct1 tstruct) { return tstruct.ldc;}
+#endif
 #else
 char   t_structs_c (tstruct) struct struct1 tstruct; { return (tstruct.c); }
 short  t_structs_s (tstruct) struct struct1 tstruct; { return (tstruct.s); }
@@ -196,6 +232,11 @@ char  *t_structs_a (tstruct) struct struct1 tstruct;
   strcpy (buf, tstruct.a);
   return buf;
 }
+#ifdef TEST_COMPLEX
+float _Complex t_structs_fc (tstruct) struct struct1 tstruct; { return tstruct.fc;}
+double _Complex t_structs_dc (tstruct) struct struct1 tstruct; { return tstruct.dc;}
+long double _Complex t_structs_ldc (tstruct) struct struct1 tstruct; { return tstruct.ldc;}
+#endif
 #endif
 
 /* Test that calling functions works if there are a lot of arguments.  */
@@ -400,6 +441,114 @@ t_double_many_args (double f1, double f2, double f3, double f4, double f5,
 	  && (sum_args - sum_values) > -DELTA);
 }
 
+/* Various functions for _Complex types.  */
+
+#ifdef TEST_COMPLEX
+
+#define COMPARE_WITHIN_RANGE(ARG1, ARG2, DEL, FUNC) \
+  ((FUNC(ARG1) - FUNC(ARG2)) < DEL) && ((FUNC(ARG1) - FUNC(ARG2) > -DEL))
+
+#define DEF_FUNC_MANY_ARGS_1(TYPE, NAME)			\
+t_##NAME##_complex_many_args (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, \
+			      f12, f13, f14, f15, f16)			\
+     TYPE _Complex f1, TYPE _Complex f2, TYPE _Complex f3, \
+     TYPE _Complex f4, TYPE _Complex f5, TYPE _Complex f6, \
+     TYPE _Complex f7, TYPE _Complex f8, TYPE _Complex f9, \
+     TYPE _Complex f10, TYPE _Complex f11, TYPE _Complex f12, \
+     TYPE _Complex f13, TYPE _Complex f14, TYPE _Complex f15, \
+     TYPE _Complex f16;
+
+#define DEF_FUNC_MANY_ARGS_2(TYPE, NAME)		  \
+t_##NAME##_complex_many_args (TYPE _Complex f1, TYPE _Complex f2, \
+			      TYPE _Complex f3, TYPE _Complex f4, \
+			      TYPE _Complex f5, TYPE _Complex f6, \
+			      TYPE _Complex f7, TYPE _Complex f8, \
+			      TYPE _Complex f9, TYPE _Complex f10,	\
+			      TYPE _Complex f11, TYPE _Complex f12,	\
+			      TYPE _Complex f13, TYPE _Complex f14,	\
+			      TYPE _Complex f15, TYPE _Complex f16)
+
+#define DEF_FUNC_MANY_ARGS_3(TYPE, CREAL, CIMAG) \
+{ \
+   TYPE _Complex expected = fc1 + fc2 + fc3 + fc4 + fc1 + fc2 + fc3 + fc4 \
+    + fc1 + fc2 + fc3 + fc4 + fc1 + fc2 + fc3 + fc4; \
+  TYPE _Complex actual = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 \
+    + f11 + f12 + f13 + f14 + f15 + f16; \
+  return (COMPARE_WITHIN_RANGE(expected, actual, DELTA, creal) \
+	  && COMPARE_WITHIN_RANGE(expected, actual, DELTA, creal) \
+	  && COMPARE_WITHIN_RANGE(expected, actual, DELTA, cimag)   \
+	  && COMPARE_WITHIN_RANGE(expected, actual, DELTA, cimag)); \
+}
+
+int
+#ifdef NO_PROTOTYPES
+DEF_FUNC_MANY_ARGS_1(float, float)
+#else
+DEF_FUNC_MANY_ARGS_2(float, float)
+#endif
+DEF_FUNC_MANY_ARGS_3(float, crealf, cimagf)
+
+int
+#ifdef NO_PROTOTYPES
+DEF_FUNC_MANY_ARGS_1(double, double)
+#else
+DEF_FUNC_MANY_ARGS_2(double, double)
+#endif
+DEF_FUNC_MANY_ARGS_3(double, creal, cimag)
+
+int
+#ifdef NO_PROTOTYPES
+DEF_FUNC_MANY_ARGS_1(long double, long_double)
+#else
+DEF_FUNC_MANY_ARGS_2(long double, long_double)
+#endif
+DEF_FUNC_MANY_ARGS_3(long double, creall, cimagl)
+
+
+
+
+#define DEF_FUNC_VALUES_1(TYPE, NAME)			\
+  t_##NAME##_complex_values (f1, f2) TYPE _Complex f1, TYPE _Complex f2;
+
+#define DEF_FUNC_VALUES_2(TYPE, NAME) \
+  t_##NAME##_complex_values (TYPE _Complex f1, TYPE _Complex f2)
+
+#define DEF_FUNC_VALUES_3(FORMAL_PARM, TYPE, CREAL, CIMAG)	\
+{ \
+ return (COMPARE_WITHIN_RANGE(f1, FORMAL_PARM##1, DELTA, CREAL) \
+	  && COMPARE_WITHIN_RANGE(f2, FORMAL_PARM##2, DELTA, CREAL) \
+	  && COMPARE_WITHIN_RANGE(f1,  FORMAL_PARM##1, DELTA, CIMAG) \
+	  && COMPARE_WITHIN_RANGE(f2,  FORMAL_PARM##2, DELTA, CIMAG)); \
+}
+
+
+int
+#ifdef NO_PROTOTYPES
+DEF_FUNC_VALUES_1(float, float)
+#else
+DEF_FUNC_VALUES_2(float, float)
+#endif
+DEF_FUNC_VALUES_3(fc, float, crealf, cimagf)
+
+int
+#ifdef NO_PROTOTYPES
+DEF_FUNC_VALUES_1(double, double)
+#else
+DEF_FUNC_VALUES_2(double, double)
+#endif
+DEF_FUNC_VALUES_3(fc, double, creal, cimag)
+
+int
+#ifdef NO_PROTOTYPES
+DEF_FUNC_VALUES_1(long double, long_double)
+#else
+DEF_FUNC_VALUES_2(long double, long_double)
+#endif
+DEF_FUNC_VALUES_3(fc, long double, creall, cimagl)
+
+#endif /* TEST_COMPLEX */
+
+
 #ifdef PROTOTYPES
 int t_string_values (char *string_arg1, char *string_arg2)
 #else
diff --git a/gdb/testsuite/gdb.base/callfuncs.exp b/gdb/testsuite/gdb.base/callfuncs.exp
index ff86eb8..7bff47c 100644
--- a/gdb/testsuite/gdb.base/callfuncs.exp
+++ b/gdb/testsuite/gdb.base/callfuncs.exp
@@ -25,7 +25,12 @@ set testfile "callfuncs"
 set srcfile ${testfile}.c
 set binfile ${objdir}/${subdir}/${testfile}
 
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+set compile_flags {debug}
+if [support_complex_tests] {
+    set compile_flags "$compile_flags additional_flags=-DTEST_COMPLEX"
+}
+
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $compile_flags] != "" } {
      untested callfuncs.exp
      return -1
 }
@@ -144,6 +149,23 @@ proc do_function_calls {} {
 	gdb_test "p t_int_double(99, 99.0)" " = 1"
     }
 
+    if [support_complex_tests] {
+	gdb_test "p t_float_complex_values(fc1, fc2)" " = 1"
+	gdb_test "p t_float_complex_values(fc3, fc4)" " = 0"
+	gdb_test "p t_float_complex_many_args(fc1, fc2, fc3, fc4, fc1, fc2, fc3, fc4, fc1, fc2, fc3, fc4, fc1, fc2, fc3, fc4)" " = 1"
+	gdb_test "p t_float_complex_many_args(fc1, fc1, fc1, fc1, fc1, fc1, fc1, fc1, fc1, fc1, fc1, fc1, fc1, fc1, fc1, fc1)" " = 0"
+
+	gdb_test "p t_double_complex_values(dc1, dc2)" " = 1"
+	gdb_test "p t_double_complex_values(dc3, dc4)" " = 0"
+	gdb_test "p t_double_complex_many_args(dc1, dc2, dc3, dc4, dc1, dc2, dc3, dc4, dc1, dc2, dc3, dc4, dc1, dc2, dc3, dc4)" " = 1"
+	gdb_test "p t_double_complex_many_args(dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1, dc1)" " = 0"
+
+	gdb_test "p t_long_double_complex_values(ldc1, ldc2)" " = 1"
+	gdb_test "p t_long_double_complex_values(ldc3, ldc4)" " = 0"
+	gdb_test "p t_long_double_complex_many_args(ldc1, ldc2, ldc3, ldc4, ldc1, ldc2, ldc3, ldc4, ldc1, ldc2, ldc3, ldc4, ldc1, ldc2, ldc3, ldc4)" " = 1"
+	gdb_test "p t_long_double_complex_many_args(ldc1, ldc1, ldc1, ldc1, ldc1, ldc1, ldc1,ldc1, ldc1, ldc1, ldc1, ldc1, ldc1, ldc1, ldc1, ldc1)" " = 0"
+    }
+
     gdb_test "p t_string_values(string_val2,string_val1)" " = 0"
     gdb_test "p t_string_values(string_val1,string_val2)" " = 1"
     gdb_test "p t_string_values(\"string 1\",\"string 2\")" " = 1"
@@ -217,6 +239,37 @@ proc do_function_calls {} {
 	    "call inferior func with struct - returns double"
     }
 
+    if [support_complex_tests] {
+
+	gdb_test_multiple "p t_structs_fc(struct_val1)" \
+	    "call inferior func with struct - returns float _Complex" {
+		-re ".*= 3 \\+ 3 \\* I.*$gdb_prompt $" {
+		    pass "call inferior func with struct - returns float _Complex"
+		}
+		-r ".*$gdb_prompt $" {
+		    kfail gdb/12783 "call inferior func with struct - returns float _Complex"
+		}
+	    }
+	gdb_test_multiple "p t_structs_dc(struct_val1)" \
+	    "call inferior func with struct - returns double _Complex" {
+		-re  ".*= 4 \\+ 4 \\* I.*$gdb_prompt $" {
+		    pass "call inferior func with struct - returns double _Complex"
+		}
+		-re ".*$gdb_prompt $" {
+		    kfail gdb/12783 "call inferior func with struct - returns double _Complex"
+		}
+	    }
+	gdb_test_multiple "p t_structs_ldc(struct_val1)" \
+	    "call inferior func with struct - returns long double _Complex" {
+		-re  "= 5 \\+ 5 \\* I.*$gdb_prompt $" {
+		    pass "call inferior func with struct - returns long double _Complex"
+		}
+		-re ".*$gdb_prompt $" {
+		    kfail gdb/12783 "call inferior func with struct - returns long double _Complex"
+		}
+	    }
+    }
+
     gdb_test "p t_structs_a(struct_val1)" "= (.unsigned char .. )?\"foo\"" \
     	"call inferior func with struct - returns char *"
 }
-- 
1.7.0.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]