From 5e55d6a53dcedf00bf23d18e88ef08cf15aacf36 Mon Sep 17 00:00:00 2001 From: Wen HU Date: Tue, 2 Mar 2021 15:33:59 -0500 Subject: [PATCH 1/2] add C sanity tests --- Makefile | 7 +- test/Makefile | 41 +++++++ test/Makefile.in | 18 +++ test/c_demo/Makefile | 18 +++ test/c_demo/README.md | 2 +- test/c_test/Makefile | 21 ++++ test/c_test/sanity/Makefile | 25 ++++ test/c_test/sanity/addr.c | 54 +++++++++ test/c_test/sanity/argc.c | 26 ++++ test/c_test/sanity/array_single.c | 86 ++++++++++++++ test/c_test/sanity/binop.c | 73 ++++++++++++ test/c_test/sanity/cand.c | 35 ++++++ test/c_test/sanity/goto.c | 35 ++++++ test/c_test/sanity/hello.c | 27 +++++ test/c_test/sanity/if_call_return.c | 44 +++++++ test/c_test/sanity/if_else.c | 28 +++++ test/c_test/sanity/if_else_fp.c | 108 +++++++++++++++++ test/c_test/sanity/ind_call.c | 31 +++++ test/c_test/sanity/large_stack.c | 43 +++++++ test/c_test/sanity/memexpr.c | 40 +++++++ test/c_test/sanity/select.c | 28 +++++ test/c_test/sanity/select_fp.c | 29 +++++ test/c_test/sanity/set.c | 112 ++++++++++++++++++ test/c_test/sanity/struct_bits.c | 85 +++++++++++++ test/c_test/sanity/sum.c | 31 +++++ test/c_test/sanity/sum_array.c | 43 +++++++ test/c_test/sanity/vararg2.c | 36 ++++++ .../maple_aarch64_with_whirl2mpl.sh | 26 ++-- 28 files changed, 1140 insertions(+), 12 deletions(-) create mode 100644 test/Makefile create mode 100644 test/Makefile.in create mode 100644 test/c_demo/Makefile create mode 100644 test/c_test/Makefile create mode 100644 test/c_test/sanity/Makefile create mode 100644 test/c_test/sanity/addr.c create mode 100644 test/c_test/sanity/argc.c create mode 100644 test/c_test/sanity/array_single.c create mode 100644 test/c_test/sanity/binop.c create mode 100644 test/c_test/sanity/cand.c create mode 100644 test/c_test/sanity/goto.c create mode 100644 test/c_test/sanity/hello.c create mode 100644 test/c_test/sanity/if_call_return.c create mode 100644 test/c_test/sanity/if_else.c create mode 100644 test/c_test/sanity/if_else_fp.c create mode 100644 test/c_test/sanity/ind_call.c create mode 100644 test/c_test/sanity/large_stack.c create mode 100644 test/c_test/sanity/memexpr.c create mode 100644 test/c_test/sanity/select.c create mode 100644 test/c_test/sanity/select_fp.c create mode 100644 test/c_test/sanity/set.c create mode 100644 test/c_test/sanity/struct_bits.c create mode 100644 test/c_test/sanity/sum.c create mode 100644 test/c_test/sanity/sum_array.c create mode 100644 test/c_test/sanity/vararg2.c rename test/{c_demo => }/maple_aarch64_with_whirl2mpl.sh (89%) diff --git a/Makefile b/Makefile index 6d2dbaca70..934794bea2 100644 --- a/Makefile +++ b/Makefile @@ -118,6 +118,10 @@ endif setup: (cd tools; ./setup_tools.sh) +.PHONY: demo +demo: + test/maple_aarch64_with_whirl2mpl.sh test/c_demo printHuawei 1 + .PHONY: test1 test1: libcore python3 test/main.py test/testsuite/ouroboros/string_test/RT0001-rt-string-ReflectString/ReflectString.java --test_cfg=test/testsuite/ouroboros/test.cfg --verbose --debug @@ -131,7 +135,8 @@ test_ourboros: libcore python3 test/main.py test/testsuite/ouroboros --test_cfg=test/testsuite/ouroboros/test.cfg --timeout=180 -j20 --retry 1 --fail_exit -pFAIL .PHONY: testall -testall: test_irbuild test_ourboros +testall: + $(MAKE) -C test all .PHONY: cleanrsd cleanrsd:uninstall_patch diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000000..1c9b70cfce --- /dev/null +++ b/test/Makefile @@ -0,0 +1,41 @@ +# +# Copyright (c) [2021] Futurewei Technologies, Inc. All rights reverved. +# +# OpenArkCompiler is licensed under Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# +# http://license.coscl.org.cn/MulanPSL2 +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +# FIT FOR A PARTICULAR PURPOSE. +# See the Mulan PSL v2 for more details. +# + +.PHONY: demo +demo: + make -C c_demo + +.PHONY: all +all: test_irbuild test_ourboros c_test + +.PHONY: test1 +test1: + python3 main.py testsuite/ouroboros/string_test/RT0001-rt-string-ReflectString/ReflectString.java --test_cfg=testsuite/ouroboros/test.cfg --verbose --debug + +.PHONY: test_irbuild +test_irbuild: + python3 main.py testsuite/irbuild_test --test_cfg=testsuite/irbuild_test/test.cfg -j20 -pFAIL + +.PHONY: test_ourboros +test_ourboros: + python3 main.py testsuite/ouroboros --test_cfg=testsuite/ouroboros/test.cfg --timeout=180 -j20 --retry 1 --fail_exit -pFAIL + +.PHONY: c_test +c_test: + make -C c_test + +.PHONY: clean +clean: + @rm -rf $(MAPLE_BUILD_OUTPUT)/test diff --git a/test/Makefile.in b/test/Makefile.in new file mode 100644 index 0000000000..1f22c94ae6 --- /dev/null +++ b/test/Makefile.in @@ -0,0 +1,18 @@ +# +# Copyright (c) [2021] Futurewei Technologies, Inc. All rights reverved. +# +# OpenArkCompiler is licensed under Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# +# http://license.coscl.org.cn/MulanPSL2 +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +# FIT FOR A PARTICULAR PURPOSE. +# See the Mulan PSL v2 for more details. +# + +CCMD := $(MAPLE_ROOT)/test/maple_aarch64_with_whirl2mpl.sh + +VERBOSE := 0 diff --git a/test/c_demo/Makefile b/test/c_demo/Makefile new file mode 100644 index 0000000000..87b571e70b --- /dev/null +++ b/test/c_demo/Makefile @@ -0,0 +1,18 @@ +# +# Copyright (c) [2021] Futurewei Technologies, Inc. All rights reverved. +# +# OpenArkCompiler is licensed under Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# +# http://license.coscl.org.cn/MulanPSL2 +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +# FIT FOR A PARTICULAR PURPOSE. +# See the Mulan PSL v2 for more details. +# + +.PHONY: default +default: + ../maple_aarch64_with_whirl2mpl.sh . printHuawei 1 diff --git a/test/c_demo/README.md b/test/c_demo/README.md index 5560fb8e65..365db62ed1 100644 --- a/test/c_demo/README.md +++ b/test/c_demo/README.md @@ -27,4 +27,4 @@ Besides maple compiler, included are processes using C front end tools: #### 使用说明 run the following scripts for details - ./maple_aarch64_with_whirl2mpl.sh + ../maple_aarch64_with_whirl2mpl.sh . printHuawei 1 diff --git a/test/c_test/Makefile b/test/c_test/Makefile new file mode 100644 index 0000000000..2674a3c4d9 --- /dev/null +++ b/test/c_test/Makefile @@ -0,0 +1,21 @@ +# +# Copyright (c) [2021] Futurewei Technologies, Inc. All rights reverved. +# +# OpenArkCompiler is licensed under Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# +# http://license.coscl.org.cn/MulanPSL2 +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +# FIT FOR A PARTICULAR PURPOSE. +# See the Mulan PSL v2 for more details. +# + +.PHONY: all +all: sanity + +.PHONY: sanity +sanity: + make -C sanity diff --git a/test/c_test/sanity/Makefile b/test/c_test/sanity/Makefile new file mode 100644 index 0000000000..9ee951c36d --- /dev/null +++ b/test/c_test/sanity/Makefile @@ -0,0 +1,25 @@ +# +# Copyright (c) [2021] Futurewei Technologies, Inc. All rights reverved. +# +# OpenArkCompiler is licensed under Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# +# http://license.coscl.org.cn/MulanPSL2 +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +# FIT FOR A PARTICULAR PURPOSE. +# See the Mulan PSL v2 for more details. +# + +include $(MAPLE_ROOT)/test/Makefile.in + +CASES=$(basename $(wildcard *.c)) + +.PHONY: all +all: $(CASES) + +% : %.c + $(CCMD) . $@ $(VERBOSE) + diff --git a/test/c_test/sanity/addr.c b/test/c_test/sanity/addr.c new file mode 100644 index 0000000000..1e0281a16f --- /dev/null +++ b/test/c_test/sanity/addr.c @@ -0,0 +1,54 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int deref(int *iptr) { + return *iptr; +} + +int deref1(int *iptr) { + int j = 8; + j = *iptr + j; + return j; +} + +int addrof(int *iptr) { + int j = 8; + int *jptr = &j; + *jptr = *iptr; + return *jptr; +} + +int main() +{ + int v = 5; + int *vptr = &v; + + if (*vptr != 5) { + abort(); + } + if (deref(&v) != 5) { + abort(); + } + if (deref1(&v) != 13) { + abort(); + } + if (addrof(&v) != 5) { + abort(); + } +} + diff --git a/test/c_test/sanity/argc.c b/test/c_test/sanity/argc.c new file mode 100644 index 0000000000..2358a1da29 --- /dev/null +++ b/test/c_test/sanity/argc.c @@ -0,0 +1,26 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int main(int argc, char *argv[]) +{ + int i = 1; + if (i > argc) { + abort(); + } + return 0; +} diff --git a/test/c_test/sanity/array_single.c b/test/c_test/sanity/array_single.c new file mode 100644 index 0000000000..22c881cdde --- /dev/null +++ b/test/c_test/sanity/array_single.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int A[5]; +int foo(int i) { + A[3] = i + A[2]; + return A[(i >= 0 && i < 5) ? i : 0]; +} + +float B[15]; +float bar(int i) { + B[3] = i + B[2]; + return B[(i >= 0 && i < 5) ? i : 0]; +} + +// variable array type +void vararr(int sz) { + int my[sz]; + int i; + for (i = 0; i < sz; ++i) { + my[i] = i; + } + for (i = 0; i < sz; ++i) { + if (my[i] != i) { + abort(); + } + } +} + +int main() +{ + vararr(4); + + A[0] = 0; + A[2] = A[3] = 2; + if (A[3] != 2) { + abort(); + } + if (foo(2) != 2) { + abort(); + } + if (A[3] != 4) { + abort(); + } + if (foo(5) != 0) { + abort(); + } + if (A[3] != 7) { + abort(); + } + + B[0] = 0; + B[1] = B[2] = B[3] = 3; + if (B[3] != 3) { + abort(); + } + if (bar(1) != 3) { + abort(); + } + if (B[3] != 4) { + abort(); + } + if (bar(5) != 0) { + abort(); + } + if (B[3] != 8) { + abort(); + } + + return 0; +} diff --git a/test/c_test/sanity/binop.c b/test/c_test/sanity/binop.c new file mode 100644 index 0000000000..733be02b68 --- /dev/null +++ b/test/c_test/sanity/binop.c @@ -0,0 +1,73 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int a = 0x80000001; +unsigned int ua = 0x00000002; +unsigned int val = 0xffffff84; + +int main() +{ + int c = a; + + c += a | 0; + c += a & 1; + c += a ^ 0; + c += a >> 0; + c += a << 0; + + c += a | 1; + c += a & 5; + c += a ^ 1; + c += a >> 1; + c += a << 1; + + c += a | 0x7ff; + c += a & 0x7ff; + c += a ^ 0x7ff; + c += a >> 16; + c += a << 16; + + c += a | 0xfff; + c += a & 0xfff; + c += a ^ 0xfff; + c += a >> 24; + c += a << 24; + + c += a | 0xffff; + c += a & 0xffff; + c += a ^ 0xffff; + c += a >> 31; + c += a << 31; + + unsigned int u = ua; + u += ua >> 0; + u += ua >> 1; + u += ua >> 16; + u += a >> 24; + u += a >> 31; + + if (c != 0xc102af83) { + abort(); + } + if (u != 0xffffff84) { + abort(); + } + if (u != val) { + abort(); + } +} diff --git a/test/c_test/sanity/cand.c b/test/c_test/sanity/cand.c new file mode 100644 index 0000000000..fa71bffcbb --- /dev/null +++ b/test/c_test/sanity/cand.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int i = 2; +int main() { + int v = (((i > 0) && (i < 3)) ? 1 : 2); + if ( v != 1 ) { + abort(); + } + + v = (((i > 0) && (i < 2)) ? 1 : 2); + if ( v != 2 ) { + abort(); + } + + v = (((i > 2) && (i < 3)) ? 1 : 2); + if ( v != 2 ) { + abort(); + } +} diff --git a/test/c_test/sanity/goto.c b/test/c_test/sanity/goto.c new file mode 100644 index 0000000000..a0bad57bf4 --- /dev/null +++ b/test/c_test/sanity/goto.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int g = 5; + +int main() { + for (int i = 0; i < 10; i++) { + if (i == 1) { + goto label; + } + g = i; // 0 + } + abort(); + +label: + if (g != 0) { + abort(); + } + return 0; +} diff --git a/test/c_test/sanity/hello.c b/test/c_test/sanity/hello.c new file mode 100644 index 0000000000..8b6d7b83d5 --- /dev/null +++ b/test/c_test/sanity/hello.c @@ -0,0 +1,27 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int main() { + char str[32]; + int v = sprintf(str,"hello world\n"); + + if (v != 12) { + abort(); + } + return 0; +} diff --git a/test/c_test/sanity/if_call_return.c b/test/c_test/sanity/if_call_return.c new file mode 100644 index 0000000000..e55533bd1f --- /dev/null +++ b/test/c_test/sanity/if_call_return.c @@ -0,0 +1,44 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int i = 1; +float f = 2.2; +long long ll = 3; +double d = 4.4; + +int fi(){ return i; } +float ff(){ return f; } +long long fll(){ return ll; } +double fd(){ return d; } + +int main() { + if (fi() != 1) { + abort(); + } + if (ff() != (float)2.2) { + abort(); + } + if (fll() != 3) { + abort(); + } + if (fd() != 4.4) { + abort(); + } + return 0; +} + diff --git a/test/c_test/sanity/if_else.c b/test/c_test/sanity/if_else.c new file mode 100644 index 0000000000..63d19c2a83 --- /dev/null +++ b/test/c_test/sanity/if_else.c @@ -0,0 +1,28 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int main() { + int i = 1; + + if (i > 1) { + abort(); + } else { + printf(""); + } + return 0; +} diff --git a/test/c_test/sanity/if_else_fp.c b/test/c_test/sanity/if_else_fp.c new file mode 100644 index 0000000000..65d0609a14 --- /dev/null +++ b/test/c_test/sanity/if_else_fp.c @@ -0,0 +1,108 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int main() { + double d1 = 10; + double d2 = 20; + int i = 0; + + if (d1 <= d2) { + i++; + } else { + abort(); + } + + if (d2 >= d1) { + i++; + } else { + abort(); + } + + if (d2 > d1) { + i++; + } else { + abort(); + } + + if (d1 < d2 && d2 > d1) { + i++; + } else { + abort(); + } + + if (d1 != d2) { + i++; + } else { + abort(); + } + + d1 = 20; + if (d1 <= d2) { + if (d1 == d2) { + i++; + } else { + abort(); + } + } + + float f1 = 10; + float f2 = 20; + + if (f1 <= f2) { + i++; + } else { + abort(); + } + + if (f2 >= f1) { + i++; + } else { + abort(); + } + + if (f2 > f1) { + i++; + } else { + abort(); + } + + if (f1 < f2 && f2 > f1) { + i++; + } else { + abort(); + } + + if (f1 != f2) { + i++; + } else { + abort(); + } + + f1 = 20; + if (f1 <= f2) { + if (f1 == f2) { + i++; + } else { + abort(); + } + } + + if (i != 12) { + abort(); + } +} diff --git a/test/c_test/sanity/ind_call.c b/test/c_test/sanity/ind_call.c new file mode 100644 index 0000000000..6cfda4c04c --- /dev/null +++ b/test/c_test/sanity/ind_call.c @@ -0,0 +1,31 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int x = 1; + +int foo(){return x;} + +int main() { + int (*fptr)() = foo; + int v = fptr(); + + if (v != 1) { + abort(); + } + return 0; +} diff --git a/test/c_test/sanity/large_stack.c b/test/c_test/sanity/large_stack.c new file mode 100644 index 0000000000..41bc2c2449 --- /dev/null +++ b/test/c_test/sanity/large_stack.c @@ -0,0 +1,43 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +#define asize 500 +int sum = 0; +void vararr(int sz) { + int my[sz]; + volatile int a[asize], b[asize], c[asize]; + + for (int i = 0; i< asize; i++) { + a[i] = i; b[i] = i + 1; c[i] = i + 2; + sum = a[i] + b[i] * c[i]; + if (i < sz) { + my[i] = sum; + } + } + + if ((my[0] != 2) || + (my[1] != 7) || + (my[2] != 14) || + (my[3] != 23)) { + abort(); + } +} + +int main() { + vararr(4); +} diff --git a/test/c_test/sanity/memexpr.c b/test/c_test/sanity/memexpr.c new file mode 100644 index 0000000000..5417248d6a --- /dev/null +++ b/test/c_test/sanity/memexpr.c @@ -0,0 +1,40 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int main() { + struct PSas { + short a, b; + int *p; + }(*PSas0), (*PSas1); + + struct PSas pSas0, pSas1, pSasa[10]; + + int i = 5; + PSas0 = &pSas0; + PSas1 = &pSas1; + + pSasa[8].a = 2; + (*PSas0).a = 3; + (*PSas1).p = &i; + + if (pSasa[8].a != 2 || (*PSas0).a != 3 || *((*PSas1).p) != 5) { + abort(); + } + + return 0; +} diff --git a/test/c_test/sanity/select.c b/test/c_test/sanity/select.c new file mode 100644 index 0000000000..dfe621fe53 --- /dev/null +++ b/test/c_test/sanity/select.c @@ -0,0 +1,28 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int main(int argc, char *argv[]) +{ + int i = (argc != 1) ? ((argc != 2) ? ((argc != 3) ? 6 : 7) : 5) : ((argc == 4) ? 8 : 9); + + if (i != 9) { + abort(); + } + + return 0; +} diff --git a/test/c_test/sanity/select_fp.c b/test/c_test/sanity/select_fp.c new file mode 100644 index 0000000000..6c3019a975 --- /dev/null +++ b/test/c_test/sanity/select_fp.c @@ -0,0 +1,29 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int main(int argc, char *argv[]) +{ + float f = 2000; + int i = (argc == 1) ? ((f != 200) ? ((f == 2000) ? 6 : 7) : 5) : ((argc == 4) ? 8 : 9); + + if (i != 6) { + abort(); + } + + return 0; +} diff --git a/test/c_test/sanity/set.c b/test/c_test/sanity/set.c new file mode 100644 index 0000000000..3eaca49ef8 --- /dev/null +++ b/test/c_test/sanity/set.c @@ -0,0 +1,112 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include + +void foo1(int x) { // x = (0, 1, -1, 1, 0, 0) + int a1 = x++ == 0; + int a2 = x-- != 0; + int a3 = --x < 0; + int a4 = x+2 > 0; + int a5 = ++x <= 0; + int a6 = x >= 0; + if (a1+a2+a3+a4+a5+a6 != 6) { + abort(); + } +} + +void foo2(int x) { // x = (1, 2, 0, 2, 1, 1) + int a1 = x == 1; + int a2 = ++x != 1; + int a3 = x-2 < 1; + int a4 = x > 1; + int a5 = --x <= 1; + int a6 = x >= 1; + if (a1+a2+a3+a4+a5+a6 != 6) { + abort(); + } +} + +void foo3(int x, int y) { // x&y = (1==1, 1!=2, 0<2, 0>-1, 0<=0, 0>=0) + int a1 = x == y; + int a2 = x != ++y; + int a3 = --x < y--; + int a4 = x > y-2; + int a5 = x <= --y; + int a6 = x >= --y; + if (a1+a2+a3+a4+a5+a6 != 6) { + abort(); + } +} + +void foo4(unsigned x) { // x = (0, 1, 0xf-f, 1, 0, 0) + unsigned a1 = x++ == 0; + unsigned a2 = x-- != 0; + unsigned a3 = (--x < 0) + 1; + unsigned a4 = x+2 > 0; + unsigned a5 = ++x <= 0; + unsigned a6 = x >= 0; + if (a1+a2+a3+a4+a5+a6 != 6) { + abort(); + } +} + +void foo5(unsigned x) { // x = (1, 2, 0, 0xf-f, 1, 1) + unsigned a1 = x == 1; + unsigned a2 = ++x != 1; + unsigned a3 = x-2 < 1; + unsigned a4 = x-3 > 1; + unsigned a5 = --x <= 1; + unsigned a6 = x >= 1; + if (a1+a2+a3+a4+a5+a6 != 6) { + abort(); + } +} + +void foo6(unsigned x, unsigned y) { // x&y = (1==1, 1!=2, 0<2, 0xf-f>1, 0<=0, 0>=0, + // 0xf-f>=0) + unsigned a1 = x == y; + unsigned a2 = x != ++y; + unsigned a3 = --x < y--; + unsigned a4 = --x > y; + unsigned a5 = ++x <= --y; + unsigned a6 = x >= y; + unsigned a7 = --x >= y; + if (a1+a2+a3+a4+a5+a6+a7 != 7) { + abort(); + } +} + +void foo7(unsigned x) { // x = (4096, 4097, 4094, 4097, 4096, 4096) + unsigned a1 = x == 4096; + unsigned a2 = ++x != 4096; + unsigned a3 = x-3 < 4095; + unsigned a4 = x > 4096; + unsigned a5 = --x <= 4096; + unsigned a6 = x >= 4096; + if (a1+a2+a3+a4+a5+a6 != 6) { + abort(); + } +} + +int main() { + foo1(0); + foo2(1); + foo3(1, 1); + foo4(0); + foo5(1); + foo6(1, 1); + foo7(4096); +} diff --git a/test/c_test/sanity/struct_bits.c b/test/c_test/sanity/struct_bits.c new file mode 100644 index 0000000000..7deea9e24a --- /dev/null +++ b/test/c_test/sanity/struct_bits.c @@ -0,0 +1,85 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +typedef struct x { + long x; + unsigned int z1:3; + unsigned int z2:12; + int z3:2; + int z4:10; + int z5:5; + int y; + char z[32]; +} x; + +typedef struct y { + long x; + long long x1 : 5; + long long x2 : 16; + unsigned long long x3 : 33; + long long x4 : 10; + int y; +} y; + +void foo() { + x xxx; + xxx.x = 1; + xxx.y = 2; + xxx.z1 = 0x7; + xxx.z2 = 0x800; + xxx.z3 = 0x3; + xxx.z4 = 0x201; + xxx.z5 = 0x11; + xxx.z[0] = 4; + xxx.z[31] = 6; + xxx.z[1] = 5; + + if (xxx.z1 != 7) { + abort(); + } + if (xxx.z2 != 0x800) { + abort(); + } + if (xxx.z3 != -1) { + abort(); + } + if (xxx.z4 != -511) { + abort(); + } + if (xxx.z5 != -15) { + abort(); + } +} + +void bar() { + y yyy; + + yyy.x = 3; + yyy.y = 4; + yyy.x1 = 7; + yyy.x2 = 0xff; + yyy.x3 = 0x800f0008; + yyy.x4 = 0x15; +} + +int main() { + foo(); + bar(); + return 0; +} + diff --git a/test/c_test/sanity/sum.c b/test/c_test/sanity/sum.c new file mode 100644 index 0000000000..d49699cfd2 --- /dev/null +++ b/test/c_test/sanity/sum.c @@ -0,0 +1,31 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +int main(int argc, char *argv[]) { + int sum = 0; + + for (int i = 0; i < 10; i++) { + sum += i; + } + + if (sum != 45) { + abort(); + } + + return 0; +} diff --git a/test/c_test/sanity/sum_array.c b/test/c_test/sanity/sum_array.c new file mode 100644 index 0000000000..714090b691 --- /dev/null +++ b/test/c_test/sanity/sum_array.c @@ -0,0 +1,43 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include +#include + +//int main(int argc, char *argv[]) +int main() +{ + int a[10], b[10], c[10], i; + + for (i = 0; i < 10; i++) { + b[i] = i << 2; + c[i] = i << b[i]; + } + + for (i = 0; i < 10; i++) { + a[i] = b[i] + c[9-i]; + } + + int sum = 0; + for (i = 0; i < 10; i++) { + sum += a[i]; + } + + if (sum != 1985229660) { + abort(); + } + + return 0; +} diff --git a/test/c_test/sanity/vararg2.c b/test/c_test/sanity/vararg2.c new file mode 100644 index 0000000000..eb0fcd53dd --- /dev/null +++ b/test/c_test/sanity/vararg2.c @@ -0,0 +1,36 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include + +static double f (float a, ...); +static double (*fp) (float a, ...); + +main () { + fp = f; + if (fp ((float) 1, (double)2) != 3.0) { + abort (); + } + exit (0); +} + +static double +f (float a, ...) { + va_list ap; + + va_start(ap, a); + float i = va_arg(ap, double); + return (double)a + i; +} diff --git a/test/c_demo/maple_aarch64_with_whirl2mpl.sh b/test/maple_aarch64_with_whirl2mpl.sh similarity index 89% rename from test/c_demo/maple_aarch64_with_whirl2mpl.sh rename to test/maple_aarch64_with_whirl2mpl.sh index 19ef9620f0..e338bc63bb 100755 --- a/test/c_demo/maple_aarch64_with_whirl2mpl.sh +++ b/test/maple_aarch64_with_whirl2mpl.sh @@ -18,9 +18,20 @@ set -e [ -n "$MAPLE_ROOT" ] || { echo MAPLE_ROOT not set. Please source envsetup.sh.; exit 1; } CURRDIR=`pwd` -WORKDIR=$CURRDIR/aarch64_use_whirl2mpl +rel=`realpath --relative-to=$MAPLE_ROOT $CURRDIR` + +dir=$1 +src=$2 +if [ $# -le 2 ]; then + dump=0 +else + dump=$3 +fi + +WORKDIR=$MAPLE_BUILD_OUTPUT/$rel/$dir/aarch64_with_whirl2mpl mkdir -p $WORKDIR +cp $dir/$src.c $WORKDIR cd $WORKDIR echo ======================================================================== > cmd.log @@ -28,14 +39,6 @@ echo ============= Use clangfe/whirl2mpl as C Frontend ======================= > echo ======================================================================== >> cmd.log echo cd $WORKDIR >> cmd.log -if [ $# -eq 0 ]; then - src=printHuawei -else - src=$1 -fi - -cp $CURRDIR/$src.c . - V=$(cd /usr/lib/gcc-cross/aarch64-linux-gnu/; ls | head -1) FLAGS="-cc1 -emit-llvm -triple aarch64-linux-gnu -D__clang__ -D__BLOCKS__ -isystem /usr/aarch64-linux-gnu/include -isystem /usr/lib/gcc-cross/aarch64-linux-gnu/$V/include" echo $MAPLE_ROOT/tools/open64_prebuilt/x86/aarch64/bin/clangfe $FLAGS $src.c >> cmd.log @@ -53,7 +56,10 @@ echo /usr/bin/aarch64-linux-gnu-gcc-$V -o $src.out $src.s >> cmd.log echo qemu-aarch64 -L /usr/aarch64-linux-gnu/ $src.out >> cmd.log qemu-aarch64 -L /usr/aarch64-linux-gnu/ $src.out > output.log -if [ $# -eq 0 ]; then +cat cmd.log >> allcmd.log + +if [ $dump -eq 1 ]; then cat cmd.log cat output.log fi + -- Gitee From 46923852eb3d6ce317ffadb0197b50652a717ee2 Mon Sep 17 00:00:00 2001 From: Wen HU Date: Tue, 2 Mar 2021 16:29:10 -0500 Subject: [PATCH 2/2] add c_test target --- test/maple_aarch64_with_whirl2mpl.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/maple_aarch64_with_whirl2mpl.sh b/test/maple_aarch64_with_whirl2mpl.sh index e338bc63bb..b0ab37fb1d 100755 --- a/test/maple_aarch64_with_whirl2mpl.sh +++ b/test/maple_aarch64_with_whirl2mpl.sh @@ -23,9 +23,9 @@ rel=`realpath --relative-to=$MAPLE_ROOT $CURRDIR` dir=$1 src=$2 if [ $# -le 2 ]; then - dump=0 + verbose=0 else - dump=$3 + verbose=$3 fi WORKDIR=$MAPLE_BUILD_OUTPUT/$rel/$dir/aarch64_with_whirl2mpl @@ -58,7 +58,7 @@ qemu-aarch64 -L /usr/aarch64-linux-gnu/ $src.out > output.log cat cmd.log >> allcmd.log -if [ $dump -eq 1 ]; then +if [ $verbose -eq 1 ]; then cat cmd.log cat output.log fi -- Gitee