diff options
author | kripken <alonzakai@gmail.com> | 2011-07-30 23:33:13 -0700 |
---|---|---|
committer | kripken <alonzakai@gmail.com> | 2011-07-30 23:33:13 -0700 |
commit | 5f5cd01b4debb82c344880d2d682f62f11c7452a (patch) | |
tree | ec11c8b360aec50f9474568866bd204d8fcf991f /tests | |
parent | 904f50c51eef50d28cc2469686ab8848a1b72258 (diff) | |
parent | 17c60015790e099393e650a60c0a225db1de0030 (diff) |
Merge pull request #58 from max99x/master
Environment and lib fixes (ctype.h, math.h)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ctype/output.txt | 233 | ||||
-rw-r--r-- | tests/ctype/src.c | 194 | ||||
-rw-r--r-- | tests/env/output.txt | 29 | ||||
-rw-r--r-- | tests/env/src.c | 43 | ||||
-rw-r--r-- | tests/runner.py | 66 |
5 files changed, 565 insertions, 0 deletions
diff --git a/tests/ctype/output.txt b/tests/ctype/output.txt new file mode 100644 index 00000000..5f98d20d --- /dev/null +++ b/tests/ctype/output.txt @@ -0,0 +1,233 @@ +ab1 +AB1 +cd2 +CD2 + +toascii(-45): 83 +toascii( 10): 10 +toascii('a'): 97 +toascii(183): 55 + +isascii/call(-45): 0 +isascii/call( 10): 1 +isascii/call('a'): 1 +isascii/call('A'): 1 +isascii/call('5'): 1 +isascii/call('.'): 1 +isascii/call(183): 0 + +islower/call(-45): 0 +islower/call( 10): 0 +islower/call('a'): 1 +islower/call('A'): 0 +islower/call('5'): 0 +islower/call('.'): 0 +islower/call(183): 0 + +isupper/call(-45): 0 +isupper/call( 10): 0 +isupper/call('a'): 0 +isupper/call('A'): 1 +isupper/call('5'): 0 +isupper/call('.'): 0 +isupper/call(183): 0 + +isupper/call(-45): 0 +isupper/call( 10): 0 +isupper/call('a'): 0 +isupper/call('A'): 1 +isupper/call('5'): 0 +isupper/call('.'): 0 +isupper/call(183): 0 + +isalpha/call(-45): 0 +isalpha/call( 10): 0 +isalpha/call('a'): 1 +isalpha/call('A'): 1 +isalpha/call('5'): 0 +isalpha/call('.'): 0 +isalpha/call(183): 0 + +isdigit/call(-45): 0 +isdigit/call( 10): 0 +isdigit/call('a'): 0 +isdigit/call('A'): 0 +isdigit/call('5'): 1 +isdigit/call('.'): 0 +isdigit/call(183): 0 + +isxdigit/call(-45): 0 +isxdigit/call( 10): 0 +isxdigit/call('a'): 1 +isxdigit/call('A'): 1 +isxdigit/call('5'): 1 +isxdigit/call('.'): 0 +isxdigit/call(183): 0 + +isalnum/call(-45): 0 +isalnum/call( 10): 0 +isalnum/call('a'): 1 +isalnum/call('A'): 1 +isalnum/call('5'): 1 +isalnum/call('.'): 0 +isalnum/call(183): 0 + +ispunct/call(-45): 0 +ispunct/call( 10): 0 +ispunct/call('a'): 0 +ispunct/call('A'): 0 +ispunct/call('5'): 0 +ispunct/call('.'): 1 +ispunct/call(183): 0 + +isspace/call(-45): 0 +isspace/call( 10): 1 +isspace/call('a'): 0 +isspace/call('A'): 0 +isspace/call('5'): 0 +isspace/call('.'): 0 +isspace/call(183): 0 + +isblank/call(-45): 0 +isblank/call( 10): 0 +isblank/call('a'): 0 +isblank/call('A'): 0 +isblank/call('5'): 0 +isblank/call('.'): 0 +isblank/call(183): 0 + +iscntrl/call(-45): 0 +iscntrl/call( 10): 1 +iscntrl/call('a'): 0 +iscntrl/call('A'): 0 +iscntrl/call('5'): 0 +iscntrl/call('.'): 0 +iscntrl/call(183): 0 + +isprint/call(-45): 0 +isprint/call( 10): 0 +isprint/call('a'): 1 +isprint/call('A'): 1 +isprint/call('5'): 1 +isprint/call('.'): 1 +isprint/call(183): 0 + +isgraph/call(-45): 0 +isgraph/call( 10): 0 +isgraph/call('a'): 1 +isgraph/call('A'): 1 +isgraph/call('5'): 1 +isgraph/call('.'): 1 +isgraph/call(183): 0 + +isascii(-45): 0 +isascii( 10): 1 +isascii('a'): 1 +isascii('A'): 1 +isascii('5'): 1 +isascii('.'): 1 +isascii(183): 0 + +islower(-45): 0 +islower( 10): 0 +islower('a'): 1 +islower('A'): 0 +islower('5'): 0 +islower('.'): 0 +islower(183): 0 + +isupper(-45): 0 +isupper( 10): 0 +isupper('a'): 0 +isupper('A'): 1 +isupper('5'): 0 +isupper('.'): 0 +isupper(183): 0 + +isupper(-45): 0 +isupper( 10): 0 +isupper('a'): 0 +isupper('A'): 1 +isupper('5'): 0 +isupper('.'): 0 +isupper(183): 0 + +isalpha(-45): 0 +isalpha( 10): 0 +isalpha('a'): 1 +isalpha('A'): 1 +isalpha('5'): 0 +isalpha('.'): 0 +isalpha(183): 0 + +isdigit(-45): 0 +isdigit( 10): 0 +isdigit('a'): 0 +isdigit('A'): 0 +isdigit('5'): 1 +isdigit('.'): 0 +isdigit(183): 0 + +isxdigit(-45): 0 +isxdigit( 10): 0 +isxdigit('a'): 1 +isxdigit('A'): 1 +isxdigit('5'): 1 +isxdigit('.'): 0 +isxdigit(183): 0 + +isalnum(-45): 0 +isalnum( 10): 0 +isalnum('a'): 1 +isalnum('A'): 1 +isalnum('5'): 1 +isalnum('.'): 0 +isalnum(183): 0 + +ispunct(-45): 0 +ispunct( 10): 0 +ispunct('a'): 0 +ispunct('A'): 0 +ispunct('5'): 0 +ispunct('.'): 1 +ispunct(183): 0 + +isspace(-45): 0 +isspace( 10): 1 +isspace('a'): 0 +isspace('A'): 0 +isspace('5'): 0 +isspace('.'): 0 +isspace(183): 0 + +isblank(-45): 0 +isblank( 10): 0 +isblank('a'): 0 +isblank('A'): 0 +isblank('5'): 0 +isblank('.'): 0 +isblank(183): 0 + +iscntrl(-45): 0 +iscntrl( 10): 1 +iscntrl('a'): 0 +iscntrl('A'): 0 +iscntrl('5'): 0 +iscntrl('.'): 0 +iscntrl(183): 0 + +isprint(-45): 0 +isprint( 10): 0 +isprint('a'): 1 +isprint('A'): 1 +isprint('5'): 1 +isprint('.'): 1 +isprint(183): 0 + +isgraph(-45): 0 +isgraph( 10): 0 +isgraph('a'): 1 +isgraph('A'): 1 +isgraph('5'): 1 +isgraph('.'): 1 +isgraph(183): 0 diff --git a/tests/ctype/src.c b/tests/ctype/src.c new file mode 100644 index 00000000..4dce6999 --- /dev/null +++ b/tests/ctype/src.c @@ -0,0 +1,194 @@ +#define _BSD_SOURCE +#include <stdio.h> +#include <ctype.h> + +int main() { + printf("%c%c%c\n", tolower('a'), tolower('B'), tolower('1')); + printf("%c%c%c\n", toupper('a'), toupper('B'), toupper('1')); + + const int* tl = *__ctype_tolower_loc(); + printf("%c%c%c\n", (char)tl['c'], (char)tl['D'], (char)tl['2']); + const int* tu = *__ctype_toupper_loc(); + printf("%c%c%c\n", (char)tu['c'], (char)tu['D'], (char)tu['2']); + + printf("\n"); + + printf("toascii(-45): %d\n", toascii(-45)); + printf("toascii( 10): %d\n", toascii(10)); + printf("toascii('a'): %d\n", toascii('a')); + printf("toascii(183): %d\n", toascii(183)); + + // These will be compiled as actual function calls. + int (*funcs[])(int) = { + isascii, + islower, + isupper, + isupper, + isalpha, + isdigit, + isxdigit, + isalnum, + ispunct, + isspace, + isblank, + iscntrl, + isprint, + isgraph + }; + char* funcNames[] = { + "isascii", + "islower", + "isupper", + "isupper", + "isalpha", + "isdigit", + "isxdigit", + "isalnum", + "ispunct", + "isspace", + "isblank", + "iscntrl", + "isprint", + "isgraph" + }; + for (int i = 0; i < sizeof funcs / sizeof funcs[0]; i++) { + printf("\n"); + printf("%s/call(-45): %d\n", funcNames[i], funcs[i](-45) != 0); + printf("%s/call( 10): %d\n", funcNames[i], funcs[i](10) != 0); + printf("%s/call('a'): %d\n", funcNames[i], funcs[i]('a') != 0); + printf("%s/call('A'): %d\n", funcNames[i], funcs[i]('A') != 0); + printf("%s/call('5'): %d\n", funcNames[i], funcs[i]('5') != 0); + printf("%s/call('.'): %d\n", funcNames[i], funcs[i]('.') != 0); + printf("%s/call(183): %d\n", funcNames[i], funcs[i](183) != 0); + } + + printf("\n"); + printf("isascii(-45): %d\n", isascii(-45) != 0); + printf("isascii( 10): %d\n", isascii( 10) != 0); + printf("isascii('a'): %d\n", isascii('a') != 0); + printf("isascii('A'): %d\n", isascii('A') != 0); + printf("isascii('5'): %d\n", isascii('5') != 0); + printf("isascii('.'): %d\n", isascii('.') != 0); + printf("isascii(183): %d\n", isascii(183) != 0); + + // These are manually preprocessed to use __ctype_b_loc. The flags combination + // that the test runner uses seems to cause the macro to be ignored. + printf("\n"); + printf("islower(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISlower) != 0); + printf("islower( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISlower) != 0); + printf("islower('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISlower) != 0); + printf("islower('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISlower) != 0); + printf("islower('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISlower) != 0); + printf("islower('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISlower) != 0); + printf("islower(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISlower) != 0); + + printf("\n"); + printf("isupper(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISupper) != 0); + printf("isupper( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISupper) != 0); + printf("isupper('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISupper) != 0); + printf("isupper('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISupper) != 0); + printf("isupper('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISupper) != 0); + printf("isupper('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISupper) != 0); + printf("isupper(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISupper) != 0); + + printf("\n"); + printf("isupper(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISupper) != 0); + printf("isupper( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISupper) != 0); + printf("isupper('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISupper) != 0); + printf("isupper('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISupper) != 0); + printf("isupper('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISupper) != 0); + printf("isupper('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISupper) != 0); + printf("isupper(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISupper) != 0); + + printf("\n"); + printf("isalpha(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISalpha) != 0); + printf("isalpha( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISalpha) != 0); + printf("isalpha('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISalpha) != 0); + printf("isalpha('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISalpha) != 0); + printf("isalpha('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISalpha) != 0); + printf("isalpha('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISalpha) != 0); + printf("isalpha(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISalpha) != 0); + + printf("\n"); + printf("isdigit(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISdigit) != 0); + printf("isdigit( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISdigit) != 0); + printf("isdigit('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISdigit) != 0); + printf("isdigit('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISdigit) != 0); + printf("isdigit('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISdigit) != 0); + printf("isdigit('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISdigit) != 0); + printf("isdigit(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISdigit) != 0); + + printf("\n"); + printf("isxdigit(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISxdigit) != 0); + printf("isxdigit( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISxdigit) != 0); + printf("isxdigit('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISxdigit) != 0); + printf("isxdigit('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISxdigit) != 0); + printf("isxdigit('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISxdigit) != 0); + printf("isxdigit('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISxdigit) != 0); + printf("isxdigit(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISxdigit) != 0); + + printf("\n"); + printf("isalnum(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISalnum) != 0); + printf("isalnum( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISalnum) != 0); + printf("isalnum('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISalnum) != 0); + printf("isalnum('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISalnum) != 0); + printf("isalnum('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISalnum) != 0); + printf("isalnum('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISalnum) != 0); + printf("isalnum(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISalnum) != 0); + + printf("\n"); + printf("ispunct(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISpunct) != 0); + printf("ispunct( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISpunct) != 0); + printf("ispunct('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISpunct) != 0); + printf("ispunct('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISpunct) != 0); + printf("ispunct('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISpunct) != 0); + printf("ispunct('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISpunct) != 0); + printf("ispunct(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISpunct) != 0); + + printf("\n"); + printf("isspace(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISspace) != 0); + printf("isspace( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISspace) != 0); + printf("isspace('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISspace) != 0); + printf("isspace('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISspace) != 0); + printf("isspace('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISspace) != 0); + printf("isspace('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISspace) != 0); + printf("isspace(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISspace) != 0); + + printf("\n"); + printf("isblank(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISblank) != 0); + printf("isblank( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISblank) != 0); + printf("isblank('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISblank) != 0); + printf("isblank('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISblank) != 0); + printf("isblank('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISblank) != 0); + printf("isblank('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISblank) != 0); + printf("isblank(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISblank) != 0); + + printf("\n"); + printf("iscntrl(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _IScntrl) != 0); + printf("iscntrl( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _IScntrl) != 0); + printf("iscntrl('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _IScntrl) != 0); + printf("iscntrl('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _IScntrl) != 0); + printf("iscntrl('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _IScntrl) != 0); + printf("iscntrl('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _IScntrl) != 0); + printf("iscntrl(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _IScntrl) != 0); + + printf("\n"); + printf("isprint(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISprint) != 0); + printf("isprint( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISprint) != 0); + printf("isprint('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISprint) != 0); + printf("isprint('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISprint) != 0); + printf("isprint('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISprint) != 0); + printf("isprint('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISprint) != 0); + printf("isprint(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISprint) != 0); + + printf("\n"); + printf("isgraph(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISgraph) != 0); + printf("isgraph( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISgraph) != 0); + printf("isgraph('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISgraph) != 0); + printf("isgraph('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISgraph) != 0); + printf("isgraph('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISgraph) != 0); + printf("isgraph('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISgraph) != 0); + printf("isgraph(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISgraph) != 0); + + return 0; +} diff --git a/tests/env/output.txt b/tests/env/output.txt new file mode 100644 index 00000000..fa342d48 --- /dev/null +++ b/tests/env/output.txt @@ -0,0 +1,29 @@ +List: +USER=root +PATH=/ +PWD=/ +HOME=/ +LANG=en_US.UTF-8 +_=./this.program + +getenv(PATH): / +getenv(NONEXISTENT): (null) +setenv/0(PATH) ret: 0 +getenv(PATH) after setenv/0: / +setenv/1(PATH) ret: 0 +getenv(PATH) after setenv/1: test2 +setenv(SET_VALUE) ret: 0 +setenv(SET_VALUE2) ret: 0 +getenv(SET_VALUE): test3 +getenv(SET_VALUE2): test4 +putenv(PUT_VALUE) ret: 0 +getenv(PUT_VALUE): test5 +getenv(PUT_VALUE) after alteration: test5 +unsetenv(PUT_VALUE) ret: 0 +getenv(PUT_VALUE) after unsetenv: (null) +setenv(0) ret: -1 +setenv('') ret: -1 +setenv(X=Y) ret: -1 +unsetenv(0) ret: -1 +unsetenv('') ret: -1 +unsetenv(X=Y) ret: -1 diff --git a/tests/env/src.c b/tests/env/src.c new file mode 100644 index 00000000..46419495 --- /dev/null +++ b/tests/env/src.c @@ -0,0 +1,43 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +int main() { + printf("List:\n"); + for (char** str = __environ; *str; str++) { + printf("%s\n", *str); + } + printf("\n"); + + printf("getenv(PATH): %s\n", getenv("PATH")); + printf("getenv(NONEXISTENT): %s\n", getenv("NONEXISTENT")); + + printf("setenv/0(PATH) ret: %d\n", setenv("PATH", "test", 0)); + printf("getenv(PATH) after setenv/0: %s\n", getenv("PATH")); + printf("setenv/1(PATH) ret: %d\n", setenv("PATH", "test2", 1)); + printf("getenv(PATH) after setenv/1: %s\n", getenv("PATH")); + + printf("setenv(SET_VALUE) ret: %d\n", setenv("SET_VALUE", "test3", 0)); + printf("setenv(SET_VALUE2) ret: %d\n", setenv("SET_VALUE2", "test4", 1)); + printf("getenv(SET_VALUE): %s\n", getenv("SET_VALUE")); + printf("getenv(SET_VALUE2): %s\n", getenv("SET_VALUE2")); + + char buffer[] = "PUT_VALUE=test5"; + printf("putenv(PUT_VALUE) ret: %d\n", putenv(buffer)); + printf("getenv(PUT_VALUE): %s\n", getenv("PUT_VALUE")); + // NOTE: This should change the value. In our implementation, it doesn't. + buffer[10] = 'Q'; + printf("getenv(PUT_VALUE) after alteration: %s\n", getenv("PUT_VALUE")); + + printf("unsetenv(PUT_VALUE) ret: %d\n", unsetenv("PUT_VALUE")); + printf("getenv(PUT_VALUE) after unsetenv: %s\n", getenv("PUT_VALUE")); + + printf("setenv(0) ret: %d\n", setenv(0, "foo", 1)); + printf("setenv('') ret: %d\n", setenv("", "foo", 1)); + printf("setenv(X=Y) ret: %d\n", setenv("X=Y", "foo", 1)); + printf("unsetenv(0) ret: %d\n", unsetenv(0)); + printf("unsetenv('') ret: %d\n", unsetenv("")); + printf("unsetenv(X=Y) ret: %d\n", unsetenv("X=Y")); + + return 0; +} diff --git a/tests/runner.py b/tests/runner.py index 8e1fdfa5..330c0726 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -2576,6 +2576,72 @@ if 'benchmark' not in sys.argv: expected = open(path_from_root('tests', 'unistd', 'misc.out'), 'r').read() self.do_test(src, expected) + def test_uname(self): + src = r''' + #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; + } + ''' + expected = ''' + ret: 0 + sysname: Emscripten + nodename: emscripten + release: 1.0 + version: #1 + machine: x86-JS + ''' + self.do_test(src, re.sub('(^|\n)\s+', '\\1', expected)) + + def test_env(self): + src = open(path_from_root('tests', 'env', 'src.c'), 'r').read() + expected = open(path_from_root('tests', 'env', 'output.txt'), 'r').read() + self.do_test(src, expected) + + def test_getloadavg(self): + src = r''' + #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]: %lf\n", load[0]); + printf("load[1]: %lf\n", load[1]); + printf("load[2]: %lf\n", load[2]); + printf("load[3]: %lf\n", load[3]); + printf("load[4]: %lf\n", load[4]); + return 0; + } + ''' + expected = ''' + ret: 3 + load[0]: 0.100000 + load[1]: 0.100000 + load[2]: 0.100000 + load[3]: 42.130000 + load[4]: 42.130000 + ''' + self.do_test(src, re.sub('(^|\n)\s+', '\\1', expected)) + + def test_ctype(self): + # The bit fiddling done by the macros using __ctype_b_loc requires this. + global CORRECT_SIGNS; CORRECT_SIGNS = 1 + src = open(path_from_root('tests', 'ctype', 'src.c'), 'r').read() + expected = open(path_from_root('tests', 'ctype', 'output.txt'), 'r').read() + self.do_test(src, expected) + CORRECT_SIGNS = 0 + ### 'Big' tests def test_fannkuch(self): |