Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kernel/src/tests/unit/test_fpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,4 @@ void test_fpu(void)
test_fpu_exp();
test_fpu_pi_precision();
test_fpu_loop_accumulation();
}
}
2 changes: 2 additions & 0 deletions lib/inc/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "sys/types.h"
#include "time.h"

#define REALTIME_SCHEDULER_SUPPORT !SCHEDULER_RR

/// @brief Structure that describes scheduling parameters.
typedef struct sched_param {
/// Static execution priority.
Expand Down
8 changes: 0 additions & 8 deletions qemu_test_output.txt

This file was deleted.

26 changes: 14 additions & 12 deletions userspace/bin/runtests.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ static char *all_tests[] = {
"t_creat",
"t_dup",
"t_environ",
"t_exit",
"t_exec",
"t_exit",
"t_fflush",
"t_fhs",
"t_fork",
"t_gid",
"t_grp",
"t_groups",
"t_grp",
"t_hashmap",
"t_itimer",
"t_kill",
Expand All @@ -42,9 +44,9 @@ static char *all_tests[] = {
"t_mkdir",
"t_msgget",
"t_ndtree",
// "t_periodic1",
// "t_periodic2",
// "t_periodic3",
"t_periodic1",
"t_periodic2",
"t_periodic3",
"t_pipe_blocking",
"t_pipe_non_blocking",
"t_pwd",
Expand All @@ -63,7 +65,7 @@ static char *all_tests[] = {
"t_spwd",
"t_stopcont",
"t_syslog",
// "t_time",
"t_time",
"t_write_read",
};

Expand All @@ -78,12 +80,12 @@ static int test_err_fd;

static int init;

#define append(...) \
do { \
bufpos += sprintf(bufpos, __VA_ARGS__); \
if (bufpos >= buf + sizeof(buf)) { \
return -1; \
} \
#define append(...) \
do { \
bufpos += sprintf(bufpos, __VA_ARGS__); \
if (bufpos >= buf + sizeof(buf)) { \
return -1; \
} \
} while (0);

static int test_out_flush(void)
Expand Down
79 changes: 38 additions & 41 deletions userspace/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,56 +1,51 @@
# List of programs.
set(TEST_LIST
t_exit.c
# t_time.c # Temporarily disabled
t_chdir.c
t_grp.c
t_pwd.c
t_mkdir.c
t_dup.c
t_hashmap.c
t_list.c
t_msgget.c
t_pipe_blocking.c
t_syslog.c
t_periodic2.c
t_sigfpe.c
t_creat.c
t_itimer.c
t_schedfb.c
t_write_read.c
t_abort.c
t_shmget.c
t_exec.c
t_gid.c
t_grp.c
t_stopcont.c
t_ndtree.c
t_pwd.c
t_fflush.c
t_sigusr.c
t_kill.c
t_periodic1.c
t_chdir.c
t_fhs.c
t_spwd.c
t_shm.c
t_semget.c
t_mkdir.c
t_alarm.c
t_periodic3.c
t_exit.c
t_environ.c
t_itimer.c
t_fork.c
t_semget.c
t_exec.c
t_sleep.c
t_periodic2.c
t_pipe_blocking.c
t_siginfo.c
t_pipe_non_blocking.c
t_sigfpe.c
t_sleep.c
t_mem.c
t_fork.c
t_semflg.c
t_time.c
t_big_write.c
t_sigmask.c
t_sigusr.c
t_shmget.c
t_stopcont.c
t_semop.c
t_sigaction.c
t_schedfb.c
t_siginfo.c
t_periodic3.c
t_semop.c
t_groups.c
t_semflg.c
t_abort.c
t_msgget.c
t_periodic1.c
t_kill.c
t_shm.c
t_mem.c
t_spwd.c
t_big_write.c
t_syslog.c
t_ndtree.c
t_list.c
t_hashmap.c
t_scanf.c
t_fflush.c
t_fhs.c
t_ext2_audit_write_boundary.c
t_ext2_audit_overflow.c
t_ext2_audit_read_failure.c
t_ext2_audit_mount_cache.c
)

# Set the directory where the compiled binaries will be placed.
Expand Down Expand Up @@ -90,6 +85,8 @@ foreach(FILE_NAME ${TEST_LIST})
target_link_libraries(${TARGET_NAME} libc)
# We need to specify the name of the entry function.
target_compile_options(${TARGET_NAME} PRIVATE -u_start)
# Add the define stating which scheduler is currently active.
target_compile_definitions(${TARGET_NAME} PRIVATE ${SCHEDULER_TYPE})
# Add the linking properties.
set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "-Wl,-Ttext=${TEXT_ADDR},-e_start,-melf_i386")
# Set the output directory.
Expand Down
120 changes: 71 additions & 49 deletions userspace/tests/t_big_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,84 +15,106 @@
#include <syslog.h>
#include <unistd.h>

#define FILENAME "/home/user/test.txt"
#define ITERATIONS 8
#define FILENAME "/tmp/test.txt"
#define ITERATIONS 4
#define BUFFER_SIZE BUFSIZ

int main(int argc, char *argv[])
int write_test_data(const char *filename, int iterations)
{
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
char write_buffer[BUFFER_SIZE] = {0};
char read_buffer[BUFFER_SIZE] = {0};

// Open the file with specified flags and mode.
int fd = open(FILENAME, O_WRONLY | O_CREAT | O_TRUNC, mode);
int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd < 0) {
syslog(LOG_ERR, "[t_big_write] Failed to open file %s: %s\n", FILENAME, strerror(errno));
syslog(LOG_ERR, "Failed to open file %s: %s\n", filename, strerror(errno));
return EXIT_FAILURE;
}

// Write test data to the file.
for (unsigned times = 0; times < ITERATIONS; ++times) {
int result = EXIT_SUCCESS;
char buffer[BUFFER_SIZE];
for (unsigned times = 0; times < iterations; ++times) {
for (unsigned i = 'A'; i < 'z'; ++i) {
memset(write_buffer, i, sizeof(write_buffer));
if (write(fd, write_buffer, sizeof(write_buffer)) < 0) {
syslog(LOG_ERR, "[t_big_write] Writing to file %s failed: %s\n", FILENAME, strerror(errno));
close(fd);
unlink(FILENAME);
return EXIT_FAILURE;
memset(buffer, i, sizeof(buffer));
if (write(fd, buffer, sizeof(buffer)) < 0) {
syslog(LOG_ERR, "Writing to file %s failed: %s\n", filename, strerror(errno));
result = EXIT_FAILURE;
goto write_close_and_cleanup;
} else {
syslog(LOG_DEBUG, "Wrote %u bytes of character %c to file %s (progress %u/%u)\n", sizeof(buffer), i, filename, times * ('z' - 'A' + 1) + i - 'A', iterations * ('z' - 'A' + 1));
}
}
}

// Close the file descriptor.
write_close_and_cleanup:
// Close the file descriptor and unlink the file after the test is done.
if (close(fd) < 0) {
syslog(LOG_ERR, "[t_big_write] Failed to close file %s: %s\n", FILENAME, strerror(errno));
unlink(FILENAME);
return EXIT_FAILURE;
syslog(LOG_ERR, "Failed to close file %s: %s\n", filename, strerror(errno));
result = EXIT_FAILURE;
}
// Unlink the file after the test is done.
if (unlink(FILENAME) < 0) {
syslog(LOG_ERR, "Failed to delete file %s: %s\n", FILENAME, strerror(errno));
result = EXIT_FAILURE;
}
return result;
}

// Open the file with specified flags and mode.
fd = open(FILENAME, O_RDONLY, mode);
int read_and_verify_test_data(const char *filename, int iterations)
{
int fd = open(filename, O_RDONLY, 0);
if (fd < 0) {
syslog(LOG_ERR, "[t_big_write] Failed to open file %s: %s\n", FILENAME, strerror(errno));
unlink(FILENAME);
syslog(LOG_ERR, "Failed to open file %s: %s\n", filename, strerror(errno));
return EXIT_FAILURE;
}

// Read and verify data from the file.
for (unsigned times = 0; times < ITERATIONS; ++times) {
for (unsigned i = 'A'; i < 'z'; ++i) {
memset(write_buffer, i, sizeof(write_buffer));
if (read(fd, read_buffer, sizeof(read_buffer)) < 0) {
syslog(LOG_ERR, "[t_big_write] Reading from file %s failed: %s\n", FILENAME, strerror(errno));
close(fd);
unlink(FILENAME);
return EXIT_FAILURE;
int result = EXIT_SUCCESS;
char read_buf[BUFFER_SIZE];
char expected[BUFFER_SIZE];

for (unsigned pass = 0; pass < iterations; ++pass) {
for (unsigned ch = 'A'; ch < 'z'; ++ch) {
/* prepare the expected pattern for this character */
memset(expected, ch, sizeof(expected));

ssize_t got = read(fd, read_buf, sizeof(read_buf));
if (got < 0) {
syslog(LOG_ERR, "Reading from file %s failed: %s\n", filename, strerror(errno));
result = EXIT_FAILURE;
goto read_close_and_cleanup;
}

// Verify read data matches what was written.
if (memcmp(write_buffer, read_buffer, sizeof(write_buffer)) != 0) {
syslog(LOG_ERR, "[t_big_write] Data mismatch in file %s at iteration %u, char %c\n", FILENAME, times, i);
close(fd);
unlink(FILENAME);
return EXIT_FAILURE;
if (got != (ssize_t)sizeof(read_buf)) {
syslog(LOG_ERR, "Unexpected read length %zd from %s\n", got, filename);
result = EXIT_FAILURE;
goto read_close_and_cleanup;
}

if (memcmp(read_buf, expected, sizeof(read_buf)) != 0) {
syslog(LOG_ERR, "Data mismatch in file %s at iteration %u, char %c\n", filename, pass, ch);
result = EXIT_FAILURE;
goto read_close_and_cleanup;
}
}
}

// Close the file descriptor.
read_close_and_cleanup:
// Close the file descriptor and unlink the file after the test is done.
if (close(fd) < 0) {
syslog(LOG_ERR, "[t_big_write] Failed to close file %s: %s\n", FILENAME, strerror(errno));
unlink(FILENAME);
return EXIT_FAILURE;
syslog(LOG_ERR, "Failed to close file %s: %s\n", filename, strerror(errno));
result = EXIT_FAILURE;
}

// Delete the test file.
// Unlink the file after the test is done.
if (unlink(FILENAME) < 0) {
syslog(LOG_ERR, "[t_big_write] Failed to delete file %s: %s\n", FILENAME, strerror(errno));
syslog(LOG_ERR, "Failed to delete file %s: %s\n", FILENAME, strerror(errno));
result = EXIT_FAILURE;
}
return result;
}

int main(int argc, char *argv[])
{
if (write_test_data(FILENAME, ITERATIONS) != EXIT_SUCCESS) {
return EXIT_FAILURE;
}

if (read_and_verify_test_data(FILENAME, ITERATIONS) != EXIT_SUCCESS) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Loading
Loading