Commit f19e0294 authored by Jeremy Soller's avatar Jeremy Soller

Merge branch 'cleanup' into 'master'

General test cleanups

See merge request !193
parents 20aeb15f 4381bb2a
Pipeline #3004 passed with stages
in 13 minutes and 38 seconds
......@@ -88,14 +88,14 @@ just in case, it'd be a good idea to map inputs to variables.
#include "string.h"
#include "stdio.h"
int main() {
// Don't do this
printf("%d\n", strcspn("Hello", "Hi"));
// Do this
char *first = "Hello";
char *second = "Hi";
printf("%d\n", strcspn(first, second));
int main(void) {
// Don't do this
printf("%d\n", strcspn("Hello", "Hi"));
// Do this
char *first = "Hello";
char *second = "Hi";
printf("%d\n", strcspn(first, second));
}
```
......@@ -120,4 +120,4 @@ You can test against verified correct output with `make verify` in the tests
directory. You will need to manually create the correct output and put it in the
tests/expected directory. Running any `make` commands in the tests directory
will ***not*** rebuild relibc, so you'll need to go back to the root directory
if you need to rebuild relibc.
\ No newline at end of file
if you need to rebuild relibc.
......@@ -2,7 +2,7 @@
#include <stdio.h>
#include <string.h>
int main(int argc, char ** argv) {
int main(void) {
char *str = (char *) alloca(17);
memset(str, 'A', 16);
......
#include <string.h>
#include <unistd.h>
int main(int argc, char ** argv) {
int main(int argc, char *argv[]) {
int i;
for(i = 0; i < argc; i++) {
write(STDOUT_FILENO, argv[i], strlen(argv[i]));
write(STDOUT_FILENO, " ", 1);
}
write(STDOUT_FILENO, "\n", 1);
return 0;
}
......@@ -3,7 +3,7 @@
#include <string.h>
#include <stdlib.h>
int main(int argc, char** argv) {
int main(void) {
uint32_t hl = 0xBADFACED;
uint32_t nl = htonl(hl);
assert(nl == 0xEDACDFBA);
......
......@@ -2,7 +2,7 @@
#include <stdlib.h>
#include <stdio.h>
int main() {
int main(void) {
assert(1 == 1);
assert(1 + 1 == 2);
puts("yay!");
......
......@@ -16,6 +16,6 @@ TEST(102)
TEST(103)
TEST(104)
int main(int argc, char *argv[]) {
int main(void) {
puts("main");
}
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
struct test_case {
int c;
......@@ -289,12 +290,12 @@ size_t num_test_cases = sizeof(test_cases) / sizeof(struct test_case);
#define CHECK_TEST(tc, fn, retval) \
if (fn(tc.c) != tc.fn) { \
retval = -1; \
retval = EXIT_FAILURE; \
printf("Unexpected result: " #fn "('%c') != %d // Char value: %d\n", tc.c, tc.fn, tc.c); \
}
int main(int argc, char* argv[]) {
int retval = 0;
int main(void) {
int retval = EXIT_SUCCESS;
for(int i = 0; i < num_test_cases; ++i) {
struct test_case tc = test_cases[i];
......@@ -316,7 +317,7 @@ int main(int argc, char* argv[]) {
CHECK_TEST(tc, toupper, retval);
}
if (!retval) {
if (retval == EXIT_SUCCESS) {
printf("Success: %d\n", retval);
} else {
printf("Failure: %d\n", retval);
......
......@@ -16,6 +16,6 @@ TEST(102)
TEST(103)
TEST(104)
int main(int argc, char *argv[]) {
int main(void) {
puts("main");
}
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
int main(void) {
printf("%lu\n", sizeof(struct dirent));
DIR* dir = opendir("example_dir/");
if (dir == NULL) {
perror("opendir");
return 1;
return EXIT_FAILURE;
}
struct dirent* entry;
......@@ -37,6 +38,4 @@ int main() {
// puts(entry->d_name);
closedir(dir);
return 0;
}
......@@ -7,12 +7,12 @@ int filter(const struct dirent* dirent) {
return strstr(dirent->d_name, "3") == NULL;
}
int main() {
int main(void) {
struct dirent** array;
int len = scandir("example_dir/", &array, filter, alphasort);
if (len < 0) {
perror("scandir");
return -1;
return EXIT_FAILURE;
}
for(int i = 0; i < len; i += 1) {
......
......@@ -3,9 +3,8 @@
#include <string.h>
#include <errno.h>
int main(int argc, char** argv) {
int main(void) {
chdir("nonexistent");
printf("errno: %d = %s\n", errno, strerror(errno));
perror("perror");
return 0;
}
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char ** argv) {
int main(void) {
int fd = creat("create.out", 0755);
if (fd >= 0) {
write(fd, "Hello World!\n", 13);
close(fd);
return 0;
return EXIT_SUCCESS;
} else {
write(STDERR_FILENO, "creat failed\n", 13);
return 1;
return EXIT_FAILURE;
}
}
......@@ -2,7 +2,7 @@
#include <stdio.h>
#include <unistd.h>
int main() {
int main(void) {
//Lose our fd and pull it again
creat("fcntl.out", 0777);
int newfd = open("fcntl.out", 0);
......@@ -10,5 +10,4 @@ int main() {
printf("fd %d duped into fd %d\n", newfd, newfd2);
close(newfd);
close(newfd2);
return 0;
}
......@@ -9,7 +9,7 @@ void test(char* pattern, char* input, int flags) {
}
}
int main() {
int main(void) {
puts("Should succeed:");
test("*World", "Hello World", 0);
test("*World", "World", 0);
......
......@@ -18,7 +18,7 @@ char * get_mutable_string(char *str) {
return copy;
}
void test_basename() {
void test_basename(void) {
test_case test_cases[] =
{ {"/usr/lib", "lib"},
{"//usr//lib//", "lib"},
......@@ -44,7 +44,7 @@ void test_basename() {
return;
}
void test_dirname() {
void test_dirname(void) {
test_case test_cases[] =
{ {"/usr/lib", "/usr"},
{"//usr//lib//", "//usr"},
......@@ -73,9 +73,8 @@ void test_dirname() {
return;
}
int main() {
int main(void) {
printf("Testing libgen.h\n");
test_basename();
test_dirname();
return 0;
}
......@@ -2,7 +2,7 @@
#include <stdio.h>
#include <string.h>
int main() {
int main(void) {
// TODO: Implement locale properly and test it here
char* val = setlocale(LC_ALL, NULL);
if (strcmp(val, "C") == 0) {
......
#include <math.h>
#include <stdio.h>
int main(int argc, char ** argv) {
int main(void) {
double pi = 3.14;
float c = cos(pi);
printf("cos(%f) = %f\n", pi, c);
return 0;
}
......@@ -22,7 +22,7 @@ int main(void) {
errcode = getaddrinfo("www.redox-os.org", NULL, &hints, &res);
if (errcode != 0) {
perror("getaddrinfo");
return -1;
return EXIT_FAILURE;
}
while (res) {
......@@ -45,6 +45,4 @@ int main(void) {
res = res->ai_next;
}
return 0;
}
......@@ -225,6 +225,6 @@ do_test (void)
return (error_count != 0);
}
int main() {
int main(void) {
do_test();
}
......@@ -13,13 +13,13 @@ void print(struct passwd *pwd) {
printf("pw_shell: %s\n", pwd->pw_shell);
}
int main() {
int main(void) {
puts("--- Checking getpwuid ---");
errno = 0;
struct passwd *pwd = getpwuid(0);
if (errno != 0) {
perror("getpwuid");
return 1;
return EXIT_FAILURE;
}
if (pwd != NULL) {
print(pwd);
......@@ -30,7 +30,7 @@ int main() {
pwd = getpwnam("nobody");
if (errno != 0) {
perror("getpwnam");
return 1;
return EXIT_FAILURE;
}
if (pwd != NULL) {
print(pwd);
......@@ -43,12 +43,12 @@ int main() {
if (getpwuid_r(0, &pwd2, buf, 100, &result) < 0) {
perror("getpwuid_r");
free(buf);
return 1;
return EXIT_FAILURE;
}
if (result != NULL) {
if (result != &pwd2) {
free(buf);
return 1;
return EXIT_FAILURE;
}
print(&pwd2);
}
......@@ -57,12 +57,12 @@ int main() {
if (getpwnam_r("nobody", &pwd2, buf, 100, &result) < 0) {
perror("getpwuid_r");
free(buf);
return 1;
return EXIT_FAILURE;
}
if (result != NULL) {
if (result != &pwd2) {
free(buf);
return 1;
return EXIT_FAILURE;
}
print(&pwd2);
}
......@@ -72,11 +72,11 @@ int main() {
char buf2[1];
if (getpwuid_r(0, &pwd2, buf2, 1, &result) == 0) {
puts("This shouldn't have succeeded, but did!");
return 1;
return EXIT_FAILURE;
}
if (errno != ERANGE) {
perror("getpwuid_r");
return 1;
return EXIT_FAILURE;
}
puts("Returned ERANGE because the buffer was too small 👍");
}
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
int main(void) {
regex_t regex;
char error_buf[256];
......@@ -10,7 +11,7 @@ int main() {
regerror(error, &regex, error_buf, 255);
error_buf[255] = 0;
printf("regcomp error: %d = %s\n", error, error_buf);
return -1;
return EXIT_FAILURE;
}
regmatch_t matches[3] = {{0}};
......@@ -22,7 +23,7 @@ int main() {
if (error) {
regerror(error, &regex, error_buf, 255);
printf("regexec error: %d = %s\n", error, error_buf);
return -1;
return EXIT_FAILURE;
}
for (int group = 0; group < 3; group += 1) {
......
......@@ -6,11 +6,11 @@ void ptimeval(struct timeval* val) {
printf("{ tv_sec: %ld, tv_usec: %ld }\n", val->tv_sec, val->tv_usec);
}
int main() {
int main(void) {
struct rusage r_usage;
if (getrusage(RUSAGE_SELF, &r_usage) < 0) {
perror("getrusage");
return 1;
return EXIT_FAILURE;
}
printf("ru_utime:");
ptimeval(&r_usage.ru_utime);
......
......@@ -3,7 +3,7 @@
#include <sys/select.h>
#include <unistd.h>
int main() {
int main(void) {
int fd = open("select.c", 0, 0);
fd_set read;
......
#include <stdio.h>
#include <setjmp.h>
int main() {
int main(void) {
jmp_buf buf;
if (setjmp(buf)) {
puts("hi from jump");
......
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
......@@ -7,18 +8,18 @@ void handler(int sig) {
puts("Signal handler called!");
}
int main() {
int main(void) {
if (signal(SIGUSR1, &handler) == SIG_ERR) {
puts("Signal error!");
printf("%d\n", errno);
return 1;
return EXIT_FAILURE;
}
puts("Raising...");
if (raise(SIGUSR1)) {
puts("Raise error!");
printf("%d\n", errno);
return 1;
return EXIT_FAILURE;
}
puts("Raised.");
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char ** argv) {
int main(void) {
FILE *f = fopen("stdio/stdio.in", "r");
printf("%c\n", fgetc(f));
ungetc('H', f);
......@@ -9,5 +9,4 @@ int main(int argc, char ** argv) {
printf("%s\n", fgets(in, 30, f));
setvbuf(stdout, 0, _IONBF, 0);
printf("Hello\n");
return 0;
}
#include <stdio.h>
int main() {
int main(void) {
// Tests what used to be a bug with buffering
fwrite("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 1, 999, stdout);
fwrite("Test\n", 1, 5, stdout);
......
#include <stdio.h>
#include <stdlib.h>
int main() {
int main(void) {
//FILE *f = fopen("/etc/ssl/certs/ca-certificates.crt", "r");
FILE *f = fopen("stdio/stdio.in", "r");
char line[256];
......@@ -12,7 +13,7 @@ int main() {
puts("EOF");
if (!feof(f)) {
puts("feof() not updated!");
return -1;
return EXIT_FAILURE;
}
break;
}
......
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
int main(int argc, char ** argv) {
int main(void) {
FILE *f = fopen("stdio/fputs.out", "w");
char *in = "Hello World!";
fputs(in, f); // calls fwrite, helpers::fwritex, internal::to_write and internal::stdio_write
fclose(f);
return 0;
}
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int main(void) {
FILE *fp = fopen("stdio/fread.in", "rb");
char buf[33] = { 0 };
for (int i = 1; i <= 32; ++i) {
if (fread(buf, 1, i, fp) < 0) {
perror("fread");
return 0;
return EXIT_FAILURE;
}
buf[i] = 0;
......@@ -16,6 +17,4 @@ int main(int argc, char *argv[]) {
}
fclose(fp);
return 0;
}
#include <stdio.h>
int main(int argc, char ** argv) {
int main(void) {
freopen("stdio/stdio.in", "r", stdin);
char in[6];
fgets(in, 6, stdin);
printf("%s\n", in); // should print Hello
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main() {
int main(void) {
FILE *f = fopen("stdio/stdio.in", "r");
if (fseek(f, 14, SEEK_CUR) < 0) {
puts("fseek error");
return 1;
return EXIT_FAILURE;
}
char buffer[256];
printf("%s", fgets(buffer, 256, f));
......
......@@ -2,23 +2,22 @@
#include <stdlib.h>
#include <errno.h>
int main(int argc, char ** argv) {
int main(void) {
FILE *f = fopen("stdio/fwrite.out", "w");
const char ptr[] = "Hello World!";
if (fwrite(ptr, 0, 17, f)) {
return -1;
return EXIT_FAILURE;
}
if (fwrite(ptr, 7, 0, f)) {
return -1;
return EXIT_FAILURE;
}
if (fwrite(ptr, 0, 0, f)) {
return -1;
return EXIT_FAILURE;
}
fwrite(ptr, sizeof(ptr), 1, f);
fclose(f);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char ** argv) {
int main(void) {
ungetc('h', stdin);
char c;
if ((c = getchar()) == 'h') {
printf("Worked!\n");
return 0;
return EXIT_SUCCESS;
}
printf("failed :( %c\n", c);
return 0;
return EXIT_FAILURE;
}
#include <stdio.h>
#include <stdlib.h>
int main() {
int main(void) {
FILE* f = fopen("stdio/stdio.in", "r");
flockfile(f);
......@@ -10,17 +11,17 @@ int main() {
if (!ftrylockfile(f)) {
puts("Mutex unlocked but it shouldn't be");
return -1;
return EXIT_FAILURE;
}
funlockfile(f);
if (ftrylockfile(f)) {
puts("Mutex locked but it shouldn't be");
return -1;
return EXIT_FAILURE;
}
if (!ftrylockfile(f)) {
puts("Mutex unlocked but it shouldn't be");
return -1;
return EXIT_FAILURE;
}
funlockfile(f);
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
int main(void) {
FILE *fp;
int status;
char path[256];
......@@ -9,7 +10,7 @@ int main(int argc, char **argv) {
fp = popen("ls -1 example_dir", "r");
if (fp == NULL) {
perror("popen");
return -1;
return EXIT_FAILURE;
}
while (fgets(path, 256, fp) != NULL) {
......@@ -20,10 +21,8 @@ int main(int argc, char **argv) {
status = pclose(fp);
if (status == -1) {
perror("pclose");
return -1;
return EXIT_FAILURE;
} else {
printf("status %x\n", status);
}
return 0;
}
#include <stdio.h>
int main(int argc, char ** argv) {
int main(void) {
int sofar = 0;
int len = printf(
"percent: %%\nstring: %s\nchar: %c\nchar: %c\nint: %d\n%nuint: %u\nhex: %x\nHEX: %X\nstring: %s\n",
......@@ -48,5 +48,4 @@ int main(int argc, char ** argv) {
printf("%G\n", 0.0001);
printf("%G\n", 0.00001);
printf("%E\n", 0.00001);
return 0;
}
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
......@@ -8,7 +9,7 @@ static char newpath[] = "new-name.out";
static char str[] = "Hello, World!";
int str_len = 13;
int main() {
int main(void) {
char buf[14];
buf[13] = 0x00;
int fd = creat(oldpath, 0777);
......@@ -20,8 +21,8 @@ int main() {
close(fd);
remove(newpath);
if (strcmp(str, buf) == 0) {
return 0;
return EXIT_SUCCESS;
} else {
return -1;
return EXIT_FAILURE;
}
}
......@@ -25,7 +25,7 @@ void test(char* fmt_in, char* input, struct params *p, ...) {
);
}
int main(int argc, char ** argv) {
int main(void) {
struct params p = { .c = 'a' };
test("%hhd %d", "12 345", &p, &p.sa, &p.ia);
......
#include <stdio.h>
#include <stdlib.h>