aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lyon <jamesly0n@hotmail.com>2013-04-18 17:55:00 +0100
committerJames Lyon <jamesly0n@hotmail.com>2013-04-18 17:55:00 +0100
commit3f1d9000071eeebe315795079c3adbe4022d6d19 (patch)
treed4d422fc5eadb6432fa2f7934a63c640a3517858
parent2bbfaf436f937ace4809d84be812ea1ac7fd7352 (diff)
downloadtinycc-3f1d9000071eeebe315795079c3adbe4022d6d19.tar.gz
tinycc-3f1d9000071eeebe315795079c3adbe4022d6d19.tar.bz2
Added some additional tests to abitest.c
This is just to ensure that I haven't (and don't) really mess anything up.
-rw-r--r--tests/abitest.c64
1 files changed, 51 insertions, 13 deletions
diff --git a/tests/abitest.c b/tests/abitest.c
index 90f4cb8..4f966a4 100644
--- a/tests/abitest.c
+++ b/tests/abitest.c
@@ -37,6 +37,46 @@ static int run_callback(const char *src, callback_type callback) {
return result;
}
+#define RET_PRIMITIVE_TEST(name, type) \
+ static int ret_ ## name ## _test_callback(void *ptr) { \
+ type (*callback) (type) = (type(*)(type))ptr; \
+ type x = 29; \
+ type y = callback(x); \
+ return (y == x+x) ? 0 : -1; \
+ } \
+ \
+ static int ret_ ## name ## _test(void) { \
+ const char *src = #type " f(" #type " x) {return x+x;}"; \
+ return run_callback(src, ret_ ## name ## _test_callback); \
+ }
+
+RET_PRIMITIVE_TEST(int, int)
+RET_PRIMITIVE_TEST(longlong, long long)
+RET_PRIMITIVE_TEST(float, float)
+RET_PRIMITIVE_TEST(double, double)
+
+typedef struct ret_2float_test_type_s {float x, y;} ret_2float_test_type;
+typedef ret_2float_test_type (*ret_2float_test_function_type) (ret_2float_test_type);
+
+static int ret_2float_test_callback(void *ptr) {
+ ret_2float_test_function_type f = (ret_2float_test_function_type)ptr;
+ ret_2float_test_type a = {10, 35};
+ ret_2float_test_type r;
+ r = f(a);
+ return ((r.x == a.x*5) && (r.y == a.y*3)) ? 0 : -1;
+}
+
+static int ret_2float_test(void) {
+ const char *src =
+ "typedef struct ret_2float_test_type_s {float x, y;} ret_2float_test_type;"
+ "ret_2float_test_type f(ret_2float_test_type a) {\n"
+ " ret_2float_test_type r = {a.x*5, a.y*3};\n"
+ " return r;\n"
+ "}\n";
+
+ return run_callback(src, ret_2float_test_callback);
+}
+
/*
* reg_pack_test: return a small struct which should be packed into
* registers (Win32) during return.
@@ -67,28 +107,21 @@ static int reg_pack_test(void) {
* sret_test: Create a struct large enough to be returned via sret
* (hidden pointer as first function argument)
*/
-typedef struct sret_test_type_s {
- long long a;
- long long b;
-} sret_test_type;
-
+typedef struct sret_test_type_s {long long a, b, c;} sret_test_type;
typedef sret_test_type (*sret_test_function_type) (sret_test_type);
static int sret_test_callback(void *ptr) {
sret_test_function_type f = (sret_test_function_type)(ptr);
- sret_test_type x = {5436LL, 658277698LL};
+ sret_test_type x = {5436LL, 658277698LL, 43878957LL};
sret_test_type r = f(x);
- return ((r.a==x.a*35)&&(r.b==x.b*19)) ? 0 : -1;
+ return ((r.a==x.a*35)&&(r.b==x.b*19)&&(r.c==x.c*21)) ? 0 : -1;
}
static int sret_test(void) {
const char *src =
- "typedef struct sret_test_type_s {\n"
- " long long a;\n"
- " long long b;\n"
- "} sret_test_type;\n"
+ "typedef struct sret_test_type_s {long long a, b, c;} sret_test_type;\n"
"sret_test_type f(sret_test_type x) {\n"
- " sret_test_type r = {x.a*35, x.b*19};\n"
+ " sret_test_type r = {x.a*35, x.b*19, x.c*21};\n"
" return r;\n"
"}\n";
@@ -112,7 +145,12 @@ int main(int argc, char **argv) {
/* if tcclib.h and libtcc1.a are not installed, where can we find them */
if (argc == 2 && !memcmp(argv[1], "lib_path=",9))
tccdir = argv[1] + 9;
-
+
+ RUN_TEST(ret_int_test);
+ RUN_TEST(ret_longlong_test);
+ RUN_TEST(ret_float_test);
+ RUN_TEST(ret_double_test);
+ RUN_TEST(ret_2float_test);
RUN_TEST(reg_pack_test);
RUN_TEST(sret_test);
return retval;