diff --git a/test/compile_tests.py b/test/compile_tests.py new file mode 100644 index 0000000..6121fe6 --- /dev/null +++ b/test/compile_tests.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python +# coding: utf-8 + +import glob +import os +from os import system +root_tests_dir = '.' + +for test_dir in os.listdir(root_tests_dir): + if os.path.isdir(os.path.join(root_tests_dir, test_dir)): + print(test_dir) + if not os.path.exists("{test_dir}/a".format(test_dir = test_dir)): + os.makedirs("{test_dir}/a".format(test_dir = test_dir)) + + if not os.path.exists("{test_dir}/b".format(test_dir = test_dir)): + os.makedirs("{test_dir}/b".format(test_dir = test_dir)) + + system("g++ -DV1 -o {test_d}/a/program.out -xc++ -g {test_files}".format(test_d = test_dir, test_files = ' '.join(glob.glob(test_dir + '/*.c??')))) + system("g++ -DV2 -o {test_d}/b/program.out -xc++ -g {test_files}".format(test_d = test_dir, test_files = ' '.join(glob.glob(test_dir + '/*.c??')))) \ No newline at end of file diff --git a/test/df_dynamic_vars_address/program.cxx b/test/df_dynamic_vars_address/program.cxx new file mode 100644 index 0000000..3d33341 --- /dev/null +++ b/test/df_dynamic_vars_address/program.cxx @@ -0,0 +1,31 @@ +// g++ -DV1 -o a/program.out -xc++ -g program.cxx +// g++ -DV2 -o b/program.out -xc++ -g program.cxx + +#include + +int f(int arg1, int arg2) { +#if V2 + int i; +#endif + + int var1 = arg1 + 1; + int var2 = arg2 + 2; + +#if V1 + return var1 + var2; +#else + int result; + for (i = 0; i < 5; i++) { + result = var1 + var2; + } + + return result; +#endif + +} + +int main() +{ + std::cout << "Result:" << f(1, 2) << std::endl; + return 0; +} diff --git a/test/dynamic_vars_address/program.cxx b/test/dynamic_vars_address/program.cxx new file mode 100644 index 0000000..ecd099f --- /dev/null +++ b/test/dynamic_vars_address/program.cxx @@ -0,0 +1,22 @@ +// g++ -DV1 -o a/program.out -xc++ -g program.cxx +// g++ -DV2 -o b/program.out -xc++ -g program.cxx + +#include + +int f(int arg1, int arg2) { +#if V1 + int *var1 = new int(1); + int *var2 = new int(2); +#else + int *var2 = new int(2); + int *var1 = new int(1); +#endif + std::cout << "var1_ptr:" << var1 << ", var2_ptr:" << var2 << std::endl; + return *var1 + *var2 + arg1 + arg2; +} + +int main() +{ + std::cout << "Result:" << f(1, 2) << std::endl; + return 0; +} diff --git a/test/local_vars_address/program.cxx b/test/local_vars_address/program.cxx new file mode 100644 index 0000000..b81c4ef --- /dev/null +++ b/test/local_vars_address/program.cxx @@ -0,0 +1,22 @@ +// g++ -DV1 -o a/program.out -xc++ -g program.cxx +// g++ -DV2 -o b/program.out -xc++ -g program.cxx + +#include + +int f(int arg1, int arg2) { +#if V1 + int var1 = 1; + int var2 = 2; +#else + int var2 = 2; + int var1 = 1; +#endif + std::cout << "var1_ptr:" << &var1 << ", var2_ptr:" << &var2 << std::endl; + return var1 + var2 + arg1 + arg2; +} + +int main() +{ + std::cout << "Result:" << f(1, 2) << std::endl; + return 0; +} diff --git a/test/local_vars_switched/program.cxx b/test/local_vars_switched/program.cxx new file mode 100644 index 0000000..c8b8eff --- /dev/null +++ b/test/local_vars_switched/program.cxx @@ -0,0 +1,21 @@ +//g++ -DV1 -o a/program.out -xc++ -g program.cxx +//g++ -DV2 -o b/program.out -xc++ -g program.cxx + +#include + +int a(int arg1, int arg2) { +#if V1 + int a_var1 = 1; + int a_var2 = 2; +#else + int a_var2 = 2; + int a_var1 = 1; +#endif + return a_var1 + a_var2 + arg1 + arg2; +} + +int main() +{ + std::cout << "Result:" << a(1, 2) << std::endl; + return a(1, 2); +} diff --git a/test/pointer_offset/program.cxx b/test/pointer_offset/program.cxx new file mode 100644 index 0000000..a575157 --- /dev/null +++ b/test/pointer_offset/program.cxx @@ -0,0 +1,18 @@ +// g++ -DV1 -o a/program.out -xc++ -g program.cxx +// g++ -DV2 -o b/program.out -xc++ -g program.cxx + +#include + +int a3(int i = 3) { + int * j = new int(2); + int * k = new int(7); + std::cout << "Ptr:" << j << std::endl; + + return 0; +} + + +int main() +{ + return a3(); +} diff --git a/test/pointer_simple_class/program.cxx b/test/pointer_simple_class/program.cxx new file mode 100644 index 0000000..fe22bea --- /dev/null +++ b/test/pointer_simple_class/program.cxx @@ -0,0 +1,41 @@ +// g++ -DV1 -o a/program.out -xc++ -g program.cxx +// g++ -DV2 -o b/program.out -xc++ -g program.cxx + +#include + +class Task { + public: + int id; + Task *next; + Task(int i, Task *n): + id(i), + next(n) + {} + }; + +int a3(int i = 3) { + int * j = new int(2); + int * k = new int(7); + std::cout << "Ptr:" << j << std::endl; + + return 0; +} + + +int main() +{ + Task *task_head = new Task(-1, NULL); + Task *task1 = new Task(1, NULL); + //Task *task2 = new Task(2, NULL); + //Task *task3 = new Task(3, NULL); + //Task *task4 = new Task(4, NULL); + //Task *task5 = new Task(5, NULL); + + task_head->next = task1; + //task1->next = task2; + //task2->next = task3; + //task3->next = task4; + //task4->next = task5; + + return 0; +} diff --git a/test/recursive_factorial/program.cxx b/test/recursive_factorial/program.cxx new file mode 100644 index 0000000..31a7bdc --- /dev/null +++ b/test/recursive_factorial/program.cxx @@ -0,0 +1,21 @@ +// g++ -DV1 -o a/program.out -xc++ -g program.cxx +// g++ -DV2 -o b/program.out -xc++ -g program.cxx + +#include + +int f(int arg1) { + if (arg1 == 0) +#if V1 + return 1; +#else + return 0; +#endif + else + return arg1 * f(arg1 - 1); +} + +int main() +{ + std::cout << "Result:" << f(5) << std::endl; + return 0; +} diff --git a/test/recursive_fib/program.cxx b/test/recursive_fib/program.cxx new file mode 100644 index 0000000..c7219d0 --- /dev/null +++ b/test/recursive_fib/program.cxx @@ -0,0 +1,24 @@ +// g++ -DV1 -o a/program.out -xc++ -g program.cxx +// g++ -DV2 -o b/program.out -xc++ -g program.cxx + +#include + +int fib(int x) { +#if V1 + if (x < 2) { + return x; + } +#else + if (x <= 1) { + return 1; + } +#endif + return (fib(x - 1) + fib(x - 2)); +} + +int main() +{ + for (int i = 0; i <= 5; i++) + std::cout << "Result fib(" << i << "):" << fib(i) << std::endl; + return 0; +} diff --git a/test/recursive_str/program.cxx b/test/recursive_str/program.cxx new file mode 100644 index 0000000..31d82b6 --- /dev/null +++ b/test/recursive_str/program.cxx @@ -0,0 +1,35 @@ +// g++ -DV1 -o a/program.out -xc++ -g program.cxx +// g++ -DV2 -o b/program.out -xc++ -g program.cxx + +#include +#include + +std::string dup(int cnt, std::string x) { +#if V1 + if (cnt <= 0) { + return ""; + } else { + return x + dup(cnt - 1, x); + } +#else + if (cnt <= 0) { + return ""; + } else { + std::string s = dup(cnt/2, x); + return (cnt%1 == 0) ? s + s : s + s + x; // cnt%2 == 0 + } +#endif +} + +int main() +{ + std::cout << "Result(0):" << dup(0, "*") << std::endl; + std::cout << "Result(1):" << dup(1, "*") << std::endl; + std::cout << "Result(2):" << dup(2, "*") << std::endl; + std::cout << "Result(3):" << dup(3, "*") << std::endl; + std::cout << "Result(4):" << dup(4, "*") << std::endl; + std::cout << "Result(5):" << dup(5, "*") << std::endl; + std::cout << "Result(6):" << dup(6, "*") << std::endl; + std::cout << "Result(200):" << dup(200, "*") << std::endl; + return 0; +} diff --git a/test/simple/program.cxx b/test/simple/program.cxx new file mode 100644 index 0000000..cb5189a --- /dev/null +++ b/test/simple/program.cxx @@ -0,0 +1,20 @@ +// g++ -DV1 -o a/program.out -xc++ -g program.cxx +// g++ -DV2 -o b/program.out -xc++ -g program.cxx + +#include + +int f(int arg1, int arg2) { + int var1 = 1; +#if V1 + int var2 = 2; +#else + int var2 = 3; +#endif + return arg1 + arg2 + var1 + var2; +} + +int main() +{ + std::cout << "Result:" << f(1, 2) << std::endl; + return 0; +} diff --git a/test/simple_functions_chain/program.cxx b/test/simple_functions_chain/program.cxx new file mode 100644 index 0000000..f35c537 --- /dev/null +++ b/test/simple_functions_chain/program.cxx @@ -0,0 +1,56 @@ +// g++ -DV1 -o a/program.out -xc++ -g program.cxx +// g++ -DV2 -o b/program.out -xc++ -g program.cxx + +#include + +int c(int arg1, int arg2) { + int c_var1 = 100; + int c_var2; +#if V1 + c_var2 = 2100; +#else + c_var2 = 2000; +#endif + int c_var3 = 300; + int c_var4 = 400; + int c_var5 = 500; + return c_var4 + c_var5; +} + +int b(int arg1, int arg2) { + int b_var1 = 10; + int b_var2; +#if V1 + b_var2 = 210; +#else + b_var2 = 200; +#endif + int b_var3 = 30; + int b_var4 = 40; + int b_var5 = 50; +#if V1 + return c(b_var4, b_var5); +#else + return c(b_var3, b_var4); +#endif +} + +int a(int arg1, int arg2) { + int a_var1 = 1; + int a_var2; +#if V1 + a_var2 = 21; +#else + a_var2 = 20; +#endif + int a_var3 = 3; + int a_var4 = 4; + int a_var5 = 5; + return b(a_var4, a_var5); +} + +int main() +{ + std::cout << "Result:" << a(1, 2) << std::endl; + return 0; +} diff --git a/test/strace_sample/program.cxx b/test/strace_sample/program.cxx new file mode 100644 index 0000000..60cd53a --- /dev/null +++ b/test/strace_sample/program.cxx @@ -0,0 +1,22 @@ +// g++ -DV1 -o a/program.out -xc++ -g program.cxx +// g++ -DV2 -o b/program.out -xc++ -g program.cxx + +#include +#include + +void file_open() +{ + char str[30]; +#if V1 + FILE *fp = fopen("/tmp/strace_sample", "r"); +#else + FILE *fp = fopen("strace_sample", "r"); +#endif + fgets(str, 5, fp); + fclose(fp); +} + +int main() { + file_open(); + return 0; +} diff --git a/test/vectors/program.cxx b/test/vectors/program.cxx new file mode 100644 index 0000000..cc14cd5 --- /dev/null +++ b/test/vectors/program.cxx @@ -0,0 +1,18 @@ +// g++ -DV1 -o a/program.out -xc++ -g program.cxx +// g++ -DV2 -o b/program.out -xc++ -g program.cxx + +static char array[1000][1000]; + +int main (void) +{ + int i, j; + + for (i = 0; i < 1000; i++) + for (j = 0; j < 1000; j++) +#if V1 + array[i][j]++; +#else + array[j][i]++; +#endif + return 0; +} \ No newline at end of file