Merge branch 'cleanup' into 'master'

tests: Macro based error handling

See merge request redox-os/relibc!195
This commit is contained in:
jD91mZM2
2019-03-03 15:19:19 +00:00
121 changed files with 1048 additions and 541 deletions
+4 -2
View File
@@ -1,12 +1,14 @@
#include <stdlib.h>
#include <stdio.h>
#include "test_helpers.h"
int main(void) {
char * s = "azAZ9."; // test boundaries
long l = a64l(s);
if (l != 194301926) {
printf("Invalid result: a64l(%s) = %ld\n", s, l);
return EXIT_FAILURE;
exit(EXIT_FAILURE);
}
printf("Correct a64l: %s = %ld\n", s, l);
@@ -15,7 +17,7 @@ int main(void) {
l = a64l(s);
if (l != 53222) {
printf("Invalid result: a64l(%s) = %ld\n", s, l);
return EXIT_FAILURE;
exit(EXIT_FAILURE);
}
printf("Correct a64l: %s = %ld\n", s, l);
}
+2
View File
@@ -3,6 +3,8 @@
#include <stdlib.h>
#include <stdint.h> /* for SIZE_MAX */
#include "test_helpers.h"
int main(void) {
char * ptr = (char *)malloc(256);
printf("malloc %p\n", ptr);
+2
View File
@@ -1,6 +1,8 @@
#include <stdlib.h>
#include <stdio.h>
#include "test_helpers.h"
int main(void) {
double d = atof("-3.14");
printf("%f\n", d);
+2
View File
@@ -1,6 +1,8 @@
#include <stdlib.h>
#include <stdio.h>
#include "test_helpers.h"
int main(void) {
printf("%d\n", atoi(" -42"));
printf("%d\n", atoi(" +555"));
+40 -40
View File
@@ -1,56 +1,56 @@
#include <stdlib.h>
#include <stdio.h>
#include "test_helpers.h"
int int_cmp(const void* a, const void* b) {
return *(const int*) a - *(const int*) b;
return *(const int*) a - *(const int*) b;
}
#define BSEARCH_TEST_INT(key, arr, len, expect) \
do { \
void* res = bsearch((const void*) &key, (void*) arr, len, sizeof(int), int_cmp); \
if (res != expect) { \
printf("FAIL bsearch for %d in [", key); \
size_t i = 0; \
for (; i < len; ++i) printf("%d,", arr[i]); \
printf("] expected %p but got %p\n", (void*) expect, res); \
return EXIT_FAILURE; \
} \
} while (0);
do { \
void* res = bsearch((const void*) &key, (void*) arr, len, sizeof(int), int_cmp); \
if (res != expect) { \
printf("FAIL bsearch for %d in [", key); \
size_t i = 0; \
for (; i < len; ++i) printf("%d,", arr[i]); \
printf("] expected %p but got %p\n", (void*) expect, res); \
exit(EXIT_FAILURE); \
} \
} while (0)
int main(void) {
int x = 0;
int y = 1024;
int x = 0;
int y = 1024;
// TODO: Zero sized arrays are a non-standard GNU extension
//int empty[] = {};
//BSEARCH_TEST_INT(x, empty, 0, NULL);
// TODO: Zero sized arrays are a non-standard GNU extension
//int empty[] = {};
//BSEARCH_TEST_INT(x, empty, 0, NULL);
int singleton[] = {42};
printf("%p\n%p\n", singleton, &singleton[1]);
BSEARCH_TEST_INT(x, singleton, 1, NULL);
BSEARCH_TEST_INT(singleton[0], singleton, 1, &singleton[0]);
BSEARCH_TEST_INT(y, singleton, 1, NULL);
int singleton[] = {42};
printf("%p\n%p\n", singleton, &singleton[1]);
BSEARCH_TEST_INT(x, singleton, 1, NULL);
BSEARCH_TEST_INT(singleton[0], singleton, 1, &singleton[0]);
BSEARCH_TEST_INT(y, singleton, 1, NULL);
int two[] = {14, 42};
BSEARCH_TEST_INT(x, two, 2, NULL);
BSEARCH_TEST_INT(y, two, 2, NULL);
BSEARCH_TEST_INT(two[0], two, 2, &two[0]);
BSEARCH_TEST_INT(two[0], two, 1, &two[0]);
BSEARCH_TEST_INT(two[1], two, 2, &two[1]);
BSEARCH_TEST_INT(two[1], two, 1, NULL);
int two[] = {14, 42};
BSEARCH_TEST_INT(x, two, 2, NULL);
BSEARCH_TEST_INT(y, two, 2, NULL);
BSEARCH_TEST_INT(two[0], two, 2, &two[0]);
BSEARCH_TEST_INT(two[0], two, 1, &two[0]);
BSEARCH_TEST_INT(two[1], two, 2, &two[1]);
BSEARCH_TEST_INT(two[1], two, 1, NULL);
int three[] = {-5, -1, 4};
BSEARCH_TEST_INT(three[0], three, 3, &three[0]);
BSEARCH_TEST_INT(three[1], three, 3, &three[1]);
BSEARCH_TEST_INT(three[2], three, 3, &three[2]);
int three[] = {-5, -1, 4};
BSEARCH_TEST_INT(three[0], three, 3, &three[0]);
BSEARCH_TEST_INT(three[1], three, 3, &three[1]);
BSEARCH_TEST_INT(three[2], three, 3, &three[2]);
int big[] = {-19, -13, -7, -3, 2, 5, 11};
BSEARCH_TEST_INT(big[0], big, 7, big);
BSEARCH_TEST_INT(big[6], big, 7, &big[6]);
BSEARCH_TEST_INT(big[3], big, 7, &big[3]);
BSEARCH_TEST_INT(x, big, 7, NULL);
int big[] = {-19, -13, -7, -3, 2, 5, 11};
BSEARCH_TEST_INT(big[0], big, 7, big);
BSEARCH_TEST_INT(big[6], big, 7, &big[6]);
BSEARCH_TEST_INT(big[3], big, 7, &big[3]);
BSEARCH_TEST_INT(x, big, 7, NULL);
printf("PASS bsearch\n");
printf("PASS bsearch\n");
}
+18 -15
View File
@@ -1,20 +1,23 @@
#include <stdlib.h>
volatile float f;
volatile long double ld;
volatile unsigned long long ll;
lldiv_t mydivt;
#include "test_helpers.h"
volatile float f;
volatile long double ld;
volatile unsigned long long ll;
lldiv_t mydivt;
int main(void) {
char* tmp;
f = strtof("gnu", &tmp);
ld = strtold("gnu", &tmp);
ll = strtoll("gnu", &tmp, 10);
ll = strtoull("gnu", &tmp, 10);
ll = llabs(10);
mydivt = lldiv(10,1);
ll = mydivt.quot;
ll = mydivt.rem;
ll = atoll("10");
_Exit(0);
char* tmp;
f = strtof("gnu", &tmp);
ld = strtold("gnu", &tmp);
ll = strtoll("gnu", &tmp, 10);
ll = strtoull("gnu", &tmp, 10);
ll = llabs(10);
mydivt = lldiv(10,1);
ll = mydivt.quot;
ll = mydivt.rem;
ll = atoll("10");
_Exit(0);
}
+3 -1
View File
@@ -2,6 +2,8 @@
#include <stdlib.h>
#include <string.h>
#include "test_helpers.h"
int main(void) {
//puts(getenv("SHELL"));
//puts(getenv("CC"));
@@ -34,7 +36,7 @@ int main(void) {
if (env) {
puts("This should be null, but isn't");
puts(env);
return EXIT_FAILURE;
exit(EXIT_FAILURE);
} else {
puts("Value deleted successfully!");
}
+2
View File
@@ -2,6 +2,8 @@
#include <stdio.h>
#include <string.h>
#include "test_helpers.h"
int main(void) {
char* file_name = (char*) calloc(18, sizeof(char));
strcpy(file_name, "tempXXXXXX.suffix");
+2
View File
@@ -2,6 +2,8 @@
#include <stdio.h>
#include <string.h>
#include "test_helpers.h"
int main(void) {
char* string = (char*) calloc(20, sizeof(char));
strcpy(string, "tempXXXXXX");
+28 -2
View File
@@ -1,8 +1,34 @@
#include <stdlib.h>
#include <stdio.h>
#include "test_helpers.h"
int main(void) {
printf("%d\n", rand());
// Uninitialized generator
int rand_uninit = rand();
printf("%d\n", rand_uninit);
// Testing the reproducibility of values
srand(259);
printf("%d\n", rand());
int rand_seed259_1 = rand();
printf("%d\n", rand_seed259_1);
srand(259);
int rand_seed259_2 = rand();
printf("%d\n", rand_seed259_2);
if (rand_seed259_1 != rand_seed259_2) {
puts("rand() doesn't return reproducible values");
exit(EXIT_FAILURE);
}
// Seed value 1 should return the same values as the ininitialized generator
srand(1);
int rand_seed1 = rand();
printf("%d\n", rand_seed1);
if (rand_uninit != rand_seed1) {
puts("srand(1) doesn't work");
exit(EXIT_FAILURE);
}
}
+11 -20
View File
@@ -4,26 +4,17 @@
#include <stdlib.h>
#include <string.h>
#include "test_helpers.h"
int main(void) {
char* path = realpath("stdlib/realpath.c", NULL);
if (!path) {
perror("realpath");
return EXIT_FAILURE;
}
puts(path);
char *path_res = realpath("stdlib/realpath.c", NULL);
ERROR_IF(realpath, path_res, == NULL);
puts(path_res);
free(path_res);
free(path);
path = malloc(PATH_MAX);
memset(path, 0, PATH_MAX);
realpath("stdlib/realpath.c", path);
if (!path) {
perror("realpath");
free(path);
return EXIT_FAILURE;
}
puts(path);
free(path);
char path_arg[PATH_MAX] = { 0 };
char *res = realpath("stdlib/realpath.c", path_arg);
ERROR_IF(realpath, res, == NULL);
puts(path_arg);
free(path_arg);
}
+2
View File
@@ -1,6 +1,8 @@
#include <stdlib.h>
#include <stdio.h>
#include "test_helpers.h"
int main(void) {
char* endptr = 0;
double d;
+2
View File
@@ -2,6 +2,8 @@
#include <stdlib.h>
#include <stdio.h>
#include "test_helpers.h"
int main(void) {
printf("%ld\n", strtol(" -42", NULL, 0));
printf("%ld\n", strtol(" +555", NULL, 0));
+2
View File
@@ -2,6 +2,8 @@
#include <stdlib.h>
#include <stdio.h>
#include "test_helpers.h"
int main(void) {
printf("%ld\n", strtoul(" -42", NULL, 0));
printf("%ld\n", strtoul(" +555", NULL, 0));
+4 -1
View File
@@ -1,5 +1,8 @@
#include <stdlib.h>
#include "test_helpers.h"
int main(void) {
system("echo test of system");
int status = system("echo test of system");
ERROR_IF(system, status, == -1);
}