diff options
author | Vasilis Kalintiris <ehostunreach@gmail.com> | 2013-12-14 16:04:52 +0200 |
---|---|---|
committer | Vasilis Kalintiris <ehostunreach@gmail.com> | 2013-12-15 20:51:29 +0200 |
commit | c05cdf26c872f76dad82194305c28a53e9123677 (patch) | |
tree | b9c48a759b8b2e58c4714e11aa8cd992de8bd0a4 | |
parent | 94e1d887ffebcbf640fbca19c76331f6dffbff23 (diff) |
Fix the indentation of core test input files with clang-format.
180 files changed, 4237 insertions, 4596 deletions
diff --git a/tests/core/test_addr_of_stacked.in b/tests/core/test_addr_of_stacked.in index af5a6e32..7a4d9ba7 100644 --- a/tests/core/test_addr_of_stacked.in +++ b/tests/core/test_addr_of_stacked.in @@ -1,14 +1,8 @@ - - #include <stdio.h> - void alter(int *y) - { - *y += 5; - } - int main() - { - int x = 2; - alter(&x); - printf("*%d*\n", x); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +void alter(int *y) { *y += 5; } +int main() { + int x = 2; + alter(&x); + printf("*%d*\n", x); + return 0; +} diff --git a/tests/core/test_alloca.in b/tests/core/test_alloca.in index 7b53e56c..bfad3324 100644 --- a/tests/core/test_alloca.in +++ b/tests/core/test_alloca.in @@ -1,11 +1,9 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> - - int main() { - char *pc; - pc = (char *)alloca(5); - printf("z:%d*%d*\n", pc > 0, (int)pc); - return 0; - } -
\ No newline at end of file +int main() { + char *pc; + pc = (char *)alloca(5); + printf("z:%d*%d*\n", pc > 0, (int)pc); + return 0; +} diff --git a/tests/core/test_alloca_stack.in b/tests/core/test_alloca_stack.in index ab7c7306..ba3afcc7 100644 --- a/tests/core/test_alloca_stack.in +++ b/tests/core/test_alloca_stack.in @@ -1,19 +1,16 @@ - // We should not blow up the stack with numerous allocas - #include <stdio.h> - #include <stdlib.h> +#include <stdio.h> +#include <stdlib.h> - func(int i) { - char *pc = (char *)alloca(100); - *pc = i; - (*pc)++; - return (*pc) % 10; - } - int main() { - int total = 0; - for (int i = 0; i < 1024*1024; i++) - total += func(i); - printf("ok:%d*\n", total); - return 0; - } - +func(int i) { + char *pc = (char *)alloca(100); + *pc = i; + (*pc)++; + return (*pc) % 10; +} +int main() { + int total = 0; + for (int i = 0; i < 1024 * 1024; i++) total += func(i); + printf("ok:%d*\n", total); + return 0; +} diff --git a/tests/core/test_array2.in b/tests/core/test_array2.in index 0e5bcbfb..452e0792 100644 --- a/tests/core/test_array2.in +++ b/tests/core/test_array2.in @@ -1,15 +1,13 @@ +#include <stdio.h> - #include <stdio.h> +static const double grid[4][2] = {{-3 / 3., -1 / 3.}, + {+1 / 3., -3 / 3.}, + {-1 / 3., +3 / 3.}, + {+3 / 3., +1 / 3.}}; - static const double grid[4][2] = { - {-3/3.,-1/3.},{+1/3.,-3/3.}, - {-1/3.,+3/3.},{+3/3.,+1/3.} - }; - - int main() { - for (int i = 0; i < 4; i++) - printf("%d:%.2f,%.2f ", i, grid[i][0], grid[i][1]); - printf("\n"); - return 0; - } -
\ No newline at end of file +int main() { + for (int i = 0; i < 4; i++) + printf("%d:%.2f,%.2f ", i, grid[i][0], grid[i][1]); + printf("\n"); + return 0; +} diff --git a/tests/core/test_array2b.in b/tests/core/test_array2b.in index b94821d8..97ace8db 100644 --- a/tests/core/test_array2b.in +++ b/tests/core/test_array2b.in @@ -1,16 +1,12 @@ +#include <stdio.h> - #include <stdio.h> +static const struct { + unsigned char left; + unsigned char right; +} prioritah[] = {{6, 6}, {6, 6}, {7, 95}, {7, 7}}; - static const struct { - unsigned char left; - unsigned char right; - } prioritah[] = { - {6, 6}, {6, 6}, {7, 95}, {7, 7} - }; - - int main() { - printf("*%d,%d\n", prioritah[1].left, prioritah[1].right); - printf("%d,%d*\n", prioritah[2].left, prioritah[2].right); - return 0; - } -
\ No newline at end of file +int main() { + printf("*%d,%d\n", prioritah[1].left, prioritah[1].right); + printf("%d,%d*\n", prioritah[2].left, prioritah[2].right); + return 0; +} diff --git a/tests/core/test_assert.in b/tests/core/test_assert.in index 7547468e..3a1898fa 100644 --- a/tests/core/test_assert.in +++ b/tests/core/test_assert.in @@ -1,9 +1,7 @@ - - #include <stdio.h> - #include <assert.h> - int main() { - assert(1 == true); // pass - assert(1 == false); // fail - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <assert.h> +int main() { + assert(1 == true); // pass + assert(1 == false); // fail + return 0; +} diff --git a/tests/core/test_atexit.in b/tests/core/test_atexit.in index 56489a6c..b40c01c0 100644 --- a/tests/core/test_atexit.in +++ b/tests/core/test_atexit.in @@ -1,17 +1,11 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +static void cleanA() { printf("A"); } +static void cleanB() { printf("B"); } - static void cleanA() { - printf("A"); - } - static void cleanB() { - printf("B"); - } - - int main() { - atexit(cleanA); - atexit(cleanB); - return 0; - } -
\ No newline at end of file +int main() { + atexit(cleanA); + atexit(cleanB); + return 0; +} diff --git a/tests/core/test_atoX.in b/tests/core/test_atoX.in index 8325acfa..327871b8 100644 --- a/tests/core/test_atoX.in +++ b/tests/core/test_atoX.in @@ -1,42 +1,40 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> - - int main () { - printf("%d*", atoi("")); - printf("%d*", atoi("a")); - printf("%d*", atoi(" b")); - printf("%d*", atoi(" c ")); - printf("%d*", atoi("6")); - printf("%d*", atoi(" 5")); - printf("%d*", atoi("4 ")); - printf("%d*", atoi("3 6")); - printf("%d*", atoi(" 3 7")); - printf("%d*", atoi("9 d")); - printf("%d\n", atoi(" 8 e")); - printf("%d*", atol("")); - printf("%d*", atol("a")); - printf("%d*", atol(" b")); - printf("%d*", atol(" c ")); - printf("%d*", atol("6")); - printf("%d*", atol(" 5")); - printf("%d*", atol("4 ")); - printf("%d*", atol("3 6")); - printf("%d*", atol(" 3 7")); - printf("%d*", atol("9 d")); - printf("%d\n", atol(" 8 e")); - printf("%lld*", atoll("6294967296")); - printf("%lld*", atoll("")); - printf("%lld*", atoll("a")); - printf("%lld*", atoll(" b")); - printf("%lld*", atoll(" c ")); - printf("%lld*", atoll("6")); - printf("%lld*", atoll(" 5")); - printf("%lld*", atoll("4 ")); - printf("%lld*", atoll("3 6")); - printf("%lld*", atoll(" 3 7")); - printf("%lld*", atoll("9 d")); - printf("%lld\n", atoll(" 8 e")); - return 0; - } -
\ No newline at end of file +int main() { + printf("%d*", atoi("")); + printf("%d*", atoi("a")); + printf("%d*", atoi(" b")); + printf("%d*", atoi(" c ")); + printf("%d*", atoi("6")); + printf("%d*", atoi(" 5")); + printf("%d*", atoi("4 ")); + printf("%d*", atoi("3 6")); + printf("%d*", atoi(" 3 7")); + printf("%d*", atoi("9 d")); + printf("%d\n", atoi(" 8 e")); + printf("%d*", atol("")); + printf("%d*", atol("a")); + printf("%d*", atol(" b")); + printf("%d*", atol(" c ")); + printf("%d*", atol("6")); + printf("%d*", atol(" 5")); + printf("%d*", atol("4 ")); + printf("%d*", atol("3 6")); + printf("%d*", atol(" 3 7")); + printf("%d*", atol("9 d")); + printf("%d\n", atol(" 8 e")); + printf("%lld*", atoll("6294967296")); + printf("%lld*", atoll("")); + printf("%lld*", atoll("a")); + printf("%lld*", atoll(" b")); + printf("%lld*", atoll(" c ")); + printf("%lld*", atoll("6")); + printf("%lld*", atoll(" 5")); + printf("%lld*", atoll("4 ")); + printf("%lld*", atoll("3 6")); + printf("%lld*", atoll(" 3 7")); + printf("%lld*", atoll("9 d")); + printf("%lld\n", atoll(" 8 e")); + return 0; +} diff --git a/tests/core/test_atomic.in b/tests/core/test_atomic.in index d0950551..2390941f 100644 --- a/tests/core/test_atomic.in +++ b/tests/core/test_atomic.in @@ -1,20 +1,18 @@ - - #include <stdio.h> - int main() { - int x = 10; - int y = __sync_add_and_fetch(&x, 5); - printf("*%d,%d*\n", x, y); - x = 10; - y = __sync_fetch_and_add(&x, 5); - printf("*%d,%d*\n", x, y); - x = 10; - y = __sync_lock_test_and_set(&x, 6); - printf("*%d,%d*\n", x, y); - x = 10; - y = __sync_bool_compare_and_swap(&x, 9, 7); - printf("*%d,%d*\n", x, y); - y = __sync_bool_compare_and_swap(&x, 10, 7); - printf("*%d,%d*\n", x, y); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +int main() { + int x = 10; + int y = __sync_add_and_fetch(&x, 5); + printf("*%d,%d*\n", x, y); + x = 10; + y = __sync_fetch_and_add(&x, 5); + printf("*%d,%d*\n", x, y); + x = 10; + y = __sync_lock_test_and_set(&x, 6); + printf("*%d,%d*\n", x, y); + x = 10; + y = __sync_bool_compare_and_swap(&x, 9, 7); + printf("*%d,%d*\n", x, y); + y = __sync_bool_compare_and_swap(&x, 10, 7); + printf("*%d,%d*\n", x, y); + return 0; +} diff --git a/tests/core/test_bigarray.in b/tests/core/test_bigarray.in index 0255c207..292a44e5 100644 --- a/tests/core/test_bigarray.in +++ b/tests/core/test_bigarray.in @@ -1,19 +1,22 @@ - // avoid "array initializer too large" errors - #include <stdio.h> - #include <assert.h> +#include <stdio.h> +#include <assert.h> - #define SIZE (1024*100) - struct Struct { - char x; - int y; - }; - Struct buffy[SIZE]; +#define SIZE (1024 * 100) +struct Struct { + char x; + int y; +}; +Struct buffy[SIZE]; - int main() { - for (int i = 0; i < SIZE; i++) { assert(buffy[i].x == 0 && buffy[i].y == 0); } // we were zeroinitialized - for (int i = 0; i < SIZE; i++) { buffy[i].x = i*i; buffy[i].y = i*i*i; } // we can save data - printf("*%d*\n", buffy[SIZE/3].x); - return 0; - } - +int main() { + for (int i = 0; i < SIZE; i++) { + assert(buffy[i].x == 0 && buffy[i].y == 0); + } // we were zeroinitialized + for (int i = 0; i < SIZE; i++) { + buffy[i].x = i * i; + buffy[i].y = i * i * i; + } // we can save data + printf("*%d*\n", buffy[SIZE / 3].x); + return 0; +} diff --git a/tests/core/test_bitfields.in b/tests/core/test_bitfields.in index 08831f23..cbc7ccf2 100644 --- a/tests/core/test_bitfields.in +++ b/tests/core/test_bitfields.in @@ -1,23 +1,20 @@ - - #include <stdio.h> - struct bitty { - unsigned x : 1; - unsigned y : 1; - unsigned z : 1; - }; - int main() - { - bitty b; - printf("*"); - for (int i = 0; i <= 1; i++) - for (int j = 0; j <= 1; j++) - for (int k = 0; k <= 1; k++) { - b.x = i; - b.y = j; - b.z = k; - printf("%d,%d,%d,", b.x, b.y, b.z); - } - printf("*\n"); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +struct bitty { + unsigned x : 1; + unsigned y : 1; + unsigned z : 1; +}; +int main() { + bitty b; + printf("*"); + for (int i = 0; i <= 1; i++) + for (int j = 0; j <= 1; j++) + for (int k = 0; k <= 1; k++) { + b.x = i; + b.y = j; + b.z = k; + printf("%d,%d,%d,", b.x, b.y, b.z); + } + printf("*\n"); + return 0; +} diff --git a/tests/core/test_bsearch.in b/tests/core/test_bsearch.in index 285210bd..3b5fb6bc 100644 --- a/tests/core/test_bsearch.in +++ b/tests/core/test_bsearch.in @@ -1,47 +1,45 @@ - - #include <stdlib.h> - #include <stdio.h> - - int cmp(const void* key, const void* member) { - return *(int *)key - *(int *)member; - } - - void printResult(int* needle, int* haystack, unsigned int len) { - void *result = bsearch(needle, haystack, len, sizeof(unsigned int), cmp); - - if (result == NULL) { - printf("null\n"); - } else { - printf("%d\n", *(unsigned int *)result); - } - } - - int main() { - int a[] = { -2, -1, 0, 6, 7, 9 }; - int b[] = { 0, 1 }; - - /* Find all keys that exist. */ - for(int i = 0; i < 6; i++) { - int val = a[i]; - - printResult(&val, a, 6); - } - - /* Keys that are covered by the range of the array but aren't in - * the array cannot be found. - */ - int v1 = 3; - int v2 = 8; - printResult(&v1, a, 6); - printResult(&v2, a, 6); - - /* Keys outside the range of the array cannot be found. */ - int v3 = -1; - int v4 = 2; - - printResult(&v3, b, 2); - printResult(&v4, b, 2); - - return 0; - } -
\ No newline at end of file +#include <stdlib.h> +#include <stdio.h> + +int cmp(const void* key, const void* member) { + return *(int*)key - *(int*)member; +} + +void printResult(int* needle, int* haystack, unsigned int len) { + void* result = bsearch(needle, haystack, len, sizeof(unsigned int), cmp); + + if (result == NULL) { + printf("null\n"); + } else { + printf("%d\n", *(unsigned int*)result); + } +} + +int main() { + int a[] = {-2, -1, 0, 6, 7, 9}; + int b[] = {0, 1}; + + /* Find all keys that exist. */ + for (int i = 0; i < 6; i++) { + int val = a[i]; + + printResult(&val, a, 6); + } + + /* Keys that are covered by the range of the array but aren't in + * the array cannot be found. + */ + int v1 = 3; + int v2 = 8; + printResult(&v1, a, 6); + printResult(&v2, a, 6); + + /* Keys outside the range of the array cannot be found. */ + int v3 = -1; + int v4 = 2; + + printResult(&v3, b, 2); + printResult(&v4, b, 2); + + return 0; +} diff --git a/tests/core/test_bswap64.in b/tests/core/test_bswap64.in index addf6086..a608ad22 100644 --- a/tests/core/test_bswap64.in +++ b/tests/core/test_bswap64.in @@ -1,56 +1,48 @@ - - #include <stdio.h> - #include <stdlib.h> - - #include <iostream> - #include <string> - #include <sstream> - - typedef unsigned long long quint64; - - using namespace std; - - inline quint64 qbswap(quint64 source) - { - return 0 - | ((source & quint64(0x00000000000000ffLL)) << 56) - | ((source & quint64(0x000000000000ff00LL)) << 40) - | ((source & quint64(0x0000000000ff0000LL)) << 24) - | ((source & quint64(0x00000000ff000000LL)) << 8) - | ((source & quint64(0x000000ff00000000LL)) >> 8) - | ((source & quint64(0x0000ff0000000000LL)) >> 24) - | ((source & quint64(0x00ff000000000000LL)) >> 40) - | ((source & quint64(0xff00000000000000LL)) >> 56); - } - - int main() - { - quint64 v = strtoull("4433ffeeddccbb00", NULL, 16); - printf("%lld\n", v); - - const string string64bitInt = "4433ffeeddccbb00"; - stringstream s(string64bitInt); - quint64 int64bitInt = 0; - printf("1\n"); - s >> hex >> int64bitInt; - printf("2\n"); - - stringstream out; - out << hex << qbswap(int64bitInt); - - cout << out.str() << endl; - cout << hex << int64bitInt << endl; - cout << string64bitInt << endl; - - if (out.str() != "bbccddeeff3344") - { - cout << "Failed!" << endl; - } - else - { - cout << "Succeeded!" << endl; - } - - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <stdlib.h> + +#include <iostream> +#include <string> +#include <sstream> + +typedef unsigned long long quint64; + +using namespace std; + +inline quint64 qbswap(quint64 source) { + return 0 | ((source & quint64(0x00000000000000ffLL)) << 56) | + ((source & quint64(0x000000000000ff00LL)) << 40) | + ((source & quint64(0x0000000000ff0000LL)) << 24) | + ((source & quint64(0x00000000ff000000LL)) << 8) | + ((source & quint64(0x000000ff00000000LL)) >> 8) | + ((source & quint64(0x0000ff0000000000LL)) >> 24) | + ((source & quint64(0x00ff000000000000LL)) >> 40) | + ((source & quint64(0xff00000000000000LL)) >> 56); +} + +int main() { + quint64 v = strtoull("4433ffeeddccbb00", NULL, 16); + printf("%lld\n", v); + + const string string64bitInt = "4433ffeeddccbb00"; + stringstream s(string64bitInt); + quint64 int64bitInt = 0; + printf("1\n"); + s >> hex >> int64bitInt; + printf("2\n"); + + stringstream out; + out << hex << qbswap(int64bitInt); + + cout << out.str() << endl; + cout << hex << int64bitInt << endl; + cout << string64bitInt << endl; + + if (out.str() != "bbccddeeff3344") { + cout << "Failed!" << endl; + } else { + cout << "Succeeded!" << endl; + } + + return 0; +} diff --git a/tests/core/test_ccall.in b/tests/core/test_ccall.in index 6374ebb3..0aefdc9d 100644 --- a/tests/core/test_ccall.in +++ b/tests/core/test_ccall.in @@ -1,19 +1,22 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +extern "C" { +int get_int() { return 5; } +float get_float() { return 3.14; } +char *get_string() { return "hello world"; } +void print_int(int x) { printf("%d\n", x); } +void print_float(float x) { printf("%.2f\n", x); } +void print_string(char *x) { printf("%s\n", x); } +int multi(int x, float y, int z, char *str) { + if (x) puts(str); + return (x + y) * z; +} +int *pointer(int *in) { + printf("%d\n", *in); + static int ret = 21; + return &ret; +} +} - extern "C" { - int get_int() { return 5; } - float get_float() { return 3.14; } - char * get_string() { return "hello world"; } - void print_int(int x) { printf("%d\n", x); } - void print_float(float x) { printf("%.2f\n", x); } - void print_string(char *x) { printf("%s\n", x); } - int multi(int x, float y, int z, char *str) { if (x) puts(str); return (x+y)*z; } - int * pointer(int *in) { printf("%d\n", *in); static int ret = 21; return &ret; } - } - - int main(int argc, char **argv) { - return 0; - } -
\ No newline at end of file +int main(int argc, char **argv) { return 0; } diff --git a/tests/core/test_class.in b/tests/core/test_class.in index fc61869e..9450b4a1 100644 --- a/tests/core/test_class.in +++ b/tests/core/test_class.in @@ -1,26 +1,28 @@ +#include <stdio.h> +struct Random { + enum { + IM = 139968, + IA = 3877, + IC = 29573 + }; + Random() : last(42) {} + float get(float max = 1.0f) { + last = (last * IA + IC) % IM; + return max * last / IM; + } - #include <stdio.h> - struct Random { - enum { IM = 139968, IA = 3877, IC = 29573 }; - Random() : last(42) {} - float get( float max = 1.0f ) { - last = ( last * IA + IC ) % IM; - return max * last / IM; - } - protected: - unsigned int last; - } rng1; - int main() - { - Random rng2; - int count = 0; - for (int i = 0; i < 100; i++) { - float x1 = rng1.get(); - float x2 = rng2.get(); - printf("%f, %f\n", x1, x2); - if (x1 != x2) count += 1; - } - printf("*%d*\n", count); - return 0; - } -
\ No newline at end of file + protected: + unsigned int last; +} rng1; +int main() { + Random rng2; + int count = 0; + for (int i = 0; i < 100; i++) { + float x1 = rng1.get(); + float x2 = rng2.get(); + printf("%f, %f\n", x1, x2); + if (x1 != x2) count += 1; + } + printf("*%d*\n", count); + return 0; +} diff --git a/tests/core/test_constglobalstructs.in b/tests/core/test_constglobalstructs.in index f2f23c5d..182fae2f 100644 --- a/tests/core/test_constglobalstructs.in +++ b/tests/core/test_constglobalstructs.in @@ -1,30 +1,21 @@ +#include <stdio.h> +struct IUB { + int c; + double p; + unsigned int pi; +}; - #include <stdio.h> - struct IUB { - int c; - double p; - unsigned int pi; - }; +IUB iub[] = {{'a', 0.27, 5}, {'c', 0.15, 4}, {'g', 0.12, 3}, {'t', 0.27, 2}, }; - IUB iub[] = { - { 'a', 0.27, 5 }, - { 'c', 0.15, 4 }, - { 'g', 0.12, 3 }, - { 't', 0.27, 2 }, - }; +const unsigned char faceedgesidx[6][4] = {{4, 5, 8, 10}, + {6, 7, 9, 11}, + {0, 2, 8, 9}, + {1, 3, 10, 11}, + {0, 1, 4, 6}, + {2, 3, 5, 7}, }; - const unsigned char faceedgesidx[6][4] = - { - { 4, 5, 8, 10 }, - { 6, 7, 9, 11 }, - { 0, 2, 8, 9 }, - { 1, 3, 10,11 }, - { 0, 1, 4, 6 }, - { 2, 3, 5, 7 }, - }; - - int main( int argc, const char *argv[] ) { - printf("*%d,%d,%d,%d*\n", iub[0].c, int(iub[1].p*100), iub[2].pi, faceedgesidx[3][2]); - return 0; - } -
\ No newline at end of file +int main(int argc, const char *argv[]) { + printf("*%d,%d,%d,%d*\n", iub[0].c, int(iub[1].p * 100), iub[2].pi, + faceedgesidx[3][2]); + return 0; +} diff --git a/tests/core/test_conststructs.in b/tests/core/test_conststructs.in index e95fd6be..6d664bea 100644 --- a/tests/core/test_conststructs.in +++ b/tests/core/test_conststructs.in @@ -1,21 +1,18 @@ +#include <stdio.h> +struct IUB { + int c; + double p; + unsigned int pi; +}; - #include <stdio.h> - struct IUB { - int c; - double p; - unsigned int pi; - }; - - int main( int argc, const char *argv[] ) { - int before = 70; - IUB iub[] = { - { 'a', 0.3029549426680, 5 }, - { 'c', 0.15, 4 }, - { 'g', 0.12, 3 }, - { 't', 0.27, 2 }, - }; - int after = 90; - printf("*%d,%d,%d,%d,%d,%d*\n", before, iub[0].c, int(iub[1].p*100), iub[2].pi, int(iub[0].p*10000), after); - return 0; - } -
\ No newline at end of file +int main(int argc, const char *argv[]) { + int before = 70; + IUB iub[] = {{'a', 0.3029549426680, 5}, + {'c', 0.15, 4}, + {'g', 0.12, 3}, + {'t', 0.27, 2}, }; + int after = 90; + printf("*%d,%d,%d,%d,%d,%d*\n", before, iub[0].c, int(iub[1].p * 100), + iub[2].pi, int(iub[0].p * 10000), after); + return 0; +} diff --git a/tests/core/test_copyop.in b/tests/core/test_copyop.in index 4bf7da12..847a516c 100644 --- a/tests/core/test_copyop.in +++ b/tests/core/test_copyop.in @@ -1,36 +1,34 @@ +#include <stdio.h> +#include <math.h> +#include <string.h> - #include <stdio.h> - #include <math.h> - #include <string.h> +struct vec { + double x, y, z; + vec() : x(0), y(0), z(0) {}; + vec(const double a, const double b, const double c) : x(a), y(b), z(c) {}; +}; - struct vec { - double x,y,z; - vec() : x(0), y(0), z(0) { }; - vec(const double a, const double b, const double c) : x(a), y(b), z(c) { }; - }; +struct basis { + vec a, b, c; + basis(const vec& v) { + a = v; // should not touch b! + printf("*%.2f,%.2f,%.2f*\n", b.x, b.y, b.z); + } +}; - struct basis { - vec a, b, c; - basis(const vec& v) { - a=v; // should not touch b! - printf("*%.2f,%.2f,%.2f*\n", b.x, b.y, b.z); - } - }; +int main() { + basis B(vec(1, 0, 0)); - int main() { - basis B(vec(1,0,0)); - - // Part 2: similar problem with memset and memmove - int x = 1, y = 77, z = 2; - memset((void*)&x, 0, sizeof(int)); - memset((void*)&z, 0, sizeof(int)); - printf("*%d,%d,%d*\n", x, y, z); - memcpy((void*)&x, (void*)&z, sizeof(int)); - memcpy((void*)&z, (void*)&x, sizeof(int)); - printf("*%d,%d,%d*\n", x, y, z); - memmove((void*)&x, (void*)&z, sizeof(int)); - memmove((void*)&z, (void*)&x, sizeof(int)); - printf("*%d,%d,%d*\n", x, y, z); - return 0; - } -
\ No newline at end of file + // Part 2: similar problem with memset and memmove + int x = 1, y = 77, z = 2; + memset((void*)&x, 0, sizeof(int)); + memset((void*)&z, 0, sizeof(int)); + printf("*%d,%d,%d*\n", x, y, z); + memcpy((void*)&x, (void*)&z, sizeof(int)); + memcpy((void*)&z, (void*)&x, sizeof(int)); + printf("*%d,%d,%d*\n", x, y, z); + memmove((void*)&x, (void*)&z, sizeof(int)); + memmove((void*)&z, (void*)&x, sizeof(int)); + printf("*%d,%d,%d*\n", x, y, z); + return 0; +} diff --git a/tests/core/test_corruption_2.in b/tests/core/test_corruption_2.in index 87aef9da..4db3b7c4 100644 --- a/tests/core/test_corruption_2.in +++ b/tests/core/test_corruption_2.in @@ -1,26 +1,21 @@ +#include <iostream> +#include <fstream> +#include <stdlib.h> +#include <stdio.h> - #include <iostream> - #include <fstream> - #include <stdlib.h> - #include <stdio.h> +void bye() { printf("all ok\n"); } - void bye() { - printf("all ok\n"); - } +int main() { + atexit(bye); - int main() { - atexit(bye); + std::string testPath = "/Script/WA-KA.txt"; + std::fstream str(testPath.c_str(), std::ios::in | std::ios::binary); - std::string testPath = "/Script/WA-KA.txt"; - std::fstream str(testPath.c_str(), std::ios::in | std::ios::binary); + if (str.is_open()) { + std::cout << "open!" << std::endl; + } else { + std::cout << "missing!" << std::endl; + } - if (str.is_open()) - { - std::cout << "open!" << std::endl; - } else { - std::cout << "missing!" << std::endl; - } - - return 1; - } -
\ No newline at end of file + return 1; +} diff --git a/tests/core/test_corruption_3.in b/tests/core/test_corruption_3.in index b951ac6b..08e7d345 100644 --- a/tests/core/test_corruption_3.in +++ b/tests/core/test_corruption_3.in @@ -1,22 +1,19 @@ +#include <stdlib.h> +#include <stdio.h> +#include <assert.h> - #include <stdlib.h> - #include <stdio.h> - #include <assert.h> +void bye() { printf("all ok\n"); } - void bye() { - printf("all ok\n"); - } +int main(int argc, char **argv) { + atexit(bye); - int main(int argc, char **argv) { - atexit(bye); - - char *buffer = (char*)malloc(100); - for (int i = 0; i < 100; i++) buffer[i] = (i*i)%256; - buffer = (char*)realloc(buffer, argc + 50); - for (int i = 0; i < argc + 50; i++) { - //printf("%d : %d : %d : %d\n", i, (int)(buffer + i), buffer[i], (char)((i*i)%256)); - assert(buffer[i] == (char)((i*i)%256)); - } - return 1; - } -
\ No newline at end of file + char *buffer = (char *)malloc(100); + for (int i = 0; i < 100; i++) buffer[i] = (i * i) % 256; + buffer = (char *)realloc(buffer, argc + 50); + for (int i = 0; i < argc + 50; i++) { + // printf("%d : %d : %d : %d\n", i, (int)(buffer + i), buffer[i], + // (char)((i*i)%256)); + assert(buffer[i] == (char)((i * i) % 256)); + } + return 1; +} diff --git a/tests/core/test_cxx03_do_run.in b/tests/core/test_cxx03_do_run.in index ec7d1189..2ed0d2cf 100644 --- a/tests/core/test_cxx03_do_run.in +++ b/tests/core/test_cxx03_do_run.in @@ -1,12 +1,10 @@ +#include <stdio.h> - #include <stdio.h> +#if __cplusplus != 199711L +#error By default, if no -std is specified, emscripten should be compiling with -std=c++03! +#endif - #if __cplusplus != 199711L - #error By default, if no -std is specified, emscripten should be compiling with -std=c++03! - #endif - - int main( int argc, const char *argv[] ) { - printf("Hello world!\n"); - return 0; - } -
\ No newline at end of file +int main(int argc, const char *argv[]) { + printf("Hello world!\n"); + return 0; +} diff --git a/tests/core/test_demangle_stacks.in b/tests/core/test_demangle_stacks.in index 8db34832..e19d1a70 100644 --- a/tests/core/test_demangle_stacks.in +++ b/tests/core/test_demangle_stacks.in @@ -1,21 +1,20 @@ +#include <stdio.h> +#include <stdlib.h> - #include<stdio.h> - #include<stdlib.h> +namespace NameSpace { +class Class { + public: + int Aborter(double x, char y, int *z) { + int addr = x + y + (int)z; + void *p = (void *)addr; + for (int i = 0; i < 100; i++) + free(p); // will abort, should show proper stack trace + } +}; +} - namespace NameSpace { - class Class { - public: - int Aborter(double x, char y, int *z) { - int addr = x+y+(int)z; - void *p = (void*)addr; - for (int i = 0; i < 100; i++) free(p); // will abort, should show proper stack trace - } - }; - } - - int main(int argc, char **argv) { - NameSpace::Class c; - c.Aborter(1.234, 'a', NULL); - return 0; - } -
\ No newline at end of file +int main(int argc, char **argv) { + NameSpace::Class c; + c.Aborter(1.234, 'a', NULL); + return 0; +} diff --git a/tests/core/test_direct_string_constant_usage.in b/tests/core/test_direct_string_constant_usage.in index e43232f0..cab335bd 100644 --- a/tests/core/test_direct_string_constant_usage.in +++ b/tests/core/test_direct_string_constant_usage.in @@ -1,13 +1,9 @@ - - #include <iostream> - template<int i> - void printText( const char (&text)[ i ] ) - { - std::cout << text; - } - int main() - { - printText( "some string constant" ); - return 0; - } -
\ No newline at end of file +#include <iostream> +template <int i> +void printText(const char (&text)[i]) { + std::cout << text; +} +int main() { + printText("some string constant"); + return 0; +} diff --git a/tests/core/test_dlfcn_self.in b/tests/core/test_dlfcn_self.in index 687c4d6f..7094b97d 100644 --- a/tests/core/test_dlfcn_self.in +++ b/tests/core/test_dlfcn_self.in @@ -1,4 +1,3 @@ - #include <stdio.h> #include <dlfcn.h> #include <emscripten.h> @@ -6,19 +5,19 @@ int EMSCRIPTEN_KEEPALIVE global = 123; extern "C" EMSCRIPTEN_KEEPALIVE void foo(int x) { -printf("%d\n", x); + printf("%d\n", x); } extern "C" EMSCRIPTEN_KEEPALIVE void repeatable() { -void* self = dlopen(NULL, RTLD_LAZY); -int* global_ptr = (int*)dlsym(self, "global"); -void (*foo_ptr)(int) = (void (*)(int))dlsym(self, "foo"); -foo_ptr(*global_ptr); -dlclose(self); + void* self = dlopen(NULL, RTLD_LAZY); + int* global_ptr = (int*)dlsym(self, "global"); + void (*foo_ptr)(int) = (void (*)(int))dlsym(self, "foo"); + foo_ptr(*global_ptr); + dlclose(self); } int main() { -repeatable(); -repeatable(); -return 0; -}
\ No newline at end of file + repeatable(); + repeatable(); + return 0; +} diff --git a/tests/core/test_dlmalloc_partial_2.in b/tests/core/test_dlmalloc_partial_2.in index f68e9cdf..1e16657e 100644 --- a/tests/core/test_dlmalloc_partial_2.in +++ b/tests/core/test_dlmalloc_partial_2.in @@ -1,14 +1,10 @@ - - #include <stdio.h> - #include <stdlib.h> - void *malloc(size_t size) - { - return (void*)123; - } - int main() { - void *x = malloc(10); - printf("got %p\n", x); - free(x); - printf("freed the faker\n"); - return 1; - } +#include <stdio.h> +#include <stdlib.h> +void *malloc(size_t size) { return (void *)123; } +int main() { + void *x = malloc(10); + printf("got %p\n", x); + free(x); + printf("freed the faker\n"); + return 1; +} diff --git a/tests/core/test_double_i64_conversion.in b/tests/core/test_double_i64_conversion.in index 404c6796..4033e211 100644 --- a/tests/core/test_double_i64_conversion.in +++ b/tests/core/test_double_i64_conversion.in @@ -1,69 +1,69 @@ +#include <cassert> +#include <inttypes.h> +#include <stdio.h> - #include <cassert> - #include <inttypes.h> - #include <stdio.h> +__attribute((noinline)) bool eq(double d, int64_t i) { + int64_t i2 = (int64_t)d; + if (i != i2) { + printf("%.20g converted to int64 returns %lld, not %lld as expected!\n", d, + i2, i); + } + return i == i2; +} - __attribute((noinline)) bool eq(double d, int64_t i) { - int64_t i2 = (int64_t)d; - if (i != i2) { - printf("%.20g converted to int64 returns %lld, not %lld as expected!\n", d, i2, i); - } - return i == i2; - } +int main() { + assert(eq(0.0, 0)); + assert(eq(-0.0, 0)); + assert(eq(0.1, 0)); + assert(eq(-0.1, 0)); + assert(eq(0.6, 0)); + assert(eq(-0.6, 0)); + assert(eq(1.0, 1)); + assert(eq(-1.0, -1)); + assert(eq(1.1, 1)); + assert(eq(-1.1, -1)); + assert(eq(1.6, 1)); + assert(eq(-1.6, -1)); + assert(eq(4294967295.0, 4294967295LL)); + assert(eq(4294967295.5, 4294967295LL)); + assert(eq(4294967296.0, 4294967296LL)); + assert(eq(4294967296.5, 4294967296LL)); + assert(eq(14294967295.0, 14294967295LL)); + assert(eq(14294967295.5, 14294967295LL)); + assert(eq(14294967296.0, 14294967296LL)); + assert(eq(14294967296.5, 14294967296LL)); + assert(eq(-4294967295.0, -4294967295LL)); + assert(eq(-4294967295.5, -4294967295LL)); + assert(eq(-4294967296.0, -4294967296LL)); + assert(eq(-4294967296.5, -4294967296LL)); + assert(eq(-14294967295.0, -14294967295LL)); + assert(eq(-14294967295.5, -14294967295LL)); + assert(eq(-14294967296.0, -14294967296LL)); + assert(eq(-14294967296.5, -14294967296LL)); - int main() { - assert(eq(0.0, 0)); - assert(eq(-0.0, 0)); - assert(eq(0.1, 0)); - assert(eq(-0.1, 0)); - assert(eq(0.6, 0)); - assert(eq(-0.6, 0)); - assert(eq(1.0, 1)); - assert(eq(-1.0, -1)); - assert(eq(1.1, 1)); - assert(eq(-1.1, -1)); - assert(eq(1.6, 1)); - assert(eq(-1.6, -1)); - assert(eq(4294967295.0, 4294967295LL)); - assert(eq(4294967295.5, 4294967295LL)); - assert(eq(4294967296.0, 4294967296LL)); - assert(eq(4294967296.5, 4294967296LL)); - assert(eq(14294967295.0, 14294967295LL)); - assert(eq(14294967295.5, 14294967295LL)); - assert(eq(14294967296.0, 14294967296LL)); - assert(eq(14294967296.5, 14294967296LL)); - assert(eq(-4294967295.0, -4294967295LL)); - assert(eq(-4294967295.5, -4294967295LL)); - assert(eq(-4294967296.0, -4294967296LL)); - assert(eq(-4294967296.5, -4294967296LL)); - assert(eq(-14294967295.0, -14294967295LL)); - assert(eq(-14294967295.5, -14294967295LL)); - assert(eq(-14294967296.0, -14294967296LL)); - assert(eq(-14294967296.5, -14294967296LL)); + assert(eq(4294967295.3, 4294967295LL)); + assert(eq(4294967296.3, 4294967296LL)); + assert(eq(14294967295.3, 14294967295LL)); + assert(eq(14294967296.3, 14294967296LL)); + assert(eq(-4294967295.3, -4294967295LL)); + assert(eq(-4294967296.3, -4294967296LL)); + assert(eq(-14294967295.3, -14294967295LL)); + assert(eq(-14294967296.3, -14294967296LL)); - assert(eq(4294967295.3, 4294967295LL)); - assert(eq(4294967296.3, 4294967296LL)); - assert(eq(14294967295.3, 14294967295LL)); - assert(eq(14294967296.3, 14294967296LL)); - assert(eq(-4294967295.3, -4294967295LL)); - assert(eq(-4294967296.3, -4294967296LL)); - assert(eq(-14294967295.3, -14294967295LL)); - assert(eq(-14294967296.3, -14294967296LL)); + assert(eq(4294967295.8, 4294967295LL)); + assert(eq(4294967296.8, 4294967296LL)); + assert(eq(14294967295.8, 14294967295LL)); + assert(eq(14294967296.8, 14294967296LL)); + assert(eq(-4294967295.8, -4294967295LL)); + assert(eq(-4294967296.8, -4294967296LL)); + assert(eq(-14294967295.8, -14294967295LL)); + assert(eq(-14294967296.8, -14294967296LL)); - assert(eq(4294967295.8, 4294967295LL)); - assert(eq(4294967296.8, 4294967296LL)); - assert(eq(14294967295.8, 14294967295LL)); - assert(eq(14294967296.8, 14294967296LL)); - assert(eq(-4294967295.8, -4294967295LL)); - assert(eq(-4294967296.8, -4294967296LL)); - assert(eq(-14294967295.8, -14294967295LL)); - assert(eq(-14294967296.8, -14294967296LL)); + // The following number is the largest double such that all integers smaller + // than this can exactly be represented in a double. + assert(eq(9007199254740992.0, 9007199254740992LL /* == 2^53 */)); + assert(eq(-9007199254740992.0, -9007199254740992LL /* == -2^53 */)); - // The following number is the largest double such that all integers smaller than this can exactly be represented in a double. - assert(eq(9007199254740992.0, 9007199254740992LL /* == 2^53 */)); - assert(eq(-9007199254740992.0, -9007199254740992LL /* == -2^53 */)); - - printf("OK!\n"); - return 0; - } -
\ No newline at end of file + printf("OK!\n"); + return 0; +} diff --git a/tests/core/test_dynamic_cast.in b/tests/core/test_dynamic_cast.in index ebe9263b..1752573c 100644 --- a/tests/core/test_dynamic_cast.in +++ b/tests/core/test_dynamic_cast.in @@ -1,17 +1,12 @@ +#include <stdio.h> - #include <stdio.h> +struct Support { + virtual void f() { printf("f()\n"); } +}; - struct Support { - virtual void f() { - printf("f()\n"); - } - }; +struct Derived : Support {}; - struct Derived : Support { - }; - - int main() { - Support * p = new Derived; - dynamic_cast<Derived*>(p)->f(); - } -
\ No newline at end of file +int main() { + Support* p = new Derived; + dynamic_cast<Derived*>(p)->f(); +} diff --git a/tests/core/test_dynamic_cast_2.in b/tests/core/test_dynamic_cast_2.in index 6da4cade..634ff5c2 100644 --- a/tests/core/test_dynamic_cast_2.in +++ b/tests/core/test_dynamic_cast_2.in @@ -1,12 +1,10 @@ +#include <stdio.h> +#include <typeinfo> - #include <stdio.h> - #include <typeinfo> +class Class {}; - class Class {}; - - int main() { - const Class* dp = dynamic_cast<const Class*>(&typeid(Class)); - // should return dp == NULL, - printf("pointer: %p\n", dp); - } -
\ No newline at end of file +int main() { + const Class* dp = dynamic_cast<const Class*>(&typeid(Class)); + // should return dp == NULL, + printf("pointer: %p\n", dp); +} diff --git a/tests/core/test_dynamic_cast_b.in b/tests/core/test_dynamic_cast_b.in index f5931fef..77981035 100644 --- a/tests/core/test_dynamic_cast_b.in +++ b/tests/core/test_dynamic_cast_b.in @@ -1,28 +1,31 @@ +#include <stdio.h> - #include <stdio.h> +class CBase { + virtual void dummy() {} +}; +class CDerived : public CBase { + int a; +}; +class CDerivedest : public CDerived { + float b; +}; - class CBase { virtual void dummy() {} }; - class CDerived : public CBase { int a; }; - class CDerivedest : public CDerived { float b; }; +int main() { + CBase *pa = new CBase; + CBase *pb = new CDerived; + CBase *pc = new CDerivedest; - int main () - { - CBase *pa = new CBase; - CBase *pb = new CDerived; - CBase *pc = new CDerivedest; + printf("a1: %d\n", dynamic_cast<CDerivedest *>(pa) != NULL); + printf("a2: %d\n", dynamic_cast<CDerived *>(pa) != NULL); + printf("a3: %d\n", dynamic_cast<CBase *>(pa) != NULL); - printf("a1: %d\n", dynamic_cast<CDerivedest*>(pa) != NULL); - printf("a2: %d\n", dynamic_cast<CDerived*>(pa) != NULL); - printf("a3: %d\n", dynamic_cast<CBase*>(pa) != NULL); + printf("b1: %d\n", dynamic_cast<CDerivedest *>(pb) != NULL); + printf("b2: %d\n", dynamic_cast<CDerived *>(pb) != NULL); + printf("b3: %d\n", dynamic_cast<CBase *>(pb) != NULL); - printf("b1: %d\n", dynamic_cast<CDerivedest*>(pb) != NULL); - printf("b2: %d\n", dynamic_cast<CDerived*>(pb) != NULL); - printf("b3: %d\n", dynamic_cast<CBase*>(pb) != NULL); + printf("c1: %d\n", dynamic_cast<CDerivedest *>(pc) != NULL); + printf("c2: %d\n", dynamic_cast<CDerived *>(pc) != NULL); + printf("c3: %d\n", dynamic_cast<CBase *>(pc) != NULL); - printf("c1: %d\n", dynamic_cast<CDerivedest*>(pc) != NULL); - printf("c2: %d\n", dynamic_cast<CDerived*>(pc) != NULL); - printf("c3: %d\n", dynamic_cast<CBase*>(pc) != NULL); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_emptyclass.in b/tests/core/test_emptyclass.in index 24a550db..370cacf5 100644 --- a/tests/core/test_emptyclass.in +++ b/tests/core/test_emptyclass.in @@ -1,15 +1,11 @@ +#include <stdio.h> - #include <stdio.h> +struct Randomized { + Randomized(int x) { printf("*zzcheezzz*\n"); } +}; - struct Randomized { - Randomized(int x) { - printf("*zzcheezzz*\n"); - } - }; +int main(int argc, const char *argv[]) { + new Randomized(55); - int main( int argc, const char *argv[] ) { - new Randomized(55); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_emscripten_api.in b/tests/core/test_emscripten_api.in index fb25175e..7ece877f 100644 --- a/tests/core/test_emscripten_api.in +++ b/tests/core/test_emscripten_api.in @@ -1,17 +1,15 @@ +#include <stdio.h> +#include "emscripten.h" - #include <stdio.h> - #include "emscripten.h" +extern "C" { +void save_me_aimee() { printf("mann\n"); } +} - extern "C" { - void save_me_aimee() { printf("mann\n"); } - } - - int main() { - // EMSCRIPTEN_COMMENT("hello from the source"); - emscripten_run_script("Module.print('hello world' + '!')"); - printf("*%d*\n", emscripten_run_script_int("5*20")); - printf("*%s*\n", emscripten_run_script_string("'five'+'six'")); - emscripten_run_script("Module['_save_me_aimee']()"); - return 0; - } -
\ No newline at end of file +int main() { + // EMSCRIPTEN_COMMENT("hello from the source"); + emscripten_run_script("Module.print('hello world' + '!')"); + printf("*%d*\n", emscripten_run_script_int("5*20")); + printf("*%s*\n", emscripten_run_script_string("'five'+'six'")); + emscripten_run_script("Module['_save_me_aimee']()"); + return 0; +} diff --git a/tests/core/test_erf.in b/tests/core/test_erf.in index 70658ea5..bd14b14f 100644 --- a/tests/core/test_erf.in +++ b/tests/core/test_erf.in @@ -1,15 +1,7 @@ - - #include <math.h> - #include <stdio.h> - int main() - { - printf("%1.6f, %1.6f, %1.6f, %1.6f, %1.6f, %1.6f\n", - erf(1.0), - erf(3.0), - erf(-1.0), - erfc(1.0), - erfc(3.0), - erfc(-1.5)); - return 0; - } -
\ No newline at end of file +#include <math.h> +#include <stdio.h> +int main() { + printf("%1.6f, %1.6f, %1.6f, %1.6f, %1.6f, %1.6f\n", erf(1.0), erf(3.0), + erf(-1.0), erfc(1.0), erfc(3.0), erfc(-1.5)); + return 0; +} diff --git a/tests/core/test_errar.in b/tests/core/test_errar.in index 7ef2b23d..9fda2099 100644 --- a/tests/core/test_errar.in +++ b/tests/core/test_errar.in @@ -1,21 +1,19 @@ +#include <stdio.h> +#include <errno.h> +#include <string.h> - #include <stdio.h> - #include <errno.h> - #include <string.h> +int main() { + char* err; + char buffer[200]; - int main() { - char* err; - char buffer[200]; + err = strerror(EDOM); + strerror_r(EWOULDBLOCK, buffer, 200); + printf("<%s>\n", err); + printf("<%s>\n", buffer); - err = strerror(EDOM); - strerror_r(EWOULDBLOCK, buffer, 200); - printf("<%s>\n", err); - printf("<%s>\n", buffer); + printf("<%d>\n", strerror_r(EWOULDBLOCK, buffer, 0)); + errno = 123; + printf("<%d>\n", errno); - printf("<%d>\n", strerror_r(EWOULDBLOCK, buffer, 0)); - errno = 123; - printf("<%d>\n", errno); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_exception_2.in b/tests/core/test_exception_2.in index 5a9efce5..2eae3198 100644 --- a/tests/core/test_exception_2.in +++ b/tests/core/test_exception_2.in @@ -1,26 +1,18 @@ +#include <stdexcept> +#include <stdio.h> - #include <stdexcept> - #include <stdio.h> +typedef void (*FuncPtr)(); - typedef void (*FuncPtr)(); +void ThrowException() { throw std::runtime_error("catch me!"); } - void ThrowException() - { - throw std::runtime_error("catch me!"); - } +FuncPtr ptr = ThrowException; - FuncPtr ptr = ThrowException; - - int main() - { - try - { - ptr(); - } - catch(...) - { - printf("Exception caught successfully!\n"); - } - return 0; - } -
\ No newline at end of file +int main() { + try { + ptr(); + } + catch (...) { + printf("Exception caught successfully!\n"); + } + return 0; +} diff --git a/tests/core/test_fakestat.in b/tests/core/test_fakestat.in index 9a09b57c..d1dbed29 100644 --- a/tests/core/test_fakestat.in +++ b/tests/core/test_fakestat.in @@ -1,10 +1,10 @@ - - #include <stdio.h> - struct stat { int x, y; }; - int main() { - stat s; - s.x = 10; - s.y = 22; - printf("*%d,%d*\n", s.x, s.y); - } -
\ No newline at end of file +#include <stdio.h> +struct stat { + int x, y; +}; +int main() { + stat s; + s.x = 10; + s.y = 22; + printf("*%d,%d*\n", s.x, s.y); +} diff --git a/tests/core/test_fast_math.in b/tests/core/test_fast_math.in index 27bd01fd..e3b283aa 100644 --- a/tests/core/test_fast_math.in +++ b/tests/core/test_fast_math.in @@ -1,4 +1,3 @@ - #include <stdio.h> #include <stdlib.h> diff --git a/tests/core/test_fcvt.in b/tests/core/test_fcvt.in index 66b5adef..2e3fdbc6 100644 --- a/tests/core/test_fcvt.in +++ b/tests/core/test_fcvt.in @@ -1,14 +1,12 @@ -/* This example borrowed from MSDN documentation */ - #include <stdlib.h> - #include <stdio.h> +/* This example borrowed from MSDN documentation */#include <stdlib.h> +#include <stdio.h> - int main() { - int decimal, sign; - char *buffer; - double source = 3.1415926535; +int main() { + int decimal, sign; + char *buffer; + double source = 3.1415926535; - buffer = fcvt(source, 7, &decimal, &sign); - printf("source: %2.10f buffer: '%s' decimal: %d sign: %d\n", - source, buffer, decimal, sign); - } - + buffer = fcvt(source, 7, &decimal, &sign); + printf("source: %2.10f buffer: '%s' decimal: %d sign: %d\n", source, + buffer, decimal, sign); +} diff --git a/tests/core/test_flexarray_struct.in b/tests/core/test_flexarray_struct.in index 40ee1ddd..cb83a7e5 100644 --- a/tests/core/test_flexarray_struct.in +++ b/tests/core/test_flexarray_struct.in @@ -1,13 +1,10 @@ - #include <stdint.h> #include <stdlib.h> #include <stdio.h> -typedef struct -{ +typedef struct { uint16_t length; - struct - { + struct { int32_t int32; } value[]; } Tuple; diff --git a/tests/core/test_float32_precise.in b/tests/core/test_float32_precise.in index 231b4289..969f5ed6 100644 --- a/tests/core/test_float32_precise.in +++ b/tests/core/test_float32_precise.in @@ -1,21 +1,19 @@ +#include <stdio.h> - #include <stdio.h> - - int main(int argc, char **argv) { - float x = 1.23456789123456789; - float y = 5.20456089123406709; - while (argc > 10 || argc % 19 == 15) { - // confuse optimizer - x /= y; - y = 2*y - 1; - argc--; - } - x = x - y; - y = 3*y - x/2; - x = x*y; - y += 0.000000000123123123123; - x -= y/7.654; - printf("\n%.20f, %.20f\n", x, y); - return 0; - } -
\ No newline at end of file +int main(int argc, char **argv) { + float x = 1.23456789123456789; + float y = 5.20456089123406709; + while (argc > 10 || argc % 19 == 15) { + // confuse optimizer + x /= y; + y = 2 * y - 1; + argc--; + } + x = x - y; + y = 3 * y - x / 2; + x = x * y; + y += 0.000000000123123123123; + x -= y / 7.654; + printf("\n%.20f, %.20f\n", x, y); + return 0; +} diff --git a/tests/core/test_floatvars.in b/tests/core/test_floatvars.in index f63da19c..b6c94c82 100644 --- a/tests/core/test_floatvars.in +++ b/tests/core/test_floatvars.in @@ -1,29 +1,27 @@ +#include <stdio.h> - #include <stdio.h> +// headers test, see issue #1013 +#include <cfloat> +#include <cmath> - // headers test, see issue #1013 - #include<cfloat> - #include<cmath> +int main(int argc, char **argv) { + float x = 1.234, y = 3.5, q = 0.00000001; + y *= 3; + int z = x < y; + printf("*%d,%d,%.1f,%d,%.4f,%.2f*\n", z, int(y), y, (int)x, x, q); - int main(int argc, char **argv) - { - float x = 1.234, y = 3.5, q = 0.00000001; - y *= 3; - int z = x < y; - printf("*%d,%d,%.1f,%d,%.4f,%.2f*\n", z, int(y), y, (int)x, x, q); + printf("%.2f, %.2f, %.2f, %.2f\n", fmin(0.5, 3.3), fmin(NAN, 3.3), + fmax(0.5, 3.3), fmax(NAN, 3.3)); - printf("%.2f, %.2f, %.2f, %.2f\n", fmin(0.5, 3.3), fmin(NAN, 3.3), fmax(0.5, 3.3), fmax(NAN, 3.3)); + printf("small: %.10f\n", argc * 0.000001); - printf("small: %.10f\n", argc * 0.000001); + /* + // Rounding behavior + float fs[6] = { -2.75, -2.50, -2.25, 2.25, 2.50, 2.75 }; + double ds[6] = { -2.75, -2.50, -2.25, 2.25, 2.50, 2.75 }; + for (int i = 0; i < 6; i++) + printf("*int(%.2f)=%d,%d*\n", fs[i], int(fs[i]), int(ds[i])); + */ - /* - // Rounding behavior - float fs[6] = { -2.75, -2.50, -2.25, 2.25, 2.50, 2.75 }; - double ds[6] = { -2.75, -2.50, -2.25, 2.25, 2.50, 2.75 }; - for (int i = 0; i < 6; i++) - printf("*int(%.2f)=%d,%d*\n", fs[i], int(fs[i]), int(ds[i])); - */ - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_frexp.in b/tests/core/test_frexp.in index d3facca8..fba3231f 100644 --- a/tests/core/test_frexp.in +++ b/tests/core/test_frexp.in @@ -1,32 +1,29 @@ +#include <stdio.h> +#include <math.h> +#include <assert.h> - #include <stdio.h> - #include <math.h> - #include <assert.h> +static const double tol = 1e-16; - static const double tol=1e-16; +void test_value(double value) { + int exponent; + double x = frexp(value, &exponent); + double expected = x * pow(2.0, exponent); - void test_value(double value) - { - int exponent; - double x=frexp(value, &exponent); - double expected=x*pow(2.0, exponent); + printf("%f=%f*2^%d\n", value, x, exponent); - printf("%f=%f*2^%d\n", value, x, exponent); + assert(fabs(expected - value) < tol); + assert(x == 0 || (fabs(x) >= 5e-1 && fabs(x) < 1)); // x has a magnitude in + // the interval [1/2, 1) +} - assert(fabs(expected-value)<tol); - assert(x==0 || (fabs(x)>=5e-1 && fabs(x)<1)); // x has a magnitude in the interval [1/2, 1) - } +int main() { + test_value(0); + test_value(100.1); + test_value(-100.1); + test_value(.5); + test_value(-.5); + test_value(1 - 1e-16); + test_value(-(1 - 1e-16)); - int main() - { - test_value(0); - test_value(100.1); - test_value(-100.1); - test_value(.5); - test_value(-.5); - test_value(1-1e-16); - test_value(-(1-1e-16)); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_funcptr.in b/tests/core/test_funcptr.in index 8328924a..23813b33 100644 --- a/tests/core/test_funcptr.in +++ b/tests/core/test_funcptr.in @@ -1,35 +1,33 @@ +#include <stdio.h> +int calc1() { return 26; } +int calc2() { return 90; } +typedef int (*fp_t)(); - #include <stdio.h> - int calc1() { return 26; } - int calc2() { return 90; } - typedef int (*fp_t)(); +fp_t globally1 = calc1; +fp_t globally2 = calc2; - fp_t globally1 = calc1; - fp_t globally2 = calc2; +int nothing(const char *str) { return 0; } - int nothing(const char *str) { return 0; } +int main() { + fp_t fp = calc1; + void *vp = (void *)fp; + fp_t fpb = (fp_t)vp; + fp_t fp2 = calc2; + void *vp2 = (void *)fp2; + fp_t fpb2 = (fp_t)vp2; + printf("*%d,%d,%d,%d,%d,%d*\n", fp(), fpb(), fp2(), fpb2(), globally1(), + globally2()); - int main() - { - fp_t fp = calc1; - void *vp = (void*)fp; - fp_t fpb = (fp_t)vp; - fp_t fp2 = calc2; - void *vp2 = (void*)fp2; - fp_t fpb2 = (fp_t)vp2; - printf("*%d,%d,%d,%d,%d,%d*\n", fp(), fpb(), fp2(), fpb2(), globally1(), globally2()); + fp_t t = calc1; + printf("*%d,%d", t == calc1, t == calc2); + t = calc2; + printf(",%d,%d*\n", t == calc1, t == calc2); - fp_t t = calc1; - printf("*%d,%d", t == calc1, t == calc2); - t = calc2; - printf(",%d,%d*\n", t == calc1, t == calc2); + int (*other)(const char * str); + other = nothing; + other("*hello!*"); + other = puts; + other("*goodbye!*"); - int (*other)(const char *str); - other = nothing; - other("*hello!*"); - other = puts; - other("*goodbye!*"); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_funcptr_namecollide.in b/tests/core/test_funcptr_namecollide.in index 0b27b07c..dc5cfaba 100644 --- a/tests/core/test_funcptr_namecollide.in +++ b/tests/core/test_funcptr_namecollide.in @@ -1,27 +1,24 @@ +#include <stdio.h> - #include <stdio.h> +void do_call(void (*puts)(const char *), const char *str); - void do_call(void (*puts)(const char *), const char *str); +void do_print(const char *str) { + if (!str) do_call(NULL, "delusion"); + if ((int)str == -1) do_print(str + 10); + puts("===="); + puts(str); + puts("===="); +} - void do_print(const char *str) { - if (!str) do_call(NULL, "delusion"); - if ((int)str == -1) do_print(str+10); - puts("===="); - puts(str); - puts("===="); - } +void do_call(void (*puts)(const char *), const char *str) { + if (!str) do_print("confusion"); + if ((int)str == -1) do_call(NULL, str - 10); + (*puts)(str); +} - void do_call(void (*puts)(const char *), const char *str) { - if (!str) do_print("confusion"); - if ((int)str == -1) do_call(NULL, str-10); - (*puts)(str); - } - - int main(int argc, char **argv) - { - for (int i = 0; i < argc; i++) { - do_call(i != 10 ? do_print : NULL, i != 15 ? "waka waka" : NULL); - } - return 0; - } -
\ No newline at end of file +int main(int argc, char **argv) { + for (int i = 0; i < argc; i++) { + do_call(i != 10 ? do_print : NULL, i != 15 ? "waka waka" : NULL); + } + return 0; +} diff --git a/tests/core/test_funcptrfunc.in b/tests/core/test_funcptrfunc.in index 6c146421..c6487b88 100644 --- a/tests/core/test_funcptrfunc.in +++ b/tests/core/test_funcptrfunc.in @@ -1,17 +1,12 @@ +#include <stdio.h> - #include <stdio.h> +typedef void (*funcptr)(int, int); +typedef funcptr (*funcptrfunc)(int); - typedef void (*funcptr)(int, int); - typedef funcptr (*funcptrfunc)(int); +funcptr __attribute__((noinline)) getIt(int x) { return (funcptr)x; } - funcptr __attribute__ ((noinline)) getIt(int x) { - return (funcptr)x; - } - - int main(int argc, char **argv) - { - funcptrfunc fpf = argc < 100 ? getIt : NULL; - printf("*%p*\n", fpf(argc)); - return 0; - } -
\ No newline at end of file +int main(int argc, char **argv) { + funcptrfunc fpf = argc < 100 ? getIt : NULL; + printf("*%p*\n", fpf(argc)); + return 0; +} diff --git a/tests/core/test_funcs.in b/tests/core/test_funcs.in index f2e707f9..3619faec 100644 --- a/tests/core/test_funcs.in +++ b/tests/core/test_funcs.in @@ -1,12 +1,6 @@ - - #include <stdio.h> - int funcy(int x) - { - return x*9; - } - int main() - { - printf("*%d,%d*\n", funcy(8), funcy(10)); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +int funcy(int x) { return x * 9; } +int main() { + printf("*%d,%d*\n", funcy(8), funcy(10)); + return 0; +} diff --git a/tests/core/test_functionpointer_libfunc_varargs.in b/tests/core/test_functionpointer_libfunc_varargs.in index 6cabe8c5..69faefa2 100644 --- a/tests/core/test_functionpointer_libfunc_varargs.in +++ b/tests/core/test_functionpointer_libfunc_varargs.in @@ -1,13 +1,11 @@ - - #include <stdio.h> - #include <fcntl.h> - typedef int (*fp_t)(int, int, ...); - int main(int argc, char **argv) { - fp_t fp = &fcntl; - if (argc == 1337) fp = (fp_t)&main; - (*fp)(0, 10); - (*fp)(0, 10, 5); - printf("waka\n"); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <fcntl.h> +typedef int (*fp_t)(int, int, ...); +int main(int argc, char **argv) { + fp_t fp = &fcntl; + if (argc == 1337) fp = (fp_t) & main; + (*fp)(0, 10); + (*fp)(0, 10, 5); + printf("waka\n"); + return 0; +} diff --git a/tests/core/test_fwrite_0.in b/tests/core/test_fwrite_0.in index 478524bb..990ab250 100644 --- a/tests/core/test_fwrite_0.in +++ b/tests/core/test_fwrite_0.in @@ -1,21 +1,18 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +int main() { + FILE *fh; - int main () - { - FILE *fh; + fh = fopen("a.txt", "wb"); + if (!fh) exit(1); + fclose(fh); - fh = fopen("a.txt", "wb"); - if (!fh) exit(1); - fclose(fh); + fh = fopen("a.txt", "rb"); + if (!fh) exit(1); - fh = fopen("a.txt", "rb"); - if (!fh) exit(1); + char data[] = "foobar"; + size_t written = fwrite(data, 1, sizeof(data), fh); - char data[] = "foobar"; - size_t written = fwrite(data, 1, sizeof(data), fh); - - printf("written=%zu\n", written); - } -
\ No newline at end of file + printf("written=%zu\n", written); +} diff --git a/tests/core/test_gc.in b/tests/core/test_gc.in index ae94b0ec..55d98e60 100644 --- a/tests/core/test_gc.in +++ b/tests/core/test_gc.in @@ -1,107 +1,107 @@ +#include <stdio.h> +#include <gc.h> +#include <assert.h> - #include <stdio.h> - #include <gc.h> - #include <assert.h> +void *global; - void *global; +void finalizer(void *ptr, void *arg) { + printf("finalizing %d (global == %d)\n", (int)arg, ptr == global); +} - void finalizer(void *ptr, void *arg) { - printf("finalizing %d (global == %d)\n", (int)arg, ptr == global); - } +void finalizer2(void *ptr, void *arg) { + printf("finalizing2 %d (global == %d)\n", (int)arg, ptr == global); +} - void finalizer2(void *ptr, void *arg) { - printf("finalizing2 %d (global == %d)\n", (int)arg, ptr == global); - } +int main() { + GC_INIT(); - int main() { - GC_INIT(); + void *local, *local2, *local3, *local4, *local5, *local6; - void *local, *local2, *local3, *local4, *local5, *local6; + // Hold on to global, drop locals - // Hold on to global, drop locals + global = GC_MALLOC(1024); // rooted since in a static allocation + GC_REGISTER_FINALIZER_NO_ORDER(global, finalizer, 0, 0, 0); + printf("alloc %p\n", global); - global = GC_MALLOC(1024); // rooted since in a static allocation - GC_REGISTER_FINALIZER_NO_ORDER(global, finalizer, 0, 0, 0); - printf("alloc %p\n", global); + local = GC_MALLOC(1024); // not rooted since stack is not scanned + GC_REGISTER_FINALIZER_NO_ORDER(local, finalizer, (void *)1, 0, 0); + printf("alloc %p\n", local); - local = GC_MALLOC(1024); // not rooted since stack is not scanned - GC_REGISTER_FINALIZER_NO_ORDER(local, finalizer, (void*)1, 0, 0); - printf("alloc %p\n", local); + assert((char *)local - (char *)global >= 1024 || + (char *)global - (char *)local >= 1024); - assert((char*)local - (char*)global >= 1024 || (char*)global - (char*)local >= 1024); + local2 = GC_MALLOC(1024); // no finalizer + printf("alloc %p\n", local2); - local2 = GC_MALLOC(1024); // no finalizer - printf("alloc %p\n", local2); + local3 = GC_MALLOC(1024); // with finalizable2 + GC_REGISTER_FINALIZER_NO_ORDER(local3, finalizer2, (void *)2, 0, 0); + printf("alloc %p\n", local); - local3 = GC_MALLOC(1024); // with finalizable2 - GC_REGISTER_FINALIZER_NO_ORDER(local3, finalizer2, (void*)2, 0, 0); - printf("alloc %p\n", local); + local4 = GC_MALLOC(1024); // yet another + GC_REGISTER_FINALIZER_NO_ORDER(local4, finalizer2, (void *)3, 0, 0); + printf("alloc %p\n", local); - local4 = GC_MALLOC(1024); // yet another - GC_REGISTER_FINALIZER_NO_ORDER(local4, finalizer2, (void*)3, 0, 0); - printf("alloc %p\n", local); + printf("basic test\n"); - printf("basic test\n"); + GC_FORCE_COLLECT(); - GC_FORCE_COLLECT(); + printf("*\n"); - printf("*\n"); + GC_FREE(global); // force free will actually work - GC_FREE(global); // force free will actually work + // scanning inside objects - // scanning inside objects + global = GC_MALLOC(12); + GC_REGISTER_FINALIZER_NO_ORDER(global, finalizer, 0, 0, 0); + local = GC_MALLOC(12); + GC_REGISTER_FINALIZER_NO_ORDER(local, finalizer, (void *)1, 0, 0); + local2 = GC_MALLOC_ATOMIC(12); + GC_REGISTER_FINALIZER_NO_ORDER(local2, finalizer, (void *)2, 0, 0); + local3 = GC_MALLOC(12); + GC_REGISTER_FINALIZER_NO_ORDER(local3, finalizer, (void *)3, 0, 0); + local4 = GC_MALLOC(12); + GC_REGISTER_FINALIZER_NO_ORDER(local4, finalizer, (void *)4, 0, 0); + local5 = GC_MALLOC_UNCOLLECTABLE(12); + // This should never trigger since local5 is uncollectable + GC_REGISTER_FINALIZER_NO_ORDER(local5, finalizer, (void *)5, 0, 0); - global = GC_MALLOC(12); - GC_REGISTER_FINALIZER_NO_ORDER(global, finalizer, 0, 0, 0); - local = GC_MALLOC(12); - GC_REGISTER_FINALIZER_NO_ORDER(local, finalizer, (void*)1, 0, 0); - local2 = GC_MALLOC_ATOMIC(12); - GC_REGISTER_FINALIZER_NO_ORDER(local2, finalizer, (void*)2, 0, 0); - local3 = GC_MALLOC(12); - GC_REGISTER_FINALIZER_NO_ORDER(local3, finalizer, (void*)3, 0, 0); - local4 = GC_MALLOC(12); - GC_REGISTER_FINALIZER_NO_ORDER(local4, finalizer, (void*)4, 0, 0); - local5 = GC_MALLOC_UNCOLLECTABLE(12); - // This should never trigger since local5 is uncollectable - GC_REGISTER_FINALIZER_NO_ORDER(local5, finalizer, (void*)5, 0, 0); + printf("heap size = %d\n", GC_get_heap_size()); - printf("heap size = %d\n", GC_get_heap_size()); + local4 = GC_REALLOC(local4, 24); - local4 = GC_REALLOC(local4, 24); + printf("heap size = %d\n", GC_get_heap_size()); - printf("heap size = %d\n", GC_get_heap_size()); + local6 = GC_MALLOC(12); + GC_REGISTER_FINALIZER_NO_ORDER(local6, finalizer, (void *)6, 0, 0); + // This should be the same as a free + GC_REALLOC(local6, 0); - local6 = GC_MALLOC(12); - GC_REGISTER_FINALIZER_NO_ORDER(local6, finalizer, (void*)6, 0, 0); - // This should be the same as a free - GC_REALLOC(local6, 0); + void **globalData = (void **)global; + globalData[0] = local; + globalData[1] = local2; - void **globalData = (void**)global; - globalData[0] = local; - globalData[1] = local2; + void **localData = (void **)local; + localData[0] = local3; - void **localData = (void**)local; - localData[0] = local3; + void **local2Data = (void **)local2; + local2Data[0] = + local4; // actually ignored, because local2 is atomic, so 4 is freeable - void **local2Data = (void**)local2; - local2Data[0] = local4; // actually ignored, because local2 is atomic, so 4 is freeable + printf("object scan test test\n"); - printf("object scan test test\n"); + GC_FORCE_COLLECT(); - GC_FORCE_COLLECT(); + printf("*\n"); - printf("*\n"); + GC_FREE(global); // force free will actually work - GC_FREE(global); // force free will actually work + printf("*\n"); - printf("*\n"); + GC_FORCE_COLLECT(); - GC_FORCE_COLLECT(); + printf(".\n"); - printf(".\n"); + global = 0; - global = 0; - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_getgep.in b/tests/core/test_getgep.in index b92c4a1a..452942f9 100644 --- a/tests/core/test_getgep.in +++ b/tests/core/test_getgep.in @@ -1,17 +1,14 @@ +#include <stdio.h> +struct { + int y[10]; + int z[10]; +} commonblock; - #include <stdio.h> - struct { - int y[10]; - int z[10]; - } commonblock; - - int main() - { - for (int i = 0; i < 10; ++i) { - commonblock.y[i] = 1; - commonblock.z[i] = 2; - } - printf("*%d %d*\n", commonblock.y[0], commonblock.z[0]); - return 0; - } -
\ No newline at end of file +int main() { + for (int i = 0; i < 10; ++i) { + commonblock.y[i] = 1; + commonblock.z[i] = 2; + } + printf("*%d %d*\n", commonblock.y[0], commonblock.z[0]); + return 0; +} diff --git a/tests/core/test_getloadavg.in b/tests/core/test_getloadavg.in index 8365a9a1..c592985a 100644 --- a/tests/core/test_getloadavg.in +++ b/tests/core/test_getloadavg.in @@ -1,15 +1,13 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> - - int main() { - double load[5] = {42.13, 42.13, 42.13, 42.13, 42.13}; - printf("ret: %d\n", getloadavg(load, 5)); - printf("load[0]: %.3lf\n", load[0]); - printf("load[1]: %.3lf\n", load[1]); - printf("load[2]: %.3lf\n", load[2]); - printf("load[3]: %.3lf\n", load[3]); - printf("load[4]: %.3lf\n", load[4]); - return 0; - } -
\ No newline at end of file +int main() { + double load[5] = {42.13, 42.13, 42.13, 42.13, 42.13}; + printf("ret: %d\n", getloadavg(load, 5)); + printf("load[0]: %.3lf\n", load[0]); + printf("load[1]: %.3lf\n", load[1]); + printf("load[2]: %.3lf\n", load[2]); + printf("load[3]: %.3lf\n", load[3]); + printf("load[4]: %.3lf\n", load[4]); + return 0; +} diff --git a/tests/core/test_getopt.in b/tests/core/test_getopt.in index 1f03ef4e..6a678b79 100644 --- a/tests/core/test_getopt.in +++ b/tests/core/test_getopt.in @@ -1,45 +1,40 @@ - - #pragma clang diagnostic ignored "-Winvalid-pp-token" - #include <unistd.h> - #include <stdlib.h> - #include <stdio.h> - - int - main(int argc, char *argv[]) - { - int flags, opt; - int nsecs, tfnd; - - nsecs = 0; - tfnd = 0; - flags = 0; - while ((opt = getopt(argc, argv, "nt:")) != -1) { - switch (opt) { - case 'n': - flags = 1; - break; - case 't': - nsecs = atoi(optarg); - tfnd = 1; - break; - default: /* '?' */ - fprintf(stderr, "Usage: %s [-t nsecs] [-n] name\n", - argv[0]); - exit(EXIT_FAILURE); - } - } - - printf("flags=%d; tfnd=%d; optind=%d\n", flags, tfnd, optind); - - if (optind >= argc) { - fprintf(stderr, "Expected argument after options\n"); - exit(EXIT_FAILURE); - } - - printf("name argument = %s\n", argv[optind]); - - /* Other code omitted */ - - exit(EXIT_SUCCESS); - } -
\ No newline at end of file +#pragma clang diagnostic ignored "-Winvalid-pp-token" +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> + +int main(int argc, char *argv[]) { + int flags, opt; + int nsecs, tfnd; + + nsecs = 0; + tfnd = 0; + flags = 0; + while ((opt = getopt(argc, argv, "nt:")) != -1) { + switch (opt) { + case 'n': + flags = 1; + break; + case 't': + nsecs = atoi(optarg); + tfnd = 1; + break; + default: /* '?' */ + fprintf(stderr, "Usage: %s [-t nsecs] [-n] name\n", argv[0]); + exit(EXIT_FAILURE); + } + } + + printf("flags=%d; tfnd=%d; optind=%d\n", flags, tfnd, optind); + + if (optind >= argc) { + fprintf(stderr, "Expected argument after options\n"); + exit(EXIT_FAILURE); + } + + printf("name argument = %s\n", argv[optind]); + + /* Other code omitted */ + + exit(EXIT_SUCCESS); +} diff --git a/tests/core/test_getopt_long.in b/tests/core/test_getopt_long.in index cc5c3e21..18f19f2e 100644 --- a/tests/core/test_getopt_long.in +++ b/tests/core/test_getopt_long.in @@ -1,82 +1,73 @@ +#pragma clang diagnostic ignored "-Winvalid-pp-token" +#pragma clang diagnostic ignored "-Wdeprecated-writable-strings" +#include <stdio.h> /* for printf */ +#include <stdlib.h> /* for exit */ +#include <getopt.h> - #pragma clang diagnostic ignored "-Winvalid-pp-token" - #pragma clang diagnostic ignored "-Wdeprecated-writable-strings" - #include <stdio.h> /* for printf */ - #include <stdlib.h> /* for exit */ - #include <getopt.h> +int main(int argc, char **argv) { + int c; + int digit_optind = 0; - int - main(int argc, char **argv) - { - int c; - int digit_optind = 0; + while (1) { + int this_option_optind = optind ? optind : 1; + int option_index = 0; + static struct option long_options[] = { + {"add", required_argument, 0, 0}, + {"append", no_argument, 0, 0}, + {"delete", required_argument, 0, 0}, + {"verbose", no_argument, 0, 0}, + {"create", required_argument, 0, 'c'}, + {"file", required_argument, 0, 0}, + {0, 0, 0, 0}}; - while (1) { - int this_option_optind = optind ? optind : 1; - int option_index = 0; - static struct option long_options[] = { - {"add", required_argument, 0, 0 }, - {"append", no_argument, 0, 0 }, - {"delete", required_argument, 0, 0 }, - {"verbose", no_argument, 0, 0 }, - {"create", required_argument, 0, 'c'}, - {"file", required_argument, 0, 0 }, - {0, 0, 0, 0 } - }; + c = getopt_long(argc, argv, "abc:d:012", long_options, &option_index); + if (c == -1) break; - c = getopt_long(argc, argv, "abc:d:012", - long_options, &option_index); - if (c == -1) - break; + switch (c) { + case 0: + printf("option %s", long_options[option_index].name); + if (optarg) printf(" with arg %s", optarg); + printf("\n"); + break; - switch (c) { - case 0: - printf("option %s", long_options[option_index].name); - if (optarg) - printf(" with arg %s", optarg); - printf("\n"); - break; + case '0': + case '1': + case '2': + if (digit_optind != 0 && digit_optind != this_option_optind) + printf("digits occur in two different argv-elements.\n"); + digit_optind = this_option_optind; + printf("option %c\n", c); + break; - case '0': - case '1': - case '2': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf("option %c\n", c); - break; + case 'a': + printf("option a\n"); + break; - case 'a': - printf("option a\n"); - break; + case 'b': + printf("option b\n"); + break; - case 'b': - printf("option b\n"); - break; + case 'c': + printf("option c with value '%s'\n", optarg); + break; - case 'c': - printf("option c with value '%s'\n", optarg); - break; + case 'd': + printf("option d with value '%s'\n", optarg); + break; - case 'd': - printf("option d with value '%s'\n", optarg); - break; + case '?': + break; - case '?': - break; + default: + printf("?? getopt returned character code 0%o ??\n", c); + } + } - default: - printf("?? getopt returned character code 0%o ??\n", c); - } - } + if (optind < argc) { + printf("non-option ARGV-elements: "); + while (optind < argc) printf("%s ", argv[optind++]); + printf("\n"); + } - if (optind < argc) { - printf("non-option ARGV-elements: "); - while (optind < argc) - printf("%s ", argv[optind++]); - printf("\n"); - } - - exit(EXIT_SUCCESS); - } -
\ No newline at end of file + exit(EXIT_SUCCESS); +} diff --git a/tests/core/test_globaldoubles.in b/tests/core/test_globaldoubles.in index 45acc194..9ccfb521 100644 --- a/tests/core/test_globaldoubles.in +++ b/tests/core/test_globaldoubles.in @@ -1,26 +1,23 @@ +#include <stdlib.h> +#include <stdio.h> - #include <stdlib.h> - #include <stdio.h> +double testVu, testVv, testWu, testWv; - double testVu, testVv, testWu, testWv; +void Test(double _testVu, double _testVv, double _testWu, double _testWv) { + testVu = _testVu; + testVv = _testVv; + testWu = _testWu; + testWv = _testWv; + printf("BUG?\n"); + printf("Display: Vu=%f Vv=%f Wu=%f Wv=%f\n", testVu, testVv, testWu, + testWv); +} - void Test(double _testVu, double _testVv, double _testWu, double _testWv) - { - testVu = _testVu; - testVv = _testVv; - testWu = _testWu; - testWv = _testWv; - printf("BUG?\n"); - printf("Display: Vu=%f Vv=%f Wu=%f Wv=%f\n", testVu, testVv, testWu, testWv); - } - - int main(void) - { - double v1 = 465.1; - double v2 = 465.2; - double v3 = 160.3; - double v4 = 111.4; - Test(v1, v2, v3, v4); - return 0; - } -
\ No newline at end of file +int main(void) { + double v1 = 465.1; + double v2 = 465.2; + double v3 = 160.3; + double v4 = 111.4; + Test(v1, v2, v3, v4); + return 0; +} diff --git a/tests/core/test_globals.in b/tests/core/test_globals.in index ed5e7891..f972687a 100644 --- a/tests/core/test_globals.in +++ b/tests/core/test_globals.in @@ -1,13 +1,10 @@ +#include <stdio.h> - #include <stdio.h> +char cache[256], *next = cache; - char cache[256], *next = cache; - - int main() - { - cache[10] = 25; - next[20] = 51; - printf("*%d,%d*\n", next[10], cache[20]); - return 0; - } -
\ No newline at end of file +int main() { + cache[10] = 25; + next[20] = 51; + printf("*%d,%d*\n", next[10], cache[20]); + return 0; +} diff --git a/tests/core/test_gmtime.in b/tests/core/test_gmtime.in index 41ce87f9..7b7227ba 100644 --- a/tests/core/test_gmtime.in +++ b/tests/core/test_gmtime.in @@ -1,28 +1,26 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <assert.h> - #include <stdio.h> - #include <stdlib.h> - #include <time.h> - #include <assert.h> +int main(void) { + time_t t = time(NULL); + struct tm *ptm = gmtime(&t); + struct tm tmCurrent = *ptm; + int hour = tmCurrent.tm_hour; - int main(void) - { - time_t t=time(NULL); - struct tm *ptm=gmtime(&t); - struct tm tmCurrent=*ptm; - int hour=tmCurrent.tm_hour; - - t-=hour*3600; // back to midnight - int yday = -1; - for(hour=0;hour<24;hour++) - { - ptm=gmtime(&t); - // tm_yday must be constant all day... - printf("yday: %d, hour: %d\n", ptm->tm_yday, hour); - if (yday == -1) yday = ptm->tm_yday; - else assert(yday == ptm->tm_yday); - t+=3600; // add one hour - } - printf("ok!\n"); - return(0); - } -
\ No newline at end of file + t -= hour * 3600; // back to midnight + int yday = -1; + for (hour = 0; hour < 24; hour++) { + ptm = gmtime(&t); + // tm_yday must be constant all day... + printf("yday: %d, hour: %d\n", ptm->tm_yday, hour); + if (yday == -1) + yday = ptm->tm_yday; + else + assert(yday == ptm->tm_yday); + t += 3600; // add one hour + } + printf("ok!\n"); + return (0); +} diff --git a/tests/core/test_hello_world.in b/tests/core/test_hello_world.in index d9ca3acb..b1d9bbbc 100644 --- a/tests/core/test_hello_world.in +++ b/tests/core/test_hello_world.in @@ -1,8 +1,5 @@ - - #include <stdio.h> - int main() - { - printf("hello, world!\n"); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +int main() { + printf("hello, world!\n"); + return 0; +} diff --git a/tests/core/test_i16_emcc_intrinsic.in b/tests/core/test_i16_emcc_intrinsic.in index 54008cee..a2aa27ee 100644 --- a/tests/core/test_i16_emcc_intrinsic.in +++ b/tests/core/test_i16_emcc_intrinsic.in @@ -1,20 +1,18 @@ +#include <stdio.h> - #include <stdio.h> +int test(unsigned short a, unsigned short b) { + unsigned short result = a; + result += b; + if (result < b) printf("C!"); + return result; +} - int test(unsigned short a, unsigned short b) { - unsigned short result = a; - result += b; - if (result < b) printf("C!"); - return result; - } - - int main(void) { - printf(",%d,", test(0, 0)); - printf(",%d,", test(1, 1)); - printf(",%d,", test(65535, 1)); - printf(",%d,", test(1, 65535)); - printf(",%d,", test(32768, 32767)); - printf(",%d,", test(32768, 32768)); - return 0; - } -
\ No newline at end of file +int main(void) { + printf(",%d,", test(0, 0)); + printf(",%d,", test(1, 1)); + printf(",%d,", test(65535, 1)); + printf(",%d,", test(1, 65535)); + printf(",%d,", test(32768, 32767)); + printf(",%d,", test(32768, 32768)); + return 0; +} diff --git a/tests/core/test_i32_mul_precise.in b/tests/core/test_i32_mul_precise.in index f045a768..2e62b4ba 100644 --- a/tests/core/test_i32_mul_precise.in +++ b/tests/core/test_i32_mul_precise.in @@ -1,11 +1,12 @@ +#include <stdio.h> - #include <stdio.h> - - int main(int argc, char **argv) { - unsigned long d1 = 0x847c9b5d; - unsigned long q = 0x549530e1; - if (argc > 1000) { q += argc; d1 -= argc; } // confuse optimizer - printf("%lu\n", d1*q); - return 0; - } -
\ No newline at end of file +int main(int argc, char **argv) { + unsigned long d1 = 0x847c9b5d; + unsigned long q = 0x549530e1; + if (argc > 1000) { + q += argc; + d1 -= argc; + } // confuse optimizer + printf("%lu\n", d1 * q); + return 0; +} diff --git a/tests/core/test_i32_mul_semiprecise.in b/tests/core/test_i32_mul_semiprecise.in index c7b4cb96..a93a69da 100644 --- a/tests/core/test_i32_mul_semiprecise.in +++ b/tests/core/test_i32_mul_semiprecise.in @@ -1,28 +1,26 @@ +#include <stdio.h> - #include <stdio.h> +typedef unsigned int uint; - typedef unsigned int uint; +// from cube2, zlib licensed - // from cube2, zlib licensed +#define N (624) +#define M (397) +#define K (0x9908B0DFU) - #define N (624) - #define M (397) - #define K (0x9908B0DFU) +static uint state[N]; +static int next = N; - static uint state[N]; - static int next = N; +void seedMT(uint seed) { + state[0] = seed; + for (uint i = 1; i < N; i++) // if we do not do this precisely, at least we + // should coerce to int immediately, not wait + state[i] = seed = 1812433253U * (seed ^ (seed >> 30)) + i; + next = 0; +} - void seedMT(uint seed) - { - state[0] = seed; - for(uint i = 1; i < N; i++) // if we do not do this precisely, at least we should coerce to int immediately, not wait - state[i] = seed = 1812433253U * (seed ^ (seed >> 30)) + i; - next = 0; - } - - int main() { - seedMT(5497); - for (int i = 0; i < 10; i++) printf("%d: %u\n", i, state[i]); - return 0; - } -
\ No newline at end of file +int main() { + seedMT(5497); + for (int i = 0; i < 10; i++) printf("%d: %u\n", i, state[i]); + return 0; +} diff --git a/tests/core/test_i64_7z.in b/tests/core/test_i64_7z.in index 1d2f03a8..c15bfd78 100644 --- a/tests/core/test_i64_7z.in +++ b/tests/core/test_i64_7z.in @@ -1,17 +1,14 @@ - - #include <stdint.h> - #include <stdio.h> - uint64_t a, b; - int main(int argc, char *argv[]) - { - a = argc; - b = argv[1][0]; - printf("%d,%d\n", a, b); - if (a > a + b || a > a + b + 1) { - printf("one %lld, %lld", a, b); - return 0; - } - printf("zero %lld, %lld", a, b); - return 0; - } -
\ No newline at end of file +#include <stdint.h> +#include <stdio.h> +uint64_t a, b; +int main(int argc, char *argv[]) { + a = argc; + b = argv[1][0]; + printf("%d,%d\n", a, b); + if (a > a + b || a > a + b + 1) { + printf("one %lld, %lld", a, b); + return 0; + } + printf("zero %lld, %lld", a, b); + return 0; +} diff --git a/tests/core/test_i64_b.in b/tests/core/test_i64_b.in index b373a3aa..1cd87104 100644 --- a/tests/core/test_i64_b.in +++ b/tests/core/test_i64_b.in @@ -1,22 +1,20 @@ +#include <stdio.h> +#include <sys/time.h> - #include <stdio.h> - #include <sys/time.h> +typedef long long int64; - typedef long long int64; +#define PRMJ_USEC_PER_SEC 1000000L - #define PRMJ_USEC_PER_SEC 1000000L - - int main(int argc, char * argv[]) { - int64 sec = 1329409675 + argc; - int64 usec = 2329509675; - int64 mul = int64(sec) * PRMJ_USEC_PER_SEC; - int64 add = mul + int64(usec); - int add_low = add; - int add_high = add >> 32; - printf("*%lld,%lld,%u,%u*\n", mul, add, add_low, add_high); - int64 x = sec + (usec << 25); - x >>= argc*3; - printf("*%llu*\n", x); - return 0; - } -
\ No newline at end of file +int main(int argc, char* argv[]) { + int64 sec = 1329409675 + argc; + int64 usec = 2329509675; + int64 mul = int64(sec) * PRMJ_USEC_PER_SEC; + int64 add = mul + int64(usec); + int add_low = add; + int add_high = add >> 32; + printf("*%lld,%lld,%u,%u*\n", mul, add, add_low, add_high); + int64 x = sec + (usec << 25); + x >>= argc * 3; + printf("*%llu*\n", x); + return 0; +} diff --git a/tests/core/test_i64_cmp.in b/tests/core/test_i64_cmp.in index b967d2ff..b9cadd4a 100644 --- a/tests/core/test_i64_cmp.in +++ b/tests/core/test_i64_cmp.in @@ -1,18 +1,14 @@ +#include <stdio.h> - #include <stdio.h> +typedef long long int64; - typedef long long int64; +bool compare(int64 val) { return val == -12; } - bool compare(int64 val) { - return val == -12; - } +bool compare2(int64 val) { return val < -12; } - bool compare2(int64 val) { - return val < -12; - } - - int main(int argc, char * argv[]) { - printf("*%d,%d,%d,%d,%d,%d*\n", argc, compare(argc-1-12), compare(1000+argc), compare2(argc-1-10), compare2(argc-1-14), compare2(argc+1000)); - return 0; - } -
\ No newline at end of file +int main(int argc, char* argv[]) { + printf("*%d,%d,%d,%d,%d,%d*\n", argc, compare(argc - 1 - 12), + compare(1000 + argc), compare2(argc - 1 - 10), compare2(argc - 1 - 14), + compare2(argc + 1000)); + return 0; +} diff --git a/tests/core/test_i64_cmp2.in b/tests/core/test_i64_cmp2.in index b285e1a1..8985e5a8 100644 --- a/tests/core/test_i64_cmp2.in +++ b/tests/core/test_i64_cmp2.in @@ -1,32 +1,28 @@ +#include <inttypes.h> +#include <stdio.h> - #include <inttypes.h> - #include <stdio.h> +typedef int32_t INT32; +typedef int64_t INT64; +typedef uint8_t UINT8; - typedef int32_t INT32; - typedef int64_t INT64; - typedef uint8_t UINT8; +void interface_clock_changed() { + UINT8 m_divshift; + INT32 m_divisor; - void interface_clock_changed() - { - UINT8 m_divshift; - INT32 m_divisor; + // INT64 attos = m_attoseconds_per_cycle; + INT64 attos = 279365114840; + m_divshift = 0; + while (attos >= (1UL << 31)) { + m_divshift++; + printf("m_divshift is %i, on %Ld >?= %lu\n", m_divshift, attos, 1UL << 31); + attos >>= 1; + } + m_divisor = attos; - //INT64 attos = m_attoseconds_per_cycle; - INT64 attos = 279365114840; - m_divshift = 0; - while (attos >= (1UL << 31)) - { - m_divshift++; - printf("m_divshift is %i, on %Ld >?= %lu\n", m_divshift, attos, 1UL << 31); - attos >>= 1; - } - m_divisor = attos; + printf("m_divisor is %i\n", m_divisor); +} - printf("m_divisor is %i\n",m_divisor); - } - - int main() { - interface_clock_changed(); - return 0; - } -
\ No newline at end of file +int main() { + interface_clock_changed(); + return 0; +} diff --git a/tests/core/test_i64_double.in b/tests/core/test_i64_double.in index 4b39355e..2b524971 100644 --- a/tests/core/test_i64_double.in +++ b/tests/core/test_i64_double.in @@ -1,38 +1,34 @@ +#include <stdio.h> - #include <stdio.h> +typedef long long int64; +#define JSDOUBLE_HI32_SIGNBIT 0x80000000 - typedef long long int64; - #define JSDOUBLE_HI32_SIGNBIT 0x80000000 +bool JSDOUBLE_IS_NEGZERO(double d) { + union { + struct { + unsigned int lo, hi; + } s; + double d; + } x; + if (d != 0) return false; + x.d = d; + return (x.s.hi & JSDOUBLE_HI32_SIGNBIT) != 0; +} - bool JSDOUBLE_IS_NEGZERO(double d) - { - union { - struct { - unsigned int lo, hi; - } s; - double d; - } x; - if (d != 0) - return false; - x.d = d; - return (x.s.hi & JSDOUBLE_HI32_SIGNBIT) != 0; - } +bool JSINT64_IS_NEGZERO(int64 l) { + union { + int64 i; + double d; + } x; + if (l != 0) return false; + x.i = l; + return x.d == -0; +} - bool JSINT64_IS_NEGZERO(int64 l) - { - union { - int64 i; - double d; - } x; - if (l != 0) - return false; - x.i = l; - return x.d == -0; - } - - int main(int argc, char * argv[]) { - printf("*%d,%d,%d,%d*\n", JSDOUBLE_IS_NEGZERO(0), JSDOUBLE_IS_NEGZERO(-0), JSDOUBLE_IS_NEGZERO(-1), JSDOUBLE_IS_NEGZERO(+1)); - printf("*%d,%d,%d,%d*\n", JSINT64_IS_NEGZERO(0), JSINT64_IS_NEGZERO(-0), JSINT64_IS_NEGZERO(-1), JSINT64_IS_NEGZERO(+1)); - return 0; - } -
\ No newline at end of file +int main(int argc, char* argv[]) { + printf("*%d,%d,%d,%d*\n", JSDOUBLE_IS_NEGZERO(0), JSDOUBLE_IS_NEGZERO(-0), + JSDOUBLE_IS_NEGZERO(-1), JSDOUBLE_IS_NEGZERO(+1)); + printf("*%d,%d,%d,%d*\n", JSINT64_IS_NEGZERO(0), JSINT64_IS_NEGZERO(-0), + JSINT64_IS_NEGZERO(-1), JSINT64_IS_NEGZERO(+1)); + return 0; +} diff --git a/tests/core/test_i64_i16.in b/tests/core/test_i64_i16.in index dcd9a69e..81d4a7bd 100644 --- a/tests/core/test_i64_i16.in +++ b/tests/core/test_i64_i16.in @@ -1,12 +1,10 @@ - - #include <stdint.h> - #include <stdio.h> - int main(int argc, char ** argv){ - int y=-133; - int64_t x= ((int64_t)((short)(y)))*(100 + argc); - if(x>0) - printf(">0\n"); - else - printf("<=0\n"); - } -
\ No newline at end of file +#include <stdint.h> +#include <stdio.h> +int main(int argc, char** argv) { + int y = -133; + int64_t x = ((int64_t)((short)(y))) * (100 + argc); + if (x > 0) + printf(">0\n"); + else + printf("<=0\n"); +} diff --git a/tests/core/test_i64_llabs.in b/tests/core/test_i64_llabs.in index 10961970..5d10bee0 100644 --- a/tests/core/test_i64_llabs.in +++ b/tests/core/test_i64_llabs.in @@ -1,9 +1,7 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> - - int main(int argc, char ** argv) { - printf("%lld,%lld\n", llabs(-576460752303423489), llabs(576460752303423489)); - return 0; - } -
\ No newline at end of file +int main(int argc, char** argv) { + printf("%lld,%lld\n", llabs(-576460752303423489), llabs(576460752303423489)); + return 0; +} diff --git a/tests/core/test_i64_qdouble.in b/tests/core/test_i64_qdouble.in index 1b8297e4..db47afa6 100644 --- a/tests/core/test_i64_qdouble.in +++ b/tests/core/test_i64_qdouble.in @@ -1,21 +1,14 @@ +#include <stdio.h> +typedef long long qint64; /* 64 bit signed */ +typedef double qreal; - #include <stdio.h> - typedef long long qint64; /* 64 bit signed */ - typedef double qreal; - - - int main(int argc, char **argv) - { - qreal c = 111; - qint64 d = -111 + (argc - 1); - c += d; - if (c < -1 || c > 1) - { - printf("Failed!\n"); - } - else - { - printf("Succeeded!\n"); - } - }; -
\ No newline at end of file +int main(int argc, char **argv) { + qreal c = 111; + qint64 d = -111 + (argc - 1); + c += d; + if (c < -1 || c > 1) { + printf("Failed!\n"); + } else { + printf("Succeeded!\n"); + } +}; diff --git a/tests/core/test_i64_umul.in b/tests/core/test_i64_umul.in index 4b4bdaca..bfe97154 100644 --- a/tests/core/test_i64_umul.in +++ b/tests/core/test_i64_umul.in @@ -1,20 +1,18 @@ +#include <inttypes.h> +#include <stdio.h> - #include <inttypes.h> - #include <stdio.h> +typedef uint32_t UINT32; +typedef uint64_t UINT64; - typedef uint32_t UINT32; - typedef uint64_t UINT64; +int main() { + volatile UINT32 testu32a = 2375724032U; + UINT32 bigu32 = 0xffffffffU; + volatile UINT64 testu64a = 14746250828952703000U; - int main() { - volatile UINT32 testu32a = 2375724032U; - UINT32 bigu32 = 0xffffffffU; - volatile UINT64 testu64a = 14746250828952703000U; + while ((UINT64)testu32a * (UINT64)bigu32 < testu64a) { + printf("testu64a is %llu\n", testu64a); + testu64a /= 2; + } - while ((UINT64)testu32a * (UINT64)bigu32 < testu64a) { - printf("testu64a is %llu\n", testu64a); - testu64a /= 2; - } - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_i64_varargs.in b/tests/core/test_i64_varargs.in index 94982b51..7d2e4267 100644 --- a/tests/core/test_i64_varargs.in +++ b/tests/core/test_i64_varargs.in @@ -1,30 +1,29 @@ +#include <stdio.h> +#include <stdint.h> +#include <stdarg.h> - #include <stdio.h> - #include <stdint.h> - #include <stdarg.h> +int64_t ccv_cache_generate_signature(char *msg, int len, int64_t sig_start, + ...) { + if (sig_start < 10123) printf("%s\n", msg + len); + va_list v; + va_start(v, sig_start); + if (sig_start > 1413) + printf("%d\n", va_arg(v, int)); + else + printf("nada\n"); + va_end(v); + return len * sig_start * (msg[0] + 1); +} - int64_t ccv_cache_generate_signature(char *msg, int len, int64_t sig_start, ...) { - if (sig_start < 10123) - printf("%s\n", msg+len); - va_list v; - va_start(v, sig_start); - if (sig_start > 1413) - printf("%d\n", va_arg(v, int)); - else - printf("nada\n"); - va_end(v); - return len*sig_start*(msg[0]+1); - } - - int main(int argc, char **argv) - { - for (int i = 0; i < argc; i++) { - int64_t x; - if (i % 123123 == 0) - x = ccv_cache_generate_signature(argv[i], i+2, (int64_t)argc*argc, 54.111); - else - x = ccv_cache_generate_signature(argv[i], i+2, (int64_t)argc*argc, 13); - printf("%lld\n", x); - } - }; -
\ No newline at end of file +int main(int argc, char **argv) { + for (int i = 0; i < argc; i++) { + int64_t x; + if (i % 123123 == 0) + x = ccv_cache_generate_signature(argv[i], i + 2, (int64_t)argc * argc, + 54.111); + else + x = ccv_cache_generate_signature(argv[i], i + 2, (int64_t)argc * argc, + 13); + printf("%lld\n", x); + } +}; diff --git a/tests/core/test_i64_zextneg.in b/tests/core/test_i64_zextneg.in index 3f77131d..b7e204fe 100644 --- a/tests/core/test_i64_zextneg.in +++ b/tests/core/test_i64_zextneg.in @@ -1,16 +1,13 @@ +#include <stdint.h> +#include <stdio.h> - #include <stdint.h> - #include <stdio.h> +int main(int argc, char *argv[]) { + uint8_t byte = 0x80; + uint16_t two = byte; + uint32_t four = byte; + uint64_t eight = byte; - int main(int argc, char *argv[]) - { - uint8_t byte = 0x80; - uint16_t two = byte; - uint32_t four = byte; - uint64_t eight = byte; + printf("value: %d,%d,%d,%lld.\n", byte, two, four, eight); - printf("value: %d,%d,%d,%lld.\n", byte, two, four, eight); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_if.in b/tests/core/test_if.in index 20ed3a01..07edbe8d 100644 --- a/tests/core/test_if.in +++ b/tests/core/test_if.in @@ -1,11 +1,8 @@ - - #include <stdio.h> - int main() - { - int x = 5; - if (x > 3) { - printf("*yes*\n"); - } - return 0; - } -
\ No newline at end of file +#include <stdio.h> +int main() { + int x = 5; + if (x > 3) { + printf("*yes*\n"); + } + return 0; +} diff --git a/tests/core/test_if_else.in b/tests/core/test_if_else.in index 03b2bfa6..b7693eed 100644 --- a/tests/core/test_if_else.in +++ b/tests/core/test_if_else.in @@ -1,13 +1,10 @@ - - #include <stdio.h> - int main() - { - int x = 5; - if (x > 10) { - printf("*yes*\n"); - } else { - printf("*no*\n"); - } - return 0; - } -
\ No newline at end of file +#include <stdio.h> +int main() { + int x = 5; + if (x > 10) { + printf("*yes*\n"); + } else { + printf("*no*\n"); + } + return 0; +} diff --git a/tests/core/test_indirectbr.in b/tests/core/test_indirectbr.in index bdc66b53..ae3f1baa 100644 --- a/tests/core/test_indirectbr.in +++ b/tests/core/test_indirectbr.in @@ -1,21 +1,20 @@ +#include <stdio.h> +int main(void) { + const void *addrs[2] = {&&FOO, &&BAR}; - #include <stdio.h> - int main(void) { - const void *addrs[2] = { &&FOO, &&BAR }; + // confuse the optimizer so it doesn't hardcode the jump and avoid generating + // an |indirectbr| instruction + int which = 0; + for (int x = 0; x < 1000; x++) which = (which + x * x) % 7; + which = (which % 2) + 1; - // confuse the optimizer so it doesn't hardcode the jump and avoid generating an |indirectbr| instruction - int which = 0; - for (int x = 0; x < 1000; x++) which = (which + x*x) % 7; - which = (which % 2) + 1; + goto *addrs[which]; - goto *addrs[which]; - - FOO: - printf("bad\n"); - return 0; - BAR: - printf("good\n"); - const void *addr = &&FOO; - goto *addr; - } -
\ No newline at end of file +FOO: + printf("bad\n"); + return 0; +BAR: + printf("good\n"); + const void *addr = &&FOO; + goto *addr; +} diff --git a/tests/core/test_inherit.in b/tests/core/test_inherit.in index e9a152e8..ae5b819d 100644 --- a/tests/core/test_inherit.in +++ b/tests/core/test_inherit.in @@ -1,25 +1,22 @@ - - #include <stdio.h> - struct Parent { - int x1, x2; - }; - struct Child : Parent { - int y; - }; - int main() - { - Parent a; - a.x1 = 50; - a.x2 = 87; - Child b; - b.x1 = 78; - b.x2 = 550; - b.y = 101; - Child* c = (Child*)&a; - c->x1 ++; - c = &b; - c->y --; - printf("*%d,%d,%d,%d,%d,%d,%d*\n", a.x1, a.x2, b.x1, b.x2, b.y, c->x1, c->x2); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +struct Parent { + int x1, x2; +}; +struct Child : Parent { + int y; +}; +int main() { + Parent a; + a.x1 = 50; + a.x2 = 87; + Child b; + b.x1 = 78; + b.x2 = 550; + b.y = 101; + Child* c = (Child*)&a; + c->x1++; + c = &b; + c->y--; + printf("*%d,%d,%d,%d,%d,%d,%d*\n", a.x1, a.x2, b.x1, b.x2, b.y, c->x1, c->x2); + return 0; +} diff --git a/tests/core/test_inlinejs.in b/tests/core/test_inlinejs.in index 0359b707..b6a98954 100644 --- a/tests/core/test_inlinejs.in +++ b/tests/core/test_inlinejs.in @@ -1,26 +1,27 @@ +#include <stdio.h> - #include <stdio.h> +double get() { + double ret = 0; + __asm __volatile__("Math.abs(-12/3.3)" : "=r"(ret)); // write to a variable + asm("#comment1"); + asm volatile("#comment2"); + asm volatile( + "#comment3\n" + "#comment4\n"); + return ret; +} - double get() { - double ret = 0; - __asm __volatile__("Math.abs(-12/3.3)":"=r"(ret)); // write to a variable - asm("#comment1"); - asm volatile("#comment2"); - asm volatile("#comment3\n" - "#comment4\n"); - return ret; - } +int main() { + asm("Module.print('Inline JS is very cool')"); + printf("%.2f\n", get()); - int main() { - asm("Module.print('Inline JS is very cool')"); - printf("%.2f\n", get()); + // Test that passing multiple input and output variables works. + int src1 = 1, src2 = 2, src3 = 3; + int dst1 = 0, dst2 = 0, dst3 = 0; + // TODO asm("Module.print(%3); Module.print(%4); Module.print(%5); %0 = %3; %1 + // = %4; %2 = %5;" : "=r"(dst1),"=r"(dst2),"=r"(dst3): + // "r"(src1),"r"(src2),"r"(src3)); + // TODO printf("%d\n%d\n%d\n", dst1, dst2, dst3); - // Test that passing multiple input and output variables works. - int src1 = 1, src2 = 2, src3 = 3; - int dst1 = 0, dst2 = 0, dst3 = 0; - // TODO asm("Module.print(%3); Module.print(%4); Module.print(%5); %0 = %3; %1 = %4; %2 = %5;" : "=r"(dst1),"=r"(dst2),"=r"(dst3): "r"(src1),"r"(src2),"r"(src3)); - // TODO printf("%d\n%d\n%d\n", dst1, dst2, dst3); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_inlinejs2.in b/tests/core/test_inlinejs2.in index 7a05fd67..438253c2 100644 --- a/tests/core/test_inlinejs2.in +++ b/tests/core/test_inlinejs2.in @@ -1,20 +1,18 @@ +#include <stdio.h> - #include <stdio.h> +int mix(int x, int y) { + int ret; + asm("Math.pow(2, %0+%1+1)" : "=r"(ret) : "r"(x), "r"(y)); // read and write + return ret; +} - int mix(int x, int y) { - int ret; - asm("Math.pow(2, %0+%1+1)" : "=r"(ret) : "r"(x), "r"(y)); // read and write - return ret; - } +void mult() { + asm("var $_$1 = Math.abs(-100); $_$1 *= 2; Module.print($_$1)"); // multiline + asm __volatile__("Module.print('done')"); +} - void mult() { - asm("var $_$1 = Math.abs(-100); $_$1 *= 2; Module.print($_$1)"); // multiline - asm __volatile__("Module.print('done')"); - } - - int main(int argc, char **argv) { - printf("%d\n", mix(argc, argc/2)); - mult(); - return 0; - } -
\ No newline at end of file +int main(int argc, char **argv) { + printf("%d\n", mix(argc, argc / 2)); + mult(); + return 0; +} diff --git a/tests/core/test_inlinejs3.in b/tests/core/test_inlinejs3.in index e7d9b1e8..3e1913ff 100644 --- a/tests/core/test_inlinejs3.in +++ b/tests/core/test_inlinejs3.in @@ -1,26 +1,20 @@ +#include <stdio.h> +#include <emscripten.h> - #include <stdio.h> - #include <emscripten.h> - - int main(int argc, char **argv) { - EM_ASM(Module.print('hello dere1')); - EM_ASM( - Module.print('hello dere2'); - ); - for (int i = 0; i < 3; i++) { - EM_ASM( - Module.print('hello dere3'); - Module.print('hello dere' + 4); - ); - } - int sum = 0; - for (int i = 0; i < argc*3; i++) { - sum += EM_ASM_INT({ - Module.print('i: ' + [$0, ($1).toFixed(2)]); - return $0*2; - }, i, double(i)/12); - } - printf("sum: %d\n", sum); - return 0; - } -
\ No newline at end of file +int main(int argc, char **argv) { + EM_ASM(Module.print('hello dere1')); + EM_ASM(Module.print('hello dere2');); + for (int i = 0; i < 3; i++) { + EM_ASM(Module.print('hello dere3'); Module.print('hello dere' + 4);); + } + int sum = 0; + for (int i = 0; i < argc * 3; i++) { + sum += EM_ASM_INT({ + Module.print('i: ' + [ $0, ($1).toFixed(2) ]); + return $0 * 2; + }, + i, double(i) / 12); + } + printf("sum: %d\n", sum); + return 0; +} diff --git a/tests/core/test_intvars.in b/tests/core/test_intvars.in index 7cf7df89..27b4180b 100644 --- a/tests/core/test_intvars.in +++ b/tests/core/test_intvars.in @@ -1,50 +1,49 @@ +#include <stdio.h> +int global = 20; +int *far; +int main() { + int x = 5; + int y = x + 17; + int z = (y - 1) / 2; // Should stay an integer after division! + y += 1; + int w = x * 3 + 4; + int k = w < 15 ? 99 : 101; + far = &k; + *far += global; + int i = k > 100; // Should be an int, not a bool! + int j = i << 6; + j >>= 1; + j = j ^ 5; + int h = 1; + h |= 0; + int p = h; + p &= 0; + printf("*%d,%d,%d,%d,%d,%d,%d,%d,%d*\n", x, y, z, w, k, i, j, h, p); - #include <stdio.h> - int global = 20; - int *far; - int main() - { - int x = 5; - int y = x+17; - int z = (y-1)/2; // Should stay an integer after division! - y += 1; - int w = x*3+4; - int k = w < 15 ? 99 : 101; - far = &k; - *far += global; - int i = k > 100; // Should be an int, not a bool! - int j = i << 6; - j >>= 1; - j = j ^ 5; - int h = 1; - h |= 0; - int p = h; - p &= 0; - printf("*%d,%d,%d,%d,%d,%d,%d,%d,%d*\n", x, y, z, w, k, i, j, h, p); + long hash = -1; + size_t perturb; + int ii = 0; + for (perturb = hash;; perturb >>= 5) { + printf("%d:%d", ii, perturb); + ii++; + if (ii == 9) break; + printf(","); + } + printf("*\n"); + printf("*%.1d,%.2d*\n", 56, 9); - long hash = -1; - size_t perturb; - int ii = 0; - for (perturb = hash; ; perturb >>= 5) { - printf("%d:%d", ii, perturb); - ii++; - if (ii == 9) break; - printf(","); - } - printf("*\n"); - printf("*%.1d,%.2d*\n", 56, 9); + // Fixed-point math on 64-bit ints. Tricky to support since we have no 64-bit + // shifts in JS + { + struct Fixed { + static int Mult(int a, int b) { + return ((long long)a * (long long)b) >> 16; + } + }; + printf("fixed:%d\n", Fixed::Mult(150000, 140000)); + } - // Fixed-point math on 64-bit ints. Tricky to support since we have no 64-bit shifts in JS - { - struct Fixed { - static int Mult(int a, int b) { - return ((long long)a * (long long)b) >> 16; - } - }; - printf("fixed:%d\n", Fixed::Mult(150000, 140000)); - } - - printf("*%ld*%p\n", (long)21, &hash); // The %p should not enter an infinite loop! - return 0; - } -
\ No newline at end of file + printf("*%ld*%p\n", (long)21, + &hash); // The %p should not enter an infinite loop! + return 0; +} diff --git a/tests/core/test_isdigit_l.in b/tests/core/test_isdigit_l.in index b94f618d..069f2027 100644 --- a/tests/core/test_isdigit_l.in +++ b/tests/core/test_isdigit_l.in @@ -1,7 +1,5 @@ - - #include <iostream> - int main() { - using namespace std; - use_facet<num_put<char> >(cout.getloc()).put(cout, cout, '0', 3.14159265); - } -
\ No newline at end of file +#include <iostream> +int main() { + using namespace std; + use_facet<num_put<char> >(cout.getloc()).put(cout, cout, '0', 3.14159265); +} diff --git a/tests/core/test_isnan.in b/tests/core/test_isnan.in index d5ca7a6e..808ffa19 100644 --- a/tests/core/test_isnan.in +++ b/tests/core/test_isnan.in @@ -1,17 +1,16 @@ +#include <stdio.h> - #include <stdio.h> +int IsNaN(double x) { + int rc; /* The value return */ + volatile double y = x; + volatile double z = y; + rc = (y != z); + return rc; +} - int IsNaN(double x){ - int rc; /* The value return */ - volatile double y = x; - volatile double z = y; - rc = (y!=z); - return rc; - } - - int main() { - double tests[] = { 1.0, 3.333, 1.0/0.0, 0.0/0.0, -1.0/0.0, -0, 0, -123123123, 12.0E200 }; - for (int i = 0; i < sizeof(tests)/sizeof(double); i++) - printf("%d - %f - %d\n", i, tests[i], IsNaN(tests[i])); - } -
\ No newline at end of file +int main() { + double tests[] = {1.0, 3.333, 1.0 / 0.0, 0.0 / 0.0, -1.0 / 0.0, + -0, 0, -123123123, 12.0E200}; + for (int i = 0; i < sizeof(tests) / sizeof(double); i++) + printf("%d - %f - %d\n", i, tests[i], IsNaN(tests[i])); +} diff --git a/tests/core/test_istream.in b/tests/core/test_istream.in index 9a9d1c9a..e5988d24 100644 --- a/tests/core/test_istream.in +++ b/tests/core/test_istream.in @@ -1,16 +1,13 @@ +#include <string> +#include <sstream> +#include <iostream> - #include <string> - #include <sstream> - #include <iostream> +int main() { + std::string mystring("1 2 3"); + std::istringstream is(mystring); + int one, two, three; - int main() - { - std::string mystring("1 2 3"); - std::istringstream is(mystring); - int one, two, three; + is >> one >> two >> three; - is >> one >> two >> three; - - printf( "%i %i %i", one, two, three ); - } -
\ No newline at end of file + printf("%i %i %i", one, two, three); +} diff --git a/tests/core/test_iswdigit.in b/tests/core/test_iswdigit.in index cc1b4a74..74277a41 100644 --- a/tests/core/test_iswdigit.in +++ b/tests/core/test_iswdigit.in @@ -1,12 +1,10 @@ +#include <stdio.h> +#include <cctype> +#include <cwctype> - #include <stdio.h> - #include <cctype> - #include <cwctype> - - int main() { - using namespace std; - printf("%d ", isdigit('0')); - printf("%d ", iswdigit(L'0')); - return 0; - } -
\ No newline at end of file +int main() { + using namespace std; + printf("%d ", isdigit('0')); + printf("%d ", iswdigit(L'0')); + return 0; +} diff --git a/tests/core/test_libcextra.in b/tests/core/test_libcextra.in index e0ff2f8e..ebeb8b50 100644 --- a/tests/core/test_libcextra.in +++ b/tests/core/test_libcextra.in @@ -1,13 +1,10 @@ +#include <stdio.h> +#include <wchar.h> - #include <stdio.h> - #include <wchar.h> +int main() { + const wchar_t* wstr = L"Hello"; - int main() - { - const wchar_t* wstr = L"Hello"; + printf("wcslen: %d\n", wcslen(wstr)); - printf("wcslen: %d\n", wcslen(wstr)); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_libgen.in b/tests/core/test_libgen.in index c7918a78..d62e4a00 100644 --- a/tests/core/test_libgen.in +++ b/tests/core/test_libgen.in @@ -1,41 +1,39 @@ +#include <stdio.h> +#include <libgen.h> - #include <stdio.h> - #include <libgen.h> +int main() { + char p1[16] = "/usr/lib", p1x[16] = "/usr/lib"; + printf("%s -> ", p1); + printf("%s : %s\n", dirname(p1x), basename(p1)); - int main() { - char p1[16] = "/usr/lib", p1x[16] = "/usr/lib"; - printf("%s -> ", p1); - printf("%s : %s\n", dirname(p1x), basename(p1)); + char p2[16] = "/usr", p2x[16] = "/usr"; + printf("%s -> ", p2); + printf("%s : %s\n", dirname(p2x), basename(p2)); - char p2[16] = "/usr", p2x[16] = "/usr"; - printf("%s -> ", p2); - printf("%s : %s\n", dirname(p2x), basename(p2)); + char p3[16] = "/usr/", p3x[16] = "/usr/"; + printf("%s -> ", p3); + printf("%s : %s\n", dirname(p3x), basename(p3)); - char p3[16] = "/usr/", p3x[16] = "/usr/"; - printf("%s -> ", p3); - printf("%s : %s\n", dirname(p3x), basename(p3)); + char p4[16] = "/usr/lib///", p4x[16] = "/usr/lib///"; + printf("%s -> ", p4); + printf("%s : %s\n", dirname(p4x), basename(p4)); - char p4[16] = "/usr/lib///", p4x[16] = "/usr/lib///"; - printf("%s -> ", p4); - printf("%s : %s\n", dirname(p4x), basename(p4)); + char p5[16] = "/", p5x[16] = "/"; + printf("%s -> ", p5); + printf("%s : %s\n", dirname(p5x), basename(p5)); - char p5[16] = "/", p5x[16] = "/"; - printf("%s -> ", p5); - printf("%s : %s\n", dirname(p5x), basename(p5)); + char p6[16] = "///", p6x[16] = "///"; + printf("%s -> ", p6); + printf("%s : %s\n", dirname(p6x), basename(p6)); - char p6[16] = "///", p6x[16] = "///"; - printf("%s -> ", p6); - printf("%s : %s\n", dirname(p6x), basename(p6)); + char p7[16] = "/usr/../lib/..", p7x[16] = "/usr/../lib/.."; + printf("%s -> ", p7); + printf("%s : %s\n", dirname(p7x), basename(p7)); - char p7[16] = "/usr/../lib/..", p7x[16] = "/usr/../lib/.."; - printf("%s -> ", p7); - printf("%s : %s\n", dirname(p7x), basename(p7)); + char p8[16] = "", p8x[16] = ""; + printf("(empty) -> %s : %s\n", dirname(p8x), basename(p8)); - char p8[16] = "", p8x[16] = ""; - printf("(empty) -> %s : %s\n", dirname(p8x), basename(p8)); + printf("(null) -> %s : %s\n", dirname(0), basename(0)); - printf("(null) -> %s : %s\n", dirname(0), basename(0)); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_linked_list.in b/tests/core/test_linked_list.in index 4ca978bf..c3d457dd 100644 --- a/tests/core/test_linked_list.in +++ b/tests/core/test_linked_list.in @@ -1,42 +1,39 @@ +#include <stdio.h> +struct worker_args { + int value; + struct worker_args* next; +}; +int main() { + worker_args a; + worker_args b; + a.value = 60; + a.next = &b; + b.value = 900; + b.next = NULL; + worker_args* c = &a; + int total = 0; + while (c) { + total += c->value; + c = c->next; + } - #include <stdio.h> - struct worker_args { - int value; - struct worker_args *next; - }; - int main() - { - worker_args a; - worker_args b; - a.value = 60; - a.next = &b; - b.value = 900; - b.next = NULL; - worker_args* c = &a; - int total = 0; - while (c) { - total += c->value; - c = c->next; - } + // Chunk of em + worker_args chunk[10]; + for (int i = 0; i < 9; i++) { + chunk[i].value = i * 10; + chunk[i].next = &chunk[i + 1]; + } + chunk[9].value = 90; + chunk[9].next = &chunk[0]; - // Chunk of em - worker_args chunk[10]; - for (int i = 0; i < 9; i++) { - chunk[i].value = i*10; - chunk[i].next = &chunk[i+1]; - } - chunk[9].value = 90; - chunk[9].next = &chunk[0]; + c = chunk; + do { + total += c->value; + c = c->next; + } while (c != chunk); - c = chunk; - do { - total += c->value; - c = c->next; - } while (c != chunk); + printf("*%d,%d*\n", total, b.next); + // NULL *is* 0, in C/C++. No JS null! (null == 0 is false, etc.) - printf("*%d,%d*\n", total, b.next); - // NULL *is* 0, in C/C++. No JS null! (null == 0 is false, etc.) - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_llrint.in b/tests/core/test_llrint.in index cbba8a21..2744c73a 100644 --- a/tests/core/test_llrint.in +++ b/tests/core/test_llrint.in @@ -1,8 +1,7 @@ - - #include <stdio.h> - #include <math.h> - int main() { - printf("%lld\n%lld\n%lld\n%lld\n", llrint(0.1), llrint(0.6), llrint(1.25), llrint(1099511627776.667)); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <math.h> +int main() { + printf("%lld\n%lld\n%lld\n%lld\n", llrint(0.1), llrint(0.6), llrint(1.25), + llrint(1099511627776.667)); + return 0; +} diff --git a/tests/core/test_llvm_intrinsics.in b/tests/core/test_llvm_intrinsics.in index 6c235bdf..2bc87a54 100644 --- a/tests/core/test_llvm_intrinsics.in +++ b/tests/core/test_llvm_intrinsics.in @@ -1,41 +1,44 @@ - - #include <stdio.h> - #include <sys/types.h> - - extern "C" { - extern unsigned short llvm_bswap_i16(unsigned short x); - extern unsigned int llvm_bswap_i32(unsigned int x); - extern int32_t llvm_ctlz_i32(int32_t x); - extern int64_t llvm_ctlz_i64(int64_t x); - extern int32_t llvm_cttz_i32(int32_t x); - extern int64_t llvm_cttz_i64(int64_t x); - extern int32_t llvm_ctpop_i32(int32_t x); - extern int64_t llvm_ctpop_i64(int64_t x); - extern int llvm_expect_i32(int x, int y); - } - - int main(void) { - unsigned short x = 0xc8ef; - printf("%x,%x\n", x&0xff, x >> 8); - x = llvm_bswap_i16(x); - printf("%x,%x\n", x&0xff, x >> 8); - - unsigned int y = 0xc5de158a; - printf("%x,%x,%x,%x\n", y&0xff, (y>>8)&0xff, (y>>16)&0xff, (y>>24)&0xff); - y = llvm_bswap_i32(y); - printf("%x,%x,%x,%x\n", y&0xff, (y>>8)&0xff, (y>>16)&0xff, (y>>24)&0xff); - - printf("%d,%d\n", (int)llvm_ctlz_i64(((int64_t)1) << 40), llvm_ctlz_i32(1<<10)); - printf("%d,%d\n", (int)llvm_cttz_i64(((int64_t)1) << 40), llvm_cttz_i32(1<<10)); - printf("%d,%d\n", (int)llvm_ctpop_i64((0x3101ULL << 32) | 1), llvm_ctpop_i32(0x3101)); - printf("%d\n", (int)llvm_ctpop_i32(-594093059)); - - printf("%d\n", llvm_expect_i32(x % 27, 3)); - - int64_t a = 1; - a = __builtin_bswap64(a); - printf("%lld\n", a); - - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <sys/types.h> + +extern "C" { +extern unsigned short llvm_bswap_i16(unsigned short x); +extern unsigned int llvm_bswap_i32(unsigned int x); +extern int32_t llvm_ctlz_i32(int32_t x); +extern int64_t llvm_ctlz_i64(int64_t x); +extern int32_t llvm_cttz_i32(int32_t x); +extern int64_t llvm_cttz_i64(int64_t x); +extern int32_t llvm_ctpop_i32(int32_t x); +extern int64_t llvm_ctpop_i64(int64_t x); +extern int llvm_expect_i32(int x, int y); +} + +int main(void) { + unsigned short x = 0xc8ef; + printf("%x,%x\n", x & 0xff, x >> 8); + x = llvm_bswap_i16(x); + printf("%x,%x\n", x & 0xff, x >> 8); + + unsigned int y = 0xc5de158a; + printf("%x,%x,%x,%x\n", y & 0xff, (y >> 8) & 0xff, (y >> 16) & 0xff, + (y >> 24) & 0xff); + y = llvm_bswap_i32(y); + printf("%x,%x,%x,%x\n", y & 0xff, (y >> 8) & 0xff, (y >> 16) & 0xff, + (y >> 24) & 0xff); + + printf("%d,%d\n", (int)llvm_ctlz_i64(((int64_t)1) << 40), + llvm_ctlz_i32(1 << 10)); + printf("%d,%d\n", (int)llvm_cttz_i64(((int64_t)1) << 40), + llvm_cttz_i32(1 << 10)); + printf("%d,%d\n", (int)llvm_ctpop_i64((0x3101ULL << 32) | 1), + llvm_ctpop_i32(0x3101)); + printf("%d\n", (int)llvm_ctpop_i32(-594093059)); + + printf("%d\n", llvm_expect_i32(x % 27, 3)); + + int64_t a = 1; + a = __builtin_bswap64(a); + printf("%lld\n", a); + + return 0; +} diff --git a/tests/core/test_llvm_used.in b/tests/core/test_llvm_used.in index e40ae09e..b3c9f10e 100644 --- a/tests/core/test_llvm_used.in +++ b/tests/core/test_llvm_used.in @@ -1,14 +1,13 @@ +#include <stdio.h> +#include <emscripten.h> - #include <stdio.h> - #include <emscripten.h> - - extern "C" { - EMSCRIPTEN_KEEPALIVE void foobar(int x) { - printf("Worked! %d\n", x); - } - } +extern "C" { + EMSCRIPTEN_KEEPALIVE void foobar(int x) { + printf("Worked! %d\n", x); + } +} - int main() { - emscripten_run_script("Module['_foobar'](10)"); - return 0; - }
\ No newline at end of file +int main() { + emscripten_run_script("Module['_foobar'](10)"); + return 0; +} diff --git a/tests/core/test_llvmswitch.in b/tests/core/test_llvmswitch.in index 64cfa652..b3f871e4 100644 --- a/tests/core/test_llvmswitch.in +++ b/tests/core/test_llvmswitch.in @@ -1,24 +1,23 @@ +#include <stdio.h> +#include <string.h> - #include <stdio.h> - #include <string.h> +int switcher(int p) { + switch (p) { + case 'a': + case 'b': + case 'c': + return p - 1; + case -15: + return p + 1; + } + return p; +} - int switcher(int p) - { - switch(p) { - case 'a': - case 'b': - case 'c': - return p-1; - case -15: - return p+1; - } - return p; - } - - int main( int argc, const char *argv[] ) { - unsigned int x = 0xfffffff1; - x >>= (argc-1); // force it to be unsigned for purpose of checking our switch comparison in signed/unsigned - printf("*%d,%d,%d,%d,%d,%d*\n", switcher('a'), switcher('b'), switcher('c'), switcher(x), switcher(-15), switcher('e')); - return 0; - } -
\ No newline at end of file +int main(int argc, const char *argv[]) { + unsigned int x = 0xfffffff1; + x >>= (argc - 1); // force it to be unsigned for purpose of checking our + // switch comparison in signed/unsigned + printf("*%d,%d,%d,%d,%d,%d*\n", switcher('a'), switcher('b'), switcher('c'), + switcher(x), switcher(-15), switcher('e')); + return 0; +} diff --git a/tests/core/test_longjmp.in b/tests/core/test_longjmp.in index 4260ed15..44940cdd 100644 --- a/tests/core/test_longjmp.in +++ b/tests/core/test_longjmp.in @@ -1,34 +1,33 @@ +#include <stdio.h> +#include <setjmp.h> - #include <stdio.h> - #include <setjmp.h> +static jmp_buf buf; - static jmp_buf buf; +void second(void) { + printf("second\n"); + longjmp(buf, -1); +} - void second(void) { - printf("second\n"); - longjmp(buf,-1); - } +void first(void) { + printf("first\n"); // prints + longjmp(buf, 1); // jumps back to where setjmp was called - making setjmp now + // return 1 +} - void first(void) { - printf("first\n"); // prints - longjmp(buf,1); // jumps back to where setjmp was called - making setjmp now return 1 - } +int main() { + volatile int x = 0; + int jmpval = setjmp(buf); + if (!jmpval) { + x++; // should be properly restored once longjmp jumps back + first(); // when executed, setjmp returns 1 + printf("skipped\n"); // does not print + } else if (jmpval == 1) { // when first() jumps back, setjmp returns 1 + printf("result: %d %d\n", x, jmpval); // prints + x++; + second(); // when executed, setjmp returns -1 + } else if (jmpval == -1) { // when second() jumps back, setjmp returns -1 + printf("result: %d %d\n", x, jmpval); // prints + } - int main() { - volatile int x = 0; - int jmpval = setjmp(buf); - if (!jmpval) { - x++; // should be properly restored once longjmp jumps back - first(); // when executed, setjmp returns 1 - printf("skipped\n"); // does not print - } else if (jmpval == 1) { // when first() jumps back, setjmp returns 1 - printf("result: %d %d\n", x, jmpval); // prints - x++; - second(); // when executed, setjmp returns -1 - } else if (jmpval == -1) { // when second() jumps back, setjmp returns -1 - printf("result: %d %d\n", x, jmpval); // prints - } - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_longjmp2.in b/tests/core/test_longjmp2.in index ef73c8ba..e09a33f7 100644 --- a/tests/core/test_longjmp2.in +++ b/tests/core/test_longjmp2.in @@ -1,37 +1,35 @@ - - #include <setjmp.h> - #include <stdio.h> - - typedef struct { - jmp_buf* jmp; - } jmp_state; - - void stack_manipulate_func(jmp_state* s, int level) { - jmp_buf buf; - - printf("Entering stack_manipulate_func, level: %d\n", level); - - if (level == 0) { - s->jmp = &buf; - if (setjmp(*(s->jmp)) == 0) { - printf("Setjmp normal execution path, level: %d\n", level); - stack_manipulate_func(s, level + 1); - } else { - printf("Setjmp error execution path, level: %d\n", level); - } - } else { - printf("Perform longjmp at level %d\n", level); - longjmp(*(s->jmp), 1); - } - - printf("Exiting stack_manipulate_func, level: %d\n", level); - } - - int main(int argc, char *argv[]) { - jmp_state s; - s.jmp = NULL; - stack_manipulate_func(&s, 0); - - return 0; - } -
\ No newline at end of file +#include <setjmp.h> +#include <stdio.h> + +typedef struct { + jmp_buf* jmp; +} jmp_state; + +void stack_manipulate_func(jmp_state* s, int level) { + jmp_buf buf; + + printf("Entering stack_manipulate_func, level: %d\n", level); + + if (level == 0) { + s->jmp = &buf; + if (setjmp(*(s->jmp)) == 0) { + printf("Setjmp normal execution path, level: %d\n", level); + stack_manipulate_func(s, level + 1); + } else { + printf("Setjmp error execution path, level: %d\n", level); + } + } else { + printf("Perform longjmp at level %d\n", level); + longjmp(*(s->jmp), 1); + } + + printf("Exiting stack_manipulate_func, level: %d\n", level); +} + +int main(int argc, char* argv[]) { + jmp_state s; + s.jmp = NULL; + stack_manipulate_func(&s, 0); + + return 0; +} diff --git a/tests/core/test_longjmp3.in b/tests/core/test_longjmp3.in index 95fcf36c..f9b88469 100644 --- a/tests/core/test_longjmp3.in +++ b/tests/core/test_longjmp3.in @@ -1,42 +1,40 @@ - - #include <setjmp.h> - #include <stdio.h> - - typedef struct { - jmp_buf* jmp; - } jmp_state; - - void setjmp_func(jmp_state* s, int level) { - jmp_buf* prev_jmp = s->jmp; - jmp_buf c_jmp; - - if (level == 2) { - printf("level is 2, perform longjmp!\n"); - longjmp(*(s->jmp), 1); - } - - if (setjmp(c_jmp) == 0) { - printf("setjmp normal execution path, level: %d\n", level); - s->jmp = &c_jmp; - setjmp_func(s, level + 1); - } else { - printf("setjmp exception execution path, level: %d\n", level); - if (prev_jmp) { - printf("prev_jmp is not empty, continue with longjmp!\n"); - s->jmp = prev_jmp; - longjmp(*(s->jmp), 1); - } - } - - printf("Exiting setjmp function, level: %d\n", level); - } - - int main(int argc, char *argv[]) { - jmp_state s; - s.jmp = NULL; - - setjmp_func(&s, 0); - - return 0; - } -
\ No newline at end of file +#include <setjmp.h> +#include <stdio.h> + +typedef struct { + jmp_buf* jmp; +} jmp_state; + +void setjmp_func(jmp_state* s, int level) { + jmp_buf* prev_jmp = s->jmp; + jmp_buf c_jmp; + + if (level == 2) { + printf("level is 2, perform longjmp!\n"); + longjmp(*(s->jmp), 1); + } + + if (setjmp(c_jmp) == 0) { + printf("setjmp normal execution path, level: %d\n", level); + s->jmp = &c_jmp; + setjmp_func(s, level + 1); + } else { + printf("setjmp exception execution path, level: %d\n", level); + if (prev_jmp) { + printf("prev_jmp is not empty, continue with longjmp!\n"); + s->jmp = prev_jmp; + longjmp(*(s->jmp), 1); + } + } + + printf("Exiting setjmp function, level: %d\n", level); +} + +int main(int argc, char* argv[]) { + jmp_state s; + s.jmp = NULL; + + setjmp_func(&s, 0); + + return 0; +} diff --git a/tests/core/test_longjmp4.in b/tests/core/test_longjmp4.in index ce27f751..68fa4c22 100644 --- a/tests/core/test_longjmp4.in +++ b/tests/core/test_longjmp4.in @@ -1,44 +1,40 @@ +#include <setjmp.h> +#include <stdio.h> - #include <setjmp.h> - #include <stdio.h> +typedef struct { + jmp_buf* jmp; +} jmp_state; - typedef struct { - jmp_buf* jmp; - } jmp_state; +void second_func(jmp_state* s); - void second_func(jmp_state* s); +void first_func(jmp_state* s) { + jmp_buf* prev_jmp = s->jmp; + jmp_buf c_jmp; + volatile int once = 0; - void first_func(jmp_state* s) { - jmp_buf* prev_jmp = s->jmp; - jmp_buf c_jmp; - volatile int once = 0; + if (setjmp(c_jmp) == 0) { + printf("Normal execution path of first function!\n"); - if (setjmp(c_jmp) == 0) { - printf("Normal execution path of first function!\n"); + s->jmp = &c_jmp; + second_func(s); + } else { + printf("Exception execution path of first function! %d\n", once); - s->jmp = &c_jmp; - second_func(s); - } else { - printf("Exception execution path of first function! %d\n", once); + if (!once) { + printf("Calling longjmp the second time!\n"); + once = 1; + longjmp(*(s->jmp), 1); + } + } +} - if (!once) { - printf("Calling longjmp the second time!\n"); - once = 1; - longjmp(*(s->jmp), 1); - } - } - } +void second_func(jmp_state* s) { longjmp(*(s->jmp), 1); } - void second_func(jmp_state* s) { - longjmp(*(s->jmp), 1); - } +int main(int argc, char* argv[]) { + jmp_state s; + s.jmp = NULL; - int main(int argc, char *argv[]) { - jmp_state s; - s.jmp = NULL; + first_func(&s); - first_func(&s); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_longjmp_exc.in b/tests/core/test_longjmp_exc.in index 3fc07b85..4e568242 100644 --- a/tests/core/test_longjmp_exc.in +++ b/tests/core/test_longjmp_exc.in @@ -1,28 +1,28 @@ +#include <stdlib.h> +#include <stdio.h> +#include <setjmp.h> +#include <emscripten.h> - #include <stdlib.h> - #include <stdio.h> - #include <setjmp.h> - #include <emscripten.h> +jmp_buf abortframe; - jmp_buf abortframe; +void dostuff(int a) { + printf("pre\n"); + if (a != 42) + emscripten_run_script( + "waka_waka()"); // this should fail, and never reach "never" + printf("never\n"); - void dostuff(int a) { - printf("pre\n"); - if (a != 42) emscripten_run_script("waka_waka()"); // this should fail, and never reach "never" - printf("never\n"); + if (a == 100) { + longjmp(abortframe, -1); + } - if (a == 100) { - longjmp (abortframe, -1); - } + if (setjmp(abortframe)) { + printf("got 100"); + } +} - if (setjmp(abortframe)) { - printf("got 100"); - } - } - - int main(int argc, char **argv) { - dostuff(argc); - exit(1); - return 1; - } -
\ No newline at end of file +int main(int argc, char **argv) { + dostuff(argc); + exit(1); + return 1; +} diff --git a/tests/core/test_longjmp_funcptr.in b/tests/core/test_longjmp_funcptr.in index e699bae6..38cbd86e 100644 --- a/tests/core/test_longjmp_funcptr.in +++ b/tests/core/test_longjmp_funcptr.in @@ -1,32 +1,31 @@ +#include <stdio.h> +#include <setjmp.h> - #include <stdio.h> - #include <setjmp.h> +static jmp_buf buf; - static jmp_buf buf; +void (*fp)() = NULL; - void (*fp)() = NULL; +void second(void) { + printf("second\n"); // prints + longjmp(buf, 1); // jumps back to where setjmp was called - making setjmp now + // return 1 +} - void second(void) { - printf("second\n"); // prints - longjmp(buf,1); // jumps back to where setjmp was called - making setjmp now return 1 - } +void first(void) { + fp(); + printf("first\n"); // does not print +} - void first(void) { - fp(); - printf("first\n"); // does not print - } +int main(int argc, char **argv) { + fp = argc == 200 ? NULL : second; - int main(int argc, char **argv) { - fp = argc == 200 ? NULL : second; + volatile int x = 0; + if (!setjmp(buf)) { + x++; + first(); // when executed, setjmp returns 0 + } else { // when longjmp jumps back, setjmp returns 1 + printf("main: %d\n", x); // prints + } - volatile int x = 0; - if ( ! setjmp(buf) ) { - x++; - first(); // when executed, setjmp returns 0 - } else { // when longjmp jumps back, setjmp returns 1 - printf("main: %d\n", x); // prints - } - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_longjmp_repeat.in b/tests/core/test_longjmp_repeat.in index 4476f8dd..f782fc0c 100644 --- a/tests/core/test_longjmp_repeat.in +++ b/tests/core/test_longjmp_repeat.in @@ -1,15 +1,13 @@ +#include <stdio.h> +#include <setjmp.h> - #include <stdio.h> - #include <setjmp.h> +static jmp_buf buf; - static jmp_buf buf; - - int main() { - volatile int x = 0; - printf("setjmp:%d\n", setjmp(buf)); - x++; - printf("x:%d\n", x); - if (x < 4) longjmp(buf, x*2); - return 0; - } -
\ No newline at end of file +int main() { + volatile int x = 0; + printf("setjmp:%d\n", setjmp(buf)); + x++; + printf("x:%d\n", x); + if (x < 4) longjmp(buf, x * 2); + return 0; +} diff --git a/tests/core/test_longjmp_stacked.in b/tests/core/test_longjmp_stacked.in index 19539561..b7fd6bfa 100644 --- a/tests/core/test_longjmp_stacked.in +++ b/tests/core/test_longjmp_stacked.in @@ -1,44 +1,42 @@ +#include <stdio.h> +#include <setjmp.h> +#include <stdlib.h> +#include <string.h> - #include <stdio.h> - #include <setjmp.h> - #include <stdlib.h> - #include <string.h> +int bottom, top; - int bottom, top; +int run(int y) { + // confuse stack + char *s = (char *)alloca(100); + memset(s, 1, 100); + s[y] = y; + s[y / 2] = y * 2; + volatile int x = s[y]; + top = (int)alloca(4); + if (x <= 2) return x; + jmp_buf buf; + printf("setjmp of %d\n", x); + if (setjmp(buf) == 0) { + printf("going\n"); + x += run(x / 2); + longjmp(buf, 1); + } + printf("back\n"); + return x / 2; +} - int run(int y) { - // confuse stack - char *s = (char*)alloca(100); - memset(s, 1, 100); - s[y] = y; - s[y/2] = y*2; - volatile int x = s[y]; - top = (int)alloca(4); - if (x <= 2) return x; - jmp_buf buf; - printf("setjmp of %d\n", x); - if (setjmp(buf) == 0) { - printf("going\n"); - x += run(x/2); - longjmp(buf, 1); - } - printf("back\n"); - return x/2; - } - - int main(int argc, char **argv) { - int sum = 0; - for (int i = 0; i < argc*2; i++) { - bottom = (int)alloca(4); - sum += run(10); - // scorch the earth - if (bottom < top) { - memset((void*)bottom, 1, top - bottom); - } else { - memset((void*)top, 1, bottom - top); - } - } - printf("%d\n", sum); - return sum; - } -
\ No newline at end of file +int main(int argc, char **argv) { + int sum = 0; + for (int i = 0; i < argc * 2; i++) { + bottom = (int)alloca(4); + sum += run(10); + // scorch the earth + if (bottom < top) { + memset((void *)bottom, 1, top - bottom); + } else { + memset((void *)top, 1, bottom - top); + } + } + printf("%d\n", sum); + return sum; +} diff --git a/tests/core/test_loop.in b/tests/core/test_loop.in index 9df45457..83721d17 100644 --- a/tests/core/test_loop.in +++ b/tests/core/test_loop.in @@ -1,17 +1,14 @@ - - #include <stdio.h> - int main() - { - int x = 5; - for (int i = 0; i < 6; i++) { - x += x*i; - if (x > 1000) { - if (x % 7 == 0) printf("cheez\n"); - x /= 2; - break; - } - } - printf("*%d*\n", x); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +int main() { + int x = 5; + for (int i = 0; i < 6; i++) { + x += x * i; + if (x > 1000) { + if (x % 7 == 0) printf("cheez\n"); + x /= 2; + break; + } + } + printf("*%d*\n", x); + return 0; +} diff --git a/tests/core/test_mainenv.in b/tests/core/test_mainenv.in index da434196..f42c6b59 100644 --- a/tests/core/test_mainenv.in +++ b/tests/core/test_mainenv.in @@ -1,8 +1,5 @@ - - #include <stdio.h> - int main(int argc, char **argv, char **envp) - { - printf("*%p*\n", envp); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +int main(int argc, char **argv, char **envp) { + printf("*%p*\n", envp); + return 0; +} diff --git a/tests/core/test_math.in b/tests/core/test_math.in index 0685c178..e638404b 100644 --- a/tests/core/test_math.in +++ b/tests/core/test_math.in @@ -1,34 +1,34 @@ - - #include <stdio.h> - #include <stdlib.h> - #include <cmath> - int main(int argc, char **argv) - { - printf("*%.2f,%.2f,%d", M_PI, -M_PI, (1/0.0) > 1e300); // could end up as infinity, or just a very very big number - printf(",%d", isfinite(NAN) != 0); - printf(",%d", isfinite(INFINITY) != 0); - printf(",%d", isfinite(-INFINITY) != 0); - printf(",%d", isfinite(12.3) != 0); - printf(",%d", isinf(NAN) != 0); - printf(",%d", isinf(INFINITY) != 0); - printf(",%d", isinf(-INFINITY) != 0); - printf(",%d", isinf(12.3) != 0); - div_t div_result = div(23, 10); - printf(",%d", div_result.quot); - printf(",%d", div_result.rem); - double sine = -1.0, cosine = -1.0; - sincos(0.0, &sine, &cosine); - printf(",%1.1lf", sine); - printf(",%1.1lf", cosine); - float fsine = -1.0f, fcosine = -1.0f; - sincosf(0.0, &fsine, &fcosine); - printf(",%1.1f", fsine); - printf(",%1.1f", fcosine); - fsine = sinf(1.1 + argc - 1); - fcosine = cosf(1.1 + argc - 1); - printf(",%1.1f", fsine); - printf(",%1.1f", fcosine); - printf("*\n"); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <stdlib.h> +#include <cmath> +int main(int argc, char **argv) { + printf("*%.2f,%.2f,%d", M_PI, -M_PI, (1 / 0.0) > 1e300); // could end up as + // infinity, or just + // a very very big + // number + printf(",%d", isfinite(NAN) != 0); + printf(",%d", isfinite(INFINITY) != 0); + printf(",%d", isfinite(-INFINITY) != 0); + printf(",%d", isfinite(12.3) != 0); + printf(",%d", isinf(NAN) != 0); + printf(",%d", isinf(INFINITY) != 0); + printf(",%d", isinf(-INFINITY) != 0); + printf(",%d", isinf(12.3) != 0); + div_t div_result = div(23, 10); + printf(",%d", div_result.quot); + printf(",%d", div_result.rem); + double sine = -1.0, cosine = -1.0; + sincos(0.0, &sine, &cosine); + printf(",%1.1lf", sine); + printf(",%1.1lf", cosine); + float fsine = -1.0f, fcosine = -1.0f; + sincosf(0.0, &fsine, &fcosine); + printf(",%1.1f", fsine); + printf(",%1.1f", fcosine); + fsine = sinf(1.1 + argc - 1); + fcosine = cosf(1.1 + argc - 1); + printf(",%1.1f", fsine); + printf(",%1.1f", fcosine); + printf("*\n"); + return 0; +} diff --git a/tests/core/test_mathfuncptr.in b/tests/core/test_mathfuncptr.in index 96e78401..87feaade 100644 --- a/tests/core/test_mathfuncptr.in +++ b/tests/core/test_mathfuncptr.in @@ -1,13 +1,11 @@ +#include <math.h> +#include <stdio.h> - #include <math.h> - #include <stdio.h> - - int - main(int argc, char **argv) { - float (*fn)(float) = argc != 12 ? &sqrtf : &fabsf; - float (*fn2)(float) = argc != 13 ? &fabsf : &sqrtf; - float (*fn3)(float) = argc != 14 ? &erff : &fabsf; - printf("fn2(-5) = %d, fn(10) = %.2f, erf(10) = %.2f\n", (int)fn2(-5), fn(10), fn3(10)); - return 0; - } -
\ No newline at end of file +int main(int argc, char **argv) { + float (*fn)(float) = argc != 12 ? &sqrtf : &fabsf; + float (*fn2)(float) = argc != 13 ? &fabsf : &sqrtf; + float (*fn3)(float) = argc != 14 ? &erff : &fabsf; + printf("fn2(-5) = %d, fn(10) = %.2f, erf(10) = %.2f\n", (int)fn2(-5), fn(10), + fn3(10)); + return 0; +} diff --git a/tests/core/test_memcpy2.in b/tests/core/test_memcpy2.in index 91e0b6a0..c7b4de89 100644 --- a/tests/core/test_memcpy2.in +++ b/tests/core/test_memcpy2.in @@ -1,22 +1,20 @@ - - #include <stdio.h> - #include <string.h> - #include <assert.h> - int main() { - char buffer[256]; - for (int i = 0; i < 10; i++) { - for (int j = 0; j < 10; j++) { - for (int k = 0; k < 35; k++) { - for (int t = 0; t < 256; t++) buffer[t] = t; - char *dest = buffer + i + 128; - char *src = buffer+j; - //printf("%d, %d, %d\n", i, j, k); - assert(memcpy(dest, src, k) == dest); - assert(memcmp(dest, src, k) == 0); - } - } - } - printf("ok.\n"); - return 1; +#include <stdio.h> +#include <string.h> +#include <assert.h> +int main() { + char buffer[256]; + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + for (int k = 0; k < 35; k++) { + for (int t = 0; t < 256; t++) buffer[t] = t; + char *dest = buffer + i + 128; + char *src = buffer + j; + // printf("%d, %d, %d\n", i, j, k); + assert(memcpy(dest, src, k) == dest); + assert(memcmp(dest, src, k) == 0); } -
\ No newline at end of file + } + } + printf("ok.\n"); + return 1; +} diff --git a/tests/core/test_memcpy_memcmp.in b/tests/core/test_memcpy_memcmp.in index c89d7ef6..fb5dfe6f 100644 --- a/tests/core/test_memcpy_memcmp.in +++ b/tests/core/test_memcpy_memcmp.in @@ -1,45 +1,43 @@ +#include <stdio.h> +#include <string.h> +#include <assert.h> - #include <stdio.h> - #include <string.h> - #include <assert.h> - - #define MAXX 48 - void reset(unsigned char *buffer) { - for (int i = 0; i < MAXX; i++) buffer[i] = i+1; - } - void dump(unsigned char *buffer) { - for (int i = 0; i < MAXX-1; i++) printf("%2d,", buffer[i]); - printf("%d\n", buffer[MAXX-1]); +#define MAXX 48 +void reset(unsigned char *buffer) { + for (int i = 0; i < MAXX; i++) buffer[i] = i + 1; +} +void dump(unsigned char *buffer) { + for (int i = 0; i < MAXX - 1; i++) printf("%2d,", buffer[i]); + printf("%d\n", buffer[MAXX - 1]); +} +int main() { + unsigned char buffer[MAXX]; + for (int i = MAXX / 4; i < MAXX - MAXX / 4; i++) { + for (int j = MAXX / 4; j < MAXX - MAXX / 4; j++) { + for (int k = 1; k < MAXX / 4; k++) { + if (i == j) continue; + if (i < j && i + k > j) continue; + if (j < i && j + k > i) continue; + printf("[%d,%d,%d] ", i, j, k); + reset(buffer); + memcpy(buffer + i, buffer + j, k); + dump(buffer); + assert(memcmp(buffer + i, buffer + j, k) == 0); + buffer[i + k / 2]++; + if (buffer[i + k / 2] != 0) { + assert(memcmp(buffer + i, buffer + j, k) > 0); + } else { + assert(memcmp(buffer + i, buffer + j, k) < 0); } - int main() { - unsigned char buffer[MAXX]; - for (int i = MAXX/4; i < MAXX-MAXX/4; i++) { - for (int j = MAXX/4; j < MAXX-MAXX/4; j++) { - for (int k = 1; k < MAXX/4; k++) { - if (i == j) continue; - if (i < j && i+k > j) continue; - if (j < i && j+k > i) continue; - printf("[%d,%d,%d] ", i, j, k); - reset(buffer); - memcpy(buffer+i, buffer+j, k); - dump(buffer); - assert(memcmp(buffer+i, buffer+j, k) == 0); - buffer[i + k/2]++; - if (buffer[i + k/2] != 0) { - assert(memcmp(buffer+i, buffer+j, k) > 0); - } else { - assert(memcmp(buffer+i, buffer+j, k) < 0); - } - buffer[i + k/2]--; - buffer[j + k/2]++; - if (buffer[j + k/2] != 0) { - assert(memcmp(buffer+i, buffer+j, k) < 0); - } else { - assert(memcmp(buffer+i, buffer+j, k) > 0); - } - } - } - } - return 0; + buffer[i + k / 2]--; + buffer[j + k / 2]++; + if (buffer[j + k / 2] != 0) { + assert(memcmp(buffer + i, buffer + j, k) < 0); + } else { + assert(memcmp(buffer + i, buffer + j, k) > 0); } -
\ No newline at end of file + } + } + } + return 0; +} diff --git a/tests/core/test_memmove.in b/tests/core/test_memmove.in index 690075d9..615a5ae1 100644 --- a/tests/core/test_memmove.in +++ b/tests/core/test_memmove.in @@ -1,10 +1,8 @@ - - #include <stdio.h> - #include <string.h> - int main() { - char str[] = "memmove can be very useful....!"; - memmove (str+20, str+15, 11); - puts(str); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <string.h> +int main() { + char str[] = "memmove can be very useful....!"; + memmove(str + 20, str + 15, 11); + puts(str); + return 0; +} diff --git a/tests/core/test_memmove2.in b/tests/core/test_memmove2.in index 087f59b8..2aed0b51 100644 --- a/tests/core/test_memmove2.in +++ b/tests/core/test_memmove2.in @@ -1,24 +1,22 @@ - - #include <stdio.h> - #include <string.h> - #include <assert.h> - int main() { - int sum = 0; - char buffer[256]; - for (int i = 0; i < 10; i++) { - for (int j = 0; j < 10; j++) { - for (int k = 0; k < 35; k++) { - for (int t = 0; t < 256; t++) buffer[t] = t; - char *dest = buffer + i; - char *src = buffer + j; - if (dest == src) continue; - //printf("%d, %d, %d\n", i, j, k); - assert(memmove(dest, src, k) == dest); - for (int t = 0; t < 256; t++) sum += buffer[t]; - } - } - } - printf("final: %d.\n", sum); - return 1; +#include <stdio.h> +#include <string.h> +#include <assert.h> +int main() { + int sum = 0; + char buffer[256]; + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + for (int k = 0; k < 35; k++) { + for (int t = 0; t < 256; t++) buffer[t] = t; + char *dest = buffer + i; + char *src = buffer + j; + if (dest == src) continue; + // printf("%d, %d, %d\n", i, j, k); + assert(memmove(dest, src, k) == dest); + for (int t = 0; t < 256; t++) sum += buffer[t]; } -
\ No newline at end of file + } + } + printf("final: %d.\n", sum); + return 1; +} diff --git a/tests/core/test_memmove3.in b/tests/core/test_memmove3.in index a28267cd..27f9055b 100644 --- a/tests/core/test_memmove3.in +++ b/tests/core/test_memmove3.in @@ -1,10 +1,8 @@ - - #include <stdio.h> - #include <string.h> - int main() { - char str[] = "memmove can be vvery useful....!"; - memmove(str+15, str+16, 17); - puts(str); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <string.h> +int main() { + char str[] = "memmove can be vvery useful....!"; + memmove(str + 15, str + 16, 17); + puts(str); + return 0; +} diff --git a/tests/core/test_mmap.in b/tests/core/test_mmap.in index 46400278..16c1c647 100644 --- a/tests/core/test_mmap.in +++ b/tests/core/test_mmap.in @@ -1,38 +1,36 @@ - - #include <stdio.h> - #include <sys/mman.h> - #include <assert.h> - - int main(int argc, char *argv[]) { - for (int i = 0; i < 10; i++) { - int* map = (int*)mmap(0, 5000, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANON, -1, 0); - /* TODO: Should we align to 4k? - assert(((int)map) % 4096 == 0); // aligned - */ - assert(munmap(map, 5000) == 0); - } - - const int NUM_BYTES = 8 * 1024 * 1024; - const int NUM_INTS = NUM_BYTES / sizeof(int); - - int* map = (int*)mmap(0, NUM_BYTES, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANON, -1, 0); - assert(map != MAP_FAILED); - - int i; - - for (i = 0; i < NUM_INTS; i++) { - map[i] = i; - } - - for (i = 0; i < NUM_INTS; i++) { - assert(map[i] == i); - } - - assert(munmap(map, NUM_BYTES) == 0); - - printf("hello,world"); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <sys/mman.h> +#include <assert.h> + +int main(int argc, char* argv[]) { + for (int i = 0; i < 10; i++) { + int* map = (int*)mmap(0, 5000, PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANON, -1, 0); + /* TODO: Should we align to 4k? + assert(((int)map) % 4096 == 0); // aligned + */ + assert(munmap(map, 5000) == 0); + } + + const int NUM_BYTES = 8 * 1024 * 1024; + const int NUM_INTS = NUM_BYTES / sizeof(int); + + int* map = (int*)mmap(0, NUM_BYTES, PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANON, -1, 0); + assert(map != MAP_FAILED); + + int i; + + for (i = 0; i < NUM_INTS; i++) { + map[i] = i; + } + + for (i = 0; i < NUM_INTS; i++) { + assert(map[i] == i); + } + + assert(munmap(map, NUM_BYTES) == 0); + + printf("hello,world"); + return 0; +} diff --git a/tests/core/test_mod_globalstruct.in b/tests/core/test_mod_globalstruct.in index 3e1ed493..3a8522cc 100644 --- a/tests/core/test_mod_globalstruct.in +++ b/tests/core/test_mod_globalstruct.in @@ -1,19 +1,18 @@ +#include <stdio.h> - #include <stdio.h> +struct malloc_params { + size_t magic, page_size; +}; - struct malloc_params { - size_t magic, page_size; - }; +malloc_params mparams; - malloc_params mparams; +#define SIZE_T_ONE ((size_t)1) +#define page_align(S) \ + (((S) + (mparams.page_size - SIZE_T_ONE)) & ~(mparams.page_size - SIZE_T_ONE)) - #define SIZE_T_ONE ((size_t)1) - #define page_align(S) (((S) + (mparams.page_size - SIZE_T_ONE)) & ~(mparams.page_size - SIZE_T_ONE)) - - int main() - { - mparams.page_size = 4096; - printf("*%d,%d,%d,%d*\n", mparams.page_size, page_align(1000), page_align(6000), page_align(66474)); - return 0; - } -
\ No newline at end of file +int main() { + mparams.page_size = 4096; + printf("*%d,%d,%d,%d*\n", mparams.page_size, page_align(1000), + page_align(6000), page_align(66474)); + return 0; +} diff --git a/tests/core/test_multiexception.in b/tests/core/test_multiexception.in index 93795388..46acbbf3 100644 --- a/tests/core/test_multiexception.in +++ b/tests/core/test_multiexception.in @@ -1,48 +1,50 @@ - #include <stdio.h> static int current_exception_id = 0; typedef struct { -int jmp; + int jmp; } jmp_state; void setjmp_func(jmp_state* s, int level) { -int prev_jmp = s->jmp; -int c_jmp; + int prev_jmp = s->jmp; + int c_jmp; -if (level == 2) { - printf("level is 2, perform longjmp!\n"); - throw 1; -} + if (level == 2) { + printf("level is 2, perform longjmp!\n"); + throw 1; + } -c_jmp = current_exception_id++; -try { - printf("setjmp normal execution path, level: %d, prev_jmp: %d\n", level, prev_jmp); - s->jmp = c_jmp; - setjmp_func(s, level + 1); -} catch (int catched_eid) { - printf("caught %d\n", catched_eid); - if (catched_eid == c_jmp) { - printf("setjmp exception execution path, level: %d, prev_jmp: %d\n", level, prev_jmp); - if (prev_jmp != -1) { - printf("prev_jmp is not empty, continue with longjmp!\n"); - s->jmp = prev_jmp; - throw s->jmp; + c_jmp = current_exception_id++; + try { + printf("setjmp normal execution path, level: %d, prev_jmp: %d\n", level, + prev_jmp); + s->jmp = c_jmp; + setjmp_func(s, level + 1); + } + catch (int catched_eid) { + printf("caught %d\n", catched_eid); + if (catched_eid == c_jmp) { + printf("setjmp exception execution path, level: %d, prev_jmp: %d\n", + level, prev_jmp); + if (prev_jmp != -1) { + printf("prev_jmp is not empty, continue with longjmp!\n"); + s->jmp = prev_jmp; + throw s->jmp; + } + } else { + throw; } - } else { - throw; } -} -printf("Exiting setjmp function, level: %d, prev_jmp: %d\n", level, prev_jmp); + printf("Exiting setjmp function, level: %d, prev_jmp: %d\n", level, prev_jmp); } -int main(int argc, char *argv[]) { -jmp_state s; -s.jmp = -1; +int main(int argc, char* argv[]) { + jmp_state s; + s.jmp = -1; -setjmp_func(&s, 0); + setjmp_func(&s, 0); -return 0; + return 0; } diff --git a/tests/core/test_negative_zero.in b/tests/core/test_negative_zero.in index 8e1fcc0b..395f84ce 100644 --- a/tests/core/test_negative_zero.in +++ b/tests/core/test_negative_zero.in @@ -1,30 +1,27 @@ +#include <stdio.h> +#include <math.h> - #include <stdio.h> - #include <math.h> - - int main() { - #define TEST(x, y) \ - printf("%.2f, %.2f ==> %.2f\n", x, y, copysign(x, y)); - TEST( 5.0f, 5.0f); - TEST( 5.0f, -5.0f); - TEST(-5.0f, 5.0f); - TEST(-5.0f, -5.0f); - TEST( 5.0f, 4.0f); - TEST( 5.0f, -4.0f); - TEST(-5.0f, 4.0f); - TEST(-5.0f, -4.0f); - TEST( 0.0f, 5.0f); - TEST( 0.0f, -5.0f); - TEST(-0.0f, 5.0f); - TEST(-0.0f, -5.0f); - TEST( 5.0f, 0.0f); - TEST( 5.0f, -0.0f); - TEST(-5.0f, 0.0f); - TEST(-5.0f, -0.0f); - TEST( 0.0f, 0.0f); - TEST( 0.0f, -0.0f); - TEST(-0.0f, 0.0f); - TEST(-0.0f, -0.0f); - return 0; - } -
\ No newline at end of file +int main() { +#define TEST(x, y) printf("%.2f, %.2f ==> %.2f\n", x, y, copysign(x, y)); + TEST(5.0f, 5.0f); + TEST(5.0f, -5.0f); + TEST(-5.0f, 5.0f); + TEST(-5.0f, -5.0f); + TEST(5.0f, 4.0f); + TEST(5.0f, -4.0f); + TEST(-5.0f, 4.0f); + TEST(-5.0f, -4.0f); + TEST(0.0f, 5.0f); + TEST(0.0f, -5.0f); + TEST(-0.0f, 5.0f); + TEST(-0.0f, -5.0f); + TEST(5.0f, 0.0f); + TEST(5.0f, -0.0f); + TEST(-5.0f, 0.0f); + TEST(-5.0f, -0.0f); + TEST(0.0f, 0.0f); + TEST(0.0f, -0.0f); + TEST(-0.0f, 0.0f); + TEST(-0.0f, -0.0f); + return 0; +} diff --git a/tests/core/test_perrar.in b/tests/core/test_perrar.in index e15c583a..d7c9eae7 100644 --- a/tests/core/test_perrar.in +++ b/tests/core/test_perrar.in @@ -1,13 +1,10 @@ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdio.h> - #include <sys/types.h> - #include <sys/stat.h> - #include <fcntl.h> - #include <stdio.h> - - int main( int argc, char** argv ){ - int retval = open( "NonExistingFile", O_RDONLY ); - if( retval == -1 ) - perror( "Cannot open NonExistingFile" ); - return 0; - } -
\ No newline at end of file +int main(int argc, char** argv) { + int retval = open("NonExistingFile", O_RDONLY); + if (retval == -1) perror("Cannot open NonExistingFile"); + return 0; +} diff --git a/tests/core/test_phiundef.in b/tests/core/test_phiundef.in index cf4b0f18..91273cc9 100644 --- a/tests/core/test_phiundef.in +++ b/tests/core/test_phiundef.in @@ -1,18 +1,17 @@ - #include <stdlib.h> #include <stdio.h> static int state; struct my_struct { -union { - struct { - unsigned char a; - unsigned char b; - } c; - unsigned int d; -} e; -unsigned int f; + union { + struct { + unsigned char a; + unsigned char b; + } c; + unsigned int d; + } e; + unsigned int f; }; int main(int argc, char **argv) { @@ -20,14 +19,12 @@ int main(int argc, char **argv) { state = 0; - for (int i=0;i<argc+10;i++) - { - if (state % 2 == 0) - r.e.c.a = 3; - else - printf("%d\n", r.e.c.a); - state++; + for (int i = 0; i < argc + 10; i++) { + if (state % 2 == 0) + r.e.c.a = 3; + else + printf("%d\n", r.e.c.a); + state++; } return 0; } -
\ No newline at end of file diff --git a/tests/core/test_poll.in b/tests/core/test_poll.in index 3fb0ebc9..aa2c09ee 100644 --- a/tests/core/test_poll.in +++ b/tests/core/test_poll.in @@ -1,30 +1,28 @@ +#include <stdio.h> +#include <errno.h> +#include <fcntl.h> +#include <poll.h> - #include <stdio.h> - #include <errno.h> - #include <fcntl.h> - #include <poll.h> +int main() { + struct pollfd multi[5]; + multi[0].fd = open("/file", O_RDONLY, 0777); + multi[1].fd = open("/device", O_RDONLY, 0777); + multi[2].fd = 123; + multi[3].fd = open("/file", O_RDONLY, 0777); + multi[4].fd = open("/file", O_RDONLY, 0777); + multi[0].events = POLLIN | POLLOUT | POLLNVAL | POLLERR; + multi[1].events = POLLIN | POLLOUT | POLLNVAL | POLLERR; + multi[2].events = POLLIN | POLLOUT | POLLNVAL | POLLERR; + multi[3].events = 0x00; + multi[4].events = POLLOUT | POLLNVAL | POLLERR; - int main() { - struct pollfd multi[5]; - multi[0].fd = open("/file", O_RDONLY, 0777); - multi[1].fd = open("/device", O_RDONLY, 0777); - multi[2].fd = 123; - multi[3].fd = open("/file", O_RDONLY, 0777); - multi[4].fd = open("/file", O_RDONLY, 0777); - multi[0].events = POLLIN | POLLOUT | POLLNVAL | POLLERR; - multi[1].events = POLLIN | POLLOUT | POLLNVAL | POLLERR; - multi[2].events = POLLIN | POLLOUT | POLLNVAL | POLLERR; - multi[3].events = 0x00; - multi[4].events = POLLOUT | POLLNVAL | POLLERR; + printf("ret: %d\n", poll(multi, 5, 123)); + printf("errno: %d\n", errno); + printf("multi[0].revents: %d\n", multi[0].revents == (POLLIN | POLLOUT)); + printf("multi[1].revents: %d\n", multi[1].revents == (POLLIN | POLLOUT)); + printf("multi[2].revents: %d\n", multi[2].revents == POLLNVAL); + printf("multi[3].revents: %d\n", multi[3].revents == 0); + printf("multi[4].revents: %d\n", multi[4].revents == POLLOUT); - printf("ret: %d\n", poll(multi, 5, 123)); - printf("errno: %d\n", errno); - printf("multi[0].revents: %d\n", multi[0].revents == (POLLIN | POLLOUT)); - printf("multi[1].revents: %d\n", multi[1].revents == (POLLIN | POLLOUT)); - printf("multi[2].revents: %d\n", multi[2].revents == POLLNVAL); - printf("multi[3].revents: %d\n", multi[3].revents == 0); - printf("multi[4].revents: %d\n", multi[4].revents == POLLOUT); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_polymorph.in b/tests/core/test_polymorph.in index 2faa1935..1f24a1aa 100644 --- a/tests/core/test_polymorph.in +++ b/tests/core/test_polymorph.in @@ -1,34 +1,33 @@ +#include <stdio.h> +struct Pure { + virtual int implme() = 0; +}; +struct Parent : Pure { + virtual int getit() { + return 11; + }; + int implme() { return 32; } +}; +struct Child : Parent { + int getit() { return 74; } + int implme() { return 1012; } +}; - #include <stdio.h> - struct Pure { - virtual int implme() = 0; - }; - struct Parent : Pure { - virtual int getit() { return 11; }; - int implme() { return 32; } - }; - struct Child : Parent { - int getit() { return 74; } - int implme() { return 1012; } - }; +struct Other { + int one() { return 11; } + int two() { return 22; } +}; - struct Other { - int one() { return 11; } - int two() { return 22; } - }; +int main() { + Parent *x = new Parent(); + Parent *y = new Child(); + printf("*%d,%d,%d,%d*\n", x->getit(), y->getit(), x->implme(), y->implme()); - int main() - { - Parent *x = new Parent(); - Parent *y = new Child(); - printf("*%d,%d,%d,%d*\n", x->getit(), y->getit(), x->implme(), y->implme()); + Other *o = new Other; + int (Other::*Ls)() = &Other::one; + printf("*%d*\n", (o->*(Ls))()); + Ls = &Other::two; + printf("*%d*\n", (o->*(Ls))()); - Other *o = new Other; - int (Other::*Ls)() = &Other::one; - printf("*%d*\n", (o->*(Ls))()); - Ls = &Other::two; - printf("*%d*\n", (o->*(Ls))()); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_printf_2.in b/tests/core/test_printf_2.in index ef94aec1..8fb16173 100644 --- a/tests/core/test_printf_2.in +++ b/tests/core/test_printf_2.in @@ -1,17 +1,15 @@ +#include <stdio.h> - #include <stdio.h> +int main() { + char c = '1'; + short s = 2; + int i = 3; + long long l = 4; + float f = 5.5; + double d = 6.6; - int main() { - char c = '1'; - short s = 2; - int i = 3; - long long l = 4; - float f = 5.5; - double d = 6.6; + printf("%c,%hd,%d,%lld,%.1f,%.1llf\n", c, s, i, l, f, d); + printf("%#x,%#x\n", 1, 0); - printf("%c,%hd,%d,%lld,%.1f,%.1llf\n", c, s, i, l, f, d); - printf("%#x,%#x\n", 1, 0); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_printf_more.in b/tests/core/test_printf_more.in index b8e3ba61..ad1cebc8 100644 --- a/tests/core/test_printf_more.in +++ b/tests/core/test_printf_more.in @@ -1,13 +1,11 @@ - - #include <stdio.h> - int main() { - int size = snprintf(NULL, 0, "%s %d %.2f\n", "me and myself", 25, 1.345); - char buf[size]; - snprintf(buf, size, "%s %d %.2f\n", "me and myself", 25, 1.345); - printf("%d : %s\n", size, buf); - char *buff = NULL; - asprintf(&buff, "%d waka %d\n", 21, 95); - puts(buff); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +int main() { + int size = snprintf(NULL, 0, "%s %d %.2f\n", "me and myself", 25, 1.345); + char buf[size]; + snprintf(buf, size, "%s %d %.2f\n", "me and myself", 25, 1.345); + printf("%d : %s\n", size, buf); + char *buff = NULL; + asprintf(&buff, "%d waka %d\n", 21, 95); + puts(buff); + return 0; +} diff --git a/tests/core/test_ptrtoint.in b/tests/core/test_ptrtoint.in index be7214e8..88e91262 100644 --- a/tests/core/test_ptrtoint.in +++ b/tests/core/test_ptrtoint.in @@ -1,16 +1,14 @@ +#include <stdio.h> - #include <stdio.h> - - int main( int argc, const char *argv[] ) { - char *a = new char[10]; - char *a0 = a+0; - char *a5 = a+5; - int *b = new int[10]; - int *b0 = b+0; - int *b5 = b+5; - int c = (int)b5-(int)b0; // Emscripten should warn! - int d = (int)b5-(int)b0; // Emscripten should warn! - printf("*%d*\n", (int)a5-(int)a0); - return 0; - } -
\ No newline at end of file +int main(int argc, const char *argv[]) { + char *a = new char[10]; + char *a0 = a + 0; + char *a5 = a + 5; + int *b = new int[10]; + int *b0 = b + 0; + int *b5 = b + 5; + int c = (int)b5 - (int)b0; // Emscripten should warn! + int d = (int)b5 - (int)b0; // Emscripten should warn! + printf("*%d*\n", (int)a5 - (int)a0); + return 0; +} diff --git a/tests/core/test_regex.in b/tests/core/test_regex.in index a7ceb7a3..4f1bdd21 100644 --- a/tests/core/test_regex.in +++ b/tests/core/test_regex.in @@ -1,37 +1,36 @@ -// This is from http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frtref%2Fregexec.htm - #include <regex.h> - #include <stdio.h> - #include <stdlib.h> +// This is from// http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frtref%2Fregexec.htm +#include <regex.h> +#include <stdio.h> +#include <stdlib.h> - int main(void) - { - regex_t preg; - const char *string = "a very simple simple simple string"; - const char *pattern = "\\(sim[a-z]le\\) \\1"; - int rc; - size_t nmatch = 2; - regmatch_t pmatch[2]; +int main(void) { + regex_t preg; + const char *string = "a very simple simple simple string"; + const char *pattern = "\\(sim[a-z]le\\) \\1"; + int rc; + size_t nmatch = 2; + regmatch_t pmatch[2]; - if (0 != (rc = regcomp(&preg, pattern, 0))) { - printf("regcomp() failed, returning nonzero (%d)\n", rc); - exit(EXIT_FAILURE); - } + if (0 != (rc = regcomp(&preg, pattern, 0))) { + printf("regcomp() failed, returning nonzero (%d)\n", rc); + exit(EXIT_FAILURE); + } - if (0 != (rc = regexec(&preg, string, nmatch, pmatch, 0))) { - printf("Failed to match '%s' with '%s',returning %d.\n", - string, pattern, rc); - } - else { - printf("With the whole expression, " - "a matched substring \"%.*s\" is found at position %d to %d.\n", - pmatch[0].rm_eo - pmatch[0].rm_so, &string[pmatch[0].rm_so], - pmatch[0].rm_so, pmatch[0].rm_eo - 1); - printf("With the sub-expression, " - "a matched substring \"%.*s\" is found at position %d to %d.\n", - pmatch[1].rm_eo - pmatch[1].rm_so, &string[pmatch[1].rm_so], - pmatch[1].rm_so, pmatch[1].rm_eo - 1); - } - regfree(&preg); - return 0; - } - + if (0 != (rc = regexec(&preg, string, nmatch, pmatch, 0))) { + printf("Failed to match '%s' with '%s',returning %d.\n", string, pattern, + rc); + } else { + printf( + "With the whole expression, " + "a matched substring \"%.*s\" is found at position %d to %d.\n", + pmatch[0].rm_eo - pmatch[0].rm_so, &string[pmatch[0].rm_so], + pmatch[0].rm_so, pmatch[0].rm_eo - 1); + printf( + "With the sub-expression, " + "a matched substring \"%.*s\" is found at position %d to %d.\n", + pmatch[1].rm_eo - pmatch[1].rm_so, &string[pmatch[1].rm_so], + pmatch[1].rm_so, pmatch[1].rm_eo - 1); + } + regfree(&preg); + return 0; +} diff --git a/tests/core/test_reinterpreted_ptrs.in b/tests/core/test_reinterpreted_ptrs.in index e5e257e0..9865c61f 100644 --- a/tests/core/test_reinterpreted_ptrs.in +++ b/tests/core/test_reinterpreted_ptrs.in @@ -1,13 +1,13 @@ - #include <stdio.h> class Foo { -private: + private: float bar; -public: + + public: int baz; - Foo(): bar(0), baz(4711) {}; + Foo() : bar(0), baz(4711) {}; int getBar() const; }; @@ -16,8 +16,8 @@ int Foo::getBar() const { return this->bar; }; -const Foo *magic1 = reinterpret_cast<Foo*>(0xDEAD111F); -const Foo *magic2 = reinterpret_cast<Foo*>(0xDEAD888F); +const Foo *magic1 = reinterpret_cast<Foo *>(0xDEAD111F); +const Foo *magic2 = reinterpret_cast<Foo *>(0xDEAD888F); static void runTest() { @@ -25,17 +25,16 @@ static void runTest() { const Foo *b = a; if (a->getBar() == 0) { - if (a->baz == 4712) - b = magic1; - else - b = magic2; + if (a->baz == 4712) + b = magic1; + else + b = magic2; } - printf("%s\n", (b == magic1 ? "magic1" : (b == magic2 ? "magic2" : "neither"))); + printf("%s\n", + (b == magic1 ? "magic1" : (b == magic2 ? "magic2" : "neither"))); }; extern "C" { - int main(int argc, char **argv) { - runTest(); - } +int main(int argc, char **argv) { runTest(); } } diff --git a/tests/core/test_rounding.in b/tests/core/test_rounding.in index 63960ac4..af7d9099 100644 --- a/tests/core/test_rounding.in +++ b/tests/core/test_rounding.in @@ -1,29 +1,26 @@ +#include <stdio.h> +#include <math.h> - #include <stdio.h> - #include <math.h> +int main() { + printf("%.1f ", round(1.4)); + printf("%.1f ", round(1.6)); + printf("%.1f ", round(-1.4)); + printf("%.1f ", round(-1.6)); - int main() - { - printf("%.1f ", round(1.4)); - printf("%.1f ", round(1.6)); - printf("%.1f ", round(-1.4)); - printf("%.1f ", round(-1.6)); + printf("%.1f ", round(1.5)); + printf("%.1f ", round(2.5)); + printf("%.1f ", round(-1.5)); + printf("%.1f ", round(-2.5)); - printf("%.1f ", round(1.5)); - printf("%.1f ", round(2.5)); - printf("%.1f ", round(-1.5)); - printf("%.1f ", round(-2.5)); + printf("%ld ", lrint(1.4)); + printf("%ld ", lrint(1.6)); + printf("%ld ", lrint(-1.4)); + printf("%ld ", lrint(-1.6)); - printf("%ld ", lrint(1.4)); - printf("%ld ", lrint(1.6)); - printf("%ld ", lrint(-1.4)); - printf("%ld ", lrint(-1.6)); + printf("%ld ", lrint(1.5)); + printf("%ld ", lrint(2.5)); + printf("%ld ", lrint(-1.5)); + printf("%ld ", lrint(-2.5)); - printf("%ld ", lrint(1.5)); - printf("%ld ", lrint(2.5)); - printf("%ld ", lrint(-1.5)); - printf("%ld ", lrint(-2.5)); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_simd.in b/tests/core/test_simd.in index 978ea96a..5018b8e3 100644 --- a/tests/core/test_simd.in +++ b/tests/core/test_simd.in @@ -1,61 +1,69 @@ - #include <stdio.h> #include <emscripten/vector.h> static inline float32x4 __attribute__((always_inline)) -_mm_set_ps(const float __Z, const float __Y, const float __X, const float __W) -{ - return (float32x4){ __W, __X, __Y, __Z }; + _mm_set_ps(const float __Z, const float __Y, const float __X, + const float __W) { + return (float32x4) {__W, __X, __Y, __Z}; } static __inline__ float32x4 __attribute__((__always_inline__)) -_mm_setzero_ps(void) -{ - return (float32x4){ 0.0, 0.0, 0.0, 0.0 }; + _mm_setzero_ps(void) { + return (float32x4) {0.0, 0.0, 0.0, 0.0}; } int main(int argc, char **argv) { float data[8]; - for (int i = 0; i < 32; i++) data[i] = (1+i+argc)*(2+i+argc*argc); // confuse optimizer + for (int i = 0; i < 32; i++) + data[i] = (1 + i + argc) * (2 + i + argc * argc); // confuse optimizer { - float32x4 *a = (float32x4*)&data[0]; - float32x4 *b = (float32x4*)&data[4]; + float32x4 *a = (float32x4 *)&data[0]; + float32x4 *b = (float32x4 *)&data[4]; float32x4 c, d; c = *a; d = *b; - printf("1floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); - c = c+d; - printf("2floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); - d = c*d; - printf("3floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); + printf("1floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], + (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); + c = c + d; + printf("2floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], + (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); + d = c * d; + printf("3floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], + (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); c = _mm_setzero_ps(); - printf("zeros %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3]); + printf("zeros %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], + (int)c[3]); } { - int32x4 *a = (int32x4*)&data[0]; - int32x4 *b = (int32x4*)&data[4]; + int32x4 *a = (int32x4 *)&data[0]; + int32x4 *b = (int32x4 *)&data[4]; int32x4 c, d, e, f; c = *a; d = *b; - printf("4ints! %d, %d, %d, %d %d, %d, %d, %d\n", c[0], c[1], c[2], c[3], d[0], d[1], d[2], d[3]); - e = c+d; - f = c-d; - printf("5ints! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]); - e = c&d; - f = c|d; - e = ~c&d; - f = c^d; - printf("5intops! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], f[0], f[1], f[2], f[3]); + printf("4ints! %d, %d, %d, %d %d, %d, %d, %d\n", c[0], c[1], c[2], c[3], + d[0], d[1], d[2], d[3]); + e = c + d; + f = c - d; + printf("5ints! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], + f[0], f[1], f[2], f[3]); + e = c & d; + f = c | d; + e = ~c & d; + f = c ^ d; + printf("5intops! %d, %d, %d, %d %d, %d, %d, %d\n", e[0], e[1], e[2], e[3], + f[0], f[1], f[2], f[3]); } { float32x4 c, d, e, f; c = _mm_set_ps(9.0, 4.0, 0, -9.0); d = _mm_set_ps(10.0, 14.0, -12, -2.0); - printf("6floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); - printf("7calcs: %d\n", emscripten_float32x4_signmask(c)); // TODO: just not just compilation but output as well + printf("6floats! %d, %d, %d, %d %d, %d, %d, %d\n", (int)c[0], (int)c[1], + (int)c[2], (int)c[3], (int)d[0], (int)d[1], (int)d[2], (int)d[3]); + printf("7calcs: %d\n", + emscripten_float32x4_signmask(c)); // TODO: just not just + // compilation but output as well } return 0; } -
\ No newline at end of file diff --git a/tests/core/test_simd2.in b/tests/core/test_simd2.in index 97b1d841..be1655c2 100644 --- a/tests/core/test_simd2.in +++ b/tests/core/test_simd2.in @@ -1,39 +1,35 @@ +#include <stdio.h> - #include <stdio.h> - - typedef float __m128 __attribute__ ((__vector_size__ (16))); - - static inline __m128 __attribute__((always_inline)) - _mm_set_ps(const float __Z, const float __Y, const float __X, const float __W) - { - return (__m128){ __W, __X, __Y, __Z }; - } - - static inline void __attribute__((always_inline)) - _mm_store_ps(float *__P, __m128 __A) - { - *(__m128 *)__P = __A; - } - - static inline __m128 __attribute__((always_inline)) - _mm_add_ps(__m128 __A, __m128 __B) - { - return __A + __B; - } - - using namespace std; - - int main(int argc, char ** argv) { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(9.0, 4.0, 0, -9.0); - __m128 v2 = _mm_set_ps(7.0, 3.0, 2.5, 1.0); - __m128 v3 = _mm_add_ps(v1, v2); - _mm_store_ps(ar, v3); - - for (int i = 0; i < 4; i++) { - printf("%f\n", ar[i]); - } - - return 0; - } -
\ No newline at end of file +typedef float __m128 __attribute__((__vector_size__(16))); + +static inline __m128 __attribute__((always_inline)) + _mm_set_ps(const float __Z, const float __Y, const float __X, + const float __W) { + return (__m128) {__W, __X, __Y, __Z}; +} + +static inline void __attribute__((always_inline)) + _mm_store_ps(float *__P, __m128 __A) { + *(__m128 *)__P = __A; +} + +static inline __m128 __attribute__((always_inline)) + _mm_add_ps(__m128 __A, __m128 __B) { + return __A + __B; +} + +using namespace std; + +int main(int argc, char **argv) { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(9.0, 4.0, 0, -9.0); + __m128 v2 = _mm_set_ps(7.0, 3.0, 2.5, 1.0); + __m128 v3 = _mm_add_ps(v1, v2); + _mm_store_ps(ar, v3); + + for (int i = 0; i < 4; i++) { + printf("%f\n", ar[i]); + } + + return 0; +} diff --git a/tests/core/test_simd3.in b/tests/core/test_simd3.in index 462370e7..f005d847 100644 --- a/tests/core/test_simd3.in +++ b/tests/core/test_simd3.in @@ -1,471 +1,488 @@ - - #include <iostream> - #include <emmintrin.h> - #include <assert.h> - #include <stdint.h> - #include <bitset> - - using namespace std; - - void testSetPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v = _mm_set_ps(1.0, 2.0, 3.0, 4.0); - _mm_store_ps(ar, v); - assert(ar[0] == 4.0); - assert(ar[1] == 3.0); - assert(ar[2] == 2.0); - assert(ar[3] == 1.0); - } - - void testSet1Ps() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v = _mm_set1_ps(5.5); - _mm_store_ps(ar, v); - assert(ar[0] == 5.5); - assert(ar[1] == 5.5); - assert(ar[2] == 5.5); - assert(ar[3] == 5.5); - } - - void testSetZeroPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v = _mm_setzero_ps(); - _mm_store_ps(ar, v); - assert(ar[0] == 0); - assert(ar[1] == 0); - assert(ar[2] == 0); - assert(ar[3] == 0); - } - - void testSetEpi32() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128i v = _mm_set_epi32(5, 7, 126, 381); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == 381); - assert(ar[1] == 126); - assert(ar[2] == 7); - assert(ar[3] == 5); - v = _mm_set_epi32(0x55555555, 0xaaaaaaaa, 0xffffffff, 0x12345678); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == 0x12345678); - assert(ar[1] == 0xffffffff); - assert(ar[2] == 0xaaaaaaaa); - assert(ar[3] == 0x55555555); - } - - void testSet1Epi32() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128i v = _mm_set1_epi32(-5); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == -5); - assert(ar[1] == -5); - assert(ar[2] == -5); - assert(ar[3] == -5); - } - - void testSetZeroSi128() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128i v = _mm_setzero_si128(); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == 0); - assert(ar[1] == 0); - assert(ar[2] == 0); - assert(ar[3] == 0); - } - - void testBitCasts() { - int32_t __attribute__((__aligned__(16))) ar1[4]; - float __attribute__((__aligned__(16))) ar2[4]; - __m128i v1 = _mm_set_epi32(0x3f800000, 0x40000000, 0x40400000, 0x40800000); - __m128 v2 = _mm_castsi128_ps(v1); - _mm_store_ps(ar2, v2); - assert(ar2[0] == 4.0); - assert(ar2[1] == 3.0); - assert(ar2[2] == 2.0); - assert(ar2[3] == 1.0); - v2 = _mm_set_ps(5.0, 6.0, 7.0, 8.0); - v1 = _mm_castps_si128(v2); - _mm_store_si128((__m128i *)ar1, v1); - assert(ar1[0] == 0x41000000); - assert(ar1[1] == 0x40e00000); - assert(ar1[2] == 0x40c00000); - assert(ar1[3] == 0x40a00000); - float w = 0; - float z = -278.3; - float y = 5.2; - float x = -987654321; - v1 = _mm_castps_si128(_mm_set_ps(w, z, y, x)); - _mm_store_ps(ar2, _mm_castsi128_ps(v1)); - assert(ar2[0] == x); - assert(ar2[1] == y); - assert(ar2[2] == z); - assert(ar2[3] == w); - /* - std::bitset<sizeof(float)*CHAR_BIT> bits1x(*reinterpret_cast<unsigned long*>(&(ar2[0]))); - std::bitset<sizeof(float)*CHAR_BIT> bits1y(*reinterpret_cast<unsigned long*>(&(ar2[1]))); - std::bitset<sizeof(float)*CHAR_BIT> bits1z(*reinterpret_cast<unsigned long*>(&(ar2[2]))); - std::bitset<sizeof(float)*CHAR_BIT> bits1w(*reinterpret_cast<unsigned long*>(&(ar2[3]))); - std::bitset<sizeof(float)*CHAR_BIT> bits2x(*reinterpret_cast<unsigned long*>(&x)); - std::bitset<sizeof(float)*CHAR_BIT> bits2y(*reinterpret_cast<unsigned long*>(&y)); - std::bitset<sizeof(float)*CHAR_BIT> bits2z(*reinterpret_cast<unsigned long*>(&z)); - std::bitset<sizeof(float)*CHAR_BIT> bits2w(*reinterpret_cast<unsigned long*>(&w)); - assert(bits1x == bits2x); - assert(bits1y == bits2y); - assert(bits1z == bits2z); - assert(bits1w == bits2w); - */ - v2 = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0, 0x5555cccc, 0xaaaaaaaa)); - _mm_store_si128((__m128i *)ar1, _mm_castps_si128(v2)); - assert(ar1[0] == 0xaaaaaaaa); - assert(ar1[1] == 0x5555cccc); - assert(ar1[2] == 0); - assert(ar1[3] == 0xffffffff); - } - - void testConversions() { - int32_t __attribute__((__aligned__(16))) ar1[4]; - float __attribute__((__aligned__(16))) ar2[4]; - __m128i v1 = _mm_set_epi32(0, -3, -517, 256); - __m128 v2 = _mm_cvtepi32_ps(v1); - _mm_store_ps(ar2, v2); - assert(ar2[0] == 256.0); - assert(ar2[1] == -517.0); - assert(ar2[2] == -3.0); - assert(ar2[3] == 0); - v2 = _mm_set_ps(5.0, 6.0, 7.45, -8.0); - v1 = _mm_cvtps_epi32(v2); - _mm_store_si128((__m128i *)ar1, v1); - assert(ar1[0] == -8); - assert(ar1[1] == 7); - assert(ar1[2] == 6); - assert(ar1[3] == 5); - } - - void testMoveMaskPs() { - __m128 v = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff)); - int mask = _mm_movemask_ps(v); - assert(mask == 13); - } - - void testAddPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0); - __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0); - __m128 v = _mm_add_ps(v1, v2); - _mm_store_ps(ar, v); - assert(ar[0] == 41.0); - assert(ar[1] == 32.0); - assert(ar[2] == 23.0); - assert(ar[3] == 14.0); - } - - void testSubPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0); - __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0); - __m128 v = _mm_sub_ps(v1, v2); - _mm_store_ps(ar, v); - assert(ar[0] == -39.0); - assert(ar[1] == -28.0); - assert(ar[2] == -17.0); - assert(ar[3] == -6.0); - } - - void testMulPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0); - __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0); - __m128 v = _mm_mul_ps(v1, v2); - _mm_store_ps(ar, v); - assert(ar[0] == 40.0); - assert(ar[1] == 60.0); - assert(ar[2] == 60.0); - assert(ar[3] == 40.0); - } - - void testDivPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(4.0, 9.0, 8.0, 1.0); - __m128 v2 = _mm_set_ps(2.0, 3.0, 1.0, 0.5); - __m128 v = _mm_div_ps(v1, v2); - _mm_store_ps(ar, v); - assert(ar[0] == 2.0); - assert(ar[1] == 8.0); - assert(ar[2] == 3.0); - assert(ar[3] == 2.0); - } - - void testMinPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(-20.0, 10.0, 30.0, 0.5); - __m128 v2 = _mm_set_ps(2.0, 1.0, 50.0, 0.0); - __m128 v = _mm_min_ps(v1, v2); - _mm_store_ps(ar, v); - assert(ar[0] == 0.0); - assert(ar[1] == 30.0); - assert(ar[2] == 1.0); - assert(ar[3] == -20.0); - } - - void testMaxPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(-20.0, 10.0, 30.0, 0.5); - __m128 v2 = _mm_set_ps(2.5, 5.0, 55.0, 1.0); - __m128 v = _mm_max_ps(v1, v2); - _mm_store_ps(ar, v); - assert(ar[0] == 1.0); - assert(ar[1] == 55.0); - assert(ar[2] == 10.0); - assert(ar[3] == 2.5); - } - - void testSqrtPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(16.0, 9.0, 4.0, 1.0); - __m128 v = _mm_sqrt_ps(v1); - _mm_store_ps(ar, v); - assert(ar[0] == 1.0); - assert(ar[1] == 2.0); - assert(ar[2] == 3.0); - assert(ar[3] == 4.0); - } - - void testCmpLtPs() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); - __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); - __m128 v = _mm_cmplt_ps(v1, v2); - _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); - assert(ar[0] == 0xffffffff); - assert(ar[1] == 0); - assert(ar[2] == 0); - assert(ar[3] == 0xffffffff); - assert(_mm_movemask_ps(v) == 9); - } - - void testCmpLePs() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); - __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); - __m128 v = _mm_cmple_ps(v1, v2); - _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); - assert(ar[0] == 0xffffffff); - assert(ar[1] == 0); - assert(ar[2] == 0xffffffff); - assert(ar[3] == 0xffffffff); - assert(_mm_movemask_ps(v) == 13); - } - - void testCmpEqPs() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); - __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); - __m128 v = _mm_cmpeq_ps(v1, v2); - _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); - assert(ar[0] == 0); - assert(ar[1] == 0); - assert(ar[2] == 0xffffffff); - assert(ar[3] == 0); - assert(_mm_movemask_ps(v) == 4); - } - - void testCmpGePs() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); - __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); - __m128 v = _mm_cmpge_ps(v1, v2); - _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); - assert(ar[0] == 0); - assert(ar[1] == 0xffffffff); - assert(ar[2] == 0xffffffff); - assert(ar[3] == 0); - assert(_mm_movemask_ps(v) == 6); - } - - void testCmpGtPs() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); - __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); - __m128 v = _mm_cmpgt_ps(v1, v2); - _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); - assert(ar[0] == 0); - assert(ar[1] == 0xffffffff); - assert(ar[2] == 0); - assert(ar[3] == 0); - assert(_mm_movemask_ps(v) == 2); - } - - void testAndPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(425, -501, -32, 68); - __m128 v2 = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff)); - __m128 v = _mm_and_ps(v1, v2); - _mm_store_ps(ar, v); - assert(ar[0] == 68); - assert(ar[1] == 0); - assert(ar[2] == -501); - assert(ar[3] == 425); - int32_t __attribute__((__aligned__(16))) ar2[4]; - v1 = _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa)); - v2 = _mm_castsi128_ps(_mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); - v = _mm_and_ps(v1, v2); - _mm_store_si128((__m128i *)ar2, _mm_castps_si128(v)); - assert(ar2[0] == 0); - assert(ar2[1] == 0); - assert(ar2[2] == 0); - assert(ar2[3] == 0); - } - - void testAndNotPs() { - float __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_set_ps(425, -501, -32, 68); - __m128 v2 = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff)); - __m128 v = _mm_andnot_ps(v2, v1); - _mm_store_ps(ar, v); - assert(ar[0] == 0); - assert(ar[1] == -32); - assert(ar[2] == 0); - assert(ar[3] == 0); - int32_t __attribute__((__aligned__(16))) ar2[4]; - v1 = _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa)); - v2 = _mm_castsi128_ps(_mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); - v = _mm_andnot_ps(v1, v2); - _mm_store_si128((__m128i *)ar2, _mm_castps_si128(v)); - assert(ar2[0] == 0x55555555); - assert(ar2[1] == 0x55555555); - assert(ar2[2] == 0x55555555); - assert(ar2[3] == 0x55555555); - } - - void testOrPs() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0)); - __m128 v2 = _mm_castsi128_ps(_mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); - __m128 v = _mm_or_ps(v1, v2); - _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); - assert(ar[0] == 0x55555555); - assert(ar[1] == 0xffffffff); - assert(ar[2] == 0xffffffff); - assert(ar[3] == 0xffffffff); - } - - void testXorPs() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128 v1 = _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0)); - __m128 v2 = _mm_castsi128_ps(_mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); - __m128 v = _mm_xor_ps(v1, v2); - _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); - assert(ar[0] == 0x55555555); - assert(ar[1] == 0xaaaaaaaa); - assert(ar[2] == 0xffffffff); - assert(ar[3] == 0xffffffff); - } - - void testAndSi128() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa); - __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); - __m128i v = _mm_and_si128(v1, v2); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == 0); - assert(ar[1] == 0); - assert(ar[2] == 0); - assert(ar[3] == 0); - } - - void testAndNotSi128() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa); - __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); - __m128i v = _mm_andnot_si128(v1, v2); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == 0x55555555); - assert(ar[1] == 0x55555555); - assert(ar[2] == 0x55555555); - assert(ar[3] == 0x55555555); - } - - void testOrSi128() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0); - __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); - __m128i v = _mm_or_si128(v1, v2); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == 0x55555555); - assert(ar[1] == 0xffffffff); - assert(ar[2] == 0xffffffff); - assert(ar[3] == 0xffffffff); - } - - void testXorSi128() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0); - __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); - __m128i v = _mm_xor_si128(v1, v2); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == 0x55555555); - assert(ar[1] == 0xaaaaaaaa); - assert(ar[2] == 0xffffffff); - assert(ar[3] == 0xffffffff); - } - - void testAddEpi32() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128i v1 = _mm_set_epi32(4, 3, 2, 1); - __m128i v2 = _mm_set_epi32(10, 20, 30, 40); - __m128i v = _mm_add_epi32(v1, v2); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == 41); - assert(ar[1] == 32); - assert(ar[2] == 23); - assert(ar[3] == 14); - } - - void testSubEpi32() { - int32_t __attribute__((__aligned__(16))) ar[4]; - __m128i v1 = _mm_set_epi32(4, 3, 2, 1); - __m128i v2 = _mm_set_epi32(10, 20, 30, 40); - __m128i v = _mm_sub_epi32(v1, v2); - _mm_store_si128((__m128i *)ar, v); - assert(ar[0] == -39); - assert(ar[1] == -28); - assert(ar[2] == -17); - assert(ar[3] == -6); - } - - int main(int argc, char ** argv) { - testSetPs(); - testSet1Ps(); - testSetZeroPs(); - testSetEpi32(); - testSet1Epi32(); - testSetZeroSi128(); - testBitCasts(); - testConversions(); - testMoveMaskPs(); - testAddPs(); - testSubPs(); - testMulPs(); - testDivPs(); - testMaxPs(); - testMinPs(); - testSqrtPs(); - testCmpLtPs(); - testCmpLePs(); - testCmpEqPs(); - testCmpGePs(); - testCmpGtPs(); - testAndPs(); - testAndNotPs(); - testOrPs(); - testXorPs(); - testAndSi128(); - testAndNotSi128(); - testOrSi128(); - testXorSi128(); - testAddEpi32(); - testSubEpi32(); - printf("DONE"); - return 0; - } -
\ No newline at end of file +#include <iostream> +#include <emmintrin.h> +#include <assert.h> +#include <stdint.h> +#include <bitset> + +using namespace std; + +void testSetPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v = _mm_set_ps(1.0, 2.0, 3.0, 4.0); + _mm_store_ps(ar, v); + assert(ar[0] == 4.0); + assert(ar[1] == 3.0); + assert(ar[2] == 2.0); + assert(ar[3] == 1.0); +} + +void testSet1Ps() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v = _mm_set1_ps(5.5); + _mm_store_ps(ar, v); + assert(ar[0] == 5.5); + assert(ar[1] == 5.5); + assert(ar[2] == 5.5); + assert(ar[3] == 5.5); +} + +void testSetZeroPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v = _mm_setzero_ps(); + _mm_store_ps(ar, v); + assert(ar[0] == 0); + assert(ar[1] == 0); + assert(ar[2] == 0); + assert(ar[3] == 0); +} + +void testSetEpi32() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v = _mm_set_epi32(5, 7, 126, 381); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 381); + assert(ar[1] == 126); + assert(ar[2] == 7); + assert(ar[3] == 5); + v = _mm_set_epi32(0x55555555, 0xaaaaaaaa, 0xffffffff, 0x12345678); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 0x12345678); + assert(ar[1] == 0xffffffff); + assert(ar[2] == 0xaaaaaaaa); + assert(ar[3] == 0x55555555); +} + +void testSet1Epi32() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v = _mm_set1_epi32(-5); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == -5); + assert(ar[1] == -5); + assert(ar[2] == -5); + assert(ar[3] == -5); +} + +void testSetZeroSi128() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v = _mm_setzero_si128(); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 0); + assert(ar[1] == 0); + assert(ar[2] == 0); + assert(ar[3] == 0); +} + +void testBitCasts() { + int32_t __attribute__((__aligned__(16))) ar1[4]; + float __attribute__((__aligned__(16))) ar2[4]; + __m128i v1 = _mm_set_epi32(0x3f800000, 0x40000000, 0x40400000, 0x40800000); + __m128 v2 = _mm_castsi128_ps(v1); + _mm_store_ps(ar2, v2); + assert(ar2[0] == 4.0); + assert(ar2[1] == 3.0); + assert(ar2[2] == 2.0); + assert(ar2[3] == 1.0); + v2 = _mm_set_ps(5.0, 6.0, 7.0, 8.0); + v1 = _mm_castps_si128(v2); + _mm_store_si128((__m128i *)ar1, v1); + assert(ar1[0] == 0x41000000); + assert(ar1[1] == 0x40e00000); + assert(ar1[2] == 0x40c00000); + assert(ar1[3] == 0x40a00000); + float w = 0; + float z = -278.3; + float y = 5.2; + float x = -987654321; + v1 = _mm_castps_si128(_mm_set_ps(w, z, y, x)); + _mm_store_ps(ar2, _mm_castsi128_ps(v1)); + assert(ar2[0] == x); + assert(ar2[1] == y); + assert(ar2[2] == z); + assert(ar2[3] == w); + /* + std::bitset<sizeof(float)*CHAR_BIT> bits1x(*reinterpret_cast<unsigned + long*>(&(ar2[0]))); + std::bitset<sizeof(float)*CHAR_BIT> bits1y(*reinterpret_cast<unsigned + long*>(&(ar2[1]))); + std::bitset<sizeof(float)*CHAR_BIT> bits1z(*reinterpret_cast<unsigned + long*>(&(ar2[2]))); + std::bitset<sizeof(float)*CHAR_BIT> bits1w(*reinterpret_cast<unsigned + long*>(&(ar2[3]))); + std::bitset<sizeof(float)*CHAR_BIT> bits2x(*reinterpret_cast<unsigned + long*>(&x)); + std::bitset<sizeof(float)*CHAR_BIT> bits2y(*reinterpret_cast<unsigned + long*>(&y)); + std::bitset<sizeof(float)*CHAR_BIT> bits2z(*reinterpret_cast<unsigned + long*>(&z)); + std::bitset<sizeof(float)*CHAR_BIT> bits2w(*reinterpret_cast<unsigned + long*>(&w)); + assert(bits1x == bits2x); + assert(bits1y == bits2y); + assert(bits1z == bits2z); + assert(bits1w == bits2w); + */ + v2 = _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0, 0x5555cccc, 0xaaaaaaaa)); + _mm_store_si128((__m128i *)ar1, _mm_castps_si128(v2)); + assert(ar1[0] == 0xaaaaaaaa); + assert(ar1[1] == 0x5555cccc); + assert(ar1[2] == 0); + assert(ar1[3] == 0xffffffff); +} + +void testConversions() { + int32_t __attribute__((__aligned__(16))) ar1[4]; + float __attribute__((__aligned__(16))) ar2[4]; + __m128i v1 = _mm_set_epi32(0, -3, -517, 256); + __m128 v2 = _mm_cvtepi32_ps(v1); + _mm_store_ps(ar2, v2); + assert(ar2[0] == 256.0); + assert(ar2[1] == -517.0); + assert(ar2[2] == -3.0); + assert(ar2[3] == 0); + v2 = _mm_set_ps(5.0, 6.0, 7.45, -8.0); + v1 = _mm_cvtps_epi32(v2); + _mm_store_si128((__m128i *)ar1, v1); + assert(ar1[0] == -8); + assert(ar1[1] == 7); + assert(ar1[2] == 6); + assert(ar1[3] == 5); +} + +void testMoveMaskPs() { + __m128 v = + _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff)); + int mask = _mm_movemask_ps(v); + assert(mask == 13); +} + +void testAddPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0); + __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0); + __m128 v = _mm_add_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == 41.0); + assert(ar[1] == 32.0); + assert(ar[2] == 23.0); + assert(ar[3] == 14.0); +} + +void testSubPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0); + __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0); + __m128 v = _mm_sub_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == -39.0); + assert(ar[1] == -28.0); + assert(ar[2] == -17.0); + assert(ar[3] == -6.0); +} + +void testMulPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(4.0, 3.0, 2.0, 1.0); + __m128 v2 = _mm_set_ps(10.0, 20.0, 30.0, 40.0); + __m128 v = _mm_mul_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == 40.0); + assert(ar[1] == 60.0); + assert(ar[2] == 60.0); + assert(ar[3] == 40.0); +} + +void testDivPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(4.0, 9.0, 8.0, 1.0); + __m128 v2 = _mm_set_ps(2.0, 3.0, 1.0, 0.5); + __m128 v = _mm_div_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == 2.0); + assert(ar[1] == 8.0); + assert(ar[2] == 3.0); + assert(ar[3] == 2.0); +} + +void testMinPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(-20.0, 10.0, 30.0, 0.5); + __m128 v2 = _mm_set_ps(2.0, 1.0, 50.0, 0.0); + __m128 v = _mm_min_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == 0.0); + assert(ar[1] == 30.0); + assert(ar[2] == 1.0); + assert(ar[3] == -20.0); +} + +void testMaxPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(-20.0, 10.0, 30.0, 0.5); + __m128 v2 = _mm_set_ps(2.5, 5.0, 55.0, 1.0); + __m128 v = _mm_max_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == 1.0); + assert(ar[1] == 55.0); + assert(ar[2] == 10.0); + assert(ar[3] == 2.5); +} + +void testSqrtPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(16.0, 9.0, 4.0, 1.0); + __m128 v = _mm_sqrt_ps(v1); + _mm_store_ps(ar, v); + assert(ar[0] == 1.0); + assert(ar[1] == 2.0); + assert(ar[2] == 3.0); + assert(ar[3] == 4.0); +} + +void testCmpLtPs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); + __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); + __m128 v = _mm_cmplt_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0xffffffff); + assert(ar[1] == 0); + assert(ar[2] == 0); + assert(ar[3] == 0xffffffff); + assert(_mm_movemask_ps(v) == 9); +} + +void testCmpLePs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); + __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); + __m128 v = _mm_cmple_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0xffffffff); + assert(ar[1] == 0); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0xffffffff); + assert(_mm_movemask_ps(v) == 13); +} + +void testCmpEqPs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); + __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); + __m128 v = _mm_cmpeq_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0); + assert(ar[1] == 0); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0); + assert(_mm_movemask_ps(v) == 4); +} + +void testCmpGePs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); + __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); + __m128 v = _mm_cmpge_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0); + assert(ar[1] == 0xffffffff); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0); + assert(_mm_movemask_ps(v) == 6); +} + +void testCmpGtPs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(1.0, 2.0, 0.1, 0.001); + __m128 v2 = _mm_set_ps(2.0, 2.0, 0.001, 0.1); + __m128 v = _mm_cmpgt_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0); + assert(ar[1] == 0xffffffff); + assert(ar[2] == 0); + assert(ar[3] == 0); + assert(_mm_movemask_ps(v) == 2); +} + +void testAndPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(425, -501, -32, 68); + __m128 v2 = + _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff)); + __m128 v = _mm_and_ps(v1, v2); + _mm_store_ps(ar, v); + assert(ar[0] == 68); + assert(ar[1] == 0); + assert(ar[2] == -501); + assert(ar[3] == 425); + int32_t __attribute__((__aligned__(16))) ar2[4]; + v1 = _mm_castsi128_ps( + _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa)); + v2 = _mm_castsi128_ps( + _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); + v = _mm_and_ps(v1, v2); + _mm_store_si128((__m128i *)ar2, _mm_castps_si128(v)); + assert(ar2[0] == 0); + assert(ar2[1] == 0); + assert(ar2[2] == 0); + assert(ar2[3] == 0); +} + +void testAndNotPs() { + float __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = _mm_set_ps(425, -501, -32, 68); + __m128 v2 = + _mm_castsi128_ps(_mm_set_epi32(0xffffffff, 0xffffffff, 0, 0xffffffff)); + __m128 v = _mm_andnot_ps(v2, v1); + _mm_store_ps(ar, v); + assert(ar[0] == 0); + assert(ar[1] == -32); + assert(ar[2] == 0); + assert(ar[3] == 0); + int32_t __attribute__((__aligned__(16))) ar2[4]; + v1 = _mm_castsi128_ps( + _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa)); + v2 = _mm_castsi128_ps( + _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); + v = _mm_andnot_ps(v1, v2); + _mm_store_si128((__m128i *)ar2, _mm_castps_si128(v)); + assert(ar2[0] == 0x55555555); + assert(ar2[1] == 0x55555555); + assert(ar2[2] == 0x55555555); + assert(ar2[3] == 0x55555555); +} + +void testOrPs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = + _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0)); + __m128 v2 = _mm_castsi128_ps( + _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); + __m128 v = _mm_or_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0x55555555); + assert(ar[1] == 0xffffffff); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0xffffffff); +} + +void testXorPs() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128 v1 = + _mm_castsi128_ps(_mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0)); + __m128 v2 = _mm_castsi128_ps( + _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555)); + __m128 v = _mm_xor_ps(v1, v2); + _mm_store_si128((__m128i *)ar, _mm_castps_si128(v)); + assert(ar[0] == 0x55555555); + assert(ar[1] == 0xaaaaaaaa); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0xffffffff); +} + +void testAndSi128() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa); + __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); + __m128i v = _mm_and_si128(v1, v2); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 0); + assert(ar[1] == 0); + assert(ar[2] == 0); + assert(ar[3] == 0); +} + +void testAndNotSi128() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, -1431655766, 0xaaaaaaaa); + __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); + __m128i v = _mm_andnot_si128(v1, v2); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 0x55555555); + assert(ar[1] == 0x55555555); + assert(ar[2] == 0x55555555); + assert(ar[3] == 0x55555555); +} + +void testOrSi128() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0); + __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); + __m128i v = _mm_or_si128(v1, v2); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 0x55555555); + assert(ar[1] == 0xffffffff); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0xffffffff); +} + +void testXorSi128() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v1 = _mm_set_epi32(0xaaaaaaaa, 0xaaaaaaaa, 0xffffffff, 0); + __m128i v2 = _mm_set_epi32(0x55555555, 0x55555555, 0x55555555, 0x55555555); + __m128i v = _mm_xor_si128(v1, v2); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 0x55555555); + assert(ar[1] == 0xaaaaaaaa); + assert(ar[2] == 0xffffffff); + assert(ar[3] == 0xffffffff); +} + +void testAddEpi32() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v1 = _mm_set_epi32(4, 3, 2, 1); + __m128i v2 = _mm_set_epi32(10, 20, 30, 40); + __m128i v = _mm_add_epi32(v1, v2); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == 41); + assert(ar[1] == 32); + assert(ar[2] == 23); + assert(ar[3] == 14); +} + +void testSubEpi32() { + int32_t __attribute__((__aligned__(16))) ar[4]; + __m128i v1 = _mm_set_epi32(4, 3, 2, 1); + __m128i v2 = _mm_set_epi32(10, 20, 30, 40); + __m128i v = _mm_sub_epi32(v1, v2); + _mm_store_si128((__m128i *)ar, v); + assert(ar[0] == -39); + assert(ar[1] == -28); + assert(ar[2] == -17); + assert(ar[3] == -6); +} + +int main(int argc, char **argv) { + testSetPs(); + testSet1Ps(); + testSetZeroPs(); + testSetEpi32(); + testSet1Epi32(); + testSetZeroSi128(); + testBitCasts(); + testConversions(); + testMoveMaskPs(); + testAddPs(); + testSubPs(); + testMulPs(); + testDivPs(); + testMaxPs(); + testMinPs(); + testSqrtPs(); + testCmpLtPs(); + testCmpLePs(); + testCmpEqPs(); + testCmpGePs(); + testCmpGtPs(); + testAndPs(); + testAndNotPs(); + testOrPs(); + testXorPs(); + testAndSi128(); + testAndNotSi128(); + testOrSi128(); + testXorSi128(); + testAddEpi32(); + testSubEpi32(); + printf("DONE"); + return 0; +} diff --git a/tests/core/test_sintvars.in b/tests/core/test_sintvars.in index 1b377c7c..570dba48 100644 --- a/tests/core/test_sintvars.in +++ b/tests/core/test_sintvars.in @@ -1,25 +1,24 @@ +#include <stdio.h> +struct S { + char *match_start; + char *strstart; +}; +int main() { + struct S _s; + struct S *s = &_s; + unsigned short int sh; - #include <stdio.h> - struct S { - char *match_start; - char *strstart; - }; - int main() - { - struct S _s; - struct S *s = &_s; - unsigned short int sh; + s->match_start = (char *)32522; + s->strstart = (char *)(32780); + printf("*%d,%d,%d*\n", (int)s->strstart, (int)s->match_start, + (int)(s->strstart - s->match_start)); + sh = s->strstart - s->match_start; + printf("*%d,%d*\n", sh, sh >> 7); - s->match_start = (char*)32522; - s->strstart = (char*)(32780); - printf("*%d,%d,%d*\n", (int)s->strstart, (int)s->match_start, (int)(s->strstart - s->match_start)); - sh = s->strstart - s->match_start; - printf("*%d,%d*\n", sh, sh>>7); - - s->match_start = (char*)32999; - s->strstart = (char*)(32780); - printf("*%d,%d,%d*\n", (int)s->strstart, (int)s->match_start, (int)(s->strstart - s->match_start)); - sh = s->strstart - s->match_start; - printf("*%d,%d*\n", sh, sh>>7); - } -
\ No newline at end of file + s->match_start = (char *)32999; + s->strstart = (char *)(32780); + printf("*%d,%d,%d*\n", (int)s->strstart, (int)s->match_start, + (int)(s->strstart - s->match_start)); + sh = s->strstart - s->match_start; + printf("*%d,%d*\n", sh, sh >> 7); +} diff --git a/tests/core/test_sizeof.in b/tests/core/test_sizeof.in index 952e900e..1186ce41 100644 --- a/tests/core/test_sizeof.in +++ b/tests/core/test_sizeof.in @@ -1,29 +1,28 @@ +#include <stdio.h> +#include <string.h> +#include "emscripten.h" - #include <stdio.h> - #include <string.h> - #include "emscripten.h" +struct A { + int x, y; +}; - struct A { int x, y; }; +int main(int argc, const char *argv[]) { + int *a = new int[10]; + int *b = new int[1]; + int *c = new int[10]; + for (int i = 0; i < 10; i++) a[i] = 2; + *b = 5; + for (int i = 0; i < 10; i++) c[i] = 8; + printf("*%d,%d,%d,%d,%d*\n", a[0], a[9], *b, c[0], c[9]); + // Should overwrite a, but not touch b! + memcpy(a, c, 10 * sizeof(int)); + printf("*%d,%d,%d,%d,%d*\n", a[0], a[9], *b, c[0], c[9]); - int main( int argc, const char *argv[] ) { - int *a = new int[10]; - int *b = new int[1]; - int *c = new int[10]; - for (int i = 0; i < 10; i++) - a[i] = 2; - *b = 5; - for (int i = 0; i < 10; i++) - c[i] = 8; - printf("*%d,%d,%d,%d,%d*\n", a[0], a[9], *b, c[0], c[9]); - // Should overwrite a, but not touch b! - memcpy(a, c, 10*sizeof(int)); - printf("*%d,%d,%d,%d,%d*\n", a[0], a[9], *b, c[0], c[9]); + // Part 2 + A as[3] = {{5, 12}, {6, 990}, {7, 2}}; + memcpy(&as[0], &as[2], sizeof(A)); - // Part 2 - A as[3] = { { 5, 12 }, { 6, 990 }, { 7, 2 } }; - memcpy(&as[0], &as[2], sizeof(A)); - - printf("*%d,%d,%d,%d,%d,%d*\n", as[0].x, as[0].y, as[1].x, as[1].y, as[2].x, as[2].y); - return 0; - } -
\ No newline at end of file + printf("*%d,%d,%d,%d,%d,%d*\n", as[0].x, as[0].y, as[1].x, as[1].y, as[2].x, + as[2].y); + return 0; +} diff --git a/tests/core/test_sscanf.in b/tests/core/test_sscanf.in index 821e0c86..d5289fe5 100644 --- a/tests/core/test_sscanf.in +++ b/tests/core/test_sscanf.in @@ -1,88 +1,91 @@ - - #include <stdio.h> - #include <string.h> - #include <stdlib.h> - - int main () { - #define CHECK(str) \ - { \ - char name[1000]; \ - memset(name, 0, 1000); \ - int prio = 99; \ - sscanf(str, "%s %d", name, &prio); \ - printf("%s : %d\n", name, prio); \ - } - CHECK("en-us 2"); - CHECK("en-r"); - CHECK("en 3"); - - printf("%f, %f\n", atof("1.234567"), atof("cheez")); - - char float_formats[] = "fegE"; - char format[] = "%_"; - for(int i = 0; i < 4; ++i) { - format[1] = float_formats[i]; - - float n = -1; - sscanf(" 2.8208", format, &n); - printf("%.4f\n", n); - - float a = -1; - sscanf("-3.03", format, &a); - printf("%.4f\n", a); - } - - char buffy[100]; - sscanf("cheez some thing moar 123\nyet more\n", "cheez %s", buffy); - printf("|%s|\n", buffy); - sscanf("cheez something\nmoar 123\nyet more\n", "cheez %s", buffy); - printf("|%s|\n", buffy); - sscanf("cheez somethingmoar\tyet more\n", "cheez %s", buffy); - printf("|%s|\n", buffy); - - int numverts = -1; - printf("%d\n", sscanf(" numverts 1499\n", " numverts %d", &numverts)); // white space is the same, even if tab vs space - printf("%d\n", numverts); - - int index; - float u, v; - short start, count; - printf("%d\n", sscanf(" vert 87 ( 0.481565 0.059481 ) 0 1\n", " vert %d ( %f %f ) %hu %hu", &index, &u, &v, &start, &count)); - printf("%d,%.6f,%.6f,%hu,%hu\n", index, u, v, start, count); - - int neg, neg2, neg3 = 0; - printf("%d\n", sscanf("-123 -765 -34-6", "%d %u %d", &neg, &neg2, &neg3)); - printf("%d,%u,%d\n", neg, neg2, neg3); - - { - int a = 0; - sscanf("1", "%i", &a); - printf("%i\n", a); - } - - char buf1[100], buf2[100], buf3[100], buf4[100]; - - int numItems = sscanf("level=4:ref=3", "%255[^:=]=%255[^:]:%255[^=]=%255c", buf1, buf2, buf3, buf4); - printf("%d, %s, %s, %s, %s\n", numItems, buf1, buf2, buf3, buf4); - - numItems = sscanf("def|456", "%[a-z]|%[0-9]", buf1, buf2); - printf("%d, %s, %s\n", numItems, buf1, buf2); - - numItems = sscanf("3-4,-ab", "%[-0-9],%[ab-z-]", buf1, buf2); - printf("%d, %s, %s\n", numItems, buf1, buf2); - - numItems = sscanf("Hello,World", "%[A-Za-z],%[^0-9]", buf1, buf2); - printf("%d, %s, %s\n", numItems, buf1, buf2); - - numItems = sscanf("Hello4711", "%[^0-9],%[^0-9]", buf1, buf2); - printf("%d, %s\n", numItems, buf1); - - numItems = sscanf("JavaScript", "%4[A-Za-z]", buf1); - printf("%d, %s\n", numItems, buf1); - - numItems = sscanf("[]", "%1[[]%1[]]", buf1, buf2); - printf("%d, %s, %s\n", numItems, buf1, buf2); - - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +int main() { +#define CHECK(str) \ + { \ + char name[1000]; \ + memset(name, 0, 1000); \ + int prio = 99; \ + sscanf(str, "%s %d", name, &prio); \ + printf("%s : %d\n", name, prio); \ + } + CHECK("en-us 2"); + CHECK("en-r"); + CHECK("en 3"); + + printf("%f, %f\n", atof("1.234567"), atof("cheez")); + + char float_formats[] = "fegE"; + char format[] = "%_"; + for (int i = 0; i < 4; ++i) { + format[1] = float_formats[i]; + + float n = -1; + sscanf(" 2.8208", format, &n); + printf("%.4f\n", n); + + float a = -1; + sscanf("-3.03", format, &a); + printf("%.4f\n", a); + } + + char buffy[100]; + sscanf("cheez some thing moar 123\nyet more\n", "cheez %s", buffy); + printf("|%s|\n", buffy); + sscanf("cheez something\nmoar 123\nyet more\n", "cheez %s", buffy); + printf("|%s|\n", buffy); + sscanf("cheez somethingmoar\tyet more\n", "cheez %s", buffy); + printf("|%s|\n", buffy); + + int numverts = -1; + printf("%d\n", + sscanf(" numverts 1499\n", " numverts %d", + &numverts)); // white space is the same, even if tab vs space + printf("%d\n", numverts); + + int index; + float u, v; + short start, count; + printf("%d\n", + sscanf(" vert 87 ( 0.481565 0.059481 ) 0 1\n", + " vert %d ( %f %f ) %hu %hu", &index, &u, &v, &start, &count)); + printf("%d,%.6f,%.6f,%hu,%hu\n", index, u, v, start, count); + + int neg, neg2, neg3 = 0; + printf("%d\n", sscanf("-123 -765 -34-6", "%d %u %d", &neg, &neg2, &neg3)); + printf("%d,%u,%d\n", neg, neg2, neg3); + + { + int a = 0; + sscanf("1", "%i", &a); + printf("%i\n", a); + } + + char buf1[100], buf2[100], buf3[100], buf4[100]; + + int numItems = sscanf("level=4:ref=3", "%255[^:=]=%255[^:]:%255[^=]=%255c", + buf1, buf2, buf3, buf4); + printf("%d, %s, %s, %s, %s\n", numItems, buf1, buf2, buf3, buf4); + + numItems = sscanf("def|456", "%[a-z]|%[0-9]", buf1, buf2); + printf("%d, %s, %s\n", numItems, buf1, buf2); + + numItems = sscanf("3-4,-ab", "%[-0-9],%[ab-z-]", buf1, buf2); + printf("%d, %s, %s\n", numItems, buf1, buf2); + + numItems = sscanf("Hello,World", "%[A-Za-z],%[^0-9]", buf1, buf2); + printf("%d, %s, %s\n", numItems, buf1, buf2); + + numItems = sscanf("Hello4711", "%[^0-9],%[^0-9]", buf1, buf2); + printf("%d, %s\n", numItems, buf1); + + numItems = sscanf("JavaScript", "%4[A-Za-z]", buf1); + printf("%d, %s\n", numItems, buf1); + + numItems = sscanf("[]", "%1[[]%1[]]", buf1, buf2); + printf("%d, %s, %s\n", numItems, buf1, buf2); + + return 0; +} diff --git a/tests/core/test_sscanf_3.in b/tests/core/test_sscanf_3.in index fb8949e7..e21897ed 100644 --- a/tests/core/test_sscanf_3.in +++ b/tests/core/test_sscanf_3.in @@ -1,17 +1,17 @@ +#include <stdint.h> +#include <stdio.h> - #include <stdint.h> - #include <stdio.h> +int main() { - int main(){ + int64_t s, m, l; + printf("%d\n", sscanf("123 1073741823 1125899906842620", "%lld %lld %lld", &s, + &m, &l)); + printf("%lld,%lld,%lld\n", s, m, l); - int64_t s, m, l; - printf("%d\n", sscanf("123 1073741823 1125899906842620", "%lld %lld %lld", &s, &m, &l)); - printf("%lld,%lld,%lld\n", s, m, l); + int64_t negS, negM, negL; + printf("%d\n", sscanf("-123 -1073741823 -1125899906842620", "%lld %lld %lld", + &negS, &negM, &negL)); + printf("%lld,%lld,%lld\n", negS, negM, negL); - int64_t negS, negM, negL; - printf("%d\n", sscanf("-123 -1073741823 -1125899906842620", "%lld %lld %lld", &negS, &negM, &negL)); - printf("%lld,%lld,%lld\n", negS, negM, negL); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_sscanf_4.in b/tests/core/test_sscanf_4.in index b54176c5..c9e3b5f1 100644 --- a/tests/core/test_sscanf_4.in +++ b/tests/core/test_sscanf_4.in @@ -1,11 +1,8 @@ +#include <stdio.h> - #include <stdio.h> - - int main() - { - char pYear[16], pMonth[16], pDay[16], pDate[64]; - printf("%d\n", sscanf("Nov 19 2012", "%s%s%s", pMonth, pDay, pYear)); - printf("day %s, month %s, year %s \n", pDay, pMonth, pYear); - return(0); - } -
\ No newline at end of file +int main() { + char pYear[16], pMonth[16], pDay[16], pDate[64]; + printf("%d\n", sscanf("Nov 19 2012", "%s%s%s", pMonth, pDay, pYear)); + printf("day %s, month %s, year %s \n", pDay, pMonth, pYear); + return (0); +} diff --git a/tests/core/test_sscanf_5.in b/tests/core/test_sscanf_5.in index c3c1ed8a..c344258d 100644 --- a/tests/core/test_sscanf_5.in +++ b/tests/core/test_sscanf_5.in @@ -1,19 +1,13 @@ +#include "stdio.h" - #include "stdio.h" +static const char *colors[] = {" c black", ". c #001100", "X c #111100"}; - static const char *colors[] = { - " c black", - ". c #001100", - "X c #111100" - }; - - int main(){ - unsigned char code; - char color[32]; - int rcode; - for(int i = 0; i < 3; i++) { - rcode = sscanf(colors[i], "%c c %s", &code, color); - printf("%i, %c, %s\n", rcode, code, color); - } - } -
\ No newline at end of file +int main() { + unsigned char code; + char color[32]; + int rcode; + for (int i = 0; i < 3; i++) { + rcode = sscanf(colors[i], "%c c %s", &code, color); + printf("%i, %c, %s\n", rcode, code, color); + } +} diff --git a/tests/core/test_sscanf_6.in b/tests/core/test_sscanf_6.in index 2f2f58a3..63ede53f 100644 --- a/tests/core/test_sscanf_6.in +++ b/tests/core/test_sscanf_6.in @@ -1,15 +1,14 @@ - - #include <stdio.h> - #include <string.h> - int main() - { - char *date = "18.07.2013w"; - char c[10]; - memset(c, 0, 10); - int y, m, d, i; - i = sscanf(date, "%d.%d.%4d%c", &d, &m, &y, c); - printf("date: %s; day %2d, month %2d, year %4d, extra: %c, %d\n", date, d, m, y, c[0], i); - i = sscanf(date, "%d.%d.%3c", &d, &m, c); - printf("date: %s; day %2d, month %2d, year %4d, extra: %s, %d\n", date, d, m, y, c, i); - } -
\ No newline at end of file +#include <stdio.h> +#include <string.h> +int main() { + char *date = "18.07.2013w"; + char c[10]; + memset(c, 0, 10); + int y, m, d, i; + i = sscanf(date, "%d.%d.%4d%c", &d, &m, &y, c); + printf("date: %s; day %2d, month %2d, year %4d, extra: %c, %d\n", date, d, m, + y, c[0], i); + i = sscanf(date, "%d.%d.%3c", &d, &m, c); + printf("date: %s; day %2d, month %2d, year %4d, extra: %s, %d\n", date, d, m, + y, c, i); +} diff --git a/tests/core/test_sscanf_caps.in b/tests/core/test_sscanf_caps.in index 39a90db5..b0936036 100644 --- a/tests/core/test_sscanf_caps.in +++ b/tests/core/test_sscanf_caps.in @@ -1,10 +1,8 @@ +#include "stdio.h" - #include "stdio.h" - - int main(){ - unsigned int a; - float e, f, g; - sscanf("a 1.1 1.1 1.1", "%X %E %F %G", &a, &e, &f, &g); - printf("%d %.1F %.1F %.1F\n", a, e, f, g); - } -
\ No newline at end of file +int main() { + unsigned int a; + float e, f, g; + sscanf("a 1.1 1.1 1.1", "%X %E %F %G", &a, &e, &f, &g); + printf("%d %.1F %.1F %.1F\n", a, e, f, g); +} diff --git a/tests/core/test_sscanf_float.in b/tests/core/test_sscanf_float.in index e87d839a..29fe2d56 100644 --- a/tests/core/test_sscanf_float.in +++ b/tests/core/test_sscanf_float.in @@ -1,9 +1,10 @@ +#include "stdio.h" - #include "stdio.h" - - int main(){ - float f1, f2, f3, f4, f5, f6, f7, f8, f9; - sscanf("0.512 0.250x5.129_-9.98 1.12*+54.32E3 +54.32E3^87.5E-3 87.5E-3$", "%f %fx%f_%f %f*%f %f^%f %f$", &f1, &f2, &f3, &f4, &f5, &f6, &f7, &f8, &f9); - printf("\n%f, %f, %f, %f, %f, %f, %f, %f, %f\n", f1, f2, f3, f4, f5, f6, f7, f8, f9); - } -
\ No newline at end of file +int main() { + float f1, f2, f3, f4, f5, f6, f7, f8, f9; + sscanf("0.512 0.250x5.129_-9.98 1.12*+54.32E3 +54.32E3^87.5E-3 87.5E-3$", + "%f %fx%f_%f %f*%f %f^%f %f$", &f1, &f2, &f3, &f4, &f5, &f6, &f7, &f8, + &f9); + printf("\n%f, %f, %f, %f, %f, %f, %f, %f, %f\n", f1, f2, f3, f4, f5, f6, f7, + f8, f9); +} diff --git a/tests/core/test_sscanf_hex.in b/tests/core/test_sscanf_hex.in index af6c158e..d8175e82 100644 --- a/tests/core/test_sscanf_hex.in +++ b/tests/core/test_sscanf_hex.in @@ -1,9 +1,7 @@ +#include "stdio.h" - #include "stdio.h" - - int main(){ - unsigned int a, b; - sscanf("0x12AB 12AB", "%x %x", &a, &b); - printf("%d %d\n", a, b); - } -
\ No newline at end of file +int main() { + unsigned int a, b; + sscanf("0x12AB 12AB", "%x %x", &a, &b); + printf("%d %d\n", a, b); +} diff --git a/tests/core/test_sscanf_n.in b/tests/core/test_sscanf_n.in index 78142b3a..b383a3d7 100644 --- a/tests/core/test_sscanf_n.in +++ b/tests/core/test_sscanf_n.in @@ -1,21 +1,19 @@ +#include <stdio.h> +int main() { + char *line = "version 1.0"; + int i, l, lineno; + char word[80]; + if (sscanf(line, "%s%n", word, &l) != 1) { + printf("Header format error, line %d\n", lineno); + } + printf("[DEBUG] word 1: %s, l: %d\n", word, l); - #include<stdio.h> - int main() { - char *line = "version 1.0"; - int i, l, lineno; - char word[80]; - if (sscanf(line, "%s%n", word, &l) != 1) { - printf("Header format error, line %d\n", lineno); - } - printf("[DEBUG] word 1: %s, l: %d\n", word, l); - - int x = sscanf("one %n two", "%s %n", word, &l); - printf("%d,%s,%d\n", x, word, l); - { - int a, b, c, count; - count = sscanf("12345 6789", "%d %n%d", &a, &b, &c); - printf("%i %i %i %i\n", count, a, b, c); - } - return 0; - } -
\ No newline at end of file + int x = sscanf("one %n two", "%s %n", word, &l); + printf("%d,%s,%d\n", x, word, l); + { + int a, b, c, count; + count = sscanf("12345 6789", "%d %n%d", &a, &b, &c); + printf("%i %i %i %i\n", count, a, b, c); + } + return 0; +} diff --git a/tests/core/test_sscanf_other_whitespace.in b/tests/core/test_sscanf_other_whitespace.in index 224d1a23..467fa4f0 100644 --- a/tests/core/test_sscanf_other_whitespace.in +++ b/tests/core/test_sscanf_other_whitespace.in @@ -1,29 +1,23 @@ +#include <stdio.h> - #include<stdio.h> +int main() { + short int x; + short int y; - int main() { - short int x; - short int y; + const char* buffer[] = { + "\t2\t3\t", /* TAB - horizontal tab */ + "\t\t5\t\t7\t\t", "\n11\n13\n", /* LF - line feed */ + "\n\n17\n\n19\n\n", "\v23\v29\v", /* VT - vertical tab */ + "\v\v31\v\v37\v\v", "\f41\f43\f", /* FF - form feed */ + "\f\f47\f\f53\f\f", "\r59\r61\r", /* CR - carrage return */ + "\r\r67\r\r71\r\r"}; - const char* buffer[] = { - "\t2\t3\t", /* TAB - horizontal tab */ - "\t\t5\t\t7\t\t", - "\n11\n13\n", /* LF - line feed */ - "\n\n17\n\n19\n\n", - "\v23\v29\v", /* VT - vertical tab */ - "\v\v31\v\v37\v\v", - "\f41\f43\f", /* FF - form feed */ - "\f\f47\f\f53\f\f", - "\r59\r61\r", /* CR - carrage return */ - "\r\r67\r\r71\r\r" - }; + for (int i = 0; i < 10; ++i) { + x = 0; + y = 0; + sscanf(buffer[i], " %d %d ", &x, &y); + printf("%d, %d, ", x, y); + } - for (int i=0; i<10; ++i) { - x = 0; y = 0; - sscanf(buffer[i], " %d %d ", &x, &y); - printf("%d, %d, ", x, y); - } - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_sscanf_skip.in b/tests/core/test_sscanf_skip.in index 0faae7aa..f4ef8265 100644 --- a/tests/core/test_sscanf_skip.in +++ b/tests/core/test_sscanf_skip.in @@ -1,16 +1,15 @@ +#include <stdint.h> +#include <stdio.h> - #include <stdint.h> - #include <stdio.h> +int main() { + int val1; + printf("%d\n", sscanf("10 20 30 40", "%*lld %*d %d", &val1)); + printf("%d\n", val1); - int main(){ - int val1; - printf("%d\n", sscanf("10 20 30 40", "%*lld %*d %d", &val1)); - printf("%d\n", val1); + int64_t large, val2; + printf("%d\n", sscanf("1000000 -1125899906842620 -123 -1073741823", + "%lld %*lld %ld %*d", &large, &val2)); + printf("%lld,%d\n", large, val2); - int64_t large, val2; - printf("%d\n", sscanf("1000000 -1125899906842620 -123 -1073741823", "%lld %*lld %ld %*d", &large, &val2)); - printf("%lld,%d\n", large, val2); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_sscanf_whitespace.in b/tests/core/test_sscanf_whitespace.in index 6947203f..8bcf1c7b 100644 --- a/tests/core/test_sscanf_whitespace.in +++ b/tests/core/test_sscanf_whitespace.in @@ -1,23 +1,16 @@ +#include <stdio.h> - #include<stdio.h> +int main() { + short int x; + short int y; - int main() { - short int x; - short int y; + const char* buffer[] = {"173,16", " 16,173", "183, 173", + " 17, 287", " 98, 123, "}; - const char* buffer[] = { - "173,16", - " 16,173", - "183, 173", - " 17, 287", - " 98, 123, " - }; + for (int i = 0; i < 5; ++i) { + sscanf(buffer[i], "%hd,%hd", &x, &y); + printf("%d:%d,%d ", i, x, y); + } - for (int i=0; i<5; ++i) { - sscanf(buffer[i], "%hd,%hd", &x, &y); - printf("%d:%d,%d ", i, x, y); - } - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_stack.in b/tests/core/test_stack.in index 94e5d380..b2bca9a1 100644 --- a/tests/core/test_stack.in +++ b/tests/core/test_stack.in @@ -1,19 +1,16 @@ - - #include <stdio.h> - int test(int i) { - int x = 10; - if (i > 0) { - return test(i-1); - } - return int(&x); // both for the number, and forces x to not be nativized - } - int main(int argc, char **argv) - { - // We should get the same value for the first and last - stack has unwound - int x1 = test(argc - 2); - int x2 = test(100); - int x3 = test((argc - 2) / 4); - printf("*%d,%d*\n", x3-x1, x2 != x1); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +int test(int i) { + int x = 10; + if (i > 0) { + return test(i - 1); + } + return int(&x); // both for the number, and forces x to not be nativized +} +int main(int argc, char **argv) { + // We should get the same value for the first and last - stack has unwound + int x1 = test(argc - 2); + int x2 = test(100); + int x3 = test((argc - 2) / 4); + printf("*%d,%d*\n", x3 - x1, x2 != x1); + return 0; +} diff --git a/tests/core/test_stack_byval.in b/tests/core/test_stack_byval.in index 565866ee..d7007d0a 100644 --- a/tests/core/test_stack_byval.in +++ b/tests/core/test_stack_byval.in @@ -1,25 +1,21 @@ - // We should also not blow up the stack with byval arguments - #include<stdio.h> - struct vec { - int x, y, z; - vec(int x_, int y_, int z_) : x(x_), y(y_), z(z_) {} - static vec add(vec a, vec b) { - return vec(a.x+b.x, a.y+b.y, a.z+b.z); - } - }; - int main() { - int total = 0; - for (int i = 0; i < 1000; i++) { - for (int j = 0; j < 1000; j++) { - vec c(i+i%10, j*2, i%255); - vec d(j*2, j%255, i%120); - vec f = vec::add(c, d); - total += (f.x + f.y + f.z) % 100; - total %= 10240; - } - } - printf("sum:%d*\n", total); - return 0; - } - +#include <stdio.h> +struct vec { + int x, y, z; + vec(int x_, int y_, int z_) : x(x_), y(y_), z(z_) {} + static vec add(vec a, vec b) { return vec(a.x + b.x, a.y + b.y, a.z + b.z); } +}; +int main() { + int total = 0; + for (int i = 0; i < 1000; i++) { + for (int j = 0; j < 1000; j++) { + vec c(i + i % 10, j * 2, i % 255); + vec d(j * 2, j % 255, i % 120); + vec f = vec::add(c, d); + total += (f.x + f.y + f.z) % 100; + total %= 10240; + } + } + printf("sum:%d*\n", total); + return 0; +} diff --git a/tests/core/test_stack_varargs.in b/tests/core/test_stack_varargs.in index 74b600bd..01c231af 100644 --- a/tests/core/test_stack_varargs.in +++ b/tests/core/test_stack_varargs.in @@ -1,16 +1,16 @@ - // We should not blow up the stack with numerous varargs - #include <stdio.h> - #include <stdlib.h> +#include <stdio.h> +#include <stdlib.h> - void func(int i) { - printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n", - i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i); - } - int main() { - for (int i = 0; i < 1024; i++) - func(i); - printf("ok!\n"); - return 0; - } - +void func(int i) { + printf( + "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d," + "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n", + i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, + i, i, i, i, i, i, i, i, i, i, i, i, i, i); +} +int main() { + for (int i = 0; i < 1024; i++) func(i); + printf("ok!\n"); + return 0; +} diff --git a/tests/core/test_stack_void.in b/tests/core/test_stack_void.in index 7e48a0f0..0e72e509 100644 --- a/tests/core/test_stack_void.in +++ b/tests/core/test_stack_void.in @@ -1,16 +1,34 @@ +#include <stdio.h> - #include <stdio.h> - - static char s[100]="aaaaa"; - static int func(void) { - if(s[0]!='a') return 0; - printf("iso open %s\n", s, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001); - return 0; - } - int main(){ - int i; - for(i=0;i<5000;i++) - func(); - printf(".ok.\n"); - } -
\ No newline at end of file +static char s[100] = "aaaaa"; +static int func(void) { + if (s[0] != 'a') return 0; + printf("iso open %s\n", s, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, + 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001); + return 0; +} +int main() { + int i; + for (i = 0; i < 5000; i++) func(); + printf(".ok.\n"); +} diff --git a/tests/core/test_static_variable.in b/tests/core/test_static_variable.in index 82fcadac..70b41324 100644 --- a/tests/core/test_static_variable.in +++ b/tests/core/test_static_variable.in @@ -1,26 +1,18 @@ +#include <stdio.h> - #include <stdio.h> +struct DATA { + int value; - struct DATA - { - int value; + DATA() { value = 0; } +}; - DATA() - { - value = 0; - } - }; +DATA& GetData() { + static DATA data; - DATA & GetData() - { - static DATA data; + return data; +} - return data; - } - - int main() - { - GetData().value = 10; - printf( "value:%i", GetData().value ); - } -
\ No newline at end of file +int main() { + GetData().value = 10; + printf("value:%i", GetData().value); +} diff --git a/tests/core/test_statics.in b/tests/core/test_statics.in index 0935aade..d3302db5 100644 --- a/tests/core/test_statics.in +++ b/tests/core/test_statics.in @@ -1,39 +1,35 @@ +#include <stdio.h> +#include <string.h> - #include <stdio.h> - #include <string.h> +#define CONSTRLEN 32 - #define CONSTRLEN 32 +char *(*func)(char *, const char *) = NULL; - char * (*func)(char *, const char *) = NULL; +void conoutfv(const char *fmt) { + static char buf[CONSTRLEN]; + func(buf, fmt); // call by function pointer to make sure we test strcpy here + puts(buf); +} - void conoutfv(const char *fmt) - { - static char buf[CONSTRLEN]; - func(buf, fmt); // call by function pointer to make sure we test strcpy here - puts(buf); - } +struct XYZ { + float x, y, z; + XYZ(float a, float b, float c) : x(a), y(b), z(c) {} + static const XYZ &getIdentity() { + static XYZ iT(1, 2, 3); + return iT; + } +}; +struct S { + static const XYZ &getIdentity() { + static const XYZ iT(XYZ::getIdentity()); + return iT; + } +}; - struct XYZ { - float x, y, z; - XYZ(float a, float b, float c) : x(a), y(b), z(c) { } - static const XYZ& getIdentity() - { - static XYZ iT(1,2,3); - return iT; - } - }; - struct S { - static const XYZ& getIdentity() - { - static const XYZ iT(XYZ::getIdentity()); - return iT; - } - }; - - int main() { - func = &strcpy; - conoutfv("*staticccz*"); - printf("*%.2f,%.2f,%.2f*\n", S::getIdentity().x, S::getIdentity().y, S::getIdentity().z); - return 0; - } -
\ No newline at end of file +int main() { + func = &strcpy; + conoutfv("*staticccz*"); + printf("*%.2f,%.2f,%.2f*\n", S::getIdentity().x, S::getIdentity().y, + S::getIdentity().z); + return 0; +} diff --git a/tests/core/test_statvfs.in b/tests/core/test_statvfs.in index f9bd781a..72891505 100644 --- a/tests/core/test_statvfs.in +++ b/tests/core/test_statvfs.in @@ -1,26 +1,24 @@ +#include <stdio.h> +#include <errno.h> +#include <sys/statvfs.h> - #include <stdio.h> - #include <errno.h> - #include <sys/statvfs.h> +int main() { + struct statvfs s; - int main() { - struct statvfs s; + printf("result: %d\n", statvfs("/test", &s)); + printf("errno: %d\n", errno); - printf("result: %d\n", statvfs("/test", &s)); - printf("errno: %d\n", errno); + printf("f_bsize: %lu\n", s.f_bsize); + printf("f_frsize: %lu\n", s.f_frsize); + printf("f_blocks: %lu\n", s.f_blocks); + printf("f_bfree: %lu\n", s.f_bfree); + printf("f_bavail: %lu\n", s.f_bavail); + printf("f_files: %d\n", s.f_files > 5); + printf("f_ffree: %lu\n", s.f_ffree); + printf("f_favail: %lu\n", s.f_favail); + printf("f_fsid: %lu\n", s.f_fsid); + printf("f_flag: %lu\n", s.f_flag); + printf("f_namemax: %lu\n", s.f_namemax); - printf("f_bsize: %lu\n", s.f_bsize); - printf("f_frsize: %lu\n", s.f_frsize); - printf("f_blocks: %lu\n", s.f_blocks); - printf("f_bfree: %lu\n", s.f_bfree); - printf("f_bavail: %lu\n", s.f_bavail); - printf("f_files: %d\n", s.f_files > 5); - printf("f_ffree: %lu\n", s.f_ffree); - printf("f_favail: %lu\n", s.f_favail); - printf("f_fsid: %lu\n", s.f_fsid); - printf("f_flag: %lu\n", s.f_flag); - printf("f_namemax: %lu\n", s.f_namemax); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_std_cout_new.in b/tests/core/test_std_cout_new.in index 20895169..d1ab3c45 100644 --- a/tests/core/test_std_cout_new.in +++ b/tests/core/test_std_cout_new.in @@ -1,24 +1,21 @@ +#include <iostream> - #include <iostream> +struct NodeInfo { // structure that we want to transmit to our shaders + float x; + float y; + float s; + float c; +}; +const int nbNodes = 100; +NodeInfo* data = new NodeInfo[nbNodes]; // our data that will be transmitted + // using float texture. - struct NodeInfo { //structure that we want to transmit to our shaders - float x; - float y; - float s; - float c; - }; - const int nbNodes = 100; - NodeInfo * data = new NodeInfo[nbNodes]; //our data that will be transmitted using float texture. +template <int i> +void printText(const char (&text)[i]) { + std::cout << text << std::endl; +} - template<int i> - void printText( const char (&text)[ i ] ) - { - std::cout << text << std::endl; - } - - int main() - { - printText( "some string constant" ); - return 0; - } -
\ No newline at end of file +int main() { + printText("some string constant"); + return 0; +} diff --git a/tests/core/test_std_exception.in b/tests/core/test_std_exception.in index 280faed2..4b5905d8 100644 --- a/tests/core/test_std_exception.in +++ b/tests/core/test_std_exception.in @@ -1,15 +1,13 @@ +#include <stdio.h> +#include <exception> - #include <stdio.h> - #include <exception> - - int main() - { - std::exception e; - try { - throw e; - } catch(std::exception e) { - printf("caught std::exception\n"); - } - return 0; - } -
\ No newline at end of file +int main() { + std::exception e; + try { + throw e; + } + catch (std::exception e) { + printf("caught std::exception\n"); + } + return 0; +} diff --git a/tests/core/test_stdvec.in b/tests/core/test_stdvec.in index 884933c2..b370eb61 100644 --- a/tests/core/test_stdvec.in +++ b/tests/core/test_stdvec.in @@ -1,31 +1,25 @@ +#include <vector> +#include <stdio.h> - #include <vector> - #include <stdio.h> +struct S { + int a; + float b; +}; - struct S { - int a; - float b; - }; +void foo(int a, float b) { printf("%d:%.2f\n", a, b); } - void foo(int a, float b) - { - printf("%d:%.2f\n", a, b); - } +int main(int argc, char *argv[]) { + std::vector<S> ar; + S s; - int main ( int argc, char *argv[] ) - { - std::vector<S> ar; - S s; + s.a = 789; + s.b = 123.456f; + ar.push_back(s); - s.a = 789; - s.b = 123.456f; - ar.push_back(s); + s.a = 0; + s.b = 100.1f; + ar.push_back(s); - s.a = 0; - s.b = 100.1f; - ar.push_back(s); - - foo(ar[0].a, ar[0].b); - foo(ar[1].a, ar[1].b); - } -
\ No newline at end of file + foo(ar[0].a, ar[0].b); + foo(ar[1].a, ar[1].b); +} diff --git a/tests/core/test_strcasecmp.in b/tests/core/test_strcasecmp.in index 6186e50b..2fb69d1a 100644 --- a/tests/core/test_strcasecmp.in +++ b/tests/core/test_strcasecmp.in @@ -1,81 +1,79 @@ +#include <stdio.h> +#include <strings.h> +int sign(int x) { + if (x < 0) return -1; + if (x > 0) return 1; + return 0; +} +int main() { + printf("*\n"); - #include <stdio.h> - #include <strings.h> - int sign(int x) { - if (x < 0) return -1; - if (x > 0) return 1; - return 0; - } - int main() { - printf("*\n"); + printf("%d\n", sign(strcasecmp("hello", "hello"))); + printf("%d\n", sign(strcasecmp("hello1", "hello"))); + printf("%d\n", sign(strcasecmp("hello", "hello1"))); + printf("%d\n", sign(strcasecmp("hello1", "hello1"))); + printf("%d\n", sign(strcasecmp("iello", "hello"))); + printf("%d\n", sign(strcasecmp("hello", "iello"))); + printf("%d\n", sign(strcasecmp("A", "hello"))); + printf("%d\n", sign(strcasecmp("Z", "hello"))); + printf("%d\n", sign(strcasecmp("a", "hello"))); + printf("%d\n", sign(strcasecmp("z", "hello"))); + printf("%d\n", sign(strcasecmp("hello", "a"))); + printf("%d\n", sign(strcasecmp("hello", "z"))); - printf("%d\n", sign(strcasecmp("hello", "hello"))); - printf("%d\n", sign(strcasecmp("hello1", "hello"))); - printf("%d\n", sign(strcasecmp("hello", "hello1"))); - printf("%d\n", sign(strcasecmp("hello1", "hello1"))); - printf("%d\n", sign(strcasecmp("iello", "hello"))); - printf("%d\n", sign(strcasecmp("hello", "iello"))); - printf("%d\n", sign(strcasecmp("A", "hello"))); - printf("%d\n", sign(strcasecmp("Z", "hello"))); - printf("%d\n", sign(strcasecmp("a", "hello"))); - printf("%d\n", sign(strcasecmp("z", "hello"))); - printf("%d\n", sign(strcasecmp("hello", "a"))); - printf("%d\n", sign(strcasecmp("hello", "z"))); + printf("%d\n", sign(strcasecmp("Hello", "hello"))); + printf("%d\n", sign(strcasecmp("Hello1", "hello"))); + printf("%d\n", sign(strcasecmp("Hello", "hello1"))); + printf("%d\n", sign(strcasecmp("Hello1", "hello1"))); + printf("%d\n", sign(strcasecmp("Iello", "hello"))); + printf("%d\n", sign(strcasecmp("Hello", "iello"))); + printf("%d\n", sign(strcasecmp("A", "hello"))); + printf("%d\n", sign(strcasecmp("Z", "hello"))); + printf("%d\n", sign(strcasecmp("a", "hello"))); + printf("%d\n", sign(strcasecmp("z", "hello"))); + printf("%d\n", sign(strcasecmp("Hello", "a"))); + printf("%d\n", sign(strcasecmp("Hello", "z"))); - printf("%d\n", sign(strcasecmp("Hello", "hello"))); - printf("%d\n", sign(strcasecmp("Hello1", "hello"))); - printf("%d\n", sign(strcasecmp("Hello", "hello1"))); - printf("%d\n", sign(strcasecmp("Hello1", "hello1"))); - printf("%d\n", sign(strcasecmp("Iello", "hello"))); - printf("%d\n", sign(strcasecmp("Hello", "iello"))); - printf("%d\n", sign(strcasecmp("A", "hello"))); - printf("%d\n", sign(strcasecmp("Z", "hello"))); - printf("%d\n", sign(strcasecmp("a", "hello"))); - printf("%d\n", sign(strcasecmp("z", "hello"))); - printf("%d\n", sign(strcasecmp("Hello", "a"))); - printf("%d\n", sign(strcasecmp("Hello", "z"))); + printf("%d\n", sign(strcasecmp("hello", "Hello"))); + printf("%d\n", sign(strcasecmp("hello1", "Hello"))); + printf("%d\n", sign(strcasecmp("hello", "Hello1"))); + printf("%d\n", sign(strcasecmp("hello1", "Hello1"))); + printf("%d\n", sign(strcasecmp("iello", "Hello"))); + printf("%d\n", sign(strcasecmp("hello", "Iello"))); + printf("%d\n", sign(strcasecmp("A", "Hello"))); + printf("%d\n", sign(strcasecmp("Z", "Hello"))); + printf("%d\n", sign(strcasecmp("a", "Hello"))); + printf("%d\n", sign(strcasecmp("z", "Hello"))); + printf("%d\n", sign(strcasecmp("hello", "a"))); + printf("%d\n", sign(strcasecmp("hello", "z"))); - printf("%d\n", sign(strcasecmp("hello", "Hello"))); - printf("%d\n", sign(strcasecmp("hello1", "Hello"))); - printf("%d\n", sign(strcasecmp("hello", "Hello1"))); - printf("%d\n", sign(strcasecmp("hello1", "Hello1"))); - printf("%d\n", sign(strcasecmp("iello", "Hello"))); - printf("%d\n", sign(strcasecmp("hello", "Iello"))); - printf("%d\n", sign(strcasecmp("A", "Hello"))); - printf("%d\n", sign(strcasecmp("Z", "Hello"))); - printf("%d\n", sign(strcasecmp("a", "Hello"))); - printf("%d\n", sign(strcasecmp("z", "Hello"))); - printf("%d\n", sign(strcasecmp("hello", "a"))); - printf("%d\n", sign(strcasecmp("hello", "z"))); + printf("%d\n", sign(strcasecmp("Hello", "Hello"))); + printf("%d\n", sign(strcasecmp("Hello1", "Hello"))); + printf("%d\n", sign(strcasecmp("Hello", "Hello1"))); + printf("%d\n", sign(strcasecmp("Hello1", "Hello1"))); + printf("%d\n", sign(strcasecmp("Iello", "Hello"))); + printf("%d\n", sign(strcasecmp("Hello", "Iello"))); + printf("%d\n", sign(strcasecmp("A", "Hello"))); + printf("%d\n", sign(strcasecmp("Z", "Hello"))); + printf("%d\n", sign(strcasecmp("a", "Hello"))); + printf("%d\n", sign(strcasecmp("z", "Hello"))); + printf("%d\n", sign(strcasecmp("Hello", "a"))); + printf("%d\n", sign(strcasecmp("Hello", "z"))); - printf("%d\n", sign(strcasecmp("Hello", "Hello"))); - printf("%d\n", sign(strcasecmp("Hello1", "Hello"))); - printf("%d\n", sign(strcasecmp("Hello", "Hello1"))); - printf("%d\n", sign(strcasecmp("Hello1", "Hello1"))); - printf("%d\n", sign(strcasecmp("Iello", "Hello"))); - printf("%d\n", sign(strcasecmp("Hello", "Iello"))); - printf("%d\n", sign(strcasecmp("A", "Hello"))); - printf("%d\n", sign(strcasecmp("Z", "Hello"))); - printf("%d\n", sign(strcasecmp("a", "Hello"))); - printf("%d\n", sign(strcasecmp("z", "Hello"))); - printf("%d\n", sign(strcasecmp("Hello", "a"))); - printf("%d\n", sign(strcasecmp("Hello", "z"))); + printf("%d\n", sign(strncasecmp("hello", "hello", 3))); + printf("%d\n", sign(strncasecmp("hello1", "hello", 3))); + printf("%d\n", sign(strncasecmp("hello", "hello1", 3))); + printf("%d\n", sign(strncasecmp("hello1", "hello1", 3))); + printf("%d\n", sign(strncasecmp("iello", "hello", 3))); + printf("%d\n", sign(strncasecmp("hello", "iello", 3))); + printf("%d\n", sign(strncasecmp("A", "hello", 3))); + printf("%d\n", sign(strncasecmp("Z", "hello", 3))); + printf("%d\n", sign(strncasecmp("a", "hello", 3))); + printf("%d\n", sign(strncasecmp("z", "hello", 3))); + printf("%d\n", sign(strncasecmp("hello", "a", 3))); + printf("%d\n", sign(strncasecmp("hello", "z", 3))); - printf("%d\n", sign(strncasecmp("hello", "hello", 3))); - printf("%d\n", sign(strncasecmp("hello1", "hello", 3))); - printf("%d\n", sign(strncasecmp("hello", "hello1", 3))); - printf("%d\n", sign(strncasecmp("hello1", "hello1", 3))); - printf("%d\n", sign(strncasecmp("iello", "hello", 3))); - printf("%d\n", sign(strncasecmp("hello", "iello", 3))); - printf("%d\n", sign(strncasecmp("A", "hello", 3))); - printf("%d\n", sign(strncasecmp("Z", "hello", 3))); - printf("%d\n", sign(strncasecmp("a", "hello", 3))); - printf("%d\n", sign(strncasecmp("z", "hello", 3))); - printf("%d\n", sign(strncasecmp("hello", "a", 3))); - printf("%d\n", sign(strncasecmp("hello", "z", 3))); + printf("*\n"); - printf("*\n"); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_strcmp_uni.in b/tests/core/test_strcmp_uni.in index 4ccd7db8..82819dde 100644 --- a/tests/core/test_strcmp_uni.in +++ b/tests/core/test_strcmp_uni.in @@ -1,11 +1,14 @@ - - #include <stdio.h> - #include <string.h> - int main() - { - #define TEST(func) { char *word = "WORD"; char wordEntry[2] = { -61,-126 }; /* "Â"; */ int cmp = func(word, wordEntry, 2); printf("Compare value " #func " is %d\n", cmp); } - TEST(strncmp); - TEST(strncasecmp); - TEST(memcmp); - } -
\ No newline at end of file +#include <stdio.h> +#include <string.h> +int main() { +#define TEST(func) \ + { \ + char *word = "WORD"; \ + char wordEntry[2] = {-61, -126}; /* "Â"; */ \ + int cmp = func(word, wordEntry, 2); \ + printf("Compare value " #func " is %d\n", cmp); \ + } + TEST(strncmp); + TEST(strncasecmp); + TEST(memcmp); +} diff --git a/tests/core/test_strftime.in b/tests/core/test_strftime.in index 1897c58a..4a3a7fda 100644 --- a/tests/core/test_strftime.in +++ b/tests/core/test_strftime.in @@ -1,153 +1,134 @@ +#include <time.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> - #include <time.h> - #include <stdio.h> - #include <string.h> - #include <stdlib.h> - - void test(int result, const char* comment, const char* parsed = "") { - printf("%d",result); - if (!result) { - printf("\nERROR: %s (\"%s\")\n", comment, parsed); - } - } - - int cmp(const char *s1, const char *s2) { - for ( ; *s1 == *s2 ; s1++,s2++ ) { - if ( *s1 == '\0' ) - break; - } - - return (*s1 - *s2); - } - - int main() { - struct tm tm; - char s[1000]; - size_t size; - - tm.tm_sec = 4; - tm.tm_min = 23; - tm.tm_hour = 20; - tm.tm_mday = 21; - tm.tm_mon = 1; - tm.tm_year = 74; - tm.tm_wday = 4; - tm.tm_yday = 51; - tm.tm_isdst = 0; - - size = strftime(s, 1000, "", &tm); - test((size==0) && (*s=='\0'), "strftime test #1", s); - - size = strftime(s, 1000, "%a", &tm); - test((size==3) && !cmp(s, "Thu"), "strftime test #2", s); - - size = strftime(s, 1000, "%A", &tm); - test((size==8) && !cmp(s, "Thursday"), "strftime test #3", s); - - size = strftime(s, 1000, "%b", &tm); - test((size==3) && !cmp(s, "Feb"), "strftime test #4", s); - - size = strftime(s, 1000, "%B", &tm); - test((size==8) && !cmp(s, "February"), - "strftime test #5", s); - - size = strftime(s, 1000, "%d", &tm); - test((size==2) && !cmp(s, "21"), - "strftime test #6", s); - - size = strftime(s, 1000, "%H", &tm); - test((size==2) && !cmp(s, "20"), - "strftime test #7", s); - - size = strftime(s, 1000, "%I", &tm); - test((size==2) && !cmp(s, "08"), - "strftime test #8", s); - - size = strftime(s, 1000, "%j", &tm); - test((size==3) && !cmp(s, "052"), - "strftime test #9", s); - - size = strftime(s, 1000, "%m", &tm); - test((size==2) && !cmp(s, "02"), - "strftime test #10", s); - - size = strftime(s, 1000, "%M", &tm); - test((size==2) && !cmp(s, "23"), - "strftime test #11", s); - - size = strftime(s, 1000, "%p", &tm); - test((size==2) && !cmp(s, "PM"), - "strftime test #12", s); - - size = strftime(s, 1000, "%S", &tm); - test((size==2) && !cmp(s, "04"), - "strftime test #13", s); - - size = strftime(s, 1000, "%U", &tm); - test((size==2) && !cmp(s, "07"), - "strftime test #14", s); - - size = strftime(s, 1000, "%w", &tm); - test((size==1) && !cmp(s, "4"), - "strftime test #15", s); - - size = strftime(s, 1000, "%W", &tm); - test((size==2) && !cmp(s, "07"), - "strftime test #16", s); - - size = strftime(s, 1000, "%y", &tm); - test((size==2) && !cmp(s, "74"), - "strftime test #17", s); - - size = strftime(s, 1000, "%Y", &tm); - test((size==4) && !cmp(s, "1974"), - "strftime test #18", s); - - size = strftime(s, 1000, "%%", &tm); - test((size==1) && !cmp(s, "%"), - "strftime test #19", s); - - size = strftime(s, 5, "%Y", &tm); - test((size==4) && !cmp(s, "1974"), - "strftime test #20", s); - - size = strftime(s, 4, "%Y", &tm); - test((size==0), "strftime test #21", s); - - tm.tm_mon = 0; - tm.tm_mday = 1; - size = strftime(s, 10, "%U", &tm); - test((size==2) && !cmp(s, "00"), "strftime test #22", s); - - size = strftime(s, 10, "%W", &tm); - test((size==2) && !cmp(s, "00"), "strftime test #23", s); - - // 1/1/1973 was a Sunday and is in CW 1 - tm.tm_year = 73; - size = strftime(s, 10, "%W", &tm); - test((size==2) && !cmp(s, "01"), "strftime test #24", s); - - // 1/1/1978 was a Monday and is in CW 1 - tm.tm_year = 78; - size = strftime(s, 10, "%U", &tm); - test((size==2) && !cmp(s, "01"), "strftime test #25", s); - - // 2/1/1999 - tm.tm_year = 99; - tm.tm_yday = 1; - size = strftime(s, 10, "%G (%V)", &tm); - test((size==9) && !cmp(s, "1998 (53)"), "strftime test #26", s); +void test(int result, const char* comment, const char* parsed = "") { + printf("%d", result); + if (!result) { + printf("\nERROR: %s (\"%s\")\n", comment, parsed); + } +} - size = strftime(s, 10, "%g", &tm); - test((size==2) && !cmp(s, "98"), "strftime test #27", s); +int cmp(const char* s1, const char* s2) { + for (; *s1 == *s2; s1++, s2++) { + if (*s1 == '\0') break; + } - // 30/12/1997 - tm.tm_year = 97; - tm.tm_yday = 363; - size = strftime(s, 10, "%G (%V)", &tm); - test((size==9) && !cmp(s, "1998 (01)"), "strftime test #28", s); - - size = strftime(s, 10, "%g", &tm); - test((size==2) && !cmp(s, "98"), "strftime test #29", s); - } -
\ No newline at end of file + return (*s1 - *s2); +} + +int main() { + struct tm tm; + char s[1000]; + size_t size; + + tm.tm_sec = 4; + tm.tm_min = 23; + tm.tm_hour = 20; + tm.tm_mday = 21; + tm.tm_mon = 1; + tm.tm_year = 74; + tm.tm_wday = 4; + tm.tm_yday = 51; + tm.tm_isdst = 0; + + size = strftime(s, 1000, "", &tm); + test((size == 0) && (*s == '\0'), "strftime test #1", s); + + size = strftime(s, 1000, "%a", &tm); + test((size == 3) && !cmp(s, "Thu"), "strftime test #2", s); + + size = strftime(s, 1000, "%A", &tm); + test((size == 8) && !cmp(s, "Thursday"), "strftime test #3", s); + + size = strftime(s, 1000, "%b", &tm); + test((size == 3) && !cmp(s, "Feb"), "strftime test #4", s); + + size = strftime(s, 1000, "%B", &tm); + test((size == 8) && !cmp(s, "February"), "strftime test #5", s); + + size = strftime(s, 1000, "%d", &tm); + test((size == 2) && !cmp(s, "21"), "strftime test #6", s); + + size = strftime(s, 1000, "%H", &tm); + test((size == 2) && !cmp(s, "20"), "strftime test #7", s); + + size = strftime(s, 1000, "%I", &tm); + test((size == 2) && !cmp(s, "08"), "strftime test #8", s); + + size = strftime(s, 1000, "%j", &tm); + test((size == 3) && !cmp(s, "052"), "strftime test #9", s); + + size = strftime(s, 1000, "%m", &tm); + test((size == 2) && !cmp(s, "02"), "strftime test #10", s); + + size = strftime(s, 1000, "%M", &tm); + test((size == 2) && !cmp(s, "23"), "strftime test #11", s); + + size = strftime(s, 1000, "%p", &tm); + test((size == 2) && !cmp(s, "PM"), "strftime test #12", s); + + size = strftime(s, 1000, "%S", &tm); + test((size == 2) && !cmp(s, "04"), "strftime test #13", s); + + size = strftime(s, 1000, "%U", &tm); + test((size == 2) && !cmp(s, "07"), "strftime test #14", s); + + size = strftime(s, 1000, "%w", &tm); + test((size == 1) && !cmp(s, "4"), "strftime test #15", s); + + size = strftime(s, 1000, "%W", &tm); + test((size == 2) && !cmp(s, "07"), "strftime test #16", s); + + size = strftime(s, 1000, "%y", &tm); + test((size == 2) && !cmp(s, "74"), "strftime test #17", s); + + size = strftime(s, 1000, "%Y", &tm); + test((size == 4) && !cmp(s, "1974"), "strftime test #18", s); + + size = strftime(s, 1000, "%%", &tm); + test((size == 1) && !cmp(s, "%"), "strftime test #19", s); + + size = strftime(s, 5, "%Y", &tm); + test((size == 4) && !cmp(s, "1974"), "strftime test #20", s); + + size = strftime(s, 4, "%Y", &tm); + test((size == 0), "strftime test #21", s); + + tm.tm_mon = 0; + tm.tm_mday = 1; + size = strftime(s, 10, "%U", &tm); + test((size == 2) && !cmp(s, "00"), "strftime test #22", s); + + size = strftime(s, 10, "%W", &tm); + test((size == 2) && !cmp(s, "00"), "strftime test #23", s); + + // 1/1/1973 was a Sunday and is in CW 1 + tm.tm_year = 73; + size = strftime(s, 10, "%W", &tm); + test((size == 2) && !cmp(s, "01"), "strftime test #24", s); + + // 1/1/1978 was a Monday and is in CW 1 + tm.tm_year = 78; + size = strftime(s, 10, "%U", &tm); + test((size == 2) && !cmp(s, "01"), "strftime test #25", s); + + // 2/1/1999 + tm.tm_year = 99; + tm.tm_yday = 1; + size = strftime(s, 10, "%G (%V)", &tm); + test((size == 9) && !cmp(s, "1998 (53)"), "strftime test #26", s); + + size = strftime(s, 10, "%g", &tm); + test((size == 2) && !cmp(s, "98"), "strftime test #27", s); + + // 30/12/1997 + tm.tm_year = 97; + tm.tm_yday = 363; + size = strftime(s, 10, "%G (%V)", &tm); + test((size == 9) && !cmp(s, "1998 (01)"), "strftime test #28", s); + + size = strftime(s, 10, "%g", &tm); + test((size == 2) && !cmp(s, "98"), "strftime test #29", s); +} diff --git a/tests/core/test_strings.in b/tests/core/test_strings.in index 6c7e2366..3161b73f 100644 --- a/tests/core/test_strings.in +++ b/tests/core/test_strings.in @@ -1,53 +1,54 @@ - - #include <stdio.h> - #include <stdlib.h> - #include <string.h> - - int main(int argc, char **argv) - { - int x = 5, y = 9, magic = 7; // fool compiler with magic - memmove(&x, &y, magic-7); // 0 should not crash us - - int xx, yy, zz; - char s[32]; - int cc = sscanf("abc_10.b1_xyz9_543_defg", "abc_%d.%2x_xyz9_%3d_%3s", &xx, &yy, &zz, s); - printf("%d:%d,%d,%d,%s\n", cc, xx, yy, zz, s); - - printf("%d\n", argc); - puts(argv[1]); - puts(argv[2]); - printf("%d\n", atoi(argv[3])+2); - const char *foolingthecompiler = "\rabcd"; - printf("%d\n", strlen(foolingthecompiler)); // Tests parsing /0D in llvm - should not be a 0 (end string) then a D! - printf("%s\n", NULL); // Should print '(null)', not the string at address 0, which is a real address for us! - printf("/* a comment */\n"); // Should not break the generated code! - printf("// another\n"); // Should not break the generated code! - - char* strdup_val = strdup("test"); - printf("%s\n", strdup_val); - free(strdup_val); - - { - char *one = "one 1 ONE !"; - char *two = "two 2 TWO ?"; - char three[1024]; - memset(three, '.', 1024); - three[50] = 0; - strncpy(three + argc, one + (argc/2), argc+1); - strncpy(three + argc*3, two + (argc/3), argc+2); - printf("waka %s\n", three); - } - - { - char *one = "string number one top notch"; - char *two = "fa la sa ho fi FI FO FUM WHEN WHERE WHY HOW WHO"; - char three[1000]; - strcpy(three, &one[argc*2]); - char *four = strcat(three, &two[argc*3]); - printf("cat |%s|\n", three); - printf("returned |%s|\n", four); - } - - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int main(int argc, char **argv) { + int x = 5, y = 9, magic = 7; // fool compiler with magic + memmove(&x, &y, magic - 7); // 0 should not crash us + + int xx, yy, zz; + char s[32]; + int cc = sscanf("abc_10.b1_xyz9_543_defg", "abc_%d.%2x_xyz9_%3d_%3s", &xx, + &yy, &zz, s); + printf("%d:%d,%d,%d,%s\n", cc, xx, yy, zz, s); + + printf("%d\n", argc); + puts(argv[1]); + puts(argv[2]); + printf("%d\n", atoi(argv[3]) + 2); + const char *foolingthecompiler = "\rabcd"; + printf("%d\n", strlen(foolingthecompiler)); // Tests parsing /0D in llvm - + // should not be a 0 (end string) + // then a D! + printf("%s\n", NULL); // Should print '(null)', not the string at address 0, + // which is a real address for us! + printf("/* a comment */\n"); // Should not break the generated code! + printf("// another\n"); // Should not break the generated code! + + char *strdup_val = strdup("test"); + printf("%s\n", strdup_val); + free(strdup_val); + + { + char *one = "one 1 ONE !"; + char *two = "two 2 TWO ?"; + char three[1024]; + memset(three, '.', 1024); + three[50] = 0; + strncpy(three + argc, one + (argc / 2), argc + 1); + strncpy(three + argc * 3, two + (argc / 3), argc + 2); + printf("waka %s\n", three); + } + + { + char *one = "string number one top notch"; + char *two = "fa la sa ho fi FI FO FUM WHEN WHERE WHY HOW WHO"; + char three[1000]; + strcpy(three, &one[argc * 2]); + char *four = strcat(three, &two[argc * 3]); + printf("cat |%s|\n", three); + printf("returned |%s|\n", four); + } + + return 0; +} diff --git a/tests/core/test_strndup.in b/tests/core/test_strndup.in index 938452a1..2457de0c 100644 --- a/tests/core/test_strndup.in +++ b/tests/core/test_strndup.in @@ -1,39 +1,38 @@ +//--------------- +//- http://pubs.opengroup.org/onlinepubs/9699919799/functions/strndup.html +//--------------- - //--------------- - //- http://pubs.opengroup.org/onlinepubs/9699919799/functions/strndup.html - //--------------- +#include <stdio.h> +#include <stdlib.h> +#include <string.h> - #include <stdio.h> - #include <stdlib.h> - #include <string.h> +int main(int argc, char** argv) { + const char* source = + "strndup - duplicate a specific number of bytes from a string"; - int main(int argc, char **argv) { - const char* source = "strndup - duplicate a specific number of bytes from a string"; + char* strdup_val = strndup(source, 0); + printf("1:%s\n", strdup_val); + free(strdup_val); - char* strdup_val = strndup(source, 0); - printf("1:%s\n", strdup_val); - free(strdup_val); + strdup_val = strndup(source, 7); + printf("2:%s\n", strdup_val); + free(strdup_val); - strdup_val = strndup(source, 7); - printf("2:%s\n", strdup_val); - free(strdup_val); + strdup_val = strndup(source, 1000); + printf("3:%s\n", strdup_val); + free(strdup_val); - strdup_val = strndup(source, 1000); - printf("3:%s\n", strdup_val); - free(strdup_val); + strdup_val = strndup(source, 60); + printf("4:%s\n", strdup_val); + free(strdup_val); - strdup_val = strndup(source, 60); - printf("4:%s\n", strdup_val); - free(strdup_val); + strdup_val = strndup(source, 19); + printf("5:%s\n", strdup_val); + free(strdup_val); - strdup_val = strndup(source, 19); - printf("5:%s\n", strdup_val); - free(strdup_val); + strdup_val = strndup(source, -1); + printf("6:%s\n", strdup_val); + free(strdup_val); - strdup_val = strndup(source, -1); - printf("6:%s\n", strdup_val); - free(strdup_val); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_strptime_days.in b/tests/core/test_strptime_days.in index d4f0c079..382ea8ef 100644 --- a/tests/core/test_strptime_days.in +++ b/tests/core/test_strptime_days.in @@ -1,34 +1,32 @@ +#include <time.h> +#include <stdio.h> +#include <string.h> - #include <time.h> - #include <stdio.h> - #include <string.h> +static const struct { + const char *input; + const char *format; +} day_tests[] = {{"2000-01-01", "%Y-%m-%d"}, + {"03/03/00", "%D"}, + {"9/9/99", "%x"}, + {"19990502123412", "%Y%m%d%H%M%S"}, + {"2001 20 Mon", "%Y %U %a"}, + {"2006 4 Fri", "%Y %U %a"}, + {"2001 21 Mon", "%Y %W %a"}, + {"2013 29 Wed", "%Y %W %a"}, + {"2000-01-01 08:12:21 AM", "%Y-%m-%d %I:%M:%S %p"}, + {"2000-01-01 08:12:21 PM", "%Y-%m-%d %I:%M:%S %p"}, + {"2001 17 Tue", "%Y %U %a"}, + {"2001 8 Thursday", "%Y %W %a"}, }; - static const struct { - const char *input; - const char *format; - } day_tests[] = { - { "2000-01-01", "%Y-%m-%d"}, - { "03/03/00", "%D"}, - { "9/9/99", "%x"}, - { "19990502123412", "%Y%m%d%H%M%S"}, - { "2001 20 Mon", "%Y %U %a"}, - { "2006 4 Fri", "%Y %U %a"}, - { "2001 21 Mon", "%Y %W %a"}, - { "2013 29 Wed", "%Y %W %a"}, - { "2000-01-01 08:12:21 AM", "%Y-%m-%d %I:%M:%S %p"}, - { "2000-01-01 08:12:21 PM", "%Y-%m-%d %I:%M:%S %p"}, - { "2001 17 Tue", "%Y %U %a"}, - { "2001 8 Thursday", "%Y %W %a"}, - }; +int main() { + struct tm tm; - int main() { - struct tm tm; + for (int i = 0; i < sizeof(day_tests) / sizeof(day_tests[0]); ++i) { + memset(&tm, '\0', sizeof(tm)); + char *ptr = strptime(day_tests[i].input, day_tests[i].format, &tm); - for (int i = 0; i < sizeof (day_tests) / sizeof (day_tests[0]); ++i) { - memset (&tm, '\0', sizeof (tm)); - char *ptr = strptime(day_tests[i].input, day_tests[i].format, &tm); - - printf("%s: %d/%d/%d (%dth DoW, %dth DoY)\n", (ptr != NULL && *ptr=='\0') ? "OK" : "ERR", tm.tm_mon+1, tm.tm_mday, 1900+tm.tm_year, tm.tm_wday, tm.tm_yday); - } - } -
\ No newline at end of file + printf("%s: %d/%d/%d (%dth DoW, %dth DoY)\n", + (ptr != NULL && *ptr == '\0') ? "OK" : "ERR", tm.tm_mon + 1, + tm.tm_mday, 1900 + tm.tm_year, tm.tm_wday, tm.tm_yday); + } +} diff --git a/tests/core/test_strptime_reentrant.in b/tests/core/test_strptime_reentrant.in index b52d2399..b2a14d1d 100644 --- a/tests/core/test_strptime_reentrant.in +++ b/tests/core/test_strptime_reentrant.in @@ -1,47 +1,45 @@ - - #include <time.h> - #include <stdio.h> - #include <string.h> - #include <stdlib.h> - - int main () { - int result = 0; - struct tm tm; - - memset (&tm, 0xaa, sizeof (tm)); - - /* Test we don't crash on uninitialized struct tm. - Some fields might contain bogus values until everything - needed is initialized, but we shouldn't crash. */ - if (strptime ("2007", "%Y", &tm) == NULL - || strptime ("12", "%d", &tm) == NULL - || strptime ("Feb", "%b", &tm) == NULL - || strptime ("13", "%M", &tm) == NULL - || strptime ("21", "%S", &tm) == NULL - || strptime ("16", "%H", &tm) == NULL) { - printf("ERR: returned NULL"); - exit(EXIT_FAILURE); - } - - if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16 - || tm.tm_mday != 12 || tm.tm_mon != 1 || tm.tm_year != 107 - || tm.tm_wday != 1 || tm.tm_yday != 42) { - printf("ERR: unexpected tm content (1) - %d/%d/%d %d:%d:%d", tm.tm_mon+1, tm.tm_mday, tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec); - exit(EXIT_FAILURE); - } - - if (strptime ("8", "%d", &tm) == NULL) { - printf("ERR: strptime failed"); - exit(EXIT_FAILURE); - } - - if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16 - || tm.tm_mday != 8 || tm.tm_mon != 1 || tm.tm_year != 107 - || tm.tm_wday != 4 || tm.tm_yday != 38) { - printf("ERR: unexpected tm content (2) - %d/%d/%d %d:%d:%d", tm.tm_mon+1, tm.tm_mday, tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec); - exit(EXIT_FAILURE); - } - - printf("OK"); - } -
\ No newline at end of file +#include <time.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +int main() { + int result = 0; + struct tm tm; + + memset(&tm, 0xaa, sizeof(tm)); + + /* Test we don't crash on uninitialized struct tm. + Some fields might contain bogus values until everything + needed is initialized, but we shouldn't crash. */ + if (strptime("2007", "%Y", &tm) == NULL || + strptime("12", "%d", &tm) == NULL || strptime("Feb", "%b", &tm) == NULL || + strptime("13", "%M", &tm) == NULL || strptime("21", "%S", &tm) == NULL || + strptime("16", "%H", &tm) == NULL) { + printf("ERR: returned NULL"); + exit(EXIT_FAILURE); + } + + if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16 || + tm.tm_mday != 12 || tm.tm_mon != 1 || tm.tm_year != 107 || + tm.tm_wday != 1 || tm.tm_yday != 42) { + printf("ERR: unexpected tm content (1) - %d/%d/%d %d:%d:%d", tm.tm_mon + 1, + tm.tm_mday, tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec); + exit(EXIT_FAILURE); + } + + if (strptime("8", "%d", &tm) == NULL) { + printf("ERR: strptime failed"); + exit(EXIT_FAILURE); + } + + if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16 || + tm.tm_mday != 8 || tm.tm_mon != 1 || tm.tm_year != 107 || + tm.tm_wday != 4 || tm.tm_yday != 38) { + printf("ERR: unexpected tm content (2) - %d/%d/%d %d:%d:%d", tm.tm_mon + 1, + tm.tm_mday, tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec); + exit(EXIT_FAILURE); + } + + printf("OK"); +} diff --git a/tests/core/test_strptime_tm.in b/tests/core/test_strptime_tm.in index 29e40223..93cdb1d5 100644 --- a/tests/core/test_strptime_tm.in +++ b/tests/core/test_strptime_tm.in @@ -1,21 +1,27 @@ +#include <time.h> +#include <stdio.h> +#include <string.h> - #include <time.h> - #include <stdio.h> - #include <string.h> +int main() { + struct tm tm; + char *ptr = strptime("17410105012000", "%H%M%S%d%m%Y", &tm); - int main() { - struct tm tm; - char *ptr = strptime("17410105012000", "%H%M%S%d%m%Y", &tm); - - printf("%s: %s, %d/%d/%d %d:%d:%d", - (ptr != NULL && *ptr=='\0') ? "OK" : "ERR", - tm.tm_wday == 0 ? "Sun" : (tm.tm_wday == 1 ? "Mon" : (tm.tm_wday == 2 ? "Tue" : (tm.tm_wday == 3 ? "Wed" : (tm.tm_wday == 4 ? "Thu" : (tm.tm_wday == 5 ? "Fri" : (tm.tm_wday == 6 ? "Sat" : "ERR")))))), - tm.tm_mon+1, - tm.tm_mday, - tm.tm_year+1900, - tm.tm_hour, - tm.tm_min, - tm.tm_sec - ); - } -
\ No newline at end of file + printf( + "%s: %s, %d/%d/%d %d:%d:%d", (ptr != NULL && *ptr == '\0') ? "OK" : "ERR", + tm.tm_wday == 0 + ? "Sun" + : (tm.tm_wday == 1 + ? "Mon" + : (tm.tm_wday == 2 + ? "Tue" + : (tm.tm_wday == 3 + ? "Wed" + : (tm.tm_wday == 4 + ? "Thu" + : (tm.tm_wday == 5 + ? "Fri" + : (tm.tm_wday == 6 ? "Sat" + : "ERR")))))), + tm.tm_mon + 1, tm.tm_mday, tm.tm_year + 1900, tm.tm_hour, tm.tm_min, + tm.tm_sec); +} diff --git a/tests/core/test_strstr.in b/tests/core/test_strstr.in index ab049cac..8aa56d4a 100644 --- a/tests/core/test_strstr.in +++ b/tests/core/test_strstr.in @@ -1,35 +1,32 @@ +#include <stdio.h> +#include <string.h> - #include <stdio.h> - #include <string.h> +int main() { + printf("%d\n", !!strstr("\\n", "\\n")); + printf("%d\n", !!strstr("cheezy", "ez")); + printf("%d\n", !!strstr("cheeezy", "ez")); + printf("%d\n", !!strstr("cheeeeeeeeeezy", "ez")); + printf("%d\n", !!strstr("cheeeeeeeeee1zy", "ez")); + printf("%d\n", !!strstr("che1ezy", "ez")); + printf("%d\n", !!strstr("che1ezy", "che")); + printf("%d\n", !!strstr("ce1ezy", "che")); + printf("%d\n", !!strstr("ce1ezy", "ezy")); + printf("%d\n", !!strstr("ce1ezyt", "ezy")); + printf("%d\n", !!strstr("ce1ez1y", "ezy")); + printf("%d\n", !!strstr("cheezy", "a")); + printf("%d\n", !!strstr("cheezy", "b")); + printf("%d\n", !!strstr("cheezy", "c")); + printf("%d\n", !!strstr("cheezy", "d")); + printf("%d\n", !!strstr("cheezy", "g")); + printf("%d\n", !!strstr("cheezy", "h")); + printf("%d\n", !!strstr("cheezy", "i")); + printf("%d\n", !!strstr("cheezy", "e")); + printf("%d\n", !!strstr("cheezy", "x")); + printf("%d\n", !!strstr("cheezy", "y")); + printf("%d\n", !!strstr("cheezy", "z")); + printf("%d\n", !!strstr("cheezy", "_")); - int main() - { - printf("%d\n", !!strstr("\\n", "\\n")); - printf("%d\n", !!strstr("cheezy", "ez")); - printf("%d\n", !!strstr("cheeezy", "ez")); - printf("%d\n", !!strstr("cheeeeeeeeeezy", "ez")); - printf("%d\n", !!strstr("cheeeeeeeeee1zy", "ez")); - printf("%d\n", !!strstr("che1ezy", "ez")); - printf("%d\n", !!strstr("che1ezy", "che")); - printf("%d\n", !!strstr("ce1ezy", "che")); - printf("%d\n", !!strstr("ce1ezy", "ezy")); - printf("%d\n", !!strstr("ce1ezyt", "ezy")); - printf("%d\n", !!strstr("ce1ez1y", "ezy")); - printf("%d\n", !!strstr("cheezy", "a")); - printf("%d\n", !!strstr("cheezy", "b")); - printf("%d\n", !!strstr("cheezy", "c")); - printf("%d\n", !!strstr("cheezy", "d")); - printf("%d\n", !!strstr("cheezy", "g")); - printf("%d\n", !!strstr("cheezy", "h")); - printf("%d\n", !!strstr("cheezy", "i")); - printf("%d\n", !!strstr("cheezy", "e")); - printf("%d\n", !!strstr("cheezy", "x")); - printf("%d\n", !!strstr("cheezy", "y")); - printf("%d\n", !!strstr("cheezy", "z")); - printf("%d\n", !!strstr("cheezy", "_")); - - const char *str = "a big string"; - printf("%d\n", strstr(str, "big") - str); - return 0; - } -
\ No newline at end of file + const char *str = "a big string"; + printf("%d\n", strstr(str, "big") - str); + return 0; +} diff --git a/tests/core/test_strtok.in b/tests/core/test_strtok.in index 6391b9b0..6ef57191 100644 --- a/tests/core/test_strtok.in +++ b/tests/core/test_strtok.in @@ -1,20 +1,20 @@ +#include <stdio.h> +#include <string.h> - #include<stdio.h> - #include<string.h> +int main() { + char test[80], blah[80]; + char *sep = "\\/:;=-"; + char *word, *phrase, *brkt, *brkb; - int main() { - char test[80], blah[80]; - char *sep = "\\/:;=-"; - char *word, *phrase, *brkt, *brkb; + strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function."); - strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function."); - - for (word = strtok_r(test, sep, &brkt); word; word = strtok_r(NULL, sep, &brkt)) { - strcpy(blah, "blah:blat:blab:blag"); - for (phrase = strtok_r(blah, sep, &brkb); phrase; phrase = strtok_r(NULL, sep, &brkb)) { - printf("at %s:%s\n", word, phrase); - } - } - return 0; - } -
\ No newline at end of file + for (word = strtok_r(test, sep, &brkt); word; + word = strtok_r(NULL, sep, &brkt)) { + strcpy(blah, "blah:blat:blab:blag"); + for (phrase = strtok_r(blah, sep, &brkb); phrase; + phrase = strtok_r(NULL, sep, &brkb)) { + printf("at %s:%s\n", word, phrase); + } + } + return 0; +} diff --git a/tests/core/test_strtol_bin.in b/tests/core/test_strtol_bin.in index 972853ba..e54e0173 100644 --- a/tests/core/test_strtol_bin.in +++ b/tests/core/test_strtol_bin.in @@ -1,17 +1,15 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +int main() { + const char *STRING = "1 -101 +1011"; + char *end_char; - int main() { - const char *STRING = "1 -101 +1011"; - char *end_char; + // defined base + long l4 = strtol(STRING, &end_char, 2); + long l5 = strtol(end_char, &end_char, 2); + long l6 = strtol(end_char, NULL, 2); - // defined base - long l4 = strtol(STRING, &end_char, 2); - long l5 = strtol(end_char, &end_char, 2); - long l6 = strtol(end_char, NULL, 2); - - printf("%d%d%d\n", l4==1, l5==-5, l6==11); - return 0; - } -
\ No newline at end of file + printf("%d%d%d\n", l4 == 1, l5 == -5, l6 == 11); + return 0; +} diff --git a/tests/core/test_strtol_dec.in b/tests/core/test_strtol_dec.in index 496e5dc8..56053521 100644 --- a/tests/core/test_strtol_dec.in +++ b/tests/core/test_strtol_dec.in @@ -1,22 +1,21 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +int main() { + const char *STRING = "4 -38 +4711"; + char *end_char; - int main() { - const char *STRING = "4 -38 +4711"; - char *end_char; + // undefined base + long l1 = strtol(STRING, &end_char, 0); + long l2 = strtol(end_char, &end_char, 0); + long l3 = strtol(end_char, NULL, 0); - // undefined base - long l1 = strtol(STRING, &end_char, 0); - long l2 = strtol(end_char, &end_char, 0); - long l3 = strtol(end_char, NULL, 0); + // defined base + long l4 = strtol(STRING, &end_char, 10); + long l5 = strtol(end_char, &end_char, 10); + long l6 = strtol(end_char, NULL, 10); - // defined base - long l4 = strtol(STRING, &end_char, 10); - long l5 = strtol(end_char, &end_char, 10); - long l6 = strtol(end_char, NULL, 10); - - printf("%d%d%d%d%d%d\n", l1==4, l2==-38, l3==4711, l4==4, l5==-38, l6==4711); - return 0; - } -
\ No newline at end of file + printf("%d%d%d%d%d%d\n", l1 == 4, l2 == -38, l3 == 4711, l4 == 4, l5 == -38, + l6 == 4711); + return 0; +} diff --git a/tests/core/test_strtol_hex.in b/tests/core/test_strtol_hex.in index f11d786a..65a43ed0 100644 --- a/tests/core/test_strtol_hex.in +++ b/tests/core/test_strtol_hex.in @@ -1,22 +1,21 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +int main() { + const char *STRING = "0x4 -0x3A +0xDEAD"; + char *end_char; - int main() { - const char *STRING = "0x4 -0x3A +0xDEAD"; - char *end_char; + // undefined base + long l1 = strtol(STRING, &end_char, 0); + long l2 = strtol(end_char, &end_char, 0); + long l3 = strtol(end_char, NULL, 0); - // undefined base - long l1 = strtol(STRING, &end_char, 0); - long l2 = strtol(end_char, &end_char, 0); - long l3 = strtol(end_char, NULL, 0); + // defined base + long l4 = strtol(STRING, &end_char, 16); + long l5 = strtol(end_char, &end_char, 16); + long l6 = strtol(end_char, NULL, 16); - // defined base - long l4 = strtol(STRING, &end_char, 16); - long l5 = strtol(end_char, &end_char, 16); - long l6 = strtol(end_char, NULL, 16); - - printf("%d%d%d%d%d%d\n", l1==0x4, l2==-0x3a, l3==0xdead, l4==0x4, l5==-0x3a, l6==0xdead); - return 0; - } -
\ No newline at end of file + printf("%d%d%d%d%d%d\n", l1 == 0x4, l2 == -0x3a, l3 == 0xdead, l4 == 0x4, + l5 == -0x3a, l6 == 0xdead); + return 0; +} diff --git a/tests/core/test_strtol_oct.in b/tests/core/test_strtol_oct.in index a50166a4..94b9c3ff 100644 --- a/tests/core/test_strtol_oct.in +++ b/tests/core/test_strtol_oct.in @@ -1,22 +1,21 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +int main() { + const char *STRING = "0 -035 +04711"; + char *end_char; - int main() { - const char *STRING = "0 -035 +04711"; - char *end_char; + // undefined base + long l1 = strtol(STRING, &end_char, 0); + long l2 = strtol(end_char, &end_char, 0); + long l3 = strtol(end_char, NULL, 0); - // undefined base - long l1 = strtol(STRING, &end_char, 0); - long l2 = strtol(end_char, &end_char, 0); - long l3 = strtol(end_char, NULL, 0); + // defined base + long l4 = strtol(STRING, &end_char, 8); + long l5 = strtol(end_char, &end_char, 8); + long l6 = strtol(end_char, NULL, 8); - // defined base - long l4 = strtol(STRING, &end_char, 8); - long l5 = strtol(end_char, &end_char, 8); - long l6 = strtol(end_char, NULL, 8); - - printf("%d%d%d%d%d%d\n", l1==0, l2==-29, l3==2505, l4==0, l5==-29, l6==2505); - return 0; - } -
\ No newline at end of file + printf("%d%d%d%d%d%d\n", l1 == 0, l2 == -29, l3 == 2505, l4 == 0, l5 == -29, + l6 == 2505); + return 0; +} diff --git a/tests/core/test_strtoll_bin.in b/tests/core/test_strtoll_bin.in index ed3c4acf..cbe5546f 100644 --- a/tests/core/test_strtoll_bin.in +++ b/tests/core/test_strtoll_bin.in @@ -1,17 +1,15 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +int main() { + const char *STRING = "1 -101 +1011"; + char *end_char; - int main() { - const char *STRING = "1 -101 +1011"; - char *end_char; + // defined base + long long int l4 = strtoll(STRING, &end_char, 2); + long long int l5 = strtoll(end_char, &end_char, 2); + long long int l6 = strtoll(end_char, NULL, 2); - // defined base - long long int l4 = strtoll(STRING, &end_char, 2); - long long int l5 = strtoll(end_char, &end_char, 2); - long long int l6 = strtoll(end_char, NULL, 2); - - printf("%d%d%d\n", l4==1, l5==-5, l6==11); - return 0; - } -
\ No newline at end of file + printf("%d%d%d\n", l4 == 1, l5 == -5, l6 == 11); + return 0; +} diff --git a/tests/core/test_strtoll_dec.in b/tests/core/test_strtoll_dec.in index fbd5749c..f4d2950e 100644 --- a/tests/core/test_strtoll_dec.in +++ b/tests/core/test_strtoll_dec.in @@ -1,22 +1,21 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +int main() { + const char *STRING = "4 -38 +4711"; + char *end_char; - int main() { - const char *STRING = "4 -38 +4711"; - char *end_char; + // undefined base + long long int l1 = strtoll(STRING, &end_char, 0); + long long int l2 = strtoll(end_char, &end_char, 0); + long long int l3 = strtoll(end_char, NULL, 0); - // undefined base - long long int l1 = strtoll(STRING, &end_char, 0); - long long int l2 = strtoll(end_char, &end_char, 0); - long long int l3 = strtoll(end_char, NULL, 0); + // defined base + long long int l4 = strtoll(STRING, &end_char, 10); + long long int l5 = strtoll(end_char, &end_char, 10); + long long int l6 = strtoll(end_char, NULL, 10); - // defined base - long long int l4 = strtoll(STRING, &end_char, 10); - long long int l5 = strtoll(end_char, &end_char, 10); - long long int l6 = strtoll(end_char, NULL, 10); - - printf("%d%d%d%d%d%d\n", l1==4, l2==-38, l3==4711, l4==4, l5==-38, l6==4711); - return 0; - } -
\ No newline at end of file + printf("%d%d%d%d%d%d\n", l1 == 4, l2 == -38, l3 == 4711, l4 == 4, l5 == -38, + l6 == 4711); + return 0; +} diff --git a/tests/core/test_strtoll_hex.in b/tests/core/test_strtoll_hex.in index 333fe512..a432d0dd 100644 --- a/tests/core/test_strtoll_hex.in +++ b/tests/core/test_strtoll_hex.in @@ -1,22 +1,21 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +int main() { + const char *STRING = "0x4 -0x3A +0xDEADBEEF"; + char *end_char; - int main() { - const char *STRING = "0x4 -0x3A +0xDEADBEEF"; - char *end_char; + // undefined base + long long int l1 = strtoll(STRING, &end_char, 0); + long long int l2 = strtoll(end_char, &end_char, 0); + long long int l3 = strtoll(end_char, NULL, 0); - // undefined base - long long int l1 = strtoll(STRING, &end_char, 0); - long long int l2 = strtoll(end_char, &end_char, 0); - long long int l3 = strtoll(end_char, NULL, 0); + // defined base + long long int l4 = strtoll(STRING, &end_char, 16); + long long int l5 = strtoll(end_char, &end_char, 16); + long long int l6 = strtoll(end_char, NULL, 16); - // defined base - long long int l4 = strtoll(STRING, &end_char, 16); - long long int l5 = strtoll(end_char, &end_char, 16); - long long int l6 = strtoll(end_char, NULL, 16); - - printf("%d%d%d%d%d%d\n", l1==0x4, l2==-0x3a, l3==0xdeadbeef, l4==0x4, l5==-0x3a, l6==0xdeadbeef); - return 0; - } -
\ No newline at end of file + printf("%d%d%d%d%d%d\n", l1 == 0x4, l2 == -0x3a, l3 == 0xdeadbeef, l4 == 0x4, + l5 == -0x3a, l6 == 0xdeadbeef); + return 0; +} diff --git a/tests/core/test_strtoll_oct.in b/tests/core/test_strtoll_oct.in index 260c7245..e5e12e24 100644 --- a/tests/core/test_strtoll_oct.in +++ b/tests/core/test_strtoll_oct.in @@ -1,22 +1,21 @@ +#include <stdio.h> +#include <stdlib.h> - #include <stdio.h> - #include <stdlib.h> +int main() { + const char *STRING = "0 -035 +04711"; + char *end_char; - int main() { - const char *STRING = "0 -035 +04711"; - char *end_char; + // undefined base + long long int l1 = strtoll(STRING, &end_char, 0); + long long int l2 = strtoll(end_char, &end_char, 0); + long long int l3 = strtoll(end_char, NULL, 0); - // undefined base - long long int l1 = strtoll(STRING, &end_char, 0); - long long int l2 = strtoll(end_char, &end_char, 0); - long long int l3 = strtoll(end_char, NULL, 0); + // defined base + long long int l4 = strtoll(STRING, &end_char, 8); + long long int l5 = strtoll(end_char, &end_char, 8); + long long int l6 = strtoll(end_char, NULL, 8); - // defined base - long long int l4 = strtoll(STRING, &end_char, 8); - long long int l5 = strtoll(end_char, &end_char, 8); - long long int l6 = strtoll(end_char, NULL, 8); - - printf("%d%d%d%d%d%d\n", l1==0, l2==-29, l3==2505, l4==0, l5==-29, l6==2505); - return 0; - } -
\ No newline at end of file + printf("%d%d%d%d%d%d\n", l1 == 0, l2 == -29, l3 == 2505, l4 == 0, l5 == -29, + l6 == 2505); + return 0; +} diff --git a/tests/core/test_structs.in b/tests/core/test_structs.in index 47158351..2d48a9aa 100644 --- a/tests/core/test_structs.in +++ b/tests/core/test_structs.in @@ -1,22 +1,21 @@ - - #include <stdio.h> - struct S - { - int x, y; - }; - int main() - { - S a, b; - a.x = 5; a.y = 6; - b.x = 101; b.y = 7009; - S *c, *d; - c = &a; - c->x *= 2; - c = &b; - c->y -= 1; - d = c; - d->y += 10; - printf("*%d,%d,%d,%d,%d,%d,%d,%d*\n", a.x, a.y, b.x, b.y, c->x, c->y, d->x, d->y); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +struct S { + int x, y; +}; +int main() { + S a, b; + a.x = 5; + a.y = 6; + b.x = 101; + b.y = 7009; + S *c, *d; + c = &a; + c->x *= 2; + c = &b; + c->y -= 1; + d = c; + d->y += 10; + printf("*%d,%d,%d,%d,%d,%d,%d,%d*\n", a.x, a.y, b.x, b.y, c->x, c->y, d->x, + d->y); + return 0; +} diff --git a/tests/core/test_time_c.in b/tests/core/test_time_c.in index 57b47217..9719464c 100644 --- a/tests/core/test_time_c.in +++ b/tests/core/test_time_c.in @@ -1,9 +1,7 @@ +#include <time.h> +#include <stdio.h> - #include <time.h> - #include <stdio.h> - - int main() { - time_t t = time(0); - printf("time: %s\n", ctime(&t)); - } -
\ No newline at end of file +int main() { + time_t t = time(0); + printf("time: %s\n", ctime(&t)); +} diff --git a/tests/core/test_timeb.in b/tests/core/test_timeb.in index baaefb8c..1e59f301 100644 --- a/tests/core/test_timeb.in +++ b/tests/core/test_timeb.in @@ -1,15 +1,13 @@ +#include <stdio.h> +#include <assert.h> +#include <sys/timeb.h> - #include <stdio.h> - #include <assert.h> - #include <sys/timeb.h> - - int main() { - timeb tb; - tb.timezone = 1; - printf("*%d\n", ftime(&tb)); - assert(tb.time > 10000); - assert(tb.timezone == 0); - assert(tb.dstflag == 0); - return 0; - } -
\ No newline at end of file +int main() { + timeb tb; + tb.timezone = 1; + printf("*%d\n", ftime(&tb)); + assert(tb.time > 10000); + assert(tb.timezone == 0); + assert(tb.dstflag == 0); + return 0; +} diff --git a/tests/core/test_tinyfuncstr.in b/tests/core/test_tinyfuncstr.in index ea07ff33..fd1c9563 100644 --- a/tests/core/test_tinyfuncstr.in +++ b/tests/core/test_tinyfuncstr.in @@ -1,13 +1,11 @@ +#include <stdio.h> - #include <stdio.h> +struct Class { + static char *name1() { return "nameA"; } + char *name2() { return "nameB"; } +}; - struct Class { - static char *name1() { return "nameA"; } - char *name2() { return "nameB"; } - }; - - int main() { - printf("*%s,%s*\n", Class::name1(), (new Class())->name2()); - return 0; - } -
\ No newline at end of file +int main() { + printf("*%s,%s*\n", Class::name1(), (new Class())->name2()); + return 0; +} diff --git a/tests/core/test_transtrcase.in b/tests/core/test_transtrcase.in index 0592405e..a19fcb6e 100644 --- a/tests/core/test_transtrcase.in +++ b/tests/core/test_transtrcase.in @@ -1,13 +1,11 @@ - - #include <stdio.h> - #include <string.h> - int main() { - char szToupr[] = "hello, "; - char szTolwr[] = "EMSCRIPTEN"; - strupr(szToupr); - strlwr(szTolwr); - printf(szToupr); - printf(szTolwr); - return 0; - } -
\ No newline at end of file +#include <stdio.h> +#include <string.h> +int main() { + char szToupr[] = "hello, "; + char szTolwr[] = "EMSCRIPTEN"; + strupr(szToupr); + strlwr(szTolwr); + printf(szToupr); + printf(szTolwr); + return 0; +} diff --git a/tests/core/test_trickystring.in b/tests/core/test_trickystring.in index 95744369..2735ef7c 100644 --- a/tests/core/test_trickystring.in +++ b/tests/core/test_trickystring.in @@ -1,26 +1,16 @@ +#include <stdio.h> - #include <stdio.h> +typedef struct { + int (*f)(void *); + void *d; + char s[16]; +} LMEXFunctionStruct; - typedef struct - { - int (*f)(void *); - void *d; - char s[16]; - } LMEXFunctionStruct; +int f(void *user) { return 0; } - int f(void *user) - { - return 0; - } +static LMEXFunctionStruct const a[] = {{f, (void *)(int)'a', "aa"}}; - static LMEXFunctionStruct const a[] = - { - {f, (void *)(int)'a', "aa"} - }; - - int main() - { - printf("ok\n"); - return a[0].f(a[0].d); - } -
\ No newline at end of file +int main() { + printf("ok\n"); + return a[0].f(a[0].d); +} diff --git a/tests/core/test_typeid.in b/tests/core/test_typeid.in index fc777183..1f87e66e 100644 --- a/tests/core/test_typeid.in +++ b/tests/core/test_typeid.in @@ -1,53 +1,52 @@ - - #include <stdio.h> - #include <string.h> - #include <typeinfo> - int main() { - printf("*\n"); - #define MAX 100 - int ptrs[MAX]; - int groups[MAX]; - memset(ptrs, 0, MAX*sizeof(int)); - memset(groups, 0, MAX*sizeof(int)); - int next_group = 1; - #define TEST(X) { \ - int ptr = (int)&typeid(X); \ - int group = 0; \ - int i; \ - for (i = 0; i < MAX; i++) { \ - if (!groups[i]) break; \ - if (ptrs[i] == ptr) { \ - group = groups[i]; \ - break; \ - } \ - } \ - if (!group) { \ - groups[i] = group = next_group++; \ - ptrs[i] = ptr; \ - } \ - printf("%s:%d\n", #X, group); \ - } - TEST(int); - TEST(unsigned int); - TEST(unsigned); - TEST(signed int); - TEST(long); - TEST(unsigned long); - TEST(signed long); - TEST(long long); - TEST(unsigned long long); - TEST(signed long long); - TEST(short); - TEST(unsigned short); - TEST(signed short); - TEST(char); - TEST(unsigned char); - TEST(signed char); - TEST(float); - TEST(double); - TEST(long double); - TEST(void); - TEST(void*); - printf("*\n"); - } -
\ No newline at end of file +#include <stdio.h> +#include <string.h> +#include <typeinfo> +int main() { + printf("*\n"); +#define MAX 100 + int ptrs[MAX]; + int groups[MAX]; + memset(ptrs, 0, MAX * sizeof(int)); + memset(groups, 0, MAX * sizeof(int)); + int next_group = 1; +#define TEST(X) \ + { \ + int ptr = (int)&typeid(X); \ + int group = 0; \ + int i; \ + for (i = 0; i < MAX; i++) { \ + if (!groups[i]) break; \ + if (ptrs[i] == ptr) { \ + group = groups[i]; \ + break; \ + } \ + } \ + if (!group) { \ + groups[i] = group = next_group++; \ + ptrs[i] = ptr; \ + } \ + printf("%s:%d\n", #X, group); \ + } + TEST(int); + TEST(unsigned int); + TEST(unsigned); + TEST(signed int); + TEST(long); + TEST(unsigned long); + TEST(signed long); + TEST(long long); + TEST(unsigned long long); + TEST(signed long long); + TEST(short); + TEST(unsigned short); + TEST(signed short); + TEST(char); + TEST(unsigned char); + TEST(signed char); + TEST(float); + TEST(double); + TEST(long double); + TEST(void); + TEST(void*); + printf("*\n"); +} diff --git a/tests/core/test_uname.in b/tests/core/test_uname.in index 5ea40b06..780a754b 100644 --- a/tests/core/test_uname.in +++ b/tests/core/test_uname.in @@ -1,16 +1,14 @@ +#include <stdio.h> +#include <sys/utsname.h> - #include <stdio.h> - #include <sys/utsname.h> - - int main() { - struct utsname u; - printf("ret: %d\n", uname(&u)); - printf("sysname: %s\n", u.sysname); - printf("nodename: %s\n", u.nodename); - printf("release: %s\n", u.release); - printf("version: %s\n", u.version); - printf("machine: %s\n", u.machine); - printf("invalid: %d\n", uname(0)); - return 0; - } -
\ No newline at end of file +int main() { + struct utsname u; + printf("ret: %d\n", uname(&u)); + printf("sysname: %s\n", u.sysname); + printf("nodename: %s\n", u.nodename); + printf("release: %s\n", u.release); + printf("version: %s\n", u.version); + printf("machine: %s\n", u.machine); + printf("invalid: %d\n", uname(0)); + return 0; +} diff --git a/tests/core/test_utf.in b/tests/core/test_utf.in index 29cb6eac..87731186 100644 --- a/tests/core/test_utf.in +++ b/tests/core/test_utf.in @@ -1,13 +1,15 @@ +#include <stdio.h> +#include <emscripten.h> - #include <stdio.h> - #include <emscripten.h> - - int main() { - char *c = "μ†ℱ ╋ℯ╳╋ 😇"; - printf("%d %d %d %d %s\n", c[0]&0xff, c[1]&0xff, c[2]&0xff, c[3]&0xff, c); - emscripten_run_script( - "cheez = _malloc(100);" - "Module.writeStringToMemory(\"μ†ℱ ╋ℯ╳╋ 😇\", cheez);" - "Module.print([Pointer_stringify(cheez), Module.getValue(cheez, 'i8')&0xff, Module.getValue(cheez+1, 'i8')&0xff, Module.getValue(cheez+2, 'i8')&0xff, Module.getValue(cheez+3, 'i8')&0xff, ]);"); - } -
\ No newline at end of file +int main() { + char *c = "μ†ℱ ╋ℯ╳╋ 😇"; + printf("%d %d %d %d %s\n", c[0] & 0xff, c[1] & 0xff, c[2] & 0xff, c[3] & 0xff, + c); + emscripten_run_script( + "cheez = _malloc(100);" + "Module.writeStringToMemory(\"μ†ℱ ╋ℯ╳╋ 😇\", cheez);" + "Module.print([Pointer_stringify(cheez), Module.getValue(cheez, " + "'i8')&0xff, Module.getValue(cheez+1, 'i8')&0xff, " + "Module.getValue(cheez+2, 'i8')&0xff, Module.getValue(cheez+3, " + "'i8')&0xff, ]);"); +} diff --git a/tests/core/test_varargs.in b/tests/core/test_varargs.in index d169c151..653a6557 100644 --- a/tests/core/test_varargs.in +++ b/tests/core/test_varargs.in @@ -1,103 +1,112 @@ +#include <stdio.h> +#include <stdarg.h> - #include <stdio.h> - #include <stdarg.h> - - void vary(const char *s, ...) - { - va_list v; - va_start(v, s); - char d[20]; - vsnprintf(d, 20, s, v); - puts(d); - - // Try it with copying - va_list tempva; - va_copy(tempva, v); - vsnprintf(d, 20, s, tempva); - puts(d); - - va_end(v); - } - - void vary2(char color, const char *s, ...) - { - va_list v; - va_start(v, s); - char d[21]; - d[0] = color; - vsnprintf(d+1, 20, s, v); - puts(d); - va_end(v); - } - - void varargs_listoffsets_list_evaluate(int count, va_list ap, int vaIteration) - { - while(count > 0) - { - const char* string = va_arg(ap, const char*); - printf("%s", string); - count--; - } - printf("\n"); - } - - void varags_listoffsets_list_copy(int count, va_list ap, int iteration) - { - va_list ap_copy; - va_copy(ap_copy, ap); - varargs_listoffsets_list_evaluate(count, ap_copy, iteration); - va_end(ap_copy); - } - - void varargs_listoffsets_args(int type, int count, ...) - { - va_list ap; - va_start(ap, count); - - // evaluate a copied list - varags_listoffsets_list_copy(count, ap, 1); - varags_listoffsets_list_copy(count, ap, 2); - varags_listoffsets_list_copy(count, ap, 3); - varags_listoffsets_list_copy(count, ap, 4); - - varargs_listoffsets_list_evaluate(count, ap, 1); - - // NOTE: we expect this test to fail, so we will check the stdout for <BAD+0><BAD+1>..... - varargs_listoffsets_list_evaluate(count, ap, 2); - - // NOTE: this test has to work again, as we restart the list - va_end(ap); - va_start(ap, count); - varargs_listoffsets_list_evaluate(count, ap, 3); - va_end(ap); - } - - void varargs_listoffsets_main() - { - varargs_listoffsets_args(0, 5, "abc", "def", "ghi", "jkl", "mno", "<BAD+0>", "<BAD+1>", "<BAD+2>", "<BAD+3>", "<BAD+4>", "<BAD+5>", "<BAD+6>", "<BAD+7>", "<BAD+8>", "<BAD+9>", "<BAD+10>", "<BAD+11>", "<BAD+12>", "<BAD+13>", "<BAD+14>", "<BAD+15>", "<BAD+16>"); - } - - #define GETMAX(pref, type) type getMax##pref(int num, ...) { va_list vv; va_start(vv, num); type maxx = va_arg(vv, type); for (int i = 1; i < num; i++) { type curr = va_arg(vv, type); maxx = curr > maxx ? curr : maxx; } va_end(vv); return maxx; } - GETMAX(i, int); - GETMAX(D, double); - - int main(int argc, char **argv) { - vary("*cheez: %d+%d*", 0, 24); // Also tests that '0' is not special as an array ender - vary("*albeit*"); // Should not fail with no var args in vararg function - vary2('Q', "%d*", 85); - - int maxxi = getMaxi(6, 2, 5, 21, 4, -10, 19); - printf("maxxi:%d*\n", maxxi); - double maxxD = getMaxD(6, (double)2.1, (double)5.1, (double)22.1, (double)4.1, (double)-10.1, (double)19.1, (double)2); - printf("maxxD:%.2f*\n", (float)maxxD); - - // And, as a function pointer - void (*vfp)(const char *s, ...) = argc == 1211 ? NULL : vary; - vfp("*vfp:%d,%d*", 22, 199); - - // ensure lists work properly when copied, reinited etc. - varargs_listoffsets_main(); - - return 0; - } -
\ No newline at end of file +void vary(const char *s, ...) { + va_list v; + va_start(v, s); + char d[20]; + vsnprintf(d, 20, s, v); + puts(d); + + // Try it with copying + va_list tempva; + va_copy(tempva, v); + vsnprintf(d, 20, s, tempva); + puts(d); + + va_end(v); +} + +void vary2(char color, const char *s, ...) { + va_list v; + va_start(v, s); + char d[21]; + d[0] = color; + vsnprintf(d + 1, 20, s, v); + puts(d); + va_end(v); +} + +void varargs_listoffsets_list_evaluate(int count, va_list ap, int vaIteration) { + while (count > 0) { + const char *string = va_arg(ap, const char *); + printf("%s", string); + count--; + } + printf("\n"); +} + +void varags_listoffsets_list_copy(int count, va_list ap, int iteration) { + va_list ap_copy; + va_copy(ap_copy, ap); + varargs_listoffsets_list_evaluate(count, ap_copy, iteration); + va_end(ap_copy); +} + +void varargs_listoffsets_args(int type, int count, ...) { + va_list ap; + va_start(ap, count); + + // evaluate a copied list + varags_listoffsets_list_copy(count, ap, 1); + varags_listoffsets_list_copy(count, ap, 2); + varags_listoffsets_list_copy(count, ap, 3); + varags_listoffsets_list_copy(count, ap, 4); + + varargs_listoffsets_list_evaluate(count, ap, 1); + + // NOTE: we expect this test to fail, so we will check the stdout for + // <BAD+0><BAD+1>..... + varargs_listoffsets_list_evaluate(count, ap, 2); + + // NOTE: this test has to work again, as we restart the list + va_end(ap); + va_start(ap, count); + varargs_listoffsets_list_evaluate(count, ap, 3); + va_end(ap); +} + +void varargs_listoffsets_main() { + varargs_listoffsets_args(0, 5, "abc", "def", "ghi", "jkl", "mno", "<BAD+0>", + "<BAD+1>", "<BAD+2>", "<BAD+3>", "<BAD+4>", + "<BAD+5>", "<BAD+6>", "<BAD+7>", "<BAD+8>", + "<BAD+9>", "<BAD+10>", "<BAD+11>", "<BAD+12>", + "<BAD+13>", "<BAD+14>", "<BAD+15>", "<BAD+16>"); +} + +#define GETMAX(pref, type) \ + type getMax##pref(int num, ...) { \ + va_list vv; \ + va_start(vv, num); \ + type maxx = va_arg(vv, type); \ + for (int i = 1; i < num; i++) { \ + type curr = va_arg(vv, type); \ + maxx = curr > maxx ? curr : maxx; \ + } \ + va_end(vv); \ + return maxx; \ + } +GETMAX(i, int); +GETMAX(D, double); + +int main(int argc, char **argv) { + vary("*cheez: %d+%d*", 0, + 24); // Also tests that '0' is not special as an array ender + vary("*albeit*"); // Should not fail with no var args in vararg function + vary2('Q', "%d*", 85); + + int maxxi = getMaxi(6, 2, 5, 21, 4, -10, 19); + printf("maxxi:%d*\n", maxxi); + double maxxD = getMaxD(6, (double)2.1, (double)5.1, (double)22.1, (double)4.1, + (double)-10.1, (double)19.1, (double)2); + printf("maxxD:%.2f*\n", (float)maxxD); + + // And, as a function pointer + void (*vfp)(const char * s, ...) = argc == 1211 ? NULL : vary; + vfp("*vfp:%d,%d*", 22, 199); + + // ensure lists work properly when copied, reinited etc. + varargs_listoffsets_main(); + + return 0; +} diff --git a/tests/core/test_vprintf.in b/tests/core/test_vprintf.in index fcaad9d9..a8af5735 100644 --- a/tests/core/test_vprintf.in +++ b/tests/core/test_vprintf.in @@ -1,18 +1,16 @@ +#include <stdio.h> +#include <stdarg.h> - #include <stdio.h> - #include <stdarg.h> +void print(char* format, ...) { + va_list args; + va_start(args, format); + vprintf(format, args); + va_end(args); +} - void print(char* format, ...) { - va_list args; - va_start (args, format); - vprintf (format, args); - va_end (args); - } +int main() { + print("Call with %d variable argument.\n", 1); + print("Call with %d variable %s.\n", 2, "arguments"); - int main () { - print("Call with %d variable argument.\n", 1); - print("Call with %d variable %s.\n", 2, "arguments"); - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_vsnprintf.in b/tests/core/test_vsnprintf.in index 938729b6..85f91e94 100644 --- a/tests/core/test_vsnprintf.in +++ b/tests/core/test_vsnprintf.in @@ -1,44 +1,41 @@ +#include <stdio.h> +#include <stdarg.h> +#include <stdint.h> - #include <stdio.h> - #include <stdarg.h> - #include <stdint.h> +void printy(const char *f, ...) { + char buffer[256]; + va_list args; + va_start(args, f); + vsnprintf(buffer, 256, f, args); + puts(buffer); + va_end(args); +} - void printy(const char *f, ...) - { - char buffer[256]; - va_list args; - va_start(args, f); - vsnprintf(buffer, 256, f, args); - puts(buffer); - va_end(args); - } +int main(int argc, char **argv) { + int64_t x = argc - 1; + int64_t y = argc - 1 + 0x400000; + if (x % 3 == 2) y *= 2; - int main(int argc, char **argv) { - int64_t x = argc - 1; - int64_t y = argc - 1 + 0x400000; - if (x % 3 == 2) y *= 2; + printy("0x%llx_0x%llx", x, y); + printy("0x%llx_0x%llx", x, x); + printy("0x%llx_0x%llx", y, x); + printy("0x%llx_0x%llx", y, y); - printy("0x%llx_0x%llx", x, y); - printy("0x%llx_0x%llx", x, x); - printy("0x%llx_0x%llx", y, x); - printy("0x%llx_0x%llx", y, y); + { + uint64_t A = 0x800000; + uint64_t B = 0x800000000000ULL; + printy("0x%llx_0x%llx", A, B); + } + { + uint64_t A = 0x800; + uint64_t B = 0x12340000000000ULL; + printy("0x%llx_0x%llx", A, B); + } + { + uint64_t A = 0x000009182746756; + uint64_t B = 0x192837465631ACBDULL; + printy("0x%llx_0x%llx", A, B); + } - { - uint64_t A = 0x800000; - uint64_t B = 0x800000000000ULL; - printy("0x%llx_0x%llx", A, B); - } - { - uint64_t A = 0x800; - uint64_t B = 0x12340000000000ULL; - printy("0x%llx_0x%llx", A, B); - } - { - uint64_t A = 0x000009182746756; - uint64_t B = 0x192837465631ACBDULL; - printy("0x%llx_0x%llx", A, B); - } - - return 0; - } -
\ No newline at end of file + return 0; +} diff --git a/tests/core/test_white_list_exception.in b/tests/core/test_white_list_exception.in index c7c29c35..2944f9fe 100644 --- a/tests/core/test_white_list_exception.in +++ b/tests/core/test_white_list_exception.in @@ -1,22 +1,21 @@ +#include <stdio.h> - #include <stdio.h> +void thrower() { + printf("infunc..."); + throw(99); + printf("FAIL"); +} - void thrower() { - printf("infunc..."); - throw(99); - printf("FAIL"); - } +void somefunction() { + try { + thrower(); + } + catch (...) { + printf("done!*\n"); + } +} - void somefunction() { - try { - thrower(); - } catch(...) { - printf("done!*\n"); - } - } - - int main() { - somefunction(); - return 0; - } -
\ No newline at end of file +int main() { + somefunction(); + return 0; +} diff --git a/tests/core/test_zero_multiplication.in b/tests/core/test_zero_multiplication.in index 2be87594..bb6e7e12 100644 --- a/tests/core/test_zero_multiplication.in +++ b/tests/core/test_zero_multiplication.in @@ -1,14 +1,12 @@ +#include <stdio.h> +int main(int argc, char* argv[]) { + int one = argc; - #include <stdio.h> - int main(int argc, char * argv[]) { - int one = argc; - - printf("%d ", 0 * one); - printf("%d ", 0 * -one); - printf("%d ", -one * 0); - printf("%g ", 0.0 * one); - printf("%g ", 0.0 * -one); - printf("%g", -one * 0.0); - return 0; - } -
\ No newline at end of file + printf("%d ", 0 * one); + printf("%d ", 0 * -one); + printf("%d ", -one * 0); + printf("%g ", 0.0 * one); + printf("%g ", 0.0 * -one); + printf("%g", -one * 0.0); + return 0; +} diff --git a/tests/core/test_zerodiv.in b/tests/core/test_zerodiv.in index 991b6c1d..21430772 100644 --- a/tests/core/test_zerodiv.in +++ b/tests/core/test_zerodiv.in @@ -1,21 +1,18 @@ +#include <stdio.h> +int main(int argc, const char* argv[]) { + float f1 = 1.0f; + float f2 = 0.0f; + float f_zero = 0.0f; - #include <stdio.h> - int main(int argc, const char* argv[]) - { - float f1 = 1.0f; - float f2 = 0.0f; - float f_zero = 0.0f; + float f3 = 0.0f / f2; + float f4 = f2 / 0.0f; + float f5 = f2 / f2; + float f6 = f2 / f_zero; - float f3 = 0.0f / f2; - float f4 = f2 / 0.0f; - float f5 = f2 / f2; - float f6 = f2 / f_zero; + printf("f3: %f\n", f3); + printf("f4: %f\n", f4); + printf("f5: %f\n", f5); + printf("f6: %f\n", f6); - printf("f3: %f\n", f3); - printf("f4: %f\n", f4); - printf("f5: %f\n", f5); - printf("f6: %f\n", f6); - - return 0; - } -
\ No newline at end of file + return 0; +} |