Skip to content

Commit

Permalink
Update.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalBlk committed Jul 8, 2022
2 parents f6c05dc + 1b90886 commit fc4a4f6
Show file tree
Hide file tree
Showing 217 changed files with 9,782 additions and 588 deletions.
5 changes: 4 additions & 1 deletion bin/mandelbrot/mandelbrot.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static int fun(float re, float im) {
}

int main(void) {
int vgafd = open("/dev/vga", O_RDWR, 0);
int vgafd = open("/dev/vga", O_WRONLY, 0);
if (vgafd < 0) {
printf("can't open /dev/vga file\n");
return 1;
Expand Down Expand Up @@ -103,6 +103,9 @@ int main(void) {

display_image(vgafd);

puts("Press CTRL+C to exit.");
pause();

close(vgafd);

return 0;
Expand Down
6 changes: 6 additions & 0 deletions bin/utest/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ int main(int argc, char **argv) {

CHECKRUN_TEST(pipe_parent_signaled);
CHECKRUN_TEST(pipe_child_signaled);
CHECKRUN_TEST(pipe_blocking_flag_manipulation);
CHECKRUN_TEST(pipe_write_interruptible_sleep);
CHECKRUN_TEST(pipe_write_errno_eagain);
CHECKRUN_TEST(pipe_read_interruptible_sleep);
CHECKRUN_TEST(pipe_read_errno_eagain);
CHECKRUN_TEST(pipe_read_return_zero);

printf("No user test \"%s\" available.\n", test_name);
return 1;
Expand Down
240 changes: 238 additions & 2 deletions bin/utest/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>

#include <signal.h>
#include <string.h>
#include <limits.h>

#include <sys/types.h>
#include <sys/wait.h>
Expand All @@ -16,8 +18,9 @@
static sig_atomic_t signal_delivered;

static void sigpipe_handler(int signo) {
assert(signo == SIGPIPE);
signal_delivered = 1;
if (signo == SIGPIPE) {
signal_delivered = 1;
}
}

int test_pipe_parent_signaled(void) {
Expand Down Expand Up @@ -104,3 +107,236 @@ int test_pipe_child_signaled(void) {

return 0;
}

int test_pipe_blocking_flag_manipulation(void) {
int pipe_fd[2];

/* creating pipe */
int pipe2_ret = pipe2(pipe_fd, O_NONBLOCK);
assert(pipe2_ret == 0);

/* check if flag is set */
int is_flag_set;
is_flag_set = fcntl(pipe_fd[0], F_GETFL) & O_NONBLOCK;
assert(is_flag_set);
is_flag_set = fcntl(pipe_fd[1], F_GETFL) & O_NONBLOCK;
assert(is_flag_set);

/* unset same flag for read end */
int read_flagset_with_block = fcntl(pipe_fd[0], F_GETFL);
assert(read_flagset_with_block > 0);
fcntl(pipe_fd[0], F_SETFL, read_flagset_with_block & ~O_NONBLOCK);
/* unset same flag for write end */
int write_flagset_with_block = fcntl(pipe_fd[1], F_GETFL);
assert(write_flagset_with_block > 0);
fcntl(pipe_fd[1], F_SETFL, write_flagset_with_block & ~O_NONBLOCK);

/* check if flag is not set */

int is_flag_not_set;
is_flag_not_set = fcntl(pipe_fd[0], F_GETFL) & O_NONBLOCK;
assert(!is_flag_not_set);
is_flag_not_set = fcntl(pipe_fd[1], F_GETFL) & O_NONBLOCK;
assert(!is_flag_not_set);

close(pipe_fd[0]);
close(pipe_fd[1]);

return 0;
}

int test_pipe_write_interruptible_sleep(void) {
int pipe_fd[2];
pid_t child_pid;

/* creating pipe */
int pipe2_ret = pipe2(pipe_fd, 0);
assert(pipe2_ret == 0);

/* forking */
child_pid = fork();
assert(child_pid >= 0);

if (child_pid == 0) { /* child */
close(pipe_fd[0]); /* closing read end of pipe */

struct sigaction sa = {
.sa_handler = sigpipe_handler,
.sa_flags = 0,
};

sigaction(SIGALRM, &sa, NULL);

int page_size = getpagesize();
char *data = malloc(page_size * sizeof(char));

for (int i = 0; i < page_size; i++) {
data[i] = (i + '0') % CHAR_MAX;
}
int bytes_wrote = 0;
alarm(1);

while (bytes_wrote >= 0) {
bytes_wrote = write(pipe_fd[1], &data, sizeof(data));
}
assert(bytes_wrote == -1);
assert(errno == EINTR);

close(pipe_fd[1]); /* closing write end of pipe */
free(data);
exit(EXIT_SUCCESS);
}

close(pipe_fd[1]); /* closing write end of pipe */
wait_for_child_exit(child_pid, EXIT_SUCCESS);
close(pipe_fd[0]); /* closing read end of pipe */
return 0;
}

int test_pipe_write_errno_eagain(void) {
int pipe_fd[2];
pid_t child_pid;
int bytes_wrote = 0;

/* creating pipe */
int pipe2_ret = pipe2(pipe_fd, O_NONBLOCK);
assert(pipe2_ret == 0);

/* forking */
child_pid = fork();
assert(child_pid >= 0);

if (child_pid == 0) {
close(pipe_fd[0]); /* closing read end of pipe */

int page_size = getpagesize();
/* prepare varying data */
char *data = malloc(page_size * sizeof(char));

for (int i = 0; i < page_size; i++) {
data[i] = (i + '0') % CHAR_MAX;
}

/* overflowing pipe */
while (bytes_wrote >= 0) {
bytes_wrote = write(pipe_fd[1], &data, sizeof(data));
}
assert(bytes_wrote == -1);
assert(errno == EAGAIN);

close(pipe_fd[1]); /* closing write end of pipe */
free(data);
exit(EXIT_SUCCESS);
}

close(pipe_fd[1]); /* closing write end of pipe */
wait_for_child_exit(child_pid, EXIT_SUCCESS);
close(pipe_fd[0]);
return 0;
}

int test_pipe_read_interruptible_sleep(void) {
int pipe_fd[2];
pid_t child_pid;
int bytes_wrote;

/* creating pipe */
int pipe2_ret = pipe2(pipe_fd, 0);
assert(pipe2_ret == 0);

/* forking */
child_pid = fork();
assert(child_pid >= 0);

if (child_pid == 0) { /* child */
close(pipe_fd[1]); /* closing write end of pipe */

struct sigaction sa = {
.sa_handler = sigpipe_handler,
.sa_flags = 0,
};

sigaction(SIGALRM, &sa, NULL);

char buf;
alarm(1);

bytes_wrote = read(pipe_fd[0], &buf, 1);

assert(bytes_wrote == -1);
assert(errno == EINTR);

close(pipe_fd[0]);
exit(EXIT_SUCCESS);
}

close(pipe_fd[0]); /* closing read end of pipe */
wait_for_child_exit(child_pid, EXIT_SUCCESS);
close(pipe_fd[1]); /* closing write end of pipe */

return 0;
}

int test_pipe_read_errno_eagain(void) {
int pipe_fd[2];
pid_t child_pid;
int bytes_wrote;

/* creating pipe */
int pipe2_ret = pipe2(pipe_fd, O_NONBLOCK);
assert(pipe2_ret == 0);

/* forking */
child_pid = fork();
assert(child_pid >= 0);

if (child_pid == 0) { /* child */

close(pipe_fd[1]); /* closing write end of pipe */

char buf;
bytes_wrote = read(pipe_fd[0], &buf, 1);
assert(errno == EAGAIN);
assert(bytes_wrote == -1);
close(pipe_fd[0]);

exit(EXIT_SUCCESS);
}

close(pipe_fd[0]); /* closing read end of pipe */
wait_for_child_exit(child_pid, EXIT_SUCCESS);
close(pipe_fd[1]); /* closing write end of pipe */
return 0;
}

int test_pipe_read_return_zero(void) {
int pipe_fd[2];
pid_t child_pid;
int bytes_wrote;

/* creating pipe */
int pipe2_ret = pipe2(pipe_fd, 0);
assert(pipe2_ret == 0);

/* forking */
child_pid = fork();
assert(child_pid >= 0);

if (child_pid == 0) { /* child */
close(pipe_fd[1]); /* closing write end of pipe */

char buf;
bytes_wrote = read(pipe_fd[0], &buf, 1);

assert(bytes_wrote == 0);
assert(errno == 0);

close(pipe_fd[0]);
exit(EXIT_SUCCESS);
}

close(pipe_fd[0]); /* closing read end of pipe */
close(pipe_fd[1]); /* closing write end of pipe */
wait_for_child_exit(child_pid, EXIT_SUCCESS);
return 0;
}
8 changes: 8 additions & 0 deletions bin/utest/utest.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,12 @@ int test_procstat(void);
int test_pipe_parent_signaled(void);
int test_pipe_child_signaled(void);

int test_pipe_blocking_flag_manipulation(void);
int test_pipe_write_interruptible_sleep(void);
int test_pipe_write_errno_eagain(void);

int test_pipe_read_interruptible_sleep(void);
int test_pipe_read_errno_eagain(void);
int test_pipe_read_return_zero(void);

#endif /* __UTEST_H__ */
2 changes: 1 addition & 1 deletion build/arch.aarch64.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#

TARGET := aarch64-mimiker-elf
GCC_ABIFLAGS :=
GCC_ABIFLAGS := -mno-outline-atomics
CLANG_ABIFLAGS := -target aarch64-elf
ELFTYPE := elf64-littleaarch64
ELFARCH := aarch64
Expand Down
2 changes: 1 addition & 1 deletion build/arch.mips.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TARGET := mipsel-mimiker-elf
# as otherwise they would exceed 64KB limit
GCC_ABIFLAGS := -mips32r2 -EL -G 0
CLANG_ABIFLAGS := -target mipsel-elf -march=mips32r2 -mno-abicalls \
-modd-spreg -G 0
-modd-spreg -G 0 -D__ELF__=1
ELFTYPE := elf32-littlemips
ELFARCH := mips

Expand Down
1 change: 1 addition & 0 deletions contrib/doom/01-vga-output.patch
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ index d55b2fe..108d82a 100644
+
void I_FinishUpdate (void)
{
+ lseek(vgafd, SEEK_SET, 0);
+ write(vgafd, screens[0], SCREENWIDTH*SCREENHEIGHT);
headless_count ++ ;
}
Expand Down
1 change: 1 addition & 0 deletions include/riscv/asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@

#define REG_LI li
#define REG_ADD add
#define REG_SUB sub
#define REG_SLLI slli
#define REG_SLL sll
#define REG_SRLI srli
Expand Down
3 changes: 0 additions & 3 deletions include/riscv/pmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
#define DMAP_MAX_SIZE 0x40000000
#endif

#define RISCV_PHYSADDR(x) \
((paddr_t)((vaddr_t)(x) & ~KERNEL_SPACE_BEGIN) + KERNEL_PHYS)

#if __riscv_xlen == 64
#define PAGE_TABLE_DEPTH 3
#define GROWKERNEL_STRIDE L1_SIZE
Expand Down
Loading

0 comments on commit fc4a4f6

Please sign in to comment.